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