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