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