HW Key Changes. Removal of unsupported and deprecated API's. NABI issue fix
[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         AppLog("MainForm::OnSceneActivatedN called");
2578         String* pSelectedScene = NULL;
2579         Object* pValue = NULL;
2580         String* pUrl = null;
2581         MultipleWindowPresentationModel::GetInstance()->GetValue(SELECTED_SCENE_ID, &pValue);
2582         pSelectedScene = (String*) pValue;
2583
2584         if (pSelectedScene != null)
2585         {
2586                 delete pSelectedScene;
2587         }
2588         MultipleWindowPresentationModel::GetInstance()->SetValue(SELECTED_SCENE_ID, null);
2589         String* selectedSceneID = new(std::nothrow) String(currentSceneId);
2590         AppLogDebug("current scene id is %ls", currentSceneId.GetPointer());
2591         AppLogDebug("selected scene id is %ls", currentSceneId.GetPointer());
2592
2593         // setting the current scene ID
2594         MultipleWindowPresentationModel::GetInstance()->SetCurrentSceneID(currentSceneId);
2595
2596         MultipleWindowPresentationModel::GetInstance()->SetValue(SELECTED_SCENE_ID, (Object*) selectedSceneID);
2597
2598         if(pArgs != null && pArgs->GetCount() > 0 && pArgs->GetCount() == 2)
2599         {
2600                 __pWindowInfo = dynamic_cast< WindowInfo* >(pArgs->GetAt(0));
2601                 if(__pWindowInfo == null)
2602                         return;
2603                 //              if(__pWindowInfo == null)
2604                 {
2605                         pUrl = dynamic_cast< String* >(pArgs->GetAt(1));
2606                 }
2607         }
2608         else if ( pArgs != null && pArgs->GetCount() == 1)
2609         {
2610                 __pWindowInfo = dynamic_cast< WindowInfo* >(pArgs->GetAt(0));
2611         }
2612
2613         InitFooter();
2614         InitAddressbar();
2615
2616         __pFooterPanel->SetBounds(0, GetClientAreaBounds().height - __pFooterPanel->GetHeight(), GetClientAreaBounds().width, __pFooterPanel->GetHeight());
2617
2618         // hiding the address bar
2619         //      __pAddressbar->SetBounds(__pAddressbar->GetX(), __pAddressbar->GetY() - __pAddressbar->GetHeight(), __pAddressbar->GetWidth(), __pAddressbar->GetHeight());
2620         __pAddressbar->SetShowState(false);
2621 //      if(__pWebViewer != null)
2622 //      {
2623 //              __pWebViewer->Resume();
2624 //      }
2625
2626         if(pUrl != null && pUrl->GetLength() > 0)
2627         {
2628                 LoadUrl(*pUrl);
2629         }
2630         else if(__pWindowInfo != null)
2631         {
2632                 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)
2633                 {
2634                         LoadUrl(__pWindowInfo->pageUrl);
2635                 }
2636                 else if (__pWindowInfo->isJavascriptInitiated == true)
2637                 {
2638                         AppLog("Called");
2639                         InitWebControl();
2640                         __pWindowInfo->pCurrentWeb = __pWebViewer;
2641                 }
2642         }
2643
2644         String homePage = SettingPresentationModel::GetInstance()->GetHomepage();
2645         AppLog("Homepage Value in Onsceneactivated is %ls",homePage.GetPointer());
2646         if(homePage.CompareTo((L"IDS_BR_BODY_MOST_VISITED_SITES")) == 0)
2647         {
2648                 InitMostVisitedSitesView(GetOrientationStatus());
2649         }
2650         else if (homePage.CompareTo((L"IDS_BR_BODY_BLANK_PAGE")) == 0)
2651         {
2652                 if(__pMostVisitedListView != null)
2653                 {
2654                         __pMostVisitedListView->SetShowState(false);
2655                 }
2656         }
2657
2658         if (__pAddressbar != null && pArgs != null && (previousSceneId == IDSCN_BOOKMARK_VIEW || previousSceneId == IDSCN_HISTORY_LIST))
2659         {
2660                 String* pBookmarkUrl = dynamic_cast< String* >(pArgs->GetAt(0));
2661
2662                 if (pBookmarkUrl == null)
2663                         return;
2664                 AppLogDebug("bookmarkUrl = %ls",pBookmarkUrl->GetPointer());
2665                 //__pAddressbar->SetUrl(*pBookmarkUrl);
2666                 SetUrl(*pBookmarkUrl);
2667
2668                 if (__pWebViewer != null && homePage.CompareTo((L"IDS_BR_BODY_BLANK_PAGE")) != 0)
2669                         __pWebViewer->LoadUrl(*pBookmarkUrl);
2670                 delete pBookmarkUrl;
2671         }
2672
2673         bool isPrivateBrowsing = SettingPresentationModel::GetInstance()->GetPrivateOn();
2674         Bitmap* pBitmap = null;
2675         if (isPrivateBrowsing == true)
2676         {
2677                 pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_BUTTON_ON);
2678
2679                 if (__pWebViewer != null)
2680                 {
2681                         __pWebViewer->SetPrivateBrowsingEnabled(true);
2682                 }
2683
2684                 if (__pAddressbar != null)
2685                 {
2686                         //      __pAddressbar->UpdateFaviconBitmap(true);
2687                 }
2688
2689         }
2690         else
2691         {
2692                 pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_BUTTON_OFF);
2693
2694                 if (__pWebViewer != null)
2695                 {
2696                         __pWebViewer->SetPrivateBrowsingEnabled(false);
2697                 }
2698
2699                 if (__pAddressbar != null)
2700                 {
2701                         //      __pAddressbar->UpdateFaviconBitmap(false);
2702                 }
2703         }
2704
2705         if (__pOptionMenu != null && __pOptionMenu->GetItemCount() != 9)
2706         {
2707                 __pOptionMenu->SetItemAt(1,CommonUtil::GetString(L"IDS_BR_BODY_PRIVACY_AND_SECURITY_ABB"),IDA_PRIVATEON_CLICKED,*pBitmap);
2708         }
2709         else if (__pOptionMenu != null )
2710         {
2711                 __pOptionMenu->SetItemAt(5,CommonUtil::GetString(L"IDS_BR_BODY_PRIVACY_AND_SECURITY_ABB"),IDA_PRIVATEON_CLICKED,*pBitmap);
2712         }
2713
2714         if (pBitmap != null)
2715         {
2716                 delete pBitmap;
2717         }
2718
2719         AppLog("ABC: OnSceneActivatedN started exit");
2720
2721 }
2722
2723 void
2724 MainForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
2725                 const Tizen::Ui::Scenes::SceneId& nextSceneId)
2726 {
2727         Canvas* pWebCanvas = null;
2728         if (__pWebViewer != null)
2729         {
2730                 pWebCanvas = __pWebViewer->GetCanvasN();
2731
2732         }
2733         if (pWebCanvas == null)
2734         {
2735                 return;
2736         }
2737         if (__pWindowInfo != null)
2738         {
2739                 if (__pWindowInfo->pWebCanvasBitmap != null)
2740                 {
2741                         delete __pWindowInfo->pWebCanvasBitmap;
2742                 }
2743                 __pWindowInfo->pWebCanvasBitmap = new(std::nothrow) Bitmap();
2744                 result r = __pWindowInfo->pWebCanvasBitmap->Construct(*pWebCanvas,Rectangle(0,0,pWebCanvas->GetBounds().width,pWebCanvas->GetBounds().height));
2745                 AppLog("Bitmap Construction result %s",GetErrorMessage(r));
2746         }
2747         Bitmap* pBitmap = GetCapturedBitmapN();
2748         AppLog("Coming here");
2749         Canvas* pCanvas = new(std::nothrow) Canvas();
2750         pCanvas->Construct(GetClientAreaBounds());
2751         if(pBitmap != null)
2752         {
2753                 pCanvas->DrawBitmap(Point(0,0),*pBitmap);
2754                 delete pBitmap;
2755         }
2756         if(__pWebViewer != null && __pWindowInfo != null)
2757                 pCanvas->DrawBitmap(__pWebViewer->GetPosition(),*__pWindowInfo->pWebCanvasBitmap);
2758
2759         WindowInfo::pFormCanvasBitmap = new(std::nothrow) Bitmap();
2760         WindowInfo::pFormCanvasBitmap->Construct(*pCanvas,Rectangle(0,0,GetClientAreaBounds().width,GetClientAreaBounds().height - __pFooterPanel->GetHeight()));
2761         delete pCanvas;
2762         AppLog("Coming here");
2763 }
2764
2765 bool
2766 MainForm::OnHttpAuthenticationRequestedN(const Tizen::Base::String& host,
2767                 const Tizen::Base::String& realm,
2768                 const Tizen::Web::Controls::AuthenticationChallenge& authentication)
2769 {
2770         return false;
2771 }
2772
2773 void
2774 MainForm::OnHttpAuthenticationCanceled(void)
2775 {
2776 }
2777
2778 void
2779 MainForm::OnLoadingStarted(void)
2780 {
2781         AppLogDebug("MainForm::OnLoadingStarted entered");
2782         __isLoaded = true;
2783         if(__pAddressbar == NULL || __pWebViewer == null)
2784         {
2785                 return;
2786         }
2787
2788         // this is added in case if menu is opened and user load the page
2789         if(__pOptionMenu != null && __pOptionMenu->GetShowState() == true)
2790         {
2791                 __pOptionMenu->SetShowState(false);
2792                 __pOptionMenu->Invalidate(true);
2793         }
2794
2795
2796
2797         if(__pImageMenu != null && __pImageMenu->GetShowState() == true)
2798         {
2799                 __pImageMenu->SetShowState(false);
2800                 __pImageMenu->Invalidate(true);
2801         }
2802         String url = __pWebViewer->GetUrl();
2803         if(url.Contains(IDS_TIZEN_SERVICE))
2804         {
2805                 String appId;
2806                 String delim(L":;,");
2807
2808                 // Creates a StringTokenizer instance
2809                 StringTokenizer strTok(url, delim);
2810
2811                 int count = strTok.GetTokenCount();     // count == 4
2812
2813                 HashMap *pMap = new HashMap();
2814                 pMap->Construct();
2815                 String token;
2816                 String key;
2817                 String value;
2818                 while (strTok.HasMoreTokens())
2819                 {
2820                         AppLog("Token: %ls", token.GetPointer());
2821                         strTok.GetNextToken(token);         // Tizen, StringTokenizer, Sample, code
2822                         if(token.Contains(IDS_APPID))
2823                         {
2824                                 token.SubString(6, appId);
2825                                 AppLog("AppID:%ls", appId.GetPointer());
2826                         }
2827                         else if(token.Contains(IDS_KEY))
2828                         {
2829                                 token.SubString(4, key);
2830                                 AppLog("key:%ls", key.GetPointer());
2831                         }
2832                         else if(token.Contains(IDS_VALUE))
2833                         {
2834                                 token.SubString(6, value);
2835                                 AppLog("value:%ls", value.GetPointer());
2836                         }
2837                 }
2838                 pMap->Add(key, value);
2839
2840                 if(appId != "")
2841                 {
2842                         AppControl *pAppControl = null;
2843                         String operationId = L"http://tizen.org/appcontrol/operation/main";
2844                         pAppControl = dynamic_cast<AppControl*>(AppManager::FindAppControlN(appId, operationId));
2845                         if(pAppControl)
2846                         {
2847                                 AppLog("Starting AppControl");
2848                                 result r = pAppControl->Start(null, null, pMap, null);
2849                                 AppLog("Result of Start %s", GetErrorMessage(r));
2850                         }
2851                         else
2852                         {
2853                                 AppLogException("AppControl not found");
2854                         }
2855                         return;
2856                 }
2857         }
2858         if ( __pAddressbar != null && __pAddressbar->GetShowState() == true)
2859         {
2860                 __pAddressbar->SetShowState(false);
2861                 AddressBarCancelledClicked(*__pAddressbar);
2862                 __pAddressbar->Invalidate(true);
2863         }
2864         Bitmap* pBitmap = FaviconManager::GetInstance()->GetDefaultFaviconN();
2865         if(pBitmap != null)
2866         {
2867                 __pAddressbar->SetFaviconBitmap(*pBitmap);
2868         }
2869         delete pBitmap;
2870         if (__adressPanelPosition.y < (0 - __pAddressbar->GetHeight() + 12))
2871         {
2872                 // updating the address bar position with respect to web control
2873                 __adressPanelPosition.y = 0 - __pAddressbar->GetHeight() + 12; //-12 is for the progress label
2874                 __distanceMoved = 0;
2875                 MoveUiControls();
2876         }
2877
2878         //__pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING);
2879         SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING);
2880         if (__pWebViewer != null)
2881         {
2882                 AppLog("MainForm::OnLoadingStarted __pWebViewer->GetUrl() %ls",__pWebViewer->GetUrl().GetPointer());
2883                 //__pAddressbar->SetUrl(__pWebViewer->GetUrl());
2884                 SetUrl(__pWebViewer->GetUrl());
2885                 if (__pWindowInfo != NULL)
2886                 {
2887                         // resetting the page title to blank, it will be received in OnPageTitleReceived()
2888                         __pWindowInfo->pageTitle = L"";
2889                         __pWindowInfo->pageUrl = __pWebViewer->GetUrl();
2890                 }
2891                 __pAddressbar->Invalidate(true);
2892         }
2893
2894 }
2895
2896 void
2897 MainForm::OnLoadingCanceled(void)
2898 {
2899
2900 }
2901
2902
2903 void
2904 MainForm::OnKeypadWillOpen(Tizen::Ui::Control& source)
2905 {
2906         AppLog("XYZ::MainForm::OnKeypadWillOpen");
2907
2908 }
2909
2910 void
2911 MainForm::OnKeypadOpened(Tizen::Ui::Control& source)
2912 {
2913         AppLog("XYZ::MainForm::OnKeypadOpened");
2914         __pFooterPanel->SetShowState(false);
2915
2916 }
2917
2918 void
2919 MainForm::OnKeypadClosed(Tizen::Ui::Control& source)
2920 {
2921         AppLog("XYZ::MainForm::OnKeypadClosed");
2922         __pFooterPanel->SetShowState(true);
2923         RelayoutControls(true);
2924 }
2925
2926 void
2927 MainForm::OnKeypadBoundsChanged(Tizen::Ui::Control &source)
2928 {
2929         AppLog("XYZ::KeypadBoundsChanged");
2930         RelayoutControls(false);
2931 }
2932
2933 void
2934 MainForm::OnLoadingErrorOccurred(LoadingErrorType error,
2935                 const Tizen::Base::String& reason)
2936 {
2937         AppLogDebug("Error: %d, %ls", error, reason.GetPointer());
2938 }
2939
2940 void
2941 MainForm::OnLoadingCompleted(void)
2942 {
2943         AppLog("MainForm::OnLoadingCompleted start");
2944         DateTime date;
2945         result r = E_SUCCESS;
2946
2947         if (__pWebViewer == null)
2948         {
2949                 return;
2950         }
2951
2952         if (__pAddressbar == null)
2953         {
2954                 return;
2955         }
2956         if (__pWebViewer->CanGoForward())
2957         {
2958                 //__pAddressbar->SetForwardButtonEnabled(true);
2959                 SetForwardButtonEnabled(true);
2960         }
2961         else
2962         {
2963                 //__pAddressbar->SetForwardButtonEnabled(false);
2964                 SetForwardButtonEnabled(false);
2965         }
2966
2967         /*if (__pAddressbar->GetAddressbarMode() != ADDRESSBAR_MODE_EDIT)
2968         {
2969                 __pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
2970
2971                 //__pAddressbar->UpdateProgress(0);
2972                 UpdateProgress(0);
2973         }*/
2974
2975         if(GetAddressbarMode() != ADDRESSBAR_MODE_EDIT)
2976         {
2977                 SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
2978                 UpdateProgress(0);
2979         }
2980
2981         AppLog("PrivateBrowsing %d",__pWebViewer->IsPrivateBrowsingEnabled());
2982         bool isPrivateBrowsing = SettingPresentationModel::GetInstance()->GetPrivateOn();
2983         if (isPrivateBrowsing == false)
2984         {
2985                 if(__pHistory != null)
2986                 {
2987                         delete __pHistory;
2988                         __pHistory = null;
2989                 }
2990
2991                 __pHistory = new(std::nothrow) History;
2992                 HistoryPresentationModel::GetCurrentDateTime(date);
2993                 if (__pWindowInfo)
2994                 {
2995                         __pHistory->SetHistoryTitle(__pWindowInfo->pageTitle);
2996                         AppLogDebug("MainForm::OnLoadingCompleted pagetitle = %ls", __pWindowInfo->pageTitle.GetPointer());
2997
2998                         __pHistory->SetHistoryUrl(__pWindowInfo->pageUrl);
2999                         AppLogDebug("MainForm::OnLoadingCompleted pageUrl = %ls", __pWindowInfo->pageUrl.GetPointer());
3000                 }
3001                 __pHistory->SetVisitedTime(date);
3002
3003                 if (__pWebViewer != null)
3004                 {
3005                         AppLog("MainForm::OnLoadingCompleted setting the fav icon 0");
3006
3007                         Bitmap* pTempBitmap = __pWebViewer->GetFaviconN();
3008                         if (pTempBitmap != null)
3009                         {
3010                                 AppLog("MainForm::OnLoadingCompleted setting the fav icon 1");
3011                                 __pHistory->SetFavIconBitmap(*pTempBitmap);
3012                         }
3013
3014                         AppLog("MainForm::OnLoadingCompleted setting the fav icon 2");
3015                 }
3016
3017                 Canvas* pCanvas = __pWebViewer->GetCanvasN();
3018                 Bitmap* pBitmap = new(std::nothrow) Bitmap();
3019                 if ( pCanvas != null &&  pCanvas != null && pBitmap != null)
3020                 {
3021                         pBitmap->Construct(*pCanvas, pCanvas->GetBounds());
3022                         pBitmap->Scale(Dimension(pBitmap->GetWidth()/4, pBitmap->GetHeight()/4));
3023                         __pHistory->SetThumbnail(pBitmap);
3024                 }
3025                 Bitmap *pFavIcon = __pWebViewer->GetFaviconN();
3026                 if (pFavIcon)
3027                 {
3028                         __pHistory->SetFavIconBitmap(*pFavIcon);
3029                         delete pFavIcon;
3030                 }
3031
3032                 HistoryPresentationModel::GetInstance()->SaveTempHistory(*__pHistory);
3033                 //delete pHistory;
3034         }
3035         else
3036         {
3037                 return;
3038         }
3039 //      if (__pWindowInfo && __pWindowInfo->faviconUrl == "")
3040         {
3041                 // temperary fixed (webpage can be not loaded)
3042                 UpdateFavicon();
3043         }
3044
3045         bool isReaderEnabled = SettingPresentationModel::GetInstance()->IsRunReaderEnabled();
3046         if (isReaderEnabled == true)
3047         {
3048                 if (__pReaderData)
3049                 {
3050                         delete __pReaderData;
3051                         __pReaderData = null;
3052                 }
3053                 String filePath = Tizen::App::UiApp::GetInstance()->GetAppRootPath();
3054                 filePath.Append(L"data/reader.js");
3055                 File file;
3056                 char buffer[10];
3057                 char buffer2[5];
3058                 int i;
3059                 int readCnt;
3060                 result r = E_SUCCESS;
3061                 FileAttributes attr;
3062
3063                 File::GetAttributes(filePath,attr);
3064                 // Creates file
3065                 r = file.Construct(filePath, L"r+");
3066                 if (IsFailed(r))
3067                 {
3068                         AppLogDebug("File construct failed with %s", GetErrorMessage(r));
3069                         return;
3070                 }
3071                 char* pScript = new(std::nothrow) char[attr.GetFileSize()+1];
3072                 if(pScript == null)
3073                 {
3074                         AppLogDebug("Memory allocation for file failed %s", GetErrorMessage(r));
3075                         return;
3076                 }
3077 //              file.Read(pScript,attr.GetFileSize());
3078 //
3079 //              AppLogDebug("scipt length %d",strlen(pScript));
3080                 String strScript = L"";
3081 //              strScript.Append(pScript);
3082 //              for(int i=0; i<25; i++)
3083                 {
3084                         file.Read(pScript,attr.GetFileSize());
3085 //                      AppLog("xyzz tell %d",file.Tell());
3086 //                      r = strScript.Append(pScript);
3087 //                      AppLog("xyzz append result %s",GetErrorMessage(r));
3088 //                      AppLog("xyzz strScript length %d",strScript.GetLength());
3089                 }
3090 //              AppLog("xyzz final strScript length %d",strScript.GetLength());
3091
3092                 __pReaderData = __pWebViewer->EvaluateJavascriptN(pScript);
3093                 if (__pReaderData == null)
3094                 {
3095                         AppLog("MainScene::data is null Error :%s",GetErrorMessage(GetLastResult()));
3096                         __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>");
3097 //                      return;
3098                 }
3099                 AppLogDebug("evaluateJavascript result %s , __pReaderData %ls",GetErrorMessage(GetLastResult()),__pReaderData->GetPointer());
3100                 if (__pReaderData->CompareTo(L"undefined") != 0 && __pReaderData->CompareTo(L"") != 0)
3101                 {
3102                         //__pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_READER);
3103                         SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_READER);
3104                 }
3105                 delete[] pScript;
3106         }
3107
3108
3109         AppLog("MainForm::OnLoadingCompleted done");
3110 }
3111
3112 void
3113 MainForm::OnEstimatedProgress(int progress)
3114 {
3115         AppLogDebug("MainForm::OnEstimatedProgress entered");
3116         if (progress < DEFAULT_PROGRESS_PERCENTAGE)
3117                 progress = DEFAULT_PROGRESS_PERCENTAGE;
3118         //if(__pAddressbar)
3119         //      __pAddressbar->UpdateProgress(progress);
3120         UpdateProgress(progress);
3121 }
3122
3123 void MainForm::OnFaviconReceived(const Tizen::Graphics::Bitmap& favicon)
3124 {
3125         AppLog("MainForm::OnFaviconReceived");
3126         if (__pWebViewer != null && __pHistory != null && __pWindowInfo != null && (__pWindowInfo->pageUrl.CompareTo(__pHistory->GetHistoryUrl()) == 0))
3127         {
3128                 Bitmap* favIcon = __pWebViewer->GetFaviconN();
3129                 if(favIcon != null)
3130                 {
3131                         HistoryPresentationModel::GetInstance()->UpdateHistoryFavIcon(*__pHistory, *favIcon);
3132                         delete favIcon;
3133                 }
3134         }
3135 }
3136
3137 void
3138 MainForm::OnUrlValueChanged(Addressbar&)
3139 {
3140         Invalidate(true);
3141 }
3142
3143 void
3144 MainForm::OnUrlSubmitted(Addressbar& addBar)
3145 {
3146         AppLog("MainForm::OnUrlSubmitted");
3147         String url = addBar.GetUrl();
3148         AppLog("MainForm::OnUrlSubmitted url is %ls", url.GetPointer());
3149
3150         if(__pFooterUrlField)
3151                 __pFooterUrlField->SetCursorPosition(__pFooterUrlField->GetTextLength());
3152         AddressBarCancelledClicked(*__pAddressbar);
3153         LoadUrl(url);
3154 }
3155
3156 void
3157 MainForm::LoadUrl(String& url)
3158 {
3159         url.Trim();
3160         String encodedUrl;
3161 //      UrlEncoder::Encode(url, L"UTF-8", encodedUrl);
3162         AppLogDebug("MainForm::LoadUrl enter");
3163
3164         if (__pWebViewer != null)
3165         {
3166                 __pWebViewer->SetShowState(true);
3167                 __pWebViewer->Invalidate(true);
3168         }
3169
3170         if (url.CompareTo(L"") == 0)
3171         {
3172                 return;
3173         }
3174         if(__pFooterPanel != null)
3175         {
3176                 __pFooterPanel->SetShowState(true);
3177                 __pFooterPanel->Invalidate(true);
3178         }
3179         InitWebControl();
3180
3181         bool ret = false;
3182         bool flag = false;
3183
3184         String firstPattern(L"((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)");
3185         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)
3186
3187         RegularExpression firstRegex;
3188         RegularExpression secondRegex;
3189
3190         firstRegex.Construct(firstPattern, REGEX_CASELESS);
3191         secondRegex.Construct(secondPattern, REGEX_CASELESS);
3192
3193         // Match
3194         ret = firstRegex.Match(url, false); // This returns true value
3195         flag = secondRegex.Match(url, false);  // Checks whether URL typed is of type  abc.com (i.e without protocol in front of it)
3196
3197         if (ret == true && __pWebViewer != null)
3198         {
3199                 SetUrl(url);
3200                 __pWebViewer->LoadUrl(url);
3201         }
3202         else if(__pWebViewer != null)
3203         {
3204                 String tempUrl = L"http://";
3205                 tempUrl.Append(url);
3206
3207                 if (flag == true)
3208                 {
3209                         __pWebViewer->LoadUrl(tempUrl);
3210                 }
3211                 else
3212                 {
3213                                 UrlEncoder::Encode(url, L"UTF-8", encodedUrl);
3214                         __pWebViewer->LoadUrl(SettingPresentationModel::GetInstance()->GetSearchUrl(encodedUrl));
3215                 }
3216         }
3217         if (__pAddressbar != null)
3218         {
3219                 //__pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING);
3220                 SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING);
3221         }
3222
3223         AppLogDebug("MainForm::LoadUrl exit");
3224
3225         return;
3226
3227 }
3228
3229 void
3230 MainForm::OnStopClicked(Addressbar& addBar)
3231 {
3232         AppLogDebug("MainForm::OnStopClicked called");
3233         if (__pWebViewer)
3234         {
3235                 //__pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
3236                 SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
3237                 __pWebViewer->StopLoading();
3238                 RequestRedraw(true);
3239         }
3240 }
3241
3242 void
3243 MainForm::OnBackClicked(/*const Addressbar& addBar*/)
3244 {
3245 //      AppLog("MainForm::OnBackClicked");
3246         result r = E_FAILURE;
3247
3248         if (__pWebViewer && __pWebViewer->CanGoBack())
3249         {
3250                 __pWebViewer->GoBack();
3251         }
3252         else if(__pWindowInfo && __pWindowInfo->isJavascriptInitiated == false)
3253         {
3254                 UiApp* pApp = null;
3255                 pApp = UiApp::GetInstance();
3256                 if (pApp != null)
3257                 {
3258                         r = pApp->Terminate();
3259                         if (IsFailed(r))
3260                         {
3261                                 AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
3262                                 return;
3263                         }
3264                 }
3265         }
3266         else
3267         {
3268                 UiApp* pApp = null;
3269                 WindowInfo* pWindowInfo = null;
3270                 int totalCount = 0;
3271                 SceneManager* pSceneManager = SceneManager::GetInstance();
3272                 if (pSceneManager == null)
3273                 {
3274                         return;
3275                 }
3276                 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
3277                 if (pAllWindowList == NULL)
3278                 {
3279                         pApp = UiApp::GetInstance();
3280                         if (pApp != null)
3281                         {
3282                                 r = pApp->Terminate();
3283                                 if (IsFailed(r))
3284                                 {
3285                                         AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
3286                                         return;
3287                                 }
3288                         }
3289                 }
3290                 if (pAllWindowList != null)
3291                 {
3292                         totalCount = pAllWindowList->GetCount();
3293                 }
3294                 for (int count = 0; count < totalCount; count++)
3295                 {
3296                         pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count));
3297                         if (pWindowInfo == null)
3298                         {
3299                                 pApp = UiApp::GetInstance();
3300                                 if (pApp != null)
3301                                 {
3302                                         r = pApp->Terminate();
3303                                         if (IsFailed(r))
3304                                         {
3305                                                 AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
3306                                                 return;
3307                                         }
3308                                 }
3309                         }
3310                         if (pSceneManager != null && pWindowInfo != null && pSceneManager->GetCurrentSceneId() == pWindowInfo->sceneID && pWindowInfo->isJavascriptInitiated == true)
3311                         {
3312                                 r = SceneRegister::DestroyAndUnRegisterScene(pWindowInfo->sceneID);
3313                                 if (IsFailed(r))
3314                                 {
3315                                         AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
3316                                         return;
3317                                 }
3318                                 r = pAllWindowList->RemoveAt(count, true);
3319                                 __pWindowInfo = null;
3320                                 if (IsFailed(r))
3321                                 {
3322                                         AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
3323                                         return;
3324                                 }
3325                                 if(count > 0)
3326                                 {
3327                                         pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count - 1));
3328                                 }
3329                                 else if(pAllWindowList->GetCount() > 0)
3330                                 {
3331                                         pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(pAllWindowList->GetCount() - 1));
3332                                 }
3333                                 else
3334                                 {
3335                                         pApp = UiApp::GetInstance();
3336                                         if (pApp != null)
3337                                         {
3338                                                 r = pApp->Terminate();
3339                                                 return;
3340                                         }
3341
3342                                 }
3343                                 if (pWindowInfo == null)
3344                                 {
3345                                         pApp = UiApp::GetInstance();
3346                                         if (pApp != null)
3347                                         {
3348                                                 r = pApp->Terminate();
3349                                                 return;
3350                                         }
3351                                 }
3352                                 else
3353                                 {
3354                                         r = pSceneManager->GoBackward(BackwardSceneTransition(pWindowInfo->sceneID ,SCENE_TRANSITION_ANIMATION_TYPE_NONE));
3355                                         if (IsFailed(r))
3356                                         {
3357                                                 AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
3358                                                 return;
3359                                         }
3360                                 }
3361                                 break;
3362                         }
3363
3364                 }
3365
3366         }
3367
3368 }
3369
3370 void
3371 MainForm::OnForwardClicked(/*const Addressbar& addBar*/)
3372 {
3373         AppLog("MainForm::OnForwardClicked");
3374         if (__pWebViewer == null)
3375                 return;
3376
3377         if (__pWebViewer->CanGoForward())
3378         {
3379                 __pWebViewer->GoForward();
3380         }
3381 }
3382
3383 void
3384 MainForm::OnAddressBarFocusGained(const Addressbar& addBar)
3385 {
3386         AppLog("XYZ::MainForm::OnAddressBarFocusGained");
3387         if(__pFooterPanel != null)
3388         {
3389                 __pFooterPanel->SetShowState(false);
3390         }
3391
3392         if (__pAddressbar != null && __pAddressbar->GetShowState() == false)
3393         {
3394                 __pAddressbar->SetShowState(true);
3395                 __pAddressbar->SetBounds(Rectangle(0,0,GetClientAreaBounds().width,__pAddressbar->GetHeight()));
3396         }
3397
3398         RelayoutControls(false);
3399 }
3400
3401 void
3402 MainForm::OnAddressBarFocusLost(const Addressbar& addBar, bool addressbarKeyPadState)
3403 {
3404         AppLog("XYZ::MainForm::OnAddressBarFocusLost");
3405
3406         int Height = GetClientAreaBounds().height;
3407         AppLog("MainForm::OnAddressBarFocusLost height is %d",Height);
3408
3409         if(__pAddressbar)
3410                 __pAddressbar->SetShowState(false);
3411
3412                 if (__pFooterPanel != null && addressbarKeyPadState == false)
3413                 {
3414                         AppLog("akjshdasd 3");
3415                         __pFooterPanel->SetShowState(true);
3416                 }
3417
3418         RelayoutControls(false);
3419 }
3420
3421 void
3422 MainForm::OnAddressCancelledClicked(const Addressbar& addBar)
3423 {
3424         AddressBarCancelledClicked(addBar);
3425 }
3426
3427 void
3428 MainForm::OnAddressBarModeChanged(/*const Addressbar& addBar*/)
3429 {
3430         __prevAddressBarMode = __curAddressBarMode;
3431
3432         if (__pAddressbar != null)
3433         {
3434                 __curAddressBarMode = GetAddressbarMode();
3435         }
3436
3437         if (__curAddressBarMode == ADDRESSBAR_MODE_EDIT)
3438         {
3439                 __adressPanelPosition.y = 0;
3440                 if (__pAddressbar != null)
3441                 {
3442                         __webControlPosition.y = __pAddressbar->GetHeight() - 12;
3443                         __pAddressbar->SetBounds(Rectangle(0,0,GetClientAreaBounds().width,__pAddressbar->GetHeight()));
3444                         __pAddressbar->Invalidate(true);
3445                 }
3446                 if (__pWebViewer != null)
3447                 {
3448                         __pWebViewer->StopLoading();
3449                 }
3450         }
3451         else if(__curAddressBarMode == ADDRESSBAR_MODE_LOADING)
3452         {
3453                 __adressPanelPosition.y = 0;
3454                 if (__pAddressbar != null)
3455                 {
3456                         __webControlPosition.y = 0;
3457                         __pAddressbar->SetBounds(Rectangle(0, __pAddressbar->GetY() - __pAddressbar->GetHeight(), GetClientAreaBounds().width, __pAddressbar->GetHeight()));
3458                         __pAddressbar->Invalidate(true);
3459                 }
3460         }
3461 }
3462
3463 void
3464 MainForm::OnClipboardClosed(const Addressbar& addBar)
3465 {
3466         AppLog("XYZ::MainForm::OnClipboardClosed");
3467         RelayoutControls(false);
3468 }
3469
3470 void
3471 MainForm::OnAddressBarKeypadClosed(const Addressbar& addBar, bool footerState)
3472 {
3473         AppLog("XYZ::MainForm::OnAddressBarKeypadClosed");
3474         if (__pFooterPanel && __pAddressbar->GetShowState() == false)
3475         {
3476                 AppLog("akjshdasd 3");
3477                 __pFooterPanel->SetShowState(true);
3478         }
3479
3480         RelayoutControls(false,footerState);
3481 }
3482
3483 void
3484 MainForm::OnAddressBarKeypadOpened(const Addressbar& addBar)
3485 {
3486         AppLog("XYZ::MainForm::OnAddressBarKeypadOpened");
3487         RelayoutControls(false);
3488 }
3489
3490 void
3491 MainForm::OnAddressBarKeypadWillOpen(const Addressbar& addBar)
3492 {
3493         __pFooterPanel->SetShowState(false);
3494 }
3495
3496 void
3497 MainForm::OnAddressBarKeypadBoundsChanged(const Addressbar& addBar)
3498 {
3499         AppLog("XYZ::MainForm::OnAddressBarKeypadBoundsChanged");
3500         RelayoutControls(false);
3501 }
3502
3503 void
3504 MainForm::OnPageTitleReceived(const Tizen::Base::String& title)
3505 {
3506         AppLog("MainForm::OnPageTitleReceived %ls",title.GetPointer());
3507         if (__pWindowInfo)
3508         {
3509                 __pWindowInfo->pageTitle = title;
3510                 if (__pWebViewer != null)
3511                 {
3512                         __pWindowInfo->pageUrl = __pWebViewer->GetUrl();
3513                 }
3514         }
3515         if (__pAddressbar != null && __pWebViewer != null)
3516         {
3517                 SetUrl(__pWebViewer->GetUrl());
3518                 __pAddressbar->Invalidate(true);
3519         }
3520 }
3521
3522 void
3523 MainForm::UpdateFavicon(void)
3524 {
3525         bool urlImageType = false;
3526         String *tempPath = null;
3527         if(__pWebViewer)
3528                 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();");
3529         Bitmap* pBitmap = null;
3530
3531         if (tempPath && tempPath->GetLength() > 0 && tempPath->CompareTo(L"undefined") != 0)
3532         {
3533                 if (__pWindowInfo != null)
3534                 {
3535                         Uri url;
3536                         url.SetUri(*tempPath);
3537                         if (url.GetHost().GetLength() == 0)
3538                         {
3539                                 Uri webUrl;
3540                                 webUrl.SetUri(__pWebViewer->GetUrl());
3541                                 result r = url.SetHost(webUrl.GetHost());
3542                                 if(IsFailed(r))
3543                                 {
3544                                         delete tempPath;
3545                                         return;
3546                                 }
3547                         }
3548                         if (url.GetScheme().GetLength() == 0)
3549                         {
3550                                 Uri webUrl;
3551                                 webUrl.SetUri(__pWebViewer->GetUrl());
3552                                 url.SetScheme(webUrl.GetScheme());
3553                         }
3554                         __pWindowInfo->faviconUrl = url.ToString();
3555
3556                         pBitmap = __pWebViewer->GetFaviconN();
3557
3558                         if (pBitmap != null)
3559                         {
3560                                 if (__pWindowInfo->pFavicon != NULL)
3561                                 {
3562                                         __pWindowInfo->pFavicon = null;
3563                                 }
3564                                 __pWindowInfo->pFavicon = new(std::nothrow) Bitmap();
3565                                 __pWindowInfo->pFavicon->Construct(*pBitmap,Rectangle(0,0,pBitmap->GetWidth(),pBitmap->GetHeight()));
3566
3567                                 __pAddressbar->SetFaviconBitmap(*__pWindowInfo->pFavicon);
3568
3569                                 FaviconManager::GetInstance()->SaveFavicon(*__pWindowInfo->pFavicon, __pWindowInfo->faviconUrl);
3570                         }
3571                         else if(__pWindowInfo->pFavicon != null)
3572                         {
3573                                 __pAddressbar->SetFaviconBitmap(*__pWindowInfo->pFavicon);
3574                         }
3575                         else
3576                         {
3577                                 Bitmap *pDefaultBmp = FaviconManager::GetInstance()->GetDefaultFaviconN();
3578                                 if(pDefaultBmp != null)
3579                                 {
3580                                         __pAddressbar->SetFaviconBitmap(*pDefaultBmp);
3581                                 }
3582                         }
3583                 }
3584                 delete tempPath;
3585         }
3586         else
3587         {
3588                 // do not remove
3589                 if(tempPath != null)
3590                 {
3591                         delete tempPath;
3592                 }
3593                 AppLogDebug("Error occured: %s", GetErrorMessage(GetLastResult()));
3594         }
3595
3596 }
3597
3598
3599 bool
3600 MainForm::OnLoadingRequested(const Tizen::Base::String& url,
3601                 Tizen::Web::Controls::WebNavigationType type)
3602 {
3603         // when load new page if find word panel is open its show state is false
3604         if(__pFindWordControl && __pFindWordControl->GetShowState() == true)
3605         {
3606                 __currentSearchStr = L"";
3607                 __currentWordIndex = 0;
3608                 __maxOccurrances = 0;
3609                 __pFindWordEditField->SetText(L"");
3610                 __pFindWordNext->SetEnabled(false);
3611                 __pFindWordPrev->SetEnabled(false);
3612                 __pFindWordCountLabel->SetText(L"0/0");
3613                 __pFindWordControl->SetShowState(false);
3614                 __pFindWordEditField->HideKeypad();
3615                 RelayoutControls(false);
3616         }
3617
3618
3619
3620         __pFooterPanel->Invalidate(true);
3621
3622         Uri uriInfo;
3623         uriInfo.SetUri(url);
3624
3625         if(url.Contains(IDS_TIZEN_SERVICE))
3626         {
3627                 String appId;
3628                 String delim(L":;,");
3629
3630                 // Creates a StringTokenizer instance
3631                 StringTokenizer strTok(url, delim);
3632
3633                 int count = strTok.GetTokenCount();     // count == 4
3634
3635                 HashMap *pMap = new HashMap();
3636                 pMap->Construct();
3637
3638                 String token;
3639                 String key;
3640                 String value;
3641                 while (strTok.HasMoreTokens())
3642                 {
3643                         AppLog("Token: %ls", token.GetPointer());
3644                         strTok.GetNextToken(token);         // Tizen, StringTokenizer, Sample, code
3645                         if(token.Contains(IDS_APPID))
3646                         {
3647                                 token.SubString(6, appId);
3648                                 AppLog("AppID:%ls", appId.GetPointer());
3649                         }
3650                         else if(token.Contains(IDS_KEY))
3651                         {
3652                                 token.SubString(4, key);
3653                                 AppLog("key:%ls", key.GetPointer());
3654                         }
3655                         else if(token.Contains(IDS_VALUE))
3656                         {
3657                                 token.SubString(6, value);
3658                                 AppLog("value:%ls", value.GetPointer());
3659                         }
3660                 }
3661                 pMap->Add(key, value);
3662
3663                 if(appId != "")
3664                 {
3665                         AppControl *pAppControl = null;
3666                         String operationId = L"http://tizen.org/appcontrol/operation/main";
3667                         pAppControl = dynamic_cast<AppControl*>(AppManager::FindAppControlN(appId, operationId));
3668                         if(pAppControl)
3669                         {
3670                                 result r = pAppControl->Start(null, null, pMap, null);
3671                         }
3672                         else
3673                         {
3674                                 AppLogException("AppControl not found");
3675                         }
3676                         return true;
3677                 }
3678         }
3679
3680         return false;
3681 }
3682
3683 DecisionPolicy
3684 MainForm::OnWebDataReceived(const Tizen::Base::String& mime,
3685                 const Tizen::Net::Http::HttpHeader& httpHeader)
3686 {
3687         return Tizen::Web::Controls::WEB_DECISION_CONTINUE;
3688 }
3689
3690
3691 void
3692 MainForm::OnWebPageBlockSelected(Web& source, FloatPoint& startPoint, FloatPoint& endPoint)
3693 {
3694         AppLog("MainForm::OnWebPageBlockSelected");
3695         if (__pHitElementResult != null)
3696         {
3697                 delete __pHitElementResult;
3698                 __pHitElementResult = null;
3699         }
3700
3701         if (__pWebViewer != null)
3702         {
3703                 AppLog("MainForm::OnWebPageBlockSelected web not null");
3704                 __pHitElementResult = __pWebViewer->GetElementByPointN(startPoint);
3705
3706                 if(GetLastResult() == E_INVALID_ARG)
3707                 {
3708                         AppLog("datafirst startpoint error %s",GetErrorMessage(GetLastResult()));
3709                         __pHitElementResult = __pWebViewer->GetElementByPointN(endPoint);
3710                         if(GetLastResult() == E_INVALID_ARG)
3711                         {
3712                                 __pHitElementResult = __pWebViewer->GetElementByPointN(__longPressPoint);
3713                         }
3714                         AppLog("datafirst endpoint error %s",GetErrorMessage(GetLastResult()));
3715                 }
3716         }
3717
3718         if (__pHitElementResult == null)
3719         {
3720                 return;
3721         }
3722
3723         if (__pHitElementResult->HasImage() != true)
3724         {
3725                 String tagName = __pHitElementResult->GetTagName();
3726                 String type = __pHitElementResult->GetAttributeValue("type");
3727
3728
3729                 AppLog("TagName %ls",tagName.GetPointer());
3730                 __currentSelectedStr.Clear();
3731                 AppLog("__currentSelectedStr after clear %ls",__currentSelectedStr.GetPointer());
3732                 __currentSelectedStr = __pWebViewer->GetTextFromBlock();
3733                 AppLog("__currentSelectedStr after GetTextFromBlock %ls",__currentSelectedStr.GetPointer());
3734
3735                 if (((tagName.CompareTo(L"INPUT") == 0)  || tagName.CompareTo(L"TEXTAREA") == 0) /*&& __isLongPressedDone == true*/ && __currentSelectedStr.CompareTo(L"") !=0)
3736                 {
3737                         AppLog("MainForm::OnWebPageBlockSelected show paste option");
3738
3739                         InitSelectTextContextMenuF(endPoint,true);
3740                         __pImageMenu->SetShowState(true);
3741                         __pImageMenu->Show();
3742                         __pImageMenu->Invalidate(true);
3743                 }
3744                 else /*if(__isLongPressedDone == true)*/
3745                 {
3746                         AppLog("MainForm::OnWebPageBlockSelected no paste option");
3747
3748                         if(__pHitElementResult->GetUrl().GetLength() > 0)
3749                         {
3750                                 __currentSelectedStr.Clear();
3751                                 __currentSelectedStr = __pHitElementResult->GetUrl();
3752                         }
3753                         InitSelectTextContextMenuF(endPoint,false);
3754                         __pImageMenu->SetShowState(true);
3755                         __pImageMenu->Show();
3756                         __pImageMenu->Invalidate(true);
3757                 }
3758
3759                 AppLog("MainForm::OnWebPageBlockSelected block text is %ls",__currentSelectedStr.GetPointer());
3760                 AppLog("MainForm::OnWebPageBlockSelected tag name is %ls",tagName.GetPointer());
3761                 AppLog("MainForm::OnWebPageBlockSelected type name is %ls",type.GetPointer());
3762         }
3763
3764 }
3765
3766 void
3767 MainForm::OnWebPageShowRequested(Tizen::Web::Controls::Web& source)
3768 {
3769
3770 }
3771
3772 Web*
3773 MainForm::OnWebWindowCreateRequested(void)
3774 {
3775         WindowInfo* pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewSceneN();
3776
3777         if (pNewWindowInfo == null)
3778         {
3779                 return null;
3780         }
3781         result r = E_SUCCESS;
3782         SceneManager* pSceneManager = SceneManager::GetInstance();
3783         if (pSceneManager == NULL)
3784         {
3785                 return null;
3786         }
3787         ArrayList* pArgList = new(std::nothrow) ArrayList();
3788         if (pArgList == NULL)
3789         {
3790                 return null;
3791         }
3792         r = pArgList->Construct();
3793         if (r == E_SUCCESS)
3794         {
3795                 pNewWindowInfo->isJavascriptInitiated = true;
3796                 pArgList->Add(*pNewWindowInfo);
3797                 r = pSceneManager->GoForward(ForwardSceneTransition(pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
3798                 delete pArgList;
3799                 if (IsFailed(r))
3800                 {
3801                         AppLogDebug("EditHistoryListForm::OnFormBackRequested Failed to GoBackward %s",GetErrorMessage(r));
3802                         return null;
3803                 }
3804         } else {
3805                 delete pArgList;
3806         }
3807
3808         return pNewWindowInfo->pCurrentWeb;
3809 }
3810
3811 void
3812 MainForm::RelayoutControls(bool showAddressbar,bool relayoutFooter)
3813 {
3814         AppLog("xyz:: MainForm::RelayoutControls called");
3815         __webControlPosition.y = 0;
3816         __webControlHeight = GetClientAreaBounds().height;
3817         AppLog("Client area height: %d", __webControlHeight);
3818
3819         AppLog("Client area height: %d", __webControlHeight);
3820         if(__pAddressbar != null && __pAddressbar->GetShowState() == true)
3821         {
3822                 __webControlPosition.y += __pAddressbar->GetHeight();
3823                 __webControlHeight -= __pAddressbar->GetHeight();
3824                 __pAddressbar->SetBounds(0, 0, __pAddressbar->GetWidth(), __pAddressbar->GetHeight());
3825         }
3826         else if(__pFindWordControl != null && __pFindWordControl->GetShowState() == true)
3827         {
3828                 __webControlPosition.y += __pFindWordControl->GetHeight();
3829                 __webControlHeight -= __pFindWordControl->GetHeight();
3830                 __pFindWordControl->SetBounds(0, 0, GetClientAreaBounds().width, __pFindWordControl->GetHeight());
3831         }
3832
3833         if(__pFooterPanel != null && __pFooterPanel->GetShowState() == true && relayoutFooter == true)
3834         {
3835                 __webControlHeight -= __pFooterPanel->GetHeight();
3836
3837                 __pFooterPanel->SetBounds(0, __webControlPosition.y + __webControlHeight, GetClientAreaBounds().width, __pFooterPanel->GetHeight());
3838         }
3839         if (__pWebViewer != null && __pWebViewer->GetShowState() == true)
3840         {
3841                 if(__pWebViewer->GetX() == 0 && __pWebViewer->GetY() == __webControlPosition.y &&__pWebViewer->GetWidth() == GetClientAreaBounds().width &&__pWebViewer->GetHeight() == __webControlHeight + 12 )
3842                 {
3843                 }
3844                 else
3845                 {
3846                         __pWebViewer->SetBounds(0, __webControlPosition.y, GetClientAreaBounds().width, __webControlHeight + 12);
3847                         __pWebViewer->Invalidate(false);
3848                 }
3849         }
3850         if(__pMostVisitedListView != null && __pAddressbar != null && __pFooterPanel != null)
3851         {
3852                 __pMostVisitedListView->SetBounds(Tizen::Graphics::Rectangle(0,__webControlPosition.y , GetClientAreaBounds().width, __webControlHeight));
3853         }
3854
3855         Invalidate(true);
3856 }
3857
3858 void
3859 MainForm::ShowFindWordPanel(bool show , bool isTouchPressed)
3860 {
3861         if (__pFindWordControl == null)
3862         {
3863                 return;
3864         }
3865
3866         Tizen::Locales::LocaleManager localeManager;
3867         Tizen::Locales::Locale local = localeManager.GetSystemLocale();
3868
3869         String languageCode;
3870         result r = SettingInfo::GetValue(L"Language", languageCode);
3871         // int languagecode = local.GetLanguageCode();
3872         AppLog("rahul language is %S", languageCode.GetPointer());
3873
3874         if (show == true)
3875         {
3876                 InitFindWordPanel();
3877
3878                 if (languageCode.CompareTo("ara") == 0)
3879                 {
3880                         AppLog("rahul language is arabic");
3881
3882                         __pFindWordPanelLeftToRight->SetShowState(false);
3883                         __pFindWordPanelRightToLeft->SetShowState(true);
3884
3885                         __pFindWordClear->SetShowState(false);
3886                         __pFindWordCountLabel->SetShowState(false);
3887                         __pFindWordEditField->SetShowState(false);
3888
3889                         __pFindWordClearRightToLeft->SetShowState(true);
3890                         __pFindWordCountLabelRightToLeft->SetShowState(true);
3891                         __pFindWordEditFieldRightToLeft->SetShowState(true);
3892                 }
3893                 else
3894                 {
3895                         AppLog("rahul language is not arabic");
3896
3897
3898                         __pFindWordPanelLeftToRight->SetShowState(true);
3899                         __pFindWordPanelRightToLeft->SetShowState(false);
3900
3901                         __pFindWordClear->SetShowState(true);
3902                         __pFindWordCountLabel->SetShowState(true);
3903                         __pFindWordEditField->SetShowState(true);
3904
3905                         __pFindWordClearRightToLeft->SetShowState(false);
3906                         __pFindWordCountLabelRightToLeft->SetShowState(false);
3907                         __pFindWordEditFieldRightToLeft->SetShowState(false);
3908                 }
3909                 __pFindWordControl->SetShowState(true);
3910         }
3911         else
3912         {
3913                 if(__pFindWordControl != null)
3914                 {
3915                         __pFindWordControl->SetShowState(false);
3916                 }
3917         }
3918
3919         AppLog("MainForm::ShowFindWordPanel %d",show);
3920         if (show && !isTouchPressed)
3921         {
3922                 if (languageCode.CompareTo("ara") == 0)
3923                 {
3924                         if (__pFindWordEditFieldRightToLeft)
3925                         {
3926                                 __pFindWordEditFieldRightToLeft->SetFocus();
3927                                 __pFindWordEditFieldRightToLeft->ShowKeypad();
3928                         }
3929                 }
3930                 else
3931                 {
3932                         if (__pFindWordEditField)
3933                         {
3934                                 __pFindWordEditField->SetFocus();
3935                                 __pFindWordEditField->ShowKeypad();
3936                         }
3937                 }
3938         }
3939         else
3940         {
3941                 if (languageCode.CompareTo("ara") == 0)
3942                 {
3943                         if (__pFindWordEditFieldRightToLeft)
3944                                 __pFindWordEditFieldRightToLeft->HideKeypad();
3945                 }
3946                 else
3947                 {
3948                         if (__pFindWordEditField)
3949                                 __pFindWordEditField->HideKeypad();
3950                 }
3951         }
3952
3953         RelayoutControls(false);
3954 }
3955
3956 void
3957 MainForm::StartWordSearch()
3958 {
3959         //Get the count of occurances of the word in the current page
3960         __maxOccurrances = 0;
3961         __currentWordIndex = 0;
3962
3963         __pFindWordPrev->SetEnabled(false);
3964         String *pCountStr = null;
3965         result r = __pWebViewer->SearchTextAllAsync(__currentSearchStr, false);
3966         AppLog("Search Result %s",GetErrorMessage(r));
3967         /*__pWebViewer->EvaluateJavascriptN(L"document.body.textContent.match(/"  + __currentSearchStr + "/gi).length;");
3968         if (pCountStr != null)
3969         {
3970                 Integer::Parse(*pCountStr, 10, __maxOccurrances);
3971                 delete pCountStr;
3972         }
3973
3974         AppLogDebug("'%ls' is found %d times", __currentSearchStr.GetPointer(), __maxOccurrances);
3975          */
3976
3977 }
3978
3979 void MainForm::OnTextFound(int totalCount, int currentOrdinal)
3980 {
3981         AppLog("MainForm::OnTextFound totalCount %d",totalCount);
3982         AppLog("MainForm::OnTextFound currentOrdinal %d",currentOrdinal);
3983
3984         if(totalCount == -1 || totalCount == 0)
3985         {
3986                 __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),84,__pFindWordCountLabel->GetHeight());
3987                 __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),214+80,__pFindWordEditField->GetHeight());
3988 //              return;
3989         }
3990         else if(totalCount > 100)
3991         {
3992                 __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),124,__pFindWordCountLabel->GetHeight());
3993                 __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),174,__pFindWordEditField->GetHeight());
3994         }
3995         else
3996         {
3997                 __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),124,__pFindWordCountLabel->GetHeight());
3998                 __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),174,__pFindWordEditField->GetHeight());
3999         }
4000
4001         __maxOccurrances = totalCount;
4002         __currentWordIndex = currentOrdinal;
4003
4004         //Reset the UI controls as per the maxOccurrance value
4005         if (totalCount <= 0)
4006         {
4007                 AppLog("Word not found");
4008                 //Show error notification to user
4009                 __pFindWordNext->SetEnabled(false);
4010                 if(__pFindWordCountLabel && __pFindWordCountLabel->GetShowState() == true)
4011                 {
4012                         __pFindWordCountLabel->SetText(L"0/0");
4013                         __pFindWordCountLabel->Invalidate(false);
4014                 }
4015                 else if(__pFindWordCountLabelRightToLeft && __pFindWordCountLabelRightToLeft->GetShowState() == true)
4016                 {
4017                         __pFindWordCountLabelRightToLeft->SetText(L"0/0");
4018                         __pFindWordCountLabelRightToLeft->Invalidate(false);
4019                 }
4020                 __pFindWordNext->Invalidate(false);
4021                 __pFindWordPrev->Invalidate(false);
4022
4023                 return;
4024         }
4025
4026         if (totalCount == 1)
4027         {
4028                 __pFindWordNext->SetEnabled(false);
4029         }
4030         else
4031         {
4032                 __pFindWordNext->SetEnabled(true);
4033         }
4034
4035         String countStr = L"";
4036         countStr.Append(__currentWordIndex);
4037         countStr.Append(L"/");
4038         countStr.Append(__maxOccurrances);
4039         if (__pFindWordCountLabel && __pFindWordCountLabel->GetShowState() == true)
4040         {
4041         __pFindWordCountLabel->SetText(countStr);
4042         __pFindWordCountLabel->Invalidate(false);
4043         __pFindWordCountLabel->Invalidate(false);
4044         }
4045         else if(__pFindWordCountLabelRightToLeft && __pFindWordCountLabelRightToLeft->GetShowState() == true)
4046         {
4047                 __pFindWordCountLabelRightToLeft->SetText(countStr);
4048                 __pFindWordCountLabelRightToLeft->Invalidate(false);
4049                 __pFindWordCountLabelRightToLeft->Invalidate(false);
4050         }
4051         //FindNextWord(true);
4052         //Update the controls
4053         __pFindWordNext->Invalidate(false);
4054         __pFindWordPrev->Invalidate(false);
4055
4056 }
4057
4058 void
4059 MainForm::FindNextWord(bool next)
4060 {
4061         if (next == true)
4062         {
4063                 //if (__pWebViewer->SearchText(__currentSearchStr, true) == true)
4064                         if (__pWebViewer->SearchNextAsync(true) == E_SUCCESS)
4065                         {
4066                                 if (__currentWordIndex < __maxOccurrances)
4067                                 {
4068                                         __currentWordIndex++;
4069                                 }
4070                         }
4071         }
4072         else
4073         {
4074                 //if (__pWebViewer->SearchText(__currentSearchStr, false) == true)
4075                 if (__pWebViewer->SearchNextAsync(false) == E_SUCCESS)
4076                 {
4077                         if(__currentWordIndex > 1)
4078                         {
4079                                 __currentWordIndex--;
4080                         }
4081                 }
4082         }
4083
4084         String countStr = L"";
4085         countStr.Append(__currentWordIndex);
4086         countStr.Append(L"/");
4087         countStr.Append(__maxOccurrances);
4088
4089         if (__pFindWordCountLabel && __pFindWordCountLabel->GetShowState() == true)
4090         {
4091         __pFindWordCountLabel->SetText(countStr);
4092         __pFindWordCountLabel->Invalidate(false);
4093         }
4094         else if(__pFindWordCountLabelRightToLeft && __pFindWordCountLabelRightToLeft->GetShowState() == true)
4095         {
4096                 __pFindWordCountLabelRightToLeft->SetText(countStr);
4097                 __pFindWordCountLabelRightToLeft->Invalidate(false);
4098         }
4099
4100         if (__currentWordIndex >= __maxOccurrances)
4101         {
4102                 __pFindWordNext->SetEnabled(false);
4103         }
4104         else
4105         {
4106                 __pFindWordNext->SetEnabled(true);
4107         }
4108         if (__currentWordIndex <= 1)
4109         {
4110                 __pFindWordPrev->SetEnabled(false);
4111         }
4112         else
4113         {
4114                 __pFindWordPrev->SetEnabled(true);
4115         }
4116         __pFindWordPrev->Invalidate(false);
4117         __pFindWordNext->Invalidate(false);
4118
4119         __pFindWordControl->Invalidate(true);
4120 }
4121
4122 void
4123 MainForm::OnWebKeypadWillOpen(Tizen::Web::Controls::Web& source)
4124 {
4125         AppLog("xyz::MainForm::OnWebKeypadWillOpen");
4126         __isWebKeypadOpened = true;
4127         __pFooterPanel->SetShowState(false);
4128         //      OnAddressBarKeypadOpened(*__pAddressbar);
4129 }
4130
4131 void
4132 MainForm::OnWebKeypadOpened(Tizen::Web::Controls::Web& source)
4133 {
4134         AppLog("xyz::MainForm::OnWebKeypadOpened");
4135
4136         if(__pFindWordControl && __pFindWordControl->GetShowState() == true)
4137         {
4138                 __currentSearchStr = L"";
4139                 __currentWordIndex = 0;
4140                 __maxOccurrances = 0;
4141                 __pFindWordEditField->SetText(L"");
4142                 __pFindWordNext->SetEnabled(false);
4143                 __pFindWordPrev->SetEnabled(false);
4144                 __pFindWordCountLabel->SetText(L"0/0");
4145                 __pWebViewer->SearchTextAllAsync(L"",false);
4146                 __pFindWordControl->SetShowState(false);
4147                 __pFindWordEditField->HideKeypad();
4148         }
4149
4150
4151         if (__pWebViewer != null && __pFooterPanel != null)
4152         {
4153                 AppLog("MainForm::OnWebKeypadOpened GetClientAreaBounds().height %d ", GetClientAreaBounds().height);
4154                 if(__pAddressbar != null)
4155                 {
4156                         __pAddressbar->SetShowState(false);
4157                 }
4158                 if(__pFindWordControl != null)
4159                 {
4160                         __pFindWordControl->SetShowState(false);
4161                 }
4162                 __pFooterPanel->SetShowState(false);
4163                 __pWebViewer->SetBounds(Rectangle(0, 0,GetClientAreaBounds().width, GetClientAreaBounds().height));
4164         }
4165 //      if(__pImageMenu && __pImageMenu->GetShowState() == true)
4166 //      {
4167 //              __pImageMenu->SetAnchorPosition(Point(__pImageMenu->GetAnchorPosition().x/2,__pImageMenu->GetAnchorPosition().y/2));
4168 //              AppLog("omgomgomg");
4169 //      }
4170         Invalidate(true);
4171 }
4172
4173 void
4174 MainForm::OnWebKeypadClosed(Tizen::Web::Controls::Web& source)
4175 {
4176         AppLog("xyz::MainForm::OnWebKeypadClosed");
4177         AppLog("akjshdasd 4");
4178         __pFooterPanel->SetShowState(true);
4179 //      OnAddressBarKeypadClosed(*__pAddressbar);
4180         RelayoutControls(false);
4181         __isWebKeypadOpened = false;
4182 }
4183
4184 void
4185 MainForm::OnWebKeypadBoundsChanged(Tizen::Web::Controls::Web& source)
4186 {
4187         //      RelativeLayout(false);
4188         if(__pWebViewer != null)
4189         {
4190                 __pWebViewer->SetBounds(Rectangle(0,__webControlPosition.y,GetClientAreaBounds().width,GetClientAreaBounds().height));
4191         }
4192 }
4193
4194 void
4195 MainForm::OnTouchDoublePressed(const Control& source, const Point& currentPosition, const TouchEventInfo& touchInfo)
4196 {
4197         Control* temp = const_cast< Control* >(&source);
4198         Header* pHeader = dynamic_cast< Header* >(temp);
4199         if (pHeader != null)
4200         {
4201                 //Header double - clicked
4202                 AppLog("Header double clicked");
4203         }
4204         if(__pFindWordControl)
4205         {
4206                 AppLog("MainForm::OnTouchPressed %d",__pFindWordControl->GetShowState());
4207                 ShowFindWordPanel(__pFindWordControl->GetShowState(), true);
4208         }
4209
4210
4211         AppLog("MainScene::OnTouchDoublePressed");
4212
4213 }
4214
4215 void MainForm::OnTouchLongPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
4216 {
4217         AppLog("abcde::MainForm::OnTouchLongPressed %d, %d" ,currentPosition.x,currentPosition.y);
4218         __longPressPoint = currentPosition;
4219
4220         if (__pHitElementResult != null)
4221         {
4222                 delete __pHitElementResult;
4223                 __pHitElementResult = null;
4224         }
4225
4226         if (__pWebViewer != null)
4227         {
4228                 AppLog("MainForm::OnTouchLongPressed web not null");
4229                 __pHitElementResult = __pWebViewer->GetElementByPointN(currentPosition);
4230         }
4231
4232         if (__pHitElementResult == null)
4233         {
4234                 return;
4235         }
4236
4237         if (__pHitElementResult->HasImage() == true)
4238         {
4239                 InitImageContextMenu(currentPosition);
4240                 __pImageMenu->SetShowState(true);
4241                 __pImageMenu->Show();
4242                 __pImageMenu->Invalidate(true);
4243         }
4244         else if(__pHitElementResult->HasUrl() == true)
4245         {
4246                 String tempURl = __pHitElementResult->GetUrl();
4247                 AppLog("tempURl is %ls", tempURl.GetPointer());
4248                 const Bitmap* pBitmap = __pHitElementResult->GetImage();
4249                 if (pBitmap != null)
4250                 {
4251                         AppLog("not null");
4252                 }
4253                 else
4254                 {
4255                         AppLog(null);
4256                 }
4257                 InitImageLinkContextMenu(currentPosition);
4258                 __pImageMenu->SetShowState(true);
4259                 __pImageMenu->Show();
4260                 __pImageMenu->Invalidate(true);
4261         }
4262         else
4263         {
4264                 String tagName = __pHitElementResult->GetTagName();
4265                 String type = __pHitElementResult->GetAttributeValue("type");
4266                 String value = __pHitElementResult->GetAttributeValue(L"value");
4267                 String innerHtml = __pHitElementResult->GetAttributeValue(L"innerHTML");
4268
4269                 __currentSelectedStr.Clear();
4270                 __currentSelectedStr = __pWebViewer->GetTextFromBlock();
4271
4272                 AppLog("tag name is %ls", tagName.GetPointer());
4273                 AppLog("type is %ls", type.GetPointer());
4274
4275
4276
4277                 //__isLongPressedDone = true;
4278                 result r =__pWebViewer->SetBlockSelectionPosition(currentPosition);
4279                 if (((tagName.CompareTo(L"INPUT") == 0)  || tagName.CompareTo(L"TEXTAREA") == 0) && innerHtml.GetLength() == 0 /*&& __isWebKeypadOpened == true*/ && __currentSelectedStr.CompareTo(L"") == 0 && r == E_INVALID_ARG)
4280                 {
4281                         AppLog("MainForm::OnWebPageBlockSelected show paste option");
4282
4283                         InitSelectTextContextMenu(currentPosition,true, true);
4284                         if(__pImageMenu)
4285                         {
4286                                 __pImageMenu->SetShowState(true);
4287                                 __pImageMenu->Show();
4288                                 __pImageMenu->Invalidate(true);
4289                         }
4290                 }
4291                 AppLog("setselectionselectedornot %s",GetErrorMessage(r));
4292
4293         }
4294 //      __inputEventToBeSupressed = true;
4295 }
4296
4297 void
4298 MainForm::OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
4299 {
4300         AppLog("xyz:: MainForm::OnTouchReleased called");
4301
4302         if (__pAddressbar && __pAddressbar->GetShowState() == true)
4303         {
4304                 __pAddressbar->SetShowState(false);
4305         }
4306
4307         // Not reuired now.
4308         /*HitElementResult* pHitElement = __pWebViewer->GetElementByPointN(currentPosition);
4309         if(pHitElement != null && pHitElement->HasUrl() == true && __inputEventToBeSupressed == true)
4310         {
4311                 __pWebViewer->ConsumeInputEvent();
4312         }
4313         if(pHitElement != null)
4314         {
4315                 delete pHitElement;
4316         }
4317         __inputEventToBeSupressed = false;*/
4318 }
4319
4320 bool
4321 MainForm::OnTouchPressed(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4322 {
4323
4324         return true;
4325 }
4326
4327 bool
4328 MainForm::OnTouchReleased(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4329 {
4330         if(__pFindWordControl && __pFindWordControl->GetShowState() == true)
4331         {
4332                 __currentSearchStr = L"";
4333                 __currentWordIndex = 0;
4334                 __maxOccurrances = 0;
4335
4336                 if (__pFindWordPanelLeftToRight && __pFindWordPanelLeftToRight->GetShowState() == true)
4337                 {
4338                         __pFindWordEditField->SetText(L"");
4339                         __pFindWordEditField->HideKeypad();
4340                         __pFindWordControl->SetShowState(false);
4341                         __pFindWordCountLabel->SetText(L"0/0");
4342                 }
4343                 else if(__pFindWordPanelRightToLeft && __pFindWordPanelRightToLeft->GetShowState() == true)
4344                 {
4345                         __pFindWordEditFieldRightToLeft->SetText(L"");
4346                         __pFindWordEditFieldRightToLeft->HideKeypad();
4347                         __pFindWordControl->SetShowState(false);
4348                         __pFindWordCountLabelRightToLeft->SetText(L"0/0");
4349                 }
4350
4351                 __pFindWordNext->SetEnabled(false);
4352                 __pFindWordPrev->SetEnabled(false);
4353
4354                 __pWebViewer->SearchText(L"aaaabbbbcccc",true);
4355                 __pFindWordControl->SetShowState(false);
4356         }
4357         if(__pAddressbar->GetShowState() == false)
4358         {
4359                 __pAddressbar->SetAddressbarURLFocus();
4360                 __pFooterPanel->SetShowState(false);
4361         }
4362
4363         return true;
4364 }
4365
4366 bool
4367 MainForm::OnTouchMoved(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4368 {
4369         return true;
4370 }
4371
4372 bool
4373 MainForm::OnTouchCanceled(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4374 {
4375         return true;
4376 }
4377
4378 bool
4379 MainForm::OnPreviewTouchPressed(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4380 {
4381         return true;
4382 }
4383
4384 bool
4385 MainForm::OnPreviewTouchReleased(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4386 {
4387         return true;
4388 }
4389
4390 bool
4391 MainForm::OnPreviewTouchMoved(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4392 {
4393         return true;
4394 }
4395
4396 void
4397 MainForm::OnOrientationChanged (const Tizen::Ui::Control &source, Tizen::Ui::OrientationStatus orientationStatus)
4398 {
4399         AppLog("MainForm::OnOrientationChanged GetClientAreaBounds %d, %d",GetClientAreaBounds().width,GetClientAreaBounds().height);
4400         int widthContextItem = 0;
4401
4402         // As per the platform engineer comment removed this line
4403         /*if(__pWebViewer != null)
4404         {
4405                 // 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
4406                 __pWebViewer->ReleaseBlock();
4407         }*/
4408
4409 //      if(__pFindWordControl != null)
4410 //              ShowFindWordPanel(__pFindWordControl->GetShowState(), false);
4411         if(__pNotification && __pNotification->GetShowState() == true)
4412         {
4413                 __pNotification->SetShowState(false);
4414                 __pNotification->Invalidate(false);
4415         }
4416         if ( __pFooterLabel != null)
4417         {
4418                 Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_SEARCH_INPUT_FIELD_BG, __pFooterLabel->GetWidth(), __pFooterLabel->GetHeight());
4419                 if(pBitmap != null)
4420                 {
4421                         __pFooterLabel->SetBackgroundBitmap(*pBitmap);
4422                         delete pBitmap;
4423                 }
4424
4425
4426         }
4427         if (__pFindWordBgLabel != null)
4428         {
4429                 Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_FINDWORD_INPUT_FIELD_BG, __pFindWordBgLabel->GetWidth(), __pFindWordBgLabel->GetHeight());
4430                 if (pBitmap != null)
4431                 {
4432                         __pFindWordBgLabel->SetBackgroundBitmap(*pBitmap);
4433                         delete pBitmap;
4434                 }
4435         }
4436
4437         if (__pFindWordBgLabelRightToLeft != null)
4438         {
4439                 Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_FINDWORD_INPUT_FIELD_BG, __pFindWordBgLabelRightToLeft->GetWidth(), __pFindWordBgLabelRightToLeft->GetHeight());
4440                 if (pBitmap != null)
4441                 {
4442                         __pFindWordBgLabelRightToLeft->SetBackgroundBitmap(*pBitmap);
4443                         delete pBitmap;
4444                 }
4445         }
4446
4447
4448         if(__pOptionMenu != null)
4449                 __pOptionMenu->SetShowState(false);
4450
4451         if( GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
4452         {
4453                 widthContextItem = WIDTH_CONTEXT_MENU_BUTTON_LANDSCAPE;
4454         }
4455         else
4456         {
4457                 widthContextItem = WIDTH_CONTEXT_MENU_BUTTON_PORTRAIT;
4458         }
4459
4460         if (__pFooterPanel)
4461         {
4462                 AppLog("__pFooterPanel->GetShowState() is true");
4463                 InitFooter();
4464                 __pFooterPanel->SetBounds(0, GetClientAreaBounds().height - __pFooterPanel->GetHeight(), __pFooterPanel->GetWidth(), __pFooterPanel->GetHeight());
4465                 __pFooterPanel->Invalidate(true);
4466         }
4467         InitAddressbar();
4468
4469         String homePage = SettingPresentationModel::GetInstance()->GetHomepage();
4470         if (homePage.CompareTo((L"IDS_BR_BODY_MOST_VISITED_SITES")) == 0)
4471         {
4472                 InitMostVisitedSitesView(orientationStatus);
4473         }
4474
4475         RelayoutControls(false);
4476         if (__pArticleReaderPanel != null)
4477         {
4478                 if (__pArticleReaderPanel->GetShowState() == true)
4479                 {
4480                         __pArticleReaderPanel->SetBounds((GetClientAreaBounds().width - __pArticleReaderPanel->GetWidth())/2,(GetClientAreaBounds().height - __pArticleReaderPanel->GetHeight())/2, __pArticleReaderPanel->GetWidth(), __pArticleReaderPanel->GetHeight());
4481
4482                         if (__pBlankPanel != null)
4483                                 __pBlankPanel->SetBounds(0,0,GetClientAreaBounds().width,GetClientAreaBounds().height);
4484
4485                         if (__pWebReader != null)
4486                         {
4487                                 __pWebReader->SetBounds(Rectangle(2,2, __pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight() - 96));
4488                         }
4489                         Bitmap* pBitmap = CommonUtil::GetNinepatchedBitmapN(L"I01_popup_bg.9.png",__pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight());
4490                         Bitmap* pSrcBitmap = CommonUtil::GetNinepatchedBitmapN(L"I01_popup_bottom_bg.9.png",__pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight());
4491
4492                         if ( pBitmap != null && pSrcBitmap != null)
4493                         {
4494                                 AppLog("CreateReaderPanel ninepatchbitmap found");
4495                                 pBitmap->Merge(Point(0,__pArticleReaderPanel->GetHeight() - 96),*pSrcBitmap,Rectangle(0,0,pSrcBitmap->GetWidth(),pSrcBitmap->GetHeight()));
4496                         }
4497
4498                         __pArticleReaderLabel->SetBounds(Rectangle(__pArticleReaderPanel->GetX(),__pArticleReaderPanel->GetY(),__pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight()));
4499                         __pArticleReaderLabel->SetBackgroundBitmap(*pBitmap);
4500                         if (pBitmap != null)
4501                         {
4502                                 delete pBitmap;
4503                                 pBitmap = null;
4504                         }
4505                         if (pSrcBitmap != null)
4506                         {
4507                                 delete pSrcBitmap;
4508                                 pSrcBitmap = null;
4509                         }
4510                 }
4511         }
4512         Invalidate(true);
4513         
4514     if (__pAddressbar != null)
4515         {
4516                 int width = GetClientAreaBounds().width;
4517                 __pAddressbar->OrientationChanged(width);
4518         }
4519 }
4520
4521 void
4522 MainForm::OnSettingsChange(int settingvalue)
4523 {
4524         AppLogDebug("MainForm::OnSettingsChange entered");
4525
4526         if(settingvalue == (int)REGISTRY_SETTING_HOMEPAGE)
4527         {
4528                 __pAddressbar->ResetGuideText();
4529         }
4530         if (__pWebViewer == null)
4531         {
4532                 AppLogDebug("Webviewer is not initialized yet.");
4533                 return;
4534         }
4535
4536         if (settingvalue == (int) REGISTRY_SETTING_DEFAULT_VIEW)
4537         {
4538                 WebSetting settings = __pWebViewer->GetSetting();
4539                 if (SettingPresentationModel::GetInstance()->GetDefaultView().CompareTo((L"IDS_BR_BODY_FIT_TO_WIDTH")) == 0)
4540                 {
4541                         settings.SetAutoFittingEnabled(true);
4542                 }
4543                 else if (SettingPresentationModel::GetInstance()->GetDefaultView().CompareTo((L"IDS_BR_BODY_READABLE")) == 0)
4544                 {
4545                         settings.SetAutoFittingEnabled(false);
4546                 }
4547                 __pWebViewer->SetSetting(settings);
4548         }
4549         else if (settingvalue == (int) REGISTRY_SETTING_RUN_JAVASCRIPT)
4550         {
4551                 WebSetting settings = __pWebViewer->GetSetting();
4552                 settings.SetJavascriptEnabled(SettingPresentationModel::GetInstance()->IsRunJavascriptEnabled());
4553                 __pWebViewer->SetSetting(settings);
4554         }
4555         else if (settingvalue == (int) REGISTRY_SETTING_DISPLAY_IMAGES)
4556         {
4557                 WebSetting settings = __pWebViewer->GetSetting();
4558                 settings.SetAutoImageLoadEnabled(SettingPresentationModel::GetInstance()->IsDisplayImagesEnabled());
4559                 __pWebViewer->SetSetting(settings);
4560                 __pWebViewer->Reload();
4561         }
4562         else if (settingvalue == (int) REGISTRY_SETTING_BLOCK_POPUP)
4563         {
4564                 WebSetting settings = __pWebViewer->GetSetting();
4565                 settings.SetJavaScriptPopupEnabled(SettingPresentationModel::GetInstance()->IsBlockPopUp());
4566                 __pWebViewer->SetSetting(settings);
4567         }
4568         else if (settingvalue == (int) REGISTRY_SETTING_ACCEPT_COOKIES)
4569         {
4570                 if (__pWebViewer)
4571                 {
4572                         __pWebViewer->SetCookieEnabled(SettingPresentationModel::GetInstance()->IsCookiesEnabled());
4573                 }
4574         }
4575         else if(settingvalue == (int) REGISTRY_SETTING_REMEMBER_FORM_DATA)
4576         {
4577                 if (__pWebViewer)
4578                 {
4579                         WebSetting settings = __pWebViewer->GetSetting();
4580                         settings.SetAutoFormDataShowEnabled(SettingPresentationModel::GetInstance()->IsRememberFormData());
4581                         __pWebViewer->SetSetting(settings);
4582                 }
4583         }
4584         else if(settingvalue == (int) REGISTRY_SETTING_REMEMBER_PASSWORD)
4585         {
4586                 if (__pWebViewer)
4587                 {
4588                         WebSetting settings = __pWebViewer->GetSetting();
4589                         settings.SetAutoLoginFormFillEnabled(SettingPresentationModel::GetInstance()->IsRememberPassword());
4590                         __pWebViewer->SetSetting(settings);
4591                 }
4592         }
4593         else if (settingvalue == (int) REGISTRY_SETTING_SHOW_SECURITY_WARNINGS)
4594         {
4595                 WebSetting settings = __pWebViewer->GetSetting();
4596                 if (SettingPresentationModel::GetInstance()->IsSecurityWarningsEnabled() == true)
4597                 {
4598                         settings.SetCertificateErrorHandlingMode(WEB_CERTIFICATE_ERROR_HANDLING_MODE_USER_CONFIRM);
4599                 }
4600                 else
4601                 {
4602                         settings.SetCertificateErrorHandlingMode(WEB_CERTIFICATE_ERROR_HANDLING_MODE_CONTINUE);
4603                 }
4604                 __pWebViewer->SetSetting(settings);
4605         }
4606         else if (settingvalue == (int) REGISTRY_SETTING_READER_FONT_SIZE)
4607         {
4608                 if (__pWebReader)
4609                 {
4610                         AppLogDebug("IntMainForm fontsize Changed to %d",SettingPresentationModel::GetInstance()->GetReaderFontSize());
4611                         WebSetting settings = __pWebReader->GetSetting();
4612                         settings.SetFontSize(SettingPresentationModel::GetInstance()->GetReaderFontSize());
4613                         __pWebReader->SetSetting(settings);
4614                 }
4615         }
4616 }
4617
4618 void
4619 MainForm::OnSettingsReset()
4620 {
4621         if (__pWebViewer)
4622         {
4623                 __pWebViewer->SetCookieEnabled(SettingPresentationModel::GetInstance()->IsCookiesEnabled());
4624                 __pWebViewer->SetSetting(SettingPresentationModel::GetInstance()->GetWebSettings());
4625         }
4626 }
4627
4628 void
4629 MainForm::OnClearCache()
4630 {
4631         result r = E_SUCCESS;
4632
4633         if (__pWebViewer != NULL)
4634         {
4635                 r = __pWebViewer->ClearCache();
4636                 if (r == E_SUCCESS)
4637                 {
4638                         AppLogDebug("Cache cleared success");
4639                 }
4640                 else
4641                 {
4642                         AppLogDebug("Cache cleared fail");
4643                 }
4644         }
4645 }
4646
4647 void
4648 MainForm::OnClearCookie()
4649 {
4650         result r = E_SUCCESS;
4651
4652         if (__pWebViewer != NULL)
4653         {
4654                 __pWebViewer->ClearCookie();
4655         }
4656         if (r == E_SUCCESS)
4657         {
4658                 AppLogDebug("Cookie cleared success");
4659         }
4660         else
4661         {
4662                 AppLogDebug("Cache cleared fail");
4663         }
4664 }
4665
4666 void
4667 MainForm::OnClearFormData()
4668 {
4669         result r = E_SUCCESS;
4670
4671         if (__pWebViewer != NULL)
4672         {
4673                 __pWebViewer->ClearFormData();
4674         }
4675         if (r == E_SUCCESS)
4676         {
4677                 AppLogDebug("Cookie cleared success");
4678         }
4679         else
4680         {
4681                 AppLogDebug("Cache cleared fail");
4682         }
4683 }
4684
4685 void
4686 MainForm::OnClearPasswords()
4687 {
4688         result r = E_SUCCESS;
4689
4690         if (__pWebViewer != NULL)
4691         {
4692                 __pWebViewer->ClearLoginFormData();
4693         }
4694         if (r == E_SUCCESS)
4695         {
4696                 AppLogDebug("Cookie cleared success");
4697         }
4698         else
4699         {
4700                 AppLogDebug("Cache cleared fail");
4701         }
4702 }
4703
4704
4705 double
4706 MainForm::findDistance(int x1,int y1,int x2, int y2)
4707 {
4708         int deltaX = Math::Abs(x2 - x1);
4709         int deltaY = Math::Abs(y2 - y1);
4710         double num = deltaX*deltaX + deltaY*deltaY;
4711
4712         if (num >= 0)
4713         {
4714                 double x = num;
4715                 int i;
4716                 for (i = 0; i < 20; i++)
4717                 {
4718                         x = (((x*x)+ num)/(2*x));
4719                 }
4720                 return num;
4721         }
4722         else
4723         {
4724                 return 0.0;
4725         }
4726 }
4727
4728 void
4729 MainForm::OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
4730 {
4731         AppLog("xyz:: MainForm::OnTouchPressed called");
4732         if(__pFindWordControl)
4733         {
4734                 AppLog("MainForm::OnTouchPressed %d",__pFindWordControl->GetShowState());
4735 //              ShowFindWordPanel(__pFindWordControl->GetShowState(), true);
4736         }
4737         //__isLongPressedDone = false;
4738
4739
4740
4741         Touch touch;
4742         IList* pList = null;
4743         pList = touch.GetTouchInfoListN(source);
4744
4745         if (pList != null)
4746         {
4747                 int count = pList->GetCount();
4748                 if (count == 1)
4749                 {
4750                         TouchInfo* pTouchInfo = static_cast<TouchInfo*>(pList->GetAt(0));
4751                         __touchPoint1 = pTouchInfo->position;
4752
4753                         /*if (__pAddressbar != null)
4754                         {
4755                                 if (__pAddressbar->GetAddressbarMode() != ADDRESSBAR_MODE_LOADING_COMPLETE && __pAddressbar->GetAddressbarMode() != ADDRESSBAR_MODE_LOADING)
4756                                 {
4757                                         if (__pAddressbar->GetAddressbarMode() == ADDRESSBAR_MODE_EDIT)
4758                                         {
4759                                                 __pAddressbar->SaveAddressbarEditText();
4760                                         }
4761                                         __pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
4762                                 }
4763
4764                                 __pAddressbar->Invalidate(true);
4765                         }*/
4766                         if (GetAddressbarMode() != ADDRESSBAR_MODE_LOADING_COMPLETE && GetAddressbarMode() != ADDRESSBAR_MODE_LOADING)
4767                         {
4768                                 if (GetAddressbarMode() == ADDRESSBAR_MODE_EDIT)
4769                                 {
4770                                         //__pAddressbar->SaveAddressbarEditText();
4771                                 }
4772                                 SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
4773                         }
4774                 }
4775                 else if (count == 2)
4776                 {
4777                         AppLogDebug("MainForm::OnTouchPressed count is two");
4778                         TouchInfo* pTouchInfo = static_cast<TouchInfo*>(pList->GetAt(0));
4779                         __touchPoint1 = pTouchInfo->position;
4780
4781                         pTouchInfo = static_cast<TouchInfo*>(pList->GetAt(1));
4782                         __touchPoint2 = pTouchInfo->position;
4783                 }
4784         }
4785         if( pList != NULL)
4786         {
4787                 pList->RemoveAll(true);
4788                 delete pList;
4789         }
4790 //      RelayoutControls(false);
4791         return;
4792 }
4793
4794 void
4795 MainForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
4796 {
4797 //      __currentWordIndex = 0;
4798         //__isLongPressedDone = false;
4799
4800 }
4801
4802 void
4803 MainForm::MoveUiControls()
4804 {
4805 }
4806
4807 void
4808 MainForm::OnTextValueChanged (const Tizen::Ui::Control &source)
4809 {
4810         if(&source == dynamic_cast<Control*>(__pFooterUrlField) && __pFooterUrlField != null)
4811         {
4812                 if(__pFooterUrlField->GetTextLength() == 0)
4813                 {
4814                         __pFooterUrlField->SetKeypadActionEnabled(false);
4815                 }
4816                 else
4817                 {
4818                         __pFooterUrlField->SetKeypadActionEnabled(true);
4819                 }
4820         }
4821         if (__pFindWordEditField != null && __pFindWordEditField->GetShowState() == true)
4822         {
4823                 __currentSearchStr = __pFindWordEditField->GetText();
4824                 if (__currentSearchStr.GetLength() > 0)
4825                 {
4826                         __pFindWordCountLabel->SetShowState(true);
4827                 }
4828                 else
4829                 {
4830                         __pFindWordCountLabel->SetShowState(false);
4831                 }
4832                 __pFindWordNext->SetEnabled(false);
4833                 __pFindWordPrev->SetEnabled(false);
4834                 __pFindWordNext->Invalidate(true);
4835                 __pFindWordPrev->Invalidate(true);
4836                 __pFindWordCountLabel->SetText(L"0/0");
4837                 __pFindWordCountLabel->Invalidate(true);
4838         }
4839         else if (__pFindWordEditFieldRightToLeft != null && __pFindWordEditFieldRightToLeft->GetShowState() == true)
4840         {
4841                 __currentSearchStr = __pFindWordEditFieldRightToLeft->GetText();
4842                 if (__currentSearchStr.GetLength() > 0)
4843                 {
4844                         __pFindWordCountLabelRightToLeft->SetShowState(true);
4845                 }
4846                 else
4847                 {
4848                         __pFindWordCountLabelRightToLeft->SetShowState(false);
4849                 }
4850
4851                 __pFindWordNext->SetEnabled(false);
4852                 __pFindWordPrev->SetEnabled(false);
4853                 __pFindWordNext->Invalidate(true);
4854                 __pFindWordPrev->Invalidate(true);
4855                 __pFindWordCountLabelRightToLeft->SetText(L"0/0");
4856                 __pFindWordCountLabelRightToLeft->Invalidate(true);
4857         }
4858         AppLog("__currentSearchStr %ls",__currentSearchStr.GetPointer());
4859         if (__currentSearchStr.GetLength() > 0)
4860         {
4861                 StartWordSearch();
4862         }
4863         else
4864         {
4865                 __currentSearchStr = L"aaaaaaaabbbbbbbccccccc";
4866                 StartWordSearch();
4867                 __currentSearchStr = L"";
4868                 AppLogDebug("Enter something");
4869         }
4870 }
4871
4872 result
4873 MainForm::InitMostVisitedSitesPanel(Tizen::Ui::OrientationStatus orientationStatus)
4874 {
4875         return E_SUCCESS;
4876
4877 }
4878
4879 result
4880 MainForm::InitMostVisitedSitesView(Tizen::Ui::OrientationStatus orientationStatus)
4881 {
4882         if(__pWebViewer != null)
4883                 return E_SUCCESS;
4884
4885         AppLog("MainForm::InitMostVisitedSitesView");
4886         result r = E_SUCCESS;
4887
4888
4889         if (__pWebViewer != null && __pMostVisitedListView != null)
4890         {
4891                 return E_SUCCESS;
4892         }
4893
4894         if (__pMostVisitedListView != null)
4895         {
4896                 RemoveControl(__pMostVisitedListView);
4897         }
4898         if(__pMostVisitedSites != null)
4899         {
4900                 __pMostVisitedSites->RemoveAll(true);
4901         }
4902
4903         HistoryPresentationModel::GetInstance()->GetMostVisitedSites(*__pMostVisitedSites);
4904
4905         __webControlHeight = GetClientAreaBounds().height - __pFooterPanel->GetHeight();
4906         __pMostVisitedListView = new(std::nothrow) ListView();
4907
4908         int height = GetClientAreaBounds().height;
4909
4910         if(__pFooterPanel->GetShowState() == true)
4911         {
4912                 height = height - __pFooterPanel->GetHeight();
4913         }
4914         if(__pAddressbar->GetShowState() == true)
4915         {
4916                 height -= __pAddressbar->GetHeight();
4917         }
4918
4919         r = __pMostVisitedListView->Construct(Tizen::Graphics::Rectangle(0,0 , GetClientAreaBounds().width, height),true,false);
4920
4921         if (r != E_SUCCESS)
4922         {
4923                 delete __pMostVisitedListView;
4924                 AppLogDebug("Addressbar init failed with %s", GetErrorMessage(r));
4925                 return r;
4926         }
4927         __pMostVisitedListView->SetItemProvider(*this);
4928         __pMostVisitedListView->AddListViewItemEventListener(*this);
4929         __pMostVisitedListView->SetTextOfEmptyList(CommonUtil::GetString(L"IDS_BR_BODY_NO_RECENTLY_VISITED_SITES"));
4930         AddControl(__pMostVisitedListView);
4931         __pMostVisitedListView->UpdateList();
4932
4933         return E_SUCCESS;
4934
4935 }
4936
4937 String
4938 MainForm::GetImagePath(void)
4939 {
4940
4941         String str;
4942         String formattedTime;
4943         DateTime currentTime;
4944         LocaleManager localManager;
4945         SystemTime::GetCurrentTime(TIME_MODE_WALL, currentTime);
4946
4947         localManager.Construct();
4948         Locale locale = localManager.GetSystemLocale();
4949         //Locale locale(LANGUAGE_ENG, COUNTRY_US);
4950
4951         // Get date formatter
4952         DateTimeFormatter* pTimeFormatter = DateTimeFormatter::CreateDateTimeFormatterN(locale, DATE_TIME_STYLE_DEFAULT);
4953
4954         if (pTimeFormatter)
4955         {
4956                 pTimeFormatter->Format(currentTime, formattedTime);
4957         }
4958
4959         AppLog("current time stamp is %ls", formattedTime.GetPointer());
4960         String delim(L" :");
4961         StringTokenizer strTok(formattedTime, delim);
4962         String token;
4963         String imageName;
4964         String str1("GMT+00");
4965         while (strTok.HasMoreTokens())
4966         {
4967                 strTok.GetNextToken(token); // Osp, StringTokenizer, Sample, code
4968                 if(token.Equals(str1))
4969                         break;
4970                 AppLog("token is %ls", token.GetPointer());
4971                 imageName.Append(token);
4972         }
4973         return imageName;
4974
4975 }
4976
4977 void MainForm::UpdateImageContent(ByteBuffer* aBuffer, String imageName)
4978 {
4979         result r = E_FAILURE;
4980         AppLog("Content manager 1");
4981         ContentId contentId;
4982         ContentManager contentManager;
4983         r = contentManager.Construct();
4984         if(IsFailed(r))
4985         {
4986                 AppLog("Content manager update content result %s" ,GetErrorMessage(r));
4987                 return;
4988         }
4989         Tizen::Base::String contentPath = Tizen::System::Environment::GetMediaPath() + L"Downloads/";
4990         Tizen::Io::Directory::Create(contentPath,true);
4991         if(GetLastResult() == E_FILE_ALREADY_EXIST)
4992         {
4993                 AppLog("Already exists");
4994         }
4995         else if(GetLastResult() == E_SUCCESS)
4996         {
4997                 AppLog("created success");
4998         }
4999         contentPath.Append(imageName);
5000         contentPath.Append(".jpg");
5001         contentId = contentManager.CreateContent(*aBuffer, contentPath);
5002         AppLog("Content manager update content result %s" ,GetErrorMessage(GetLastResult()));
5003 }
5004
5005 void
5006 MainForm::SetForwardButtonEnabled(bool isEnabled)
5007 {
5008         __pGoForwardBtn->SetEnabled(isEnabled);
5009         __pGoForwardBtn->Invalidate(true);
5010 }
5011
5012 void
5013 MainForm::SetBackButtonEnabled(bool isEnabled)
5014 {
5015         __pGoBackBtn->SetEnabled(isEnabled);
5016         __pGoBackBtn->Invalidate(true);
5017 }
5018
5019 void
5020 MainForm::UpdateProgress(int percentage)
5021 {
5022         __progressPercentage = percentage;
5023         if (percentage == 0 || percentage == 100)
5024         {
5025                 __isLoadingData = false;
5026                 if (percentage == 100)
5027                 {
5028                         __isLoadingCompleted = true;
5029                         __progressPercentage = 0;
5030                 }
5031                 else
5032                 {
5033                         __isLoadingCompleted = false;
5034                 }
5035         }
5036         else
5037         {
5038                 __isLoadingData = true;
5039         }
5040         UpdateProgressBitmap();
5041 }
5042
5043 int
5044 MainForm::GetProgress(void)
5045 {
5046         return __progressPercentage;
5047 }
5048
5049 void
5050 MainForm::UpdateProgressBitmap(void)
5051 {
5052         result r = E_SUCCESS;
5053         if (__pProgressbarLabel == null)
5054                 return;
5055         int w = __pProgressbarLabel->GetWidth();
5056         int h = __pProgressbarLabel->GetHeight();
5057         Canvas canvas;
5058         int progressWidth = 0;
5059         Bitmap* pRetBitmap = null;
5060
5061         if (__progressPercentage == 0 || __progressPercentage == 100)
5062         {
5063                 __pProgressbarLabel->SetShowState(false);
5064                 __pProgressbarLabel->Invalidate(false);
5065                 return;
5066         }
5067         else
5068         {
5069                 __pProgressbarLabel->SetShowState(true);
5070                 __pProgressbarLabel->Invalidate(false);
5071         }
5072
5073         r = canvas.Construct(Rectangle(0, 0, w, h));
5074
5075         if (r != E_SUCCESS)
5076         {
5077                 AppLogException("Canvas construction failed with %s", GetErrorMessage(r));
5078                 return;
5079         }
5080
5081         canvas.Clear();
5082         Bitmap *pBgBmp = AppResource::GetInstance()->GetBitmapN(IDB_TITLE_PROGRESS_BAR_BG);
5083
5084         if (pBgBmp != null)
5085         {
5086                 pBgBmp->Scale(Dimension(w, h));
5087                 canvas.DrawBitmap(Point(0,0), *pBgBmp);
5088                 delete pBgBmp;
5089         }
5090
5091         progressWidth = (double) (w) * __progressPercentage / 100;
5092         AppLogDebug("progressWidth: %d", progressWidth);
5093         Bitmap *pProgressBmp = AppResource::GetInstance()->GetBitmapN(IDB_TITLE_PROGRESS_BAR);
5094
5095         if (pProgressBmp != null)
5096         {
5097                 pProgressBmp->Scale(Dimension(progressWidth, h));
5098                 canvas.DrawBitmap(Point(0,0), *pProgressBmp);
5099                 delete pProgressBmp;
5100         }
5101
5102         pRetBitmap = new (std::nothrow) Bitmap();
5103
5104         if (pRetBitmap == null)
5105         {
5106                 AppLogException("Bitmap creation failed with %s", GetErrorMessage(r));
5107                 return;
5108         }
5109
5110         pRetBitmap->Construct(canvas, canvas.GetBounds());
5111
5112         if (__pProgressbarLabel != null && pRetBitmap != null)
5113         {
5114                 __pProgressbarLabel->SetBackgroundBitmap(*pRetBitmap);
5115                 __pProgressbarLabel->Invalidate(false);
5116         }
5117
5118         if (pRetBitmap != null)
5119         {
5120                 delete pRetBitmap;
5121                 pRetBitmap = null;
5122         }
5123         return;
5124 }
5125
5126 void
5127 MainForm::ReaderClicked()
5128 {
5129         result r = E_SUCCESS;
5130         ArrayList* pArgList = new(std::nothrow) ArrayList();
5131         if (pArgList != null)
5132         {
5133                 r = pArgList->Construct();
5134                 if (IsFailed(r))
5135                 {
5136                         delete pArgList;
5137                         return;
5138                 }
5139
5140                 r = pArgList->Add(*new(std::nothrow) String(*__pReaderData));
5141                 if (IsFailed(r))
5142                 {
5143                         delete pArgList;
5144                         return;
5145                 }
5146
5147                 r = pArgList->Add(*new(std::nothrow) String(__pWebViewer->GetUrl()));
5148                 if (IsFailed(r))
5149                 {
5150                         delete pArgList;
5151                         return;
5152                 }
5153
5154                 r = pArgList->Add(*new(std::nothrow) String(__pWindowInfo->pageTitle));
5155                 if (IsFailed(r))
5156                 {
5157                         delete pArgList;
5158                         return;
5159                 }
5160         }
5161
5162         SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_ARTICLE_READER, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
5163         return;
5164
5165
5166         int bodyWidth = ((double)(GetClientAreaBounds().width))*0.73;
5167
5168         CreateReaderPanel();
5169         AppLogDebug("MainScene::ReaderClicked entered");
5170
5171
5172         /*if (__pArticleReaderPanel)
5173         {
5174                 AppLogDebug("showstate true for reader panel");
5175                 __pArticleReaderPanel->SetShowState(true);
5176                 __pArticleReaderPanel->Show();
5177         }*/
5178         int xPos = __pArticleReaderPanel->GetX();
5179         int yPos = __pArticleReaderPanel->GetY();
5180         AppLog("ReaderClicked() xPos = %d",xPos);
5181         AppLog("ReaderClicked() yPos = %d",yPos);
5182
5183         if (__pReaderData == null)
5184         {
5185                 return;
5186         }
5187
5188         String loadData = L"<html>\
5189                                         <head>\
5190                                         <meta name='viewport' content='width=device-width*0.73,minimum-scale=1.0, maximum-scale=1.0, user-scalable=no'>\
5191                                         <style>\
5192                                         h1\
5193                                         {\
5194                                         font-weight:bold;\
5195                                         background-color: transparent;\
5196                                         }\
5197                                         div\
5198                                         {\
5199                                         display: block;\
5200                                         }\
5201                                         p\
5202                                         {\
5203                                         display: block; \
5204                                         }\
5205                                         img\
5206                                         {\
5207                                         margin-left:auto;\
5208                                         margin-right:auto;\
5209                                         }\
5210                                         \
5211                                         \
5212                                         </style>\
5213                                         </head>\
5214                                         <body style='width:'";
5215         loadData.Append(bodyWidth);
5216         loadData.Append(L"px'>");
5217         AppLogDebug("data->GetLength %d",__pReaderData->GetLength());
5218         loadData.Append(*__pReaderData);
5219         loadData.Append(L"</body></html>");
5220
5221         ByteBuffer buf ;
5222         buf.Construct(loadData.GetLength());
5223         AppLogDebug("data->GetLength %d",loadData.GetLength());
5224         for (int z=0;z<loadData.GetLength();z++)
5225         {
5226                 mchar b;
5227                 loadData.GetCharAt(z,b);
5228                 buf.SetByte((byte)b);
5229         }
5230
5231         buf.Flip();
5232         if (__pWebReader != null)
5233         {
5234                 __pWebReader->LoadData(L"",buf,L"text/html");
5235                 AppLogDebug("LoadData result %s",GetErrorMessage(GetLastResult()));
5236         }
5237         else
5238         {
5239                 AppLogDebug("cannot LoadData __pWebReader is null");
5240         }
5241
5242 }
5243
5244 void MainForm::SetAddressbarMode(AddressBarMode addMode)
5245 {
5246         AppLogDebug("AddressBar::setAddressbarMode to %d",addMode);
5247
5248         __currentAddMode = addMode;
5249
5250         switch(addMode)
5251         {
5252         case ADDRESSBAR_MODE_INVALID:
5253         {
5254                 // do nothing
5255         }
5256         break;
5257         case ADDRESSBAR_MODE_READER:
5258         {
5259                 __pStopBtn->SetShowState(false);
5260                 __pRefreshBtn->SetShowState(false);
5261                 __pClearBtn->SetShowState(false);
5262                 __pReaderBtn->SetShowState(false);
5263         }
5264         break;
5265         case ADDRESSBAR_MODE_LOADING:
5266         {
5267                 __pRefreshBtn->SetShowState(false);
5268                 __pStopBtn->SetShowState(true);
5269                 __pClearBtn->SetShowState(false);
5270                 __pReaderBtn->SetShowState(false);
5271         }
5272         break;
5273         case ADDRESSBAR_MODE_LOADING_COMPLETE:
5274         {
5275 //              SetUrl(__pAddressbar->GetUrl());
5276
5277                 __pRefreshBtn->SetShowState(true);
5278                 __pStopBtn->SetShowState(false);
5279                 __pClearBtn->SetShowState(false);
5280                 __pReaderBtn->SetShowState(false);
5281         }
5282         break;
5283         case ADDRESSBAR_MODE_EDIT:
5284         {
5285                 __pRefreshBtn->SetShowState(false);
5286                 __pStopBtn->SetShowState(false);
5287                 __pReaderBtn->SetShowState(false);
5288                 __pClearBtn->SetShowState(true);
5289         }
5290         break;
5291         }
5292
5293         Invalidate(true);
5294
5295         OnAddressBarModeChanged();
5296 }
5297
5298 AddressBarMode MainForm::GetAddressbarMode(void)
5299 {
5300         return __currentAddMode;
5301 }
5302
5303 void MainForm::SetUrl(const String& url)
5304 {
5305         __displayUrl = url;
5306         if(__displayUrl.GetLength() > 2048)
5307                 __displayUrl.SubString(0,2048,__displayUrl);
5308
5309         if (__pFooterUrlField != NULL)
5310         {
5311                 String removedHttpUrl = RemoveHttpTextFromDisplayURL();
5312                 if (removedHttpUrl.IsEmpty() == false)
5313                 {
5314                         __pFooterUrlField->SetText(removedHttpUrl);
5315                         if(__pAddressbar != NULL && __pAddressbar->HasCurrentFocus() == false)
5316                                 __pAddressbar->SetUrl(__displayUrl);
5317                 }
5318                 else
5319                 {
5320                         __pFooterUrlField->SetText(__displayUrl);
5321                         if(__pAddressbar != NULL && __pAddressbar->HasCurrentFocus() == false)
5322                                 __pAddressbar->SetUrl(__displayUrl);
5323                 }
5324                 if(__pFooterUrlField)
5325                         __pFooterUrlField->SetCursorPosition(__pFooterUrlField->GetTextLength());
5326                 __pFooterUrlField->Invalidate(false);
5327                 if(__pAddressbar != NULL && __pAddressbar->HasFocus())
5328                         __pAddressbar->Invalidate(true);
5329 //              __pFooterUrlField->SetCursorPosition(0);
5330         }
5331 }
5332
5333 String
5334 MainForm::RemoveHttpTextFromDisplayURL(void)
5335 {
5336         AppLog("MainForm::RemoveHttpTextFromDisplayURL __displayUrl %ls",__displayUrl.GetPointer());
5337         int index = -1;
5338 //      bool isHttpText = __displayUrl.Contains(L"http://");
5339         String updatedDisplayUrl;
5340         updatedDisplayUrl.Clear();
5341         if(__displayUrl.IndexOf(L"http://",0,index) == E_SUCCESS && index == 0)
5342         {
5343                 __displayUrl.SubString(7,updatedDisplayUrl);
5344         }
5345         else if(__displayUrl.IndexOf(L"https://",0,index) == E_SUCCESS && index == 0)
5346         {
5347                 __displayUrl.SubString(8,updatedDisplayUrl);
5348         }
5349         return updatedDisplayUrl;
5350 }
5351
5352 void MainForm::OnSharePopupControlStarted(void)
5353 {
5354         __pWebViewer->AddTouchEventListener(*this);
5355 }
5356
5357 void
5358 MainForm::OnUserEventReceivedN (RequestId requestId, Tizen::Base::Collection::IList *pArgs)
5359 {
5360         if (requestId == BACK_GROUND_APP_EVENT)
5361         {
5362                 if(__pWebViewer != null)
5363                 {
5364                         __pWebViewer->Pause();
5365                 }
5366                 if(__pAddressbar != null)
5367                 {
5368                         __pAddressbar->SendUserEvent(BACK_GROUND_APP_EVENT,NULL);
5369                 }
5370         }
5371         else if(requestId == FORE_GROUND_APP_EVENT)
5372         {
5373                 if(__pWebViewer != null)
5374                 {
5375                         __pWebViewer->Resume();
5376                 }
5377                 if(__pAddressbar != null)
5378                 {
5379                         __pAddressbar->SendUserEvent(FORE_GROUND_APP_EVENT,NULL);
5380                 }
5381         }
5382 }
5383
5384 void
5385 MainForm::AddressBarCancelledClicked(const Addressbar& addBar)
5386 {
5387         AppLog("XYZ::MainForm::AddressBarCancelledClicked");
5388         result r = E_SUCCESS;
5389
5390         if (__pAddressbar)
5391                 __pAddressbar->SetShowState(false);
5392
5393         //AppLog("akjshdasd 5");
5394         //__pFooterPanel->SetShowState(true);
5395
5396         if(__pWebViewer)
5397                 __pWebViewer->SetFocus();
5398         else if(__pMostVisitedListView)
5399                 __pMostVisitedListView->SetFocus();
5400         else if(__pMultiWindowButton)
5401                 __pMultiWindowButton->SetFocus();
5402         else if(__pMoreButton)
5403                 __pMoreButton->SetFocus();
5404
5405         __pAddressbar->SetShowState(false);
5406
5407         RelayoutControls(false);
5408 }
5409
5410 void
5411 MainForm::OnFormMenuRequested (Tizen::Ui::Controls::Form &source)
5412 {
5413         AppLog("MainForm::OnFormMenuRequested called");
5414         InitOptionMenu();
5415         if (__pWindowInfo != NULL && __pWindowInfo->pageUrl != NULL && __pWebViewer->GetShowState() == true)
5416         {
5417                 int bookmarkCount=0;
5418                 bool exist = false;
5419                 String url=L"";
5420                 url=__pWindowInfo->pageUrl;
5421                 result r = E_SUCCESS;
5422                 Bitmap* pBitmap = null;
5423
5424                 r=BookmarkPresentationModel::GetInstance()->DoesBookmarkExist(url,exist);
5425                 if (IsFailed(r))
5426                 {
5427                         AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED failed");
5428                         return;
5429                 }
5430                 if ( exist == true)
5431                 {
5432                         pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ICON_BOOKMARK_ON_TEMP);
5433                 }
5434                 else
5435                 {
5436                         pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ICON_BOOKMARK_OFF_TEMP);
5437                 }
5438                 AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED 3");
5439
5440                 if (__pOptionMenu->GetItemCount() == 9)
5441                 {
5442                         r = __pOptionMenu->SetItemAt(1,CommonUtil::GetString(L"IDS_BR_OPT_ADDTOBOOKMARKS"), IDA_ADDTOBOOKMARK_CLICKED,*pBitmap);
5443                 }
5444                 else
5445                 {
5446                         r = __pOptionMenu->InsertItemAt(1,CommonUtil::GetString(L"IDS_BR_OPT_ADDTOBOOKMARKS"), IDA_ADDTOBOOKMARK_CLICKED,*pBitmap);
5447                 }
5448
5449                 if (IsFailed(r))
5450                 {
5451                         AppLogException("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED Add to Bookmark failed with %s", GetErrorMessage(r));
5452                         delete pBitmap;
5453                         return ;
5454                 }
5455                 AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED 4");
5456                 if (__pOptionMenu->GetItemCount() != 9)
5457                 {
5458                         __pOptionMenu->InsertItemAt(1,CommonUtil::GetString(L"IDS_BR_OPT_ADDTOBOOKMARKS"), IDA_ADDTOBOOKMARK_CLICKED);
5459                         __pOptionMenu->InsertItemAt(2,CommonUtil::GetString(L"IDS_BR_BODY_PRINT"), IDA_PRINT_CLICKED);
5460 //                              __pOptionMenu->InsertItemAt(2,L"Add to Home"/*CommonUtil::GetString(L"IDS_BR_OPT_SHARE")*/, IDA_ADD_TO_HOME_CLICKED);
5461                         __pOptionMenu->InsertItemAt(3,CommonUtil::GetString(L"IDS_BR_OPT_SHARE"), IDA_SHARE_CLICKED);
5462                         __pOptionMenu->InsertItemAt(4,CommonUtil::GetString(L"IDS_BR_OPT_FIND_ON_PAGE_ABB"), IDA_FINDONPAGE_CLICKED);
5463                         __pOptionMenu->SetMaxVisibleItemsCount(6);
5464                 }
5465                 if( GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE)
5466                 {
5467                         AppLog(" Orientation landscape");
5468                         __pOptionMenu->SetMaxVisibleItemsCount(5);
5469                 }
5470                 else
5471                 {
5472                         AppLog(" Orientation potrait");
5473                         __pOptionMenu->SetMaxVisibleItemsCount(6);
5474                 }
5475
5476                 AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED 5");
5477                 delete pBitmap;
5478         }
5479         AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED end");
5480         __pOptionMenu->SetShowState(true);
5481         __pOptionMenu->Invalidate(true);
5482         __pOptionMenu->Show();
5483
5484 }