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