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