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