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