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