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