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