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