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