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