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