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