Fixed Nabi Issues N_SE-37149,37150,37266,36875,37109,36975,36962,36964,37114,37110...
[apps/osp/Internet.git] / src / IntMainForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 //!Internet MainForm class
18 /*@file:        MainForm.cpp
19  *@brief:       The %MainForm provides the common functionalities for the Main View of the Browser including the addressbar,
20  *                      loading,handling events etc.
21  */
22
23 #include <FApp.h>
24 #include <FGraphics.h>
25 #include <FMedia.h>
26 #include <FUi.h>
27 #include <FContent.h>
28
29 #include "IntBookmarkData.h"
30 #include "IntBookmarkPresentationModel.h"
31 #include "IntCommonLib.h"
32 #include "IntFaviconManager.h"
33 #include "IntMainForm.h"
34 #include "IntNotificationPanel.h"
35 #include "IntSceneRegister.h"
36 #include "IntSettingPresentationModel.h"
37
38 using namespace Tizen::App;
39 using namespace Tizen::Base;
40 using namespace Tizen::Base::Collection;
41 using namespace Tizen::Base::Runtime;
42 using namespace Tizen::Base::Utility;
43 using namespace Tizen::Graphics;
44 using namespace Tizen::Io;
45 using namespace Tizen::Locales;
46 using namespace Tizen::Media;
47 using namespace Tizen::Ui;
48 using namespace Tizen::Ui::Controls;
49 using namespace Tizen::Content;
50 using namespace Tizen::Ui::Scenes;
51 using namespace Tizen::System;
52 using namespace Tizen::Web;
53 using namespace Tizen::Web::Controls;
54
55 static const wchar_t* IDB_SEARCH_INPUT_FIELD_BG = L"I01_toolbar_input_field.9.png";
56 static const wchar_t* IDB_FINDWORD_INPUT_FIELD_BG = L"I01_toolbar_input_field_findword.9.png";
57 static const wchar_t* IDB_BTN_BACK = L"I01_icon_Back.png";
58 static const wchar_t* IDB_BTN_BACK_PRESS = L"I01_icon_Back_press.png";
59 static const wchar_t* IDB_CONTRLBAR_ICON_BOOKMARK = L"I01_search_list_icon_favorite.png";
60 static const wchar_t* IDB_CONTRLBAR_ICON_BOOKMARK_PRESS = L"I01_search_list_icon_favorite_press.png";
61 static const wchar_t* IDB_CONTRLBAR_ICON_MORE = L"I01_icon_more.png";
62 static const wchar_t* IDB_CONTRLBAR_ICON_MORE_PRESS = L"I01_icon_more_press.png";
63 static const wchar_t* IDB_CONTRLBAR_ICON_NEW_WINDOW = L"I01_icon_plus.png";
64 static const wchar_t* IDB_CONTRLBAR_ICON_NEW_WINDOW_PRESS = L"I01_icon_plus_press.png";
65 static const wchar_t* IDB_CONTROLBAR_ICON_CREATE_DISABLE = L"I01_controlbar_icon_create_disable.png";
66 static const wchar_t* IDB_BUTTON_ON = L"00_button_on.png";
67 static const wchar_t* IDB_BUTTON_OFF = L"00_button_off.png";
68 static const wchar_t* IDB_ICON_BOOKMARK_OFF_TEMP = L"I01_icon_bookmark_off_temp.png";
69 static const wchar_t* IDB_ICON_BOOKMARK_ON_TEMP = L"I01_icon_bookmark_on_temp.png";
70 static const wchar_t* IDS_TIZEN_SERVICE = L"tizen-service";
71 static const wchar_t* IDS_APPID = L"AppID";
72 static const wchar_t* IDB_TITLE_PROGRESS_BAR_BG = L"I01_title_progress_bar_bg.png";
73 static const wchar_t* IDB_TITLE_PROGRESS_BAR = L"I01_title_progress_bar.png";
74
75 const int IDA_BACKBTN_CLICKED = 101;
76 const int IDA_BOOKMARKBTN_CLICKED = 102;
77 const int IDA_MOREBTN_CLICKED = 103;
78 const int IDA_MULTIWINDOWBTN_CLICKED = 104;
79 const int IDA_NEWWINDOWBTN_CLICKED = 105;
80 const int IDA_FORWARD_CLICKED = 106;
81 const int IDA_ADDTOBOOKMARK_CLICKED = 107;
82 const int IDA_SHARE_CLICKED = 108;
83 const int IDA_FINDONPAGE_CLICKED = 109;
84 const int IDA_PRIVATEON_CLICKED = 110;
85 const int IDA_SETTINGS_CLICKED = 111;
86 const int IDA_READER_CLOSE_CLICKED = 112;
87 const int IDA_SMALLFONT_BTN_CLICKED = 113;
88 const int IDA_LARGEFONT_BTN_CLICKED = 114;
89 const int IDA_BRIGHTNESS_BTN_CLICKED = 115;
90 const int IDA_HISTORY_CLICKED = 116;
91 const int IDA_ADD_TO_BOOKMARKBTN_CLICKED = 117;
92 const int IDA_ADD_TO_HOME_CLICKED = 118;
93 const int IDA_SAVED_PAGES_CLICKED = 119;
94 const int IDA_DESKTOP_VIEW_CLICKED = 120;
95 const int IDA_SAVE_CLICKED = 121;
96
97 const int IDA_FINDWORD_SEARCH_CLICKED = 201;
98 const int IDA_FINDWORD_NEXT_CLICKED = 202;
99 const int IDA_FINDWORD_PREV_CLICKED = 203;
100 const int IDA_FINDWORD_CLEAR_CLICKED = 204;
101 const int IDA_FINDWORD_CANCEL_CLICKED = 205;
102
103 const int IDA_COPY_IMAGE_CLICKED = 206;
104 const int IDA_VIEW_IMAGE_CLICKED = 207;
105 const int IDA_SAVE_IMAGE_CLICKED = 208;
106 const int IDA_SHARE_IMAGE_CLICKED = 209;
107
108 const int IDA_COPY_TEXT_CLICKED = 210;
109 const int IDA_PASTE_TEXT_CLICKED = 211;
110 const int IDA_FIND_TEXT__CLICKED = 212;
111 const int IDA_SHARE_TEXT_CLICKED = 213;
112
113 const int IDA_GO_BACK = 214;
114 const int IDA_GO_FORWARD = 215;
115 const int IDA_REFRESH_BTN_CLICKED = 216;
116 const int IDA_STOP_BTN_CLICKED = 217;
117 const int IDA_CLEAR_URL = 218;
118
119 const int IDA_HYPERLINK_OPEN_CLICKED = 219;
120 const int IDA_HYPERLINK_COPY_LINK_CLICKED = 220;
121 const int IDA_HYPERLINK_SAVE_IMAGE_CLICKED = 222;
122 const int IDA_HYPERLINK_SHARE_IMAGE_CLICKED = 223;
123
124 const int DEFAULT_PROGRESS_PERCENTAGE = 10;
125
126 const int MainForm::IDA_FORMAT_BITMAP = 500;
127 const int MainForm::IDA_FORMAT_DELETE_BITMAP = 501;
128 const int MainForm::IDA_FORMAT_TITLE_STRING = 502;
129 const int MainForm::IDA_FORMAT_URL_STRING = 503;
130 const int MainForm::IDA_CONTEXT_ITEM_DELETE = 504;
131
132 static const int WIDTH_CONTEXT_MENU_BUTTON_PORTRAIT = 336;
133 static const int WIDTH_CONTEXT_MENU_BUTTON_LANDSCAPE = 800;
134 static const int HEIGHT_CONTEXT_MENU_BUTTON = 72;
135
136 MainForm::MainForm(void)
137 {
138         __isLongPressedDone = false;
139         __pAddressbar = null;
140         //      __pMostVisitedSitesPanel = null;
141         __pMostVisitedListView = null;
142         __pFooterPanel = null;
143         __pHitElementResult = null;
144         __pWindowInfo = null;
145         __pWebViewer = null;
146         __pImageMenu = null;
147         __pMenu = null;
148         __pFindWordControl = null;
149
150         __pFindWordBgLabel = null;
151         __pFindWordEditField = null;
152         __pFindWordClear = null;
153         __pFindWordCountLabel = null;
154         __pFindWordNext = null;
155         __pFindWordPrev = null;
156         __previousZoomLevel = 1.0;
157         __pSaveImage = null;
158         __currentAddMode = ADDRESSBAR_MODE_LOADING_COMPLETE;
159         __displayUrl = L"";
160         __editTextUrl = L"";
161         __currentSearchStr = L"";
162         __currentSelectedStr = L"";
163         __maxOccurrances = 0;
164         __currentWordIndex = 0;
165         __distanceMoved = 0;
166         __isLoaded = false;
167         __inputEventToBeSupressed = false;
168         __isLoadingData = false;
169         __isLoadingCompleted = false;
170         __progressPercentage = 0;
171         __touchPoint1 = Point(-1,-1);
172         __touchPoint2 = Point(-1,-1);
173         __pWebReader = null;
174         //      __pReaderPopup = null;
175         __pReaderData = null;
176         __pPopUp = null;
177         __pReaderCloseBtn = null;
178         //__pNewWindowButton = null;
179         __pMoreButton = null;
180         __pMultiWindowButton = null;
181         __pArticleReaderPanel = null;
182         __pBlankPanel = null;
183         __pArticleReaderLabel = null;
184         __webControlHeight = 0;
185         __prevAddressBarMode = ADDRESSBAR_MODE_INVALID;
186         __curAddressBarMode = ADDRESSBAR_MODE_INVALID;
187         __pMostVisitedSites = null;
188         __pFooterUrlField = null;
189         __pGoBackBtn = null;
190         __pGoForwardBtn = null;
191         __pRefreshBtn = null;
192         __pProgressbarLabel = null;
193         __pFooterLabel = null;
194         __pStopBtn = null;
195         __pClearBtn = null;
196         __isWebKeypadOpened = false;
197 }
198
199 MainForm::~MainForm(void)
200 {
201         SettingPresentationModel::GetInstance()->RemoveSettingsEventListener(*this);
202
203         if(__pAddressbar)
204         {
205                 __pAddressbar->SetAddressbarEventListener(null);
206         }
207         if (__pReaderData != null)
208         {
209                 delete __pReaderData;
210                 __pReaderData = null;
211         }
212
213         if (__pPopUp != null)
214         {
215                 delete __pPopUp;
216                 __pPopUp = null;
217         }
218
219         if (__pHitElementResult != null)
220         {
221                 delete __pHitElementResult;
222                 __pHitElementResult = null;
223         }
224
225         String* pSelectedScene = NULL;
226         Object* pValue = NULL;
227         MultipleWindowPresentationModel::GetInstance()->GetValue(SELECTED_SCENE_ID, &pValue);
228         pSelectedScene = (String*) pValue;
229
230         /*if (pSelectedScene != null)
231         {
232                 delete pSelectedScene;
233         }
234         MultiWindowPresentationModel::SetValue(SELECTED_SCENE_ID, null);*/
235 }
236
237 bool
238 MainForm::Initialize(void)
239 {
240         Construct(L"IDL_FORM");
241         return true;
242 }
243
244 result
245 MainForm::OnInitializing(void)
246 {
247         AppLog("get client area width = %d",GetClientAreaBounds().width);
248         AppLog("get client area height = %d",GetClientAreaBounds().height);
249         const int WIDTH_CONTEXT_MENU_BUTTON = 336;
250         const int HEIGHT_CONTEXT_MENU_BUTTON = 72;
251
252         Panel* pFooterPanel = null;
253
254         __pSaveImage = new Image();
255         __pSaveImage->Construct();
256
257         // Setup back event listener
258         SettingPresentationModel::GetInstance()->AddSettingsEventListener(*this);
259         SceneManager::GetInstance()->AddSceneEventListener(IDSCN_MAIN_VIEW, *this);
260         AddOrientationEventListener(*this);
261         AppLogDebug(" MainForm::OnInitializing ended");
262         if (__pMostVisitedSites == null)
263         {
264                 __pMostVisitedSites = new(std::nothrow) ArrayList();
265                 __pMostVisitedSites->Construct();
266         }
267         HistoryPresentationModel::GetInstance()->GetMostVisitedSites(*__pMostVisitedSites);
268
269         __pItemContext= new(std::nothrow) ListContextItem();
270         __pItemContext->Construct();
271         Bitmap* pBitmapNormal = CommonUtil::GetNinepatchedBitmapN(L"00_button_sweep_delete.9.png", WIDTH_CONTEXT_MENU_BUTTON,HEIGHT_CONTEXT_MENU_BUTTON);
272         Bitmap* pBitmapPressed = CommonUtil::GetNinepatchedBitmapN(L"00_button_sweep_delete_press.9.png", WIDTH_CONTEXT_MENU_BUTTON, HEIGHT_CONTEXT_MENU_BUTTON);
273
274         if (pBitmapNormal != null && pBitmapPressed != null)
275         {
276                 __pItemContext->AddElement(IDA_CONTEXT_ITEM_DELETE, CommonUtil::GetString(L"IDS_BR_SK_DELETE_ABB"), *pBitmapNormal, *pBitmapPressed, pBitmapPressed);
277         }
278
279         if (pBitmapNormal != null)
280         {
281                 delete pBitmapNormal;
282         }
283
284         if (pBitmapPressed != null)
285         {
286                 delete pBitmapPressed;
287         }
288
289         __pItemContextLandscape= new(std::nothrow) ListContextItem();
290         __pItemContextLandscape->Construct();
291         pBitmapNormal = CommonUtil::GetNinepatchedBitmapN(L"00_button_sweep_delete.9.png", WIDTH_CONTEXT_MENU_BUTTON_LANDSCAPE,HEIGHT_CONTEXT_MENU_BUTTON);
292         pBitmapPressed = CommonUtil::GetNinepatchedBitmapN(L"00_button_sweep_delete_press.9.png", WIDTH_CONTEXT_MENU_BUTTON_LANDSCAPE, HEIGHT_CONTEXT_MENU_BUTTON);
293
294         if (pBitmapNormal != null && pBitmapPressed != null)
295         {
296                 __pItemContextLandscape->AddElement(IDA_CONTEXT_ITEM_DELETE, CommonUtil::GetString(L"IDS_BR_SK_DELETE_ABB"), *pBitmapNormal, *pBitmapPressed, pBitmapPressed);
297         }
298
299         if (pBitmapNormal != null)
300         {
301                 delete pBitmapNormal;
302         }
303
304         if (pBitmapPressed != null)
305         {
306                 delete pBitmapPressed;
307         }
308
309         return E_SUCCESS;
310 }
311
312 result
313 MainForm::InitAddressbar(void)
314 {
315         AppLogDebug("MainForm::InitAddressbar entered");
316
317         result r = E_SUCCESS;
318
319         if (__pAddressbar != null)
320         {
321                 return E_SUCCESS;
322         }
323         __pAddressbar = new(std::nothrow) Addressbar();
324         AppLog("MainForm::InitAddressbar GetClientAreaBounds().width %d",GetClientAreaBounds().width);
325         r = __pAddressbar->Initialize(Tizen::Graphics::Rectangle(0, 0, GetClientAreaBounds().width, 82));
326         if (r != E_SUCCESS)
327         {
328                 AppLogDebug("Addressbar init failed with %s", GetErrorMessage(r));
329                 return r;
330         }
331         __pAddressbar->SetAddressbarEventListener(this);
332         AddControl(*__pAddressbar);
333         __pAddressbar->SetBounds(Rectangle(0,0,GetClientAreaBounds().width,__pAddressbar->GetHeight()));
334         SetControlAlwaysOnTop(*__pAddressbar, true);
335         __adressPanelPosition = __pAddressbar->GetPosition();
336
337         AppLogDebug("MainForm::InitAddressbar exit");
338
339         return E_SUCCESS;
340 }
341
342 result
343 MainForm::CreateReaderPanel(void)
344 {
345         AppLogDebug("CreateReaderPanel() width %d",GetClientAreaBounds().width);
346         result r = E_FAILURE;
347         WebSetting settings;
348         Button *pSmallFontBtn = null;
349         Button *pLargeFontBtn = null;
350
351         __pBlankPanel = new (std::nothrow) Panel();
352         __pBlankPanel->Construct(L"IDL_BLANK_PANEL");
353
354         __pArticleReaderPanel = new (std::nothrow) Panel();
355         __pArticleReaderPanel->Construct(L"IDL_ARTICLE_READER");
356
357         __pReaderCloseBtn =  static_cast<Button*>(__pArticleReaderPanel->GetControl(L"IDC_CLOSE_READER",true));
358         if (__pReaderCloseBtn)
359         {
360                 AppLogDebug("CreateReaderPanel() 6");
361                 __pReaderCloseBtn->AddActionEventListener(*this);
362                 __pReaderCloseBtn->SetActionId(IDA_READER_CLOSE_CLICKED);
363         }
364
365         __pWebReader = new (std::nothrow) Web();
366         __pWebReader->Construct(Rectangle(2,2, __pArticleReaderPanel->GetWidth()-2,__pArticleReaderPanel->GetHeight() - 96 -2));
367
368         settings.SetInputStyle(INPUT_STYLE_OVERLAY);
369         settings.SetFontSize(SettingPresentationModel::GetInstance()->GetReaderFontSize());
370
371         r = __pWebReader->SetSetting(settings);
372         if (IsFailed(r))
373                 AppLogDebug("Web setting add failed with %s", GetErrorMessage(r));
374
375
376         __pArticleReaderLabel = new Label();
377         __pArticleReaderLabel->Construct(Rectangle(__pArticleReaderPanel->GetX(),__pArticleReaderPanel->GetY(),__pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight()),L"");
378
379         __pBlankPanel->AddControl(*__pArticleReaderLabel);
380         __pBlankPanel->AddControl(*__pArticleReaderPanel);
381         AddControl(*__pBlankPanel);
382
383         __pBlankPanel->SetBounds(0,0,GetClientAreaBounds().width,GetClientAreaBounds().height);
384         __pArticleReaderPanel->SetBounds((GetClientAreaBounds().width - __pArticleReaderPanel->GetWidth())/2,(GetClientAreaBounds().height - __pArticleReaderPanel->GetHeight())/2, __pArticleReaderPanel->GetWidth(), __pArticleReaderPanel->GetHeight());
385         __pArticleReaderLabel->SetBounds(__pArticleReaderPanel->GetX(),__pArticleReaderPanel->GetY(),__pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight());
386
387         __pArticleReaderPanel->AddControl(*__pWebReader);
388         __pWebReader->SetBounds(Rectangle(2,2, __pArticleReaderPanel->GetWidth()-2,__pArticleReaderPanel->GetHeight() - 96 -2));
389         Bitmap* pBitmap = CommonUtil::GetNinepatchedBitmapN(L"I01_popup_bg.9.png",__pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight());
390         Bitmap* pSrcBitmap = CommonUtil::GetNinepatchedBitmapN(L"I01_popup_bottom_bg.9.png",__pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight());
391
392         if (pBitmap != null && pSrcBitmap != null)
393         {
394                 pBitmap->Merge(Point(0,__pArticleReaderPanel->GetHeight() - 96),*pSrcBitmap,Rectangle(0,0,pSrcBitmap->GetWidth(),pSrcBitmap->GetHeight()));
395         }
396         __pArticleReaderLabel->SetBackgroundBitmap(*pBitmap);
397
398         pSmallFontBtn =  static_cast<Button*>(__pArticleReaderPanel->GetControl(L"IDC_SMALL_FONT",true));
399         if (pSmallFontBtn)
400         {
401                 pSmallFontBtn->AddActionEventListener(*this);
402                 pSmallFontBtn->SetActionId(IDA_SMALLFONT_BTN_CLICKED);
403         }
404
405         pLargeFontBtn =  static_cast<Button*>(__pArticleReaderPanel->GetControl(L"IDC_LARGE_FONT",true));
406         if (pLargeFontBtn)
407         {
408                 pLargeFontBtn->AddActionEventListener(*this);
409                 pLargeFontBtn->SetActionId(IDA_LARGEFONT_BTN_CLICKED);
410         }
411
412
413         if (pBitmap != null)
414         {
415                 delete pBitmap;
416                 pBitmap = null;
417         }
418         if (pSrcBitmap != null)
419         {
420                 delete pSrcBitmap;
421                 pSrcBitmap = null;
422         }
423
424         SetControlAlwaysOnTop(*__pBlankPanel, true);
425         //__pBlankPanel->SetControlAlwaysAtBottom(*__pArticleReaderPanel, true);
426         Invalidate(true);
427
428         return E_SUCCESS;
429 }
430
431 result
432 MainForm::InitWebControl()
433 {
434         AppLogDebug("MainForm::InitWebControl enter");
435         result r = E_SUCCESS;
436         AppLogDebug("InitWebControl");
437
438         if (__pAddressbar == null || __pFooterPanel == null)
439                 return E_FAILURE;
440
441         const int Y_WEBCONTROL_POSITION = 0;
442         __webControlHeight = GetClientAreaBounds().height - __pFooterPanel->GetHeight();
443         if (__pMostVisitedListView)
444         {
445                 __pMostVisitedListView->SetShowState(false);
446         }
447         if (__pWebViewer != null)
448         {
449                 AppLogDebug("Already initialized");
450                 return E_SUCCESS;
451         }
452         __pWebViewer = new(std::nothrow) Web();
453         if(__pWebViewer == NULL)
454         {
455                 AppLogDebug("Initialization failed");
456                 return E_FAILURE;
457         }
458         r = __pWebViewer->Construct(Rectangle(0, Y_WEBCONTROL_POSITION, GetClientAreaBounds().width,__webControlHeight));
459
460         if (IsFailed(r))
461         {
462                 AppLogDebug("Web construct failed with %s", GetErrorMessage(r));
463                 delete __pWebViewer;
464                 __pWebViewer = null;
465                 return r;
466         }
467         else
468         {
469                 r = AddControl(*__pWebViewer);
470
471                 if (IsFailed(r))
472                 {
473                         delete __pWebViewer;
474                         __pWebViewer = null;
475                         AppLogDebug("Web addcontrol failed with %s", GetErrorMessage(r));
476                         return r;
477                 }
478                 __webControlPosition = __pWebViewer->GetPosition();
479                 r = __pWebViewer->SetSetting(SettingPresentationModel::GetInstance()->GetWebSettings());
480                 if (IsFailed(r))
481                 {
482                         AppLogDebug("Web setting add failed with %s", GetErrorMessage(r));
483                         return r;
484                 }
485
486                 __pWebViewer->SetLoadingListener(this);
487                 __pWebViewer->SetWebUiEventListener(this);
488                 __pWebViewer->SetWebKeypadEventListener(this);
489                 __pWebViewer->SetFocus();
490                 __pWebViewer->AddTouchEventListener(*this);
491
492                 __pWebViewer->SetCookieEnabled(SettingPresentationModel::GetInstance()->IsCookiesEnabled());
493                 __pWebViewer->SetTextSearchListener(this);
494         }
495
496         AppLogDebug("MainForm :before return");
497         Invalidate(true);
498         AppLogDebug("MainForm::InitWebControl Exit");
499
500         return r;
501 }
502
503 void
504 MainForm::OnFocusGained(const Control& source)
505 {
506         AppLog("MainForm::OnFocusGained");
507 }
508
509 void
510 MainForm::OnFocusLost(const Control& source)
511 {
512         AppLog("MainForm::OnFocusLost");
513 }
514
515 void
516 MainForm::SetJavascriptEnabled()
517 {
518         WebSetting settings = __pWebViewer->GetSetting();
519         settings.SetJavascriptEnabled(SettingPresentationModel::GetInstance()->IsRunJavascriptEnabled());
520         __pWebViewer->SetSetting(settings);
521 }
522
523 void
524 MainForm::SetImageLoadEnabled()
525 {
526         WebSetting settings = __pWebViewer->GetSetting();
527         settings.SetAutoImageLoadEnabled(SettingPresentationModel::GetInstance()->IsDisplayImagesEnabled());
528         __pWebViewer->SetSetting(settings);
529 }
530
531 result
532 MainForm::InitFooter(void)
533 {
534         AppLogDebug("MainForm::InitFooter entered");
535         Button* pBackButton = null;
536         Button* pBookmarkButton = null;
537         Button* pMultiWindowButton = null;
538         Bitmap *pIconBitmap = null;
539         Bitmap *pBGBitmap = null;
540         Label *pBGLabel = null;
541
542         if (__pFooterPanel == null)
543         {
544                 __pFooterPanel = static_cast< Panel* >(GetControl(L"IDC_FOOTER_PANEL", true));
545         }
546
547         if (__pFooterPanel == null)
548         {
549                 return E_FAILURE;
550         }
551
552         SetControlAlwaysOnTop(*__pFooterPanel, true);
553
554         __pFooterLabel = static_cast< Label* >(GetControl(L"IDC_FOOTER_LABEL", true));
555         if ( __pFooterLabel == NULL )
556         {
557                 return E_FAILURE;
558         }
559         //__pFooterPanel->SetBackgroundColor(CUSTOM_COLOR_TRANSPARENT);
560         Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_SEARCH_INPUT_FIELD_BG, __pFooterLabel->GetWidth(), __pFooterLabel->GetHeight());
561         if (pBitmap != null)
562         {
563                 __pFooterLabel->SetBackgroundBitmap(*pBitmap);
564                 delete pBitmap;
565         }
566
567         __pMultiWindowButton = static_cast< Button* >(GetControl(L"IDC_MULTIWINDOW_BUTTON", true));
568
569         if ( __pMultiWindowButton == NULL )
570         {
571                 return E_FAILURE;
572         }
573
574         __pMoreButton = static_cast<Button*>(GetControl(L"IDC_MORE_BUTTON",true));
575
576         if ( __pMoreButton == NULL )
577         {
578                 return E_FAILURE;
579         }
580
581         if (__pMultiWindowButton != null)
582         {
583                 Bitmap* pBitmap = null;
584                 Bitmap* pPressedBitmap = null;
585                 String imagePath = "I01_toolbar_icon_windows_manager_0";
586                 String pressedImagePath = "I01_toolbar_icon_windows_manager_0";
587                 int totalCount = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList()->GetCount();
588                 imagePath.Append(totalCount);
589                 imagePath.Append(".png");
590
591                 pressedImagePath.Append(totalCount);
592                 pressedImagePath.Append("_press.png");
593
594                 pBitmap = AppResource::GetInstance()->GetBitmapN(imagePath);
595                 pPressedBitmap = AppResource::GetInstance()->GetBitmapN(pressedImagePath);
596                 if ( pBitmap == null )
597                 {
598                         return E_FAILURE;
599                 }
600
601                 Point startPoint = Point((__pMultiWindowButton->GetWidth() - pBitmap->GetWidth())/2,(__pMultiWindowButton->GetHeight() - pBitmap->GetHeight())/2);
602                 if (pBitmap != null)
603                 {
604                         __pMultiWindowButton->SetNormalBitmap(startPoint, *pBitmap);
605                         __pMultiWindowButton->SetPressedBitmap(startPoint, *pPressedBitmap);
606
607                         delete pBitmap;
608                 }
609
610                 __pMultiWindowButton->AddActionEventListener(*this);
611                 __pMultiWindowButton->SetActionId(IDA_MULTIWINDOWBTN_CLICKED);
612         }
613
614         if (__pMoreButton)
615         {
616                 Bitmap* pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_CONTRLBAR_ICON_MORE);
617                 Bitmap* pPressedBitmap = AppResource::GetInstance()->GetBitmapN(IDB_CONTRLBAR_ICON_MORE_PRESS);
618                 if (pBitmap != null)
619                 {
620                         Point startPoint((__pMoreButton->GetWidth() - pBitmap->GetWidth())/2,(__pMoreButton->GetHeight() - pBitmap->GetHeight())/2 );
621                         __pMoreButton->SetNormalBitmap(startPoint, *pBitmap);
622                         __pMoreButton->SetPressedBitmap(startPoint, *pPressedBitmap);
623
624                         delete pBitmap;
625                 }
626                 __pMoreButton->AddActionEventListener(*this);
627                 __pMoreButton->SetActionId(IDA_MOREBTN_CLICKED);
628         }
629
630         //Add the editfield for url
631         __pFooterUrlField =  static_cast<EditField*> (GetControl(L"IDC_URL_EDIT_FIELD",true));
632         if (__pFooterUrlField == NULL)
633         {
634                 return E_INVALID_KEY;
635         }
636
637         __pFooterUrlField->SetOverlayKeypadCommandButtonVisible(false);
638         __pFooterUrlField->SetKeypadAction(KEYPAD_ACTION_GO);
639         //__pFooterUrlField->AddFocusEventListener(*this);
640         __pFooterUrlField->AddKeypadEventListener(*this);
641         //__pFooterUrlField->AddFocusEventListener(*this);
642         __pFooterUrlField->SetPropagatedTouchEventListener(this);
643
644         if (SettingPresentationModel::GetInstance()->GetHomepage().CompareTo((L"IDS_BR_BODY_MOST_VISITED_SITES")) == 0)
645         {
646                 __pFooterUrlField->SetGuideText(CommonUtil::GetString(L"IDS_BR_BODY_SEARCH_OR_ENTER_URL"));
647         }
648         else if (SettingPresentationModel::GetInstance()->GetHomepage().CompareTo((L"IDS_BR_BODY_BLANK_PAGE")) == 0)
649         {
650                 __pFooterUrlField->SetGuideText(CommonUtil::GetString(L"IDS_BR_BODY_ABOUT_C_BLANK"));
651         }
652         else
653         {
654                 //__pUrlField->SetText(SettingPresentationModel::GetInstance()->GetFavoriteURL());
655                 __pFooterUrlField->SetGuideText(CommonUtil::GetString(L"IDS_BR_BODY_SEARCH_OR_ENTER_URL"));
656         }
657
658
659         //Add the go Back Button
660         __pGoBackBtn = static_cast<Button*> (GetControl(L"IDC_PAGEBACK_BUTTON",true));
661         if (__pGoBackBtn == NULL)
662         {
663                 AppLogDebug("__pGoBackBtn Control not found returning E_INVALID_KEY");
664                 return E_INVALID_KEY;
665         }
666         __pGoBackBtn->SetActionId(IDA_GO_BACK);
667         __pGoBackBtn->AddActionEventListener(*this);
668
669         //Add the go forward Button
670         __pGoForwardBtn = static_cast<Button*> (GetControl(L"IDC_PAGEFORWARD_BUTTON",true));
671         if (__pGoForwardBtn == NULL)
672         {
673                 AppLogDebug("Control not found returning E_INVALID_KEY");
674                 return E_INVALID_KEY;
675         }
676         __pGoForwardBtn->SetActionId(IDA_GO_FORWARD);
677         __pGoForwardBtn->AddActionEventListener(*this);
678         __pGoForwardBtn->SetEnabled(false);
679
680         __pRefreshBtn = static_cast<Button*> (GetControl(L"IDC_REFRESH_BUTTON",true));
681         if (__pRefreshBtn == NULL)
682         {
683                 AppLogDebug("Control not found returning E_INVALID_KEY");
684                 return E_INVALID_KEY;
685         }
686
687         __pRefreshBtn->SetActionId(IDA_REFRESH_BTN_CLICKED);
688         __pRefreshBtn->AddActionEventListener(*this);
689         __pRefreshBtn->SetShowState(true);
690
691         //Add the backround label for displaying progressbar
692         __pProgressbarLabel = static_cast<Label*> (GetControl(L"IDC_PROGRESS_BAR_LABEL",true));
693         if (__pProgressbarLabel == NULL)
694         {
695                 AppLogDebug("__pProgressbarLabel Control not found returning E_INVALID_KEY");
696                 return E_INVALID_KEY;
697         }
698         __pProgressbarLabel->SetShowState(false);
699
700         __pStopBtn = static_cast<Button*> (GetControl(L"IDC_STOP_BUTTON",true));
701         if (__pStopBtn == NULL)
702         {
703                 AppLogDebug("Control not found returning E_INVALID_KEY");
704                 return E_INVALID_KEY;
705         }
706         __pStopBtn->SetActionId(IDA_STOP_BTN_CLICKED);
707         __pStopBtn->AddActionEventListener(*this);
708         __pStopBtn->SetShowState(false);
709
710         __pClearBtn = static_cast<Button*> (GetControl(L"IDC_CLEAR_BUTTON",true));
711         if (__pClearBtn == NULL)
712         {
713                 AppLogDebug("Control not found returning E_INVALID_KEY");
714                 return E_INVALID_KEY;
715         }
716         __pClearBtn->SetActionId(IDA_CLEAR_URL);
717         __pClearBtn->AddActionEventListener(*this);
718         __pClearBtn->SetShowState(false);
719
720         //      __pFooterPanel->Invalidate(true);
721         AppLogDebug("MainForm::InitFooter exit");
722         return E_SUCCESS;
723 }
724
725
726 result
727 MainForm::InitContextMenu(Point& p)
728 {
729         result r = E_SUCCESS;
730         bool isPrivateBrowsing = false;
731         Bitmap* pBitmap = null;
732
733         if (__pMenu != null)
734         {
735                 __pMenu->SetAnchorPosition(p);
736                 __pMenu->Invalidate(true);
737                 return r;
738         }
739
740         __pMenu = new(std::nothrow) ContextMenu();
741         r = __pMenu->Construct(p, CONTEXT_MENU_STYLE_LIST, CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD);
742         TryCatch(!IsFailed(r),,"Contextmenu creation failed with%s",GetErrorMessage(r));
743
744         isPrivateBrowsing = SettingPresentationModel::GetInstance()->GetPrivateOn();
745
746
747         if (isPrivateBrowsing == true)
748         {
749                 pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_BUTTON_ON);
750         }
751         else
752         {
753                 pBitmap  = AppResource::GetInstance()->GetBitmapN(IDB_BUTTON_OFF);
754         }
755
756         r = __pMenu->AddItem(CommonUtil::GetString(L"IDS_BR_OPT_BOOKMARK"), IDA_BOOKMARKBTN_CLICKED);
757
758         if ( pBitmap != NULL)
759         {
760                 __pMenu->AddItem(CommonUtil::GetString(L"IDS_BR_BODY_PRIVACY"), IDA_PRIVATEON_CLICKED,*pBitmap);
761                 delete pBitmap;
762         }
763         r = __pMenu->AddItem(CommonUtil::GetString(L"IDS_BR_TAB_HISTORY"), IDA_HISTORY_CLICKED);
764         r = __pMenu->AddItem(CommonUtil::GetString(L"IDS_COM_OPT_BRIGHTNESS"), IDA_BRIGHTNESS_BTN_CLICKED);
765         r = __pMenu->AddItem(CommonUtil::GetString(L"IDS_COM_BODY_SETTINGS"), IDA_SETTINGS_CLICKED);
766
767
768         __pMenu->SetMaxVisibleItemsCount(6);
769         __pMenu->SetShowState(false);
770         __pMenu->AddActionEventListener(*this);
771         SetControlAlwaysOnTop(*__pMenu, true);
772
773         CATCH:
774         return r;
775 }
776
777 result MainForm::InitImageContextMenu(Tizen::Graphics::Point p)
778 {
779         result r = E_SUCCESS;
780         ContextMenuAnchorDirection direction = CONTEXT_MENU_ANCHOR_DIRECTION_AUTO;
781
782         AppLog("MainForm::InitImageContextMenu clicked on image");
783         if (__pImageMenu != null)
784         {
785                 delete __pImageMenu;
786                 __pImageMenu = null;
787         }
788
789 //      p.y = p.y + __pAddressbar->GetHeight() + 12;
790 //      AppLog("vinaypy %d",p.y);
791 //      if(p.y < 100)
792 //      {
793 //              direction = CONTEXT_MENU_ANCHOR_DIRECTION_DOWNWARD;
794 //      }
795 //      else
796 //      {
797 //              direction = CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD;
798 //      }
799         __pImageMenu = new (std::nothrow) ContextMenu();
800         r = __pImageMenu->Construct(p, CONTEXT_MENU_STYLE_LIST, direction);
801         TryCatch(!IsFailed(r),, "Context image menu creation failed with%s",GetErrorMessage(r));
802
803         r = __pImageMenu->AddItem(CommonUtil::GetString(L"IDS_BR_OPT_COPY_IMAGE"),IDA_COPY_IMAGE_CLICKED);
804         r = __pImageMenu->AddItem(CommonUtil::GetString(L"IDS_BR_OPT_VIEW_IMAGE"),IDA_VIEW_IMAGE_CLICKED);
805         r = __pImageMenu->AddItem(CommonUtil::GetString(L"IDS_BR_OPT_SAVE_IMAGE"),IDA_SAVE_IMAGE_CLICKED);
806         r = __pImageMenu->AddItem(CommonUtil::GetString(L"IDS_DLNA_BODY_SHARE_IMAGE_ABB"),IDA_SHARE_IMAGE_CLICKED);
807         __pImageMenu->SetMaxVisibleItemsCount(4);
808         __pImageMenu->AddActionEventListener(*this);
809         SetControlAlwaysOnTop(*__pImageMenu, true);
810
811         CATCH: return r;
812 }
813
814 result
815 MainForm::InitImageLinkContextMenu(Tizen::Graphics::Point p)
816 {
817         result r = E_SUCCESS;
818         ContextMenuAnchorDirection direction = CONTEXT_MENU_ANCHOR_DIRECTION_AUTO;
819
820         AppLog("MainForm::InitImageContextMenu clicked on image");
821         if (__pImageMenu != null)
822         {
823                 delete __pImageMenu;
824                 __pImageMenu = null;
825         }
826
827         p.y = p.y + __pAddressbar->GetHeight() + 12;
828         if (p.y < 100)
829         {
830                 direction = CONTEXT_MENU_ANCHOR_DIRECTION_DOWNWARD;
831         }
832         else
833         {
834                 direction = CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD;
835         }
836         __pImageMenu = new (std::nothrow) ContextMenu();
837         r = __pImageMenu->Construct(p, CONTEXT_MENU_STYLE_LIST, direction);
838         TryCatch(!IsFailed(r),, "Context image menu creation failed with%s",GetErrorMessage(r));
839
840         r = __pImageMenu->AddItem("Open in new window"/*CommonUtil::GetString(L"IDS_BR_OPT_COPY_IMAGE")*/,IDA_HYPERLINK_OPEN_CLICKED);
841         r = __pImageMenu->AddItem("Copy link URL"/*CommonUtil::GetString(L"IDS_DLNA_BODY_SHARE_IMAGE_ABB")*/,IDA_HYPERLINK_COPY_LINK_CLICKED);
842         //r = __pImageMenu->AddItem(CommonUtil::GetString(L"IDS_BR_OPT_SAVE_IMAGE"),IDA_HYPERLINK_SAVE_IMAGE_CLICKED);
843         r = __pImageMenu->AddItem(CommonUtil::GetString(L"IDS_BR_OPT_SHARE"),IDA_HYPERLINK_SHARE_IMAGE_CLICKED);
844
845         __pImageMenu->SetMaxVisibleItemsCount(3);
846         __pImageMenu->AddActionEventListener(*this);
847         SetControlAlwaysOnTop(*__pImageMenu, true);
848
849         CATCH: return r;
850
851 }
852
853 result MainForm::InitSelectTextContextMenu(Tizen::Graphics::Point p, bool pasteOption, bool onlyPasteOption = false)
854 {
855         result r = E_SUCCESS;
856         ContextMenuAnchorDirection direction = CONTEXT_MENU_ANCHOR_DIRECTION_AUTO;
857         if(onlyPasteOption == true)
858                 return E_SUCCESS;
859
860         AppLog("MainForm::InitSelectTextContextMenu clicked on text");
861         if (__pImageMenu != null)
862         {
863                 delete __pImageMenu;
864                 __pImageMenu = null;
865         }
866 //      p.y = p.y + __pAddressbar->GetHeight() + 12;
867
868         if(p.y < 150)
869         {
870                 p.y = p.y + 50;
871                 direction = CONTEXT_MENU_ANCHOR_DIRECTION_DOWNWARD;
872         }
873         else
874         {
875 //              p.y = p.y - 100;
876                 direction = CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD;
877         }
878         __pImageMenu = new (std::nothrow) ContextMenu();
879         r = __pImageMenu->Construct(p, CONTEXT_MENU_STYLE_GRID, direction);
880         TryCatch(!IsFailed(r),, "Context image menu creation failed with%s",GetErrorMessage(r));
881
882         if(onlyPasteOption == false)
883         {
884                 r = __pImageMenu->AddItem(CommonUtil::GetString(L"IDS_COM_OPT_COPY"),IDA_COPY_TEXT_CLICKED);
885         }
886         if (pasteOption || onlyPasteOption)
887         {
888                 r = __pImageMenu->AddItem(CommonUtil::GetString(L"IDS_COM_BODY_PASTE"),IDA_PASTE_TEXT_CLICKED);
889         }
890         if(onlyPasteOption == false)
891         {
892                 r = __pImageMenu->AddItem(CommonUtil::GetString(L"IDS_BR_OPT_FIND_ON_PAGE_ABB"),IDA_FIND_TEXT__CLICKED);
893                 r = __pImageMenu->AddItem(CommonUtil::GetString(L"IDS_BR_OPT_SHARE"),IDA_SHARE_TEXT_CLICKED);
894         }
895
896         __pImageMenu->SetMaxVisibleItemsCount(3);
897         __pImageMenu->AddActionEventListener(*this);
898         SetControlAlwaysOnTop(*__pImageMenu, true);
899
900         CATCH: return r;
901
902 }
903
904 result
905 MainForm::InitFindWordPanel(void)
906 {
907         result r = E_SUCCESS;
908         Bitmap *pIconBitmap = null;
909
910         if (__pFindWordControl != null)
911         {
912                 AppLogDebug("Findword panel already initialized");
913                 if (__pFindWordBgLabel != null)
914                 {
915                         Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_FINDWORD_INPUT_FIELD_BG, __pFindWordBgLabel->GetWidth(), __pFindWordBgLabel->GetHeight());
916                         if (pBitmap != null)
917                         {
918                                 __pFindWordBgLabel->SetBackgroundBitmap(*pBitmap);
919                                 delete pBitmap;
920                         }
921                 }
922                 return r;
923         }
924
925         __pFindWordControl = new (std::nothrow) Panel();
926         r = __pFindWordControl->Construct(L"IDL_FIND_ON_PAGE");
927         if (IsFailed(r))
928         {
929                 AppLogException("There is some problem in the xml file. Please check.");
930                 return E_FAILURE;
931         }
932         AddControl(*__pFindWordControl);
933         __pFindWordControl->SetBounds(0,0, __pFindWordControl->GetWidth(), __pFindWordControl->GetHeight());
934         SetControlAlwaysOnTop(*__pFindWordControl,true);
935         __pFindWordControl->SetShowState(false);
936         __pFindWordControl->Invalidate(false);
937
938         __pFindWordBgLabel = static_cast<Label*>(__pFindWordControl->GetControl(L"IDC_LABEL1", true));
939         if (__pFindWordBgLabel != null)
940         {
941                 Panel* pPanel1 = static_cast<Panel*>(__pFindWordControl->GetControl(L"IDC_PANEL1", true));
942                 Rectangle pRect = pPanel1->GetBounds();
943                 pRect.x = pRect.y = 0;
944                 __pFindWordBgLabel->SetBounds(pRect);
945                 Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(L"I01_search_input_field_bg.9.png", __pFindWordBgLabel->GetWidth(), __pFindWordBgLabel->GetHeight());
946                 if (pBitmap != null)
947                 {
948                         AppLogDebug("InitFindWordPanel: Coming here");
949                         __pFindWordBgLabel->SetBackgroundBitmap(*pBitmap);
950                         delete pBitmap;
951                 }
952                 else
953                 {
954                         AppLogDebug("InitFindWordPanel: shouldn't Come here");
955                 }
956         }
957
958         Button* pfindWordCancel = null;
959         pfindWordCancel = static_cast<Button*>(__pFindWordControl->GetControl(L"IDC_FIND_CANCEL", true));
960         if (pfindWordCancel == null)
961         {
962                 AppLogException("There is some problem in the xml file. Please check.");
963                 return E_FAILURE;
964         }
965         pfindWordCancel->SetActionId(IDA_FINDWORD_CANCEL_CLICKED);
966         pfindWordCancel->AddActionEventListener(*this);
967
968         __pFindWordClear = static_cast<Button*>(__pFindWordControl->GetControl(L"IDC_FIND_CLEAR", true));
969         if (__pFindWordClear == null)
970         {
971                 AppLogException("There is some problem in the xml file. Please check.");
972                 return E_FAILURE;
973         }
974
975         __pFindWordClear->SetActionId(IDA_FINDWORD_CLEAR_CLICKED);
976         __pFindWordClear->AddActionEventListener(*this);
977
978         __pFindWordNext = static_cast<Button*>(__pFindWordControl->GetControl(L"IDC_FIND_NEXT", true));
979         if (__pFindWordNext == null)
980         {
981                 AppLogException("There is some problem in the xml file. Please check.");
982                 return E_FAILURE;
983         }
984
985         __pFindWordNext->SetActionId(IDA_FINDWORD_NEXT_CLICKED);
986         __pFindWordNext->AddActionEventListener(*this);
987
988         __pFindWordPrev = static_cast<Button*>(__pFindWordControl->GetControl(L"IDC_FIND_PREV", true));
989         if (__pFindWordPrev == null)
990         {
991                 AppLogException("There is some problem in the xml file. Please check.");
992                 return E_FAILURE;
993         }
994
995         __pFindWordPrev->SetActionId(IDA_FINDWORD_PREV_CLICKED);
996         __pFindWordPrev->AddActionEventListener(*this);
997
998         __pFindWordNext->SetEnabled(false);
999         __pFindWordPrev->SetEnabled(false);
1000
1001         __pFindWordCountLabel = static_cast<Label*>(__pFindWordControl->GetControl(L"IDC_FIND_COUNT_LABEL", true));
1002         if (__pFindWordCountLabel == null)
1003         {
1004                 AppLogException("There is some problem in the xml file. Please check.");
1005                 return E_FAILURE;
1006         }
1007
1008         __pFindWordEditField = static_cast<EditField*>(__pFindWordControl->GetControl(L"IDC_FIND_WORD_EDITFIELD", true));
1009         if (__pFindWordEditField == null)
1010         {
1011                 AppLogException("There is some problem in the xml file. Please check.");
1012                 return E_FAILURE;
1013         }
1014         __pFindWordEditField->AddTextEventListener(*this);
1015         __pFindWordEditField->AddKeypadEventListener(*this);
1016         __pFindWordEditField->SetOverlayKeypadCommandButtonVisible(false);
1017
1018         return r;
1019 }
1020
1021 ListItemBase*
1022 MainForm::CreateItem (int index, int itemWidth)
1023 {
1024         Rectangle listImageRect;
1025         Rectangle pagetTitleRect;
1026         Rectangle pageURLRect;
1027         Rectangle deleteImageRect;
1028         String pageTitle(L"");
1029         String pageURL(L"");
1030         result r = E_SUCCESS;
1031         Bitmap* pListIconImage = null;
1032
1033
1034         History* pHistory = static_cast < History* >(__pMostVisitedSites->GetAt(index));
1035         if(pHistory == null)
1036         {
1037                 return null;
1038         }
1039         AppResource* pAppResource = Application::GetInstance()->GetAppResource();
1040         if ( pAppResource == NULL )
1041         {
1042                 return null;
1043         }
1044         ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
1045
1046         CustomItem* pItem = new(std::nothrow) CustomItem();
1047         pageTitle = pHistory->GetHistoryTitle();
1048         pageURL = pHistory->GetHistoryUrl();
1049
1050         if (pageURL.GetLength() == 0)
1051         {
1052                 String nourl;
1053                 pAppResource->GetString(L"IDS_BR_BODY_ABOUT_C_BLANK", nourl);
1054                 pageURL = L"<"+ nourl +">";
1055
1056         }
1057
1058         Rectangle screenBounds = GetBounds();
1059         if (pItem != null)
1060         {
1061                 r = pItem->Construct(Dimension(itemWidth, 128), style);
1062         }
1063         if (IsFailed(r))
1064         {
1065                 delete pItem;
1066                 return NULL;
1067         }
1068
1069
1070         Bitmap* pBitmap = pHistory->GetFavIconBitmap();
1071
1072         if ( pBitmap != NULL)
1073         {
1074                 pListIconImage = new Bitmap();
1075                 pListIconImage->Construct(*pBitmap,Rectangle(0,0,pBitmap->GetWidth(),pBitmap->GetHeight()));
1076                 delete pBitmap;
1077         }
1078
1079         if(pListIconImage == null)
1080         {
1081                 pListIconImage = pAppResource->GetBitmapN(L"I01_icon_default_favicon.png");
1082         }
1083
1084         if ( pListIconImage != NULL)
1085         {
1086                 listImageRect.SetBounds(screenBounds.x + 16, screenBounds.y + 28,72, 72);
1087                 pagetTitleRect.SetBounds(listImageRect.x + 72 + 16,10, screenBounds.width - 2 * pListIconImage->GetWidth() - 120, 60);
1088                 pageURLRect.SetBounds(pagetTitleRect.x, pagetTitleRect.y + pagetTitleRect.height, screenBounds.width - 2 * pListIconImage->GetWidth() - 120, 48);
1089
1090
1091                 if (pItem != null && pListIconImage != NULL)
1092                 {
1093                         pItem->AddElement(listImageRect, IDA_FORMAT_BITMAP, *pListIconImage, null, null);
1094                 }
1095         }
1096
1097         if (pageTitle.CompareTo(L"") != 0)
1098         {
1099                 if (pItem != null)
1100                 {
1101                         pItem->AddElement(pagetTitleRect, IDA_FORMAT_TITLE_STRING, pageTitle, 44, CUSTOM_COLOR_TRANSPARENT, CUSTOM_COLOR_TRANSPARENT, CUSTOM_COLOR_TRANSPARENT, true);
1102                 }
1103         }
1104
1105         if (pageURL.CompareTo(L"") != 0)
1106         {
1107                 if (pItem != null)
1108                 {
1109                         pItem->AddElement(pageURLRect, IDA_FORMAT_URL_STRING, pageURL, 32, CUSTOM_COLOR_GREY, CUSTOM_COLOR_GREY, CUSTOM_COLOR_GREY, true);
1110                 }
1111         }
1112
1113
1114         if(GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT || GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT_REVERSE)
1115         {
1116                 if ( __pItemContext!= NULL)
1117                 {
1118                         if (pItem != null)
1119                         {
1120                                 pItem->SetContextItem(__pItemContext);
1121                         }
1122                 }
1123         }
1124         else
1125         {
1126                 if ( __pItemContextLandscape!= NULL)
1127                 {
1128                         if (pItem != null)
1129                         {
1130                                 pItem->SetContextItem(__pItemContextLandscape);
1131                         }
1132                 }
1133         }
1134         if( pListIconImage != NULL)
1135         {
1136                 delete pListIconImage;
1137                 pListIconImage = null;
1138         }
1139
1140         return pItem;
1141 }
1142
1143 bool
1144 MainForm::DeleteItem (int index, Tizen::Ui::Controls::ListItemBase *pItem, int itemWidth)
1145 {
1146         delete pItem;
1147         return true;
1148 }
1149
1150 int
1151 MainForm::GetItemCount (void)
1152 {
1153         if(__pMostVisitedSites != null)
1154         {
1155                 __pMostVisitedSites->RemoveAll(true);
1156         }
1157         HistoryPresentationModel::GetInstance()->GetMostVisitedSites(*__pMostVisitedSites);
1158         if(__pMostVisitedSites != null)
1159         {
1160                 return __pMostVisitedSites->GetCount();
1161         }
1162         else
1163                 return 0;
1164 }
1165
1166 void
1167 MainForm::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state)
1168 {
1169         History* pHistory = static_cast < History* >(__pMostVisitedSites->GetAt(index));
1170         String url = pHistory->GetHistoryUrl();
1171         HistoryPresentationModel::GetInstance()->DeleteHistory(url);
1172         __pMostVisitedListView->UpdateList();
1173 }
1174
1175 void
1176 MainForm::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
1177 {
1178         History* pHistory = static_cast < History* >(__pMostVisitedSites->GetAt(index));
1179         String url = pHistory->GetHistoryUrl();
1180         if (url != null)
1181         {
1182                 LoadUrl(url);
1183         }
1184 }
1185
1186 void
1187 MainForm::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction)
1188 {
1189
1190 }
1191
1192 result
1193 MainForm::OnTerminating(void)
1194 {
1195         result r = E_SUCCESS;
1196         if(__pItemContext)
1197         {
1198                 delete __pItemContext;
1199         }
1200         if(__pItemContextLandscape)
1201         {
1202                 delete __pItemContextLandscape;
1203         }
1204         return r;
1205 }
1206
1207 void
1208 MainForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
1209 {
1210         result r = E_SUCCESS;
1211
1212         AppLogDebug("Clicked : %d", actionId);
1213         switch (actionId)
1214         {
1215 //      case IDA_BACKBTN_CLICKED:
1216 //      {
1217 //              if (__pWebViewer && __pWebViewer->CanGoBack())
1218 //              {
1219 //                      __pWebViewer->GoBack();
1220 //              }
1221 //              else
1222 //              {
1223 //                      UiApp* pApp = null;
1224 //                      pApp = UiApp::GetInstance();
1225 //                      if (pApp != null)
1226 //                      {
1227 //                              r = pApp->Terminate();
1228 //                              if (IsFailed(r))
1229 //                              {
1230 //                                      AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
1231 //                                      return;
1232 //                              }
1233 //                      }
1234 //              }
1235 //      }
1236 //      break;
1237
1238         case IDA_BACKBTN_CLICKED:
1239                 {
1240                         if (__pWebViewer && __pWebViewer->CanGoBack())
1241                         {
1242                                 __pWebViewer->GoBack();
1243                         }
1244                         else if(__pWindowInfo->isJavascriptInitiated == false)
1245                         {
1246                                 UiApp* pApp = null;
1247                                 pApp = UiApp::GetInstance();
1248                                 if (pApp != null)
1249                                 {
1250                                         r = pApp->Terminate();
1251                                         if (IsFailed(r))
1252                                         {
1253                                                 AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
1254                                                 return;
1255                                         }
1256                                 }
1257                         }
1258                         else
1259                         {
1260                                 UiApp* pApp = null;
1261                                 WindowInfo* pWindowInfo = null;
1262                                 int totalCount = 0;
1263                                 SceneManager* pSceneManager = SceneManager::GetInstance();
1264                                 if (pSceneManager == null)
1265                                 {
1266                                         return;
1267                                 }
1268                                 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
1269                                 if (pAllWindowList == NULL)
1270                                 {
1271                                         pApp = UiApp::GetInstance();
1272                                         if (pApp != null)
1273                                         {
1274                                                 r = pApp->Terminate();
1275                                                 if (IsFailed(r))
1276                                                 {
1277                                                         AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
1278                                                         return;
1279                                                 }
1280                                         }
1281                                 }
1282                                 if (pAllWindowList != null)
1283                                 {
1284                                         totalCount = pAllWindowList->GetCount();
1285                                 }
1286                                 for (int count = 0; count < totalCount; count++)
1287                                 {
1288                                         pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count));
1289                                         if (pWindowInfo == null)
1290                                         {
1291                                                 pApp = UiApp::GetInstance();
1292                                                 if (pApp != null)
1293                                                 {
1294                                                         r = pApp->Terminate();
1295                                                         if (IsFailed(r))
1296                                                         {
1297                                                                 AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
1298                                                                 return;
1299                                                         }
1300                                                 }
1301                                         }
1302                                         if (pSceneManager->GetCurrentSceneId() == pWindowInfo->sceneID && pWindowInfo->isJavascriptInitiated == true)
1303                                         {
1304                                                 r = SceneRegister::DestroyAndUnRegisterScene(pWindowInfo->sceneID);
1305                                                 if (IsFailed(r))
1306                                                 {
1307                                                         AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
1308                                                         return;
1309                                                 }
1310                                                 r = pAllWindowList->RemoveAt(count, true);
1311                                                 __pWindowInfo = null;
1312                                                 if (IsFailed(r))
1313                                                 {
1314                                                         AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
1315                                                         return;
1316                                                 }
1317                                                 if(count > 0)
1318                                                 {
1319                                                         pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count - 1));
1320                                                 }
1321                                                 else
1322                                                 {
1323                                                         pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(pAllWindowList->GetCount() - 1));
1324                                                 }
1325                                                 if (pWindowInfo == null)
1326                                                 {
1327                                                         pApp = UiApp::GetInstance();
1328                                                         if (pApp != null)
1329                                                         {
1330                                                                 r = pApp->Terminate();
1331                                                                 return;
1332                                                         }
1333                                                 }
1334                                                 else
1335                                                 {
1336                                                         r = pSceneManager->GoBackward(BackwardSceneTransition(pWindowInfo->sceneID ,SCENE_TRANSITION_ANIMATION_TYPE_NONE));
1337                                                         if (IsFailed(r))
1338                                                         {
1339                                                                 AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
1340                                                                 return;
1341                                                         }
1342                                                 }
1343                                                 break;
1344                                         }
1345
1346                                 }
1347
1348                         }
1349                 }
1350                 break;
1351
1352         case IDA_FORWARD_CLICKED:
1353                 if (__pWebViewer == null)
1354                         return;
1355
1356                 if (__pWebViewer->CanGoForward())
1357                 {
1358                         __pWebViewer->GoForward();
1359                 }
1360                 __pMenu->SetShowState(false);
1361                 __pMenu->Invalidate(false);
1362                 break;
1363
1364         case IDA_FINDONPAGE_CLICKED:
1365         {
1366                 AppLogDebug("MainForm::OnActionPerformed findword clicked");
1367                 __currentSearchStr.Clear();
1368
1369                 InitFindWordPanel();
1370                 __pMenu->SetShowState(false);
1371                 __pMenu->Invalidate(false);
1372
1373                 __pFindWordEditField->SetFocus();
1374                 /*
1375                 if (__pWebViewer != null)
1376                 {
1377                         // releasing the set block
1378                         __pWebViewer->ReleaseBlock();
1379                 }
1380                 */
1381                 ShowFindWordPanel(true);
1382         }
1383         break;
1384         case IDA_PRIVATEON_CLICKED:
1385         {
1386                 result r = E_SUCCESS;
1387                 int itemIndex = 0;
1388                 bool isPrivateBrowsing = SettingPresentationModel::GetInstance()->GetPrivateOn();
1389                 Bitmap* pBitmap = null;
1390                 if (isPrivateBrowsing == true)
1391                 {
1392                         pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_BUTTON_OFF);
1393                         if (IsFailed(r))
1394                         {
1395                                 AppLogException("Contextmenu additem:Find on page failed with %s", GetErrorMessage(r));
1396                                 return ;
1397                         }
1398
1399                         if (__pWebViewer != NULL)
1400                         {
1401                                 __pWebViewer->SetPrivateBrowsingEnabled(false);
1402                         }
1403
1404                         SettingPresentationModel::GetInstance()->SetPrivateOn(false);
1405
1406                         if (__pAddressbar != null)
1407                         {
1408                                 __pAddressbar->UpdateFaviconBitmap(false);
1409                         }
1410
1411                 }
1412                 else
1413                 {
1414                         pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_BUTTON_ON);
1415                         if (IsFailed(r))
1416                         {
1417                                 AppLogException("Contextmenu additem:Find on page failed with %s", GetErrorMessage(r));
1418                                 return ;
1419                         }
1420
1421                         if (__pWebViewer != NULL)
1422                         {
1423                                 __pWebViewer->SetPrivateBrowsingEnabled(true);
1424                         }
1425
1426                         SettingPresentationModel::GetInstance()->SetPrivateOn(true);
1427
1428                         if (__pAddressbar != null)
1429                         {
1430                                 __pAddressbar->UpdateFaviconBitmap(true);
1431                         }
1432                 }
1433
1434
1435                 itemIndex = __pMenu->GetItemIndexFromActionId(IDA_PRIVATEON_CLICKED);
1436                 r = __pMenu->SetItemAt(itemIndex,CommonUtil::GetString(L"IDS_BR_BODY_PRIVACY"),IDA_PRIVATEON_CLICKED,*pBitmap);
1437                 AppLog("Result:: %s for index = %d", GetErrorMessage(r),itemIndex);
1438                 __pMenu->Invalidate(true);
1439
1440                 if ( pBitmap != NULL )
1441                 {
1442                         delete pBitmap;
1443                 }
1444
1445         }
1446         break;
1447         case IDA_SETTINGS_CLICKED:
1448         {
1449
1450                 ArrayList* pArgList = new(std::nothrow) ArrayList();
1451                 if (pArgList)
1452                 {
1453                         pArgList->Construct();
1454                         pArgList->Add(*__pWindowInfo);
1455                         SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_SETTINGS), pArgList);
1456                 }
1457                 __pMenu->SetShowState(false);
1458                 __pMenu->Invalidate(false);
1459                 if (pArgList != null)
1460                 {
1461                         delete pArgList;
1462                         pArgList = null;
1463                 }
1464
1465         }
1466         break;
1467
1468         case IDA_ADDTOBOOKMARK_CLICKED:
1469         {
1470
1471                 if (__pWindowInfo != NULL && __pWindowInfo->pageUrl != NULL)
1472                 {
1473                         int bookmarkCount=0;
1474                         bool exist = false;
1475                         String url=L"";
1476                         url=__pWindowInfo->pageUrl;
1477                         result r = E_SUCCESS;
1478                         Bitmap* pBitmap = null;
1479                         r=BookmarkPresentationModel::GetInstance()->DoesBookmarkExist(url,exist);
1480
1481                         if (IsFailed(r))
1482                         {
1483                                 return;
1484                         }
1485                         if ( exist == true)
1486                         {
1487                                 String message = CommonUtil::GetString(L"IDS_BR_POP_BOOKMARK_REMOVED");
1488                                 BookmarkPresentationModel::GetInstance()->DeleteBookmark(url);
1489                                 pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ICON_BOOKMARK_OFF_TEMP);
1490
1491                                 NotificationPanel* pNotification = new (std::nothrow) NotificationPanel(*this);
1492                                 if (pNotification != null)
1493                                 {
1494                                         pNotification->SetText(message);
1495                                         pNotification->SetPositionDiff(__pFooterPanel->GetHeight());
1496                                         pNotification->ShowNotification();
1497                                 }
1498                         }
1499                         else
1500                         {
1501                                 String title=__pWindowInfo->pageTitle;
1502                                 String message = CommonUtil::GetString(L"IDS_BR_POP_BOOKMARK_ADDED");
1503                                 BookmarkData* pBookmark=new (std::nothrow) BookmarkData();
1504
1505                                 pBookmark->SetBookmarkTitle(title);
1506                                 pBookmark->SetUrl(url);
1507                                 if (__pWebViewer != null && __pWebViewer->GetFaviconN() != null)
1508                                 {
1509                                         pBookmark->SetFavIconBitmap(*(__pWebViewer->GetFaviconN()));
1510                                 }
1511                                 String id = FaviconManager::GetInstance()->SaveFavicon(*__pWindowInfo->pFavicon, __pWindowInfo->faviconUrl);
1512                                 pBookmark->SetFaviconId(id);
1513                                 //r = BookmarkPresentationModel::GetInstance()->SaveBookmark(*pBookmark);
1514                                 r = BookmarkPresentationModel::GetInstance()->SaveTempBookmark(*pBookmark);
1515                                 delete pBookmark;
1516
1517                                 NotificationPanel* pNotification = new (std::nothrow) NotificationPanel(*this);
1518                                 if (pNotification != null)
1519                                 {
1520                                         pNotification->SetText(message);
1521                                         pNotification->SetPositionDiff(__pFooterPanel->GetHeight());
1522                                         pNotification->ShowNotification();
1523                                         pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ICON_BOOKMARK_ON_TEMP);
1524                                 }
1525                         }
1526                         if (pBitmap != null)
1527                         {
1528                                 r = __pMenu->SetItemAt(0,CommonUtil::GetString(L"IDS_BR_OPT_ADDTOBOOKMARKS"), IDA_ADDTOBOOKMARK_CLICKED,*pBitmap);
1529                                 delete pBitmap;
1530                         }
1531                 }
1532                 __pMenu->Invalidate(true);
1533
1534         }
1535         break;
1536         case IDA_SHARE_CLICKED:
1537         {
1538                 if(__pPopUp != null)
1539                 {
1540                         delete __pPopUp;
1541                         __pPopUp = null;
1542                 }
1543                 __pPopUp = new(std::nothrow) SharePopup();
1544                 __pPopUp->Initialize();
1545                 if (__pWindowInfo != null)
1546                 {
1547                         ShareInfo* pShareInfo = new(std::nothrow) ShareInfo();
1548                         pShareInfo->SetPageTitle(__pWindowInfo->pageTitle);
1549                         pShareInfo->SetPageUrl(__pWindowInfo->pageUrl);
1550                         pShareInfo->SetImageAttached(false);
1551                         __pPopUp->RemoveAllShareInfo();
1552                         __pPopUp->AddShareInfo(pShareInfo);
1553                 }
1554                 __pPopUp->SetShowState(true);
1555                 __pPopUp->Show();
1556         }
1557         break;
1558         case IDA_BOOKMARKBTN_CLICKED:
1559         {
1560                 AppLogDebug("ONACTION_PERFORMED:IDA_BOOKMARKBTN_CLICKED");
1561                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_BOOKMARK_VIEW, SCENE_TRANSITION_ANIMATION_TYPE_NONE));
1562         }
1563         break;
1564         case IDA_ADD_TO_BOOKMARKBTN_CLICKED:
1565         {
1566
1567         }
1568         break;
1569         case IDA_MOREBTN_CLICKED:
1570         {
1571                 AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED 1");
1572                 Point p = Point(__pMoreButton->GetX() + __pMoreButton->GetWidth() / 2, GetClientAreaBounds().y + GetClientAreaBounds().height - __pMoreButton->GetHeight());
1573                 AppLog("Anchot pos: %d %d", p.x, p.y);
1574                 InitContextMenu(p);
1575                 if (__pWindowInfo != NULL && __pWindowInfo->pageUrl != NULL && __pWebViewer->GetShowState() == true)
1576                 {
1577                         AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED 2");
1578                         int bookmarkCount=0;
1579                         bool exist = false;
1580                         String url=L"";
1581                         url=__pWindowInfo->pageUrl;
1582                         result r = E_SUCCESS;
1583                         Bitmap* pBitmap = null;
1584
1585                         r=BookmarkPresentationModel::GetInstance()->DoesBookmarkExist(url,exist);
1586                         if (IsFailed(r))
1587                         {
1588                                 AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED failed");
1589                                 return;
1590                         }
1591                         if ( exist == true)
1592                         {
1593                                 pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ICON_BOOKMARK_ON_TEMP);
1594                         }
1595                         else
1596                         {
1597                                 pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ICON_BOOKMARK_OFF_TEMP);
1598                         }
1599                         AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED 3");
1600
1601                         if (__pMenu->GetItemCount() == 8)
1602                         {
1603                                 r = __pMenu->SetItemAt(1,CommonUtil::GetString(L"IDS_BR_OPT_ADDTOBOOKMARKS"), IDA_ADDTOBOOKMARK_CLICKED,*pBitmap);
1604                         }
1605                         else
1606                         {
1607                                 r = __pMenu->InsertItemAt(1,CommonUtil::GetString(L"IDS_BR_OPT_ADDTOBOOKMARKS"), IDA_ADDTOBOOKMARK_CLICKED,*pBitmap);
1608                         }
1609
1610                         if (IsFailed(r))
1611                         {
1612                                 AppLogException("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED Add to Bookmark failed with %s", GetErrorMessage(r));
1613                                 delete pBitmap;
1614                                 return ;
1615                         }
1616                         AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED 4");
1617                         if (__pMenu->GetItemCount() != 8)
1618                         {
1619                                 __pMenu->InsertItemAt(1,CommonUtil::GetString(L"IDS_BR_OPT_ADDTOBOOKMARKS"), IDA_ADDTOBOOKMARK_CLICKED);
1620
1621 //                              __pMenu->InsertItemAt(2,L"Add to Home"/*CommonUtil::GetString(L"IDS_BR_OPT_SHARE")*/, IDA_ADD_TO_HOME_CLICKED);
1622                                 __pMenu->InsertItemAt(2,CommonUtil::GetString(L"IDS_BR_OPT_SHARE"), IDA_SHARE_CLICKED);
1623                                 __pMenu->InsertItemAt(3,CommonUtil::GetString(L"IDS_BR_OPT_FIND_ON_PAGE_ABB"), IDA_FINDONPAGE_CLICKED);
1624                                 __pMenu->SetMaxVisibleItemsCount(6);
1625                         }
1626                         if( GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE)
1627                         {
1628                                 AppLog(" Orientation landscape");
1629                                 __pMenu->SetMaxVisibleItemsCount(5);
1630                         }
1631                         else
1632                         {
1633                                 AppLog(" Orientation potrait");
1634                                 __pMenu->SetMaxVisibleItemsCount(6);
1635                         }
1636
1637                         AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED 5");
1638                         delete pBitmap;
1639                 }
1640                 AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED end");
1641                 __pMenu->SetShowState(true);
1642                 __pMenu->Invalidate(true);
1643                 __pMenu->Show();
1644         }
1645         break;
1646         case IDA_HISTORY_CLICKED:
1647         {
1648                 AppLogDebug("ONACTION_PERFORMED:IDA_HISTORYBTN_CLICKED");
1649                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_HISTORY_LIST, SCENE_TRANSITION_ANIMATION_TYPE_NONE));
1650         }
1651         break;
1652         case IDA_SAVED_PAGES_CLICKED:
1653         {
1654
1655         }
1656         break;
1657         case IDA_DESKTOP_VIEW_CLICKED:
1658         {
1659
1660         }
1661         break;
1662         case IDA_SAVE_CLICKED:
1663         {
1664
1665         }
1666         break;
1667         case IDA_MULTIWINDOWBTN_CLICKED:
1668         {
1669                 result r = SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_MULTIPLE_WINDOW, SCENE_TRANSITION_ANIMATION_TYPE_NONE));
1670                 AppLog("IDA_MULTIWINDOWBTN_CLICKED result %s",GetErrorMessage(r));
1671         }
1672         break;
1673
1674         case IDA_NEWWINDOWBTN_CLICKED:
1675         {
1676                 WindowInfo* pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewScene();
1677
1678                 if (pNewWindowInfo == null)
1679                 {
1680                         return;
1681                 }
1682                 result r = E_SUCCESS;
1683                 SceneManager* pSceneManager = SceneManager::GetInstance();
1684
1685                 if (pSceneManager == NULL)
1686                 {
1687                         return;
1688                 }
1689                 ArrayList* pArgList = new(std::nothrow) ArrayList();
1690                 if (pArgList == NULL)
1691                 {
1692                         return;
1693                 }
1694                 r = pArgList->Construct();
1695                 if (r == E_SUCCESS)
1696                 {
1697                         pArgList->Add(*pNewWindowInfo);
1698                         r = pSceneManager->GoForward(ForwardSceneTransition(pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
1699                 } 
1700                 delete pArgList;
1701                 pArgList = null;
1702                 if (IsFailed(r))
1703                 {
1704                         AppLogDebug("MainForm::OnActionPerformed Failed to GoBackward %s",GetErrorMessage(r));
1705                         return;
1706                 }
1707         }
1708         break;
1709         case IDA_SMALLFONT_BTN_CLICKED:
1710         {
1711                 WebSetting setting = __pWebReader->GetSetting();
1712                 setting.SetFontSize(15);
1713                 __pWebReader->SetSetting(setting);
1714         }
1715         break;
1716         case IDA_LARGEFONT_BTN_CLICKED:
1717         {
1718                 WebSetting setting = __pWebReader->GetSetting();
1719                 setting.SetFontSize(25);
1720                 __pWebReader->SetSetting(setting);
1721         }
1722         break;
1723         case IDA_READER_CLOSE_CLICKED:
1724         {
1725                 if (__pArticleReaderPanel != null && __pBlankPanel != null)
1726                 {
1727                         //__pArticleReaderPanel->SetShowState(false);
1728                         //__pArticleReaderPanel->Show();
1729                         RemoveControl(*__pBlankPanel);
1730                         //RemoveControl(*__pArticleReaderPanel);
1731                         __pArticleReaderPanel = null;
1732                         __pBlankPanel = null;
1733                         __pArticleReaderLabel = null;
1734                 }
1735                 //if (__pAddressbar)
1736                 //      __pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
1737                 SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
1738         }
1739         break;
1740         case IDA_FINDWORD_CANCEL_CLICKED:
1741         {
1742                 __currentSearchStr = L"";
1743                 __currentWordIndex = 0;
1744                 __maxOccurrances = 0;
1745                 __pFindWordEditField->SetText(L"");
1746                 __pFindWordNext->SetEnabled(false);
1747                 __pFindWordPrev->SetEnabled(false);
1748                 __pFindWordCountLabel->SetText(L"0/0");
1749                 __pWebViewer->SearchText(L"aaaabbbbcccc",true);
1750                 ShowFindWordPanel(false);
1751         }
1752         break;
1753         case IDA_FINDWORD_SEARCH_CLICKED:
1754         {
1755                 __currentSearchStr = __pFindWordEditField->GetText();
1756                 if (__currentSearchStr.GetLength() > 0)
1757                 {
1758                         StartWordSearch();
1759                 }
1760                 else
1761                 {
1762                         AppLogDebug("Enter something");
1763                 }
1764         }
1765         break;
1766         case IDA_FINDWORD_CLEAR_CLICKED:
1767         {
1768                 __pFindWordCountLabel->SetText(L"0/0");
1769                 __pFindWordEditField->SetText(L"");
1770                 __currentSearchStr = L"aaaaaabbbbbbccccccc";
1771                 StartWordSearch();
1772                 __currentSearchStr = L"";
1773                 __pFindWordNext->SetEnabled(false);
1774                 __pFindWordPrev->SetEnabled(false);
1775                 __pFindWordControl->Invalidate(true);
1776         }
1777         break;
1778         case IDA_FINDWORD_NEXT_CLICKED:
1779         {
1780                 FindNextWord(true);
1781         }
1782         break;
1783         case IDA_FINDWORD_PREV_CLICKED:
1784         {
1785                 FindNextWord(false);
1786         }
1787         break;
1788         case IDA_BRIGHTNESS_BTN_CLICKED:
1789         {
1790                 AppLogDebug("IDA_BRIGHTNESS_BTN_CLICKED");
1791                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_BRIGHTNESS, SCENE_TRANSITION_ANIMATION_TYPE_NONE));
1792         }
1793         break;
1794         case IDA_COPY_IMAGE_CLICKED:
1795         {
1796                 AppLogDebug("IDA_COPY_IMAGE_CLICKED");
1797                 AppLogDebug("IDA_COPY_IMAGE_CLICKED");
1798                 ClipboardItem item;
1799                 const Bitmap* pBitmap = null;
1800                 if (__pHitElementResult != null)
1801                 {
1802                         pBitmap = __pHitElementResult->GetImage();
1803                 }
1804
1805                 String resourcePath = App::GetInstance()->GetAppResourcePath();
1806                 item.Construct(CLIPBOARD_DATA_TYPE_IMAGE , *pBitmap);
1807
1808                 // copying the item to clipboard
1809                 Clipboard* pClipboard = Clipboard::GetInstance();
1810                 if (pClipboard != null)
1811                 {
1812                         pClipboard->CopyItem(item);
1813                 }
1814         }
1815         break;
1816         case IDA_VIEW_IMAGE_CLICKED:
1817         {
1818                 AppLogDebug("IDA_VIEW_IMAGE_CLICKED");
1819                 WindowInfo* pNewWindowInfo = null;
1820                 if (__pHitElementResult != null)
1821                 {
1822                         String srcUrl = __pHitElementResult->GetAttributeValue(L"src");
1823                         AppLog("MainForm::OnTouchLongPressed srcUrl is %ls",srcUrl.GetPointer());
1824                         LoadUrl(srcUrl);
1825
1826                 }
1827         }
1828         break;
1829         case IDA_SAVE_IMAGE_CLICKED:
1830         {
1831                 AppLogDebug("IDA_SAVE_IMAGE_CLICKED");
1832                 const Bitmap* pSaveBitmap = null;
1833                 String imageName = GetImagePath();
1834                 AppLog("Content manager image name %ls",imageName.GetPointer());
1835                 String imagePath;
1836                 imagePath.Clear();
1837                 imagePath.Append(imageName);
1838                 imagePath.Format(100, L"%ls/Downloads/%ls.jpg",Tizen::System::Environment::GetMediaPath().GetPointer(),  imageName.GetPointer());
1839                 AppLog("Content manager image path %ls",imagePath.GetPointer());
1840                 if (__pHitElementResult != null)
1841                 {
1842                         pSaveBitmap = __pHitElementResult->GetImage();
1843                 }
1844                 ByteBuffer* pBuffer = __pSaveImage->EncodeToBufferN(*pSaveBitmap, IMG_FORMAT_JPG);
1845
1846                 if(pBuffer)
1847                 {
1848                         UpdateImageContent(pBuffer, imageName);
1849                         delete pBuffer;
1850                         NotificationPanel *pNotification = new NotificationPanel(*this);
1851                         String msg;
1852                         AppResource::GetInstance()->GetString("IDS_COM_SK_SAVE", msg);
1853                         msg.Append(imagePath);
1854                         if (pNotification != null)
1855                         {
1856                                 pNotification->SetText(msg);
1857                                 pNotification->SetPositionDiff(__pFooterPanel->GetHeight());
1858                                 pNotification->ShowNotification();
1859                         }
1860                 }
1861                 else
1862                 {
1863                         int __modalMsgBoxResult;
1864                         MessageBox* pMsgBox = new MessageBox();
1865                         pMsgBox->Construct(CommonUtil::GetString(L"IDS_COM_FAILED_TO_SAVE_IMAGE"),CommonUtil::GetString(L"IDS_COM_FAILED_TO_SAVE_IMAGE"),MSGBOX_STYLE_OK,3000);
1866                         pMsgBox->ShowAndWait(__modalMsgBoxResult);
1867                         delete pMsgBox;
1868                         pMsgBox = null;
1869                         __modalMsgBoxResult = 0;
1870                 }
1871         }
1872         break;
1873         case IDA_SHARE_IMAGE_CLICKED:
1874         {
1875                 AppLogDebug("IDA_SHARE_IMAGE_CLICKED");
1876                 if (__pPopUp != null)
1877                 {
1878                         delete __pPopUp;
1879                         __pPopUp = null;
1880                 }
1881                 __pPopUp = new(std::nothrow) SharePopup();
1882                 __pPopUp->Initialize();
1883                 if (__pHitElementResult != null)
1884                 {
1885                         const Bitmap* pSaveBitmap = null;
1886                         String imageName = GetImagePath();
1887                         AppLog("Content manager image name %ls",imageName.GetPointer());
1888                         String imagePath;
1889                         imagePath.Clear();
1890                         imagePath.Append(imageName);
1891                         imagePath.Format(100, L"%lsDownloads/%ls.jpg",Tizen::System::Environment::GetMediaPath().GetPointer(),  imageName.GetPointer());
1892                         AppLog("Content manager image path %ls",imagePath.GetPointer());
1893                         if (__pHitElementResult != null)
1894                         {
1895                                 pSaveBitmap = __pHitElementResult->GetImage();
1896                         }
1897                         __pSaveImage->EncodeToFile(*pSaveBitmap, IMG_FORMAT_JPG, imagePath, true);
1898
1899                         String srcUrl = __pHitElementResult->GetAttributeValue(L"src");
1900                         AppLog("MainForm::OnTouchLongPressed srcUrl is %ls",srcUrl.GetPointer());
1901
1902                         ShareInfo* pShareInfo = new(std::nothrow) ShareInfo();
1903                         pShareInfo->SetPageTitle(L"");
1904                         pShareInfo->SetPageUrl(srcUrl);
1905                         pShareInfo->SetImageAttached(true);
1906                         pShareInfo->SetImagePath(imagePath);
1907                         __pPopUp->RemoveAllShareInfo();
1908                         __pPopUp->AddShareInfo(pShareInfo);
1909                         __pPopUp->SetShowState(true);
1910                         __pPopUp->Show();
1911                 }
1912         }
1913         break;
1914         case IDA_HYPERLINK_OPEN_CLICKED:
1915         {
1916                 if (__pHitElementResult != null)
1917                 {
1918                         String srcUrl = __pHitElementResult->GetUrl();
1919
1920                         WindowInfo* pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewScene(srcUrl);
1921
1922                         if (pNewWindowInfo == null)
1923                         {
1924                                 return;
1925                         }
1926                         result r = E_SUCCESS;
1927                         SceneManager* pSceneManager = SceneManager::GetInstance();
1928                         if (pSceneManager == NULL)
1929                         {
1930                                 return;
1931                         }
1932                         ArrayList* pArgList = new(std::nothrow) ArrayList();
1933                         if (pArgList == NULL)
1934                         {
1935                                 return;
1936                         }
1937                         pArgList->Construct();
1938
1939                         pArgList->Add(*pNewWindowInfo);
1940                         r = pSceneManager->GoForward(ForwardSceneTransition(pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
1941                         if (pArgList != null)
1942                         {
1943                                 delete pArgList;
1944                                 pArgList = null;
1945                         }
1946                         if(IsFailed(r))
1947                         {
1948                                 AppLogDebug("MultipleWindowForm::OnActionPerformed GoForward failed %s",GetErrorMessage(r));
1949                                 return;
1950                         }
1951                 }
1952         }
1953         break;
1954         case IDA_HYPERLINK_SHARE_IMAGE_CLICKED:
1955         {
1956                 if (__pHitElementResult == null)
1957                 {
1958                         return;
1959                 }
1960
1961                 if(__pPopUp != null)
1962                 {
1963                         delete __pPopUp;
1964                         __pPopUp = null;
1965                 }
1966                 __pPopUp = new(std::nothrow) SharePopup();
1967                 __pPopUp->Initialize();
1968
1969                 ShareInfo* pShareInfo = new(std::nothrow) ShareInfo();
1970                 pShareInfo->SetPageUrl(__pHitElementResult->GetUrl());
1971                 pShareInfo->SetImageAttached(false);
1972                 __pPopUp->RemoveAllShareInfo();
1973                 __pPopUp->AddShareInfo(pShareInfo);
1974
1975                 __pPopUp->SetShowState(true);
1976                 __pPopUp->Show();
1977         }
1978         break;
1979         case IDA_HYPERLINK_COPY_LINK_CLICKED:
1980         {
1981                 ClipboardItem item;
1982                 String url;
1983                 if (__pHitElementResult != null)
1984                 {
1985                         url = __pHitElementResult->GetUrl();
1986                 }
1987
1988                 String resourcePath = App::GetInstance()->GetAppResourcePath();
1989                 item.Construct(CLIPBOARD_DATA_TYPE_TEXT , url);
1990
1991                 // copying the item to clipboard
1992                 Clipboard* pClipboard = Clipboard::GetInstance();
1993                 if (pClipboard != null)
1994                 {
1995                         pClipboard->CopyItem(item);
1996                 }
1997         }
1998         break;
1999         case IDA_FIND_TEXT__CLICKED:
2000         {
2001                 OnAddressCancelledClicked(*__pAddressbar);
2002                 AppLogDebug("MainForm::OnActionPerformed find word clicked");
2003                 __currentSearchStr.Clear();
2004                 __currentSearchStr.Append(__currentSelectedStr);
2005                 InitFindWordPanel();
2006                 __pFindWordEditField->SetText(__currentSearchStr);
2007                 if(__pMenu != null)
2008                 {
2009                         __pMenu->SetShowState(false);
2010                         __pMenu->Invalidate(false);
2011                 }
2012
2013                 __adressPanelPosition.y = 0;
2014
2015                 if (__pAddressbar != null && __pWebViewer != NULL)
2016                 {
2017                         __webControlPosition.y = __pAddressbar->GetHeight() - 12;
2018                         //__pAddressbar->SetBounds(0,__adressPanelPosition.y,GetClientAreaBounds().width,__pAddressbar->GetHeight());
2019                         //__pAddressbar->Invalidate(true);
2020                         __webControlHeight = GetClientAreaBounds().height - __pFooterPanel->GetHeight() - ( /*__pAddressbar->GetY() +*/ __pAddressbar->GetHeight() - 12);
2021
2022                         if (__pFooterPanel->GetShowState() == false)
2023                                 __pWebViewer->SetBounds(Rectangle(0,__webControlPosition.y,GetClientAreaBounds().width, GetClientAreaBounds().height - ( /*__pAddressbar->GetY() +*/ __pAddressbar->GetHeight() - 12)));
2024                         else
2025                                 __pWebViewer->SetBounds(Rectangle(0,__webControlPosition.y,GetClientAreaBounds().width, __webControlHeight));
2026                         //                      __pWebViewer->SetBounds(Rectangle(0,__webControlPosition.y,GetClientAreaBounds().width,__webControlHeight));
2027                         __pWebViewer->Invalidate(true);
2028                 }
2029
2030                 ShowFindWordPanel(true);
2031                 __pFindWordEditField->SetFocus();
2032                 if (__currentSearchStr.GetLength() > 0)
2033                 {
2034                         StartWordSearch();
2035                 }
2036                 else
2037                 {
2038                         AppLogDebug("Enter something");
2039                 }
2040
2041                 if (__pWebViewer != null)
2042                 {
2043                         // releasing the set block
2044                         __pWebViewer->ReleaseBlock();
2045                 }
2046
2047         }
2048         break;
2049         case IDA_SHARE_TEXT_CLICKED:
2050         {
2051                 AppLogDebug("IDA_SHARE_TEXT_CLICKED");
2052                 if(__pPopUp != null)
2053                 {
2054                         delete __pPopUp;
2055                         __pPopUp = null;
2056                 }
2057                 __pPopUp = new(std::nothrow) SharePopup();
2058                 __pPopUp->Initialize();
2059                 if (__pHitElementResult != null)
2060                 {
2061                         ShareInfo* pShareInfo = new(std::nothrow) ShareInfo();
2062                         pShareInfo->SetPageTitle(L"");
2063                         pShareInfo->SetPageUrl(__currentSelectedStr);
2064                         pShareInfo->SetImageAttached(false);
2065                         __pPopUp->RemoveAllShareInfo();
2066                         __pPopUp->AddShareInfo(pShareInfo);
2067                         __pPopUp->SetShowState(true);
2068                         __pPopUp->Show();
2069                 }
2070         }
2071         break;
2072         case IDA_COPY_TEXT_CLICKED:
2073         {
2074                 __pWebViewer->ReleaseBlock();
2075                 // need to implement
2076                 //__currentSelectedStr
2077                 // Sets data to a clip board item
2078                 ClipboardItem item;
2079                 String resourcePath = App::GetInstance()->GetAppResourcePath();
2080                 item.Construct(CLIPBOARD_DATA_TYPE_TEXT, __currentSelectedStr);
2081
2082                 // copying the item to clipboard
2083                 Clipboard* pClipboard = Clipboard::GetInstance();
2084                 if (pClipboard != null)
2085                 {
2086                         pClipboard->CopyItem(item);
2087                 }
2088         }
2089         break;
2090         case IDA_PASTE_TEXT_CLICKED:
2091         {
2092                 Clipboard* pClipboard = Clipboard::GetInstance();
2093
2094                 if(pClipboard == null)
2095                 {
2096                         return;
2097                 }
2098                 // Retrieves a latest item
2099                 ClipboardItem* pItem = pClipboard->RetrieveLatestItemN(CLIPBOARD_DATA_TYPE_TEXT | CLIPBOARD_DATA_TYPE_HTML);
2100
2101                 if(pItem == null)
2102                 {
2103                         return;
2104                 }
2105                 //Gets data from the clipboard item
2106                 String* pString = dynamic_cast<String*>(pItem->GetData());
2107
2108                 if (pString != null)
2109                 {
2110                         String idElement = __pHitElementResult->GetAttributeValue(L"id");
2111                         String nameElement = __pHitElementResult->GetAttributeValue(L"name");
2112                         AppLog("MainForm::IDA_PASTE_TEXT_CLICKED id is %ls",idElement.GetPointer());
2113                         String script = L"function insertAtCursor(myField, myValue) {   if (document.selection) {               myField.focus();                sel = document.selection.createRange();                 sel.text = myValue;     }               else if (myField.selectionStart || myField.selectionStart == '0'){              var startPos = myField.selectionStart;          var endPos = myField.selectionEnd;              myField.value = myField.value.substring(0, startPos)+ myValue + myField.value.substring(endPos, myField.value.length);          } else {                        myField.value += myValue;               }       } ";
2114                         if(idElement.GetLength() != 0)
2115                         {
2116                                 script.Append("insertAtCursor(");
2117                                 script.Append(idElement);
2118                                 script.Append(",");
2119                                 script.Append("\"");
2120                                 script.Append(*pString);
2121                                 script.Append("\");");
2122                         }
2123                         else if (nameElement.GetLength() != 0)
2124                         {
2125                                 script.Append("insertAtCursor(document.getElementsByName('");
2126                                 script.Append(nameElement);
2127                                 script.Append("')[0],");
2128                                 script.Append("\"");
2129                                 script.Append(*pString);
2130                                 script.Append("\");");
2131                         }
2132                         AppLog("MainForm::OnTouchLongPressed script is %ls",script.GetPointer());
2133                         String* pStr = __pWebViewer->EvaluateJavascriptN(script);
2134                         delete pStr;
2135                 }
2136                 delete pItem;
2137         }
2138         break;
2139         case IDA_GO_BACK:
2140         {
2141                 OnBackClicked();
2142         }
2143         break;
2144         case IDA_GO_FORWARD:
2145         {
2146                 OnForwardClicked();
2147         }
2148         break;
2149         case IDA_REFRESH_BTN_CLICKED:
2150         {
2151                 __isLoadingCompleted = false;
2152                 __isLoadingData = true;
2153                 __progressPercentage = 0;
2154                 __displayUrl = __pFooterUrlField->GetText();
2155
2156                 String url = __pFooterUrlField->GetText();
2157                 AppLog("MainForm::OnUrlSubmitted url is %ls", url.GetPointer());
2158                 LoadUrl(url);
2159
2160                 //OnUrlSubmitted();
2161                 UpdateProgressBitmap();
2162         }
2163         break;
2164         case IDA_STOP_BTN_CLICKED:
2165         {
2166                 __isLoadingCompleted = false;
2167                 __isLoadingData = false;
2168                 __progressPercentage = 0;
2169                 __pFooterUrlField->HideKeypad();
2170                 __displayUrl = __pFooterUrlField->GetText();
2171
2172                 if (__pWebViewer)
2173                 {
2174                         //__pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
2175                         SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
2176                         __pWebViewer->StopLoading();
2177                         RequestRedraw(true);
2178                 }
2179
2180                 UpdateProgressBitmap();
2181         }
2182         break;
2183         case IDA_CLEAR_URL:
2184         {
2185                 if (__pFooterUrlField->GetText().IsEmpty() == false)
2186                 {
2187                         //__displayUrl = __pUrlField->GetText();
2188                         __pFooterUrlField->Clear();
2189
2190                 }
2191         }
2192         break;
2193         default:
2194                 break;
2195         }
2196 }
2197
2198 void
2199 MainForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
2200 {
2201
2202         UiApp* pApp = UiApp::GetInstance();
2203         if (pApp == null)
2204         {
2205                 return;
2206         }
2207         pApp->Terminate();
2208 }
2209
2210 void
2211 MainForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
2212                 const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
2213 {
2214         AppLog("MainForm::OnSceneActivatedN called");
2215         String* pSelectedScene = NULL;
2216         Object* pValue = NULL;
2217         String* pUrl = null;
2218         MultipleWindowPresentationModel::GetInstance()->GetValue(SELECTED_SCENE_ID, &pValue);
2219         pSelectedScene = (String*) pValue;
2220
2221         if (pSelectedScene != null)
2222         {
2223                 delete pSelectedScene;
2224         }
2225         MultipleWindowPresentationModel::GetInstance()->SetValue(SELECTED_SCENE_ID, null);
2226         String* selectedSceneID = new(std::nothrow) String(currentSceneId);
2227         AppLogDebug("current scene id is %ls", currentSceneId.GetPointer());
2228         AppLogDebug("selected scene id is %ls", currentSceneId.GetPointer());
2229
2230         // setting the current scene ID
2231         MultipleWindowPresentationModel::GetInstance()->SetCurrentSceneID(currentSceneId);
2232
2233         MultipleWindowPresentationModel::GetInstance()->SetValue(SELECTED_SCENE_ID, (Object*) selectedSceneID);
2234
2235         if(pArgs != null && pArgs->GetCount() > 0 && pArgs->GetCount() == 2)
2236         {
2237                 __pWindowInfo = dynamic_cast< WindowInfo* >(pArgs->GetAt(0));
2238                 if(__pWindowInfo == null)
2239                         return;
2240                 //              if(__pWindowInfo == null)
2241                 {
2242                         pUrl = dynamic_cast< String* >(pArgs->GetAt(1));
2243                 }
2244         }
2245         else if ( pArgs != null && pArgs->GetCount() == 1)
2246         {
2247                 __pWindowInfo = dynamic_cast< WindowInfo* >(pArgs->GetAt(0));
2248         }
2249
2250         InitFooter();
2251         InitAddressbar();
2252
2253         // hiding the address bar
2254         //      __pAddressbar->SetBounds(__pAddressbar->GetX(), __pAddressbar->GetY() - __pAddressbar->GetHeight(), __pAddressbar->GetWidth(), __pAddressbar->GetHeight());
2255         __pAddressbar->SetShowState(false);
2256         if(__pWebViewer != null)
2257         {
2258                 __pWebViewer->Resume();
2259         }
2260
2261         if(pUrl != null && pUrl->GetLength() > 0)
2262         {
2263                 LoadUrl(*pUrl);
2264         }
2265         else if(__pWindowInfo != null)
2266         {
2267                 if(__pWindowInfo->pageUrl.GetLength() > 0 && previousSceneId != IDSCN_MULTIPLE_WINDOW && previousSceneId != IDSCN_MULTIPLE_WINDOW_GRID && previousSceneId != IDSCN_BOOKMARK_VIEW && previousSceneId != IDSCN_SETTINGS && previousSceneId != IDSCN_MAIN_VIEW)
2268                 {
2269                         LoadUrl(__pWindowInfo->pageUrl);
2270                 }
2271                 else if (__pWindowInfo->isJavascriptInitiated == true)
2272                 {
2273                         AppLog("Called");
2274                         InitWebControl();
2275                         __pWindowInfo->pCurrentWeb = __pWebViewer;
2276                 }
2277         }
2278
2279         String homePage = SettingPresentationModel::GetInstance()->GetHomepage();
2280         AppLog("Homepage Value in Onsceneactivated is %ls",homePage.GetPointer());
2281         if(homePage.CompareTo((L"IDS_BR_BODY_MOST_VISITED_SITES")) == 0)
2282         {
2283                 InitMostVisitedSitesView(GetOrientationStatus());
2284         }
2285
2286         if (__pAddressbar != null && pArgs != null && (previousSceneId == IDSCN_BOOKMARK_VIEW || previousSceneId == IDSCN_HISTORY_LIST))
2287         {
2288                 String* pBookmarkUrl = dynamic_cast< String* >(pArgs->GetAt(0));
2289
2290                 if (pBookmarkUrl == null)
2291                         return;
2292                 AppLogDebug("bookmarkUrl = %ls",pBookmarkUrl->GetPointer());
2293                 //__pAddressbar->SetUrl(*pBookmarkUrl);
2294                 SetUrl(*pBookmarkUrl);
2295
2296                 if (__pWebViewer != null && homePage.CompareTo((L"IDS_BR_BODY_BLANK_PAGE")) != 0)
2297                         __pWebViewer->LoadUrl(*pBookmarkUrl);
2298                 delete pBookmarkUrl;
2299         }
2300
2301         bool isPrivateBrowsing = SettingPresentationModel::GetInstance()->GetPrivateOn();
2302         Bitmap* pBitmap = null;
2303         if (isPrivateBrowsing == true)
2304         {
2305                 pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_BUTTON_ON);
2306
2307                 if (__pWebViewer != null)
2308                 {
2309                         __pWebViewer->SetPrivateBrowsingEnabled(true);
2310                 }
2311
2312                 if (__pAddressbar != null)
2313                 {
2314                         //      __pAddressbar->UpdateFaviconBitmap(true);
2315                 }
2316
2317         }
2318         else
2319         {
2320                 pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_BUTTON_OFF);
2321
2322                 if (__pWebViewer != null)
2323                 {
2324                         __pWebViewer->SetPrivateBrowsingEnabled(false);
2325                 }
2326
2327                 if (__pAddressbar != null)
2328                 {
2329                         //      __pAddressbar->UpdateFaviconBitmap(false);
2330                 }
2331         }
2332
2333         if (__pMenu != null && __pMenu->GetItemCount() == 3)
2334         {
2335                 __pMenu->SetItemAt(0,CommonUtil::GetString(L"IDS_BR_BODY_PRIVACY"),IDA_PRIVATEON_CLICKED,*pBitmap);
2336         }
2337         else if (__pMenu != null )
2338         {
2339                 __pMenu->SetItemAt(3,CommonUtil::GetString(L"IDS_BR_BODY_PRIVACY"),IDA_PRIVATEON_CLICKED,*pBitmap);
2340         }
2341
2342         if (pBitmap != null)
2343         {
2344                 delete pBitmap;
2345         }
2346
2347         AppLog("ABC: OnSceneActivatedN started exit");
2348
2349 }
2350
2351 void
2352 MainForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
2353                 const Tizen::Ui::Scenes::SceneId& nextSceneId)
2354 {
2355         Canvas* pWebCanvas = null;
2356         if (__pWebViewer != null)
2357         {
2358                 pWebCanvas = __pWebViewer->GetCanvasN();
2359                 __pWebViewer->Pause();
2360
2361         }
2362         if (pWebCanvas == null)
2363         {
2364                 return;
2365         }
2366         if (__pWindowInfo != null)
2367         {
2368                 if (__pWindowInfo->pWebCanvasBitmap != null)
2369                 {
2370                         delete __pWindowInfo->pWebCanvasBitmap;
2371                 }
2372                 __pWindowInfo->pWebCanvasBitmap = new(std::nothrow) Bitmap();
2373                 result r = __pWindowInfo->pWebCanvasBitmap->Construct(*pWebCanvas,Rectangle(0,0,pWebCanvas->GetBounds().width,pWebCanvas->GetBounds().height));
2374                 AppLog("Bitmap Construction result %s",GetErrorMessage(r));
2375         }
2376         Bitmap* pBitmap = GetCapturedBitmapN();
2377         AppLog("Coming here");
2378         Canvas* pCanvas = new(std::nothrow) Canvas();
2379         pCanvas->Construct(GetClientAreaBounds());
2380         if(pBitmap != null)
2381         {
2382                 pCanvas->DrawBitmap(Point(0,0),*pBitmap);
2383                 delete pBitmap;
2384         }
2385         if(__pWebViewer != null && __pWindowInfo != null)
2386                 pCanvas->DrawBitmap(__pWebViewer->GetPosition(),*__pWindowInfo->pWebCanvasBitmap);
2387
2388         WindowInfo::pFormCanvasBitmap = new(std::nothrow) Bitmap();
2389         WindowInfo::pFormCanvasBitmap->Construct(*pCanvas,Rectangle(0,0,GetClientAreaBounds().width,GetClientAreaBounds().height - __pFooterPanel->GetHeight()));
2390         delete pCanvas;
2391         AppLog("Coming here");
2392 }
2393
2394 bool
2395 MainForm::OnHttpAuthenticationRequestedN(const Tizen::Base::String& host,
2396                 const Tizen::Base::String& realm,
2397                 const Tizen::Web::Controls::AuthenticationChallenge& authentication)
2398 {
2399         return false;
2400 }
2401
2402 void
2403 MainForm::OnHttpAuthenticationCanceled(void)
2404 {
2405 }
2406
2407 void
2408 MainForm::OnLoadingStarted(void)
2409 {
2410         AppLogDebug("MainForm::OnLoadingStarted entered");
2411         __isLoaded = true;
2412         if(__pAddressbar == NULL || __pWebViewer == null)
2413         {
2414                 return;
2415         }
2416         String url = __pWebViewer->GetUrl();
2417         if(url.Contains(IDS_TIZEN_SERVICE))
2418         {
2419                 String appId;
2420                 String delim(L":;");
2421
2422                 // Creates a StringTokenizer instance
2423                 StringTokenizer strTok(url, delim);
2424
2425                 int count = strTok.GetTokenCount();     // count == 4
2426
2427                 HashMap *pMap = new HashMap();
2428                 pMap->Construct();
2429                 String token;
2430                 String key;
2431                 String value;
2432                 while (strTok.HasMoreTokens())
2433                 {
2434                         AppLog("Token: %ls", token.GetPointer());
2435                         strTok.GetNextToken(token);         // Tizen, StringTokenizer, Sample, code
2436                         if(token.Contains(IDS_APPID))
2437                         {
2438                                 token.SubString(6, appId);
2439                                 AppLog("AppID:%ls", appId.GetPointer());
2440                         }
2441                         else if(token.Contains("="))
2442                         {
2443                                 String *pKey = new String();
2444                                 String *pValue = new String();
2445                                 int index = -1;
2446                                 token.IndexOf("=", 0, index);
2447                                 if(index != -1)
2448                                 {
2449                                         token.SubString(0, index, *pKey);
2450                                         token.SubString(index + 1, *pValue);
2451                                         pMap->Add(pKey, pValue);
2452                                 }
2453                         }
2454                 }
2455                 if(appId != "")
2456                 {
2457                         AppControl *pAppControl = null;
2458                         String operationId = L"http://tizen.org/appcontrol/operation/main";
2459                         pAppControl = dynamic_cast<AppControl*>(AppManager::FindAppControlN(appId, operationId));
2460                         if(pAppControl)
2461                         {
2462                                 AppLog("Starting AppControl");
2463                                 result r = pAppControl->Start(null, null, pMap, null);
2464                                 AppLog("Result of Start %s", GetErrorMessage(r));
2465                         }
2466                         else
2467                         {
2468                                 AppLogException("AppControl not found");
2469                         }
2470                         return;
2471                 }
2472         }
2473         Bitmap* pBitmap = FaviconManager::GetInstance()->GetDefaultFaviconN();
2474         if(pBitmap != null)
2475         {
2476                 __pAddressbar->SetFaviconBitmap(*pBitmap);
2477         }
2478         delete pBitmap;
2479         if (__adressPanelPosition.y < (0 - __pAddressbar->GetHeight() + 12))
2480         {
2481                 // updating the address bar position with respect to web control
2482                 __adressPanelPosition.y = 0 - __pAddressbar->GetHeight() + 12; //-12 is for the progress label
2483                 __distanceMoved = 0;
2484                 MoveUiControls();
2485         }
2486
2487         //__pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING);
2488         SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING);
2489         if (__pWebViewer != null)
2490         {
2491                 AppLog("MainForm::OnLoadingStarted __pWebViewer->GetUrl() %ls",__pWebViewer->GetUrl().GetPointer());
2492                 //__pAddressbar->SetUrl(__pWebViewer->GetUrl());
2493                 SetUrl(__pWebViewer->GetUrl());
2494                 if (__pWindowInfo != NULL)
2495                 {
2496                         __pWindowInfo->pageUrl = __pWebViewer->GetUrl();
2497                 }
2498                 __pAddressbar->Invalidate(true);
2499         }
2500
2501 }
2502
2503 void
2504 MainForm::OnLoadingCanceled(void)
2505 {
2506
2507 }
2508
2509
2510 void
2511 MainForm::OnKeypadWillOpen(Tizen::Ui::Control& source)
2512 {
2513         AppLog("MainForm::OnKeypadWillOpen");
2514         if (__pAddressbar != null)
2515         {
2516                 OnAddressBarKeypadWillOpen(*__pAddressbar);
2517         }
2518
2519 }
2520
2521 void
2522 MainForm::OnKeypadOpened(Tizen::Ui::Control& source)
2523 {
2524         if(__pAddressbar != null)
2525         {
2526                 OnAddressBarKeypadOpened(*__pAddressbar);
2527         }
2528 }
2529
2530
2531 void
2532 MainForm::OnKeypadClosed(Tizen::Ui::Control& source)
2533 {
2534
2535
2536         if (__pAddressbar != null)
2537         {
2538                 OnAddressBarKeypadClosed(*__pAddressbar);
2539         }
2540 }
2541
2542 void
2543 MainForm::OnKeypadBoundsChanged(Tizen::Ui::Control &source)
2544 {
2545         AppLog("KeypadBoundsChanged");
2546         RelayoutControls(false);
2547 }
2548
2549 void
2550 MainForm::OnLoadingErrorOccurred(LoadingErrorType error,
2551                 const Tizen::Base::String& reason)
2552 {
2553         AppLogDebug("Error: %d, %ls", error, reason.GetPointer());
2554 }
2555
2556 void
2557 MainForm::OnLoadingCompleted(void)
2558 {
2559         AppLog("MainForm::OnLoadingCompleted start");
2560         DateTime date;
2561         result r = E_SUCCESS;
2562
2563         if (__pWebViewer == null)
2564         {
2565                 return;
2566         }
2567
2568         if (__pAddressbar == null)
2569         {
2570                 return;
2571         }
2572         if (__pWebViewer->CanGoForward())
2573         {
2574                 //__pAddressbar->SetForwardButtonEnabled(true);
2575                 SetForwardButtonEnabled(true);
2576         }
2577         else
2578         {
2579                 //__pAddressbar->SetForwardButtonEnabled(false);
2580                 SetForwardButtonEnabled(false);
2581         }
2582
2583         /*if (__pAddressbar->GetAddressbarMode() != ADDRESSBAR_MODE_EDIT)
2584         {
2585                 __pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
2586
2587                 //__pAddressbar->UpdateProgress(0);
2588                 UpdateProgress(0);
2589         }*/
2590
2591         if(GetAddressbarMode() != ADDRESSBAR_MODE_EDIT)
2592         {
2593                 SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
2594                 UpdateProgress(0);
2595         }
2596
2597         AppLog("PrivateBrowsing %d",__pWebViewer->IsPrivateBrowsingEnabled());
2598         bool isPrivateBrowsing = SettingPresentationModel::GetInstance()->GetPrivateOn();
2599         if (isPrivateBrowsing == false)
2600         {
2601                 History* pHistory = new(std::nothrow) History;
2602
2603                 HistoryPresentationModel::GetCurrentDateTime(date);
2604                 if(__pWindowInfo)
2605                 {
2606                         pHistory->SetHistoryTitle(__pWindowInfo->pageTitle);
2607                         AppLogDebug("MainForm::OnLoadingCompleted pagetitle = %ls", __pWindowInfo->pageTitle.GetPointer());
2608
2609                         pHistory->SetHistoryUrl(__pWindowInfo->pageUrl);
2610                         AppLogDebug("MainForm::OnLoadingCompleted pageUrl = %ls", __pWindowInfo->pageUrl.GetPointer());
2611                 }
2612                 pHistory->SetVisitedTime(date);
2613                 /*String id = "";
2614                 if(__pWindowInfo)
2615                         id = FaviconManager::GetInstance()->SaveFavicon(*__pWindowInfo->pFavicon, __pWindowInfo->faviconUrl);
2616                 pHistory->SetFaviconId(id);*/
2617
2618                 if (__pWebViewer != null)
2619                 {
2620                         AppLog("MainForm::OnLoadingCompleted setting the fav icon 0");
2621
2622                         Bitmap* pTempBitmap = __pWebViewer->GetFaviconN();
2623                         if (pTempBitmap != null)
2624                         {
2625                                 AppLog("MainForm::OnLoadingCompleted setting the fav icon 1");
2626                                 pHistory->SetFavIconBitmap(*pTempBitmap);
2627                         }
2628
2629                         AppLog("MainForm::OnLoadingCompleted setting the fav icon 2");
2630                 }
2631
2632                 Canvas* pCanvas = __pWebViewer->GetCanvasN();
2633                 Bitmap* pBitmap = new(std::nothrow) Bitmap();
2634                 if ( pCanvas != null &&  pCanvas != null && pBitmap != null)
2635                 {
2636                         pBitmap->Construct(*pCanvas, pCanvas->GetBounds());
2637                         pBitmap->Scale(Dimension(pBitmap->GetWidth()/4, pBitmap->GetHeight()/4));
2638                         pHistory->SetThumbnail(pBitmap);
2639                 }
2640                 Bitmap *pFavIcon = __pWebViewer->GetFaviconN();
2641                 if(pFavIcon)
2642                 {
2643                         pHistory->SetFavIconBitmap(*pFavIcon);
2644                         delete pFavIcon;
2645                 }
2646
2647                 HistoryPresentationModel::GetInstance()->SaveTempHistory(*pHistory);
2648                 delete pHistory;
2649         }
2650         else
2651         {
2652                 return;
2653         }
2654         if (__pWindowInfo && __pWindowInfo->faviconUrl == "")
2655         {
2656                 // temperary fixed (webpage can be not loaded)
2657                 UpdateFavicon();
2658         }
2659         AppLog("MainForm::OnLoadingCompleted done");
2660 }
2661
2662 void
2663 MainForm::OnEstimatedProgress(int progress)
2664 {
2665         AppLogDebug("MainForm::OnEstimatedProgress entered");
2666         if (progress < DEFAULT_PROGRESS_PERCENTAGE)
2667                 progress = DEFAULT_PROGRESS_PERCENTAGE;
2668         //if(__pAddressbar)
2669         //      __pAddressbar->UpdateProgress(progress);
2670         UpdateProgress(progress);
2671 }
2672
2673 void MainForm::OnFaviconReceived(const Tizen::Graphics::Bitmap& favicon)
2674 {
2675         AppLog("MainForm::OnFaviconReceived");
2676         Bitmap* pFavIconBitmap = __pWebViewer->GetFaviconN();
2677
2678         if (pFavIconBitmap != null)
2679         {
2680                 pFavIconBitmap->GetWidth();
2681                 pFavIconBitmap->GetHeight();
2682         }
2683 }
2684
2685 void
2686 MainForm::OnUrlValueChanged(Addressbar&)
2687 {
2688         Invalidate(true);
2689 }
2690
2691 void
2692 MainForm::OnUrlSubmitted(Addressbar& addBar)
2693 {
2694         AppLog("MainForm::OnUrlSubmitted");
2695         String url = addBar.GetUrl();
2696         AppLog("MainForm::OnUrlSubmitted url is %ls", url.GetPointer());
2697
2698 //      __pFooterPanel->SetShowState(true);
2699         if(__pFooterUrlField)
2700                 __pFooterUrlField->SetCursorPosition(__pFooterUrlField->GetTextLength());
2701         OnAddressCancelledClicked(*__pAddressbar);
2702 //      __pAddressbar->SetShowState(false);
2703 //      RelayoutControls(false);
2704         LoadUrl(url);
2705 }
2706
2707 void
2708 MainForm::LoadUrl(String& url)
2709 {
2710         url.Trim();
2711         String encodedUrl;
2712 //      UrlEncoder::Encode(url, L"UTF-8", encodedUrl);
2713         AppLogDebug("MainForm::LoadUrl enter");
2714
2715         if (__pWebViewer != null)
2716         {
2717                 __pWebViewer->SetShowState(true);
2718                 __pWebViewer->Invalidate(true);
2719         }
2720
2721         if (url.CompareTo(L"") == 0)
2722         {
2723                 return;
2724         }
2725         if(__pFooterPanel != null)
2726         {
2727                 __pFooterPanel->SetShowState(true);
2728                 __pFooterPanel->Invalidate(true);
2729         }
2730         InitWebControl();
2731
2732         bool ret = false;
2733         bool flag = false;
2734
2735         String firstPattern(L"((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)");
2736         String secondPattern(L"^[A-Za-z0-9\.\+-:#@%/;$~?]+\\.[A-Za-z0-9!\+-=:#@%/;$~()_?\\\.&]{2,}$");   // URL of type  abc.com (i.e without protocol in front of it)
2737
2738         RegularExpression firstRegex;
2739         RegularExpression secondRegex;
2740
2741         firstRegex.Construct(firstPattern, REGEX_CASELESS);
2742         secondRegex.Construct(secondPattern, REGEX_CASELESS);
2743
2744         // Match
2745         ret = firstRegex.Match(url, false); // This returns true value
2746         flag = secondRegex.Match(url, false);  // Checks whether URL typed is of type  abc.com (i.e without protocol in front of it)
2747
2748         if (ret == true && __pWebViewer != null)
2749         {
2750                 __pWebViewer->LoadUrl(url);
2751         }
2752         else if(__pWebViewer != null)
2753         {
2754                 String tempUrl = L"http://";
2755                 tempUrl.Append(url);
2756
2757                 if (flag == true)
2758                 {
2759                         __pWebViewer->LoadUrl(tempUrl);
2760                 }
2761                 else
2762                 {
2763                                 UrlEncoder::Encode(url, L"UTF-8", encodedUrl);
2764                         __pWebViewer->LoadUrl(SettingPresentationModel::GetInstance()->GetSearchUrl(encodedUrl));
2765                 }
2766         }
2767         if (__pAddressbar != null)
2768         {
2769                 //__pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING);
2770                 SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING);
2771         }
2772
2773         AppLogDebug("MainForm::LoadUrl exit");
2774
2775         return;
2776
2777 }
2778
2779 void
2780 MainForm::OnStopClicked(Addressbar& addBar)
2781 {
2782         AppLogDebug("MainForm::OnStopClicked called");
2783         if (__pWebViewer)
2784         {
2785                 //__pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
2786                 SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
2787                 __pWebViewer->StopLoading();
2788                 RequestRedraw(true);
2789         }
2790 }
2791
2792 void
2793 MainForm::OnReaderClicked(const Addressbar& addBar)
2794 {
2795         int bodyWidth = ((double)(GetClientAreaBounds().width))*0.73;
2796
2797         CreateReaderPanel();
2798         AppLogDebug("MainScene::OnReaderClicked entered");
2799
2800
2801         /*if (__pArticleReaderPanel)
2802         {
2803                 AppLogDebug("showstate true for reader panel");
2804                 __pArticleReaderPanel->SetShowState(true);
2805                 __pArticleReaderPanel->Show();
2806         }*/
2807         int xPos = __pArticleReaderPanel->GetX();
2808         int yPos = __pArticleReaderPanel->GetY();
2809         AppLog("OnReaderClicked() xPos = %d",xPos);
2810         AppLog("OnReaderClicked() yPos = %d",yPos);
2811
2812         if (__pReaderData == null)
2813         {
2814                 return;
2815         }
2816
2817         String loadData = L"<html>\
2818                                         <head>\
2819                                         <meta name='viewport' content='width=device-width*0.73,minimum-scale=1.0, maximum-scale=1.0, user-scalable=no'>\
2820                                         <style>\
2821                                         h1\
2822                                         {\
2823                                         font-weight:bold;\
2824                                         background-color: transparent;\
2825                                         }\
2826                                         div\
2827                                         {\
2828                                         display: block;\
2829                                         }\
2830                                         p\
2831                                         {\
2832                                         display: block; \
2833                                         }\
2834                                         img\
2835                                         {\
2836                                         margin-left:auto;\
2837                                         margin-right:auto;\
2838                                         }\
2839                                         \
2840                                         \
2841                                         </style>\
2842                                         </head>\
2843                                         <body style='width:'";
2844         loadData.Append(bodyWidth);
2845         loadData.Append(L"px'>");
2846         AppLogDebug("data->GetLength %d",__pReaderData->GetLength());
2847         loadData.Append(*__pReaderData);
2848         loadData.Append(L"</body></html>");
2849
2850         ByteBuffer buf ;
2851         buf.Construct(loadData.GetLength());
2852         AppLogDebug("data->GetLength %d",loadData.GetLength());
2853         for (int z=0;z<loadData.GetLength();z++)
2854         {
2855                 mchar b;
2856                 loadData.GetCharAt(z,b);
2857                 buf.SetByte((byte)b);
2858         }
2859
2860         buf.Flip();
2861         if (__pWebReader != null)
2862         {
2863                 __pWebReader->LoadData(L"",buf,L"text/html");
2864                 AppLogDebug("LoadData result %s",GetErrorMessage(GetLastResult()));
2865         }
2866         else
2867         {
2868                 AppLogDebug("cannot LoadData __pWebReader is null");
2869         }
2870
2871 }
2872
2873 void
2874 MainForm::OnBackClicked(/*const Addressbar& addBar*/)
2875 {
2876 //      AppLog("MainForm::OnBackClicked");
2877         result r = E_FAILURE;
2878
2879         if (__pWebViewer && __pWebViewer->CanGoBack())
2880         {
2881                 __pWebViewer->GoBack();
2882         }
2883         else if(__pWindowInfo && __pWindowInfo->isJavascriptInitiated == false)
2884         {
2885                 UiApp* pApp = null;
2886                 pApp = UiApp::GetInstance();
2887                 if (pApp != null)
2888                 {
2889                         r = pApp->Terminate();
2890                         if (IsFailed(r))
2891                         {
2892                                 AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
2893                                 return;
2894                         }
2895                 }
2896         }
2897         else
2898         {
2899                 UiApp* pApp = null;
2900                 WindowInfo* pWindowInfo = null;
2901                 int totalCount = 0;
2902                 SceneManager* pSceneManager = SceneManager::GetInstance();
2903                 if (pSceneManager == null)
2904                 {
2905                         return;
2906                 }
2907                 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
2908                 if (pAllWindowList == NULL)
2909                 {
2910                         pApp = UiApp::GetInstance();
2911                         if (pApp != null)
2912                         {
2913                                 r = pApp->Terminate();
2914                                 if (IsFailed(r))
2915                                 {
2916                                         AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
2917                                         return;
2918                                 }
2919                         }
2920                 }
2921                 if (pAllWindowList != null)
2922                 {
2923                         totalCount = pAllWindowList->GetCount();
2924                 }
2925                 for (int count = 0; count < totalCount; count++)
2926                 {
2927                         pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count));
2928                         if (pWindowInfo == null)
2929                         {
2930                                 pApp = UiApp::GetInstance();
2931                                 if (pApp != null)
2932                                 {
2933                                         r = pApp->Terminate();
2934                                         if (IsFailed(r))
2935                                         {
2936                                                 AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
2937                                                 return;
2938                                         }
2939                                 }
2940                         }
2941                         if (pSceneManager != null && pWindowInfo != null && pSceneManager->GetCurrentSceneId() == pWindowInfo->sceneID && pWindowInfo->isJavascriptInitiated == true)
2942                         {
2943                                 r = SceneRegister::DestroyAndUnRegisterScene(pWindowInfo->sceneID);
2944                                 if (IsFailed(r))
2945                                 {
2946                                         AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
2947                                         return;
2948                                 }
2949                                 r = pAllWindowList->RemoveAt(count, true);
2950                                 __pWindowInfo = null;
2951                                 if (IsFailed(r))
2952                                 {
2953                                         AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
2954                                         return;
2955                                 }
2956                                 if(count > 0)
2957                                 {
2958                                         pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count - 1));
2959                                 }
2960                                 else
2961                                 {
2962                                         pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(pAllWindowList->GetCount() - 1));
2963                                 }
2964                                 if (pWindowInfo == null)
2965                                 {
2966                                         pApp = UiApp::GetInstance();
2967                                         if (pApp != null)
2968                                         {
2969                                                 r = pApp->Terminate();
2970                                                 return;
2971                                         }
2972                                 }
2973                                 else
2974                                 {
2975                                         r = pSceneManager->GoBackward(BackwardSceneTransition(pWindowInfo->sceneID ,SCENE_TRANSITION_ANIMATION_TYPE_NONE));
2976                                         if (IsFailed(r))
2977                                         {
2978                                                 AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
2979                                                 return;
2980                                         }
2981                                 }
2982                                 break;
2983                         }
2984
2985                 }
2986
2987         }
2988
2989 }
2990
2991 void
2992 MainForm::OnForwardClicked(/*const Addressbar& addBar*/)
2993 {
2994         AppLog("MainForm::OnForwardClicked");
2995         if (__pWebViewer == null)
2996                 return;
2997
2998         if (__pWebViewer->CanGoForward())
2999         {
3000                 __pWebViewer->GoForward();
3001         }
3002 }
3003
3004 void
3005 MainForm::OnAddressCancelledClicked(const Addressbar& addBar)
3006 {
3007         result r = E_SUCCESS;
3008
3009         __pFooterPanel->SetShowState(true);
3010         __pFooterUrlField->SetFocusable(true);
3011
3012         if(__pWebViewer)
3013                 __pWebViewer->SetFocus();
3014         else if(__pMostVisitedListView)
3015                 __pMostVisitedListView->SetFocus();
3016         else if(__pMultiWindowButton)
3017                 __pMultiWindowButton->SetFocus();
3018         __pMoreButton->SetFocus();
3019
3020         __pAddressbar->SetShowState(false);
3021
3022         RelayoutControls(false);
3023
3024 }
3025
3026 void
3027 MainForm::OnAddressBarModeChanged(/*const Addressbar& addBar*/)
3028 {
3029         __prevAddressBarMode = __curAddressBarMode;
3030
3031         if (__pAddressbar != null)
3032         {
3033                 __curAddressBarMode = GetAddressbarMode();
3034         }
3035
3036         if (__curAddressBarMode == ADDRESSBAR_MODE_EDIT)
3037         {
3038                 __adressPanelPosition.y = 0;
3039                 if (__pAddressbar != null)
3040                 {
3041                         __webControlPosition.y = __pAddressbar->GetHeight() - 12;
3042                         __pAddressbar->SetBounds(Rectangle(0,0,GetClientAreaBounds().width,__pAddressbar->GetHeight()));
3043                         __pAddressbar->Invalidate(true);
3044                 }
3045                 if (__pWebViewer != null)
3046                 {
3047                         __pWebViewer->StopLoading();
3048                 }
3049         }
3050         else if(__curAddressBarMode == ADDRESSBAR_MODE_LOADING)
3051         {
3052                 __adressPanelPosition.y = 0;
3053                 if (__pAddressbar != null)
3054                 {
3055                         __webControlPosition.y = 0;
3056                         __pAddressbar->SetBounds(Rectangle(0, __pAddressbar->GetY() - __pAddressbar->GetHeight(), GetClientAreaBounds().width, __pAddressbar->GetHeight()));
3057                         __pAddressbar->Invalidate(true);
3058                 }
3059         }
3060 }
3061
3062 void
3063 MainForm::OnClipboardClosed(const Addressbar& addBar)
3064 {
3065         RelayoutControls(false);
3066 }
3067
3068 void
3069 MainForm::OnAddressBarKeypadClosed(const Addressbar& addBar, bool footerState)
3070 {
3071         if(__pAddressbar)
3072                 __pAddressbar->SetShowState(false);
3073         if(__pFooterPanel)
3074                 __pFooterPanel->SetShowState(true);
3075 //      if(__pWebViewer)
3076 //              __pWebViewer->SetFocus();
3077         if(__pFooterUrlField)
3078         {
3079                 __pFooterUrlField->SetFocusable(true);
3080         }
3081         RelayoutControls(false);
3082 }
3083
3084 void
3085 MainForm::OnAddressBarKeypadOpened(const Addressbar& addBar)
3086 {
3087         if (__pFindWordControl && __pFindWordControl->GetShowState() == true)
3088         {
3089                 __pAddressbar->SetShowState(false);
3090         }
3091         else
3092         {
3093                 if (__pAddressbar != null && __pAddressbar->GetShowState() == false)
3094                 {
3095                         __pAddressbar->SetShowState(true);
3096                         __pAddressbar->SetBounds(Rectangle(0,0,GetClientAreaBounds().width,__pAddressbar->GetHeight()));
3097                         __pAddressbar->SetAddressbarURLFocus();
3098                 }
3099         }
3100
3101         RelayoutControls(false);
3102 }
3103
3104 void
3105 MainForm::OnAddressBarKeypadWillOpen(const Addressbar& addBar)
3106 {
3107         __pFooterPanel->SetShowState(false);
3108 }
3109
3110 void
3111 MainForm::OnAddressBarKeypadBoundsChanged(const Addressbar& addBar)
3112 {
3113         AppLog("KeypadBoundsChanged");
3114         RelayoutControls(false);
3115 }
3116
3117 void
3118 MainForm::OnPageTitleReceived(const Tizen::Base::String& title)
3119 {
3120         if (__pWindowInfo)
3121         {
3122                 __pWindowInfo->pageTitle = title;
3123                 if (__pWebViewer != null)
3124                 {
3125                         __pWindowInfo->pageUrl = __pWebViewer->GetUrl();
3126                 }
3127         }
3128         if (__pAddressbar != null && __pWebViewer != null)
3129         {
3130                 SetUrl(__pWebViewer->GetUrl());
3131                 __pAddressbar->Invalidate(true);
3132         }
3133 }
3134
3135 void
3136 MainForm::UpdateFavicon(void)
3137 {
3138         bool urlImageType = false;
3139         String *tempPath = __pWebViewer->EvaluateJavascriptN(L"var getFavicon = function() {      var favicon = '/favicon.ico';      var nodeList = document.getElementsByTagName('link');    if(nodeList) {  for (var i = 0; i < nodeList.length; i++)      {          if ((nodeList[i].getAttribute('rel') == 'icon')||(nodeList[i].getAttribute('rel') == 'shortcut icon'))         {              favicon = nodeList[i].getAttribute('href');          }      } }     return favicon;          };  getFavicon();");
3140         Bitmap* pBitmap = null;
3141
3142         if (tempPath && tempPath->GetLength() > 0 && tempPath->CompareTo(L"undefined") != 0)
3143         {
3144                 if (__pWindowInfo != null)
3145                 {
3146                         Uri url;
3147                         url.SetUri(*tempPath);
3148                         if (url.GetHost().GetLength() == 0)
3149                         {
3150                                 Uri webUrl;
3151                                 webUrl.SetUri(__pWebViewer->GetUrl());
3152                                 result r = url.SetHost(webUrl.GetHost());
3153                                 if(IsFailed(r))
3154                                 {
3155                                         delete tempPath;
3156                                         return;
3157                                 }
3158                         }
3159                         if (url.GetScheme().GetLength() == 0)
3160                         {
3161                                 Uri webUrl;
3162                                 webUrl.SetUri(__pWebViewer->GetUrl());
3163                                 url.SetScheme(webUrl.GetScheme());
3164                         }
3165                         __pWindowInfo->faviconUrl = url.ToString();
3166
3167                         pBitmap = __pWebViewer->GetFaviconN();
3168
3169                         if (pBitmap != null)
3170                         {
3171                                 if (__pWindowInfo->pFavicon != NULL)
3172                                 {
3173                                         __pWindowInfo->pFavicon = null;
3174                                 }
3175                                 __pWindowInfo->pFavicon = new(std::nothrow) Bitmap();
3176                                 __pWindowInfo->pFavicon->Construct(*pBitmap,Rectangle(0,0,pBitmap->GetWidth(),pBitmap->GetHeight()));
3177
3178                                 __pAddressbar->SetFaviconBitmap(*__pWindowInfo->pFavicon);
3179
3180                                 FaviconManager::GetInstance()->SaveFavicon(*__pWindowInfo->pFavicon, __pWindowInfo->faviconUrl);
3181                         }
3182                         else if(__pWindowInfo->pFavicon != null)
3183                         {
3184                                 __pAddressbar->SetFaviconBitmap(*__pWindowInfo->pFavicon);
3185                         }
3186                         else
3187                         {
3188                                 Bitmap *pDefaultBmp = FaviconManager::GetInstance()->GetDefaultFaviconN();
3189                                 if(pDefaultBmp != null)
3190                                 {
3191                                         __pAddressbar->SetFaviconBitmap(*pDefaultBmp);
3192                                 }
3193                         }
3194                 }
3195                 delete tempPath;
3196         }
3197         else
3198         {
3199                 delete tempPath;
3200                 AppLogDebug("Error occured: %s", GetErrorMessage(GetLastResult()));
3201         }
3202
3203 }
3204
3205
3206 bool
3207 MainForm::OnLoadingRequested(const Tizen::Base::String& url,
3208                 Tizen::Web::Controls::WebNavigationType type)
3209 {
3210         // when load new page if find word panel is open its show state is false
3211         ShowFindWordPanel(false);
3212
3213         __pFooterPanel->Invalidate(true);
3214
3215         Uri uriInfo;
3216         uriInfo.SetUri(url);
3217
3218         if(url.Contains(IDS_TIZEN_SERVICE))
3219         {
3220                 String appId;
3221                 String delim(L":;,");
3222
3223                 // Creates a StringTokenizer instance
3224                 StringTokenizer strTok(url, delim);
3225
3226                 int count = strTok.GetTokenCount();     // count == 4
3227
3228                 HashMap *pMap = new HashMap();
3229                 pMap->Construct();
3230
3231                 String token;
3232                 String key;
3233                 String value;
3234                 while (strTok.HasMoreTokens())
3235                 {
3236                         AppLog("Token: %ls", token.GetPointer());
3237                         strTok.GetNextToken(token);         // Tizen, StringTokenizer, Sample, code
3238                         if(token.Contains(IDS_APPID))
3239                         {
3240                                 token.SubString(6, appId);
3241                                 AppLog("AppID:%ls", appId.GetPointer());
3242                         }
3243                         else if(token.Contains("="))
3244                         {
3245                                 String *pKey = new String();
3246                                 String *pValue = new String();
3247                                 int index = -1;
3248                                 token.IndexOf("=", 0, index);
3249                                 if(index != -1)
3250                                 {
3251                                         token.SubString(0, index, *pKey);
3252                                         token.SubString(index + 1, *pValue);
3253                                         pMap->Add(pKey, pValue);
3254                                 }
3255                         }
3256                 }
3257                 if(appId != "")
3258                 {
3259                         AppControl *pAppControl = null;
3260                         String operationId = L"http://tizen.org/appcontrol/operation/main";
3261                         pAppControl = dynamic_cast<AppControl*>(AppManager::FindAppControlN(appId, operationId));
3262                         if(pAppControl)
3263                         {
3264                                 result r = pAppControl->Start(null, null, pMap, null);
3265                         }
3266                         else
3267                         {
3268                                 AppLogException("AppControl not found");
3269                         }
3270                         return true;
3271                 }
3272         }
3273
3274         if ( __pAddressbar != null && __pAddressbar->GetShowState() == true)
3275         {
3276                 __pAddressbar->SetShowState(false);
3277                 OnAddressCancelledClicked(*__pAddressbar);
3278                 __pAddressbar->Invalidate(true);
3279         }
3280         return false;
3281 }
3282
3283 DecisionPolicy
3284 MainForm::OnWebDataReceived(const Tizen::Base::String& mime,
3285                 const Tizen::Net::Http::HttpHeader& httpHeader)
3286 {
3287         return Tizen::Web::Controls::WEB_DECISION_CONTINUE;
3288 }
3289
3290
3291 void
3292 MainForm::OnWebPageBlockSelected(Tizen::Web::Controls::Web& source, Tizen::Graphics::Point& startPoint, Tizen::Graphics::Point& endPoint)
3293 {
3294         AppLog("MainForm::OnWebPageBlockSelected");
3295         if (__pHitElementResult != null)
3296         {
3297                 delete __pHitElementResult;
3298                 __pHitElementResult = null;
3299         }
3300
3301         if (__pWebViewer != null)
3302         {
3303                 AppLog("MainForm::OnWebPageBlockSelected web not null");
3304                 __pHitElementResult = __pWebViewer->GetElementByPointN(endPoint);
3305         }
3306
3307         if (__pHitElementResult == null)
3308         {
3309                 return;
3310         }
3311
3312         if (__pHitElementResult->HasImage() != true)
3313         {
3314                 String tagName = __pHitElementResult->GetTagName();
3315                 String type = __pHitElementResult->GetAttributeValue("type");
3316
3317                 __currentSelectedStr.Clear();
3318                 AppLog("__currentSelectedStr after clear %ls",__currentSelectedStr.GetPointer());
3319                 __currentSelectedStr = __pWebViewer->GetTextFromBlock();
3320                 AppLog("__currentSelectedStr after GetTextFromBlock %ls",__currentSelectedStr.GetPointer());
3321
3322                 if (((tagName.CompareTo(L"INPUT") == 0)  || tagName.CompareTo(L"TEXTAREA") == 0) && __isLongPressedDone == true)
3323                 {
3324                         AppLog("MainForm::OnWebPageBlockSelected show paste option");
3325
3326                         InitSelectTextContextMenu(endPoint,true);
3327                         __pImageMenu->SetShowState(true);
3328                         __pImageMenu->Show();
3329                         __pImageMenu->Invalidate(true);
3330                 }
3331                 else if(__isLongPressedDone == true)
3332                 {
3333                         AppLog("MainForm::OnWebPageBlockSelected no paste option");
3334
3335                         if(__pHitElementResult->GetUrl().GetLength() > 0)
3336                         {
3337                                 __currentSelectedStr.Clear();
3338                                 __currentSelectedStr = __pHitElementResult->GetUrl();
3339                         }
3340                         InitSelectTextContextMenu(endPoint,false);
3341                         __pImageMenu->SetShowState(true);
3342                         __pImageMenu->Show();
3343                         __pImageMenu->Invalidate(true);
3344                 }
3345
3346                 AppLog("MainForm::OnWebPageBlockSelected block text is %ls",__currentSelectedStr.GetPointer());
3347                 AppLog("MainForm::OnWebPageBlockSelected tag name is %ls",tagName.GetPointer());
3348                 AppLog("MainForm::OnWebPageBlockSelected type name is %ls",type.GetPointer());
3349         }
3350
3351 }
3352
3353 void
3354 MainForm::OnWebPageShowRequested(Tizen::Web::Controls::Web& source)
3355 {
3356
3357 }
3358
3359 Web*
3360 MainForm::OnWebWindowCreateRequested(void)
3361 {
3362         WindowInfo* pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewScene();
3363
3364         if (pNewWindowInfo == null)
3365         {
3366                 return null;
3367         }
3368         result r = E_SUCCESS;
3369         SceneManager* pSceneManager = SceneManager::GetInstance();
3370         if (pSceneManager == NULL)
3371         {
3372                 return null;
3373         }
3374         ArrayList* pArgList = new(std::nothrow) ArrayList();
3375         if (pArgList == NULL)
3376         {
3377                 return null;
3378         }
3379         r = pArgList->Construct();
3380         if (r == E_SUCCESS)
3381         {
3382                 pNewWindowInfo->isJavascriptInitiated = true;
3383                 pArgList->Add(*pNewWindowInfo);
3384                 r = pSceneManager->GoForward(ForwardSceneTransition(pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
3385                 delete pArgList;
3386                 if (IsFailed(r))
3387                 {
3388                         AppLogDebug("EditHistoryListForm::OnFormBackRequested Failed to GoBackward %s",GetErrorMessage(r));
3389                         return null;
3390                 }
3391         } else {
3392                 delete pArgList;
3393         }
3394
3395         return pNewWindowInfo->pCurrentWeb;
3396 }
3397
3398 void
3399 MainForm::RelayoutControls(bool showAddressbar)
3400 {
3401         __webControlPosition.y = 0;
3402         __webControlHeight = GetClientAreaBounds().height;
3403         AppLog("Client area height: %d", __webControlHeight);
3404
3405         AppLog("Client area height: %d", __webControlHeight);
3406         if(__pAddressbar != null && __pAddressbar->GetShowState() == true)
3407         {
3408                 __webControlPosition.y += __pAddressbar->GetHeight();
3409                 __webControlHeight -= __pAddressbar->GetHeight();
3410                 __pAddressbar->SetBounds(0, 0, __pAddressbar->GetWidth(), __pAddressbar->GetHeight());
3411         }
3412         else if(__pFindWordControl != null && __pFindWordControl->GetShowState() == true)
3413         {
3414                 __webControlPosition.y += __pFindWordControl->GetHeight();
3415                 __webControlHeight -= __pFindWordControl->GetHeight();
3416                 __pFindWordControl->SetBounds(0, 0, GetClientAreaBounds().width, __pFindWordControl->GetHeight());
3417         }
3418
3419         if(__pFooterPanel != null && __pFooterPanel->GetShowState() == true)
3420         {
3421                 __webControlHeight -= __pFooterPanel->GetHeight();
3422                 __pFooterPanel->SetBounds(0, __webControlPosition.y + __webControlHeight, GetClientAreaBounds().width, __pFooterPanel->GetHeight());
3423         }
3424         if (__pWebViewer != null && __pWebViewer->GetShowState() == true)
3425         {
3426                 __pWebViewer->SetBounds(0, __webControlPosition.y, GetClientAreaBounds().width, __webControlHeight);
3427                 __pWebViewer->Invalidate(false);
3428         }
3429         if(__pMostVisitedListView != null && __pAddressbar != null && __pFooterPanel != null)
3430         {
3431                 __pMostVisitedListView->SetBounds(Tizen::Graphics::Rectangle(0,__webControlPosition.y , GetClientAreaBounds().width, __webControlHeight));
3432         }
3433
3434         Invalidate(true);
3435 }
3436
3437 void
3438 MainForm::ShowFindWordPanel(bool show , bool isTouchPressed)
3439 {
3440         if (__pFindWordControl == null)
3441         {
3442                 return;
3443         }
3444         if (show == true)
3445         {
3446                 InitFindWordPanel();
3447 //              __pFindWordEditField->SetText(__currentSearchStr);
3448                 //__pFindWordCountLabel->SetText(L"");
3449 //              __pFindWordCountLabel->SetText(L"0/0");
3450                 __pFindWordControl->SetShowState(true);
3451         }
3452         else
3453         {
3454                 if(__pFindWordControl != null)
3455                 {
3456                         __pFindWordControl->SetShowState(false);
3457                 }
3458         }
3459
3460         AppLog("MainForm::ShowFindWordPanel %d",show);
3461         if (show && !isTouchPressed)
3462         {
3463                 if (__pFindWordEditField)
3464                 {
3465                         __pFindWordEditField->SetFocus();
3466                         __pFindWordEditField->ShowKeypad();
3467                 }
3468         }
3469         else
3470         {
3471                 if (__pFindWordEditField)
3472                         __pFindWordEditField->HideKeypad();
3473         }
3474
3475         RelayoutControls(false);
3476 }
3477
3478 void
3479 MainForm::StartWordSearch()
3480 {
3481         //Get the count of occurances of the word in the current page
3482         __maxOccurrances = 0;
3483         __currentWordIndex = 0;
3484
3485         __pFindWordPrev->SetEnabled(false);
3486         String *pCountStr = null;
3487         __pWebViewer->SearchTextAllAsync(__currentSearchStr, false);
3488         /*__pWebViewer->EvaluateJavascriptN(L"document.body.textContent.match(/"  + __currentSearchStr + "/gi).length;");
3489         if (pCountStr != null)
3490         {
3491                 Integer::Parse(*pCountStr, 10, __maxOccurrances);
3492                 delete pCountStr;
3493         }
3494
3495         AppLogDebug("'%ls' is found %d times", __currentSearchStr.GetPointer(), __maxOccurrances);
3496          */
3497
3498 }
3499
3500 void MainForm::OnTextFound(int totalCount, int currentOrdinal)
3501 {
3502         AppLog("MainForm::OnTextFound totalCount %d",totalCount);
3503         AppLog("MainForm::OnTextFound currentOrdinal %d",currentOrdinal);
3504
3505         if(totalCount == -1 || totalCount == 0)
3506         {
3507                 __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),64,__pFindWordCountLabel->GetHeight());
3508                 __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),214+80,__pFindWordEditField->GetHeight());
3509 //              return;
3510         }
3511         else if(totalCount > 100)
3512         {
3513                 __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),124,__pFindWordCountLabel->GetHeight());
3514                 __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),174,__pFindWordEditField->GetHeight());
3515         }
3516         else
3517         {
3518                 __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),124,__pFindWordCountLabel->GetHeight());
3519                 __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),174,__pFindWordEditField->GetHeight());
3520         }
3521
3522         __maxOccurrances = totalCount;
3523         __currentWordIndex = currentOrdinal;
3524
3525         //Reset the UI controls as per the maxOccurrance value
3526         if (totalCount <= 0)
3527         {
3528                 AppLog("Word not found");
3529                 //Show error notification to user
3530                 __pFindWordNext->SetEnabled(false);
3531                 __pFindWordCountLabel->SetText(L"0/0");
3532                 __pFindWordNext->Invalidate(false);
3533                 __pFindWordPrev->Invalidate(false);
3534                 __pFindWordCountLabel->Invalidate(false);
3535                 return;
3536         }
3537
3538         if (totalCount == 1)
3539         {
3540                 __pFindWordNext->SetEnabled(false);
3541         }
3542         else
3543         {
3544                 __pFindWordNext->SetEnabled(true);
3545         }
3546
3547         String countStr = L"";
3548         countStr.Append(__currentWordIndex);
3549         countStr.Append(L"/");
3550         countStr.Append(__maxOccurrances);
3551         __pFindWordCountLabel->SetText(countStr);
3552         //      __pFindWordCountLabel->SetShowState(true);
3553         __pFindWordCountLabel->Invalidate(false);
3554
3555         //FindNextWord(true);
3556         //Update the controls
3557         __pFindWordNext->Invalidate(false);
3558         __pFindWordPrev->Invalidate(false);
3559         __pFindWordCountLabel->Invalidate(false);
3560 }
3561
3562 void
3563 MainForm::FindNextWord(bool next)
3564 {
3565         if (next == true)
3566         {
3567                 if (__pWebViewer->SearchText(__currentSearchStr, true) == true)
3568                 {
3569                         if(__currentWordIndex < __maxOccurrances)
3570                         {
3571                                 __currentWordIndex++;
3572                         }
3573                 }
3574         }
3575         else
3576         {
3577                 if (__pWebViewer->SearchText(__currentSearchStr, false) == true)
3578                 {
3579                         if(__currentWordIndex > 1)
3580                         {
3581                                 __currentWordIndex--;
3582                         }
3583                 }
3584         }
3585
3586         String countStr = L"";
3587         countStr.Append(__currentWordIndex);
3588         countStr.Append(L"/");
3589         countStr.Append(__maxOccurrances);
3590         __pFindWordCountLabel->SetText(countStr);
3591         //      __pFindWordCountLabel->SetShowState(true);
3592         __pFindWordCountLabel->Invalidate(false);
3593         if (__currentWordIndex >= __maxOccurrances)
3594         {
3595                 __pFindWordNext->SetEnabled(false);
3596         }
3597         else
3598         {
3599                 __pFindWordNext->SetEnabled(true);
3600         }
3601         if (__currentWordIndex <= 1)
3602         {
3603                 __pFindWordPrev->SetEnabled(false);
3604         }
3605         else
3606         {
3607                 __pFindWordPrev->SetEnabled(true);
3608         }
3609         __pFindWordPrev->Invalidate(false);
3610         __pFindWordNext->Invalidate(false);
3611         __pFindWordCountLabel->Invalidate(false);
3612         __pFindWordControl->Invalidate(true);
3613 }
3614 void
3615 MainForm::OnWebKeypadWillOpen(Tizen::Web::Controls::Web& source)
3616 {
3617         AppLog("MainForm::OnWebKeypadWillOpen");
3618         __isWebKeypadOpened = true;
3619         //      OnAddressBarKeypadOpened(*__pAddressbar);
3620 }
3621
3622 void
3623 MainForm::OnWebKeypadOpened(Tizen::Web::Controls::Web& source)
3624 {
3625
3626         if(__pFindWordControl && __pFindWordControl->GetShowState() == true)
3627         {
3628                 __currentSearchStr = L"";
3629                 __currentWordIndex = 0;
3630                 __maxOccurrances = 0;
3631                 __pFindWordEditField->SetText(L"");
3632                 __pFindWordNext->SetEnabled(false);
3633                 __pFindWordPrev->SetEnabled(false);
3634                 __pFindWordCountLabel->SetText(L"0/0");
3635                 __pWebViewer->SearchText(L"aaaabbbbcccc",true);
3636                 __pFindWordControl->SetShowState(false);
3637                 if (__pFindWordEditField)
3638                         __pFindWordEditField->HideKeypad();
3639         }
3640
3641
3642         if (__pWebViewer != null && __pFooterPanel != null)
3643         {
3644                 AppLog("MainForm::OnOrientationChanged GetClientAreaBounds().height %d ", GetClientAreaBounds().height);
3645                 if(__pAddressbar != null)
3646                 {
3647                         __pAddressbar->SetShowState(false);
3648                 }
3649                 if(__pFindWordControl != null)
3650                 {
3651                         __pFindWordControl->SetShowState(false);
3652                 }
3653                 __pFooterPanel->SetShowState(false);
3654                 __pWebViewer->SetBounds(Rectangle(0, 0,GetClientAreaBounds().width, GetClientAreaBounds().height));
3655         }
3656         Invalidate(true);
3657 }
3658
3659 void
3660 MainForm::OnWebKeypadClosed(Tizen::Web::Controls::Web& source)
3661 {
3662         __pFooterPanel->SetShowState(true);
3663         OnAddressBarKeypadClosed(*__pAddressbar);
3664         __isWebKeypadOpened = false;
3665 }
3666
3667 void
3668 MainForm::OnTouchDoublePressed(const Control& source, const Point& currentPosition, const TouchEventInfo& touchInfo)
3669 {
3670         Control* temp = const_cast< Control* >(&source);
3671         Header* pHeader = dynamic_cast< Header* >(temp);
3672         if (pHeader != null)
3673         {
3674                 //Header double - clicked
3675                 AppLog("Header double clicked");
3676         }
3677         if(__pFindWordControl)
3678         {
3679                 AppLog("MainForm::OnTouchPressed %d",__pFindWordControl->GetShowState());
3680                 ShowFindWordPanel(__pFindWordControl->GetShowState(), true);
3681         }
3682
3683
3684         AppLog("MainScene::OnTouchDoublePressed");
3685         bool isReaderEnabled = SettingPresentationModel::GetInstance()->IsRunReaderEnabled();
3686         if (isReaderEnabled == true)
3687         {
3688                 if (__pReaderData)
3689                 {
3690                         delete __pReaderData;
3691                         __pReaderData = null;
3692                 }
3693                 String filePath = Tizen::App::UiApp::GetInstance()->GetAppRootPath();
3694                 filePath.Append(L"data/reader.js");
3695                 File file;
3696                 char buffer[10];
3697                 char buffer2[5];
3698                 int i;
3699                 int readCnt;
3700                 result r = E_SUCCESS;
3701                 FileAttributes attr;
3702
3703                 File::GetAttributes(filePath,attr);
3704                 // Creates file
3705                 r = file.Construct(filePath, L"r+");
3706                 if (IsFailed(r))
3707                 {
3708                         AppLogDebug("File construct failed with %s", GetErrorMessage(r));
3709                         return;
3710                 }
3711                 char* pScript = new(std::nothrow) char[attr.GetFileSize()+1];
3712                 if(pScript == null)
3713                 {
3714                         AppLogDebug("Memory allocation for file failed %s", GetErrorMessage(r));
3715                         return;
3716                 }
3717                 file.Read(pScript,attr.GetFileSize());
3718
3719                 AppLogDebug("scipt length %d",strlen(pScript));
3720                 String strScript = L"";
3721                 strScript.Append(pScript);
3722                 __pReaderData = __pWebViewer->EvaluateJavascriptN(strScript);
3723                 if (!__pReaderData)
3724                 {
3725                         AppLog("MainScene::data is null Error :%s",GetErrorMessage(GetLastResult()));
3726                         return;
3727                 }
3728                 AppLogDebug("evaluateJavascript result %s , __pReaderData %ls",GetErrorMessage(GetLastResult()),__pReaderData->GetPointer());
3729                 if (__pReaderData->CompareTo(L"undefined") != 0 && __pReaderData->CompareTo(L"") != 0)
3730                 {
3731                         //__pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_READER);
3732                         SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_READER);
3733                 }
3734                 delete[] pScript;
3735         }
3736 }
3737
3738 void MainForm::OnTouchLongPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
3739 {
3740         AppLog("abcde::MainForm::OnTouchLongPressed %d, %d" ,currentPosition.x,currentPosition.y);
3741
3742         if (__pHitElementResult != null)
3743         {
3744                 delete __pHitElementResult;
3745                 __pHitElementResult = null;
3746         }
3747
3748         if (__pWebViewer != null)
3749         {
3750                 AppLog("MainForm::OnTouchLongPressed web not null");
3751                 __pHitElementResult = __pWebViewer->GetElementByPointN(currentPosition);
3752         }
3753
3754         if (__pHitElementResult == null)
3755         {
3756                 return;
3757         }
3758
3759         if (__pHitElementResult->HasImage() == true)
3760         {
3761                 InitImageContextMenu(currentPosition);
3762                 __pImageMenu->SetShowState(true);
3763                 __pImageMenu->Show();
3764                 __pImageMenu->Invalidate(true);
3765         }
3766         else if(__pHitElementResult->HasUrl() == true)
3767         {
3768                 String tempURl = __pHitElementResult->GetUrl();
3769                 AppLog("tempURl is %ls", tempURl.GetPointer());
3770                 const Bitmap* pBitmap = __pHitElementResult->GetImage();
3771                 if (pBitmap != null)
3772                 {
3773                         AppLog("not null");
3774                 }
3775                 else
3776                 {
3777                         AppLog(null);
3778                 }
3779                 InitImageLinkContextMenu(currentPosition);
3780                 __pImageMenu->SetShowState(true);
3781                 __pImageMenu->Show();
3782                 __pImageMenu->Invalidate(true);
3783         }
3784         else
3785         {
3786                 String tagName = __pHitElementResult->GetTagName();
3787                 String type = __pHitElementResult->GetAttributeValue("type");
3788                 String value = __pHitElementResult->GetAttributeValue(L"value");
3789                 String innerHtml = __pHitElementResult->GetAttributeValue(L"innerHTML");
3790
3791                 __currentSelectedStr.Clear();
3792                 __currentSelectedStr = __pWebViewer->GetTextFromBlock();
3793
3794                 AppLog("tag name is %ls", tagName.GetPointer());
3795                 AppLog("type is %ls", type.GetPointer());
3796                 AppLog("innerHtml is %ls", innerHtml.GetPointer());
3797
3798                 if (((tagName.CompareTo(L"INPUT") == 0)  || tagName.CompareTo(L"TEXTAREA") == 0) &&  value.GetLength() == 0 && innerHtml.GetLength() == 0 && __isWebKeypadOpened == true)
3799                 {
3800                         AppLog("MainForm::OnWebPageBlockSelected show paste option");
3801
3802                         InitSelectTextContextMenu(currentPosition,true, true);
3803                         if(__pImageMenu)
3804                         {
3805 //                              __pImageMenu->SetShowState(true);
3806 //                              __pImageMenu->Show();
3807 //                              __pImageMenu->Invalidate(true);
3808                         }
3809                 }
3810                 __isLongPressedDone = true;
3811                 result r =__pWebViewer->SetBlockSelectionPosition(currentPosition);
3812                 AppLog("setselectionselectedornot %s",GetErrorMessage(r));
3813
3814         }
3815         __inputEventToBeSupressed = true;
3816 }
3817
3818 void
3819 MainForm::OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
3820 {
3821         AppLog("MainForm::OnTouchReleased");
3822
3823         HitElementResult* pHitElement = __pWebViewer->GetElementByPointN(currentPosition);
3824         if(pHitElement != null && pHitElement->HasUrl() == true && __inputEventToBeSupressed == true)
3825         {
3826                 __pWebViewer->ConsumeInputEvent();
3827         }
3828         if(pHitElement != null)
3829         {
3830                 delete pHitElement;
3831         }
3832         __inputEventToBeSupressed = false;
3833 }
3834
3835 bool
3836 MainForm::OnTouchPressed(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
3837 {
3838
3839         return true;
3840 }
3841
3842 bool
3843 MainForm::OnTouchReleased(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
3844 {
3845         if(__pFindWordControl && __pFindWordControl->GetShowState() == true)
3846         {
3847                 __currentSearchStr = L"";
3848                 __currentWordIndex = 0;
3849                 __maxOccurrances = 0;
3850                 __pFindWordEditField->SetText(L"");
3851                 __pFindWordNext->SetEnabled(false);
3852                 __pFindWordPrev->SetEnabled(false);
3853                 __pFindWordCountLabel->SetText(L"0/0");
3854                 __pWebViewer->SearchText(L"aaaabbbbcccc",true);
3855                 __pFindWordControl->SetShowState(false);
3856                 __pFindWordEditField->HideKeypad();
3857         }
3858         if(__pAddressbar->GetShowState() == false)
3859         {
3860                 __pAddressbar->SetShowState(true);
3861                 __pAddressbar->SetAddressbarURLFocus();
3862 //              __pFooterUrlField->SetFocusable(false);
3863                 __pFooterPanel->SetShowState(false);
3864         }
3865
3866         return true;
3867 }
3868
3869 bool
3870 MainForm::OnTouchMoved(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
3871 {
3872         return true;
3873 }
3874
3875 bool
3876 MainForm::OnTouchCanceled(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
3877 {
3878         return true;
3879 }
3880
3881 bool
3882 MainForm::OnPreviewTouchPressed(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
3883 {
3884         return true;
3885 }
3886
3887 bool
3888 MainForm::OnPreviewTouchReleased(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
3889 {
3890         return true;
3891 }
3892
3893 bool
3894 MainForm::OnPreviewTouchMoved(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
3895 {
3896         return true;
3897 }
3898
3899 void
3900 MainForm::OnOrientationChanged (const Tizen::Ui::Control &source, Tizen::Ui::OrientationStatus orientationStatus)
3901 {
3902         AppLog("MainForm::OnOrientationChanged GetClientAreaBounds %d, %d",GetClientAreaBounds().width,GetClientAreaBounds().height);
3903         int widthContextItem = 0;
3904         if(__pFindWordControl != null)
3905                 ShowFindWordPanel(__pFindWordControl->GetShowState(), false);
3906         if ( __pFooterLabel != null)
3907         {
3908                 Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_SEARCH_INPUT_FIELD_BG, __pFooterLabel->GetWidth(), __pFooterLabel->GetHeight());
3909                 if(pBitmap != null)
3910                 {
3911                         __pFooterLabel->SetBackgroundBitmap(*pBitmap);
3912                         delete pBitmap;
3913                 }
3914         }
3915
3916         if (__pFindWordBgLabel != null)
3917         {
3918                 Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_FINDWORD_INPUT_FIELD_BG, __pFindWordBgLabel->GetWidth(), __pFindWordBgLabel->GetHeight());
3919                 if (pBitmap != null)
3920                 {
3921                         __pFindWordBgLabel->SetBackgroundBitmap(*pBitmap);
3922                         delete pBitmap;
3923                 }
3924         }
3925
3926         if(__pMenu != null)
3927                 __pMenu->SetShowState(false);
3928         if( GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
3929         {
3930                 widthContextItem = WIDTH_CONTEXT_MENU_BUTTON_LANDSCAPE;
3931         }
3932         else
3933         {
3934                 widthContextItem = WIDTH_CONTEXT_MENU_BUTTON_PORTRAIT;
3935         }
3936
3937         if (__pFooterPanel)
3938         {
3939                 AppLog("__pFooterPanel->GetShowState() is true");
3940                 InitFooter();
3941                 __pFooterPanel->SetBounds(0, GetClientAreaBounds().height - __pFooterPanel->GetHeight(), __pFooterPanel->GetWidth(), __pFooterPanel->GetHeight());
3942                 __pFooterPanel->Invalidate(true);
3943         }
3944         InitAddressbar();
3945
3946         if(__pMoreButton && __pMenu)
3947         {
3948                 Point p = Point(__pMoreButton->GetX() + __pMoreButton->GetWidth() / 2, GetBounds().height - __pMoreButton->GetHeight());
3949                 __pMenu->SetAnchorPosition(p);
3950                 __pMenu->Invalidate(true);
3951         }
3952
3953         String homePage = SettingPresentationModel::GetInstance()->GetHomepage();
3954         if (homePage.CompareTo((L"IDS_BR_BODY_MOST_VISITED_SITES")) == 0)
3955         {
3956                 InitMostVisitedSitesView(orientationStatus);
3957         }
3958
3959         RelayoutControls(false);
3960         if (__pArticleReaderPanel != null)
3961         {
3962                 if (__pArticleReaderPanel->GetShowState() == true)
3963                 {
3964                         __pArticleReaderPanel->SetBounds((GetClientAreaBounds().width - __pArticleReaderPanel->GetWidth())/2,(GetClientAreaBounds().height - __pArticleReaderPanel->GetHeight())/2, __pArticleReaderPanel->GetWidth(), __pArticleReaderPanel->GetHeight());
3965
3966                         if (__pBlankPanel != null)
3967                                 __pBlankPanel->SetBounds(0,0,GetClientAreaBounds().width,GetClientAreaBounds().height);
3968
3969                         if (__pWebReader != null)
3970                         {
3971                                 __pWebReader->SetBounds(Rectangle(2,2, __pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight() - 96));
3972                         }
3973                         Bitmap* pBitmap = CommonUtil::GetNinepatchedBitmapN(L"I01_popup_bg.9.png",__pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight());
3974                         Bitmap* pSrcBitmap = CommonUtil::GetNinepatchedBitmapN(L"I01_popup_bottom_bg.9.png",__pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight());
3975
3976                         if ( pBitmap != null && pSrcBitmap != null)
3977                         {
3978                                 AppLog("CreateReaderPanel ninepatchbitmap found");
3979                                 pBitmap->Merge(Point(0,__pArticleReaderPanel->GetHeight() - 96),*pSrcBitmap,Rectangle(0,0,pSrcBitmap->GetWidth(),pSrcBitmap->GetHeight()));
3980                         }
3981
3982                         __pArticleReaderLabel->SetBounds(Rectangle(__pArticleReaderPanel->GetX(),__pArticleReaderPanel->GetY(),__pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight()));
3983                         __pArticleReaderLabel->SetBackgroundBitmap(*pBitmap);
3984                         if (pBitmap != null)
3985                         {
3986                                 delete pBitmap;
3987                                 pBitmap = null;
3988                         }
3989                         if (pSrcBitmap != null)
3990                         {
3991                                 delete pSrcBitmap;
3992                                 pSrcBitmap = null;
3993                         }
3994                 }
3995         }
3996         Invalidate(true);
3997         
3998     if (__pAddressbar != null)
3999         {
4000                 int width = GetClientAreaBounds().width;
4001                 __pAddressbar->OrientationChanged(width);
4002         }
4003 }
4004
4005 void
4006 MainForm::OnSettingsChange(int settingvalue)
4007 {
4008         AppLogDebug("MainForm::OnSettingsChange entered");
4009
4010         if(settingvalue == (int)REGISTRY_SETTING_HOMEPAGE)
4011         {
4012                 __pAddressbar->ResetGuideText();
4013         }
4014         if (__pWebViewer == null)
4015         {
4016                 AppLogDebug("Webviewer is not initialized yet.");
4017                 return;
4018         }
4019
4020         if (settingvalue == (int) REGISTRY_SETTING_DEFAULT_VIEW)
4021         {
4022                 WebSetting settings = __pWebViewer->GetSetting();
4023                 if (SettingPresentationModel::GetInstance()->GetDefaultView().CompareTo(CommonUtil::GetString(L"IDS_BR_BODY_FIT_TO_WIDTH")) == 0)
4024                 {
4025                         settings.SetAutoFittingEnabled(true);
4026                 }
4027                 else if (SettingPresentationModel::GetInstance()->GetDefaultView().CompareTo(CommonUtil::GetString(L"IDS_BR_BODY_READABLE")) == 0)
4028                 {
4029                         settings.SetAutoFittingEnabled(false);
4030                 }
4031                 __pWebViewer->SetSetting(settings);
4032         }
4033         else if (settingvalue == (int) REGISTRY_SETTING_RUN_JAVASCRIPT)
4034         {
4035                 WebSetting settings = __pWebViewer->GetSetting();
4036                 settings.SetJavascriptEnabled(SettingPresentationModel::GetInstance()->IsRunJavascriptEnabled());
4037                 __pWebViewer->SetSetting(settings);
4038         }
4039         else if (settingvalue == (int) REGISTRY_SETTING_DISPLAY_IMAGES)
4040         {
4041                 WebSetting settings = __pWebViewer->GetSetting();
4042                 settings.SetAutoImageLoadEnabled(SettingPresentationModel::GetInstance()->IsDisplayImagesEnabled());
4043                 __pWebViewer->SetSetting(settings);
4044         }
4045         else if (settingvalue == (int) REGISTRY_SETTING_BLOCK_POPUP)
4046         {
4047                 WebSetting settings = __pWebViewer->GetSetting();
4048                 settings.SetJavaScriptPopupEnabled(SettingPresentationModel::GetInstance()->IsBlockPopUp());
4049                 __pWebViewer->SetSetting(settings);
4050         }
4051         else if (settingvalue == (int) REGISTRY_SETTING_ACCEPT_COOKIES)
4052         {
4053                 if (__pWebViewer)
4054                 {
4055                         __pWebViewer->SetCookieEnabled(SettingPresentationModel::GetInstance()->IsCookiesEnabled());
4056                 }
4057         }
4058
4059         else if (settingvalue == (int) REGISTRY_SETTING_SHOW_SECURITY_WARNINGS)
4060         {
4061                 WebSetting settings = __pWebViewer->GetSetting();
4062                 if (SettingPresentationModel::GetInstance()->IsSecurityWarningsEnabled() == true)
4063                 {
4064                         settings.SetCertificateErrorHandlingMode(WEB_CERTIFICATE_ERROR_HANDLING_MODE_USER_CONFIRM);
4065                 }
4066                 else
4067                 {
4068                         settings.SetCertificateErrorHandlingMode(WEB_CERTIFICATE_ERROR_HANDLING_MODE_CONTINUE);
4069                 }
4070                 __pWebViewer->SetSetting(settings);
4071         }
4072         else if (settingvalue == (int) REGISTRY_SETTING_READER_FONT_SIZE)
4073         {
4074                 if (__pWebReader)
4075                 {
4076                         AppLogDebug("IntMainForm fontsize Changed to %d",SettingPresentationModel::GetInstance()->GetReaderFontSize());
4077                         WebSetting settings = __pWebReader->GetSetting();
4078                         settings.SetFontSize(SettingPresentationModel::GetInstance()->GetReaderFontSize());
4079                         __pWebReader->SetSetting(settings);
4080                 }
4081         }
4082 }
4083
4084 void
4085 MainForm::OnSettingsReset()
4086 {
4087         if (__pWebViewer)
4088         {
4089                 __pWebViewer->SetCookieEnabled(SettingPresentationModel::GetInstance()->IsCookiesEnabled());
4090                 __pWebViewer->SetSetting(SettingPresentationModel::GetInstance()->GetWebSettings());
4091         }
4092 }
4093
4094 void
4095 MainForm::OnClearCache()
4096 {
4097         result r = E_SUCCESS;
4098
4099         if (__pWebViewer != NULL)
4100         {
4101                 r = __pWebViewer->ClearCache();
4102                 if (r == E_SUCCESS)
4103                 {
4104                         AppLogDebug("Cache cleared success");
4105                 }
4106                 else
4107                 {
4108                         AppLogDebug("Cache cleared fail");
4109                 }
4110         }
4111 }
4112
4113 void
4114 MainForm::OnClearCookie()
4115 {
4116         result r = E_SUCCESS;
4117
4118         if (__pWebViewer != NULL)
4119         {
4120                 __pWebViewer->ClearCookie();
4121         }
4122         if (r == E_SUCCESS)
4123         {
4124                 AppLogDebug("Cookie cleared success");
4125         }
4126         else
4127         {
4128                 AppLogDebug("Cache cleared fail");
4129         }
4130 }
4131
4132 void
4133 MainForm::OnClearFormData()
4134 {
4135         result r = E_SUCCESS;
4136
4137         if (__pWebViewer != NULL)
4138         {
4139                 __pWebViewer->ClearFormData();
4140         }
4141         if (r == E_SUCCESS)
4142         {
4143                 AppLogDebug("Cookie cleared success");
4144         }
4145         else
4146         {
4147                 AppLogDebug("Cache cleared fail");
4148         }
4149 }
4150
4151 void
4152 MainForm::OnClearPasswords()
4153 {
4154         result r = E_SUCCESS;
4155
4156         if (__pWebViewer != NULL)
4157         {
4158                 __pWebViewer->ClearLoginFormData();
4159         }
4160         if (r == E_SUCCESS)
4161         {
4162                 AppLogDebug("Cookie cleared success");
4163         }
4164         else
4165         {
4166                 AppLogDebug("Cache cleared fail");
4167         }
4168 }
4169
4170
4171 double
4172 MainForm::findDistance(int x1,int y1,int x2, int y2)
4173 {
4174         int deltaX = Math::Abs(x2 - x1);
4175         int deltaY = Math::Abs(y2 - y1);
4176         double num = deltaX*deltaX + deltaY*deltaY;
4177
4178         if (num >= 0)
4179         {
4180                 double x = num;
4181                 int i;
4182                 for (i = 0; i < 20; i++)
4183                 {
4184                         x = (((x*x)+ num)/(2*x));
4185                 }
4186                 return num;
4187         }
4188         else
4189         {
4190                 return 0.0;
4191         }
4192 }
4193
4194 void
4195 MainForm::OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
4196 {
4197         if(__pFindWordControl)
4198         {
4199                 AppLog("MainForm::OnTouchPressed %d",__pFindWordControl->GetShowState());
4200                 ShowFindWordPanel(__pFindWordControl->GetShowState(), true);
4201         }
4202         __isLongPressedDone = false;
4203
4204         Touch touch;
4205         IList* pList = null;
4206         pList = touch.GetTouchInfoListN(source);
4207
4208         if (pList != null)
4209         {
4210                 int count = pList->GetCount();
4211                 if (count == 1)
4212                 {
4213                         TouchInfo* pTouchInfo = static_cast<TouchInfo*>(pList->GetAt(0));
4214                         __touchPoint1 = pTouchInfo->position;
4215
4216                         /*if (__pAddressbar != null)
4217                         {
4218                                 if (__pAddressbar->GetAddressbarMode() != ADDRESSBAR_MODE_LOADING_COMPLETE && __pAddressbar->GetAddressbarMode() != ADDRESSBAR_MODE_LOADING)
4219                                 {
4220                                         if (__pAddressbar->GetAddressbarMode() == ADDRESSBAR_MODE_EDIT)
4221                                         {
4222                                                 __pAddressbar->SaveAddressbarEditText();
4223                                         }
4224                                         __pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
4225                                 }
4226
4227                                 __pAddressbar->Invalidate(true);
4228                         }*/
4229                         if (GetAddressbarMode() != ADDRESSBAR_MODE_LOADING_COMPLETE && GetAddressbarMode() != ADDRESSBAR_MODE_LOADING)
4230                         {
4231                                 if (GetAddressbarMode() == ADDRESSBAR_MODE_EDIT)
4232                                 {
4233                                         //__pAddressbar->SaveAddressbarEditText();
4234                                 }
4235                                 SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
4236                         }
4237                 }
4238                 else if (count == 2)
4239                 {
4240                         AppLogDebug("MainForm::OnTouchPressed count is two");
4241                         TouchInfo* pTouchInfo = static_cast<TouchInfo*>(pList->GetAt(0));
4242                         __touchPoint1 = pTouchInfo->position;
4243
4244                         pTouchInfo = static_cast<TouchInfo*>(pList->GetAt(1));
4245                         __touchPoint2 = pTouchInfo->position;
4246                 }
4247         }
4248         if( pList != NULL)
4249
4250         {
4251                 pList->RemoveAll(true);
4252                 delete pList;
4253         }
4254         return;
4255 }
4256
4257 void
4258 MainForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
4259 {
4260         __currentWordIndex = 0;
4261         __isLongPressedDone = false;
4262
4263 }
4264
4265 void
4266 MainForm::MoveUiControls()
4267 {
4268 }
4269
4270 void
4271 MainForm::OnTextValueChanged (const Tizen::Ui::Control &source)
4272 {
4273         if(&source == dynamic_cast<Control*>(__pFooterUrlField) && __pFooterUrlField != null)
4274         {
4275                 if(__pFooterUrlField->GetTextLength() == 0)
4276                 {
4277                         __pFooterUrlField->SetKeypadActionEnabled(false);
4278                 }
4279                 else
4280                 {
4281                         __pFooterUrlField->SetKeypadActionEnabled(true);
4282                 }
4283         }
4284         if (__pFindWordEditField != null)
4285         {
4286                 __currentSearchStr = __pFindWordEditField->GetText();
4287                 __pFindWordNext->SetEnabled(false);
4288                 __pFindWordPrev->SetEnabled(false);
4289                 __pFindWordNext->Invalidate(true);
4290                 __pFindWordPrev->Invalidate(true);
4291                 __pFindWordCountLabel->SetText(L"0/0");
4292                 __pFindWordCountLabel->Invalidate(true);
4293         }
4294         AppLog("__currentSearchStr %ls",__currentSearchStr.GetPointer());
4295         if (__currentSearchStr.GetLength() > 0)
4296         {
4297                 StartWordSearch();
4298         }
4299         else
4300         {
4301                 __currentSearchStr = L"aaaaaaaabbbbbbbccccccc";
4302                 StartWordSearch();
4303                 __currentSearchStr = L"";
4304                 AppLogDebug("Enter something");
4305         }
4306 }
4307
4308 result
4309 MainForm::InitMostVisitedSitesPanel(Tizen::Ui::OrientationStatus orientationStatus)
4310 {
4311         return E_SUCCESS;
4312
4313 }
4314
4315 result
4316 MainForm::InitMostVisitedSitesView(Tizen::Ui::OrientationStatus orientationStatus)
4317 {
4318         if(__pWebViewer != null)
4319                 return E_SUCCESS;
4320
4321         AppLog("MainForm::InitMostVisitedSitesView");
4322         result r = E_SUCCESS;
4323
4324
4325         if (__pWebViewer != null && __pMostVisitedListView != null)
4326         {
4327                 return E_SUCCESS;
4328         }
4329
4330         if (__pMostVisitedListView != null)
4331         {
4332                 RemoveControl(*__pMostVisitedListView);
4333         }
4334         if(__pMostVisitedSites != null)
4335         {
4336                 __pMostVisitedSites->RemoveAll(true);
4337         }
4338
4339         HistoryPresentationModel::GetInstance()->GetMostVisitedSites(*__pMostVisitedSites);
4340
4341         __webControlHeight = GetClientAreaBounds().height - __pFooterPanel->GetHeight();
4342         __pMostVisitedListView = new(std::nothrow) ListView();
4343
4344         int height = GetClientAreaBounds().height;
4345
4346         if(__pFooterPanel->GetShowState() == true)
4347         {
4348                 height = height - __pFooterPanel->GetHeight();
4349         }
4350         if(__pAddressbar->GetShowState() == true)
4351         {
4352                 height -= __pAddressbar->GetHeight();
4353         }
4354
4355         r = __pMostVisitedListView->Construct(Tizen::Graphics::Rectangle(0,0 , GetClientAreaBounds().width, height),true,false);
4356
4357         if (r != E_SUCCESS)
4358         {
4359                 delete __pMostVisitedListView;
4360                 AppLogDebug("Addressbar init failed with %s", GetErrorMessage(r));
4361                 return r;
4362         }
4363         __pMostVisitedListView->SetItemProvider(*this);
4364         __pMostVisitedListView->AddListViewItemEventListener(*this);
4365         __pMostVisitedListView->SetTextOfEmptyList(CommonUtil::GetString(L"IDS_BR_BODY_NO_RECENTLY_VISITED_SITES"));
4366         AddControl(*__pMostVisitedListView);
4367         __pMostVisitedListView->UpdateList();
4368
4369         return E_SUCCESS;
4370
4371 }
4372
4373 String
4374 MainForm::GetImagePath(void)
4375 {
4376
4377         String str;
4378         String formattedTime;
4379         DateTime currentTime;
4380         LocaleManager localManager;
4381         SystemTime::GetCurrentTime(TIME_MODE_WALL, currentTime);
4382
4383         localManager.Construct();
4384         Locale locale = localManager.GetSystemLocale();
4385         //Locale locale(LANGUAGE_ENG, COUNTRY_US);
4386
4387         // Get date formatter
4388         DateTimeFormatter* pTimeFormatter = DateTimeFormatter::CreateDateTimeFormatterN(locale, DATE_TIME_STYLE_DEFAULT);
4389
4390         if (pTimeFormatter)
4391         {
4392                 pTimeFormatter->Format(currentTime, formattedTime);
4393         }
4394
4395         AppLog("current time stamp is %ls", formattedTime.GetPointer());
4396         String delim(L" :");
4397         StringTokenizer strTok(formattedTime, delim);
4398         String token;
4399         String imageName;
4400         String str1("GMT+00");
4401         while (strTok.HasMoreTokens())
4402         {
4403                 strTok.GetNextToken(token); // Osp, StringTokenizer, Sample, code
4404                 if(token.Equals(str1))
4405                         break;
4406                 AppLog("token is %ls", token.GetPointer());
4407                 imageName.Append(token);
4408         }
4409         return imageName;
4410
4411 }
4412
4413 void MainForm::UpdateImageContent(ByteBuffer* aBuffer, String imageName)
4414 {
4415         result r = E_FAILURE;
4416         AppLog("Content manager 1");
4417         ContentId contentId;
4418         ContentManager contentManager;
4419         r = contentManager.Construct();
4420         if(IsFailed(r))
4421         {
4422                 AppLog("Content manager update content result %s" ,GetErrorMessage(r));
4423                 return;
4424         }
4425         Tizen::Base::String contentPath = Tizen::System::Environment::GetMediaPath() + L"Downloads/";
4426         contentPath.Append(imageName);
4427         contentPath.Append(".jpg");
4428         contentId = contentManager.CreateContent(*aBuffer, contentPath);
4429         AppLog("Content manager update content result %s" ,GetErrorMessage(GetLastResult()));
4430 }
4431
4432 void
4433 MainForm::SetForwardButtonEnabled(bool isEnabled)
4434 {
4435         __pGoForwardBtn->SetEnabled(isEnabled);
4436         __pGoForwardBtn->Invalidate(true);
4437 }
4438
4439 void
4440 MainForm::SetBackButtonEnabled(bool isEnabled)
4441 {
4442         __pGoBackBtn->SetEnabled(isEnabled);
4443         __pGoBackBtn->Invalidate(true);
4444 }
4445
4446 void
4447 MainForm::UpdateProgress(int percentage)
4448 {
4449         __progressPercentage = percentage;
4450         if (percentage == 0 || percentage == 100)
4451         {
4452                 __isLoadingData = false;
4453                 if (percentage == 100)
4454                 {
4455                         __isLoadingCompleted = true;
4456                         __progressPercentage = 0;
4457                 }
4458                 else
4459                 {
4460                         __isLoadingCompleted = false;
4461                 }
4462         }
4463         else
4464         {
4465                 __isLoadingData = true;
4466         }
4467         UpdateProgressBitmap();
4468 }
4469
4470 int
4471 MainForm::GetProgress(void)
4472 {
4473         return __progressPercentage;
4474 }
4475
4476 void
4477 MainForm::UpdateProgressBitmap(void)
4478 {
4479         result r = E_SUCCESS;
4480         if (__pProgressbarLabel == null)
4481                 return;
4482         int w = __pProgressbarLabel->GetWidth();
4483         int h = __pProgressbarLabel->GetHeight();
4484         Canvas canvas;
4485         int progressWidth = 0;
4486         Bitmap* pRetBitmap = null;
4487
4488         if (__progressPercentage == 0 || __progressPercentage == 100)
4489         {
4490                 __pProgressbarLabel->SetShowState(false);
4491                 __pProgressbarLabel->Invalidate(false);
4492                 return;
4493         }
4494         else
4495         {
4496                 __pProgressbarLabel->SetShowState(true);
4497                 __pProgressbarLabel->Invalidate(false);
4498         }
4499
4500         r = canvas.Construct(Rectangle(0, 0, w, h));
4501
4502         if (r != E_SUCCESS)
4503         {
4504                 AppLogException("Canvas construction failed with %s", GetErrorMessage(r));
4505                 return;
4506         }
4507
4508         canvas.Clear();
4509         Bitmap *pBgBmp = AppResource::GetInstance()->GetBitmapN(IDB_TITLE_PROGRESS_BAR_BG);
4510
4511         if (pBgBmp != null)
4512         {
4513                 pBgBmp->Scale(Dimension(w, h));
4514                 canvas.DrawBitmap(Point(0,0), *pBgBmp);
4515                 delete pBgBmp;
4516         }
4517
4518         progressWidth = (double) (w) * __progressPercentage / 100;
4519         AppLogDebug("progressWidth: %d", progressWidth);
4520         Bitmap *pProgressBmp = AppResource::GetInstance()->GetBitmapN(IDB_TITLE_PROGRESS_BAR);
4521
4522         if (pProgressBmp != null)
4523         {
4524                 pProgressBmp->Scale(Dimension(progressWidth, h));
4525                 canvas.DrawBitmap(Point(0,0), *pProgressBmp);
4526                 delete pProgressBmp;
4527         }
4528
4529         pRetBitmap = new (std::nothrow) Bitmap();
4530
4531         if (pRetBitmap == null)
4532         {
4533                 AppLogException("Bitmap creation failed with %s", GetErrorMessage(r));
4534                 return;
4535         }
4536
4537         pRetBitmap->Construct(canvas, canvas.GetBounds());
4538
4539         if (__pProgressbarLabel != null && pRetBitmap != null)
4540         {
4541                 __pProgressbarLabel->SetBackgroundBitmap(*pRetBitmap);
4542                 __pProgressbarLabel->Invalidate(false);
4543         }
4544
4545         if (pRetBitmap != null)
4546         {
4547                 delete pRetBitmap;
4548                 pRetBitmap = null;
4549         }
4550         return;
4551 }
4552
4553 void MainForm::SetAddressbarMode(AddressBarMode addMode)
4554 {
4555         AppLogDebug("AddressBar::setAddressbarMode to %d",addMode);
4556
4557         __currentAddMode = addMode;
4558
4559         switch(addMode)
4560         {
4561         case ADDRESSBAR_MODE_INVALID:
4562         {
4563                 // do nothing
4564         }
4565         break;
4566         case ADDRESSBAR_MODE_READER:
4567         {
4568                 __pStopBtn->SetShowState(false);
4569                 __pClearBtn->SetShowState(false);
4570         }
4571         break;
4572         case ADDRESSBAR_MODE_LOADING:
4573         {
4574                 __pRefreshBtn->SetShowState(false);
4575                 __pStopBtn->SetShowState(true);
4576                 __pClearBtn->SetShowState(false);
4577         }
4578         break;
4579         case ADDRESSBAR_MODE_LOADING_COMPLETE:
4580         {
4581 //              SetUrl(__pAddressbar->GetUrl());
4582
4583                 __pRefreshBtn->SetShowState(true);
4584                 __pStopBtn->SetShowState(false);
4585                 __pClearBtn->SetShowState(false);
4586         }
4587         break;
4588         case ADDRESSBAR_MODE_EDIT:
4589         {
4590                 __pRefreshBtn->SetShowState(false);
4591                 __pStopBtn->SetShowState(false);
4592                 __pClearBtn->SetShowState(true);
4593         }
4594         break;
4595         }
4596
4597         Invalidate(true);
4598
4599         OnAddressBarModeChanged();
4600 }
4601
4602 AddressBarMode MainForm::GetAddressbarMode(void)
4603 {
4604         return __currentAddMode;
4605 }
4606
4607 void MainForm::SetUrl(const String& url)
4608 {
4609         __displayUrl = url;
4610
4611         if (__pFooterUrlField != NULL)
4612         {
4613                 String removedHttpUrl = RemoveHttpTextFromDisplayURL();
4614                 if (removedHttpUrl.IsEmpty() == false)
4615                 {
4616                         __pFooterUrlField->SetText(removedHttpUrl);
4617                         __pAddressbar->SetUrl(__displayUrl);
4618                 }
4619                 else
4620                 {
4621                         __pFooterUrlField->SetText(__displayUrl);
4622                         __pAddressbar->SetUrl(__displayUrl);
4623                 }
4624                 if(__pFooterUrlField)
4625                         __pFooterUrlField->SetCursorPosition(__pFooterUrlField->GetTextLength());
4626                 __pFooterUrlField->Invalidate(false);
4627                 __pAddressbar->Invalidate(true);
4628 //              __pFooterUrlField->SetCursorPosition(0);
4629         }
4630 }
4631
4632 String
4633 MainForm::RemoveHttpTextFromDisplayURL(void)
4634 {
4635         bool isHttpText = __displayUrl.Contains(L"http://");
4636         String updatedDisplayUrl;
4637         updatedDisplayUrl.Clear();
4638
4639         if (isHttpText == true)
4640         {
4641                 __displayUrl.SubString(7,updatedDisplayUrl);
4642         }
4643         return updatedDisplayUrl;
4644 }
4645
4646 void MainForm::OnSharePopupControlStarted(void)
4647 {
4648         __pWebViewer->AddTouchEventListener(*this);
4649 }