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