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