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