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