Fixed Nabi issues N_SE-49218, N_SE-49706
[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"00_icon_favorite_off_74x74.png";
72 static const wchar_t* IDB_ICON_BOOKMARK_ON_TEMP = L"00_icon_favorite_on_74x74.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
2513                         String script;
2514                         if(idElement.GetLength() != 0)
2515                         {
2516                                 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;   }  } ";
2517                                 script.Append("insertAtCursor('");
2518                                 script.Append(idElement);
2519                                 script.Append("',");
2520                                 script.Append("\"");
2521                                 script.Append(*pString);
2522                                 script.Append("\");");
2523                         }
2524                         else if (nameElement.GetLength() != 0 && pCount->Equals("1",false) == true)
2525                         {
2526                                 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;   }  } ";
2527                                 script.Append("insertAtCursor(document.getElementsByName('");
2528                                 script.Append(nameElement);
2529                                 script.Append("')[0],");
2530                                 script.Append("\"");
2531                                 script.Append(*pString);
2532                                 script.Append("\");");
2533                         }
2534                         else if(tagElement.GetLength() != 0) //adding for twitter post page
2535                         {
2536                                 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;   }  } ";
2537                                 script.Append("insertAtCursor(document.getElementsByTagName('");
2538                                 script.Append(tagElement);
2539                                 script.Append("')[0],");
2540                                 script.Append("\"");
2541                                 script.Append(*pString);
2542                                 script.Append("\");");
2543                         }
2544                         AppLog("MainForm::OnTouchLongPressed script is %ls",script.GetPointer());
2545                         String* pStr = __pWebViewer->EvaluateJavascriptN(script);
2546                         delete pStr;
2547                         delete pCount;
2548                 }
2549                 delete pItem;
2550         }
2551         break;
2552         case IDA_GO_BACK:
2553         {
2554                 OnBackClicked();
2555         }
2556         break;
2557         case IDA_GO_FORWARD:
2558         {
2559                 OnForwardClicked();
2560         }
2561         break;
2562         case IDA_REFRESH_BTN_CLICKED:
2563         {
2564                 __isLoadingCompleted = false;
2565                 __isLoadingData = true;
2566                 __progressPercentage = 0;
2567                 __displayUrl = __pFooterUrlField->GetText();
2568
2569                 String url = __pFooterUrlField->GetText();
2570                 AppLog("MainForm::OnUrlSubmitted url is %ls", url.GetPointer());
2571 //              LoadUrl(url);
2572                 if (__pWebViewer != null && __pAddressbar != null)
2573                 {
2574                         __pWebViewer->Reload();
2575                         SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING);
2576                 }
2577
2578                 //OnUrlSubmitted();
2579                 UpdateProgressBitmap();
2580         }
2581         break;
2582         case IDA_STOP_BTN_CLICKED:
2583         {
2584                 __isLoadingCompleted = false;
2585                 __isLoadingData = false;
2586                 __progressPercentage = 0;
2587                 __pFooterUrlField->HideKeypad();
2588                 __displayUrl = __pFooterUrlField->GetText();
2589
2590                 if (__pWebViewer)
2591                 {
2592                         //__pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
2593                         SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
2594                         __pWebViewer->StopLoading();
2595                         RequestRedraw(true);
2596                 }
2597
2598                 UpdateProgressBitmap();
2599         }
2600         break;
2601         case IDA_CLEAR_URL:
2602         {
2603                 if (__pFooterUrlField->GetText().IsEmpty() == false)
2604                 {
2605                         //__displayUrl = __pUrlField->GetText();
2606                         __pFooterUrlField->Clear();
2607
2608                 }
2609         }
2610         break;
2611         case IDA_READER_BTN_CLICKED:
2612         {
2613                 ReaderClicked();
2614         }
2615         break;
2616         default:
2617                 break;
2618         }
2619 }
2620
2621 void
2622 MainForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
2623 {
2624         AppLog("MainForm::OnFormBackRequested entered");
2625         result r = E_FAILURE;
2626         if(__pImageMenu && __pImageMenu->GetShowState() == true)
2627         {
2628                 AppLog("Hiding the menu");
2629                 __pImageMenu->SetShowState(false);
2630         }
2631         if (__pWebViewer && __pWebViewer->CanGoBack())
2632         {
2633                 __pWebViewer->GoBack();
2634         }
2635         else if(__pWindowInfo && __pWindowInfo->isJavascriptInitiated == false)
2636         {
2637                 UiApp* pApp = null;
2638                 pApp = UiApp::GetInstance();
2639                 if (pApp != null)
2640                 {
2641                         r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
2642                         if (IsFailed(r))
2643                         {
2644                                 AppLogException("MainForm::OnFormBackRequested failed with %s", GetErrorMessage(r));
2645                                 return;
2646                         }
2647                 }
2648         }
2649         else
2650         {
2651                 UiApp* pApp = null;
2652                 WindowInfo* pWindowInfo = null;
2653                 int totalCount = 0;
2654                 SceneManager* pSceneManager = SceneManager::GetInstance();
2655                 if (pSceneManager == null)
2656                 {
2657                         return;
2658                 }
2659                 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
2660                 if (pAllWindowList == NULL)
2661                 {
2662                         pApp = UiApp::GetInstance();
2663                         if (pApp != null)
2664                         {
2665                                 r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
2666                                 if (IsFailed(r))
2667                                 {
2668                                         AppLogException("MainForm::OnFormBackRequested failed with %s", GetErrorMessage(r));
2669                                         return;
2670                                 }
2671                         }
2672                 }
2673                 if (pAllWindowList != null)
2674                 {
2675                         totalCount = pAllWindowList->GetCount();
2676                 }
2677                 for (int count = 0; count < totalCount; count++)
2678                 {
2679                         pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count));
2680                         if (pWindowInfo == null)
2681                         {
2682                                 pApp = UiApp::GetInstance();
2683                                 if (pApp != null)
2684                                 {
2685                                         r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
2686                                         if (IsFailed(r))
2687                                         {
2688                                                 AppLogException("MainForm::OnFormBackRequested failed with %s", GetErrorMessage(r));
2689                                                 return;
2690                                         }
2691                                 }
2692                         }
2693                         else
2694                         {
2695                                 if (pWindowInfo && pSceneManager->GetCurrentSceneId() == pWindowInfo->sceneID && pWindowInfo->isJavascriptInitiated == true)
2696                                 {
2697                                         r = SceneRegister::DestroyAndUnRegisterScene(pWindowInfo->sceneID);
2698                                         if (IsFailed(r))
2699                                         {
2700                                                 AppLogException("MainForm::OnFormBackRequested failed with %s", GetErrorMessage(r));
2701                                                 return;
2702                                         }
2703                                         r = pAllWindowList->RemoveAt(count, true);
2704                                         __pWindowInfo = null;
2705                                         if (IsFailed(r))
2706                                         {
2707                                                 AppLogException("MainForm::OnFormBackRequested failed with %s", GetErrorMessage(r));
2708                                                 return;
2709                                         }
2710                                         if(count > 0)
2711                                         {
2712                                                 pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count - 1));
2713                                         }
2714                                         else
2715                                         {
2716                                                 pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(pAllWindowList->GetCount() - 1));
2717                                         }
2718                                         if (pWindowInfo == null)
2719                                         {
2720                                                 pApp = UiApp::GetInstance();
2721                                                 if (pApp != null)
2722                                                 {
2723                                                         r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
2724                                                         return;
2725                                                 }
2726                                         }
2727                                         else
2728                                         {
2729                                                 if(pWindowInfo != null)
2730                                                         r = pSceneManager->GoForward(ForwardSceneTransition(pWindowInfo->sceneID ,SCENE_TRANSITION_ANIMATION_TYPE_NONE,SCENE_HISTORY_OPTION_ADD_HISTORY,SCENE_DESTROY_OPTION_DESTROY));
2731                                                 if (IsFailed(r))
2732                                                 {
2733                                                         AppLogException("MainForm::OnFormBackRequested failed with %s", GetErrorMessage(r));
2734                                                         return;
2735                                                 }
2736                                         }
2737                                         break;
2738                                 }
2739 //                              else if (pWindowInfo && pSceneManager->GetCurrentSceneId() == pWindowInfo->sceneID && pWindowInfo->isJavascriptInitiated == false)
2740 //                              {
2741 //                                      UiApp* pApp = null;
2742 //                                      pApp = UiApp::GetInstance();
2743 //                                      if (pApp != null)
2744 //                                      {
2745 //                                              r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
2746 //                                              if (IsFailed(r))
2747 //                                              {
2748 //                                                      AppLogException("MainForm::OnFormBackRequested failed with %s", GetErrorMessage(r));
2749 //                                                      return;
2750 //                                              }
2751 //                                      }
2752 //                              }
2753                         }
2754                 }
2755         }
2756         AppLog("MainForm::OnFormBackRequested exit");
2757 }
2758
2759 void
2760 MainForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
2761                 const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
2762 {
2763
2764         AppLog("MainForm::OnSceneActivatedN called");
2765         String* pSelectedScene = NULL;
2766         Object* pValue = NULL;
2767         String* pUrl = null;
2768         MultipleWindowPresentationModel::GetInstance()->GetValue(SELECTED_SCENE_ID, &pValue);
2769         pSelectedScene = (String*) pValue;
2770
2771         if (pSelectedScene != null)
2772         {
2773                 delete pSelectedScene;
2774         }
2775         MultipleWindowPresentationModel::GetInstance()->SetValue(SELECTED_SCENE_ID, null);
2776         String* selectedSceneID = new(std::nothrow) String(currentSceneId);
2777         AppLogDebug("current scene id is %ls", currentSceneId.GetPointer());
2778         AppLogDebug("selected scene id is %ls", currentSceneId.GetPointer());
2779
2780         // setting the current scene ID
2781         MultipleWindowPresentationModel::GetInstance()->SetCurrentSceneID(currentSceneId);
2782
2783         MultipleWindowPresentationModel::GetInstance()->SetValue(SELECTED_SCENE_ID, (Object*) selectedSceneID);
2784
2785         if(pArgs != null && pArgs->GetCount() > 0 && pArgs->GetCount() == 2)
2786         {
2787                 __pWindowInfo = dynamic_cast< WindowInfo* >(pArgs->GetAt(0));
2788                 if(__pWindowInfo == null)
2789                         return;
2790                 //              if(__pWindowInfo == null)
2791                 {
2792                         pUrl = dynamic_cast< String* >(pArgs->GetAt(1));
2793                 }
2794         }
2795         else if ( pArgs != null && pArgs->GetCount() == 1)
2796         {
2797                 __pWindowInfo = dynamic_cast< WindowInfo* >(pArgs->GetAt(0));
2798         }
2799
2800         InitFooter();
2801         InitAddressbar();
2802
2803         __pFooterPanel->SetBounds(0, GetClientAreaBounds().height - __pFooterPanel->GetHeight(), GetClientAreaBounds().width, __pFooterPanel->GetHeight());
2804
2805         // hiding the address bar
2806         //      __pAddressbar->SetBounds(__pAddressbar->GetX(), __pAddressbar->GetY() - __pAddressbar->GetHeight(), __pAddressbar->GetWidth(), __pAddressbar->GetHeight());
2807         __pAddressbar->SetShowState(false);
2808 //      if(__pWebViewer != null)
2809 //      {
2810 //              __pWebViewer->Resume();
2811 //      }
2812
2813         if(pUrl != null && pUrl->GetLength() > 0)
2814         {
2815                 LoadUrl(*pUrl);
2816         }
2817         else if(__pWindowInfo != null)
2818         {
2819                 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)
2820                 {
2821                         LoadUrl(__pWindowInfo->pageUrl);
2822                 }
2823                 else if(__pWindowInfo->pageUrl.GetLength() > 0 && __pWindowInfo->isAppcontrolTriggered == true)
2824                 {
2825                         LoadUrl(__pWindowInfo->pageUrl);
2826                         __pWindowInfo->isAppcontrolTriggered = false;
2827                 }
2828                 else if (__pWindowInfo->isJavascriptInitiated == true && __pWindowInfo->isFirstLaunch == true)
2829                 {
2830                         __pWindowInfo->isFirstLaunch = false;
2831                         AppLog("Called");
2832                         InitWebControl();
2833                         __pWindowInfo->pCurrentWeb = __pWebViewer;
2834                         if(__pWindowInfo->pageUrl.GetLength() > 0)
2835                                 LoadUrl(__pWindowInfo->pageUrl);
2836                 }
2837         }
2838
2839         String homePage = SettingPresentationModel::GetInstance()->GetHomepage();
2840         AppLog("Homepage Value in Onsceneactivated is %ls",homePage.GetPointer());
2841         if(homePage.CompareTo((L"IDS_BR_BODY_MOST_VISITED_SITES")) == 0)
2842         {
2843                 InitMostVisitedSitesView(GetOrientationStatus());
2844         }
2845         else if (homePage.CompareTo((L"IDS_BR_BODY_BLANK_PAGE")) == 0)
2846         {
2847                 if(__pMostVisitedListView != null)
2848                 {
2849                         __pMostVisitedListView->SetShowState(false);
2850                 }
2851         }
2852
2853         if (__pAddressbar != null && pArgs != null && (previousSceneId == IDSCN_BOOKMARK_VIEW || previousSceneId == IDSCN_HISTORY_LIST))
2854         {
2855                 String* pBookmarkUrl = dynamic_cast< String* >(pArgs->GetAt(0));
2856
2857                 if (pBookmarkUrl == null)
2858                         return;
2859                 AppLogDebug("bookmarkUrl = %ls",pBookmarkUrl->GetPointer());
2860                 //__pAddressbar->SetUrl(*pBookmarkUrl);
2861                 SetUrl(*pBookmarkUrl);
2862
2863                 if (__pWebViewer != null && homePage.CompareTo((L"IDS_BR_BODY_BLANK_PAGE")) != 0)
2864                         __pWebViewer->LoadUrl(*pBookmarkUrl);
2865                 delete pBookmarkUrl;
2866         }
2867
2868         bool isPrivateBrowsing = SettingPresentationModel::GetInstance()->GetPrivateOn();
2869         Bitmap* pBitmap = null;
2870         if (isPrivateBrowsing == true)
2871         {
2872                 pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_BUTTON_ON);
2873
2874                 if (__pWebViewer != null)
2875                 {
2876                         __pWebViewer->SetPrivateBrowsingEnabled(true);
2877                 }
2878
2879                 if (__pAddressbar != null)
2880                 {
2881                         //      __pAddressbar->UpdateFaviconBitmap(true);
2882                 }
2883
2884         }
2885         else
2886         {
2887                 pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_BUTTON_OFF);
2888
2889                 if (__pWebViewer != null)
2890                 {
2891                         __pWebViewer->SetPrivateBrowsingEnabled(false);
2892                 }
2893
2894                 if (__pAddressbar != null)
2895                 {
2896                         //      __pAddressbar->UpdateFaviconBitmap(false);
2897                 }
2898         }
2899
2900         if (__pOptionMenu != null && __pOptionMenu->GetItemCount() != 9)
2901         {
2902                 __pOptionMenu->SetItemAt(1,CommonUtil::GetString(L"IDS_BR_BODY_PRIVACY_AND_SECURITY_ABB"),IDA_PRIVATEON_CLICKED,*pBitmap);
2903         }
2904         else if (__pOptionMenu != null )
2905         {
2906                 __pOptionMenu->SetItemAt(5,CommonUtil::GetString(L"IDS_BR_BODY_PRIVACY_AND_SECURITY_ABB"),IDA_PRIVATEON_CLICKED,*pBitmap);
2907         }
2908
2909         if (pBitmap != null)
2910         {
2911                 delete pBitmap;
2912         }
2913
2914         RelayoutControls(false);
2915         AppLog("ABC: OnSceneActivatedN started exit");
2916
2917 }
2918
2919 void
2920 MainForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
2921                 const Tizen::Ui::Scenes::SceneId& nextSceneId)
2922 {
2923         Canvas* pWebCanvas = null;
2924         if (__pWebViewer != null)
2925         {
2926                 pWebCanvas = __pWebViewer->GetCanvasN();
2927
2928         }
2929         if (pWebCanvas == null)
2930         {
2931                 return;
2932         }
2933         if (__pWindowInfo != null)
2934         {
2935                 if (__pWindowInfo->pWebCanvasBitmap != null)
2936                 {
2937                         delete __pWindowInfo->pWebCanvasBitmap;
2938                 }
2939                 __pWindowInfo->pWebCanvasBitmap = new(std::nothrow) Bitmap();
2940                 result r = __pWindowInfo->pWebCanvasBitmap->Construct(*pWebCanvas,Rectangle(0,0,pWebCanvas->GetBounds().width,pWebCanvas->GetBounds().height));
2941                 AppLog("Bitmap Construction result %s",GetErrorMessage(r));
2942         }
2943         Bitmap* pBitmap = GetCapturedBitmapN();
2944         AppLog("Coming here");
2945         Canvas* pCanvas = new(std::nothrow) Canvas();
2946         pCanvas->Construct(GetClientAreaBounds());
2947         if(pBitmap != null)
2948         {
2949                 pCanvas->DrawBitmap(Point(0,0),*pBitmap);
2950                 delete pBitmap;
2951         }
2952         if(__pWebViewer != null && __pWindowInfo != null)
2953                 pCanvas->DrawBitmap(__pWebViewer->GetPosition(),*__pWindowInfo->pWebCanvasBitmap);
2954
2955         WindowInfo::pFormCanvasBitmap = new(std::nothrow) Bitmap();
2956         WindowInfo::pFormCanvasBitmap->Construct(*pCanvas,Rectangle(0,0,GetClientAreaBounds().width,GetClientAreaBounds().height - __pFooterPanel->GetHeight()));
2957         delete pCanvas;
2958         delete pWebCanvas;
2959         if(__pAddressbar)
2960                 __pAddressbar->SetShowState(false);
2961         AppLog("Coming here");
2962 }
2963
2964 bool
2965 MainForm::OnHttpAuthenticationRequestedN(const Tizen::Base::String& host,
2966                 const Tizen::Base::String& realm,
2967                 const Tizen::Web::Controls::AuthenticationChallenge& authentication)
2968 {
2969         return false;
2970 }
2971
2972 void
2973 MainForm::OnHttpAuthenticationCanceled(void)
2974 {
2975 }
2976
2977 void
2978 MainForm::OnLoadingStarted(void)
2979 {
2980         AppLogDebug("MainForm::OnLoadingStarted entered");
2981         __isLoaded = true;
2982         if(__pAddressbar == NULL || __pWebViewer == null)
2983         {
2984                 return;
2985         }
2986
2987         // this is added in case if menu is opened and user load the page
2988         if(__pOptionMenu != null && __pOptionMenu->GetShowState() == true)
2989         {
2990                 __pOptionMenu->SetShowState(false);
2991                 __pOptionMenu->Invalidate(true);
2992         }
2993
2994
2995
2996         if(__pImageMenu != null && __pImageMenu->GetShowState() == true)
2997         {
2998                 __pImageMenu->SetShowState(false);
2999                 __pImageMenu->Invalidate(true);
3000         }
3001         String url = __pWebViewer->GetUrl();
3002         if(url.Contains(IDS_TIZEN_SERVICE))
3003         {
3004                 String appId;
3005                 String delim(L":;,");
3006
3007                 // Creates a StringTokenizer instance
3008                 StringTokenizer strTok(url, delim);
3009
3010                 int count = strTok.GetTokenCount();     // count == 4
3011
3012                 HashMap *pMap = new HashMap();
3013                 pMap->Construct();
3014                 String token;
3015                 String key;
3016                 String value;
3017                 while (strTok.HasMoreTokens())
3018                 {
3019                         AppLog("Token: %ls", token.GetPointer());
3020                         strTok.GetNextToken(token);         // Tizen, StringTokenizer, Sample, code
3021                         if(token.Contains(IDS_APPID))
3022                         {
3023                                 token.SubString(6, appId);
3024                                 AppLog("AppID:%ls", appId.GetPointer());
3025                         }
3026                         else if(token.Contains(IDS_KEY))
3027                         {
3028                                 token.SubString(4, key);
3029                                 AppLog("key:%ls", key.GetPointer());
3030                         }
3031                         else if(token.Contains(IDS_VALUE))
3032                         {
3033                                 token.SubString(6, value);
3034                                 AppLog("value:%ls", value.GetPointer());
3035                         }
3036                 }
3037                 pMap->Add(key, value);
3038
3039                 if(appId != "")
3040                 {
3041                         AppControl *pAppControl = null;
3042                         String operationId = L"http://tizen.org/appcontrol/operation/main";
3043                         pAppControl = dynamic_cast<AppControl*>(AppManager::FindAppControlN(appId, operationId));
3044                         if(pAppControl)
3045                         {
3046                                 AppLog("Starting AppControl");
3047                                 result r = pAppControl->Start(null, null, pMap, null);
3048                                 AppLog("Result of Start %s", GetErrorMessage(r));
3049                         }
3050                         else
3051                         {
3052                                 AppLogException("AppControl not found");
3053                         }
3054                         return;
3055                 }
3056         }
3057         if ( __pAddressbar != null && __pAddressbar->GetShowState() == true)
3058         {
3059                 __pAddressbar->SetShowState(false);
3060                 AddressBarCancelledClicked(*__pAddressbar);
3061                 __pAddressbar->Invalidate(true);
3062         }
3063         Bitmap* pBitmap = FaviconManager::GetInstance()->GetDefaultFaviconN();
3064         if(pBitmap != null)
3065         {
3066                 __pAddressbar->SetFaviconBitmap(*pBitmap);
3067         }
3068         delete pBitmap;
3069         if (__adressPanelPosition.y < (0 - __pAddressbar->GetHeight() + 12))
3070         {
3071                 // updating the address bar position with respect to web control
3072                 __adressPanelPosition.y = 0 - __pAddressbar->GetHeight() + 12; //-12 is for the progress label
3073                 __distanceMoved = 0;
3074                 MoveUiControls();
3075         }
3076
3077         //__pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING);
3078         SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING);
3079         if (__pWebViewer != null)
3080         {
3081                 AppLog("MainForm::OnLoadingStarted __pWebViewer->GetUrl() %ls",__pWebViewer->GetUrl().GetPointer());
3082                 //__pAddressbar->SetUrl(__pWebViewer->GetUrl());
3083                 SetUrl(__pWebViewer->GetUrl());
3084                 if (__pWindowInfo != NULL)
3085                 {
3086                         // resetting the page title to blank, it will be received in OnPageTitleReceived()
3087                         __pWindowInfo->pageTitle = L"";
3088                         __pWindowInfo->pageUrl = __pWebViewer->GetUrl();
3089                 }
3090                 __pAddressbar->Invalidate(true);
3091         }
3092
3093 }
3094
3095 void
3096 MainForm::OnLoadingCanceled(void)
3097 {
3098
3099 }
3100
3101
3102 void
3103 MainForm::OnKeypadWillOpen(Tizen::Ui::Control& source)
3104 {
3105         AppLog("XYZ::MainForm::OnKeypadWillOpen");
3106
3107 }
3108
3109 void
3110 MainForm::OnKeypadOpened(Tizen::Ui::Control& source)
3111 {
3112         AppLog("XYZ::MainForm::OnKeypadOpened");
3113         __isKeypadOpened = true;
3114         __pFooterPanel->SetShowState(false);
3115
3116 }
3117
3118 void
3119 MainForm::OnKeypadClosed(Tizen::Ui::Control& source)
3120 {
3121         AppLog("XYZ::MainForm::OnKeypadClosed");
3122         __isKeypadOpened = false;
3123         __pFooterPanel->SetShowState(true);
3124         RelayoutControls(true);
3125 }
3126
3127 void
3128 MainForm::OnKeypadBoundsChanged(Tizen::Ui::Control &source)
3129 {
3130         AppLog("XYZ::KeypadBoundsChanged");
3131         RelayoutControls(false);
3132 }
3133
3134 void
3135 MainForm::OnLoadingErrorOccurred(LoadingErrorType error,
3136                 const Tizen::Base::String& reason)
3137 {
3138         AppLogDebug("Error: %d, %ls", error, reason.GetPointer());
3139 }
3140
3141 void
3142 MainForm::OnLoadingCompleted(void)
3143 {
3144         AppLog("MainForm::OnLoadingCompleted start");
3145         DateTime date;
3146         result r = E_SUCCESS;
3147
3148         if (__pWebViewer == null)
3149         {
3150                 return;
3151         }
3152
3153         if (__pAddressbar == null)
3154         {
3155                 return;
3156         }
3157
3158         if(__pImageMenu && __pImageMenu->GetShowState())
3159         {
3160                 __pImageMenu->SetShowState(false);
3161                 __pImageMenu->Invalidate(true);
3162         }
3163
3164         if (__pWebViewer->CanGoForward())
3165         {
3166                 //__pAddressbar->SetForwardButtonEnabled(true);
3167                 SetForwardButtonEnabled(true);
3168         }
3169         else
3170         {
3171                 //__pAddressbar->SetForwardButtonEnabled(false);
3172                 SetForwardButtonEnabled(false);
3173         }
3174
3175         /*if (__pAddressbar->GetAddressbarMode() != ADDRESSBAR_MODE_EDIT)
3176         {
3177                 __pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
3178
3179                 //__pAddressbar->UpdateProgress(0);
3180                 UpdateProgress(0);
3181         }*/
3182
3183         if(GetAddressbarMode() != ADDRESSBAR_MODE_EDIT)
3184         {
3185                 SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
3186                 UpdateProgress(0);
3187         }
3188
3189         AppLog("PrivateBrowsing %d",__pWebViewer->IsPrivateBrowsingEnabled());
3190         bool isPrivateBrowsing = SettingPresentationModel::GetInstance()->GetPrivateOn();
3191         if (isPrivateBrowsing == false)
3192         {
3193                 if(__pHistory != null)
3194                 {
3195                         delete __pHistory;
3196                         __pHistory = null;
3197                 }
3198
3199                 __pHistory = new(std::nothrow) History;
3200                 HistoryPresentationModel::GetCurrentDateTime(date);
3201                 if (__pWindowInfo)
3202                 {
3203                         __pHistory->SetHistoryTitle(__pWindowInfo->pageTitle);
3204                         AppLogDebug("MainForm::OnLoadingCompleted pagetitle = %ls", __pWindowInfo->pageTitle.GetPointer());
3205
3206                         __pHistory->SetHistoryUrl(__pWindowInfo->pageUrl);
3207                         AppLogDebug("MainForm::OnLoadingCompleted pageUrl = %ls", __pWindowInfo->pageUrl.GetPointer());
3208                 }
3209                 __pHistory->SetVisitedTime(date);
3210
3211                 if (__pWebViewer != null)
3212                 {
3213                         AppLog("MainForm::OnLoadingCompleted setting the fav icon 0");
3214
3215                         Bitmap* pTempBitmap = __pWebViewer->GetFaviconN();
3216                         if (pTempBitmap != null)
3217                         {
3218                                 AppLog("MainForm::OnLoadingCompleted setting the fav icon 1");
3219                                 __pHistory->SetFavIconBitmap(*pTempBitmap);
3220                         }
3221
3222                         AppLog("MainForm::OnLoadingCompleted setting the fav icon 2");
3223                 }
3224
3225                 Canvas* pCanvas = __pWebViewer->GetCanvasN();
3226                 Bitmap* pBitmap = new(std::nothrow) Bitmap();
3227                 if ( pCanvas != null &&  pCanvas != null && pBitmap != null)
3228                 {
3229                         pBitmap->Construct(*pCanvas, pCanvas->GetBounds());
3230                         pBitmap->Scale(Dimension(pBitmap->GetWidth()/4, pBitmap->GetHeight()/4));
3231                         __pHistory->SetThumbnail(pBitmap);
3232                 }
3233                 Bitmap *pFavIcon = __pWebViewer->GetFaviconN();
3234                 if (pFavIcon)
3235                 {
3236                         __pHistory->SetFavIconBitmap(*pFavIcon);
3237                         delete pFavIcon;
3238                 }
3239
3240                 HistoryPresentationModel::GetInstance()->SaveTempHistory(*__pHistory);
3241                 //delete pHistory;
3242         }
3243         else
3244         {
3245                 return;
3246         }
3247 //      if (__pWindowInfo && __pWindowInfo->faviconUrl == "")
3248         {
3249                 // temperary fixed (webpage can be not loaded)
3250                 UpdateFavicon();
3251         }
3252
3253         bool isReaderEnabled = SettingPresentationModel::GetInstance()->IsRunReaderEnabled();
3254         if (isReaderEnabled == true)
3255         {
3256                 if (__pReaderData)
3257                 {
3258                         delete __pReaderData;
3259                         __pReaderData = null;
3260                 }
3261                 String filePath = Tizen::App::UiApp::GetInstance()->GetAppRootPath();
3262                 filePath.Append(L"data/reader.js");
3263                 File file;
3264                 char buffer[10];
3265                 char buffer2[5];
3266                 int i;
3267                 int readCnt;
3268                 result r = E_SUCCESS;
3269                 FileAttributes attr;
3270
3271                 File::GetAttributes(filePath,attr);
3272                 // Creates file
3273                 r = file.Construct(filePath, L"r+");
3274                 if (IsFailed(r))
3275                 {
3276                         AppLogDebug("File construct failed with %s", GetErrorMessage(r));
3277                         return;
3278                 }
3279                 char* pScript = new(std::nothrow) char[attr.GetFileSize()+1];
3280                 if(pScript == null)
3281                 {
3282                         AppLogDebug("Memory allocation for file failed %s", GetErrorMessage(r));
3283                         return;
3284                 }
3285 //              file.Read(pScript,attr.GetFileSize());
3286 //
3287 //              AppLogDebug("scipt length %d",strlen(pScript));
3288                 String strScript = L"";
3289 //              strScript.Append(pScript);
3290 //              for(int i=0; i<25; i++)
3291                 {
3292                         file.Read(pScript,attr.GetFileSize());
3293 //                      AppLog("xyzz tell %d",file.Tell());
3294 //                      r = strScript.Append(pScript);
3295 //                      AppLog("xyzz append result %s",GetErrorMessage(r));
3296 //                      AppLog("xyzz strScript length %d",strScript.GetLength());
3297                 }
3298 //              AppLog("xyzz final strScript length %d",strScript.GetLength());
3299
3300                 __pReaderData = __pWebViewer->EvaluateJavascriptN(pScript);
3301                 if (__pReaderData == null)
3302                 {
3303                         AppLog("MainScene::data is null Error :%s",GetErrorMessage(GetLastResult()));
3304                         __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>");
3305 //                      return;
3306                 }
3307                 AppLogDebug("evaluateJavascript result %s , __pReaderData %ls",GetErrorMessage(GetLastResult()),__pReaderData->GetPointer());
3308                 if (__pReaderData->CompareTo(L"undefined") != 0 && __pReaderData->CompareTo(L"") != 0)
3309                 {
3310                         //__pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_READER);
3311                         SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_READER);
3312                 }
3313                 delete[] pScript;
3314         }
3315
3316
3317         AppLog("MainForm::OnLoadingCompleted done");
3318 }
3319
3320 void
3321 MainForm::OnEstimatedProgress(int progress)
3322 {
3323         AppLogDebug("MainForm::OnEstimatedProgress entered %d",progress);
3324
3325         if (progress < DEFAULT_PROGRESS_PERCENTAGE)
3326                 progress = DEFAULT_PROGRESS_PERCENTAGE;
3327         //if(__pAddressbar)
3328         //      __pAddressbar->UpdateProgress(progress);
3329         UpdateProgress(progress);
3330 }
3331
3332 void MainForm::OnFaviconReceived(const Tizen::Graphics::Bitmap& favicon)
3333 {
3334         AppLog("MainForm::OnFaviconReceived");
3335         if (__pWebViewer != null && __pHistory != null && __pWindowInfo != null && (__pWindowInfo->pageUrl.CompareTo(__pHistory->GetHistoryUrl()) == 0))
3336         {
3337                 Bitmap* favIcon = __pWebViewer->GetFaviconN();
3338                 if(favIcon != null)
3339                 {
3340                         HistoryPresentationModel::GetInstance()->UpdateHistoryFavIcon(*__pHistory, *favIcon);
3341                         delete favIcon;
3342                 }
3343         }
3344 }
3345
3346 void
3347 MainForm::OnUrlValueChanged(Addressbar&)
3348 {
3349         Invalidate(true);
3350 }
3351
3352 void
3353 MainForm::OnUrlSubmitted(Addressbar& addBar)
3354 {
3355         AppLog("MainForm::OnUrlSubmitted");
3356         String url = addBar.GetUrl();
3357         AppLog("MainForm::OnUrlSubmitted url is %ls", url.GetPointer());
3358
3359         if(__pFooterUrlField)
3360                 __pFooterUrlField->SetCursorPosition(__pFooterUrlField->GetTextLength());
3361         AddressBarCancelledClicked(*__pAddressbar);
3362         LoadUrl(url);
3363 }
3364
3365 void
3366 MainForm::LoadUrl(String& url)
3367 {
3368         url.Trim();
3369         String encodedUrl;
3370 //      UrlEncoder::Encode(url, L"UTF-8", encodedUrl);
3371         AppLogDebug("MainForm::LoadUrl enter");
3372
3373         if (__pWebViewer != null)
3374         {
3375                 __pWebViewer->SetShowState(true);
3376                 __pWebViewer->Invalidate(true);
3377         }
3378
3379         if (url.CompareTo(L"") == 0)
3380         {
3381                 return;
3382         }
3383         if(__pFooterPanel != null)
3384         {
3385                 __pFooterPanel->SetShowState(true);
3386                 __pFooterPanel->Invalidate(true);
3387         }
3388         InitWebControl();
3389
3390         bool ret = false;
3391         bool flag = false;
3392
3393         String firstPattern(L"((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)");
3394         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)
3395
3396         RegularExpression firstRegex;
3397         RegularExpression secondRegex;
3398
3399         firstRegex.Construct(firstPattern, REGEX_CASELESS);
3400         secondRegex.Construct(secondPattern, REGEX_CASELESS);
3401
3402         // Match
3403         ret = firstRegex.Match(url, false); // This returns true value
3404         flag = secondRegex.Match(url, false);  // Checks whether URL typed is of type  abc.com (i.e without protocol in front of it)
3405
3406         if (ret == true && __pWebViewer != null)
3407         {
3408                 SetUrl(url);
3409                 __pWebViewer->LoadUrl(url);
3410         }
3411         else if(__pWebViewer != null)
3412         {
3413                 String tempUrl = L"http://";
3414                 tempUrl.Append(url);
3415
3416                 if (flag == true)
3417                 {
3418                         __pWebViewer->LoadUrl(tempUrl);
3419                 }
3420                 else
3421                 {
3422                                 UrlEncoder::Encode(url, L"UTF-8", encodedUrl);
3423                         __pWebViewer->LoadUrl(SettingPresentationModel::GetInstance()->GetSearchUrl(encodedUrl));
3424                 }
3425         }
3426         if (__pAddressbar != null)
3427         {
3428                 //__pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING);
3429                 SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING);
3430         }
3431
3432         AppLogDebug("MainForm::LoadUrl exit");
3433
3434         return;
3435
3436 }
3437
3438 void
3439 MainForm::OnFocusGained(const Tizen::Ui::Control& source)
3440 {
3441         AppLog("MainForm::OnFocusGained");
3442         if(__pFooterPanel)
3443         {
3444                 __pFooterPanel->SetShowState(false);
3445         }
3446
3447         if(__pAddressbar)
3448         {
3449                 __pAddressbar->SetShowState(true);
3450                 __pAddressbar->SetAddressbarURLFocus();
3451         }
3452         if(__pFindWordControl && __pFindWordControl->GetShowState() == true)
3453         {
3454                 __currentSearchStr = L"";
3455                 __currentWordIndex = 0;
3456                 __maxOccurrances = 0;
3457
3458                 if (__pFindWordPanelLeftToRight && __pFindWordPanelLeftToRight->GetShowState() == true)
3459                 {
3460                         __pFindWordEditField->SetText(L"");
3461                         __pFindWordEditField->HideKeypad();
3462                         __pFindWordControl->SetShowState(false);
3463                         __pFindWordCountLabel->SetText(L"0/0");
3464                 }
3465                 else if(__pFindWordPanelRightToLeft && __pFindWordPanelRightToLeft->GetShowState() == true)
3466                 {
3467                         __pFindWordEditFieldRightToLeft->SetText(L"");
3468                         __pFindWordEditFieldRightToLeft->HideKeypad();
3469                         __pFindWordControl->SetShowState(false);
3470                         __pFindWordCountLabelRightToLeft->SetText(L"0/0");
3471                 }
3472
3473                 __pFindWordNext->SetEnabled(false);
3474                 __pFindWordPrev->SetEnabled(false);
3475
3476                 __pWebViewer->SearchTextAllAsync(L"",true);
3477                 __pFindWordControl->SetShowState(false);
3478         }
3479         RelayoutControls(false);
3480 }
3481
3482 void
3483 MainForm::OnFocusLost(const Tizen::Ui::Control& source)
3484 {
3485         AppLog("MainForm::OnFocusLost called");
3486 }
3487
3488 void
3489 MainForm::OnStopClicked(Addressbar& addBar)
3490 {
3491         AppLogDebug("MainForm::OnStopClicked called");
3492         if (__pWebViewer)
3493         {
3494                 //__pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
3495                 SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
3496                 __pWebViewer->StopLoading();
3497                 RequestRedraw(true);
3498         }
3499 }
3500
3501 void
3502 MainForm::OnBackClicked(/*const Addressbar& addBar*/)
3503 {
3504         //      AppLog("MainForm::OnBackClicked");
3505         result r = E_FAILURE;
3506         if(__pImageMenu && __pImageMenu->GetShowState() == true)
3507         {
3508                 AppLog("Hiding the menu");
3509                 __pImageMenu->SetShowState(false);
3510         }
3511
3512         if (__pWebViewer && __pWebViewer->CanGoBack())
3513         {
3514                 __pWebViewer->GoBack();
3515         }
3516         else if(__pWindowInfo && __pWindowInfo->isJavascriptInitiated == false)
3517         {
3518                 UiApp* pApp = null;
3519                 pApp = UiApp::GetInstance();
3520                 if (pApp != null)
3521                 {
3522                         r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
3523                         if (IsFailed(r))
3524                         {
3525                                 AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
3526                                 return;
3527                         }
3528                 }
3529         }
3530         else
3531         {
3532                 UiApp* pApp = null;
3533                 WindowInfo* pWindowInfo = null;
3534                 int totalCount = 0;
3535                 SceneManager* pSceneManager = SceneManager::GetInstance();
3536                 if (pSceneManager == null)
3537                 {
3538                         return;
3539                 }
3540                 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
3541                 if (pAllWindowList == NULL)
3542                 {
3543                         pApp = UiApp::GetInstance();
3544                         if (pApp != null)
3545                         {
3546                                 r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
3547                                 if (IsFailed(r))
3548                                 {
3549                                         AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
3550                                         return;
3551                                 }
3552                         }
3553                 }
3554                 if (pAllWindowList != null)
3555                 {
3556                         totalCount = pAllWindowList->GetCount();
3557                 }
3558                 for (int count = 0; count < totalCount; count++)
3559                 {
3560                         pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count));
3561                         if (pWindowInfo == null)
3562                         {
3563                                 pApp = UiApp::GetInstance();
3564                                 if (pApp != null)
3565                                 {
3566                                         r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
3567                                         if (IsFailed(r))
3568                                         {
3569                                                 AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
3570                                                 return;
3571                                         }
3572                                 }
3573                         }
3574                         if (pSceneManager != null && pWindowInfo != null && pSceneManager->GetCurrentSceneId() == pWindowInfo->sceneID && pWindowInfo->isJavascriptInitiated == true)
3575                         {
3576                                 r = SceneRegister::DestroyAndUnRegisterScene(pWindowInfo->sceneID);
3577                                 if (IsFailed(r))
3578                                 {
3579                                         AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
3580                                         return;
3581                                 }
3582                                 r = pAllWindowList->RemoveAt(count, true);
3583                                 __pWindowInfo = null;
3584                                 if (IsFailed(r))
3585                                 {
3586                                         AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
3587                                         return;
3588                                 }
3589                                 if(count > 0)
3590                                 {
3591                                         pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count - 1));
3592                                 }
3593                                 else if(pAllWindowList->GetCount() > 0)
3594                                 {
3595                                         pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(pAllWindowList->GetCount() - 1));
3596                                 }
3597                                 else
3598                                 {
3599                                         pApp = UiApp::GetInstance();
3600                                         if (pApp != null)
3601                                         {
3602                                                 r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
3603                                                 return;
3604                                         }
3605
3606                                 }
3607                                 if (pWindowInfo == null)
3608                                 {
3609                                         pApp = UiApp::GetInstance();
3610                                         if (pApp != null)
3611                                         {
3612                                                 r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
3613                                                 return;
3614                                         }
3615                                 }
3616                                 else
3617                                 {
3618                                         r = pSceneManager->GoForward(ForwardSceneTransition(pWindowInfo->sceneID ,SCENE_TRANSITION_ANIMATION_TYPE_NONE,SCENE_HISTORY_OPTION_ADD_HISTORY,SCENE_DESTROY_OPTION_DESTROY));
3619 //                                      r = pSceneManager->GoBackward(BackwardSceneTransition(pWindowInfo->sceneID ,SCENE_TRANSITION_ANIMATION_TYPE_NONE));
3620                                         if (IsFailed(r))
3621                                         {
3622                                                 AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
3623                                                 return;
3624                                         }
3625                                 }
3626                                 break;
3627                         }
3628
3629                 }
3630
3631         }
3632
3633 }
3634
3635 void
3636 MainForm::OnForwardClicked(/*const Addressbar& addBar*/)
3637 {
3638         AppLog("MainForm::OnForwardClicked");
3639         if (__pWebViewer == null)
3640                 return;
3641
3642         if (__pWebViewer->CanGoForward())
3643         {
3644                 __pWebViewer->GoForward();
3645         }
3646 }
3647
3648 void
3649 MainForm::OnAddressBarFocusGained(const Addressbar& addBar)
3650 {
3651         AppLog("XYZ::MainForm::OnAddressBarFocusGained");
3652         if(__pFooterPanel != null)
3653         {
3654                 __pFooterPanel->SetShowState(false);
3655         }
3656
3657         if (__pAddressbar != null && __pAddressbar->GetShowState() == false)
3658         {
3659                 __pAddressbar->SetShowState(true);
3660                 __pAddressbar->SetBounds(Rectangle(0,0,GetClientAreaBounds().width,__pAddressbar->GetHeight()));
3661         }
3662
3663         RelayoutControls(false);
3664 }
3665
3666 void
3667 MainForm::OnAddressBarFocusLost(const Addressbar& addBar, bool addressbarKeyPadState)
3668 {
3669         AppLog("XYZ::MainForm::OnAddressBarFocusLost");
3670
3671         int Height = GetClientAreaBounds().height;
3672         AppLog("MainForm::OnAddressBarFocusLost height is %d",Height);
3673
3674         RelayoutControls(false);
3675 }
3676
3677 void
3678 MainForm::OnAddressCancelledClicked(const Addressbar& addBar)
3679 {
3680         AddressBarCancelledClicked(addBar);
3681 }
3682
3683 void
3684 MainForm::OnAddressBarModeChanged(/*const Addressbar& addBar*/)
3685 {
3686         __prevAddressBarMode = __curAddressBarMode;
3687
3688         if (__pAddressbar != null)
3689         {
3690                 __curAddressBarMode = GetAddressbarMode();
3691         }
3692
3693         if (__curAddressBarMode == ADDRESSBAR_MODE_EDIT)
3694         {
3695                 __adressPanelPosition.y = 0;
3696                 if (__pAddressbar != null)
3697                 {
3698                         __webControlPosition.y = __pAddressbar->GetHeight() - 12;
3699                         __pAddressbar->SetBounds(Rectangle(0,0,GetClientAreaBounds().width,__pAddressbar->GetHeight()));
3700                         __pAddressbar->Invalidate(true);
3701                 }
3702                 if (__pWebViewer != null)
3703                 {
3704                         __pWebViewer->StopLoading();
3705                 }
3706         }
3707         else if(__curAddressBarMode == ADDRESSBAR_MODE_LOADING)
3708         {
3709                 __adressPanelPosition.y = 0;
3710                 if (__pAddressbar != null)
3711                 {
3712                         __webControlPosition.y = 0;
3713                         __pAddressbar->SetBounds(Rectangle(0, __pAddressbar->GetY() - __pAddressbar->GetHeight(), GetClientAreaBounds().width, __pAddressbar->GetHeight()));
3714                         __pAddressbar->Invalidate(true);
3715                 }
3716         }
3717 }
3718
3719 void
3720 MainForm::OnClipboardClosed(const Addressbar& addBar)
3721 {
3722         AppLog("XYZ::MainForm::OnClipboardClosed");
3723         if (__pFooterPanel && __pAddressbar->GetShowState() == false)
3724         {
3725                 AppLog("akjshdasd 3");
3726                 __pFooterPanel->SetShowState(true);
3727         }
3728         __isKeypadOpened = false;
3729         RelayoutControls(false);
3730 }
3731
3732 void
3733 MainForm::OnAddressBarKeypadClosed(const Addressbar& addBar, bool footerState)
3734 {
3735         AppLog("XYZ::MainForm::OnAddressBarKeypadClosed");
3736         if (__pFooterPanel && __pAddressbar->GetShowState() == false)
3737         {
3738                 AppLog("akjshdasd 3");
3739                 __pFooterPanel->SetShowState(true);
3740         }
3741         __isKeypadOpened = false;
3742         if(__pNotification && __pNotification->GetShowState())
3743         {
3744                 __pNotification->SetPosition(0,GetClientAreaBounds().height - __pNotification->GetHeight());
3745         }
3746
3747         RelayoutControls(false,footerState);
3748 }
3749
3750 void
3751 MainForm::OnAddressBarKeypadOpened(const Addressbar& addBar)
3752 {
3753         AppLog("XYZ::MainForm::OnAddressBarKeypadOpened");
3754         __isKeypadOpened = true;
3755         if(__pNotification && __pNotification->GetShowState())
3756         {
3757                 __pNotification->SetPosition(0,GetClientAreaBounds().height - __pNotification->GetHeight());
3758         }
3759         RelayoutControls(false);
3760 }
3761
3762 void
3763 MainForm::OnAddressBarKeypadWillOpen(const Addressbar& addBar)
3764 {
3765         __isKeypadOpened = true;
3766         __pFooterPanel->SetShowState(false);
3767 }
3768
3769 void
3770 MainForm::OnAddressBarKeypadBoundsChanged(const Addressbar& addBar)
3771 {
3772         AppLog("XYZ::MainForm::OnAddressBarKeypadBoundsChanged");
3773         RelayoutControls(false);
3774 }
3775
3776 void
3777 MainForm::OnPageTitleReceived(const Tizen::Base::String& title)
3778 {
3779         AppLog("MainForm::OnPageTitleReceived %ls",title.GetPointer());
3780         if (__pWindowInfo)
3781         {
3782                 __pWindowInfo->pageTitle = title;
3783                 if (__pWebViewer != null)
3784                 {
3785                         __pWindowInfo->pageUrl = __pWebViewer->GetUrl();
3786                         AppLog("MainForm::OnPageTitleReceived url %ls",__pWindowInfo->pageUrl.GetPointer());
3787                 }
3788         }
3789         if (__pAddressbar != null && __pWebViewer != null)
3790         {
3791                 SetUrl(__pWebViewer->GetUrl());
3792                 __pAddressbar->Invalidate(true);
3793         }
3794 }
3795
3796 void
3797 MainForm::UpdateFavicon(void)
3798 {
3799         bool urlImageType = false;
3800         String *tempPath = null;
3801         if(__pWebViewer)
3802                 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();");
3803         Bitmap* pBitmap = null;
3804
3805         if (tempPath && tempPath->GetLength() > 0 && tempPath->CompareTo(L"undefined") != 0)
3806         {
3807                 if (__pWindowInfo != null)
3808                 {
3809                         Uri url;
3810                         url.SetUri(*tempPath);
3811                         if (url.GetHost().GetLength() == 0)
3812                         {
3813                                 Uri webUrl;
3814                                 if(__pWebViewer)
3815                                         webUrl.SetUri(__pWebViewer->GetUrl());
3816                                 result r = url.SetHost(webUrl.GetHost());
3817                                 if(IsFailed(r))
3818                                 {
3819                                         delete tempPath;
3820                                         return;
3821                                 }
3822                         }
3823                         if (url.GetScheme().GetLength() == 0)
3824                         {
3825                                 Uri webUrl;
3826                                 if(__pWebViewer)
3827                                         webUrl.SetUri(__pWebViewer->GetUrl());
3828                                 url.SetScheme(webUrl.GetScheme());
3829                         }
3830                         __pWindowInfo->faviconUrl = url.ToString();
3831
3832                         pBitmap = __pWebViewer->GetFaviconN();
3833
3834                         if (pBitmap != null)
3835                         {
3836                                 if (__pWindowInfo->pFavicon != NULL)
3837                                 {
3838                                         __pWindowInfo->pFavicon = null;
3839                                 }
3840                                 __pWindowInfo->pFavicon = new(std::nothrow) Bitmap();
3841                                 __pWindowInfo->pFavicon->Construct(*pBitmap,Rectangle(0,0,pBitmap->GetWidth(),pBitmap->GetHeight()));
3842
3843                                 __pAddressbar->SetFaviconBitmap(*__pWindowInfo->pFavicon);
3844
3845                                 FaviconManager::GetInstance()->SaveFavicon(*__pWindowInfo->pFavicon, __pWindowInfo->faviconUrl);
3846                         }
3847                         else if(__pWindowInfo->pFavicon != null)
3848                         {
3849                                 __pAddressbar->SetFaviconBitmap(*__pWindowInfo->pFavicon);
3850                         }
3851                         else
3852                         {
3853                                 Bitmap *pDefaultBmp = FaviconManager::GetInstance()->GetDefaultFaviconN();
3854                                 if(pDefaultBmp != null)
3855                                 {
3856                                         __pAddressbar->SetFaviconBitmap(*pDefaultBmp);
3857                                 }
3858                         }
3859                         if(pBitmap)
3860                         {
3861                                 delete pBitmap;
3862                                 pBitmap = null;
3863                         }
3864                 }
3865                 delete tempPath;
3866         }
3867         else
3868         {
3869                 // do not remove
3870                 if(tempPath != null)
3871                 {
3872                         delete tempPath;
3873                 }
3874                 AppLogDebug("Error occured: %s", GetErrorMessage(GetLastResult()));
3875         }
3876
3877 }
3878
3879 bool
3880 MainForm::OnLoadingRequested(const Tizen::Base::String& url,
3881                 Tizen::Web::Controls::WebNavigationType type)
3882 {
3883         AppLog("urlk %ls",url.GetPointer());
3884         // when load new page if find word panel is open its show state is false
3885         if(__pFindWordControl && __pFindWordControl->GetShowState() == true)
3886         {
3887                 __currentSearchStr = L"";
3888                 __currentWordIndex = 0;
3889                 __maxOccurrances = 0;
3890                 __pFindWordEditField->SetText(L"");
3891                 __pFindWordNext->SetEnabled(false);
3892                 __pFindWordPrev->SetEnabled(false);
3893                 __pFindWordCountLabel->SetText(L"0/0");
3894                 __pFindWordControl->SetShowState(false);
3895                 __pFindWordEditField->HideKeypad();
3896                 RelayoutControls(false);
3897         }
3898
3899         __pFooterPanel->Invalidate(true);
3900
3901         Uri uriInfo;
3902         uriInfo.SetUri(url);
3903
3904         if(url.Contains(IDS_TIZEN_SERVICE))
3905         {
3906                 String appId;
3907                 String delim(L":;,");
3908
3909                 // Creates a StringTokenizer instance
3910                 StringTokenizer strTok(url, delim);
3911
3912                 int count = strTok.GetTokenCount();     // count == 4
3913
3914                 HashMap *pMap = new HashMap();
3915                 pMap->Construct();
3916
3917                 String token;
3918                 String key;
3919                 String value;
3920                 while (strTok.HasMoreTokens())
3921                 {
3922                         AppLog("Token: %ls", token.GetPointer());
3923                         strTok.GetNextToken(token);         // Tizen, StringTokenizer, Sample, code
3924                         if(token.Contains(IDS_APPID))
3925                         {
3926                                 token.SubString(6, appId);
3927                                 AppLog("AppID:%ls", appId.GetPointer());
3928                         }
3929                         else if(token.Contains(IDS_KEY))
3930                         {
3931                                 token.SubString(4, key);
3932                                 AppLog("key:%ls", key.GetPointer());
3933                         }
3934                         else if(token.Contains(IDS_VALUE))
3935                         {
3936                                 token.SubString(6, value);
3937                                 AppLog("value:%ls", value.GetPointer());
3938                         }
3939                 }
3940                 pMap->Add(key, value);
3941
3942                 if(appId != "")
3943                 {
3944                         AppControl *pAppControl = null;
3945                         String operationId = L"http://tizen.org/appcontrol/operation/main";
3946                         pAppControl = dynamic_cast<AppControl*>(AppManager::FindAppControlN(appId, operationId));
3947                         if(pAppControl)
3948                         {
3949                                 result r = pAppControl->Start(null, null, pMap, null);
3950                         }
3951                         else
3952                         {
3953                                 AppLogException("AppControl not found");
3954                         }
3955                         return true;
3956                 }
3957         }
3958
3959         return false;
3960 }
3961
3962 DecisionPolicy
3963 MainForm::OnWebDataReceived(const Tizen::Base::String& mime,
3964                 const Tizen::Net::Http::HttpHeader& httpHeader)
3965 {
3966         return Tizen::Web::Controls::WEB_DECISION_CONTINUE;
3967 }
3968
3969 void
3970 MainForm::OnWebPageBlockSelected(Web& source, FloatPoint& startPoint, FloatPoint& endPoint)
3971 {
3972         AppLog("MainForm::OnWebPageBlockSelected");
3973 //      if(__isLongPressedDone == false)
3974 //              return;
3975
3976         if (__pHitElementResult != null)
3977         {
3978                 delete __pHitElementResult;
3979                 __pHitElementResult = null;
3980         }
3981
3982         if (__pWebViewer != null)
3983         {
3984                 AppLog("MainForm::OnWebPageBlockSelected web not null");
3985                 __pHitElementResult = __pWebViewer->GetElementByPointN(startPoint);
3986
3987                 if(GetLastResult() == E_INVALID_ARG || (__pHitElementResult->GetTagName().Equals(L"INPUT",false) == false && __pHitElementResult->GetTagName().Equals(L"TEXTAREA",false) == false))
3988                 {
3989                         AppLog("datafirst startpoint error %s",GetErrorMessage(GetLastResult()));
3990                         __pHitElementResult = __pWebViewer->GetElementByPointN(endPoint);
3991                         if(GetLastResult() == E_INVALID_ARG || (__pHitElementResult->GetTagName().Equals(L"INPUT",false) == false && __pHitElementResult->GetTagName().Equals(L"TEXTAREA",false) == false))
3992                         {
3993                                 __pHitElementResult = __pWebViewer->GetElementByPointN(__longPressPoint);
3994                         }
3995                         AppLog("datafirst endpoint error %s",GetErrorMessage(GetLastResult()));
3996                 }
3997         }
3998
3999         if (__pHitElementResult == null)
4000         {
4001                 return;
4002         }
4003
4004         if (__pHitElementResult->HasImage() != true)
4005         {
4006                 String tagName = __pHitElementResult->GetTagName();
4007                 String type = __pHitElementResult->GetAttributeValue("type");
4008
4009
4010                 AppLog("TagName %ls",tagName.GetPointer());
4011                 __currentSelectedStr.Clear();
4012                 AppLog("__currentSelectedStr after clear %ls",__currentSelectedStr.GetPointer());
4013                 __currentSelectedStr = __pWebViewer->GetTextFromBlock();
4014                 AppLog("__currentSelectedStr after GetTextFromBlock %ls",__currentSelectedStr.GetPointer());
4015                 if(tagName.Equals(L"TEXTAREA",false) == true)
4016                 {
4017                         AppLog("Tagnameseemstobe TEXTAREA");
4018                 }
4019                 else if(tagName.Equals(L"INPUT",false) == true)
4020                 {
4021                         AppLog("Tagnameseemstobe INPUT");
4022                 }
4023
4024                 if (((tagName.Equals(L"INPUT",false) == true)  || tagName.Equals(L"TEXTAREA",false) == true) /*&& __isLongPressedDone == true*/ && __currentSelectedStr.CompareTo(L"") !=0)
4025                 {
4026                         AppLog("MainForm::OnWebPageBlockSelected show paste option");
4027
4028                         InitSelectTextContextMenuF(FloatPoint(endPoint.x,endPoint.y + __pWebViewer->GetY()),true);
4029                         if(__pImageMenu)
4030                         {
4031                                 __pImageMenu->SetShowState(true);
4032                                 __pImageMenu->Show();
4033                                 __pImageMenu->Invalidate(true);
4034                         }
4035                 }
4036                 else /*if(__isLongPressedDone == true)*/
4037                 {
4038                         AppLog("MainForm::OnWebPageBlockSelected no paste option");
4039
4040                         if(__pHitElementResult->GetUrl().GetLength() > 0)
4041                         {
4042                                 __currentSelectedStr.Clear();
4043                                 __currentSelectedStr = __pHitElementResult->GetUrl();
4044                         }
4045                         InitSelectTextContextMenuF(FloatPoint(endPoint.x,endPoint.y + __pWebViewer->GetY()),false);
4046                         if(__pImageMenu)
4047                         {
4048                                 __pImageMenu->SetShowState(true);
4049                                 __pImageMenu->Show();
4050                                 __pImageMenu->Invalidate(true);
4051                         }
4052                 }
4053
4054                 AppLog("MainForm::OnWebPageBlockSelected block text is %ls",__currentSelectedStr.GetPointer());
4055                 AppLog("MainForm::OnWebPageBlockSelected tag name is %ls",tagName.GetPointer());
4056                 AppLog("MainForm::OnWebPageBlockSelected type name is %ls",type.GetPointer());
4057         }
4058
4059 }
4060
4061 void
4062 MainForm::OnWebPageShowRequested(Tizen::Web::Controls::Web& source)
4063 {
4064
4065 }
4066
4067 Web*
4068 MainForm::OnWebWindowCreateRequested(void)
4069 {
4070         AppLog("MainForm::OnWebWindowCreateRequested entered");
4071         WindowInfo* pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewSceneN();
4072
4073         if (pNewWindowInfo == null)
4074         {
4075                 return null;
4076         }
4077         result r = E_SUCCESS;
4078         SceneManager* pSceneManager = SceneManager::GetInstance();
4079         if (pSceneManager == NULL)
4080         {
4081                 return null;
4082         }
4083         ArrayList* pArgList = new(std::nothrow) ArrayList();
4084         if (pArgList == NULL)
4085         {
4086                 return null;
4087         }
4088         r = pArgList->Construct();
4089         if (r == E_SUCCESS)
4090         {
4091                 pNewWindowInfo->isJavascriptInitiated = true;
4092                 pArgList->Add(*pNewWindowInfo);
4093                 r = pSceneManager->GoForward(ForwardSceneTransition(pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
4094                 delete pArgList;
4095                 if (IsFailed(r))
4096                 {
4097                         AppLogDebug("EditHistoryListForm::OnFormBackRequested Failed to GoBackward %s",GetErrorMessage(r));
4098                         return null;
4099                 }
4100         } else {
4101                 delete pArgList;
4102         }
4103
4104         return pNewWindowInfo->pCurrentWeb;
4105 }
4106
4107 void MainForm::OnWebWindowCloseRequested(Tizen::Web::Controls::Web& source)
4108 {
4109         AppLog("OnWebWindowCloseRequested");
4110         ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
4111         SceneManager* pSceneManager = SceneManager::GetInstance();
4112         WindowInfo* pWindowInfo = null;
4113         WindowInfo* pNewWindowInfo = null;
4114         int totalCount = 0;
4115         UiApp* pApp = null;
4116         result r = E_FAILURE;
4117
4118         if (pAllWindowList != null)
4119         {
4120                 totalCount = pAllWindowList->GetCount();
4121         }
4122
4123         for (int count = 0; count < totalCount; count++)
4124         {
4125                 pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count));
4126                 if (pSceneManager != null && pWindowInfo != null && pSceneManager->GetCurrentSceneId() == pWindowInfo->sceneID)
4127                 {
4128                         r = SceneRegister::DestroyAndUnRegisterScene(pWindowInfo->sceneID);
4129                         if (IsFailed(r))
4130                         {
4131                                 AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
4132                                 return;
4133                         }
4134
4135                         r = pAllWindowList->RemoveAt(count, true);
4136
4137                         if(count > 0)
4138                         {
4139                                 pNewWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count - 1));
4140                         }
4141                         else if(pAllWindowList->GetCount() > 0)
4142                         {
4143                                 pNewWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(pAllWindowList->GetCount() - 1));
4144                         }
4145                         else
4146                         {
4147                                 WindowInfo* pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewSceneN();
4148
4149                                 if (pNewWindowInfo == null)
4150                                 {
4151                                         return;
4152                                 }
4153                                 result r = E_SUCCESS;
4154                                 SceneManager* pSceneManager = SceneManager::GetInstance();
4155                                 if (pSceneManager == NULL)
4156                                 {
4157                                         return;
4158                                 }
4159                                 ArrayList* pArgList = new(std::nothrow) ArrayList();
4160                                 if (pArgList == NULL)
4161                                 {
4162                                         return;
4163                                 }
4164                                 r = pArgList->Construct();
4165                                 if (r == E_SUCCESS)
4166                                 {
4167                                         pArgList->Add(*pNewWindowInfo);
4168                                         result r = pSceneManager->GoForward(ForwardSceneTransition(pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
4169                                         if (pArgList != null)
4170                                         {
4171                                                 delete pArgList;
4172                                                 pArgList = null;
4173                                         }
4174                                         if(IsFailed(r))
4175                                         {
4176                                                 AppLogDebug("MultipleWindowForm::OnActionPerformed GoForward failed %s",GetErrorMessage(r));
4177                                                 return;
4178                                         }
4179                                 }
4180
4181                                 pApp = UiApp::GetInstance();
4182                                 if (pApp != null)
4183                                 {
4184                                         r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
4185                                         return;
4186                                 }
4187
4188                         }
4189                         r = pSceneManager->GoForward(ForwardSceneTransition(pNewWindowInfo->sceneID ,SCENE_TRANSITION_ANIMATION_TYPE_NONE,SCENE_HISTORY_OPTION_ADD_HISTORY,SCENE_DESTROY_OPTION_DESTROY));
4190
4191                         __pWindowInfo = null;
4192                         break;
4193                 }
4194         }
4195
4196 }
4197
4198 void
4199 MainForm::RelayoutControls(bool showAddressbar,bool relayoutFooter)
4200 {
4201         AppLog("xyz:: MainForm::RelayoutControls called");
4202         __webControlPosition.y = 0;
4203         __webControlHeight = GetClientAreaBounds().height;
4204         AppLog("Client area height: %d", __webControlHeight);
4205
4206         AppLog("Client area height: %d", __webControlHeight);
4207         if(__pAddressbar != null && __pAddressbar->GetShowState() == true)
4208         {
4209                 __webControlPosition.y += __pAddressbar->GetHeight();
4210                 __webControlHeight -= __pAddressbar->GetHeight();
4211                 __pAddressbar->SetBounds(0, 0, __pAddressbar->GetWidth(), __pAddressbar->GetHeight());
4212         }
4213         else if(__pFindWordControl != null && __pFindWordControl->GetShowState() == true)
4214         {
4215                 __webControlPosition.y += __pFindWordControl->GetHeight();
4216                 __webControlHeight -= __pFindWordControl->GetHeight();
4217                 __pFindWordControl->SetBounds(0, 0, GetClientAreaBounds().width, __pFindWordControl->GetHeight());
4218         }
4219
4220         if(__pFooterPanel != null && __pFooterPanel->GetShowState() == true && relayoutFooter == true)
4221         {
4222                 __webControlHeight -= __pFooterPanel->GetHeight();
4223
4224                 __pFooterPanel->SetBounds(0, __webControlPosition.y + __webControlHeight, GetClientAreaBounds().width, __pFooterPanel->GetHeight());
4225                 __webControlHeight = __webControlHeight + 12;
4226         }
4227         if (__pWebViewer != null && __pWebViewer->GetShowState() == true)
4228         {
4229                 if(__pWebViewer->GetX() == 0 && __pWebViewer->GetY() == __webControlPosition.y &&__pWebViewer->GetWidth() == GetClientAreaBounds().width &&__pWebViewer->GetHeight() == __webControlHeight )
4230                 {
4231                 }
4232                 else
4233                 {
4234                         __pWebViewer->SetBounds(0, __webControlPosition.y, GetClientAreaBounds().width, __webControlHeight );
4235                         AppLog("xyz:: MainForm::RelayoutControls called __webControlHeight %d",__webControlHeight);
4236                         __pWebViewer->Invalidate(false);
4237                 }
4238         }
4239         if(__pMostVisitedListView != null && __pAddressbar != null && __pFooterPanel != null)
4240         {
4241                 __pMostVisitedListView->SetBounds(Tizen::Graphics::Rectangle(0,__webControlPosition.y , GetClientAreaBounds().width, __webControlHeight));
4242         }
4243
4244         Invalidate(true);
4245 }
4246
4247 void
4248 MainForm::ShowFindWordPanel(bool show , bool isTouchPressed)
4249 {
4250         if (__pFindWordControl == null)
4251         {
4252                 return;
4253         }
4254
4255         Tizen::Locales::LocaleManager localeManager;
4256         Tizen::Locales::Locale local = localeManager.GetSystemLocale();
4257
4258         String languageCode;
4259         result r = SettingInfo::GetValue(L"Language", languageCode);
4260         // int languagecode = local.GetLanguageCode();
4261         AppLog("rahul language is %S", languageCode.GetPointer());
4262
4263         if (show == true)
4264         {
4265                 InitFindWordPanel();
4266
4267                 if (languageCode.CompareTo("ara") == 0)
4268                 {
4269                         AppLog("rahul language is arabic");
4270
4271                         __pFindWordPanelLeftToRight->SetShowState(false);
4272                         __pFindWordPanelRightToLeft->SetShowState(true);
4273
4274                         __pFindWordClear->SetShowState(false);
4275                         __pFindWordCountLabel->SetShowState(false);
4276                         __pFindWordEditField->SetShowState(false);
4277
4278                         __pFindWordClearRightToLeft->SetShowState(true);
4279                         __pFindWordCountLabelRightToLeft->SetShowState(true);
4280                         __pFindWordEditFieldRightToLeft->SetShowState(true);
4281                 }
4282                 else
4283                 {
4284                         AppLog("rahul language is not arabic");
4285
4286
4287                         __pFindWordPanelLeftToRight->SetShowState(true);
4288                         __pFindWordPanelRightToLeft->SetShowState(false);
4289
4290                         __pFindWordClear->SetShowState(true);
4291                         __pFindWordCountLabel->SetShowState(true);
4292                         __pFindWordEditField->SetShowState(true);
4293
4294                         __pFindWordClearRightToLeft->SetShowState(false);
4295                         __pFindWordCountLabelRightToLeft->SetShowState(false);
4296                         __pFindWordEditFieldRightToLeft->SetShowState(false);
4297                 }
4298                 __pFindWordControl->SetShowState(true);
4299         }
4300         else
4301         {
4302                 if(__pFindWordControl != null)
4303                 {
4304                         __pFindWordControl->SetShowState(false);
4305                 }
4306         }
4307
4308         AppLog("MainForm::ShowFindWordPanel %d",show);
4309         if (show && !isTouchPressed)
4310         {
4311                 if (languageCode.CompareTo("ara") == 0)
4312                 {
4313                         if (__pFindWordEditFieldRightToLeft)
4314                         {
4315                                 __pFindWordEditFieldRightToLeft->SetFocus();
4316                                 __pFindWordEditFieldRightToLeft->ShowKeypad();
4317                         }
4318                 }
4319                 else
4320                 {
4321                         if (__pFindWordEditField)
4322                         {
4323                                 __pFindWordEditField->SetFocus();
4324                                 __pFindWordEditField->ShowKeypad();
4325                         }
4326                 }
4327         }
4328         else
4329         {
4330                 if (languageCode.CompareTo("ara") == 0)
4331                 {
4332                         if (__pFindWordEditFieldRightToLeft)
4333                                 __pFindWordEditFieldRightToLeft->HideKeypad();
4334                 }
4335                 else
4336                 {
4337                         if (__pFindWordEditField)
4338                                 __pFindWordEditField->HideKeypad();
4339                 }
4340         }
4341
4342         RelayoutControls(false);
4343 }
4344
4345 void
4346 MainForm::StartWordSearch()
4347 {
4348         //Get the count of occurances of the word in the current page
4349         __maxOccurrances = 0;
4350         __currentWordIndex = 0;
4351
4352         __pFindWordPrev->SetEnabled(false);
4353         String *pCountStr = null;
4354         if (__pWebViewer)
4355         {
4356                 result r = __pWebViewer->SearchTextAllAsync(__currentSearchStr, false);
4357                 AppLog("Search Result %s",GetErrorMessage(r));
4358         }
4359
4360         /*__pWebViewer->EvaluateJavascriptN(L"document.body.textContent.match(/"  + __currentSearchStr + "/gi).length;");
4361         if (pCountStr != null)
4362         {
4363                 Integer::Parse(*pCountStr, 10, __maxOccurrances);
4364                 delete pCountStr;
4365         }
4366
4367         AppLogDebug("'%ls' is found %d times", __currentSearchStr.GetPointer(), __maxOccurrances);
4368          */
4369
4370 }
4371
4372 void MainForm::OnTextFound(int totalCount, int currentOrdinal)
4373 {
4374         AppLog("MainForm::OnTextFound totalCount %d",totalCount);
4375         AppLog("MainForm::OnTextFound currentOrdinal %d",currentOrdinal);
4376
4377         if(totalCount <= 9)
4378         {
4379                 if (__pFindWordCountLabel)
4380                 {
4381                         __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),84,__pFindWordCountLabel->GetHeight());
4382                 }
4383                 if (__pFindWordEditField)
4384                 {
4385                         __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),214+80,__pFindWordEditField->GetHeight());
4386                 }
4387         }
4388         else if(totalCount >= 100)
4389         {
4390                 if (__pFindWordCountLabel)
4391                 {
4392                         __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),124,__pFindWordCountLabel->GetHeight());
4393                 }
4394                 if (__pFindWordEditField)
4395                 {
4396                         __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),174,__pFindWordEditField->GetHeight());
4397                 }
4398         }
4399         else
4400         {
4401                 if (__pFindWordCountLabel)
4402                 {
4403                         __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),124,__pFindWordCountLabel->GetHeight());
4404                 }
4405                 if (__pFindWordEditField)
4406                 {
4407                         __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),174,__pFindWordEditField->GetHeight());
4408                 }
4409         }
4410
4411         __maxOccurrances = totalCount;
4412         __currentWordIndex = currentOrdinal;
4413
4414         //Reset the UI controls as per the maxOccurrance value
4415         if (totalCount <= 0)
4416         {
4417                 AppLog("Word not found");
4418                 //Show error notification to user
4419                 __pFindWordNext->SetEnabled(false);
4420                 if(__pFindWordCountLabel && __pFindWordCountLabel->GetShowState() == true)
4421                 {
4422                         __pFindWordCountLabel->SetText(L"0/0");
4423                         __pFindWordCountLabel->Invalidate(false);
4424                 }
4425                 else if(__pFindWordCountLabelRightToLeft && __pFindWordCountLabelRightToLeft->GetShowState() == true)
4426                 {
4427                         __pFindWordCountLabelRightToLeft->SetText(L"0/0");
4428                         __pFindWordCountLabelRightToLeft->Invalidate(false);
4429                 }
4430                 __pFindWordNext->Invalidate(false);
4431                 __pFindWordPrev->Invalidate(false);
4432
4433                 return;
4434         }
4435
4436         if (totalCount == 1 || totalCount == currentOrdinal)
4437         {
4438                 __pFindWordNext->SetEnabled(false);
4439         }
4440         else
4441         {
4442                 __pFindWordNext->SetEnabled(true);
4443         }
4444
4445         String countStr = L"";
4446         countStr.Append(__currentWordIndex);
4447         countStr.Append(L"/");
4448         countStr.Append(__maxOccurrances);
4449         if (__pFindWordCountLabel && __pFindWordCountLabel->GetShowState() == true)
4450         {
4451         __pFindWordCountLabel->SetText(countStr);
4452         __pFindWordCountLabel->Invalidate(false);
4453         __pFindWordCountLabel->Invalidate(false);
4454         }
4455         else if (__pFindWordCountLabelRightToLeft && __pFindWordCountLabelRightToLeft->GetShowState() == true)
4456         {
4457                 __pFindWordCountLabelRightToLeft->SetText(countStr);
4458                 __pFindWordCountLabelRightToLeft->Invalidate(false);
4459                 __pFindWordCountLabelRightToLeft->Invalidate(false);
4460         }
4461         if (__pFindWordNext)
4462         {
4463                 __pFindWordNext->Invalidate(false);
4464         }
4465         if (__pFindWordPrev)
4466         {
4467                 __pFindWordPrev->Invalidate(false);
4468         }
4469
4470 }
4471
4472 void
4473 MainForm::FindNextWord(bool next)
4474 {
4475         if (next == true)
4476         {
4477                 //if (__pWebViewer->SearchText(__currentSearchStr, true) == true)
4478                         if (__pWebViewer->SearchNextAsync(true) == E_SUCCESS)
4479                         {
4480                                 if (__currentWordIndex < __maxOccurrances)
4481                                 {
4482                                         __currentWordIndex++;
4483                                 }
4484                         }
4485         }
4486         else
4487         {
4488                 //if (__pWebViewer->SearchText(__currentSearchStr, false) == true)
4489                 if (__pWebViewer->SearchNextAsync(false) == E_SUCCESS)
4490                 {
4491                         if(__currentWordIndex > 1)
4492                         {
4493                                 __currentWordIndex--;
4494                         }
4495                 }
4496         }
4497
4498         String countStr = L"";
4499         countStr.Append(__currentWordIndex);
4500         countStr.Append(L"/");
4501         countStr.Append(__maxOccurrances);
4502
4503         if (__pFindWordCountLabel && __pFindWordCountLabel->GetShowState() == true)
4504         {
4505         __pFindWordCountLabel->SetText(countStr);
4506         __pFindWordCountLabel->Invalidate(false);
4507         }
4508         else if(__pFindWordCountLabelRightToLeft && __pFindWordCountLabelRightToLeft->GetShowState() == true)
4509         {
4510                 __pFindWordCountLabelRightToLeft->SetText(countStr);
4511                 __pFindWordCountLabelRightToLeft->Invalidate(false);
4512         }
4513
4514         if (__currentWordIndex >= __maxOccurrances)
4515         {
4516                 __pFindWordNext->SetEnabled(false);
4517         }
4518         else
4519         {
4520                 __pFindWordNext->SetEnabled(true);
4521         }
4522         if (__currentWordIndex <= 1)
4523         {
4524                 __pFindWordPrev->SetEnabled(false);
4525         }
4526         else
4527         {
4528                 __pFindWordPrev->SetEnabled(true);
4529         }
4530         __pFindWordPrev->Invalidate(false);
4531         __pFindWordNext->Invalidate(false);
4532
4533         __pFindWordControl->Invalidate(true);
4534 }
4535
4536 void
4537 MainForm::OnWebKeypadWillOpen(Tizen::Web::Controls::Web& source)
4538 {
4539         AppLog("xyz::MainForm::OnWebKeypadWillOpen");
4540         __isKeypadOpened = true;
4541         __pFooterPanel->SetShowState(false);
4542         //      OnAddressBarKeypadOpened(*__pAddressbar);
4543 }
4544
4545 void
4546 MainForm::OnWebKeypadOpened(Tizen::Web::Controls::Web& source)
4547 {
4548         __isKeypadOpened = true;
4549         AppLog("xyz::MainForm::OnWebKeypadOpened");
4550
4551         if(__pFindWordControl && __pFindWordControl->GetShowState() == true)
4552         {
4553                 __currentSearchStr = L"";
4554                 __currentWordIndex = 0;
4555                 __maxOccurrances = 0;
4556                 __pFindWordEditField->SetText(L"");
4557                 __pFindWordNext->SetEnabled(false);
4558                 __pFindWordPrev->SetEnabled(false);
4559                 __pFindWordCountLabel->SetText(L"0/0");
4560                 __pWebViewer->SearchTextAllAsync(L"",false);
4561                 __pFindWordControl->SetShowState(false);
4562                 __pFindWordEditField->HideKeypad();
4563         }
4564
4565
4566         if (__pWebViewer != null && __pFooterPanel != null)
4567         {
4568                 AppLog("MainForm::OnWebKeypadOpened GetClientAreaBounds().height %d ", GetClientAreaBounds().height);
4569                 if(__pAddressbar != null)
4570                 {
4571                         __pAddressbar->SetShowState(false);
4572                 }
4573                 if(__pFindWordControl != null)
4574                 {
4575                         __pFindWordControl->SetShowState(false);
4576                 }
4577                 __pFooterPanel->SetShowState(false);
4578                 __pWebViewer->SetBounds(Rectangle(0, 0,GetClientAreaBounds().width, GetClientAreaBounds().height));
4579         }
4580 //      if(__pImageMenu && __pImageMenu->GetShowState() == true)
4581 //      {
4582 //              __pImageMenu->SetAnchorPosition(Point(__pImageMenu->GetAnchorPosition().x/2,__pImageMenu->GetAnchorPosition().y/2));
4583 //              AppLog("omgomgomg");
4584 //      }
4585         Invalidate(true);
4586 }
4587
4588 void
4589 MainForm::OnWebKeypadClosed(Tizen::Web::Controls::Web& source)
4590 {
4591         AppLog("abcde::MainForm::OnWebKeypadClosed");
4592         AppLog("xyz::MainForm::OnWebKeypadClosed");
4593         AppLog("akjshdasd 4");
4594         __pFooterPanel->SetShowState(true);
4595 //      OnAddressBarKeypadClosed(*__pAddressbar);
4596         RelayoutControls(false);
4597         __isKeypadOpened = false;
4598
4599
4600         if(__pImageMenu && __pImageMenu->GetShowState() == true)
4601         {
4602                 AppLog("abcde: imagemenu visible.");
4603                 Point p(0,0);
4604                 Point q(0,0);
4605                 __pWebViewer->GetBlockRange(p,q);
4606                 if (p == Point(0,0) && q == Point(0,0))
4607                         return;
4608
4609                 __pImageMenu->SetAnchorPosition(p);
4610                 __pImageMenu->Show();
4611                 Invalidate(true);
4612         }
4613 }
4614
4615 void
4616 MainForm::OnWebKeypadBoundsChanged(Tizen::Web::Controls::Web& source)
4617 {
4618         //      RelativeLayout(false);
4619         if(__pWebViewer != null)
4620         {
4621                 __pWebViewer->SetBounds(Rectangle(0,__webControlPosition.y,GetClientAreaBounds().width,GetClientAreaBounds().height));
4622         }
4623 }
4624
4625 void
4626 MainForm::OnTouchDoublePressed(const Control& source, const Point& currentPosition, const TouchEventInfo& touchInfo)
4627 {
4628         Control* temp = const_cast< Control* >(&source);
4629         Header* pHeader = dynamic_cast< Header* >(temp);
4630         if (pHeader != null)
4631         {
4632                 //Header double - clicked
4633                 AppLog("Header double clicked");
4634         }
4635         if(__pFindWordControl)
4636         {
4637                 AppLog("MainForm::OnTouchPressed %d",__pFindWordControl->GetShowState());
4638                 ShowFindWordPanel(__pFindWordControl->GetShowState(), true);
4639         }
4640
4641
4642         AppLog("MainScene::OnTouchDoublePressed");
4643
4644 }
4645
4646 void MainForm::OnTouchLongPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
4647 {
4648         AppLog("abcde::MainForm::OnTouchLongPressed %d, %d" ,currentPosition.x,currentPosition.y);
4649         if(TouchEventManager::GetInstance() && TouchEventManager::GetInstance()->GetTouchInfoListN() && TouchEventManager::GetInstance()->GetTouchInfoListN()->GetCount() >1)
4650         {
4651                 AppLog("Returning because of more than one touch point.");
4652                 return;
4653         }
4654         __longPressPoint = currentPosition;
4655
4656         if (__pHitElementResult != null)
4657         {
4658                 delete __pHitElementResult;
4659                 __pHitElementResult = null;
4660         }
4661
4662         if (__pWebViewer != null)
4663         {
4664                 AppLog("MainForm::OnTouchLongPressed web not null");
4665                 __pHitElementResult = __pWebViewer->GetElementByPointN(currentPosition);
4666         }
4667
4668         if (__pHitElementResult == null)
4669         {
4670                 return;
4671         }
4672
4673         if (__pHitElementResult->HasImage() == true)
4674         {
4675                 if(__pWebViewer != null)
4676                         InitImageContextMenu(Point(currentPosition.x,currentPosition.y + __pWebViewer->GetY()));
4677                 __pImageMenu->SetShowState(true);
4678                 __pImageMenu->Show();
4679                 __pImageMenu->Invalidate(true);
4680         }
4681         else if(__pHitElementResult->HasUrl() == true)
4682         {
4683                 String tempURl = __pHitElementResult->GetUrl();
4684                 AppLog("tempURl is %ls", tempURl.GetPointer());
4685                 const Bitmap* pBitmap = __pHitElementResult->GetImage();
4686                 if (pBitmap != null)
4687                 {
4688                         AppLog("not null");
4689                 }
4690                 else
4691                 {
4692                         AppLog(null);
4693                 }
4694                 InitImageLinkContextMenu(Point(currentPosition.x,currentPosition.y + __pWebViewer->GetY()));
4695                 __pImageMenu->SetShowState(true);
4696                 __pImageMenu->Show();
4697                 __pImageMenu->Invalidate(true);
4698         }
4699         else
4700         {
4701                 String tagName = __pHitElementResult->GetTagName();
4702                 String type = __pHitElementResult->GetAttributeValue("type");
4703                 String value = __pHitElementResult->GetAttributeValue(L"value");
4704                 String innerHtml = __pHitElementResult->GetAttributeValue(L"innerHTML");
4705
4706                 __currentSelectedStr.Clear();
4707                 __currentSelectedStr = __pWebViewer->GetTextFromBlock();
4708
4709                 AppLog("tag name is %ls", tagName.GetPointer());
4710                 AppLog("type is %ls", type.GetPointer());
4711
4712
4713
4714                 __isLongPressedDone = true;
4715                 result r =__pWebViewer->SetBlockSelectionPosition(currentPosition);
4716                 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)
4717                 {
4718                         AppLog("MainForm::OnWebPageBlockSelected show paste option");
4719
4720                         InitSelectTextContextMenu(Point(currentPosition.x , currentPosition.y + __pWebViewer->GetY()),true, true);
4721                         if(__pImageMenu)
4722                         {
4723                                 __pImageMenu->SetShowState(true);
4724                                 __pImageMenu->Show();
4725                                 __pImageMenu->Invalidate(true);
4726                         }
4727                 }
4728                 AppLog("setselectionselectedornot %s",GetErrorMessage(r));
4729
4730         }
4731 //      __inputEventToBeSupressed = true;
4732 }
4733
4734 void
4735 MainForm::OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
4736 {
4737         AppLog("xyz:: MainForm::OnTouchReleased called");
4738
4739         if (__pAddressbar && __pAddressbar->GetShowState() == true)
4740         {
4741                 __pAddressbar->SetShowState(false);
4742         }
4743         if(__pFooterPanel && __isKeypadOpened == false)
4744         {
4745                 __pFooterPanel->SetShowState(true);
4746         }
4747
4748         // Not reuired now.
4749         /*HitElementResult* pHitElement = __pWebViewer->GetElementByPointN(currentPosition);
4750         if(pHitElement != null && pHitElement->HasUrl() == true && __inputEventToBeSupressed == true)
4751         {
4752                 __pWebViewer->ConsumeInputEvent();
4753         }
4754         if(pHitElement != null)
4755         {
4756                 delete pHitElement;
4757         }
4758         __inputEventToBeSupressed = false;*/
4759 }
4760
4761 bool
4762 MainForm::OnTouchPressed(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4763 {
4764
4765         return true;
4766 }
4767
4768 bool
4769 MainForm::OnTouchReleased(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4770 {
4771         if(__pFindWordControl && __pFindWordControl->GetShowState() == true)
4772         {
4773                 __currentSearchStr = L"";
4774                 __currentWordIndex = 0;
4775                 __maxOccurrances = 0;
4776
4777                 if (__pFindWordPanelLeftToRight && __pFindWordPanelLeftToRight->GetShowState() == true)
4778                 {
4779                         __pFindWordEditField->SetText(L"");
4780                         __pFindWordEditField->HideKeypad();
4781                         __pFindWordControl->SetShowState(false);
4782                         __pFindWordCountLabel->SetText(L"0/0");
4783                 }
4784                 else if(__pFindWordPanelRightToLeft && __pFindWordPanelRightToLeft->GetShowState() == true)
4785                 {
4786                         __pFindWordEditFieldRightToLeft->SetText(L"");
4787                         __pFindWordEditFieldRightToLeft->HideKeypad();
4788                         __pFindWordControl->SetShowState(false);
4789                         __pFindWordCountLabelRightToLeft->SetText(L"0/0");
4790                 }
4791
4792                 __pFindWordNext->SetEnabled(false);
4793                 __pFindWordPrev->SetEnabled(false);
4794
4795                 __pWebViewer->SearchTextAllAsync(L"",true);
4796                 __pFindWordControl->SetShowState(false);
4797         }
4798         AppLog("__pAddressbar->GetShowState() %d",__pAddressbar->GetShowState());
4799         if(__pAddressbar->GetShowState() == false)
4800         {
4801                 __pAddressbar->SetAddressbarURLFocus();
4802                 __pFooterPanel->SetShowState(false);
4803         }
4804
4805         return false;
4806 }
4807
4808 bool
4809 MainForm::OnTouchMoved(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4810 {
4811         return true;
4812 }
4813
4814 bool
4815 MainForm::OnTouchCanceled(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4816 {
4817         return true;
4818 }
4819
4820 bool
4821 MainForm::OnPreviewTouchPressed(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4822 {
4823         return true;
4824 }
4825
4826 bool
4827 MainForm::OnPreviewTouchReleased(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4828 {
4829         return true;
4830 }
4831
4832 bool
4833 MainForm::OnPreviewTouchMoved(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4834 {
4835         return true;
4836 }
4837
4838 void
4839 MainForm::OnOrientationChanged (const Tizen::Ui::Control &source, Tizen::Ui::OrientationStatus orientationStatus)
4840 {
4841         AppLog("MainForm::OnOrientationChanged GetClientAreaBounds %d, %d",GetClientAreaBounds().width,GetClientAreaBounds().height);
4842         int widthContextItem = 0;
4843         if(__pFindWordCountLabel)
4844                 __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),124,__pFindWordCountLabel->GetHeight());
4845         // As per the platform engineer comment removed this line
4846         /*if(__pWebViewer != null)
4847         {
4848                 // 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
4849                 __pWebViewer->ReleaseBlock();
4850         }*/
4851
4852 //      if(__pFindWordControl != null)
4853 //              ShowFindWordPanel(__pFindWordControl->GetShowState(), false);
4854
4855         if(__pOptionMenu && __pOptionMenu->GetShowState() == true)
4856         {
4857                 if( GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
4858                 {
4859                         AppLog(" Orientation landscape");
4860                         __pOptionMenu->SetMaxVisibleItemsCount(5);
4861                 }
4862                 else
4863                 {
4864                         AppLog(" Orientation potrait");
4865                         __pOptionMenu->SetMaxVisibleItemsCount(6);
4866                 }
4867         }
4868         if(__pNotification && __pNotification->GetShowState() == true)
4869         {
4870                 __pNotification->SetShowState(false);
4871                 __pNotification->Invalidate(false);
4872         }
4873         if ( __pFooterLabel != null)
4874         {
4875                 Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_SEARCH_INPUT_FIELD_BG, __pFooterLabel->GetWidth(), __pFooterLabel->GetHeight());
4876                 if(pBitmap != null)
4877                 {
4878                         __pFooterLabel->SetBackgroundBitmap(*pBitmap);
4879                         delete pBitmap;
4880                 }
4881
4882
4883         }
4884         if (__pFindWordBgLabel != null)
4885         {
4886                 Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_FINDWORD_INPUT_FIELD_BG, __pFindWordBgLabel->GetWidth(), __pFindWordBgLabel->GetHeight());
4887                 if (pBitmap != null)
4888                 {
4889                         __pFindWordBgLabel->SetBackgroundBitmap(*pBitmap);
4890                         delete pBitmap;
4891                 }
4892         }
4893
4894         if (__pFindWordBgLabelRightToLeft != null)
4895         {
4896                 Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_FINDWORD_INPUT_FIELD_BG, __pFindWordBgLabelRightToLeft->GetWidth(), __pFindWordBgLabelRightToLeft->GetHeight());
4897                 if (pBitmap != null)
4898                 {
4899                         __pFindWordBgLabelRightToLeft->SetBackgroundBitmap(*pBitmap);
4900                         delete pBitmap;
4901                 }
4902         }
4903
4904
4905 //      if(__pOptionMenu != null)
4906 //              __pOptionMenu->SetShowState(false);
4907
4908         if( GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
4909         {
4910                 widthContextItem = WIDTH_CONTEXT_MENU_BUTTON_LANDSCAPE;
4911         }
4912         else
4913         {
4914                 widthContextItem = WIDTH_CONTEXT_MENU_BUTTON_PORTRAIT;
4915         }
4916
4917         if (__pFooterPanel)
4918         {
4919                 AppLog("__pFooterPanel->GetShowState() is true");
4920                 InitFooter();
4921                 __pFooterPanel->SetBounds(0, GetClientAreaBounds().height - __pFooterPanel->GetHeight(), __pFooterPanel->GetWidth(), __pFooterPanel->GetHeight());
4922                 __pFooterPanel->Invalidate(true);
4923         }
4924         InitAddressbar();
4925
4926         String homePage = SettingPresentationModel::GetInstance()->GetHomepage();
4927         if (homePage.CompareTo((L"IDS_BR_BODY_MOST_VISITED_SITES")) == 0)
4928         {
4929                 InitMostVisitedSitesView(orientationStatus);
4930         }
4931
4932         RelayoutControls(false);
4933         if (__pArticleReaderPanel != null)
4934         {
4935                 if (__pArticleReaderPanel->GetShowState() == true)
4936                 {
4937                         __pArticleReaderPanel->SetBounds((GetClientAreaBounds().width - __pArticleReaderPanel->GetWidth())/2,(GetClientAreaBounds().height - __pArticleReaderPanel->GetHeight())/2, __pArticleReaderPanel->GetWidth(), __pArticleReaderPanel->GetHeight());
4938
4939                         if (__pBlankPanel != null)
4940                                 __pBlankPanel->SetBounds(0,0,GetClientAreaBounds().width,GetClientAreaBounds().height);
4941
4942                         if (__pWebReader != null)
4943                         {
4944                                 __pWebReader->SetBounds(Rectangle(2,2, __pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight() - 96));
4945                         }
4946                         Bitmap* pBitmap = CommonUtil::GetNinepatchedBitmapN(L"I01_popup_bg.9.png",__pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight());
4947                         Bitmap* pSrcBitmap = CommonUtil::GetNinepatchedBitmapN(L"I01_popup_bottom_bg.9.png",__pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight());
4948
4949                         if ( pBitmap != null && pSrcBitmap != null)
4950                         {
4951                                 AppLog("CreateReaderPanel ninepatchbitmap found");
4952                                 pBitmap->Merge(Point(0,__pArticleReaderPanel->GetHeight() - 96),*pSrcBitmap,Rectangle(0,0,pSrcBitmap->GetWidth(),pSrcBitmap->GetHeight()));
4953                         }
4954
4955                         __pArticleReaderLabel->SetBounds(Rectangle(__pArticleReaderPanel->GetX(),__pArticleReaderPanel->GetY(),__pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight()));
4956                         __pArticleReaderLabel->SetBackgroundBitmap(*pBitmap);
4957                         if (pBitmap != null)
4958                         {
4959                                 delete pBitmap;
4960                                 pBitmap = null;
4961                         }
4962                         if (pSrcBitmap != null)
4963                         {
4964                                 delete pSrcBitmap;
4965                                 pSrcBitmap = null;
4966                         }
4967                 }
4968         }
4969         Invalidate(true);
4970         
4971     if (__pAddressbar != null)
4972         {
4973                 int width = GetClientAreaBounds().width;
4974                 __pAddressbar->OrientationChanged(width);
4975         }
4976 }
4977
4978 void
4979 MainForm::OnSettingsChange(int settingvalue)
4980 {
4981         AppLogDebug("MainForm::OnSettingsChange entered");
4982
4983         if(settingvalue == (int)REGISTRY_SETTING_HOMEPAGE)
4984         {
4985                 __pAddressbar->ResetGuideText();
4986         }
4987         if (__pWebViewer == null)
4988         {
4989                 AppLogDebug("Webviewer is not initialized yet.");
4990                 return;
4991         }
4992
4993         if (settingvalue == (int) REGISTRY_SETTING_DEFAULT_VIEW)
4994         {
4995                 WebSetting settings = __pWebViewer->GetSetting();
4996                 if (SettingPresentationModel::GetInstance()->GetDefaultView().CompareTo((L"IDS_BR_BODY_FIT_TO_WIDTH")) == 0)
4997                 {
4998                         settings.SetAutoFittingEnabled(true);
4999                 }
5000                 else if (SettingPresentationModel::GetInstance()->GetDefaultView().CompareTo((L"IDS_BR_BODY_READABLE")) == 0)
5001                 {
5002                         settings.SetAutoFittingEnabled(false);
5003                 }
5004                 __pWebViewer->SetSetting(settings);
5005         }
5006         else if (settingvalue == (int) REGISTRY_SETTING_RUN_JAVASCRIPT)
5007         {
5008                 WebSetting settings = __pWebViewer->GetSetting();
5009                 settings.SetJavascriptEnabled(SettingPresentationModel::GetInstance()->IsRunJavascriptEnabled());
5010                 __pWebViewer->SetSetting(settings);
5011         }
5012         else if (settingvalue == (int) REGISTRY_SETTING_DISPLAY_IMAGES)
5013         {
5014                 WebSetting settings = __pWebViewer->GetSetting();
5015                 settings.SetAutoImageLoadEnabled(SettingPresentationModel::GetInstance()->IsDisplayImagesEnabled());
5016                 __pWebViewer->SetSetting(settings);
5017                 __pWebViewer->Reload();
5018         }
5019         else if (settingvalue == (int) REGISTRY_SETTING_BLOCK_POPUP)
5020         {
5021                 WebSetting settings = __pWebViewer->GetSetting();
5022                 settings.SetJavaScriptPopupEnabled(SettingPresentationModel::GetInstance()->IsBlockPopUp());
5023                 __pWebViewer->SetSetting(settings);
5024         }
5025         else if (settingvalue == (int) REGISTRY_SETTING_ACCEPT_COOKIES)
5026         {
5027                 if (__pWebViewer)
5028                 {
5029                         __pWebViewer->SetCookieEnabled(SettingPresentationModel::GetInstance()->IsCookiesEnabled());
5030                 }
5031         }
5032         else if(settingvalue == (int) REGISTRY_SETTING_REMEMBER_FORM_DATA)
5033         {
5034                 if (__pWebViewer)
5035                 {
5036                         WebSetting settings = __pWebViewer->GetSetting();
5037                         settings.SetAutoFormDataShowEnabled(SettingPresentationModel::GetInstance()->IsRememberFormData());
5038                         __pWebViewer->SetSetting(settings);
5039                 }
5040         }
5041         else if(settingvalue == (int) REGISTRY_SETTING_REMEMBER_PASSWORD)
5042         {
5043                 if (__pWebViewer)
5044                 {
5045                         WebSetting settings = __pWebViewer->GetSetting();
5046                         settings.SetAutoLoginFormFillEnabled(SettingPresentationModel::GetInstance()->IsRememberPassword());
5047                         __pWebViewer->SetSetting(settings);
5048                 }
5049         }
5050         else if (settingvalue == (int) REGISTRY_SETTING_SHOW_SECURITY_WARNINGS)
5051         {
5052                 WebSetting settings = __pWebViewer->GetSetting();
5053                 if (SettingPresentationModel::GetInstance()->IsSecurityWarningsEnabled() == true)
5054                 {
5055                         settings.SetCertificateErrorHandlingMode(WEB_CERTIFICATE_ERROR_HANDLING_MODE_USER_CONFIRM);
5056                 }
5057                 else
5058                 {
5059                         settings.SetCertificateErrorHandlingMode(WEB_CERTIFICATE_ERROR_HANDLING_MODE_CONTINUE);
5060                 }
5061                 __pWebViewer->SetSetting(settings);
5062         }
5063         else if (settingvalue == (int) REGISTRY_SETTING_READER_FONT_SIZE)
5064         {
5065                 if (__pWebReader)
5066                 {
5067                         AppLogDebug("IntMainForm fontsize Changed to %d",SettingPresentationModel::GetInstance()->GetReaderFontSize());
5068                         WebSetting settings = __pWebReader->GetSetting();
5069                         settings.SetFontSize(SettingPresentationModel::GetInstance()->GetReaderFontSize());
5070                         __pWebReader->SetSetting(settings);
5071                 }
5072         }
5073 }
5074
5075 void
5076 MainForm::OnSettingsReset()
5077 {
5078         if (__pWebViewer)
5079         {
5080                 __pWebViewer->SetCookieEnabled(SettingPresentationModel::GetInstance()->IsCookiesEnabled());
5081                 __pWebViewer->SetSetting(SettingPresentationModel::GetInstance()->GetWebSettings());
5082         }
5083 }
5084
5085 void
5086 MainForm::OnClearCache()
5087 {
5088         result r = E_SUCCESS;
5089
5090         if (__pWebViewer != NULL)
5091         {
5092                 r = __pWebViewer->ClearCache();
5093                 if (r == E_SUCCESS)
5094                 {
5095                         AppLogDebug("Cache cleared success");
5096                 }
5097                 else
5098                 {
5099                         AppLogDebug("Cache cleared fail");
5100                 }
5101         }
5102 }
5103
5104 void
5105 MainForm::OnClearCookie()
5106 {
5107         result r = E_SUCCESS;
5108
5109         if (__pWebViewer != NULL)
5110         {
5111                 __pWebViewer->ClearCookie();
5112         }
5113         if (r == E_SUCCESS)
5114         {
5115                 AppLogDebug("Cookie cleared success");
5116         }
5117         else
5118         {
5119                 AppLogDebug("Cache cleared fail");
5120         }
5121 }
5122
5123 void
5124 MainForm::OnClearFormData()
5125 {
5126         result r = E_SUCCESS;
5127
5128         if (__pWebViewer != NULL)
5129         {
5130                 __pWebViewer->ClearFormData();
5131         }
5132         if (r == E_SUCCESS)
5133         {
5134                 AppLogDebug("Cookie cleared success");
5135         }
5136         else
5137         {
5138                 AppLogDebug("Cache cleared fail");
5139         }
5140 }
5141
5142 void
5143 MainForm::OnClearPasswords()
5144 {
5145         result r = E_SUCCESS;
5146
5147         if (__pWebViewer != NULL)
5148         {
5149                 __pWebViewer->ClearLoginFormData();
5150         }
5151         if (r == E_SUCCESS)
5152         {
5153                 AppLogDebug("Cookie cleared success");
5154         }
5155         else
5156         {
5157                 AppLogDebug("Cache cleared fail");
5158         }
5159 }
5160
5161
5162 double
5163 MainForm::findDistance(int x1,int y1,int x2, int y2)
5164 {
5165         int deltaX = Math::Abs(x2 - x1);
5166         int deltaY = Math::Abs(y2 - y1);
5167         double num = deltaX*deltaX + deltaY*deltaY;
5168
5169         if (num >= 0)
5170         {
5171                 double x = num;
5172                 int i;
5173                 for (i = 0; i < 20; i++)
5174                 {
5175                         x = (((x*x)+ num)/(2*x));
5176                 }
5177                 return num;
5178         }
5179         else
5180         {
5181                 return 0.0;
5182         }
5183 }
5184
5185 void
5186 MainForm::OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
5187 {
5188         AppLog("xyz:: MainForm::OnTouchPressed called");
5189         if(__pFindWordControl)
5190         {
5191                 AppLog("MainForm::OnTouchPressed %d",__pFindWordControl->GetShowState());
5192 //              ShowFindWordPanel(__pFindWordControl->GetShowState(), true);
5193         }
5194         __isLongPressedDone = false;
5195
5196
5197
5198         Touch touch;
5199         IList* pList = null;
5200         pList = touch.GetTouchInfoListN(source);
5201
5202         if (pList != null)
5203         {
5204                 int count = pList->GetCount();
5205                 if (count == 1)
5206                 {
5207                         TouchInfo* pTouchInfo = static_cast<TouchInfo*>(pList->GetAt(0));
5208                         __touchPoint1 = pTouchInfo->position;
5209
5210                         /*if (__pAddressbar != null)
5211                         {
5212                                 if (__pAddressbar->GetAddressbarMode() != ADDRESSBAR_MODE_LOADING_COMPLETE && __pAddressbar->GetAddressbarMode() != ADDRESSBAR_MODE_LOADING)
5213                                 {
5214                                         if (__pAddressbar->GetAddressbarMode() == ADDRESSBAR_MODE_EDIT)
5215                                         {
5216                                                 __pAddressbar->SaveAddressbarEditText();
5217                                         }
5218                                         __pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
5219                                 }
5220
5221                                 __pAddressbar->Invalidate(true);
5222                         }*/
5223                         if (GetAddressbarMode() != ADDRESSBAR_MODE_LOADING_COMPLETE && GetAddressbarMode() != ADDRESSBAR_MODE_LOADING)
5224                         {
5225                                 if (GetAddressbarMode() == ADDRESSBAR_MODE_EDIT)
5226                                 {
5227                                         //__pAddressbar->SaveAddressbarEditText();
5228                                 }
5229                                 SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
5230                         }
5231                 }
5232                 else if (count == 2)
5233                 {
5234                         AppLogDebug("MainForm::OnTouchPressed count is two");
5235                         TouchInfo* pTouchInfo = static_cast<TouchInfo*>(pList->GetAt(0));
5236                         __touchPoint1 = pTouchInfo->position;
5237
5238                         pTouchInfo = static_cast<TouchInfo*>(pList->GetAt(1));
5239                         __touchPoint2 = pTouchInfo->position;
5240                 }
5241         }
5242         if( pList != NULL)
5243         {
5244                 pList->RemoveAll(true);
5245                 delete pList;
5246         }
5247         if(__pAddressbar)
5248         {
5249                 __pAddressbar->SetShowState(false);
5250         }
5251         if(__pFooterPanel && __isKeypadOpened == false)
5252         {
5253                 __pFooterPanel->SetShowState(true);
5254         }
5255         RelayoutControls(false);
5256         return;
5257 }
5258
5259 void
5260 MainForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
5261 {
5262 //      __currentWordIndex = 0;
5263         __isLongPressedDone = false;
5264
5265 }
5266
5267 void
5268 MainForm::MoveUiControls()
5269 {
5270 }
5271
5272 void
5273 MainForm::OnTextValueChanged (const Tizen::Ui::Control &source)
5274 {
5275         if(&source == dynamic_cast<Control*>(__pFooterUrlField) && __pFooterUrlField != null)
5276         {
5277                 if(__pFooterUrlField->GetTextLength() == 0)
5278                 {
5279                         __pFooterUrlField->SetKeypadActionEnabled(false);
5280                 }
5281                 else
5282                 {
5283                         __pFooterUrlField->SetKeypadActionEnabled(true);
5284                 }
5285         }
5286         if (__pFindWordEditField != null && __pFindWordEditField->GetShowState() == true)
5287         {
5288                 __currentSearchStr = __pFindWordEditField->GetText();
5289                 if (__currentSearchStr.GetLength() > 0)
5290                 {
5291                         __pFindWordCountLabel->SetShowState(true);
5292                 }
5293                 else
5294                 {
5295 //                      __pFindWordCountLabel->SetShowState(false);
5296                         __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),84,__pFindWordCountLabel->GetHeight());
5297                         __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),214+80,__pFindWordEditField->GetHeight());
5298
5299                 }
5300                 __pFindWordNext->SetEnabled(false);
5301                 __pFindWordPrev->SetEnabled(false);
5302                 __pFindWordNext->Invalidate(true);
5303                 __pFindWordPrev->Invalidate(true);
5304                 __pFindWordCountLabel->SetText(L"0/0");
5305                 __pFindWordCountLabel->Invalidate(true);
5306         }
5307         else if (__pFindWordEditFieldRightToLeft != null && __pFindWordEditFieldRightToLeft->GetShowState() == true)
5308         {
5309                 __currentSearchStr = __pFindWordEditFieldRightToLeft->GetText();
5310                 if (__currentSearchStr.GetLength() > 0)
5311                 {
5312                         __pFindWordCountLabelRightToLeft->SetShowState(true);
5313                 }
5314                 else
5315                 {
5316                         __pFindWordCountLabelRightToLeft->SetShowState(false);
5317                 }
5318
5319                 __pFindWordNext->SetEnabled(false);
5320                 __pFindWordPrev->SetEnabled(false);
5321                 __pFindWordNext->Invalidate(true);
5322                 __pFindWordPrev->Invalidate(true);
5323                 __pFindWordCountLabelRightToLeft->SetText(L"0/0");
5324                 __pFindWordCountLabelRightToLeft->Invalidate(true);
5325         }
5326         AppLog("__currentSearchStr %ls",__currentSearchStr.GetPointer());
5327         if (__currentSearchStr.GetLength() > 0)
5328         {
5329                 StartWordSearch();
5330         }
5331         else
5332         {
5333                 __currentSearchStr = L"aaaaaaaabbbbbbbccccccc";
5334                 StartWordSearch();
5335                 __currentSearchStr = L"";
5336                 AppLogDebug("Enter something");
5337         }
5338 }
5339
5340 result
5341 MainForm::InitMostVisitedSitesPanel(Tizen::Ui::OrientationStatus orientationStatus)
5342 {
5343         return E_SUCCESS;
5344
5345 }
5346
5347 result
5348 MainForm::InitMostVisitedSitesView(Tizen::Ui::OrientationStatus orientationStatus)
5349 {
5350         if(__pWebViewer != null)
5351                 return E_SUCCESS;
5352
5353         AppLog("MainForm::InitMostVisitedSitesView");
5354         result r = E_SUCCESS;
5355
5356
5357         if (__pWebViewer != null && __pMostVisitedListView != null)
5358         {
5359                 return E_SUCCESS;
5360         }
5361
5362         if (__pMostVisitedListView != null)
5363         {
5364                 RemoveControl(__pMostVisitedListView);
5365         }
5366         if(__pMostVisitedSites != null)
5367         {
5368                 __pMostVisitedSites->RemoveAll(true);
5369         }
5370
5371         HistoryPresentationModel::GetInstance()->GetMostVisitedSites(*__pMostVisitedSites);
5372
5373         __webControlHeight = GetClientAreaBounds().height - __pFooterPanel->GetHeight();
5374         __pMostVisitedListView = new(std::nothrow) ListView();
5375
5376         int height = GetClientAreaBounds().height;
5377
5378         if(__pFooterPanel->GetShowState() == true)
5379         {
5380                 height = height - __pFooterPanel->GetHeight();
5381         }
5382         if(__pAddressbar->GetShowState() == true)
5383         {
5384                 height -= __pAddressbar->GetHeight();
5385         }
5386
5387         r = __pMostVisitedListView->Construct(Tizen::Graphics::Rectangle(0,0 , GetClientAreaBounds().width, height),true,false);
5388
5389         if (r != E_SUCCESS)
5390         {
5391                 delete __pMostVisitedListView;
5392                 AppLogDebug("Addressbar init failed with %s", GetErrorMessage(r));
5393                 return r;
5394         }
5395         __pMostVisitedListView->SetItemProvider(*this);
5396         __pMostVisitedListView->AddListViewItemEventListener(*this);
5397         __pMostVisitedListView->SetTextOfEmptyList(CommonUtil::GetString(L"IDS_BR_BODY_NO_VISITED_SITES"));
5398         AddControl(__pMostVisitedListView);
5399         __pMostVisitedListView->UpdateList();
5400
5401         return E_SUCCESS;
5402
5403 }
5404
5405 String
5406 MainForm::GetImagePath(void)
5407 {
5408
5409         String str;
5410         String formattedTime;
5411         DateTime currentTime;
5412         LocaleManager localManager;
5413         SystemTime::GetCurrentTime(TIME_MODE_WALL, currentTime);
5414
5415         localManager.Construct();
5416         Locale locale = localManager.GetSystemLocale();
5417         //Locale locale(LANGUAGE_ENG, COUNTRY_US);
5418
5419         // Get date formatter
5420         DateTimeFormatter* pTimeFormatter = DateTimeFormatter::CreateDateTimeFormatterN(locale, DATE_TIME_STYLE_DEFAULT);
5421
5422         if (pTimeFormatter)
5423         {
5424                 pTimeFormatter->Format(currentTime, formattedTime);
5425         }
5426
5427         AppLog("current time stamp is %ls", formattedTime.GetPointer());
5428         String delim(L" :");
5429         StringTokenizer strTok(formattedTime, delim);
5430         String token;
5431         String imageName;
5432         String str1("GMT+00");
5433         while (strTok.HasMoreTokens())
5434         {
5435                 strTok.GetNextToken(token); // Osp, StringTokenizer, Sample, code
5436                 if(token.Equals(str1))
5437                         break;
5438                 AppLog("token is %ls", token.GetPointer());
5439                 imageName.Append(token);
5440         }
5441         return imageName;
5442
5443 }
5444
5445 void MainForm::UpdateImageContent(ByteBuffer* aBuffer, String imageName)
5446 {
5447         result r = E_FAILURE;
5448         AppLog("Content manager 1");
5449         ContentId contentId;
5450         ContentManager contentManager;
5451         r = contentManager.Construct();
5452         if(IsFailed(r))
5453         {
5454                 AppLog("Content manager update content result %s" ,GetErrorMessage(r));
5455                 return;
5456         }
5457         Tizen::Base::String contentPath = Tizen::System::Environment::GetMediaPath() + L"Downloads/";
5458         Tizen::Io::Directory::Create(contentPath,true);
5459         if(GetLastResult() == E_FILE_ALREADY_EXIST)
5460         {
5461                 AppLog("Already exists");
5462         }
5463         else if(GetLastResult() == E_SUCCESS)
5464         {
5465                 AppLog("created success");
5466         }
5467         contentPath.Append(imageName);
5468         contentPath.Append(".jpg");
5469         contentId = contentManager.CreateContent(*aBuffer, contentPath);
5470         ShowIndicatorNotification(L"Download Complete",contentPath);
5471         AppLog("Content manager update content result %s" ,GetErrorMessage(GetLastResult()));
5472 }
5473
5474 void
5475 MainForm::ShowIndicatorNotification(const String& messageText, const String& contentPath)
5476 {
5477         AppLogDebug("ENTER");
5478
5479         NotificationRequest request;
5480         request.SetAlertText(messageText);
5481         request.SetTitleText(L"");
5482         request.SetAppMessage(contentPath);
5483         request.SetOngoingActivityType(ONGOING_ACTIVITY_TYPE_TEXT);
5484         request.SetNotificationStyle(NOTIFICATION_STYLE_THUMBNAIL);
5485         Tizen::App::App* pApp = Tizen::App::App::GetInstance();
5486         String homePath = pApp->GetAppRootPath();
5487         String iconPath = homePath + L"res/screen-density-xhigh/Notification_download_complete.png";
5488         AppLog("The iconPath is : %ls", homePath.GetPointer());
5489         request.SetIconFilePath(iconPath);
5490
5491         Tizen::Shell::NotificationManager notiMgr;
5492         notiMgr.Construct();
5493         notiMgr.NotifyOngoingActivity(request);
5494         AppLogDebug("EXIT: %s", GetErrorMessage(GetLastResult()));
5495         return;
5496 }
5497
5498 void
5499 MainForm::SetForwardButtonEnabled(bool isEnabled)
5500 {
5501         __pGoForwardBtn->SetEnabled(isEnabled);
5502         __pGoForwardBtn->Invalidate(true);
5503 }
5504
5505 void
5506 MainForm::SetBackButtonEnabled(bool isEnabled)
5507 {
5508         __pGoBackBtn->SetEnabled(isEnabled);
5509         __pGoBackBtn->Invalidate(true);
5510 }
5511
5512 void
5513 MainForm::UpdateProgress(int percentage)
5514 {
5515         __progressPercentage = percentage;
5516         if (percentage == 0 || percentage == 100)
5517         {
5518                 __isLoadingData = false;
5519                 if (percentage == 100)
5520                 {
5521                         __isLoadingCompleted = true;
5522                         __progressPercentage = 0;
5523                 }
5524                 else
5525                 {
5526                         __isLoadingCompleted = false;
5527                 }
5528         }
5529         else
5530         {
5531                 __isLoadingData = true;
5532         }
5533         UpdateProgressBitmap();
5534 }
5535
5536 int
5537 MainForm::GetProgress(void)
5538 {
5539         return __progressPercentage;
5540 }
5541
5542 void
5543 MainForm::UpdateProgressBitmap(void)
5544 {
5545         result r = E_SUCCESS;
5546         if (__pProgressbarLabel == null)
5547                 return;
5548         int w = __pProgressbarLabel->GetWidth();
5549         int h = __pProgressbarLabel->GetHeight();
5550         Canvas canvas;
5551         int progressWidth = 0;
5552         Bitmap* pRetBitmap = null;
5553
5554         if (__progressPercentage == 0 || __progressPercentage == 100)
5555         {
5556                 __pProgressbarLabel->SetShowState(false);
5557                 __pProgressbarLabel->Invalidate(false);
5558                 return;
5559         }
5560         else
5561         {
5562                 __pProgressbarLabel->SetShowState(true);
5563                 __pProgressbarLabel->Invalidate(false);
5564         }
5565
5566         r = canvas.Construct(Rectangle(0, 0, w, h));
5567
5568         if (r != E_SUCCESS)
5569         {
5570                 AppLogException("Canvas construction failed with %s", GetErrorMessage(r));
5571                 return;
5572         }
5573
5574         canvas.Clear();
5575         Bitmap *pBgBmp = AppResource::GetInstance()->GetBitmapN(IDB_TITLE_PROGRESS_BAR_BG);
5576
5577         if (pBgBmp != null)
5578         {
5579                 pBgBmp->Scale(Dimension(w, h));
5580                 canvas.DrawBitmap(Point(0,0), *pBgBmp);
5581                 delete pBgBmp;
5582         }
5583
5584         progressWidth = (double) (w) * __progressPercentage / 100;
5585         AppLogDebug("progressWidth: %d", progressWidth);
5586         Bitmap *pProgressBmp = AppResource::GetInstance()->GetBitmapN(IDB_TITLE_PROGRESS_BAR);
5587
5588         if (pProgressBmp != null)
5589         {
5590                 pProgressBmp->Scale(Dimension(progressWidth, h));
5591                 canvas.DrawBitmap(Point(0,0), *pProgressBmp);
5592                 delete pProgressBmp;
5593         }
5594
5595         pRetBitmap = new (std::nothrow) Bitmap();
5596
5597         if (pRetBitmap == null)
5598         {
5599                 AppLogException("Bitmap creation failed with %s", GetErrorMessage(r));
5600                 return;
5601         }
5602
5603         pRetBitmap->Construct(canvas, canvas.GetBounds());
5604
5605         if (__pProgressbarLabel != null && pRetBitmap != null)
5606         {
5607                 __pProgressbarLabel->SetBackgroundBitmap(*pRetBitmap);
5608                 __pProgressbarLabel->Invalidate(false);
5609         }
5610
5611         if (pRetBitmap != null)
5612         {
5613                 delete pRetBitmap;
5614                 pRetBitmap = null;
5615         }
5616         return;
5617 }
5618
5619 void
5620 MainForm::ReaderClicked()
5621 {
5622         result r = E_SUCCESS;
5623         ArrayList* pArgList = new(std::nothrow) ArrayList();
5624         if (pArgList != null)
5625         {
5626                 r = pArgList->Construct();
5627                 if (IsFailed(r))
5628                 {
5629                         delete pArgList;
5630                         return;
5631                 }
5632
5633                 r = pArgList->Add(*new(std::nothrow) String(*__pReaderData));
5634                 if (IsFailed(r))
5635                 {
5636                         delete pArgList;
5637                         return;
5638                 }
5639
5640                 r = pArgList->Add(*new(std::nothrow) String(__pWebViewer->GetUrl()));
5641                 if (IsFailed(r))
5642                 {
5643                         delete pArgList;
5644                         return;
5645                 }
5646
5647                 r = pArgList->Add(*new(std::nothrow) String(__pWindowInfo->pageTitle));
5648                 if (IsFailed(r))
5649                 {
5650                         delete pArgList;
5651                         return;
5652                 }
5653         }
5654
5655         SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_ARTICLE_READER, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
5656         return;
5657
5658
5659 }
5660
5661 void MainForm::SetAddressbarMode(AddressBarMode addMode)
5662 {
5663         AppLogDebug("AddressBar::setAddressbarMode to %d",addMode);
5664
5665         __currentAddMode = addMode;
5666
5667         switch(addMode)
5668         {
5669         case ADDRESSBAR_MODE_INVALID:
5670         {
5671                 // do nothing
5672         }
5673         break;
5674         case ADDRESSBAR_MODE_READER:
5675         {
5676                 __pStopBtn->SetShowState(false);
5677                 __pRefreshBtn->SetShowState(false);
5678                 __pClearBtn->SetShowState(false);
5679                 __pReaderBtn->SetShowState(false);
5680         }
5681         break;
5682         case ADDRESSBAR_MODE_LOADING:
5683         {
5684                 __pRefreshBtn->SetShowState(false);
5685                 __pStopBtn->SetShowState(true);
5686                 __pClearBtn->SetShowState(false);
5687                 __pReaderBtn->SetShowState(false);
5688         }
5689         break;
5690         case ADDRESSBAR_MODE_LOADING_COMPLETE:
5691         {
5692 //              SetUrl(__pAddressbar->GetUrl());
5693
5694                 __pRefreshBtn->SetShowState(true);
5695                 __pStopBtn->SetShowState(false);
5696                 __pClearBtn->SetShowState(false);
5697                 __pReaderBtn->SetShowState(false);
5698         }
5699         break;
5700         case ADDRESSBAR_MODE_EDIT:
5701         {
5702                 __pRefreshBtn->SetShowState(false);
5703                 __pStopBtn->SetShowState(false);
5704                 __pReaderBtn->SetShowState(false);
5705                 __pClearBtn->SetShowState(true);
5706         }
5707         break;
5708         }
5709
5710         Invalidate(true);
5711
5712         OnAddressBarModeChanged();
5713 }
5714
5715 AddressBarMode MainForm::GetAddressbarMode(void)
5716 {
5717         return __currentAddMode;
5718 }
5719
5720 void MainForm::SetUrl(const String& url)
5721 {
5722         __displayUrl = url;
5723         if(__displayUrl.GetLength() > 2048)
5724                 __displayUrl.SubString(0,2048,__displayUrl);
5725
5726         if (__pFooterUrlField != NULL)
5727         {
5728                 String removedHttpUrl = RemoveHttpTextFromDisplayURL();
5729                 if (removedHttpUrl.IsEmpty() == false)
5730                 {
5731                         __pFooterUrlField->SetText(removedHttpUrl);
5732                         if(__pAddressbar != NULL && __pAddressbar->HasCurrentFocus() == false)
5733                                 __pAddressbar->SetUrl(__displayUrl);
5734                 }
5735                 else
5736                 {
5737                         __pFooterUrlField->SetText(__displayUrl);
5738                         if(__pAddressbar != NULL && __pAddressbar->HasCurrentFocus() == false)
5739                                 __pAddressbar->SetUrl(__displayUrl);
5740                 }
5741                 if(__pFooterUrlField)
5742                         __pFooterUrlField->SetCursorPosition(__pFooterUrlField->GetTextLength());
5743                 __pFooterUrlField->Invalidate(false);
5744                 if(__pAddressbar != NULL && __pAddressbar->HasFocus())
5745                         __pAddressbar->Invalidate(true);
5746 //              __pFooterUrlField->SetCursorPosition(0);
5747         }
5748 }
5749
5750 String
5751 MainForm::RemoveHttpTextFromDisplayURL(void)
5752 {
5753         AppLog("MainForm::RemoveHttpTextFromDisplayURL __displayUrl %ls",__displayUrl.GetPointer());
5754         int index = -1;
5755 //      bool isHttpText = __displayUrl.Contains(L"http://");
5756         String updatedDisplayUrl;
5757         updatedDisplayUrl.Clear();
5758         if(__displayUrl.IndexOf(L"http://",0,index) == E_SUCCESS && index == 0)
5759         {
5760                 __displayUrl.SubString(7,updatedDisplayUrl);
5761         }
5762         else if(__displayUrl.IndexOf(L"https://",0,index) == E_SUCCESS && index == 0)
5763         {
5764                 __displayUrl.SubString(8,updatedDisplayUrl);
5765         }
5766         return updatedDisplayUrl;
5767 }
5768
5769 void MainForm::OnSharePopupControlStarted(void)
5770 {
5771         __pWebViewer->AddTouchEventListener(*this);
5772 }
5773
5774 void
5775 MainForm::OnUserEventReceivedN (RequestId requestId, Tizen::Base::Collection::IList *pArgs)
5776 {
5777         if (requestId == BACK_GROUND_APP_EVENT)
5778         {
5779                 if(__pWebViewer != null)
5780                 {
5781                         __pWebViewer->Pause();
5782                 }
5783                 if(__pImageMenu)
5784                 {
5785                         __pImageMenu->SetShowState(false);
5786                 }
5787                 if(__pAddressbar != null)
5788                 {
5789                         __pAddressbar->SendUserEvent(BACK_GROUND_APP_EVENT,NULL);
5790                 }
5791         }
5792         else if(requestId == FORE_GROUND_APP_EVENT)
5793         {
5794                 if(__pWebViewer != null)
5795                 {
5796                         __pWebViewer->Resume();
5797                 }
5798                 if(__pAddressbar != null)
5799                 {
5800                         __pAddressbar->SendUserEvent(FORE_GROUND_APP_EVENT,NULL);
5801                 }
5802         }
5803 }
5804
5805 void
5806 MainForm::AddressBarCancelledClicked(const Addressbar& addBar)
5807 {
5808         AppLog("XYZ::MainForm::AddressBarCancelledClicked");
5809         result r = E_SUCCESS;
5810
5811         if (__pAddressbar)
5812                 __pAddressbar->SetShowState(false);
5813
5814         AppLog("akjshdasd 5");
5815         __pFooterPanel->SetShowState(true);
5816
5817         if(__pWebViewer)
5818                 __pWebViewer->SetFocus();
5819         else if(__pMostVisitedListView)
5820                 __pMostVisitedListView->SetFocus();
5821         else if(__pMultiWindowButton)
5822                 __pMultiWindowButton->SetFocus();
5823         else if(__pMoreButton)
5824                 __pMoreButton->SetFocus();
5825
5826         __pAddressbar->SetShowState(false);
5827
5828         RelayoutControls(false);
5829 }
5830
5831 void
5832 MainForm::OnFormMenuRequested (Tizen::Ui::Controls::Form &source)
5833 {
5834         AppLog("MainForm::OnFormMenuRequested called");
5835         InitOptionMenu();
5836         if (__pWindowInfo != NULL && __pWindowInfo->pageUrl != NULL && __pWebViewer && __pWebViewer->GetShowState() == true)
5837         {
5838                 int bookmarkCount=0;
5839                 bool exist = false;
5840                 String url=L"";
5841                 url=__pWindowInfo->pageUrl;
5842                 AppLog("MainForm::OnFormMenuRequested url %ls",url.GetPointer());
5843                 result r = E_SUCCESS;
5844                 Bitmap* pBitmap = null;
5845                 String lastChar = L"";
5846 //              if(url.SubString(url.GetLength()-1,lastChar));
5847 //              if(lastChar == L"/")
5848 //              {
5849 //                      bool exist1 = false;
5850 //                      bool exist2 = false;
5851 //                      r=BookmarkPresentationModel::GetInstance()->DoesBookmarkExist(url,exist1);
5852 //                      url.SubString(0,url.GetLength() - 1,url);
5853 //                      r=BookmarkPresentationModel::GetInstance()->DoesBookmarkExist(url,exist2);
5854 //                      exist = exist1 | exist2;
5855 //              }
5856 //              else
5857 //              {
5858                         r=BookmarkPresentationModel::GetInstance()->DoesBookmarkExist(url,exist);
5859                         if (IsFailed(r))
5860                         {
5861                                 AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED failed");
5862                                 return;
5863                         }
5864 //              }
5865                 if ( exist == true)
5866                 {
5867                         pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ICON_BOOKMARK_ON_TEMP);
5868                 }
5869                 else
5870                 {
5871                         pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ICON_BOOKMARK_OFF_TEMP);
5872                 }
5873                 AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED 3");
5874
5875                 if (__pOptionMenu->GetItemCount() == 9)
5876                 {
5877                         r = __pOptionMenu->SetItemAt(1,CommonUtil::GetString(L"IDS_BR_OPT_ADDTOBOOKMARKS"), IDA_ADDTOBOOKMARK_CLICKED,*pBitmap);
5878                 }
5879                 else
5880                 {
5881                         r = __pOptionMenu->InsertItemAt(1,CommonUtil::GetString(L"IDS_BR_OPT_ADDTOBOOKMARKS"), IDA_ADDTOBOOKMARK_CLICKED,*pBitmap);
5882                 }
5883
5884                 if (IsFailed(r))
5885                 {
5886                         AppLogException("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED Add to Bookmark failed with %s", GetErrorMessage(r));
5887                         delete pBitmap;
5888                         return ;
5889                 }
5890                 AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED 4");
5891                 if (__pOptionMenu->GetItemCount() != 9)
5892                 {
5893                         __pOptionMenu->InsertItemAt(1,CommonUtil::GetString(L"IDS_BR_OPT_ADDTOBOOKMARKS"), IDA_ADDTOBOOKMARK_CLICKED);
5894                         __pOptionMenu->InsertItemAt(2,CommonUtil::GetString(L"IDS_BR_BODY_PRINT"), IDA_PRINT_CLICKED);
5895 //                              __pOptionMenu->InsertItemAt(2,L"Add to Home"/*CommonUtil::GetString(L"IDS_BR_OPT_SHARE")*/, IDA_ADD_TO_HOME_CLICKED);
5896                         __pOptionMenu->InsertItemAt(3,CommonUtil::GetString(L"IDS_BR_OPT_SHARE"), IDA_SHARE_CLICKED);
5897                         __pOptionMenu->InsertItemAt(4,CommonUtil::GetString(L"IDS_BR_OPT_FIND_ON_PAGE_ABB"), IDA_FINDONPAGE_CLICKED);
5898                         __pOptionMenu->SetMaxVisibleItemsCount(6);
5899                 }
5900                 if( GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
5901                 {
5902                         AppLog(" Orientation landscape");
5903                         __pOptionMenu->SetMaxVisibleItemsCount(5);
5904                 }
5905                 else
5906                 {
5907                         AppLog(" Orientation potrait");
5908                         __pOptionMenu->SetMaxVisibleItemsCount(6);
5909                 }
5910
5911                 AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED 5");
5912                 delete pBitmap;
5913         }
5914         AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED end");
5915         if(__pAddressbar)
5916                 __pAddressbar->SetShowState(false);
5917         SetFocus();
5918         __pFooterPanel->SetShowState(true);
5919         result r = __pOptionMenu->SetShowState(true);
5920         AppLog("ajsghd %s",GetErrorMessage(r));
5921         RelayoutControls(false);
5922         __pOptionMenu->Invalidate(true);
5923         __pOptionMenu->Show();
5924
5925 }