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