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