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