Fixed Nabi Issues
[apps/osp/Internet.git] / src / IntMainForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 //!Internet MainForm class
18 /*@file:        MainForm.cpp
19  *@brief:       The %MainForm provides the common functionalities for the Main View of the Browser including the addressbar,
20  *                      loading,handling events etc.
21  */
22
23 #include <FApp.h>
24 #include <FGraphics.h>
25 #include <FMedia.h>
26 #include <FUi.h>
27 #include <FContent.h>
28 #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         if(TouchEventManager::GetInstance()->GetTouchInfoListN()->GetCount() >1)
4236         {
4237                 AppLog("Returning because of more than one touch point.");
4238                 return;
4239         }
4240         __longPressPoint = currentPosition;
4241
4242         if (__pHitElementResult != null)
4243         {
4244                 delete __pHitElementResult;
4245                 __pHitElementResult = null;
4246         }
4247
4248         if (__pWebViewer != null)
4249         {
4250                 AppLog("MainForm::OnTouchLongPressed web not null");
4251                 __pHitElementResult = __pWebViewer->GetElementByPointN(currentPosition);
4252         }
4253
4254         if (__pHitElementResult == null)
4255         {
4256                 return;
4257         }
4258
4259         if (__pHitElementResult->HasImage() == true)
4260         {
4261                 if(__pWebViewer != null)
4262                         InitImageContextMenu(Point(currentPosition.x,currentPosition.y + __pWebViewer->GetY()));
4263                 __pImageMenu->SetShowState(true);
4264                 __pImageMenu->Show();
4265                 __pImageMenu->Invalidate(true);
4266         }
4267         else if(__pHitElementResult->HasUrl() == true)
4268         {
4269                 String tempURl = __pHitElementResult->GetUrl();
4270                 AppLog("tempURl is %ls", tempURl.GetPointer());
4271                 const Bitmap* pBitmap = __pHitElementResult->GetImage();
4272                 if (pBitmap != null)
4273                 {
4274                         AppLog("not null");
4275                 }
4276                 else
4277                 {
4278                         AppLog(null);
4279                 }
4280                 InitImageLinkContextMenu(Point(currentPosition.x,currentPosition.y + __pWebViewer->GetY()));
4281                 __pImageMenu->SetShowState(true);
4282                 __pImageMenu->Show();
4283                 __pImageMenu->Invalidate(true);
4284         }
4285         else
4286         {
4287                 String tagName = __pHitElementResult->GetTagName();
4288                 String type = __pHitElementResult->GetAttributeValue("type");
4289                 String value = __pHitElementResult->GetAttributeValue(L"value");
4290                 String innerHtml = __pHitElementResult->GetAttributeValue(L"innerHTML");
4291
4292                 __currentSelectedStr.Clear();
4293                 __currentSelectedStr = __pWebViewer->GetTextFromBlock();
4294
4295                 AppLog("tag name is %ls", tagName.GetPointer());
4296                 AppLog("type is %ls", type.GetPointer());
4297
4298
4299
4300                 //__isLongPressedDone = true;
4301                 result r =__pWebViewer->SetBlockSelectionPosition(currentPosition);
4302                 if (((tagName.CompareTo(L"INPUT") == 0)  || tagName.CompareTo(L"TEXTAREA") == 0) && innerHtml.GetLength() == 0 /*&& __isWebKeypadOpened == true*/ && __currentSelectedStr.CompareTo(L"") == 0 && r == E_INVALID_ARG)
4303                 {
4304                         AppLog("MainForm::OnWebPageBlockSelected show paste option");
4305
4306                         InitSelectTextContextMenu(Point(currentPosition.x , currentPosition.y + __pWebViewer->GetY()),true, true);
4307                         if(__pImageMenu)
4308                         {
4309                                 __pImageMenu->SetShowState(true);
4310                                 __pImageMenu->Show();
4311                                 __pImageMenu->Invalidate(true);
4312                         }
4313                 }
4314                 AppLog("setselectionselectedornot %s",GetErrorMessage(r));
4315
4316         }
4317 //      __inputEventToBeSupressed = true;
4318 }
4319
4320 void
4321 MainForm::OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
4322 {
4323         AppLog("xyz:: MainForm::OnTouchReleased called");
4324
4325         if (__pAddressbar && __pAddressbar->GetShowState() == true)
4326         {
4327                 __pAddressbar->SetShowState(false);
4328         }
4329
4330         // Not reuired now.
4331         /*HitElementResult* pHitElement = __pWebViewer->GetElementByPointN(currentPosition);
4332         if(pHitElement != null && pHitElement->HasUrl() == true && __inputEventToBeSupressed == true)
4333         {
4334                 __pWebViewer->ConsumeInputEvent();
4335         }
4336         if(pHitElement != null)
4337         {
4338                 delete pHitElement;
4339         }
4340         __inputEventToBeSupressed = false;*/
4341 }
4342
4343 bool
4344 MainForm::OnTouchPressed(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4345 {
4346
4347         return true;
4348 }
4349
4350 bool
4351 MainForm::OnTouchReleased(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4352 {
4353         if(__pFindWordControl && __pFindWordControl->GetShowState() == true)
4354         {
4355                 __currentSearchStr = L"";
4356                 __currentWordIndex = 0;
4357                 __maxOccurrances = 0;
4358
4359                 if (__pFindWordPanelLeftToRight && __pFindWordPanelLeftToRight->GetShowState() == true)
4360                 {
4361                         __pFindWordEditField->SetText(L"");
4362                         __pFindWordEditField->HideKeypad();
4363                         __pFindWordControl->SetShowState(false);
4364                         __pFindWordCountLabel->SetText(L"0/0");
4365                 }
4366                 else if(__pFindWordPanelRightToLeft && __pFindWordPanelRightToLeft->GetShowState() == true)
4367                 {
4368                         __pFindWordEditFieldRightToLeft->SetText(L"");
4369                         __pFindWordEditFieldRightToLeft->HideKeypad();
4370                         __pFindWordControl->SetShowState(false);
4371                         __pFindWordCountLabelRightToLeft->SetText(L"0/0");
4372                 }
4373
4374                 __pFindWordNext->SetEnabled(false);
4375                 __pFindWordPrev->SetEnabled(false);
4376
4377                 __pWebViewer->SearchText(L"aaaabbbbcccc",true);
4378                 __pFindWordControl->SetShowState(false);
4379         }
4380         if(__pAddressbar->GetShowState() == false)
4381         {
4382                 __pAddressbar->SetAddressbarURLFocus();
4383                 __pFooterPanel->SetShowState(false);
4384         }
4385
4386         return true;
4387 }
4388
4389 bool
4390 MainForm::OnTouchMoved(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4391 {
4392         return true;
4393 }
4394
4395 bool
4396 MainForm::OnTouchCanceled(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4397 {
4398         return true;
4399 }
4400
4401 bool
4402 MainForm::OnPreviewTouchPressed(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4403 {
4404         return true;
4405 }
4406
4407 bool
4408 MainForm::OnPreviewTouchReleased(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4409 {
4410         return true;
4411 }
4412
4413 bool
4414 MainForm::OnPreviewTouchMoved(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4415 {
4416         return true;
4417 }
4418
4419 void
4420 MainForm::OnOrientationChanged (const Tizen::Ui::Control &source, Tizen::Ui::OrientationStatus orientationStatus)
4421 {
4422         AppLog("MainForm::OnOrientationChanged GetClientAreaBounds %d, %d",GetClientAreaBounds().width,GetClientAreaBounds().height);
4423         int widthContextItem = 0;
4424         if(__pFindWordCountLabel)
4425                 __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),124,__pFindWordCountLabel->GetHeight());
4426         // As per the platform engineer comment removed this line
4427         /*if(__pWebViewer != null)
4428         {
4429                 // 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
4430                 __pWebViewer->ReleaseBlock();
4431         }*/
4432
4433 //      if(__pFindWordControl != null)
4434 //              ShowFindWordPanel(__pFindWordControl->GetShowState(), false);
4435         if(__pNotification && __pNotification->GetShowState() == true)
4436         {
4437                 __pNotification->SetShowState(false);
4438                 __pNotification->Invalidate(false);
4439         }
4440         if ( __pFooterLabel != null)
4441         {
4442                 Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_SEARCH_INPUT_FIELD_BG, __pFooterLabel->GetWidth(), __pFooterLabel->GetHeight());
4443                 if(pBitmap != null)
4444                 {
4445                         __pFooterLabel->SetBackgroundBitmap(*pBitmap);
4446                         delete pBitmap;
4447                 }
4448
4449
4450         }
4451         if (__pFindWordBgLabel != null)
4452         {
4453                 Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_FINDWORD_INPUT_FIELD_BG, __pFindWordBgLabel->GetWidth(), __pFindWordBgLabel->GetHeight());
4454                 if (pBitmap != null)
4455                 {
4456                         __pFindWordBgLabel->SetBackgroundBitmap(*pBitmap);
4457                         delete pBitmap;
4458                 }
4459         }
4460
4461         if (__pFindWordBgLabelRightToLeft != null)
4462         {
4463                 Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_FINDWORD_INPUT_FIELD_BG, __pFindWordBgLabelRightToLeft->GetWidth(), __pFindWordBgLabelRightToLeft->GetHeight());
4464                 if (pBitmap != null)
4465                 {
4466                         __pFindWordBgLabelRightToLeft->SetBackgroundBitmap(*pBitmap);
4467                         delete pBitmap;
4468                 }
4469         }
4470
4471
4472         if(__pOptionMenu != null)
4473                 __pOptionMenu->SetShowState(false);
4474
4475         if( GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
4476         {
4477                 widthContextItem = WIDTH_CONTEXT_MENU_BUTTON_LANDSCAPE;
4478         }
4479         else
4480         {
4481                 widthContextItem = WIDTH_CONTEXT_MENU_BUTTON_PORTRAIT;
4482         }
4483
4484         if (__pFooterPanel)
4485         {
4486                 AppLog("__pFooterPanel->GetShowState() is true");
4487                 InitFooter();
4488                 __pFooterPanel->SetBounds(0, GetClientAreaBounds().height - __pFooterPanel->GetHeight(), __pFooterPanel->GetWidth(), __pFooterPanel->GetHeight());
4489                 __pFooterPanel->Invalidate(true);
4490         }
4491         InitAddressbar();
4492
4493         String homePage = SettingPresentationModel::GetInstance()->GetHomepage();
4494         if (homePage.CompareTo((L"IDS_BR_BODY_MOST_VISITED_SITES")) == 0)
4495         {
4496                 InitMostVisitedSitesView(orientationStatus);
4497         }
4498
4499         RelayoutControls(false);
4500         if (__pArticleReaderPanel != null)
4501         {
4502                 if (__pArticleReaderPanel->GetShowState() == true)
4503                 {
4504                         __pArticleReaderPanel->SetBounds((GetClientAreaBounds().width - __pArticleReaderPanel->GetWidth())/2,(GetClientAreaBounds().height - __pArticleReaderPanel->GetHeight())/2, __pArticleReaderPanel->GetWidth(), __pArticleReaderPanel->GetHeight());
4505
4506                         if (__pBlankPanel != null)
4507                                 __pBlankPanel->SetBounds(0,0,GetClientAreaBounds().width,GetClientAreaBounds().height);
4508
4509                         if (__pWebReader != null)
4510                         {
4511                                 __pWebReader->SetBounds(Rectangle(2,2, __pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight() - 96));
4512                         }
4513                         Bitmap* pBitmap = CommonUtil::GetNinepatchedBitmapN(L"I01_popup_bg.9.png",__pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight());
4514                         Bitmap* pSrcBitmap = CommonUtil::GetNinepatchedBitmapN(L"I01_popup_bottom_bg.9.png",__pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight());
4515
4516                         if ( pBitmap != null && pSrcBitmap != null)
4517                         {
4518                                 AppLog("CreateReaderPanel ninepatchbitmap found");
4519                                 pBitmap->Merge(Point(0,__pArticleReaderPanel->GetHeight() - 96),*pSrcBitmap,Rectangle(0,0,pSrcBitmap->GetWidth(),pSrcBitmap->GetHeight()));
4520                         }
4521
4522                         __pArticleReaderLabel->SetBounds(Rectangle(__pArticleReaderPanel->GetX(),__pArticleReaderPanel->GetY(),__pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight()));
4523                         __pArticleReaderLabel->SetBackgroundBitmap(*pBitmap);
4524                         if (pBitmap != null)
4525                         {
4526                                 delete pBitmap;
4527                                 pBitmap = null;
4528                         }
4529                         if (pSrcBitmap != null)
4530                         {
4531                                 delete pSrcBitmap;
4532                                 pSrcBitmap = null;
4533                         }
4534                 }
4535         }
4536         Invalidate(true);
4537         
4538     if (__pAddressbar != null)
4539         {
4540                 int width = GetClientAreaBounds().width;
4541                 __pAddressbar->OrientationChanged(width);
4542         }
4543 }
4544
4545 void
4546 MainForm::OnSettingsChange(int settingvalue)
4547 {
4548         AppLogDebug("MainForm::OnSettingsChange entered");
4549
4550         if(settingvalue == (int)REGISTRY_SETTING_HOMEPAGE)
4551         {
4552                 __pAddressbar->ResetGuideText();
4553         }
4554         if (__pWebViewer == null)
4555         {
4556                 AppLogDebug("Webviewer is not initialized yet.");
4557                 return;
4558         }
4559
4560         if (settingvalue == (int) REGISTRY_SETTING_DEFAULT_VIEW)
4561         {
4562                 WebSetting settings = __pWebViewer->GetSetting();
4563                 if (SettingPresentationModel::GetInstance()->GetDefaultView().CompareTo((L"IDS_BR_BODY_FIT_TO_WIDTH")) == 0)
4564                 {
4565                         settings.SetAutoFittingEnabled(true);
4566                 }
4567                 else if (SettingPresentationModel::GetInstance()->GetDefaultView().CompareTo((L"IDS_BR_BODY_READABLE")) == 0)
4568                 {
4569                         settings.SetAutoFittingEnabled(false);
4570                 }
4571                 __pWebViewer->SetSetting(settings);
4572         }
4573         else if (settingvalue == (int) REGISTRY_SETTING_RUN_JAVASCRIPT)
4574         {
4575                 WebSetting settings = __pWebViewer->GetSetting();
4576                 settings.SetJavascriptEnabled(SettingPresentationModel::GetInstance()->IsRunJavascriptEnabled());
4577                 __pWebViewer->SetSetting(settings);
4578         }
4579         else if (settingvalue == (int) REGISTRY_SETTING_DISPLAY_IMAGES)
4580         {
4581                 WebSetting settings = __pWebViewer->GetSetting();
4582                 settings.SetAutoImageLoadEnabled(SettingPresentationModel::GetInstance()->IsDisplayImagesEnabled());
4583                 __pWebViewer->SetSetting(settings);
4584                 __pWebViewer->Reload();
4585         }
4586         else if (settingvalue == (int) REGISTRY_SETTING_BLOCK_POPUP)
4587         {
4588                 WebSetting settings = __pWebViewer->GetSetting();
4589                 settings.SetJavaScriptPopupEnabled(SettingPresentationModel::GetInstance()->IsBlockPopUp());
4590                 __pWebViewer->SetSetting(settings);
4591         }
4592         else if (settingvalue == (int) REGISTRY_SETTING_ACCEPT_COOKIES)
4593         {
4594                 if (__pWebViewer)
4595                 {
4596                         __pWebViewer->SetCookieEnabled(SettingPresentationModel::GetInstance()->IsCookiesEnabled());
4597                 }
4598         }
4599         else if(settingvalue == (int) REGISTRY_SETTING_REMEMBER_FORM_DATA)
4600         {
4601                 if (__pWebViewer)
4602                 {
4603                         WebSetting settings = __pWebViewer->GetSetting();
4604                         settings.SetAutoFormDataShowEnabled(SettingPresentationModel::GetInstance()->IsRememberFormData());
4605                         __pWebViewer->SetSetting(settings);
4606                 }
4607         }
4608         else if(settingvalue == (int) REGISTRY_SETTING_REMEMBER_PASSWORD)
4609         {
4610                 if (__pWebViewer)
4611                 {
4612                         WebSetting settings = __pWebViewer->GetSetting();
4613                         settings.SetAutoLoginFormFillEnabled(SettingPresentationModel::GetInstance()->IsRememberPassword());
4614                         __pWebViewer->SetSetting(settings);
4615                 }
4616         }
4617         else if (settingvalue == (int) REGISTRY_SETTING_SHOW_SECURITY_WARNINGS)
4618         {
4619                 WebSetting settings = __pWebViewer->GetSetting();
4620                 if (SettingPresentationModel::GetInstance()->IsSecurityWarningsEnabled() == true)
4621                 {
4622                         settings.SetCertificateErrorHandlingMode(WEB_CERTIFICATE_ERROR_HANDLING_MODE_USER_CONFIRM);
4623                 }
4624                 else
4625                 {
4626                         settings.SetCertificateErrorHandlingMode(WEB_CERTIFICATE_ERROR_HANDLING_MODE_CONTINUE);
4627                 }
4628                 __pWebViewer->SetSetting(settings);
4629         }
4630         else if (settingvalue == (int) REGISTRY_SETTING_READER_FONT_SIZE)
4631         {
4632                 if (__pWebReader)
4633                 {
4634                         AppLogDebug("IntMainForm fontsize Changed to %d",SettingPresentationModel::GetInstance()->GetReaderFontSize());
4635                         WebSetting settings = __pWebReader->GetSetting();
4636                         settings.SetFontSize(SettingPresentationModel::GetInstance()->GetReaderFontSize());
4637                         __pWebReader->SetSetting(settings);
4638                 }
4639         }
4640 }
4641
4642 void
4643 MainForm::OnSettingsReset()
4644 {
4645         if (__pWebViewer)
4646         {
4647                 __pWebViewer->SetCookieEnabled(SettingPresentationModel::GetInstance()->IsCookiesEnabled());
4648                 __pWebViewer->SetSetting(SettingPresentationModel::GetInstance()->GetWebSettings());
4649         }
4650 }
4651
4652 void
4653 MainForm::OnClearCache()
4654 {
4655         result r = E_SUCCESS;
4656
4657         if (__pWebViewer != NULL)
4658         {
4659                 r = __pWebViewer->ClearCache();
4660                 if (r == E_SUCCESS)
4661                 {
4662                         AppLogDebug("Cache cleared success");
4663                 }
4664                 else
4665                 {
4666                         AppLogDebug("Cache cleared fail");
4667                 }
4668         }
4669 }
4670
4671 void
4672 MainForm::OnClearCookie()
4673 {
4674         result r = E_SUCCESS;
4675
4676         if (__pWebViewer != NULL)
4677         {
4678                 __pWebViewer->ClearCookie();
4679         }
4680         if (r == E_SUCCESS)
4681         {
4682                 AppLogDebug("Cookie cleared success");
4683         }
4684         else
4685         {
4686                 AppLogDebug("Cache cleared fail");
4687         }
4688 }
4689
4690 void
4691 MainForm::OnClearFormData()
4692 {
4693         result r = E_SUCCESS;
4694
4695         if (__pWebViewer != NULL)
4696         {
4697                 __pWebViewer->ClearFormData();
4698         }
4699         if (r == E_SUCCESS)
4700         {
4701                 AppLogDebug("Cookie cleared success");
4702         }
4703         else
4704         {
4705                 AppLogDebug("Cache cleared fail");
4706         }
4707 }
4708
4709 void
4710 MainForm::OnClearPasswords()
4711 {
4712         result r = E_SUCCESS;
4713
4714         if (__pWebViewer != NULL)
4715         {
4716                 __pWebViewer->ClearLoginFormData();
4717         }
4718         if (r == E_SUCCESS)
4719         {
4720                 AppLogDebug("Cookie cleared success");
4721         }
4722         else
4723         {
4724                 AppLogDebug("Cache cleared fail");
4725         }
4726 }
4727
4728
4729 double
4730 MainForm::findDistance(int x1,int y1,int x2, int y2)
4731 {
4732         int deltaX = Math::Abs(x2 - x1);
4733         int deltaY = Math::Abs(y2 - y1);
4734         double num = deltaX*deltaX + deltaY*deltaY;
4735
4736         if (num >= 0)
4737         {
4738                 double x = num;
4739                 int i;
4740                 for (i = 0; i < 20; i++)
4741                 {
4742                         x = (((x*x)+ num)/(2*x));
4743                 }
4744                 return num;
4745         }
4746         else
4747         {
4748                 return 0.0;
4749         }
4750 }
4751
4752 void
4753 MainForm::OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
4754 {
4755         AppLog("xyz:: MainForm::OnTouchPressed called");
4756         if(__pFindWordControl)
4757         {
4758                 AppLog("MainForm::OnTouchPressed %d",__pFindWordControl->GetShowState());
4759 //              ShowFindWordPanel(__pFindWordControl->GetShowState(), true);
4760         }
4761         //__isLongPressedDone = false;
4762
4763
4764
4765         Touch touch;
4766         IList* pList = null;
4767         pList = touch.GetTouchInfoListN(source);
4768
4769         if (pList != null)
4770         {
4771                 int count = pList->GetCount();
4772                 if (count == 1)
4773                 {
4774                         TouchInfo* pTouchInfo = static_cast<TouchInfo*>(pList->GetAt(0));
4775                         __touchPoint1 = pTouchInfo->position;
4776
4777                         /*if (__pAddressbar != null)
4778                         {
4779                                 if (__pAddressbar->GetAddressbarMode() != ADDRESSBAR_MODE_LOADING_COMPLETE && __pAddressbar->GetAddressbarMode() != ADDRESSBAR_MODE_LOADING)
4780                                 {
4781                                         if (__pAddressbar->GetAddressbarMode() == ADDRESSBAR_MODE_EDIT)
4782                                         {
4783                                                 __pAddressbar->SaveAddressbarEditText();
4784                                         }
4785                                         __pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
4786                                 }
4787
4788                                 __pAddressbar->Invalidate(true);
4789                         }*/
4790                         if (GetAddressbarMode() != ADDRESSBAR_MODE_LOADING_COMPLETE && GetAddressbarMode() != ADDRESSBAR_MODE_LOADING)
4791                         {
4792                                 if (GetAddressbarMode() == ADDRESSBAR_MODE_EDIT)
4793                                 {
4794                                         //__pAddressbar->SaveAddressbarEditText();
4795                                 }
4796                                 SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
4797                         }
4798                 }
4799                 else if (count == 2)
4800                 {
4801                         AppLogDebug("MainForm::OnTouchPressed count is two");
4802                         TouchInfo* pTouchInfo = static_cast<TouchInfo*>(pList->GetAt(0));
4803                         __touchPoint1 = pTouchInfo->position;
4804
4805                         pTouchInfo = static_cast<TouchInfo*>(pList->GetAt(1));
4806                         __touchPoint2 = pTouchInfo->position;
4807                 }
4808         }
4809         if( pList != NULL)
4810         {
4811                 pList->RemoveAll(true);
4812                 delete pList;
4813         }
4814         if(__pAddressbar)
4815                 __pAddressbar->SetShowState(false);
4816         RelayoutControls(false);
4817         return;
4818 }
4819
4820 void
4821 MainForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
4822 {
4823 //      __currentWordIndex = 0;
4824         //__isLongPressedDone = false;
4825
4826 }
4827
4828 void
4829 MainForm::MoveUiControls()
4830 {
4831 }
4832
4833 void
4834 MainForm::OnTextValueChanged (const Tizen::Ui::Control &source)
4835 {
4836         if(&source == dynamic_cast<Control*>(__pFooterUrlField) && __pFooterUrlField != null)
4837         {
4838                 if(__pFooterUrlField->GetTextLength() == 0)
4839                 {
4840                         __pFooterUrlField->SetKeypadActionEnabled(false);
4841                 }
4842                 else
4843                 {
4844                         __pFooterUrlField->SetKeypadActionEnabled(true);
4845                 }
4846         }
4847         if (__pFindWordEditField != null && __pFindWordEditField->GetShowState() == true)
4848         {
4849                 __currentSearchStr = __pFindWordEditField->GetText();
4850                 if (__currentSearchStr.GetLength() > 0)
4851                 {
4852                         __pFindWordCountLabel->SetShowState(true);
4853                 }
4854                 else
4855                 {
4856                         __pFindWordCountLabel->SetShowState(false);
4857                 }
4858                 __pFindWordNext->SetEnabled(false);
4859                 __pFindWordPrev->SetEnabled(false);
4860                 __pFindWordNext->Invalidate(true);
4861                 __pFindWordPrev->Invalidate(true);
4862                 __pFindWordCountLabel->SetText(L"0/0");
4863                 __pFindWordCountLabel->Invalidate(true);
4864         }
4865         else if (__pFindWordEditFieldRightToLeft != null && __pFindWordEditFieldRightToLeft->GetShowState() == true)
4866         {
4867                 __currentSearchStr = __pFindWordEditFieldRightToLeft->GetText();
4868                 if (__currentSearchStr.GetLength() > 0)
4869                 {
4870                         __pFindWordCountLabelRightToLeft->SetShowState(true);
4871                 }
4872                 else
4873                 {
4874                         __pFindWordCountLabelRightToLeft->SetShowState(false);
4875                 }
4876
4877                 __pFindWordNext->SetEnabled(false);
4878                 __pFindWordPrev->SetEnabled(false);
4879                 __pFindWordNext->Invalidate(true);
4880                 __pFindWordPrev->Invalidate(true);
4881                 __pFindWordCountLabelRightToLeft->SetText(L"0/0");
4882                 __pFindWordCountLabelRightToLeft->Invalidate(true);
4883         }
4884         AppLog("__currentSearchStr %ls",__currentSearchStr.GetPointer());
4885         if (__currentSearchStr.GetLength() > 0)
4886         {
4887                 StartWordSearch();
4888         }
4889         else
4890         {
4891                 __currentSearchStr = L"aaaaaaaabbbbbbbccccccc";
4892                 StartWordSearch();
4893                 __currentSearchStr = L"";
4894                 AppLogDebug("Enter something");
4895         }
4896 }
4897
4898 result
4899 MainForm::InitMostVisitedSitesPanel(Tizen::Ui::OrientationStatus orientationStatus)
4900 {
4901         return E_SUCCESS;
4902
4903 }
4904
4905 result
4906 MainForm::InitMostVisitedSitesView(Tizen::Ui::OrientationStatus orientationStatus)
4907 {
4908         if(__pWebViewer != null)
4909                 return E_SUCCESS;
4910
4911         AppLog("MainForm::InitMostVisitedSitesView");
4912         result r = E_SUCCESS;
4913
4914
4915         if (__pWebViewer != null && __pMostVisitedListView != null)
4916         {
4917                 return E_SUCCESS;
4918         }
4919
4920         if (__pMostVisitedListView != null)
4921         {
4922                 RemoveControl(__pMostVisitedListView);
4923         }
4924         if(__pMostVisitedSites != null)
4925         {
4926                 __pMostVisitedSites->RemoveAll(true);
4927         }
4928
4929         HistoryPresentationModel::GetInstance()->GetMostVisitedSites(*__pMostVisitedSites);
4930
4931         __webControlHeight = GetClientAreaBounds().height - __pFooterPanel->GetHeight();
4932         __pMostVisitedListView = new(std::nothrow) ListView();
4933
4934         int height = GetClientAreaBounds().height;
4935
4936         if(__pFooterPanel->GetShowState() == true)
4937         {
4938                 height = height - __pFooterPanel->GetHeight();
4939         }
4940         if(__pAddressbar->GetShowState() == true)
4941         {
4942                 height -= __pAddressbar->GetHeight();
4943         }
4944
4945         r = __pMostVisitedListView->Construct(Tizen::Graphics::Rectangle(0,0 , GetClientAreaBounds().width, height),true,false);
4946
4947         if (r != E_SUCCESS)
4948         {
4949                 delete __pMostVisitedListView;
4950                 AppLogDebug("Addressbar init failed with %s", GetErrorMessage(r));
4951                 return r;
4952         }
4953         __pMostVisitedListView->SetItemProvider(*this);
4954         __pMostVisitedListView->AddListViewItemEventListener(*this);
4955         __pMostVisitedListView->SetTextOfEmptyList(CommonUtil::GetString(L"IDS_BR_BODY_NO_RECENTLY_VISITED_SITES"));
4956         AddControl(__pMostVisitedListView);
4957         __pMostVisitedListView->UpdateList();
4958
4959         return E_SUCCESS;
4960
4961 }
4962
4963 String
4964 MainForm::GetImagePath(void)
4965 {
4966
4967         String str;
4968         String formattedTime;
4969         DateTime currentTime;
4970         LocaleManager localManager;
4971         SystemTime::GetCurrentTime(TIME_MODE_WALL, currentTime);
4972
4973         localManager.Construct();
4974         Locale locale = localManager.GetSystemLocale();
4975         //Locale locale(LANGUAGE_ENG, COUNTRY_US);
4976
4977         // Get date formatter
4978         DateTimeFormatter* pTimeFormatter = DateTimeFormatter::CreateDateTimeFormatterN(locale, DATE_TIME_STYLE_DEFAULT);
4979
4980         if (pTimeFormatter)
4981         {
4982                 pTimeFormatter->Format(currentTime, formattedTime);
4983         }
4984
4985         AppLog("current time stamp is %ls", formattedTime.GetPointer());
4986         String delim(L" :");
4987         StringTokenizer strTok(formattedTime, delim);
4988         String token;
4989         String imageName;
4990         String str1("GMT+00");
4991         while (strTok.HasMoreTokens())
4992         {
4993                 strTok.GetNextToken(token); // Osp, StringTokenizer, Sample, code
4994                 if(token.Equals(str1))
4995                         break;
4996                 AppLog("token is %ls", token.GetPointer());
4997                 imageName.Append(token);
4998         }
4999         return imageName;
5000
5001 }
5002
5003 void MainForm::UpdateImageContent(ByteBuffer* aBuffer, String imageName)
5004 {
5005         result r = E_FAILURE;
5006         AppLog("Content manager 1");
5007         ContentId contentId;
5008         ContentManager contentManager;
5009         r = contentManager.Construct();
5010         if(IsFailed(r))
5011         {
5012                 AppLog("Content manager update content result %s" ,GetErrorMessage(r));
5013                 return;
5014         }
5015         Tizen::Base::String contentPath = Tizen::System::Environment::GetMediaPath() + L"Downloads/";
5016         Tizen::Io::Directory::Create(contentPath,true);
5017         if(GetLastResult() == E_FILE_ALREADY_EXIST)
5018         {
5019                 AppLog("Already exists");
5020         }
5021         else if(GetLastResult() == E_SUCCESS)
5022         {
5023                 AppLog("created success");
5024         }
5025         contentPath.Append(imageName);
5026         contentPath.Append(".jpg");
5027         contentId = contentManager.CreateContent(*aBuffer, contentPath);
5028         ShowIndicatorNotification(L"Download Complete");
5029         AppLog("Content manager update content result %s" ,GetErrorMessage(GetLastResult()));
5030 }
5031
5032 void
5033 MainForm::ShowIndicatorNotification(const String& messageText)
5034 {
5035         AppLogDebug("ENTER");
5036
5037         NotificationRequest request;
5038         request.SetAlertText(messageText);
5039         request.SetTitleText(L"");
5040         request.SetAppMessage(L"AppMessage");
5041
5042         Tizen::App::App* pApp = Tizen::App::App::GetInstance();
5043         String homePath = pApp->GetAppRootPath();
5044         String iconPath = homePath + L"res/screen-density-xhigh/Notification_download_complete.png";
5045         AppLog("The iconPath is : %ls", homePath.GetPointer());
5046         request.SetIconFilePath(iconPath);
5047
5048         Tizen::Shell::NotificationManager notiMgr;
5049         notiMgr.Construct();
5050         notiMgr.Notify(request);
5051
5052         AppLogDebug("EXIT: %s", GetErrorMessage(GetLastResult()));
5053         return;
5054 }
5055
5056 void
5057 MainForm::SetForwardButtonEnabled(bool isEnabled)
5058 {
5059         __pGoForwardBtn->SetEnabled(isEnabled);
5060         __pGoForwardBtn->Invalidate(true);
5061 }
5062
5063 void
5064 MainForm::SetBackButtonEnabled(bool isEnabled)
5065 {
5066         __pGoBackBtn->SetEnabled(isEnabled);
5067         __pGoBackBtn->Invalidate(true);
5068 }
5069
5070 void
5071 MainForm::UpdateProgress(int percentage)
5072 {
5073         __progressPercentage = percentage;
5074         if (percentage == 0 || percentage == 100)
5075         {
5076                 __isLoadingData = false;
5077                 if (percentage == 100)
5078                 {
5079                         __isLoadingCompleted = true;
5080                         __progressPercentage = 0;
5081                 }
5082                 else
5083                 {
5084                         __isLoadingCompleted = false;
5085                 }
5086         }
5087         else
5088         {
5089                 __isLoadingData = true;
5090         }
5091         UpdateProgressBitmap();
5092 }
5093
5094 int
5095 MainForm::GetProgress(void)
5096 {
5097         return __progressPercentage;
5098 }
5099
5100 void
5101 MainForm::UpdateProgressBitmap(void)
5102 {
5103         result r = E_SUCCESS;
5104         if (__pProgressbarLabel == null)
5105                 return;
5106         int w = __pProgressbarLabel->GetWidth();
5107         int h = __pProgressbarLabel->GetHeight();
5108         Canvas canvas;
5109         int progressWidth = 0;
5110         Bitmap* pRetBitmap = null;
5111
5112         if (__progressPercentage == 0 || __progressPercentage == 100)
5113         {
5114                 __pProgressbarLabel->SetShowState(false);
5115                 __pProgressbarLabel->Invalidate(false);
5116                 return;
5117         }
5118         else
5119         {
5120                 __pProgressbarLabel->SetShowState(true);
5121                 __pProgressbarLabel->Invalidate(false);
5122         }
5123
5124         r = canvas.Construct(Rectangle(0, 0, w, h));
5125
5126         if (r != E_SUCCESS)
5127         {
5128                 AppLogException("Canvas construction failed with %s", GetErrorMessage(r));
5129                 return;
5130         }
5131
5132         canvas.Clear();
5133         Bitmap *pBgBmp = AppResource::GetInstance()->GetBitmapN(IDB_TITLE_PROGRESS_BAR_BG);
5134
5135         if (pBgBmp != null)
5136         {
5137                 pBgBmp->Scale(Dimension(w, h));
5138                 canvas.DrawBitmap(Point(0,0), *pBgBmp);
5139                 delete pBgBmp;
5140         }
5141
5142         progressWidth = (double) (w) * __progressPercentage / 100;
5143         AppLogDebug("progressWidth: %d", progressWidth);
5144         Bitmap *pProgressBmp = AppResource::GetInstance()->GetBitmapN(IDB_TITLE_PROGRESS_BAR);
5145
5146         if (pProgressBmp != null)
5147         {
5148                 pProgressBmp->Scale(Dimension(progressWidth, h));
5149                 canvas.DrawBitmap(Point(0,0), *pProgressBmp);
5150                 delete pProgressBmp;
5151         }
5152
5153         pRetBitmap = new (std::nothrow) Bitmap();
5154
5155         if (pRetBitmap == null)
5156         {
5157                 AppLogException("Bitmap creation failed with %s", GetErrorMessage(r));
5158                 return;
5159         }
5160
5161         pRetBitmap->Construct(canvas, canvas.GetBounds());
5162
5163         if (__pProgressbarLabel != null && pRetBitmap != null)
5164         {
5165                 __pProgressbarLabel->SetBackgroundBitmap(*pRetBitmap);
5166                 __pProgressbarLabel->Invalidate(false);
5167         }
5168
5169         if (pRetBitmap != null)
5170         {
5171                 delete pRetBitmap;
5172                 pRetBitmap = null;
5173         }
5174         return;
5175 }
5176
5177 void
5178 MainForm::ReaderClicked()
5179 {
5180         result r = E_SUCCESS;
5181         ArrayList* pArgList = new(std::nothrow) ArrayList();
5182         if (pArgList != null)
5183         {
5184                 r = pArgList->Construct();
5185                 if (IsFailed(r))
5186                 {
5187                         delete pArgList;
5188                         return;
5189                 }
5190
5191                 r = pArgList->Add(*new(std::nothrow) String(*__pReaderData));
5192                 if (IsFailed(r))
5193                 {
5194                         delete pArgList;
5195                         return;
5196                 }
5197
5198                 r = pArgList->Add(*new(std::nothrow) String(__pWebViewer->GetUrl()));
5199                 if (IsFailed(r))
5200                 {
5201                         delete pArgList;
5202                         return;
5203                 }
5204
5205                 r = pArgList->Add(*new(std::nothrow) String(__pWindowInfo->pageTitle));
5206                 if (IsFailed(r))
5207                 {
5208                         delete pArgList;
5209                         return;
5210                 }
5211         }
5212
5213         SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_ARTICLE_READER, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
5214         return;
5215
5216
5217 }
5218
5219 void MainForm::SetAddressbarMode(AddressBarMode addMode)
5220 {
5221         AppLogDebug("AddressBar::setAddressbarMode to %d",addMode);
5222
5223         __currentAddMode = addMode;
5224
5225         switch(addMode)
5226         {
5227         case ADDRESSBAR_MODE_INVALID:
5228         {
5229                 // do nothing
5230         }
5231         break;
5232         case ADDRESSBAR_MODE_READER:
5233         {
5234                 __pStopBtn->SetShowState(false);
5235                 __pRefreshBtn->SetShowState(false);
5236                 __pClearBtn->SetShowState(false);
5237                 __pReaderBtn->SetShowState(false);
5238         }
5239         break;
5240         case ADDRESSBAR_MODE_LOADING:
5241         {
5242                 __pRefreshBtn->SetShowState(false);
5243                 __pStopBtn->SetShowState(true);
5244                 __pClearBtn->SetShowState(false);
5245                 __pReaderBtn->SetShowState(false);
5246         }
5247         break;
5248         case ADDRESSBAR_MODE_LOADING_COMPLETE:
5249         {
5250 //              SetUrl(__pAddressbar->GetUrl());
5251
5252                 __pRefreshBtn->SetShowState(true);
5253                 __pStopBtn->SetShowState(false);
5254                 __pClearBtn->SetShowState(false);
5255                 __pReaderBtn->SetShowState(false);
5256         }
5257         break;
5258         case ADDRESSBAR_MODE_EDIT:
5259         {
5260                 __pRefreshBtn->SetShowState(false);
5261                 __pStopBtn->SetShowState(false);
5262                 __pReaderBtn->SetShowState(false);
5263                 __pClearBtn->SetShowState(true);
5264         }
5265         break;
5266         }
5267
5268         Invalidate(true);
5269
5270         OnAddressBarModeChanged();
5271 }
5272
5273 AddressBarMode MainForm::GetAddressbarMode(void)
5274 {
5275         return __currentAddMode;
5276 }
5277
5278 void MainForm::SetUrl(const String& url)
5279 {
5280         __displayUrl = url;
5281         if(__displayUrl.GetLength() > 2048)
5282                 __displayUrl.SubString(0,2048,__displayUrl);
5283
5284         if (__pFooterUrlField != NULL)
5285         {
5286                 String removedHttpUrl = RemoveHttpTextFromDisplayURL();
5287                 if (removedHttpUrl.IsEmpty() == false)
5288                 {
5289                         __pFooterUrlField->SetText(removedHttpUrl);
5290                         if(__pAddressbar != NULL && __pAddressbar->HasCurrentFocus() == false)
5291                                 __pAddressbar->SetUrl(__displayUrl);
5292                 }
5293                 else
5294                 {
5295                         __pFooterUrlField->SetText(__displayUrl);
5296                         if(__pAddressbar != NULL && __pAddressbar->HasCurrentFocus() == false)
5297                                 __pAddressbar->SetUrl(__displayUrl);
5298                 }
5299                 if(__pFooterUrlField)
5300                         __pFooterUrlField->SetCursorPosition(__pFooterUrlField->GetTextLength());
5301                 __pFooterUrlField->Invalidate(false);
5302                 if(__pAddressbar != NULL && __pAddressbar->HasFocus())
5303                         __pAddressbar->Invalidate(true);
5304 //              __pFooterUrlField->SetCursorPosition(0);
5305         }
5306 }
5307
5308 String
5309 MainForm::RemoveHttpTextFromDisplayURL(void)
5310 {
5311         AppLog("MainForm::RemoveHttpTextFromDisplayURL __displayUrl %ls",__displayUrl.GetPointer());
5312         int index = -1;
5313 //      bool isHttpText = __displayUrl.Contains(L"http://");
5314         String updatedDisplayUrl;
5315         updatedDisplayUrl.Clear();
5316         if(__displayUrl.IndexOf(L"http://",0,index) == E_SUCCESS && index == 0)
5317         {
5318                 __displayUrl.SubString(7,updatedDisplayUrl);
5319         }
5320         else if(__displayUrl.IndexOf(L"https://",0,index) == E_SUCCESS && index == 0)
5321         {
5322                 __displayUrl.SubString(8,updatedDisplayUrl);
5323         }
5324         return updatedDisplayUrl;
5325 }
5326
5327 void MainForm::OnSharePopupControlStarted(void)
5328 {
5329         __pWebViewer->AddTouchEventListener(*this);
5330 }
5331
5332 void
5333 MainForm::OnUserEventReceivedN (RequestId requestId, Tizen::Base::Collection::IList *pArgs)
5334 {
5335         if (requestId == BACK_GROUND_APP_EVENT)
5336         {
5337                 if(__pWebViewer != null)
5338                 {
5339                         __pWebViewer->Pause();
5340                 }
5341                 if(__pAddressbar != null)
5342                 {
5343                         __pAddressbar->SendUserEvent(BACK_GROUND_APP_EVENT,NULL);
5344                 }
5345         }
5346         else if(requestId == FORE_GROUND_APP_EVENT)
5347         {
5348                 if(__pWebViewer != null)
5349                 {
5350                         __pWebViewer->Resume();
5351                 }
5352                 if(__pAddressbar != null)
5353                 {
5354                         __pAddressbar->SendUserEvent(FORE_GROUND_APP_EVENT,NULL);
5355                 }
5356         }
5357 }
5358
5359 void
5360 MainForm::AddressBarCancelledClicked(const Addressbar& addBar)
5361 {
5362         AppLog("XYZ::MainForm::AddressBarCancelledClicked");
5363         result r = E_SUCCESS;
5364
5365         if (__pAddressbar)
5366                 __pAddressbar->SetShowState(false);
5367
5368         //AppLog("akjshdasd 5");
5369         //__pFooterPanel->SetShowState(true);
5370
5371         if(__pWebViewer)
5372                 __pWebViewer->SetFocus();
5373         else if(__pMostVisitedListView)
5374                 __pMostVisitedListView->SetFocus();
5375         else if(__pMultiWindowButton)
5376                 __pMultiWindowButton->SetFocus();
5377         else if(__pMoreButton)
5378                 __pMoreButton->SetFocus();
5379
5380         __pAddressbar->SetShowState(false);
5381
5382         RelayoutControls(false);
5383 }
5384
5385 void
5386 MainForm::OnFormMenuRequested (Tizen::Ui::Controls::Form &source)
5387 {
5388         AppLog("MainForm::OnFormMenuRequested called");
5389         InitOptionMenu();
5390         if (__pWindowInfo != NULL && __pWindowInfo->pageUrl != NULL && __pWebViewer->GetShowState() == true)
5391         {
5392                 int bookmarkCount=0;
5393                 bool exist = false;
5394                 String url=L"";
5395                 url=__pWindowInfo->pageUrl;
5396                 AppLog("MainForm::OnFormMenuRequested url %ls",url.GetPointer());
5397                 result r = E_SUCCESS;
5398                 Bitmap* pBitmap = null;
5399                 String lastChar = L"";
5400                 if(url.SubString(url.GetLength()-1,lastChar));
5401 //              if(lastChar == L"/")
5402 //              {
5403 //                      bool exist1 = false;
5404 //                      bool exist2 = false;
5405 //                      r=BookmarkPresentationModel::GetInstance()->DoesBookmarkExist(url,exist1);
5406 //                      url.SubString(0,url.GetLength() - 1,url);
5407 //                      r=BookmarkPresentationModel::GetInstance()->DoesBookmarkExist(url,exist2);
5408 //                      exist = exist1 | exist2;
5409 //              }
5410 //              else
5411 //              {
5412                         r=BookmarkPresentationModel::GetInstance()->DoesBookmarkExist(url,exist);
5413                         if (IsFailed(r))
5414                         {
5415                                 AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED failed");
5416                                 return;
5417                         }
5418 //              }
5419                 if ( exist == true)
5420                 {
5421                         pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ICON_BOOKMARK_ON_TEMP);
5422                 }
5423                 else
5424                 {
5425                         pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ICON_BOOKMARK_OFF_TEMP);
5426                 }
5427                 AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED 3");
5428
5429                 if (__pOptionMenu->GetItemCount() == 9)
5430                 {
5431                         r = __pOptionMenu->SetItemAt(1,CommonUtil::GetString(L"IDS_BR_OPT_ADDTOBOOKMARKS"), IDA_ADDTOBOOKMARK_CLICKED,*pBitmap);
5432                 }
5433                 else
5434                 {
5435                         r = __pOptionMenu->InsertItemAt(1,CommonUtil::GetString(L"IDS_BR_OPT_ADDTOBOOKMARKS"), IDA_ADDTOBOOKMARK_CLICKED,*pBitmap);
5436                 }
5437
5438                 if (IsFailed(r))
5439                 {
5440                         AppLogException("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED Add to Bookmark failed with %s", GetErrorMessage(r));
5441                         delete pBitmap;
5442                         return ;
5443                 }
5444                 AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED 4");
5445                 if (__pOptionMenu->GetItemCount() != 9)
5446                 {
5447                         __pOptionMenu->InsertItemAt(1,CommonUtil::GetString(L"IDS_BR_OPT_ADDTOBOOKMARKS"), IDA_ADDTOBOOKMARK_CLICKED);
5448                         __pOptionMenu->InsertItemAt(2,CommonUtil::GetString(L"IDS_BR_BODY_PRINT"), IDA_PRINT_CLICKED);
5449 //                              __pOptionMenu->InsertItemAt(2,L"Add to Home"/*CommonUtil::GetString(L"IDS_BR_OPT_SHARE")*/, IDA_ADD_TO_HOME_CLICKED);
5450                         __pOptionMenu->InsertItemAt(3,CommonUtil::GetString(L"IDS_BR_OPT_SHARE"), IDA_SHARE_CLICKED);
5451                         __pOptionMenu->InsertItemAt(4,CommonUtil::GetString(L"IDS_BR_OPT_FIND_ON_PAGE_ABB"), IDA_FINDONPAGE_CLICKED);
5452                         __pOptionMenu->SetMaxVisibleItemsCount(6);
5453                 }
5454                 if( GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE)
5455                 {
5456                         AppLog(" Orientation landscape");
5457                         __pOptionMenu->SetMaxVisibleItemsCount(5);
5458                 }
5459                 else
5460                 {
5461                         AppLog(" Orientation potrait");
5462                         __pOptionMenu->SetMaxVisibleItemsCount(6);
5463                 }
5464
5465                 AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED 5");
5466                 delete pBitmap;
5467         }
5468         AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED end");
5469         __pOptionMenu->SetShowState(true);
5470         __pOptionMenu->Invalidate(true);
5471         __pOptionMenu->Show();
5472
5473 }