Fixed Nabi issues N_SE-45388, N_Se-45329, N_SE-44967
[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         if (pSelectedScene != null)
2749         {
2750                 delete pSelectedScene;
2751         }
2752         MultipleWindowPresentationModel::GetInstance()->SetValue(SELECTED_SCENE_ID, null);
2753         String* selectedSceneID = new(std::nothrow) String(currentSceneId);
2754         AppLogDebug("current scene id is %ls", currentSceneId.GetPointer());
2755         AppLogDebug("selected scene id is %ls", currentSceneId.GetPointer());
2756
2757         // setting the current scene ID
2758         MultipleWindowPresentationModel::GetInstance()->SetCurrentSceneID(currentSceneId);
2759
2760         MultipleWindowPresentationModel::GetInstance()->SetValue(SELECTED_SCENE_ID, (Object*) selectedSceneID);
2761
2762         if(pArgs != null && pArgs->GetCount() > 0 && pArgs->GetCount() == 2)
2763         {
2764                 __pWindowInfo = dynamic_cast< WindowInfo* >(pArgs->GetAt(0));
2765                 if(__pWindowInfo == null)
2766                         return;
2767                 //              if(__pWindowInfo == null)
2768                 {
2769                         pUrl = dynamic_cast< String* >(pArgs->GetAt(1));
2770                 }
2771         }
2772         else if ( pArgs != null && pArgs->GetCount() == 1)
2773         {
2774                 __pWindowInfo = dynamic_cast< WindowInfo* >(pArgs->GetAt(0));
2775         }
2776
2777         InitFooter();
2778         InitAddressbar();
2779
2780         __pFooterPanel->SetBounds(0, GetClientAreaBounds().height - __pFooterPanel->GetHeight(), GetClientAreaBounds().width, __pFooterPanel->GetHeight());
2781
2782         // hiding the address bar
2783         //      __pAddressbar->SetBounds(__pAddressbar->GetX(), __pAddressbar->GetY() - __pAddressbar->GetHeight(), __pAddressbar->GetWidth(), __pAddressbar->GetHeight());
2784         __pAddressbar->SetShowState(false);
2785 //      if(__pWebViewer != null)
2786 //      {
2787 //              __pWebViewer->Resume();
2788 //      }
2789
2790         if(pUrl != null && pUrl->GetLength() > 0)
2791         {
2792                 LoadUrl(*pUrl);
2793         }
2794         else if(__pWindowInfo != null)
2795         {
2796                 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)
2797                 {
2798                         LoadUrl(__pWindowInfo->pageUrl);
2799                 }
2800                 else if(__pWindowInfo->pageUrl.GetLength() > 0 && __pWindowInfo->isAppcontrolTriggered == true)
2801                 {
2802                         LoadUrl(__pWindowInfo->pageUrl);
2803                 }
2804                 else if (__pWindowInfo->isJavascriptInitiated == true)
2805                 {
2806                         AppLog("Called");
2807                         InitWebControl();
2808                         __pWindowInfo->pCurrentWeb = __pWebViewer;
2809                 }
2810         }
2811
2812         String homePage = SettingPresentationModel::GetInstance()->GetHomepage();
2813         AppLog("Homepage Value in Onsceneactivated is %ls",homePage.GetPointer());
2814         if(homePage.CompareTo((L"IDS_BR_BODY_MOST_VISITED_SITES")) == 0)
2815         {
2816                 InitMostVisitedSitesView(GetOrientationStatus());
2817         }
2818         else if (homePage.CompareTo((L"IDS_BR_BODY_BLANK_PAGE")) == 0)
2819         {
2820                 if(__pMostVisitedListView != null)
2821                 {
2822                         __pMostVisitedListView->SetShowState(false);
2823                 }
2824         }
2825
2826         if (__pAddressbar != null && pArgs != null && (previousSceneId == IDSCN_BOOKMARK_VIEW || previousSceneId == IDSCN_HISTORY_LIST))
2827         {
2828                 String* pBookmarkUrl = dynamic_cast< String* >(pArgs->GetAt(0));
2829
2830                 if (pBookmarkUrl == null)
2831                         return;
2832                 AppLogDebug("bookmarkUrl = %ls",pBookmarkUrl->GetPointer());
2833                 //__pAddressbar->SetUrl(*pBookmarkUrl);
2834                 SetUrl(*pBookmarkUrl);
2835
2836                 if (__pWebViewer != null && homePage.CompareTo((L"IDS_BR_BODY_BLANK_PAGE")) != 0)
2837                         __pWebViewer->LoadUrl(*pBookmarkUrl);
2838                 delete pBookmarkUrl;
2839         }
2840
2841         bool isPrivateBrowsing = SettingPresentationModel::GetInstance()->GetPrivateOn();
2842         Bitmap* pBitmap = null;
2843         if (isPrivateBrowsing == true)
2844         {
2845                 pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_BUTTON_ON);
2846
2847                 if (__pWebViewer != null)
2848                 {
2849                         __pWebViewer->SetPrivateBrowsingEnabled(true);
2850                 }
2851
2852                 if (__pAddressbar != null)
2853                 {
2854                         //      __pAddressbar->UpdateFaviconBitmap(true);
2855                 }
2856
2857         }
2858         else
2859         {
2860                 pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_BUTTON_OFF);
2861
2862                 if (__pWebViewer != null)
2863                 {
2864                         __pWebViewer->SetPrivateBrowsingEnabled(false);
2865                 }
2866
2867                 if (__pAddressbar != null)
2868                 {
2869                         //      __pAddressbar->UpdateFaviconBitmap(false);
2870                 }
2871         }
2872
2873         if (__pOptionMenu != null && __pOptionMenu->GetItemCount() != 9)
2874         {
2875                 __pOptionMenu->SetItemAt(1,CommonUtil::GetString(L"IDS_BR_BODY_PRIVACY_AND_SECURITY_ABB"),IDA_PRIVATEON_CLICKED,*pBitmap);
2876         }
2877         else if (__pOptionMenu != null )
2878         {
2879                 __pOptionMenu->SetItemAt(5,CommonUtil::GetString(L"IDS_BR_BODY_PRIVACY_AND_SECURITY_ABB"),IDA_PRIVATEON_CLICKED,*pBitmap);
2880         }
2881
2882         if (pBitmap != null)
2883         {
2884                 delete pBitmap;
2885         }
2886
2887         AppLog("ABC: OnSceneActivatedN started exit");
2888
2889 }
2890
2891 void
2892 MainForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
2893                 const Tizen::Ui::Scenes::SceneId& nextSceneId)
2894 {
2895         Canvas* pWebCanvas = null;
2896         if (__pWebViewer != null)
2897         {
2898                 pWebCanvas = __pWebViewer->GetCanvasN();
2899
2900         }
2901         if (pWebCanvas == null)
2902         {
2903                 return;
2904         }
2905         if (__pWindowInfo != null)
2906         {
2907                 if (__pWindowInfo->pWebCanvasBitmap != null)
2908                 {
2909                         delete __pWindowInfo->pWebCanvasBitmap;
2910                 }
2911                 __pWindowInfo->pWebCanvasBitmap = new(std::nothrow) Bitmap();
2912                 result r = __pWindowInfo->pWebCanvasBitmap->Construct(*pWebCanvas,Rectangle(0,0,pWebCanvas->GetBounds().width,pWebCanvas->GetBounds().height));
2913                 AppLog("Bitmap Construction result %s",GetErrorMessage(r));
2914         }
2915         Bitmap* pBitmap = GetCapturedBitmapN();
2916         AppLog("Coming here");
2917         Canvas* pCanvas = new(std::nothrow) Canvas();
2918         pCanvas->Construct(GetClientAreaBounds());
2919         if(pBitmap != null)
2920         {
2921                 pCanvas->DrawBitmap(Point(0,0),*pBitmap);
2922                 delete pBitmap;
2923         }
2924         if(__pWebViewer != null && __pWindowInfo != null)
2925                 pCanvas->DrawBitmap(__pWebViewer->GetPosition(),*__pWindowInfo->pWebCanvasBitmap);
2926
2927         WindowInfo::pFormCanvasBitmap = new(std::nothrow) Bitmap();
2928         WindowInfo::pFormCanvasBitmap->Construct(*pCanvas,Rectangle(0,0,GetClientAreaBounds().width,GetClientAreaBounds().height - __pFooterPanel->GetHeight()));
2929         delete pCanvas;
2930         delete pWebCanvas;
2931         AppLog("Coming here");
2932 }
2933
2934 bool
2935 MainForm::OnHttpAuthenticationRequestedN(const Tizen::Base::String& host,
2936                 const Tizen::Base::String& realm,
2937                 const Tizen::Web::Controls::AuthenticationChallenge& authentication)
2938 {
2939         return false;
2940 }
2941
2942 void
2943 MainForm::OnHttpAuthenticationCanceled(void)
2944 {
2945 }
2946
2947 void
2948 MainForm::OnLoadingStarted(void)
2949 {
2950         AppLogDebug("MainForm::OnLoadingStarted entered");
2951         __isLoaded = true;
2952         if(__pAddressbar == NULL || __pWebViewer == null)
2953         {
2954                 return;
2955         }
2956
2957         // this is added in case if menu is opened and user load the page
2958         if(__pOptionMenu != null && __pOptionMenu->GetShowState() == true)
2959         {
2960                 __pOptionMenu->SetShowState(false);
2961                 __pOptionMenu->Invalidate(true);
2962         }
2963
2964
2965
2966         if(__pImageMenu != null && __pImageMenu->GetShowState() == true)
2967         {
2968                 __pImageMenu->SetShowState(false);
2969                 __pImageMenu->Invalidate(true);
2970         }
2971         String url = __pWebViewer->GetUrl();
2972         if(url.Contains(IDS_TIZEN_SERVICE))
2973         {
2974                 String appId;
2975                 String delim(L":;,");
2976
2977                 // Creates a StringTokenizer instance
2978                 StringTokenizer strTok(url, delim);
2979
2980                 int count = strTok.GetTokenCount();     // count == 4
2981
2982                 HashMap *pMap = new HashMap();
2983                 pMap->Construct();
2984                 String token;
2985                 String key;
2986                 String value;
2987                 while (strTok.HasMoreTokens())
2988                 {
2989                         AppLog("Token: %ls", token.GetPointer());
2990                         strTok.GetNextToken(token);         // Tizen, StringTokenizer, Sample, code
2991                         if(token.Contains(IDS_APPID))
2992                         {
2993                                 token.SubString(6, appId);
2994                                 AppLog("AppID:%ls", appId.GetPointer());
2995                         }
2996                         else if(token.Contains(IDS_KEY))
2997                         {
2998                                 token.SubString(4, key);
2999                                 AppLog("key:%ls", key.GetPointer());
3000                         }
3001                         else if(token.Contains(IDS_VALUE))
3002                         {
3003                                 token.SubString(6, value);
3004                                 AppLog("value:%ls", value.GetPointer());
3005                         }
3006                 }
3007                 pMap->Add(key, value);
3008
3009                 if(appId != "")
3010                 {
3011                         AppControl *pAppControl = null;
3012                         String operationId = L"http://tizen.org/appcontrol/operation/main";
3013                         pAppControl = dynamic_cast<AppControl*>(AppManager::FindAppControlN(appId, operationId));
3014                         if(pAppControl)
3015                         {
3016                                 AppLog("Starting AppControl");
3017                                 result r = pAppControl->Start(null, null, pMap, null);
3018                                 AppLog("Result of Start %s", GetErrorMessage(r));
3019                         }
3020                         else
3021                         {
3022                                 AppLogException("AppControl not found");
3023                         }
3024                         return;
3025                 }
3026         }
3027         if ( __pAddressbar != null && __pAddressbar->GetShowState() == true)
3028         {
3029                 __pAddressbar->SetShowState(false);
3030                 AddressBarCancelledClicked(*__pAddressbar);
3031                 __pAddressbar->Invalidate(true);
3032         }
3033         Bitmap* pBitmap = FaviconManager::GetInstance()->GetDefaultFaviconN();
3034         if(pBitmap != null)
3035         {
3036                 __pAddressbar->SetFaviconBitmap(*pBitmap);
3037         }
3038         delete pBitmap;
3039         if (__adressPanelPosition.y < (0 - __pAddressbar->GetHeight() + 12))
3040         {
3041                 // updating the address bar position with respect to web control
3042                 __adressPanelPosition.y = 0 - __pAddressbar->GetHeight() + 12; //-12 is for the progress label
3043                 __distanceMoved = 0;
3044                 MoveUiControls();
3045         }
3046
3047         //__pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING);
3048         SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING);
3049         if (__pWebViewer != null)
3050         {
3051                 AppLog("MainForm::OnLoadingStarted __pWebViewer->GetUrl() %ls",__pWebViewer->GetUrl().GetPointer());
3052                 //__pAddressbar->SetUrl(__pWebViewer->GetUrl());
3053                 SetUrl(__pWebViewer->GetUrl());
3054                 if (__pWindowInfo != NULL)
3055                 {
3056                         // resetting the page title to blank, it will be received in OnPageTitleReceived()
3057                         __pWindowInfo->pageTitle = L"";
3058                         __pWindowInfo->pageUrl = __pWebViewer->GetUrl();
3059                 }
3060                 __pAddressbar->Invalidate(true);
3061         }
3062
3063 }
3064
3065 void
3066 MainForm::OnLoadingCanceled(void)
3067 {
3068
3069 }
3070
3071
3072 void
3073 MainForm::OnKeypadWillOpen(Tizen::Ui::Control& source)
3074 {
3075         AppLog("XYZ::MainForm::OnKeypadWillOpen");
3076
3077 }
3078
3079 void
3080 MainForm::OnKeypadOpened(Tizen::Ui::Control& source)
3081 {
3082         AppLog("XYZ::MainForm::OnKeypadOpened");
3083         __pFooterPanel->SetShowState(false);
3084
3085 }
3086
3087 void
3088 MainForm::OnKeypadClosed(Tizen::Ui::Control& source)
3089 {
3090         AppLog("XYZ::MainForm::OnKeypadClosed");
3091         __pFooterPanel->SetShowState(true);
3092         RelayoutControls(true);
3093 }
3094
3095 void
3096 MainForm::OnKeypadBoundsChanged(Tizen::Ui::Control &source)
3097 {
3098         AppLog("XYZ::KeypadBoundsChanged");
3099         RelayoutControls(false);
3100 }
3101
3102 void
3103 MainForm::OnLoadingErrorOccurred(LoadingErrorType error,
3104                 const Tizen::Base::String& reason)
3105 {
3106         AppLogDebug("Error: %d, %ls", error, reason.GetPointer());
3107 }
3108
3109 void
3110 MainForm::OnLoadingCompleted(void)
3111 {
3112         AppLog("MainForm::OnLoadingCompleted start");
3113         DateTime date;
3114         result r = E_SUCCESS;
3115
3116         if (__pWebViewer == null)
3117         {
3118                 return;
3119         }
3120
3121         if (__pAddressbar == null)
3122         {
3123                 return;
3124         }
3125
3126         if(__pImageMenu && __pImageMenu->GetShowState())
3127         {
3128                 __pImageMenu->SetShowState(false);
3129                 __pImageMenu->Invalidate(true);
3130         }
3131
3132         if (__pWebViewer->CanGoForward())
3133         {
3134                 //__pAddressbar->SetForwardButtonEnabled(true);
3135                 SetForwardButtonEnabled(true);
3136         }
3137         else
3138         {
3139                 //__pAddressbar->SetForwardButtonEnabled(false);
3140                 SetForwardButtonEnabled(false);
3141         }
3142
3143         /*if (__pAddressbar->GetAddressbarMode() != ADDRESSBAR_MODE_EDIT)
3144         {
3145                 __pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
3146
3147                 //__pAddressbar->UpdateProgress(0);
3148                 UpdateProgress(0);
3149         }*/
3150
3151         if(GetAddressbarMode() != ADDRESSBAR_MODE_EDIT)
3152         {
3153                 SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
3154                 UpdateProgress(0);
3155         }
3156
3157         AppLog("PrivateBrowsing %d",__pWebViewer->IsPrivateBrowsingEnabled());
3158         bool isPrivateBrowsing = SettingPresentationModel::GetInstance()->GetPrivateOn();
3159         if (isPrivateBrowsing == false)
3160         {
3161                 if(__pHistory != null)
3162                 {
3163                         delete __pHistory;
3164                         __pHistory = null;
3165                 }
3166
3167                 __pHistory = new(std::nothrow) History;
3168                 HistoryPresentationModel::GetCurrentDateTime(date);
3169                 if (__pWindowInfo)
3170                 {
3171                         __pHistory->SetHistoryTitle(__pWindowInfo->pageTitle);
3172                         AppLogDebug("MainForm::OnLoadingCompleted pagetitle = %ls", __pWindowInfo->pageTitle.GetPointer());
3173
3174                         __pHistory->SetHistoryUrl(__pWindowInfo->pageUrl);
3175                         AppLogDebug("MainForm::OnLoadingCompleted pageUrl = %ls", __pWindowInfo->pageUrl.GetPointer());
3176                 }
3177                 __pHistory->SetVisitedTime(date);
3178
3179                 if (__pWebViewer != null)
3180                 {
3181                         AppLog("MainForm::OnLoadingCompleted setting the fav icon 0");
3182
3183                         Bitmap* pTempBitmap = __pWebViewer->GetFaviconN();
3184                         if (pTempBitmap != null)
3185                         {
3186                                 AppLog("MainForm::OnLoadingCompleted setting the fav icon 1");
3187                                 __pHistory->SetFavIconBitmap(*pTempBitmap);
3188                         }
3189
3190                         AppLog("MainForm::OnLoadingCompleted setting the fav icon 2");
3191                 }
3192
3193                 Canvas* pCanvas = __pWebViewer->GetCanvasN();
3194                 Bitmap* pBitmap = new(std::nothrow) Bitmap();
3195                 if ( pCanvas != null &&  pCanvas != null && pBitmap != null)
3196                 {
3197                         pBitmap->Construct(*pCanvas, pCanvas->GetBounds());
3198                         pBitmap->Scale(Dimension(pBitmap->GetWidth()/4, pBitmap->GetHeight()/4));
3199                         __pHistory->SetThumbnail(pBitmap);
3200                 }
3201                 Bitmap *pFavIcon = __pWebViewer->GetFaviconN();
3202                 if (pFavIcon)
3203                 {
3204                         __pHistory->SetFavIconBitmap(*pFavIcon);
3205                         delete pFavIcon;
3206                 }
3207
3208                 HistoryPresentationModel::GetInstance()->SaveTempHistory(*__pHistory);
3209                 //delete pHistory;
3210         }
3211         else
3212         {
3213                 return;
3214         }
3215 //      if (__pWindowInfo && __pWindowInfo->faviconUrl == "")
3216         {
3217                 // temperary fixed (webpage can be not loaded)
3218                 UpdateFavicon();
3219         }
3220
3221         bool isReaderEnabled = SettingPresentationModel::GetInstance()->IsRunReaderEnabled();
3222         if (isReaderEnabled == true)
3223         {
3224                 if (__pReaderData)
3225                 {
3226                         delete __pReaderData;
3227                         __pReaderData = null;
3228                 }
3229                 String filePath = Tizen::App::UiApp::GetInstance()->GetAppRootPath();
3230                 filePath.Append(L"data/reader.js");
3231                 File file;
3232                 char buffer[10];
3233                 char buffer2[5];
3234                 int i;
3235                 int readCnt;
3236                 result r = E_SUCCESS;
3237                 FileAttributes attr;
3238
3239                 File::GetAttributes(filePath,attr);
3240                 // Creates file
3241                 r = file.Construct(filePath, L"r+");
3242                 if (IsFailed(r))
3243                 {
3244                         AppLogDebug("File construct failed with %s", GetErrorMessage(r));
3245                         return;
3246                 }
3247                 char* pScript = new(std::nothrow) char[attr.GetFileSize()+1];
3248                 if(pScript == null)
3249                 {
3250                         AppLogDebug("Memory allocation for file failed %s", GetErrorMessage(r));
3251                         return;
3252                 }
3253 //              file.Read(pScript,attr.GetFileSize());
3254 //
3255 //              AppLogDebug("scipt length %d",strlen(pScript));
3256                 String strScript = L"";
3257 //              strScript.Append(pScript);
3258 //              for(int i=0; i<25; i++)
3259                 {
3260                         file.Read(pScript,attr.GetFileSize());
3261 //                      AppLog("xyzz tell %d",file.Tell());
3262 //                      r = strScript.Append(pScript);
3263 //                      AppLog("xyzz append result %s",GetErrorMessage(r));
3264 //                      AppLog("xyzz strScript length %d",strScript.GetLength());
3265                 }
3266 //              AppLog("xyzz final strScript length %d",strScript.GetLength());
3267
3268                 __pReaderData = __pWebViewer->EvaluateJavascriptN(pScript);
3269                 if (__pReaderData == null)
3270                 {
3271                         AppLog("MainScene::data is null Error :%s",GetErrorMessage(GetLastResult()));
3272                         __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>");
3273 //                      return;
3274                 }
3275                 AppLogDebug("evaluateJavascript result %s , __pReaderData %ls",GetErrorMessage(GetLastResult()),__pReaderData->GetPointer());
3276                 if (__pReaderData->CompareTo(L"undefined") != 0 && __pReaderData->CompareTo(L"") != 0)
3277                 {
3278                         //__pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_READER);
3279                         SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_READER);
3280                 }
3281                 delete[] pScript;
3282         }
3283
3284
3285         AppLog("MainForm::OnLoadingCompleted done");
3286 }
3287
3288 void
3289 MainForm::OnEstimatedProgress(int progress)
3290 {
3291         AppLogDebug("MainForm::OnEstimatedProgress entered");
3292
3293         if (progress < DEFAULT_PROGRESS_PERCENTAGE)
3294                 progress = DEFAULT_PROGRESS_PERCENTAGE;
3295         //if(__pAddressbar)
3296         //      __pAddressbar->UpdateProgress(progress);
3297         UpdateProgress(progress);
3298 }
3299
3300 void MainForm::OnFaviconReceived(const Tizen::Graphics::Bitmap& favicon)
3301 {
3302         AppLog("MainForm::OnFaviconReceived");
3303         if (__pWebViewer != null && __pHistory != null && __pWindowInfo != null && (__pWindowInfo->pageUrl.CompareTo(__pHistory->GetHistoryUrl()) == 0))
3304         {
3305                 Bitmap* favIcon = __pWebViewer->GetFaviconN();
3306                 if(favIcon != null)
3307                 {
3308                         HistoryPresentationModel::GetInstance()->UpdateHistoryFavIcon(*__pHistory, *favIcon);
3309                         delete favIcon;
3310                 }
3311         }
3312 }
3313
3314 void
3315 MainForm::OnUrlValueChanged(Addressbar&)
3316 {
3317         Invalidate(true);
3318 }
3319
3320 void
3321 MainForm::OnUrlSubmitted(Addressbar& addBar)
3322 {
3323         AppLog("MainForm::OnUrlSubmitted");
3324         String url = addBar.GetUrl();
3325         AppLog("MainForm::OnUrlSubmitted url is %ls", url.GetPointer());
3326
3327         if(__pFooterUrlField)
3328                 __pFooterUrlField->SetCursorPosition(__pFooterUrlField->GetTextLength());
3329         AddressBarCancelledClicked(*__pAddressbar);
3330         LoadUrl(url);
3331 }
3332
3333 void
3334 MainForm::LoadUrl(String& url)
3335 {
3336         url.Trim();
3337         String encodedUrl;
3338 //      UrlEncoder::Encode(url, L"UTF-8", encodedUrl);
3339         AppLogDebug("MainForm::LoadUrl enter");
3340
3341         if (__pWebViewer != null)
3342         {
3343                 __pWebViewer->SetShowState(true);
3344                 __pWebViewer->Invalidate(true);
3345         }
3346
3347         if (url.CompareTo(L"") == 0)
3348         {
3349                 return;
3350         }
3351         if(__pFooterPanel != null)
3352         {
3353                 __pFooterPanel->SetShowState(true);
3354                 __pFooterPanel->Invalidate(true);
3355         }
3356         InitWebControl();
3357
3358         bool ret = false;
3359         bool flag = false;
3360
3361         String firstPattern(L"((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)");
3362         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)
3363
3364         RegularExpression firstRegex;
3365         RegularExpression secondRegex;
3366
3367         firstRegex.Construct(firstPattern, REGEX_CASELESS);
3368         secondRegex.Construct(secondPattern, REGEX_CASELESS);
3369
3370         // Match
3371         ret = firstRegex.Match(url, false); // This returns true value
3372         flag = secondRegex.Match(url, false);  // Checks whether URL typed is of type  abc.com (i.e without protocol in front of it)
3373
3374         if (ret == true && __pWebViewer != null)
3375         {
3376                 SetUrl(url);
3377                 __pWebViewer->LoadUrl(url);
3378         }
3379         else if(__pWebViewer != null)
3380         {
3381                 String tempUrl = L"http://";
3382                 tempUrl.Append(url);
3383
3384                 if (flag == true)
3385                 {
3386                         __pWebViewer->LoadUrl(tempUrl);
3387                 }
3388                 else
3389                 {
3390                                 UrlEncoder::Encode(url, L"UTF-8", encodedUrl);
3391                         __pWebViewer->LoadUrl(SettingPresentationModel::GetInstance()->GetSearchUrl(encodedUrl));
3392                 }
3393         }
3394         if (__pAddressbar != null)
3395         {
3396                 //__pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING);
3397                 SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING);
3398         }
3399
3400         AppLogDebug("MainForm::LoadUrl exit");
3401
3402         return;
3403
3404 }
3405
3406 void
3407 MainForm::OnFocusGained(const Tizen::Ui::Control& source)
3408 {
3409         if(__pFooterPanel)
3410         {
3411                 __pFooterPanel->SetShowState(false);
3412         }
3413
3414         if(__pAddressbar)
3415         {
3416                 __pAddressbar->SetShowState(true);
3417                 __pAddressbar->SetAddressbarURLFocus();
3418         }
3419         RelayoutControls(false);
3420 }
3421
3422 void
3423 MainForm::OnFocusLost(const Tizen::Ui::Control& source)
3424 {
3425
3426 }
3427
3428 void
3429 MainForm::OnStopClicked(Addressbar& addBar)
3430 {
3431         AppLogDebug("MainForm::OnStopClicked called");
3432         if (__pWebViewer)
3433         {
3434                 //__pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
3435                 SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
3436                 __pWebViewer->StopLoading();
3437                 RequestRedraw(true);
3438         }
3439 }
3440
3441 void
3442 MainForm::OnBackClicked(/*const Addressbar& addBar*/)
3443 {
3444         //      AppLog("MainForm::OnBackClicked");
3445         result r = E_FAILURE;
3446         if(__pImageMenu && __pImageMenu->GetShowState() == true)
3447         {
3448                 AppLog("Hiding the menu");
3449                 __pImageMenu->SetShowState(false);
3450         }
3451
3452         if (__pWebViewer && __pWebViewer->CanGoBack())
3453         {
3454                 __pWebViewer->GoBack();
3455         }
3456         else if(__pWindowInfo && __pWindowInfo->isJavascriptInitiated == false)
3457         {
3458                 UiApp* pApp = null;
3459                 pApp = UiApp::GetInstance();
3460                 if (pApp != null)
3461                 {
3462
3463                         RemoveOrientationEventListener(*this);
3464
3465                         if(__pAddressbar)
3466                         {
3467                                 __pAddressbar->SetAddressbarEventListener(null);
3468                         }
3469
3470                         if(__pWebViewer)
3471                         {
3472                                 __pWebViewer->RemoveTouchEventListener(*this);
3473                                 __pWebViewer->SetWebUiEventListenerF(null);
3474                                 __pWebViewer->SetWebKeypadEventListener(null);
3475                                 __pWebViewer->SetTextSearchListener(null);
3476                                 __pWebViewer->SetLoadingListener(null);
3477                         }
3478
3479
3480                         r = pApp->Terminate();
3481                         if (IsFailed(r))
3482                         {
3483                                 AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
3484                                 return;
3485                         }
3486                 }
3487         }
3488         else
3489         {
3490                 UiApp* pApp = null;
3491                 WindowInfo* pWindowInfo = null;
3492                 int totalCount = 0;
3493                 SceneManager* pSceneManager = SceneManager::GetInstance();
3494                 if (pSceneManager == null)
3495                 {
3496                         return;
3497                 }
3498                 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
3499                 if (pAllWindowList == NULL)
3500                 {
3501                         pApp = UiApp::GetInstance();
3502                         if (pApp != null)
3503                         {
3504                                 RemoveOrientationEventListener(*this);
3505
3506                                 if(__pAddressbar)
3507                                 {
3508                                         __pAddressbar->SetAddressbarEventListener(null);
3509                                 }
3510
3511                                 if(__pWebViewer)
3512                                 {
3513                                         __pWebViewer->RemoveTouchEventListener(*this);
3514                                         __pWebViewer->SetWebUiEventListenerF(null);
3515                                         __pWebViewer->SetWebKeypadEventListener(null);
3516                                         __pWebViewer->SetTextSearchListener(null);
3517                                         __pWebViewer->SetLoadingListener(null);
3518                                 }
3519
3520
3521                                 r = pApp->Terminate();
3522                                 if (IsFailed(r))
3523                                 {
3524                                         AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
3525                                         return;
3526                                 }
3527                         }
3528                 }
3529                 if (pAllWindowList != null)
3530                 {
3531                         totalCount = pAllWindowList->GetCount();
3532                 }
3533                 for (int count = 0; count < totalCount; count++)
3534                 {
3535                         pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count));
3536                         if (pWindowInfo == null)
3537                         {
3538                                 pApp = UiApp::GetInstance();
3539                                 if (pApp != null)
3540                                 {
3541                                         RemoveOrientationEventListener(*this);
3542
3543                                         if(__pAddressbar)
3544                                         {
3545                                                 __pAddressbar->SetAddressbarEventListener(null);
3546                                         }
3547
3548                                         if(__pWebViewer)
3549                                         {
3550                                                 __pWebViewer->RemoveTouchEventListener(*this);
3551                                                 __pWebViewer->SetWebUiEventListenerF(null);
3552                                                 __pWebViewer->SetWebKeypadEventListener(null);
3553                                                 __pWebViewer->SetTextSearchListener(null);
3554                                                 __pWebViewer->SetLoadingListener(null);
3555                                         }
3556
3557
3558                                         r = pApp->Terminate();
3559                                         if (IsFailed(r))
3560                                         {
3561                                                 AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
3562                                                 return;
3563                                         }
3564                                 }
3565                         }
3566                         if (pSceneManager != null && pWindowInfo != null && pSceneManager->GetCurrentSceneId() == pWindowInfo->sceneID && pWindowInfo->isJavascriptInitiated == true)
3567                         {
3568                                 r = SceneRegister::DestroyAndUnRegisterScene(pWindowInfo->sceneID);
3569                                 if (IsFailed(r))
3570                                 {
3571                                         AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
3572                                         return;
3573                                 }
3574                                 r = pAllWindowList->RemoveAt(count, true);
3575                                 __pWindowInfo = null;
3576                                 if (IsFailed(r))
3577                                 {
3578                                         AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
3579                                         return;
3580                                 }
3581                                 if(count > 0)
3582                                 {
3583                                         pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count - 1));
3584                                 }
3585                                 else if(pAllWindowList->GetCount() > 0)
3586                                 {
3587                                         pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(pAllWindowList->GetCount() - 1));
3588                                 }
3589                                 else
3590                                 {
3591                                         pApp = UiApp::GetInstance();
3592                                         if (pApp != null)
3593                                         {
3594                                                 RemoveOrientationEventListener(*this);
3595
3596                                                 if(__pAddressbar)
3597                                                 {
3598                                                         __pAddressbar->SetAddressbarEventListener(null);
3599                                                 }
3600
3601                                                 if(__pWebViewer)
3602                                                 {
3603                                                         __pWebViewer->RemoveTouchEventListener(*this);
3604                                                         __pWebViewer->SetWebUiEventListenerF(null);
3605                                                         __pWebViewer->SetWebKeypadEventListener(null);
3606                                                         __pWebViewer->SetTextSearchListener(null);
3607                                                         __pWebViewer->SetLoadingListener(null);
3608                                                 }
3609
3610
3611                                                 r = pApp->Terminate();
3612                                                 return;
3613                                         }
3614
3615                                 }
3616                                 if (pWindowInfo == null)
3617                                 {
3618                                         pApp = UiApp::GetInstance();
3619                                         if (pApp != null)
3620                                         {
3621                                                 RemoveOrientationEventListener(*this);
3622
3623                                                 if(__pAddressbar)
3624                                                 {
3625                                                         __pAddressbar->SetAddressbarEventListener(null);
3626                                                 }
3627
3628                                                 if(__pWebViewer)
3629                                                 {
3630                                                         __pWebViewer->RemoveTouchEventListener(*this);
3631                                                         __pWebViewer->SetWebUiEventListenerF(null);
3632                                                         __pWebViewer->SetWebKeypadEventListener(null);
3633                                                         __pWebViewer->SetTextSearchListener(null);
3634                                                         __pWebViewer->SetLoadingListener(null);
3635                                                 }
3636
3637
3638                                                 r = pApp->Terminate();
3639                                                 return;
3640                                         }
3641                                 }
3642                                 else
3643                                 {
3644                                         r = pSceneManager->GoBackward(BackwardSceneTransition(pWindowInfo->sceneID ,SCENE_TRANSITION_ANIMATION_TYPE_NONE));
3645                                         if (IsFailed(r))
3646                                         {
3647                                                 AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
3648                                                 return;
3649                                         }
3650                                 }
3651                                 break;
3652                         }
3653
3654                 }
3655
3656         }
3657
3658 }
3659
3660 void
3661 MainForm::OnForwardClicked(/*const Addressbar& addBar*/)
3662 {
3663         AppLog("MainForm::OnForwardClicked");
3664         if (__pWebViewer == null)
3665                 return;
3666
3667         if (__pWebViewer->CanGoForward())
3668         {
3669                 __pWebViewer->GoForward();
3670         }
3671 }
3672
3673 void
3674 MainForm::OnAddressBarFocusGained(const Addressbar& addBar)
3675 {
3676         AppLog("XYZ::MainForm::OnAddressBarFocusGained");
3677         if(__pFooterPanel != null)
3678         {
3679                 __pFooterPanel->SetShowState(false);
3680         }
3681
3682         if (__pAddressbar != null && __pAddressbar->GetShowState() == false)
3683         {
3684                 __pAddressbar->SetShowState(true);
3685                 __pAddressbar->SetBounds(Rectangle(0,0,GetClientAreaBounds().width,__pAddressbar->GetHeight()));
3686         }
3687
3688         RelayoutControls(false);
3689 }
3690
3691 void
3692 MainForm::OnAddressBarFocusLost(const Addressbar& addBar, bool addressbarKeyPadState)
3693 {
3694         AppLog("XYZ::MainForm::OnAddressBarFocusLost");
3695
3696         int Height = GetClientAreaBounds().height;
3697         AppLog("MainForm::OnAddressBarFocusLost height is %d",Height);
3698
3699         RelayoutControls(false);
3700 }
3701
3702 void
3703 MainForm::OnAddressCancelledClicked(const Addressbar& addBar)
3704 {
3705         AddressBarCancelledClicked(addBar);
3706 }
3707
3708 void
3709 MainForm::OnAddressBarModeChanged(/*const Addressbar& addBar*/)
3710 {
3711         __prevAddressBarMode = __curAddressBarMode;
3712
3713         if (__pAddressbar != null)
3714         {
3715                 __curAddressBarMode = GetAddressbarMode();
3716         }
3717
3718         if (__curAddressBarMode == ADDRESSBAR_MODE_EDIT)
3719         {
3720                 __adressPanelPosition.y = 0;
3721                 if (__pAddressbar != null)
3722                 {
3723                         __webControlPosition.y = __pAddressbar->GetHeight() - 12;
3724                         __pAddressbar->SetBounds(Rectangle(0,0,GetClientAreaBounds().width,__pAddressbar->GetHeight()));
3725                         __pAddressbar->Invalidate(true);
3726                 }
3727                 if (__pWebViewer != null)
3728                 {
3729                         __pWebViewer->StopLoading();
3730                 }
3731         }
3732         else if(__curAddressBarMode == ADDRESSBAR_MODE_LOADING)
3733         {
3734                 __adressPanelPosition.y = 0;
3735                 if (__pAddressbar != null)
3736                 {
3737                         __webControlPosition.y = 0;
3738                         __pAddressbar->SetBounds(Rectangle(0, __pAddressbar->GetY() - __pAddressbar->GetHeight(), GetClientAreaBounds().width, __pAddressbar->GetHeight()));
3739                         __pAddressbar->Invalidate(true);
3740                 }
3741         }
3742 }
3743
3744 void
3745 MainForm::OnClipboardClosed(const Addressbar& addBar)
3746 {
3747         AppLog("XYZ::MainForm::OnClipboardClosed");
3748         RelayoutControls(false);
3749 }
3750
3751 void
3752 MainForm::OnAddressBarKeypadClosed(const Addressbar& addBar, bool footerState)
3753 {
3754         AppLog("XYZ::MainForm::OnAddressBarKeypadClosed");
3755         if (__pFooterPanel && __pAddressbar->GetShowState() == false)
3756         {
3757                 AppLog("akjshdasd 3");
3758                 __pFooterPanel->SetShowState(true);
3759         }
3760
3761         RelayoutControls(false,footerState);
3762 }
3763
3764 void
3765 MainForm::OnAddressBarKeypadOpened(const Addressbar& addBar)
3766 {
3767         AppLog("XYZ::MainForm::OnAddressBarKeypadOpened");
3768         RelayoutControls(false);
3769 }
3770
3771 void
3772 MainForm::OnAddressBarKeypadWillOpen(const Addressbar& addBar)
3773 {
3774         __pFooterPanel->SetShowState(false);
3775 }
3776
3777 void
3778 MainForm::OnAddressBarKeypadBoundsChanged(const Addressbar& addBar)
3779 {
3780         AppLog("XYZ::MainForm::OnAddressBarKeypadBoundsChanged");
3781         RelayoutControls(false);
3782 }
3783
3784 void
3785 MainForm::OnPageTitleReceived(const Tizen::Base::String& title)
3786 {
3787         AppLog("MainForm::OnPageTitleReceived %ls",title.GetPointer());
3788         if (__pWindowInfo)
3789         {
3790                 __pWindowInfo->pageTitle = title;
3791                 if (__pWebViewer != null)
3792                 {
3793                         __pWindowInfo->pageUrl = __pWebViewer->GetUrl();
3794                 }
3795         }
3796         if (__pAddressbar != null && __pWebViewer != null)
3797         {
3798                 SetUrl(__pWebViewer->GetUrl());
3799                 __pAddressbar->Invalidate(true);
3800         }
3801 }
3802
3803 void
3804 MainForm::UpdateFavicon(void)
3805 {
3806         bool urlImageType = false;
3807         String *tempPath = null;
3808         if(__pWebViewer)
3809                 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();");
3810         Bitmap* pBitmap = null;
3811
3812         if (tempPath && tempPath->GetLength() > 0 && tempPath->CompareTo(L"undefined") != 0)
3813         {
3814                 if (__pWindowInfo != null)
3815                 {
3816                         Uri url;
3817                         url.SetUri(*tempPath);
3818                         if (url.GetHost().GetLength() == 0)
3819                         {
3820                                 Uri webUrl;
3821                                 webUrl.SetUri(__pWebViewer->GetUrl());
3822                                 result r = url.SetHost(webUrl.GetHost());
3823                                 if(IsFailed(r))
3824                                 {
3825                                         delete tempPath;
3826                                         return;
3827                                 }
3828                         }
3829                         if (url.GetScheme().GetLength() == 0)
3830                         {
3831                                 Uri webUrl;
3832                                 webUrl.SetUri(__pWebViewer->GetUrl());
3833                                 url.SetScheme(webUrl.GetScheme());
3834                         }
3835                         __pWindowInfo->faviconUrl = url.ToString();
3836
3837                         pBitmap = __pWebViewer->GetFaviconN();
3838
3839                         if (pBitmap != null)
3840                         {
3841                                 if (__pWindowInfo->pFavicon != NULL)
3842                                 {
3843                                         __pWindowInfo->pFavicon = null;
3844                                 }
3845                                 __pWindowInfo->pFavicon = new(std::nothrow) Bitmap();
3846                                 __pWindowInfo->pFavicon->Construct(*pBitmap,Rectangle(0,0,pBitmap->GetWidth(),pBitmap->GetHeight()));
3847
3848                                 __pAddressbar->SetFaviconBitmap(*__pWindowInfo->pFavicon);
3849
3850                                 FaviconManager::GetInstance()->SaveFavicon(*__pWindowInfo->pFavicon, __pWindowInfo->faviconUrl);
3851                         }
3852                         else if(__pWindowInfo->pFavicon != null)
3853                         {
3854                                 __pAddressbar->SetFaviconBitmap(*__pWindowInfo->pFavicon);
3855                         }
3856                         else
3857                         {
3858                                 Bitmap *pDefaultBmp = FaviconManager::GetInstance()->GetDefaultFaviconN();
3859                                 if(pDefaultBmp != null)
3860                                 {
3861                                         __pAddressbar->SetFaviconBitmap(*pDefaultBmp);
3862                                 }
3863                         }
3864                         if(pBitmap)
3865                         {
3866                                 delete pBitmap;
3867                                 pBitmap = null;
3868                         }
3869                 }
3870                 delete tempPath;
3871         }
3872         else
3873         {
3874                 // do not remove
3875                 if(tempPath != null)
3876                 {
3877                         delete tempPath;
3878                 }
3879                 AppLogDebug("Error occured: %s", GetErrorMessage(GetLastResult()));
3880         }
3881
3882 }
3883
3884 bool
3885 MainForm::OnLoadingRequested(const Tizen::Base::String& url,
3886                 Tizen::Web::Controls::WebNavigationType type)
3887 {
3888         AppLog("urlk %ls",url.GetPointer());
3889         // when load new page if find word panel is open its show state is false
3890         if(__pFindWordControl && __pFindWordControl->GetShowState() == true)
3891         {
3892                 __currentSearchStr = L"";
3893                 __currentWordIndex = 0;
3894                 __maxOccurrances = 0;
3895                 __pFindWordEditField->SetText(L"");
3896                 __pFindWordNext->SetEnabled(false);
3897                 __pFindWordPrev->SetEnabled(false);
3898                 __pFindWordCountLabel->SetText(L"0/0");
3899                 __pFindWordControl->SetShowState(false);
3900                 __pFindWordEditField->HideKeypad();
3901                 RelayoutControls(false);
3902         }
3903
3904         __pFooterPanel->Invalidate(true);
3905
3906         Uri uriInfo;
3907         uriInfo.SetUri(url);
3908
3909         if(url.Contains(IDS_TIZEN_SERVICE))
3910         {
3911                 String appId;
3912                 String delim(L":;,");
3913
3914                 // Creates a StringTokenizer instance
3915                 StringTokenizer strTok(url, delim);
3916
3917                 int count = strTok.GetTokenCount();     // count == 4
3918
3919                 HashMap *pMap = new HashMap();
3920                 pMap->Construct();
3921
3922                 String token;
3923                 String key;
3924                 String value;
3925                 while (strTok.HasMoreTokens())
3926                 {
3927                         AppLog("Token: %ls", token.GetPointer());
3928                         strTok.GetNextToken(token);         // Tizen, StringTokenizer, Sample, code
3929                         if(token.Contains(IDS_APPID))
3930                         {
3931                                 token.SubString(6, appId);
3932                                 AppLog("AppID:%ls", appId.GetPointer());
3933                         }
3934                         else if(token.Contains(IDS_KEY))
3935                         {
3936                                 token.SubString(4, key);
3937                                 AppLog("key:%ls", key.GetPointer());
3938                         }
3939                         else if(token.Contains(IDS_VALUE))
3940                         {
3941                                 token.SubString(6, value);
3942                                 AppLog("value:%ls", value.GetPointer());
3943                         }
3944                 }
3945                 pMap->Add(key, value);
3946
3947                 if(appId != "")
3948                 {
3949                         AppControl *pAppControl = null;
3950                         String operationId = L"http://tizen.org/appcontrol/operation/main";
3951                         pAppControl = dynamic_cast<AppControl*>(AppManager::FindAppControlN(appId, operationId));
3952                         if(pAppControl)
3953                         {
3954                                 result r = pAppControl->Start(null, null, pMap, null);
3955                         }
3956                         else
3957                         {
3958                                 AppLogException("AppControl not found");
3959                         }
3960                         return true;
3961                 }
3962         }
3963
3964         return false;
3965 }
3966
3967 DecisionPolicy
3968 MainForm::OnWebDataReceived(const Tizen::Base::String& mime,
3969                 const Tizen::Net::Http::HttpHeader& httpHeader)
3970 {
3971         return Tizen::Web::Controls::WEB_DECISION_CONTINUE;
3972 }
3973
3974 void
3975 MainForm::OnWebPageBlockSelected(Web& source, FloatPoint& startPoint, FloatPoint& endPoint)
3976 {
3977         if(__isLongPressedDone == false)
3978                 return;
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",contentPath);
5308         AppLog("Content manager update content result %s" ,GetErrorMessage(GetLastResult()));
5309 }
5310
5311 void
5312 MainForm::ShowIndicatorNotification(const String& messageText, const String& contentPath)
5313 {
5314         AppLogDebug("ENTER");
5315
5316         NotificationRequest request;
5317         request.SetAlertText(messageText);
5318         request.SetTitleText(L"");
5319         request.SetAppMessage(contentPath);
5320         request.SetOngoingActivityType(ONGOING_ACTIVITY_TYPE_TEXT);
5321         request.SetNotificationStyle(NOTIFICATION_STYLE_THUMBNAIL);
5322         Tizen::App::App* pApp = Tizen::App::App::GetInstance();
5323         String homePath = pApp->GetAppRootPath();
5324         String iconPath = homePath + L"res/screen-density-xhigh/Notification_download_complete.png";
5325         AppLog("The iconPath is : %ls", homePath.GetPointer());
5326         request.SetIconFilePath(iconPath);
5327
5328         Tizen::Shell::NotificationManager notiMgr;
5329         notiMgr.Construct();
5330         notiMgr.NotifyOngoingActivity(request);
5331
5332         AppLogDebug("EXIT: %s", GetErrorMessage(GetLastResult()));
5333         return;
5334 }
5335
5336 void
5337 MainForm::SetForwardButtonEnabled(bool isEnabled)
5338 {
5339         __pGoForwardBtn->SetEnabled(isEnabled);
5340         __pGoForwardBtn->Invalidate(true);
5341 }
5342
5343 void
5344 MainForm::SetBackButtonEnabled(bool isEnabled)
5345 {
5346         __pGoBackBtn->SetEnabled(isEnabled);
5347         __pGoBackBtn->Invalidate(true);
5348 }
5349
5350 void
5351 MainForm::UpdateProgress(int percentage)
5352 {
5353         __progressPercentage = percentage;
5354         if (percentage == 0 || percentage == 100)
5355         {
5356                 __isLoadingData = false;
5357                 if (percentage == 100)
5358                 {
5359                         __isLoadingCompleted = true;
5360                         __progressPercentage = 0;
5361                 }
5362                 else
5363                 {
5364                         __isLoadingCompleted = false;
5365                 }
5366         }
5367         else
5368         {
5369                 __isLoadingData = true;
5370         }
5371         UpdateProgressBitmap();
5372 }
5373
5374 int
5375 MainForm::GetProgress(void)
5376 {
5377         return __progressPercentage;
5378 }
5379
5380 void
5381 MainForm::UpdateProgressBitmap(void)
5382 {
5383         result r = E_SUCCESS;
5384         if (__pProgressbarLabel == null)
5385                 return;
5386         int w = __pProgressbarLabel->GetWidth();
5387         int h = __pProgressbarLabel->GetHeight();
5388         Canvas canvas;
5389         int progressWidth = 0;
5390         Bitmap* pRetBitmap = null;
5391
5392         if (__progressPercentage == 0 || __progressPercentage == 100)
5393         {
5394                 __pProgressbarLabel->SetShowState(false);
5395                 __pProgressbarLabel->Invalidate(false);
5396                 return;
5397         }
5398         else
5399         {
5400                 __pProgressbarLabel->SetShowState(true);
5401                 __pProgressbarLabel->Invalidate(false);
5402         }
5403
5404         r = canvas.Construct(Rectangle(0, 0, w, h));
5405
5406         if (r != E_SUCCESS)
5407         {
5408                 AppLogException("Canvas construction failed with %s", GetErrorMessage(r));
5409                 return;
5410         }
5411
5412         canvas.Clear();
5413         Bitmap *pBgBmp = AppResource::GetInstance()->GetBitmapN(IDB_TITLE_PROGRESS_BAR_BG);
5414
5415         if (pBgBmp != null)
5416         {
5417                 pBgBmp->Scale(Dimension(w, h));
5418                 canvas.DrawBitmap(Point(0,0), *pBgBmp);
5419                 delete pBgBmp;
5420         }
5421
5422         progressWidth = (double) (w) * __progressPercentage / 100;
5423         AppLogDebug("progressWidth: %d", progressWidth);
5424         Bitmap *pProgressBmp = AppResource::GetInstance()->GetBitmapN(IDB_TITLE_PROGRESS_BAR);
5425
5426         if (pProgressBmp != null)
5427         {
5428                 pProgressBmp->Scale(Dimension(progressWidth, h));
5429                 canvas.DrawBitmap(Point(0,0), *pProgressBmp);
5430                 delete pProgressBmp;
5431         }
5432
5433         pRetBitmap = new (std::nothrow) Bitmap();
5434
5435         if (pRetBitmap == null)
5436         {
5437                 AppLogException("Bitmap creation failed with %s", GetErrorMessage(r));
5438                 return;
5439         }
5440
5441         pRetBitmap->Construct(canvas, canvas.GetBounds());
5442
5443         if (__pProgressbarLabel != null && pRetBitmap != null)
5444         {
5445                 __pProgressbarLabel->SetBackgroundBitmap(*pRetBitmap);
5446                 __pProgressbarLabel->Invalidate(false);
5447         }
5448
5449         if (pRetBitmap != null)
5450         {
5451                 delete pRetBitmap;
5452                 pRetBitmap = null;
5453         }
5454         return;
5455 }
5456
5457 void
5458 MainForm::ReaderClicked()
5459 {
5460         result r = E_SUCCESS;
5461         ArrayList* pArgList = new(std::nothrow) ArrayList();
5462         if (pArgList != null)
5463         {
5464                 r = pArgList->Construct();
5465                 if (IsFailed(r))
5466                 {
5467                         delete pArgList;
5468                         return;
5469                 }
5470
5471                 r = pArgList->Add(*new(std::nothrow) String(*__pReaderData));
5472                 if (IsFailed(r))
5473                 {
5474                         delete pArgList;
5475                         return;
5476                 }
5477
5478                 r = pArgList->Add(*new(std::nothrow) String(__pWebViewer->GetUrl()));
5479                 if (IsFailed(r))
5480                 {
5481                         delete pArgList;
5482                         return;
5483                 }
5484
5485                 r = pArgList->Add(*new(std::nothrow) String(__pWindowInfo->pageTitle));
5486                 if (IsFailed(r))
5487                 {
5488                         delete pArgList;
5489                         return;
5490                 }
5491         }
5492
5493         SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_ARTICLE_READER, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
5494         return;
5495
5496
5497 }
5498
5499 void MainForm::SetAddressbarMode(AddressBarMode addMode)
5500 {
5501         AppLogDebug("AddressBar::setAddressbarMode to %d",addMode);
5502
5503         __currentAddMode = addMode;
5504
5505         switch(addMode)
5506         {
5507         case ADDRESSBAR_MODE_INVALID:
5508         {
5509                 // do nothing
5510         }
5511         break;
5512         case ADDRESSBAR_MODE_READER:
5513         {
5514                 __pStopBtn->SetShowState(false);
5515                 __pRefreshBtn->SetShowState(false);
5516                 __pClearBtn->SetShowState(false);
5517                 __pReaderBtn->SetShowState(false);
5518         }
5519         break;
5520         case ADDRESSBAR_MODE_LOADING:
5521         {
5522                 __pRefreshBtn->SetShowState(false);
5523                 __pStopBtn->SetShowState(true);
5524                 __pClearBtn->SetShowState(false);
5525                 __pReaderBtn->SetShowState(false);
5526         }
5527         break;
5528         case ADDRESSBAR_MODE_LOADING_COMPLETE:
5529         {
5530 //              SetUrl(__pAddressbar->GetUrl());
5531
5532                 __pRefreshBtn->SetShowState(true);
5533                 __pStopBtn->SetShowState(false);
5534                 __pClearBtn->SetShowState(false);
5535                 __pReaderBtn->SetShowState(false);
5536         }
5537         break;
5538         case ADDRESSBAR_MODE_EDIT:
5539         {
5540                 __pRefreshBtn->SetShowState(false);
5541                 __pStopBtn->SetShowState(false);
5542                 __pReaderBtn->SetShowState(false);
5543                 __pClearBtn->SetShowState(true);
5544         }
5545         break;
5546         }
5547
5548         Invalidate(true);
5549
5550         OnAddressBarModeChanged();
5551 }
5552
5553 AddressBarMode MainForm::GetAddressbarMode(void)
5554 {
5555         return __currentAddMode;
5556 }
5557
5558 void MainForm::SetUrl(const String& url)
5559 {
5560         __displayUrl = url;
5561         if(__displayUrl.GetLength() > 2048)
5562                 __displayUrl.SubString(0,2048,__displayUrl);
5563
5564         if (__pFooterUrlField != NULL)
5565         {
5566                 String removedHttpUrl = RemoveHttpTextFromDisplayURL();
5567                 if (removedHttpUrl.IsEmpty() == false)
5568                 {
5569                         __pFooterUrlField->SetText(removedHttpUrl);
5570                         if(__pAddressbar != NULL && __pAddressbar->HasCurrentFocus() == false)
5571                                 __pAddressbar->SetUrl(__displayUrl);
5572                 }
5573                 else
5574                 {
5575                         __pFooterUrlField->SetText(__displayUrl);
5576                         if(__pAddressbar != NULL && __pAddressbar->HasCurrentFocus() == false)
5577                                 __pAddressbar->SetUrl(__displayUrl);
5578                 }
5579                 if(__pFooterUrlField)
5580                         __pFooterUrlField->SetCursorPosition(__pFooterUrlField->GetTextLength());
5581                 __pFooterUrlField->Invalidate(false);
5582                 if(__pAddressbar != NULL && __pAddressbar->HasFocus())
5583                         __pAddressbar->Invalidate(true);
5584 //              __pFooterUrlField->SetCursorPosition(0);
5585         }
5586 }
5587
5588 String
5589 MainForm::RemoveHttpTextFromDisplayURL(void)
5590 {
5591         AppLog("MainForm::RemoveHttpTextFromDisplayURL __displayUrl %ls",__displayUrl.GetPointer());
5592         int index = -1;
5593 //      bool isHttpText = __displayUrl.Contains(L"http://");
5594         String updatedDisplayUrl;
5595         updatedDisplayUrl.Clear();
5596         if(__displayUrl.IndexOf(L"http://",0,index) == E_SUCCESS && index == 0)
5597         {
5598                 __displayUrl.SubString(7,updatedDisplayUrl);
5599         }
5600         else if(__displayUrl.IndexOf(L"https://",0,index) == E_SUCCESS && index == 0)
5601         {
5602                 __displayUrl.SubString(8,updatedDisplayUrl);
5603         }
5604         return updatedDisplayUrl;
5605 }
5606
5607 void MainForm::OnSharePopupControlStarted(void)
5608 {
5609         __pWebViewer->AddTouchEventListener(*this);
5610 }
5611
5612 void
5613 MainForm::OnUserEventReceivedN (RequestId requestId, Tizen::Base::Collection::IList *pArgs)
5614 {
5615         if (requestId == BACK_GROUND_APP_EVENT)
5616         {
5617                 if(__pWebViewer != null)
5618                 {
5619                         __pWebViewer->Pause();
5620                 }
5621                 if(__pAddressbar != null)
5622                 {
5623                         __pAddressbar->SendUserEvent(BACK_GROUND_APP_EVENT,NULL);
5624                 }
5625         }
5626         else if(requestId == FORE_GROUND_APP_EVENT)
5627         {
5628                 if(__pWebViewer != null)
5629                 {
5630                         __pWebViewer->Resume();
5631                 }
5632                 if(__pAddressbar != null)
5633                 {
5634                         __pAddressbar->SendUserEvent(FORE_GROUND_APP_EVENT,NULL);
5635                 }
5636         }
5637 }
5638
5639 void
5640 MainForm::AddressBarCancelledClicked(const Addressbar& addBar)
5641 {
5642         AppLog("XYZ::MainForm::AddressBarCancelledClicked");
5643         result r = E_SUCCESS;
5644
5645         if (__pAddressbar)
5646                 __pAddressbar->SetShowState(false);
5647
5648         AppLog("akjshdasd 5");
5649         __pFooterPanel->SetShowState(true);
5650
5651         if(__pWebViewer)
5652                 __pWebViewer->SetFocus();
5653         else if(__pMostVisitedListView)
5654                 __pMostVisitedListView->SetFocus();
5655         else if(__pMultiWindowButton)
5656                 __pMultiWindowButton->SetFocus();
5657         else if(__pMoreButton)
5658                 __pMoreButton->SetFocus();
5659
5660         __pAddressbar->SetShowState(false);
5661
5662         RelayoutControls(false);
5663 }
5664
5665 void
5666 MainForm::OnFormMenuRequested (Tizen::Ui::Controls::Form &source)
5667 {
5668         AppLog("MainForm::OnFormMenuRequested called");
5669         InitOptionMenu();
5670         if (__pWindowInfo != NULL && __pWindowInfo->pageUrl != NULL && __pWebViewer && __pWebViewer->GetShowState() == true)
5671         {
5672                 int bookmarkCount=0;
5673                 bool exist = false;
5674                 String url=L"";
5675                 url=__pWindowInfo->pageUrl;
5676                 AppLog("MainForm::OnFormMenuRequested url %ls",url.GetPointer());
5677                 result r = E_SUCCESS;
5678                 Bitmap* pBitmap = null;
5679                 String lastChar = L"";
5680 //              if(url.SubString(url.GetLength()-1,lastChar));
5681 //              if(lastChar == L"/")
5682 //              {
5683 //                      bool exist1 = false;
5684 //                      bool exist2 = false;
5685 //                      r=BookmarkPresentationModel::GetInstance()->DoesBookmarkExist(url,exist1);
5686 //                      url.SubString(0,url.GetLength() - 1,url);
5687 //                      r=BookmarkPresentationModel::GetInstance()->DoesBookmarkExist(url,exist2);
5688 //                      exist = exist1 | exist2;
5689 //              }
5690 //              else
5691 //              {
5692                         r=BookmarkPresentationModel::GetInstance()->DoesBookmarkExist(url,exist);
5693                         if (IsFailed(r))
5694                         {
5695                                 AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED failed");
5696                                 return;
5697                         }
5698 //              }
5699                 if ( exist == true)
5700                 {
5701                         pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ICON_BOOKMARK_ON_TEMP);
5702                 }
5703                 else
5704                 {
5705                         pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ICON_BOOKMARK_OFF_TEMP);
5706                 }
5707                 AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED 3");
5708
5709                 if (__pOptionMenu->GetItemCount() == 9)
5710                 {
5711                         r = __pOptionMenu->SetItemAt(1,CommonUtil::GetString(L"IDS_BR_OPT_ADDTOBOOKMARKS"), IDA_ADDTOBOOKMARK_CLICKED,*pBitmap);
5712                 }
5713                 else
5714                 {
5715                         r = __pOptionMenu->InsertItemAt(1,CommonUtil::GetString(L"IDS_BR_OPT_ADDTOBOOKMARKS"), IDA_ADDTOBOOKMARK_CLICKED,*pBitmap);
5716                 }
5717
5718                 if (IsFailed(r))
5719                 {
5720                         AppLogException("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED Add to Bookmark failed with %s", GetErrorMessage(r));
5721                         delete pBitmap;
5722                         return ;
5723                 }
5724                 AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED 4");
5725                 if (__pOptionMenu->GetItemCount() != 9)
5726                 {
5727                         __pOptionMenu->InsertItemAt(1,CommonUtil::GetString(L"IDS_BR_OPT_ADDTOBOOKMARKS"), IDA_ADDTOBOOKMARK_CLICKED);
5728                         __pOptionMenu->InsertItemAt(2,CommonUtil::GetString(L"IDS_BR_BODY_PRINT"), IDA_PRINT_CLICKED);
5729 //                              __pOptionMenu->InsertItemAt(2,L"Add to Home"/*CommonUtil::GetString(L"IDS_BR_OPT_SHARE")*/, IDA_ADD_TO_HOME_CLICKED);
5730                         __pOptionMenu->InsertItemAt(3,CommonUtil::GetString(L"IDS_BR_OPT_SHARE"), IDA_SHARE_CLICKED);
5731                         __pOptionMenu->InsertItemAt(4,CommonUtil::GetString(L"IDS_BR_OPT_FIND_ON_PAGE_ABB"), IDA_FINDONPAGE_CLICKED);
5732                         __pOptionMenu->SetMaxVisibleItemsCount(6);
5733                 }
5734                 if( GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE)
5735                 {
5736                         AppLog(" Orientation landscape");
5737                         __pOptionMenu->SetMaxVisibleItemsCount(5);
5738                 }
5739                 else
5740                 {
5741                         AppLog(" Orientation potrait");
5742                         __pOptionMenu->SetMaxVisibleItemsCount(6);
5743                 }
5744
5745                 AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED 5");
5746                 delete pBitmap;
5747         }
5748         AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED end");
5749         __pOptionMenu->SetShowState(true);
5750         __pOptionMenu->Invalidate(true);
5751         __pOptionMenu->Show();
5752
5753 }