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