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