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