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