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