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