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