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