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