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