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