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