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