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