NABI issues
[apps/osp/Internet.git] / src / IntMainForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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(L"History"/*CommonUtil::GetString(L"IDS_BR_OPT_BOOKMARK")*/, 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() == 9)
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         __pFooterPanel->SetShowState(true);
2686         RelayoutControls(false);
2687 }
2688
2689 void
2690 MainForm::OnAddressBarKeypadOpened(const Addressbar& addBar)
2691 {
2692         if (__pFindWordControl && __pFindWordControl->GetShowState() == true)
2693         {
2694                 __pAddressbar->SetShowState(false);
2695         }
2696         else
2697         {
2698                 if (__pAddressbar != null && __pAddressbar->GetShowState() == false)
2699                 {
2700                         __pAddressbar->SetShowState(true);
2701                         __pAddressbar->SetBounds(Rectangle(0,0,GetClientAreaBounds().width,__pAddressbar->GetHeight()));
2702                         __pAddressbar->SetAddressbarURLFocus();
2703                 }
2704         }
2705
2706         RelayoutControls(false);
2707 }
2708
2709 void
2710 MainForm::OnAddressBarKeypadWillOpen(const Addressbar& addBar)
2711 {
2712         __pFooterPanel->SetShowState(false);
2713 }
2714
2715 void
2716 MainForm::OnAddressBarKeypadBoundsChanged(const Addressbar& addBar)
2717 {
2718         AppLog("KeypadBoundsChanged");
2719         RelayoutControls(false);
2720 }
2721
2722 void
2723 MainForm::OnPageTitleReceived(const Tizen::Base::String& title)
2724 {
2725         if (__pWindowInfo)
2726         {
2727                 __pWindowInfo->pageTitle = title;
2728                 if (__pWebViewer != null)
2729                 {
2730                         __pWindowInfo->pageUrl = __pWebViewer->GetUrl();
2731                 }
2732         }
2733         if (__pAddressbar != null && __pWebViewer != null)
2734         {
2735                 SetUrl(__pWebViewer->GetUrl());
2736                 __pAddressbar->Invalidate(true);
2737         }
2738 }
2739
2740 void
2741 MainForm::UpdateFavicon(void)
2742 {
2743         bool urlImageType = false;
2744         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();");
2745         Bitmap* pBitmap = null;
2746
2747         if (tempPath && tempPath->GetLength() > 0 && tempPath->CompareTo(L"undefined") != 0)
2748         {
2749                 if (__pWindowInfo != null)
2750                 {
2751                         Uri url;
2752                         url.SetUri(*tempPath);
2753                         if (url.GetHost().GetLength() == 0)
2754                         {
2755                                 Uri webUrl;
2756                                 webUrl.SetUri(__pWebViewer->GetUrl());
2757                                 result r = url.SetHost(webUrl.GetHost());
2758                                 if(IsFailed(r))
2759                                 {
2760                                         delete tempPath;
2761                                         return;
2762                                 }
2763                         }
2764                         if (url.GetScheme().GetLength() == 0)
2765                         {
2766                                 Uri webUrl;
2767                                 webUrl.SetUri(__pWebViewer->GetUrl());
2768                                 url.SetScheme(webUrl.GetScheme());
2769                         }
2770                         __pWindowInfo->faviconUrl = url.ToString();
2771
2772                         pBitmap = __pWebViewer->GetFaviconN();
2773
2774                         if (pBitmap != null)
2775                         {
2776                                 if (__pWindowInfo->pFavicon != NULL)
2777                                 {
2778                                         __pWindowInfo->pFavicon = null;
2779                                 }
2780                                 __pWindowInfo->pFavicon = new(std::nothrow) Bitmap();
2781                                 __pWindowInfo->pFavicon->Construct(*pBitmap,Rectangle(0,0,pBitmap->GetWidth(),pBitmap->GetHeight()));
2782
2783                                 __pAddressbar->SetFaviconBitmap(*__pWindowInfo->pFavicon);
2784
2785                                 FaviconManager::GetInstance()->SaveFavicon(*__pWindowInfo->pFavicon, __pWindowInfo->faviconUrl);
2786                         }
2787                         else if(__pWindowInfo->pFavicon != null)
2788                         {
2789                                 __pAddressbar->SetFaviconBitmap(*__pWindowInfo->pFavicon);
2790                         }
2791                         else
2792                         {
2793                                 Bitmap *pDefaultBmp = FaviconManager::GetInstance()->GetDefaultFaviconN();
2794                                 if(pDefaultBmp != null)
2795                                 {
2796                                         __pAddressbar->SetFaviconBitmap(*pDefaultBmp);
2797                                 }
2798                         }
2799                 }
2800                 delete tempPath;
2801         }
2802         else
2803         {
2804                 delete tempPath;
2805                 AppLogDebug("Error occured: %s", GetErrorMessage(GetLastResult()));
2806         }
2807
2808 }
2809
2810
2811 bool
2812 MainForm::OnLoadingRequested(const Tizen::Base::String& url,
2813                 Tizen::Web::Controls::WebNavigationType type)
2814 {
2815         // when load new page if find word panel is open its show state is false
2816         ShowFindWordPanel(false);
2817         AppLog("__pAddressbar->GetAddressbarURL() is %ls",__pAddressbar->GetAddressbarURL().GetPointer());
2818
2819         __pFooterPanel->Invalidate(true);
2820
2821         Uri uriInfo;
2822         uriInfo.SetUri(url);
2823
2824         if(url.Contains(IDS_TIZEN_SERVICE))
2825         {
2826                 String appId;
2827                 String delim(L":;");
2828
2829                 // Creates a StringTokenizer instance
2830                 StringTokenizer strTok(url, delim);
2831
2832                 int count = strTok.GetTokenCount();     // count == 4
2833
2834                 HashMap *pMap = new HashMap();
2835                 pMap->Construct();
2836
2837                 String token;
2838                 String key;
2839                 String value;
2840                 while (strTok.HasMoreTokens())
2841                 {
2842                         AppLog("Token: %ls", token.GetPointer());
2843                         strTok.GetNextToken(token);         // Tizen, StringTokenizer, Sample, code
2844                         if(token.Contains(IDS_APPID))
2845                         {
2846                                 token.SubString(6, appId);
2847                                 AppLog("AppID:%ls", appId.GetPointer());
2848                         }
2849                         else if(token.Contains("="))
2850                         {
2851                                 String *pKey = new String();
2852                                 String *pValue = new String();
2853                                 int index = -1;
2854                                 token.IndexOf("=", 0, index);
2855                                 if(index != -1)
2856                                 {
2857                                         token.SubString(0, index, *pKey);
2858                                         token.SubString(index + 1, *pValue);
2859                                         pMap->Add(pKey, pValue);
2860                                 }
2861                         }
2862                 }
2863                 if(appId != "")
2864                 {
2865                         AppControl *pAppControl = null;
2866                         String operationId = L"http://tizen.org/appcontrol/operation/main";
2867                         pAppControl = dynamic_cast<AppControl*>(AppManager::FindAppControlN(appId, operationId));
2868                         if(pAppControl)
2869                         {
2870                                 result r = pAppControl->Start(null, null, pMap, null);
2871                         }
2872                         else
2873                         {
2874                                 AppLogException("AppControl not found");
2875                         }
2876                         return true;
2877                 }
2878         }
2879
2880         if (__pWebViewer && __pAddressbar)
2881         {
2882                 __pAddressbar->SetShowState(false);
2883                 /*AppLog("__pWebViewer->GetUrl() %ls",__pWebViewer->GetUrl().GetPointer());
2884                 __pAddressbar->SetUrl(__pWebViewer->GetUrl());
2885                 __pAddressbar->UpdateProgress(DEFAULT_PROGRESS_PERCENTAGE);
2886
2887                 if (__pWindowInfo)
2888                 {
2889                         __pWindowInfo->pageTitle = CommonUtil::GetString(L"IDS_BR_BODY_ABOUT_C_BLANK");
2890                         __pWindowInfo->pageUrl = __pWebViewer->GetUrl();
2891                         __pWindowInfo->faviconUrl = "";
2892                         __pWindowInfo->faviconFilePath = "";
2893
2894                         if (__pWindowInfo->pFavicon != NULL)
2895                         {
2896                                 //                              delete __pWindowInfo->pFavicon;
2897                                 __pWindowInfo->pFavicon = null ;
2898                         }
2899                         __pWindowInfo->pFavicon = FaviconManager::GetInstance()->GetDefaultFaviconN();
2900
2901                 }*/
2902
2903                 __pAddressbar->Invalidate(true);
2904         }
2905         return false;
2906 }
2907
2908 DecisionPolicy
2909 MainForm::OnWebDataReceived(const Tizen::Base::String& mime,
2910                 const Tizen::Net::Http::HttpHeader& httpHeader)
2911 {
2912         return Tizen::Web::Controls::WEB_DECISION_CONTINUE;
2913 }
2914
2915
2916 void
2917 MainForm::OnWebPageBlockSelected(Tizen::Web::Controls::Web& source, Tizen::Graphics::Point& startPoint, Tizen::Graphics::Point& endPoint)
2918 {
2919         AppLog("MainForm::OnWebPageBlockSelected");
2920         if (__pHitElementResult != null)
2921         {
2922                 delete __pHitElementResult;
2923                 __pHitElementResult = null;
2924         }
2925
2926         if (__pWebViewer != null)
2927         {
2928                 AppLog("MainForm::OnWebPageBlockSelected web not null");
2929                 __pHitElementResult = __pWebViewer->GetElementByPointN(endPoint);
2930         }
2931
2932         if (__pHitElementResult == null)
2933         {
2934                 return;
2935         }
2936
2937         if (__pHitElementResult->HasImage() != true)
2938         {
2939                 String tagName = __pHitElementResult->GetTagName();
2940                 String type = __pHitElementResult->GetAttributeValue("type");
2941
2942                 __currentSelectedStr.Clear();
2943                 AppLog("__currentSelectedStr after clear %ls",__currentSelectedStr.GetPointer());
2944                 __currentSelectedStr = __pWebViewer->GetTextFromBlock();
2945                 AppLog("__currentSelectedStr after GetTextFromBlock %ls",__currentSelectedStr.GetPointer());
2946
2947                 if (((tagName.CompareTo(L"INPUT") == 0)  || tagName.CompareTo(L"TEXTAREA") == 0) && __isLongPressedDone == true)
2948                 {
2949                         AppLog("MainForm::OnWebPageBlockSelected show paste option");
2950
2951                         InitSelectTextContextMenu(endPoint,true);
2952                         __pImageMenu->SetShowState(true);
2953                         __pImageMenu->Show();
2954                         __pImageMenu->Invalidate(true);
2955                 }
2956                 else if(__isLongPressedDone == true)
2957                 {
2958                         AppLog("MainForm::OnWebPageBlockSelected no paste option");
2959
2960                         if(__pHitElementResult->GetUrl().GetLength() > 0)
2961                         {
2962                                 __currentSelectedStr.Clear();
2963                                 __currentSelectedStr = __pHitElementResult->GetUrl();
2964                         }
2965                         InitSelectTextContextMenu(endPoint,false);
2966                         __pImageMenu->SetShowState(true);
2967                         __pImageMenu->Show();
2968                         __pImageMenu->Invalidate(true);
2969                 }
2970
2971                 AppLog("MainForm::OnWebPageBlockSelected block text is %ls",__currentSelectedStr.GetPointer());
2972                 AppLog("MainForm::OnWebPageBlockSelected tag name is %ls",tagName.GetPointer());
2973                 AppLog("MainForm::OnWebPageBlockSelected type name is %ls",type.GetPointer());
2974         }
2975
2976 }
2977
2978 void
2979 MainForm::OnWebPageShowRequested(Tizen::Web::Controls::Web& source)
2980 {
2981
2982 }
2983
2984 Web*
2985 MainForm::OnWebWindowCreateRequested(void)
2986 {
2987         WindowInfo* pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewScene();
2988
2989         if (pNewWindowInfo == null)
2990         {
2991                 return null;
2992         }
2993         result r = E_SUCCESS;
2994         SceneManager* pSceneManager = SceneManager::GetInstance();
2995         if (pSceneManager == NULL)
2996         {
2997                 return null;
2998         }
2999         ArrayList* pArgList = new(std::nothrow) ArrayList();
3000         if (pArgList == NULL)
3001         {
3002                 return null;
3003         }
3004         r = pArgList->Construct();
3005         if (r == E_SUCCESS)
3006         {
3007                 pNewWindowInfo->isJavascriptInitiated = true;
3008                 pArgList->Add(*pNewWindowInfo);
3009                 r = pSceneManager->GoForward(ForwardSceneTransition(pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
3010                 delete pArgList;
3011                 if (IsFailed(r))
3012                 {
3013                         AppLogDebug("EditHistoryListForm::OnFormBackRequested Failed to GoBackward %s",GetErrorMessage(r));
3014                         return null;
3015                 }
3016         } else {
3017                 delete pArgList;
3018         }
3019
3020         return pNewWindowInfo->pCurrentWeb;
3021 }
3022
3023 void
3024 MainForm::RelayoutControls(bool showAddressbar)
3025 {
3026         __webControlPosition.y = 0;
3027         __webControlHeight = GetClientAreaBounds().height;
3028         AppLog("Client area height: %d", __webControlHeight);
3029
3030         AppLog("Client area height: %d", __webControlHeight);
3031         if(__pAddressbar != null && __pAddressbar->GetShowState() == true)
3032         {
3033                 __webControlPosition.y += __pAddressbar->GetHeight();
3034                 __webControlHeight -= __pAddressbar->GetHeight();
3035                 __pAddressbar->SetBounds(0, 0, __pAddressbar->GetWidth(), __pAddressbar->GetHeight());
3036         }
3037         else if(__pFindWordControl != null && __pFindWordControl->GetShowState() == true)
3038         {
3039                 __webControlPosition.y += __pFindWordControl->GetHeight();
3040                 __webControlHeight -= __pFindWordControl->GetHeight();
3041                 __pFindWordControl->SetBounds(0, 0, GetClientAreaBounds().width, __pFindWordControl->GetHeight());
3042         }
3043
3044         if(__pFooterPanel != null && __pFooterPanel->GetShowState() == true)
3045         {
3046                 __webControlHeight -= __pFooterPanel->GetHeight();
3047                 __pFooterPanel->SetBounds(0, __webControlPosition.y + __webControlHeight, GetClientAreaBounds().width, __pFooterPanel->GetHeight());
3048         }
3049         if (__pWebViewer != null && __pWebViewer->GetShowState() == true)
3050         {
3051                 __pWebViewer->SetBounds(0, __webControlPosition.y, GetClientAreaBounds().width, __webControlHeight);
3052                 __pWebViewer->Invalidate(false);
3053         }
3054         if(__pMostVisitedListView != null && __pAddressbar != null && __pFooterPanel != null)
3055         {
3056                 __pMostVisitedListView->SetBounds(Tizen::Graphics::Rectangle(0,__webControlPosition.y , GetClientAreaBounds().width, __webControlHeight));
3057         }
3058
3059         Invalidate(true);
3060 }
3061
3062 void MainForm::ShowFindWordPanel(bool show , bool isTouchPressed)
3063 {
3064         if (__pFindWordControl == null)
3065         {
3066                 return;
3067         }
3068         if (show == true)
3069         {
3070                 InitFindWordPanel();
3071                 __pFindWordEditField->SetText(__currentSearchStr);
3072                 //__pFindWordCountLabel->SetText(L"");
3073                 __pFindWordCountLabel->SetText(L"0/0");
3074                 __pFindWordPanel->SetShowState(true);
3075         }
3076         else
3077         {
3078                 if(__pFindWordControl != null)
3079                 {
3080                         __pFindWordControl->SetShowState(false);
3081                 }
3082         }
3083
3084         AppLog("MainForm::ShowFindWordPanel %d",show);
3085         if (show && !isTouchPressed)
3086         {
3087                 if (__pFindWordEditField)
3088                 {
3089                         __pFindWordEditField->SetFocus();
3090                         __pFindWordEditField->ShowKeypad();
3091                 }
3092         }
3093         else
3094         {
3095                 if (__pFindWordEditField)
3096                         __pFindWordEditField->HideKeypad();
3097         }
3098
3099         RelayoutControls(false);
3100 }
3101
3102 void
3103 MainForm::StartWordSearch()
3104 {
3105         //Get the count of occurances of the word in the current page
3106         __maxOccurrances = 0;
3107         __currentWordIndex = 0;
3108
3109         __pFindWordPrev->SetEnabled(false);
3110         String *pCountStr = null;
3111         __pWebViewer->SearchTextAllAsync(__currentSearchStr, false);
3112         /*__pWebViewer->EvaluateJavascriptN(L"document.body.textContent.match(/"  + __currentSearchStr + "/gi).length;");
3113         if (pCountStr != null)
3114         {
3115                 Integer::Parse(*pCountStr, 10, __maxOccurrances);
3116                 delete pCountStr;
3117         }
3118
3119         AppLogDebug("'%ls' is found %d times", __currentSearchStr.GetPointer(), __maxOccurrances);
3120          */
3121
3122 }
3123
3124 void MainForm::OnTextFound(int totalCount, int currentOrdinal)
3125 {
3126         AppLog("MainForm::OnTextFound totalCount %d",totalCount);
3127         AppLog("MainForm::OnTextFound currentOrdinal %d",currentOrdinal);
3128
3129         if(totalCount == -1 || totalCount == 0)
3130         {
3131                 __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),64,__pFindWordCountLabel->GetHeight());
3132                 __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),214+80,__pFindWordEditField->GetHeight());
3133 //              return;
3134         }
3135         else if(totalCount > 100)
3136         {
3137                 __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),124,__pFindWordCountLabel->GetHeight());
3138                 __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),174,__pFindWordEditField->GetHeight());
3139         }
3140
3141         __maxOccurrances = totalCount;
3142         __currentWordIndex = currentOrdinal;
3143
3144         //Reset the UI controls as per the maxOccurrance value
3145         if (totalCount <= 0)
3146         {
3147                 AppLog("Word not found");
3148                 //Show error notification to user
3149                 __pFindWordNext->SetEnabled(false);
3150                 __pFindWordCountLabel->SetText(L"0/0");
3151                 __pFindWordNext->Invalidate(false);
3152                 __pFindWordPrev->Invalidate(false);
3153                 __pFindWordCountLabel->Invalidate(false);
3154                 return;
3155         }
3156
3157         if (totalCount == 1)
3158         {
3159                 __pFindWordNext->SetEnabled(false);
3160         }
3161         else
3162         {
3163                 __pFindWordNext->SetEnabled(true);
3164         }
3165
3166         String countStr = L"";
3167         countStr.Append(__currentWordIndex);
3168         countStr.Append(L"/");
3169         countStr.Append(__maxOccurrances);
3170         __pFindWordCountLabel->SetText(countStr);
3171         //      __pFindWordCountLabel->SetShowState(true);
3172         __pFindWordCountLabel->Invalidate(false);
3173
3174         //FindNextWord(true);
3175         //Update the controls
3176         __pFindWordNext->Invalidate(false);
3177         __pFindWordPrev->Invalidate(false);
3178         __pFindWordCountLabel->Invalidate(false);
3179 }
3180
3181 void
3182 MainForm::FindNextWord(bool next)
3183 {
3184         if (next == true)
3185         {
3186                 if (__pWebViewer->SearchText(__currentSearchStr, true) == true)
3187                 {
3188                         if(__currentWordIndex < __maxOccurrances)
3189                         {
3190                                 __currentWordIndex++;
3191                         }
3192                 }
3193         }
3194         else
3195         {
3196                 if (__pWebViewer->SearchText(__currentSearchStr, false) == true)
3197                 {
3198                         if(__currentWordIndex > 1)
3199                         {
3200                                 __currentWordIndex--;
3201                         }
3202                 }
3203         }
3204
3205         String countStr = L"";
3206         countStr.Append(__currentWordIndex);
3207         countStr.Append(L"/");
3208         countStr.Append(__maxOccurrances);
3209         __pFindWordCountLabel->SetText(countStr);
3210         //      __pFindWordCountLabel->SetShowState(true);
3211         __pFindWordCountLabel->Invalidate(false);
3212         if (__currentWordIndex >= __maxOccurrances)
3213         {
3214                 __pFindWordNext->SetEnabled(false);
3215         }
3216         else
3217         {
3218                 __pFindWordNext->SetEnabled(true);
3219         }
3220         if (__currentWordIndex <= 1)
3221         {
3222                 __pFindWordPrev->SetEnabled(false);
3223         }
3224         else
3225         {
3226                 __pFindWordPrev->SetEnabled(true);
3227         }
3228         __pFindWordPrev->Invalidate(false);
3229         __pFindWordNext->Invalidate(false);
3230         __pFindWordCountLabel->Invalidate(false);
3231         __pFindWordPanel->Invalidate(true);
3232 }
3233 void
3234 MainForm::OnWebKeypadWillOpen(Tizen::Web::Controls::Web& source)
3235 {
3236         AppLog("MainForm::OnWebKeypadWillOpen");
3237         //      OnAddressBarKeypadOpened(*__pAddressbar);
3238 }
3239
3240 void
3241 MainForm::OnWebKeypadOpened(Tizen::Web::Controls::Web& source)
3242 {
3243
3244         if (__pWebViewer != null && __pFooterPanel != null)
3245         {
3246                 AppLog("MainForm::OnOrientationChanged GetClientAreaBounds().height %d ", GetClientAreaBounds().height);
3247                 if(__pAddressbar != null)
3248                 {
3249                         __pAddressbar->SetShowState(false);
3250                 }
3251                 if(__pFindWordControl != null)
3252                 {
3253                         __pFindWordControl->SetShowState(false);
3254                 }
3255                 __pFooterPanel->SetShowState(false);
3256                 __pWebViewer->SetBounds(Rectangle(0, 0,GetClientAreaBounds().width, GetClientAreaBounds().height));
3257         }
3258         Invalidate(true);
3259 }
3260
3261 void
3262 MainForm::OnWebKeypadClosed(Tizen::Web::Controls::Web& source)
3263 {
3264         __pFooterPanel->SetShowState(true);
3265         OnAddressBarKeypadClosed(*__pAddressbar);
3266 }
3267
3268 void
3269 MainForm::OnTouchDoublePressed(const Control& source, const Point& currentPosition, const TouchEventInfo& touchInfo)
3270 {
3271         Control* temp = const_cast< Control* >(&source);
3272         Header* pHeader = dynamic_cast< Header* >(temp);
3273         if (pHeader != null)
3274         {
3275                 //Header double - clicked
3276                 AppLog("Header double clicked");
3277         }
3278         if(__pFindWordPanel)
3279         {
3280                 AppLog("MainForm::OnTouchPressed %d",__pFindWordPanel->GetShowState());
3281                 ShowFindWordPanel(__pFindWordPanel->GetShowState(), true);
3282         }
3283
3284
3285         AppLog("MainScene::OnTouchDoublePressed");
3286         bool isReaderEnabled = SettingPresentationModel::GetInstance()->IsRunReaderEnabled();
3287         if (isReaderEnabled == true)
3288         {
3289                 if (__pReaderData)
3290                 {
3291                         delete __pReaderData;
3292                         __pReaderData = null;
3293                 }
3294                 String filePath = Tizen::App::UiApp::GetInstance()->GetAppRootPath();
3295                 filePath.Append(L"data/reader.js");
3296                 File file;
3297                 char buffer[10];
3298                 char buffer2[5];
3299                 int i;
3300                 int readCnt;
3301                 result r = E_SUCCESS;
3302                 FileAttributes attr;
3303
3304                 File::GetAttributes(filePath,attr);
3305                 // Creates file
3306                 r = file.Construct(filePath, L"r+");
3307                 if (IsFailed(r))
3308                 {
3309                         AppLogDebug("File construct failed with %s", GetErrorMessage(r));
3310                         return;
3311                 }
3312                 char* pScript = new(std::nothrow) char[attr.GetFileSize()+1];
3313                 if(pScript == null)
3314                 {
3315                         AppLogDebug("Memory allocation for file failed %s", GetErrorMessage(r));
3316                         return;
3317                 }
3318                 file.Read(pScript,attr.GetFileSize());
3319
3320                 AppLogDebug("scipt length %d",strlen(pScript));
3321                 String strScript = L"";
3322                 strScript.Append(pScript);
3323                 __pReaderData = __pWebViewer->EvaluateJavascriptN(strScript);
3324                 if (!__pReaderData)
3325                 {
3326                         AppLog("MainScene::data is null Error :%s",GetErrorMessage(GetLastResult()));
3327                         return;
3328                 }
3329                 AppLogDebug("evaluateJavascript result %s , __pReaderData %ls",GetErrorMessage(GetLastResult()),__pReaderData->GetPointer());
3330                 if (__pReaderData->CompareTo(L"undefined") != 0 && __pReaderData->CompareTo(L"") != 0)
3331                 {
3332                         //__pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_READER);
3333                         SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_READER);
3334                 }
3335                 delete[] pScript;
3336         }
3337 }
3338
3339 void MainForm::OnTouchLongPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
3340 {
3341         AppLog("MainForm::OnTouchLongPressed");
3342
3343         if (__pHitElementResult != null)
3344         {
3345                 delete __pHitElementResult;
3346                 __pHitElementResult = null;
3347         }
3348
3349         if (__pWebViewer != null)
3350         {
3351                 AppLog("MainForm::OnTouchLongPressed web not null");
3352                 __pHitElementResult = __pWebViewer->GetElementByPointN(currentPosition);
3353         }
3354
3355         if (__pHitElementResult == null)
3356         {
3357                 return;
3358         }
3359
3360         if (__pHitElementResult->HasImage() == true)
3361         {
3362                 InitImageContextMenu(currentPosition);
3363                 __pImageMenu->SetShowState(true);
3364                 __pImageMenu->Show();
3365                 __pImageMenu->Invalidate(true);
3366         }
3367         else
3368         {
3369                 String tagName = __pHitElementResult->GetTagName();
3370                 String type = __pHitElementResult->GetAttributeValue("type");
3371                 String value = __pHitElementResult->GetAttributeValue(L"value");
3372                 String innerHtml = __pHitElementResult->GetAttributeValue(L"innerHTML");
3373
3374                 __currentSelectedStr.Clear();
3375                 __currentSelectedStr = __pWebViewer->GetTextFromBlock();
3376
3377                 if (((tagName.CompareTo(L"INPUT") == 0)  || tagName.CompareTo(L"TEXTAREA") == 0) &&  value.GetLength() == 0 && innerHtml.GetLength() == 0)
3378                 {
3379                         AppLog("MainForm::OnWebPageBlockSelected show paste option");
3380
3381                         InitSelectTextContextMenu(currentPosition,true, true);
3382                         __pImageMenu->SetShowState(true);
3383                         __pImageMenu->Show();
3384                         __pImageMenu->Invalidate(true);
3385                 }
3386                 __isLongPressedDone = true;
3387                 __pWebViewer->SetBlockSelectionPosition(currentPosition);
3388
3389
3390
3391         }
3392         __inputEventToBeSupressed = true;
3393 }
3394
3395 void
3396 MainForm::OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
3397 {
3398         AppLog("MainForm::OnTouchReleased");
3399
3400         HitElementResult* pHitElement = __pWebViewer->GetElementByPointN(currentPosition);
3401         if(pHitElement != null && pHitElement->HasUrl() == true && __inputEventToBeSupressed == true)
3402         {
3403                 __pWebViewer->ConsumeInputEvent();
3404         }
3405         if(pHitElement != null)
3406         {
3407                 delete pHitElement;
3408         }
3409         __inputEventToBeSupressed = false;
3410 }
3411
3412 void
3413 MainForm::OnOrientationChanged (const Tizen::Ui::Control &source, Tizen::Ui::OrientationStatus orientationStatus)
3414 {
3415         AppLog("MainForm::OnOrientationChanged GetClientAreaBounds %d, %d",GetClientAreaBounds().width,GetClientAreaBounds().height);
3416         int widthContextItem = 0;
3417
3418         Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_SEARCH_INPUT_FIELD_BG, __pFooterLabel->GetWidth(), __pFooterLabel->GetHeight());
3419         if (pBitmap != null && __pFooterLabel != null)
3420         {
3421                 __pFooterLabel->SetBackgroundBitmap(*pBitmap);
3422                 delete pBitmap;
3423         }
3424
3425         if (__pFindWordBgLabel != null)
3426         {
3427                 Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_FINDWORD_INPUT_FIELD_BG, __pFindWordBgLabel->GetWidth(), __pFindWordBgLabel->GetHeight());
3428                 if (pBitmap != null)
3429                 {
3430                         __pFindWordBgLabel->SetBackgroundBitmap(*pBitmap);
3431                         delete pBitmap;
3432                 }
3433         }
3434
3435         if(__pMenu != null)
3436                 __pMenu->SetShowState(false);
3437         if( GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
3438         {
3439                 widthContextItem = WIDTH_CONTEXT_MENU_BUTTON_LANDSCAPE;
3440         }
3441         else
3442         {
3443                 widthContextItem = WIDTH_CONTEXT_MENU_BUTTON_PORTRAIT;
3444         }
3445
3446         if (__pFooterPanel)
3447         {
3448                 AppLog("__pFooterPanel->GetShowState() is true");
3449                 InitFooter();
3450                 __pFooterPanel->SetBounds(0, GetClientAreaBounds().height - __pFooterPanel->GetHeight(), __pFooterPanel->GetWidth(), __pFooterPanel->GetHeight());
3451                 __pFooterPanel->Invalidate(true);
3452         }
3453         InitAddressbar();
3454
3455         if(__pMoreButton && __pMenu)
3456         {
3457                 Point p = Point(__pMoreButton->GetX() + __pMoreButton->GetWidth() / 2, GetBounds().height - __pMoreButton->GetHeight());
3458                 __pMenu->SetAnchorPosition(p);
3459                 __pMenu->Invalidate(true);
3460         }
3461
3462         String homePage = SettingPresentationModel::GetInstance()->GetHomepage();
3463         if (homePage.CompareTo((L"IDS_BR_BODY_MOST_VISITED_SITES")) == 0)
3464         {
3465                 InitMostVisitedSitesView(orientationStatus);
3466         }
3467
3468         RelayoutControls(false);
3469         if (__pArticleReaderPanel != null)
3470         {
3471                 if (__pArticleReaderPanel->GetShowState() == true)
3472                 {
3473                         __pArticleReaderPanel->SetBounds((GetClientAreaBounds().width - __pArticleReaderPanel->GetWidth())/2,(GetClientAreaBounds().height - __pArticleReaderPanel->GetHeight())/2, __pArticleReaderPanel->GetWidth(), __pArticleReaderPanel->GetHeight());
3474
3475                         if (__pBlankPanel != null)
3476                                 __pBlankPanel->SetBounds(0,0,GetClientAreaBounds().width,GetClientAreaBounds().height);
3477
3478                         if (__pWebReader != null)
3479                         {
3480                                 __pWebReader->SetBounds(Rectangle(2,2, __pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight() - 96));
3481                         }
3482                         Bitmap* pBitmap = CommonUtil::GetNinepatchedBitmapN(L"I01_popup_bg.9.png",__pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight());
3483                         Bitmap* pSrcBitmap = CommonUtil::GetNinepatchedBitmapN(L"I01_popup_bottom_bg.9.png",__pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight());
3484
3485                         if ( pBitmap != null && pSrcBitmap != null)
3486                         {
3487                                 AppLog("CreateReaderPanel ninepatchbitmap found");
3488                                 pBitmap->Merge(Point(0,__pArticleReaderPanel->GetHeight() - 96),*pSrcBitmap,Rectangle(0,0,pSrcBitmap->GetWidth(),pSrcBitmap->GetHeight()));
3489                         }
3490
3491                         __pArticleReaderLabel->SetBounds(Rectangle(__pArticleReaderPanel->GetX(),__pArticleReaderPanel->GetY(),__pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight()));
3492                         __pArticleReaderLabel->SetBackgroundBitmap(*pBitmap);
3493                         if (pBitmap != null)
3494                         {
3495                                 delete pBitmap;
3496                                 pBitmap = null;
3497                         }
3498                         if (pSrcBitmap != null)
3499                         {
3500                                 delete pSrcBitmap;
3501                                 pSrcBitmap = null;
3502                         }
3503                 }
3504         }
3505         Invalidate(true);
3506         if(__pAddressbar != null)
3507         {
3508                 __pAddressbar->OrientationChanged();
3509         }
3510 }
3511
3512 void
3513 MainForm::OnSettingsChange(int settingvalue)
3514 {
3515         AppLogDebug("MainForm::OnSettingsChange entered");
3516         if (__pWebViewer == null)
3517         {
3518                 AppLogDebug("Webviewer is not initialized yet.");
3519                 return;
3520         }
3521         if (settingvalue == (int) REGISTRY_SETTING_DEFAULT_VIEW)
3522         {
3523                 WebSetting settings = __pWebViewer->GetSetting();
3524                 if (SettingPresentationModel::GetInstance()->GetDefaultView().CompareTo(CommonUtil::GetString(L"IDS_BR_BODY_FIT_TO_WIDTH")) == 0)
3525                 {
3526                         settings.SetAutoFittingEnabled(true);
3527                 }
3528                 else if (SettingPresentationModel::GetInstance()->GetDefaultView().CompareTo(CommonUtil::GetString(L"IDS_BR_BODY_READABLE")) == 0)
3529                 {
3530                         settings.SetAutoFittingEnabled(false);
3531                 }
3532                 __pWebViewer->SetSetting(settings);
3533         }
3534         else if (settingvalue == (int) REGISTRY_SETTING_RUN_JAVASCRIPT)
3535         {
3536                 WebSetting settings = __pWebViewer->GetSetting();
3537                 settings.SetJavascriptEnabled(SettingPresentationModel::GetInstance()->IsRunJavascriptEnabled());
3538                 __pWebViewer->SetSetting(settings);
3539         }
3540         else if (settingvalue == (int) REGISTRY_SETTING_DISPLAY_IMAGES)
3541         {
3542                 WebSetting settings = __pWebViewer->GetSetting();
3543                 settings.SetAutoImageLoadEnabled(SettingPresentationModel::GetInstance()->IsDisplayImagesEnabled());
3544                 __pWebViewer->SetSetting(settings);
3545         }
3546         else if (settingvalue == (int) REGISTRY_SETTING_BLOCK_POPUP)
3547         {
3548                 WebSetting settings = __pWebViewer->GetSetting();
3549                 settings.SetJavaScriptPopupEnabled(SettingPresentationModel::GetInstance()->IsBlockPopUp());
3550                 __pWebViewer->SetSetting(settings);
3551         }
3552         else if (settingvalue == (int) REGISTRY_SETTING_ACCEPT_COOKIES)
3553         {
3554                 if (__pWebViewer)
3555                 {
3556                         __pWebViewer->SetCookieEnabled(SettingPresentationModel::GetInstance()->IsCookiesEnabled());
3557                 }
3558         }
3559
3560         else if (settingvalue == (int) REGISTRY_SETTING_SHOW_SECURITY_WARNINGS)
3561         {
3562                 WebSetting settings = __pWebViewer->GetSetting();
3563                 if (SettingPresentationModel::GetInstance()->IsSecurityWarningsEnabled() == true)
3564                 {
3565                         settings.SetCertificateErrorHandlingMode(WEB_CERTIFICATE_ERROR_HANDLING_MODE_USER_CONFIRM);
3566                 }
3567                 else
3568                 {
3569                         settings.SetCertificateErrorHandlingMode(WEB_CERTIFICATE_ERROR_HANDLING_MODE_CONTINUE);
3570                 }
3571                 __pWebViewer->SetSetting(settings);
3572         }
3573         else if (settingvalue == (int) REGISTRY_SETTING_READER_FONT_SIZE)
3574         {
3575                 if (__pWebReader)
3576                 {
3577                         AppLogDebug("IntMainForm fontsize Changed to %d",SettingPresentationModel::GetInstance()->GetReaderFontSize());
3578                         WebSetting settings = __pWebReader->GetSetting();
3579                         settings.SetFontSize(SettingPresentationModel::GetInstance()->GetReaderFontSize());
3580                         __pWebReader->SetSetting(settings);
3581                 }
3582         }
3583 }
3584
3585 void
3586 MainForm::OnSettingsReset()
3587 {
3588         if (__pWebViewer)
3589         {
3590                 __pWebViewer->SetCookieEnabled(SettingPresentationModel::GetInstance()->IsCookiesEnabled());
3591                 __pWebViewer->SetSetting(SettingPresentationModel::GetInstance()->GetWebSettings());
3592         }
3593 }
3594
3595 void
3596 MainForm::OnClearCache()
3597 {
3598         result r = E_SUCCESS;
3599
3600         if (__pWebViewer != NULL)
3601         {
3602                 r = __pWebViewer->ClearCache();
3603                 if (r == E_SUCCESS)
3604                 {
3605                         AppLogDebug("Cache cleared success");
3606                 }
3607                 else
3608                 {
3609                         AppLogDebug("Cache cleared fail");
3610                 }
3611         }
3612 }
3613
3614 void
3615 MainForm::OnClearCookie()
3616 {
3617         result r = E_SUCCESS;
3618
3619         if (__pWebViewer != NULL)
3620         {
3621                 __pWebViewer->ClearCookie();
3622         }
3623         if (r == E_SUCCESS)
3624         {
3625                 AppLogDebug("Cookie cleared success");
3626         }
3627         else
3628         {
3629                 AppLogDebug("Cache cleared fail");
3630         }
3631 }
3632
3633 double
3634 MainForm::findDistance(int x1,int y1,int x2, int y2)
3635 {
3636         int deltaX = Math::Abs(x2 - x1);
3637         int deltaY = Math::Abs(y2 - y1);
3638         double num = deltaX*deltaX + deltaY*deltaY;
3639
3640         if (num >= 0)
3641         {
3642                 double x = num;
3643                 int i;
3644                 for (i = 0; i < 20; i++)
3645                 {
3646                         x = (((x*x)+ num)/(2*x));
3647                 }
3648                 return num;
3649         }
3650         else
3651         {
3652                 return 0.0;
3653         }
3654 }
3655
3656 void
3657 MainForm::OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
3658 {
3659         if(__pFindWordPanel)
3660         {
3661                 AppLog("MainForm::OnTouchPressed %d",__pFindWordPanel->GetShowState());
3662                 ShowFindWordPanel(__pFindWordPanel->GetShowState(), true);
3663         }
3664         __isLongPressedDone = false;
3665
3666         Touch touch;
3667         IList* pList = null;
3668         pList = touch.GetTouchInfoListN(source);
3669
3670         if (pList != null)
3671         {
3672                 int count = pList->GetCount();
3673                 if (count == 1)
3674                 {
3675                         TouchInfo* pTouchInfo = static_cast<TouchInfo*>(pList->GetAt(0));
3676                         __touchPoint1 = pTouchInfo->position;
3677
3678                         /*if (__pAddressbar != null)
3679                         {
3680                                 if (__pAddressbar->GetAddressbarMode() != ADDRESSBAR_MODE_LOADING_COMPLETE && __pAddressbar->GetAddressbarMode() != ADDRESSBAR_MODE_LOADING)
3681                                 {
3682                                         if (__pAddressbar->GetAddressbarMode() == ADDRESSBAR_MODE_EDIT)
3683                                         {
3684                                                 __pAddressbar->SaveAddressbarEditText();
3685                                         }
3686                                         __pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
3687                                 }
3688
3689                                 __pAddressbar->Invalidate(true);
3690                         }*/
3691                         if (GetAddressbarMode() != ADDRESSBAR_MODE_LOADING_COMPLETE && GetAddressbarMode() != ADDRESSBAR_MODE_LOADING)
3692                         {
3693                                 if (GetAddressbarMode() == ADDRESSBAR_MODE_EDIT)
3694                                 {
3695                                         //__pAddressbar->SaveAddressbarEditText();
3696                                 }
3697                                 SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
3698                         }
3699                 }
3700                 else if (count == 2)
3701                 {
3702                         AppLogDebug("MainForm::OnTouchPressed count is two");
3703                         TouchInfo* pTouchInfo = static_cast<TouchInfo*>(pList->GetAt(0));
3704                         __touchPoint1 = pTouchInfo->position;
3705
3706                         pTouchInfo = static_cast<TouchInfo*>(pList->GetAt(1));
3707                         __touchPoint2 = pTouchInfo->position;
3708                 }
3709         }
3710         if( pList != NULL)
3711
3712         {
3713                 pList->RemoveAll(true);
3714                 delete pList;
3715         }
3716         return;
3717 }
3718
3719 void
3720 MainForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
3721 {
3722         __currentWordIndex = 0;
3723         __isLongPressedDone = false;
3724
3725 }
3726
3727 void
3728 MainForm::MoveUiControls()
3729 {
3730 }
3731
3732 void
3733 MainForm::OnTextValueChanged (const Tizen::Ui::Control &source)
3734 {
3735         if(&source == dynamic_cast<Control*>(__pFooterUrlField) && __pFooterUrlField != null)
3736         {
3737                 if(__pFooterUrlField->GetTextLength() == 0)
3738                 {
3739                         __pFooterUrlField->SetKeypadActionEnabled(false);
3740                 }
3741                 else
3742                 {
3743                         __pFooterUrlField->SetKeypadActionEnabled(true);
3744                 }
3745         }
3746         if (__pFindWordEditField != null)
3747         {
3748                 __currentSearchStr = __pFindWordEditField->GetText();
3749                 __pFindWordNext->SetEnabled(false);
3750                 __pFindWordPrev->SetEnabled(false);
3751                 __pFindWordNext->Invalidate(true);
3752                 __pFindWordPrev->Invalidate(true);
3753                 __pFindWordCountLabel->SetText(L"0/0");
3754                 __pFindWordCountLabel->Invalidate(true);
3755         }
3756         AppLog("__currentSearchStr %ls",__currentSearchStr.GetPointer());
3757         if (__currentSearchStr.GetLength() > 0)
3758         {
3759                 StartWordSearch();
3760         }
3761         else
3762         {
3763                 __currentSearchStr = L"aaaaaaaabbbbbbbccccccc";
3764                 StartWordSearch();
3765                 AppLogDebug("Enter something");
3766         }
3767 }
3768
3769 result
3770 MainForm::InitMostVisitedSitesPanel(Tizen::Ui::OrientationStatus orientationStatus)
3771 {
3772         return E_SUCCESS;
3773
3774 }
3775
3776 result
3777 MainForm::InitMostVisitedSitesView(Tizen::Ui::OrientationStatus orientationStatus)
3778 {
3779         if(__pWebViewer != null)
3780                 return E_SUCCESS;
3781
3782         AppLog("MainForm::InitMostVisitedSitesView");
3783         result r = E_SUCCESS;
3784
3785
3786         if (__pWebViewer != null && __pMostVisitedListView != null)
3787         {
3788                 return E_SUCCESS;
3789         }
3790
3791         if (__pMostVisitedListView != null)
3792         {
3793                 RemoveControl(*__pMostVisitedListView);
3794         }
3795         if(__pMostVisitedSites != null)
3796         {
3797                 __pMostVisitedSites->RemoveAll(true);
3798         }
3799
3800         HistoryPresentationModel::GetInstance()->GetMostVisitedSites(*__pMostVisitedSites);
3801
3802         __webControlHeight = GetClientAreaBounds().height - __pFooterPanel->GetHeight();
3803         __pMostVisitedListView = new(std::nothrow) ListView();
3804
3805         int height = GetClientAreaBounds().height;
3806
3807         if(__pFooterPanel->GetShowState() == true)
3808         {
3809                 height = height - __pFooterPanel->GetHeight();
3810         }
3811         if(__pAddressbar->GetShowState() == true)
3812         {
3813                 height -= __pAddressbar->GetHeight();
3814         }
3815
3816         r = __pMostVisitedListView->Construct(Tizen::Graphics::Rectangle(0,0 , GetClientAreaBounds().width, height),true,false);
3817
3818         if (r != E_SUCCESS)
3819         {
3820                 delete __pMostVisitedListView;
3821                 AppLogDebug("Addressbar init failed with %s", GetErrorMessage(r));
3822                 return r;
3823         }
3824         __pMostVisitedListView->SetItemProvider(*this);
3825         __pMostVisitedListView->AddListViewItemEventListener(*this);
3826         __pMostVisitedListView->SetTextOfEmptyList(CommonUtil::GetString(L"IDS_BR_BODY_NO_RECENTLY_VISITED_SITES"));
3827         AddControl(*__pMostVisitedListView);
3828         __pMostVisitedListView->UpdateList();
3829
3830         return E_SUCCESS;
3831
3832 }
3833
3834 String
3835 MainForm::GetImagePath(void)
3836 {
3837
3838         String str;
3839         String formattedTime;
3840         DateTime currentTime;
3841         LocaleManager localManager;
3842         SystemTime::GetCurrentTime(TIME_MODE_WALL, currentTime);
3843
3844         localManager.Construct();
3845         Locale locale = localManager.GetSystemLocale();
3846         //Locale locale(LANGUAGE_ENG, COUNTRY_US);
3847
3848         // Get date formatter
3849         DateTimeFormatter* pTimeFormatter = DateTimeFormatter::CreateDateTimeFormatterN(locale, DATE_TIME_STYLE_DEFAULT);
3850
3851         if (pTimeFormatter)
3852         {
3853                 pTimeFormatter->Format(currentTime, formattedTime);
3854         }
3855
3856         AppLog("current time stamp is %ls", formattedTime.GetPointer());
3857         String delim(L" :");
3858         StringTokenizer strTok(formattedTime, delim);
3859         String token;
3860         String imageName;
3861         String str1("GMT+00");
3862         while (strTok.HasMoreTokens())
3863         {
3864                 strTok.GetNextToken(token); // Osp, StringTokenizer, Sample, code
3865                 if(token.Equals(str1))
3866                         break;
3867                 AppLog("token is %ls", token.GetPointer());
3868                 imageName.Append(token);
3869         }
3870         return imageName;
3871
3872 }
3873
3874 void MainForm::UpdateImageContent(ByteBuffer* aBuffer, String imageName)
3875 {
3876         result r = E_FAILURE;
3877         AppLog("Content manager 1");
3878         ContentId contentId;
3879         ContentManager contentManager;
3880         r = contentManager.Construct();
3881         if(IsFailed(r))
3882         {
3883                 AppLog("Content manager update content result %s" ,GetErrorMessage(r));
3884                 return;
3885         }
3886         Tizen::Base::String contentPath = Tizen::System::Environment::GetMediaPath() + L"Downloads/";
3887         contentPath.Append(imageName);
3888         contentPath.Append(".jpg");
3889         contentId = contentManager.CreateContent(*aBuffer, contentPath);
3890         AppLog("Content manager update content result %s" ,GetErrorMessage(GetLastResult()));
3891 }
3892
3893 void
3894 MainForm::SetForwardButtonEnabled(bool isEnabled)
3895 {
3896         __pGoForwardBtn->SetEnabled(isEnabled);
3897         __pGoBackBtn->Invalidate(true);
3898 }
3899
3900 void
3901 MainForm::SetBackButtonEnabled(bool isEnabled)
3902 {
3903         __pGoBackBtn->SetEnabled(isEnabled);
3904         __pGoBackBtn->Invalidate(true);
3905 }
3906
3907 void
3908 MainForm::UpdateProgress(int percentage)
3909 {
3910         __progressPercentage = percentage;
3911         if (percentage == 0 || percentage == 100)
3912         {
3913                 __isLoadingData = false;
3914                 if (percentage == 100)
3915                 {
3916                         __isLoadingCompleted = true;
3917                         __progressPercentage = 0;
3918                 }
3919                 else
3920                 {
3921                         __isLoadingCompleted = false;
3922                 }
3923         }
3924         else
3925         {
3926                 __isLoadingData = true;
3927         }
3928         UpdateProgressBitmap();
3929 }
3930
3931 int
3932 MainForm::GetProgress(void)
3933 {
3934         return __progressPercentage;
3935 }
3936
3937 void
3938 MainForm::UpdateProgressBitmap(void)
3939 {
3940         result r = E_SUCCESS;
3941         if (__pProgressbarLabel == null)
3942                 return;
3943         int w = __pProgressbarLabel->GetWidth();
3944         int h = __pProgressbarLabel->GetHeight();
3945         Canvas canvas;
3946         int progressWidth = 0;
3947         Bitmap* pRetBitmap = null;
3948
3949         if (__progressPercentage == 0 || __progressPercentage == 100)
3950         {
3951                 __pProgressbarLabel->SetShowState(false);
3952                 __pProgressbarLabel->Invalidate(false);
3953                 return;
3954         }
3955         else
3956         {
3957                 __pProgressbarLabel->SetShowState(true);
3958                 __pProgressbarLabel->Invalidate(false);
3959         }
3960
3961         r = canvas.Construct(Rectangle(0, 0, w, h));
3962
3963         if (r != E_SUCCESS)
3964         {
3965                 AppLogException("Canvas construction failed with %s", GetErrorMessage(r));
3966                 return;
3967         }
3968
3969         canvas.Clear();
3970         Bitmap *pBgBmp = AppResource::GetInstance()->GetBitmapN(IDB_TITLE_PROGRESS_BAR_BG);
3971
3972         if (pBgBmp != null)
3973         {
3974                 pBgBmp->Scale(Dimension(w, h));
3975                 canvas.DrawBitmap(Point(0,0), *pBgBmp);
3976                 delete pBgBmp;
3977         }
3978
3979         progressWidth = (double) (w) * __progressPercentage / 100;
3980         AppLogDebug("progressWidth: %d", progressWidth);
3981         Bitmap *pProgressBmp = AppResource::GetInstance()->GetBitmapN(IDB_TITLE_PROGRESS_BAR);
3982
3983         if (pProgressBmp != null)
3984         {
3985                 pProgressBmp->Scale(Dimension(progressWidth, h));
3986                 canvas.DrawBitmap(Point(0,0), *pProgressBmp);
3987                 delete pProgressBmp;
3988         }
3989
3990         pRetBitmap = new (std::nothrow) Bitmap();
3991
3992         if (pRetBitmap == null)
3993         {
3994                 AppLogException("Bitmap creation failed with %s", GetErrorMessage(r));
3995                 return;
3996         }
3997
3998         pRetBitmap->Construct(canvas, canvas.GetBounds());
3999
4000         if (__pProgressbarLabel != null && pRetBitmap != null)
4001         {
4002                 __pProgressbarLabel->SetBackgroundBitmap(*pRetBitmap);
4003                 __pProgressbarLabel->Invalidate(false);
4004         }
4005
4006         if (pRetBitmap != null)
4007         {
4008                 delete pRetBitmap;
4009                 pRetBitmap = null;
4010         }
4011         return;
4012 }
4013
4014 void MainForm::SetAddressbarMode(AddressBarMode addMode)
4015 {
4016         AppLogDebug("AddressBar::setAddressbarMode to %d",addMode);
4017
4018         __currentAddMode = addMode;
4019
4020         switch(addMode)
4021         {
4022         case ADDRESSBAR_MODE_INVALID:
4023         {
4024                 // do nothing
4025         }
4026         break;
4027         case ADDRESSBAR_MODE_READER:
4028         {
4029                 __pStopBtn->SetShowState(false);
4030                 __pClearBtn->SetShowState(false);
4031         }
4032         break;
4033         case ADDRESSBAR_MODE_LOADING:
4034         {
4035                 __pRefreshBtn->SetShowState(false);
4036                 __pStopBtn->SetShowState(true);
4037                 __pClearBtn->SetShowState(false);
4038         }
4039         break;
4040         case ADDRESSBAR_MODE_LOADING_COMPLETE:
4041         {
4042 //              SetUrl(__pAddressbar->GetUrl());
4043
4044                 __pRefreshBtn->SetShowState(true);
4045                 __pStopBtn->SetShowState(false);
4046                 __pClearBtn->SetShowState(false);
4047         }
4048         break;
4049         case ADDRESSBAR_MODE_EDIT:
4050         {
4051                 __pRefreshBtn->SetShowState(false);
4052                 __pStopBtn->SetShowState(false);
4053                 __pClearBtn->SetShowState(true);
4054         }
4055         break;
4056         }
4057
4058         Invalidate(true);
4059
4060         OnAddressBarModeChanged();
4061 }
4062
4063 AddressBarMode MainForm::GetAddressbarMode(void)
4064 {
4065         return __currentAddMode;
4066 }
4067
4068 void MainForm::SetUrl(const String& url)
4069 {
4070         __displayUrl = url;
4071
4072         if (__pFooterUrlField != NULL)
4073         {
4074                 String removedHttpUrl = RemoveHttpTextFromDisplayURL();
4075                 if (removedHttpUrl.IsEmpty() == false)
4076                 {
4077                         __pFooterUrlField->SetText(removedHttpUrl);
4078                         __pAddressbar->SetUrl(__displayUrl);
4079                 }
4080                 else
4081                 {
4082                         __pFooterUrlField->SetText(__displayUrl);
4083                         __pAddressbar->SetUrl(__displayUrl);
4084                 }
4085
4086                 __pFooterUrlField->Invalidate(false);
4087                 __pAddressbar->Invalidate(true);
4088                 __pFooterUrlField->SetCursorPosition(0);
4089         }
4090 }
4091
4092 String
4093 MainForm::RemoveHttpTextFromDisplayURL(void)
4094 {
4095         bool isHttpText = __displayUrl.Contains(L"http://");
4096         String updatedDisplayUrl;
4097         updatedDisplayUrl.Clear();
4098
4099         if (isHttpText == true)
4100         {
4101                 __displayUrl.SubString(7,updatedDisplayUrl);
4102         }
4103         return updatedDisplayUrl;
4104 }