Fixed Nabi Issues
[apps/osp/Internet.git] / src / IntMainForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (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 #include <FShell.h>
29 //#include <FShellNotificationManager.h>
30
31 #include "IntBookmarkData.h"
32 #include "IntBookmarkPresentationModel.h"
33 #include "IntCommonLib.h"
34 #include "IntFaviconManager.h"
35 #include "IntInternetApp.h"
36 #include "IntMainForm.h"
37 #include "IntSceneRegister.h"
38 #include "IntSettingPresentationModel.h"
39
40 using namespace Tizen::App;
41 using namespace Tizen::Base;
42 using namespace Tizen::Base::Collection;
43 using namespace Tizen::Base::Runtime;
44 using namespace Tizen::Base::Utility;
45 using namespace Tizen::Graphics;
46 using namespace Tizen::Io;
47 using namespace Tizen::Locales;
48 using namespace Tizen::Media;
49 using namespace Tizen::Shell;
50 using namespace Tizen::Ui;
51 using namespace Tizen::Ui::Controls;
52 using namespace Tizen::Content;
53 using namespace Tizen::Ui::Scenes;
54 using namespace Tizen::System;
55 using namespace Tizen::Web;
56 using namespace Tizen::Web::Controls;
57
58 static const wchar_t* IDB_SEARCH_INPUT_FIELD_BG = L"I01_toolbar_input_field.9.png";
59 static const wchar_t* IDB_FINDWORD_INPUT_FIELD_BG = L"I01_toolbar_input_field_findword.9.png";
60 static const wchar_t* IDB_BTN_BACK = L"I01_icon_Back.png";
61 static const wchar_t* IDB_BTN_BACK_PRESS = L"I01_icon_Back_press.png";
62 static const wchar_t* IDB_CONTRLBAR_ICON_BOOKMARK = L"I01_search_list_icon_favorite.png";
63 static const wchar_t* IDB_CONTRLBAR_ICON_BOOKMARK_PRESS = L"I01_search_list_icon_favorite_press.png";
64 static const wchar_t* IDB_CONTRLBAR_ICON_MORE = L"I01_icon_more.png";
65 static const wchar_t* IDB_CONTRLBAR_ICON_MORE_PRESS = L"I01_icon_more_press.png";
66 static const wchar_t* IDB_CONTRLBAR_ICON_NEW_WINDOW = L"I01_icon_plus.png";
67 static const wchar_t* IDB_CONTRLBAR_ICON_NEW_WINDOW_PRESS = L"I01_icon_plus_press.png";
68 static const wchar_t* IDB_CONTROLBAR_ICON_CREATE_DISABLE = L"I01_controlbar_icon_create_disable.png";
69 static const wchar_t* IDB_BUTTON_ON = L"00_button_on.png";
70 static const wchar_t* IDB_BUTTON_OFF = L"00_button_off.png";
71 static const wchar_t* IDB_ICON_BOOKMARK_OFF_TEMP = L"I01_icon_bookmark_off_temp.png";
72 static const wchar_t* IDB_ICON_BOOKMARK_ON_TEMP = L"I01_icon_bookmark_on_temp.png";
73 static const wchar_t* IDS_TIZEN_SERVICE = L"tizen-service";
74 static const wchar_t* IDS_APPID = L"AppID";
75 static const wchar_t* IDS_KEY = L"key";
76 static const wchar_t* IDS_VALUE = L"value";
77 static const wchar_t* IDB_TITLE_PROGRESS_BAR_BG = L"I01_title_progress_bar_bg.png";
78 static const wchar_t* IDB_TITLE_PROGRESS_BAR = L"I01_title_progress_bar.png";
79 //static const wchar_t* IDB_ADDRESS_BAR_BACKGROUND = L"I01_toolbar_bg_02.9.png";
80
81 const int IDA_BACKBTN_CLICKED = 101;
82 const int IDA_BOOKMARKBTN_CLICKED = 102;
83 const int IDA_MOREBTN_CLICKED = 103;
84 const int IDA_MULTIWINDOWBTN_CLICKED = 104;
85 const int IDA_NEWWINDOWBTN_CLICKED = 105;
86 const int IDA_FORWARD_CLICKED = 106;
87 const int IDA_ADDTOBOOKMARK_CLICKED = 107;
88 const int IDA_SHARE_CLICKED = 108;
89 const int IDA_FINDONPAGE_CLICKED = 109;
90 const int IDA_PRIVATEON_CLICKED = 110;
91 const int IDA_SETTINGS_CLICKED = 111;
92 const int IDA_READER_CLOSE_CLICKED = 112;
93 const int IDA_SMALLFONT_BTN_CLICKED = 113;
94 const int IDA_LARGEFONT_BTN_CLICKED = 114;
95 const int IDA_BRIGHTNESS_BTN_CLICKED = 115;
96 const int IDA_HISTORY_CLICKED = 116;
97 const int IDA_ADD_TO_BOOKMARKBTN_CLICKED = 117;
98 const int IDA_ADD_TO_HOME_CLICKED = 118;
99 const int IDA_SAVED_PAGES_CLICKED = 119;
100 const int IDA_DESKTOP_VIEW_CLICKED = 120;
101 const int IDA_SAVE_CLICKED = 121;
102 const int IDA_PRINT_CLICKED = 122;
103
104 const int IDA_FINDWORD_SEARCH_CLICKED = 201;
105 const int IDA_FINDWORD_NEXT_CLICKED = 202;
106 const int IDA_FINDWORD_PREV_CLICKED = 203;
107 const int IDA_FINDWORD_CLEAR_CLICKED = 204;
108 const int IDA_FINDWORD_CANCEL_CLICKED = 205;
109
110 const int IDA_COPY_IMAGE_CLICKED = 206;
111 const int IDA_VIEW_IMAGE_CLICKED = 207;
112 const int IDA_SAVE_IMAGE_CLICKED = 208;
113 const int IDA_SHARE_IMAGE_CLICKED = 209;
114
115 const int IDA_COPY_TEXT_CLICKED = 210;
116 const int IDA_PASTE_TEXT_CLICKED = 211;
117 const int IDA_FIND_TEXT__CLICKED = 212;
118 const int IDA_SHARE_TEXT_CLICKED = 213;
119
120 const int IDA_GO_BACK = 214;
121 const int IDA_GO_FORWARD = 215;
122 const int IDA_REFRESH_BTN_CLICKED = 216;
123 const int IDA_STOP_BTN_CLICKED = 217;
124 const int IDA_CLEAR_URL = 218;
125 const int IDA_READER_BTN_CLICKED = 219;
126
127
128 const int IDA_HYPERLINK_OPEN_CLICKED = 220;
129 const int IDA_HYPERLINK_COPY_LINK_CLICKED = 221;
130 const int IDA_HYPERLINK_SAVE_IMAGE_CLICKED = 222;
131 const int IDA_HYPERLINK_SHARE_IMAGE_CLICKED = 223;
132
133 const int IDA_FINDWORD_CLEAR_RIGHT_TO_LEFT_CLICKED = 224;
134
135 const int DEFAULT_PROGRESS_PERCENTAGE = 10;
136
137 const int MainForm::IDA_FORMAT_BITMAP = 500;
138 const int MainForm::IDA_FORMAT_DELETE_BITMAP = 501;
139 const int MainForm::IDA_FORMAT_TITLE_STRING = 502;
140 const int MainForm::IDA_FORMAT_URL_STRING = 503;
141 const int MainForm::IDA_CONTEXT_ITEM_DELETE = 504;
142
143 static const int WIDTH_CONTEXT_MENU_BUTTON_PORTRAIT = 336;
144 static const int WIDTH_CONTEXT_MENU_BUTTON_LANDSCAPE = 800;
145 static const int HEIGHT_CONTEXT_MENU_BUTTON = 72;
146
147 static const wchar_t* APPCONTROL_OPERATION_ID_IMAGE_VIEWER = L"http://tizen.org/appcontrol/operation/view";
148 MainForm::MainForm(void)
149 {
150         __isLongPressedDone = false;
151         __pHistory = null;
152         __pAddressbar = null;
153         //      __pMostVisitedSitesPanel = null;
154         __pMostVisitedListView = null;
155         __pFooterPanel = null;
156         __pHitElementResult = null;
157         __pWindowInfo = null;
158         __pWebViewer = null;
159         __pImageMenu = null;
160         __pOptionMenu = null;
161         __pFindWordControl = null;
162         __pFindWordPanelLeftToRight = null;
163         __pFindWordPanelRightToLeft = null;
164         __pFindWordBgLabel = null;
165         __pFindWordBgLabelRightToLeft = null;
166         __pFindWordEditField = null;
167         __pFindWordEditFieldRightToLeft = null;
168         __pFindWordClear = null;
169         __pFindWordClearRightToLeft = null;
170         __pFindWordCountLabel = null;
171         __pFindWordClearRightToLeft = null;
172         __pFindWordNext = null;
173         __pFindWordPrev = null;
174         __previousZoomLevel = 1.0;
175         __pSaveImage = null;
176         __currentAddMode = ADDRESSBAR_MODE_LOADING_COMPLETE;
177         __displayUrl = L"";
178         __editTextUrl = L"";
179         __currentSearchStr = L"";
180         __currentSelectedStr = L"";
181         __maxOccurrances = 0;
182         __currentWordIndex = 0;
183         __distanceMoved = 0;
184         __isLoaded = false;
185         //__inputEventToBeSupressed = false;
186         __isLoadingData = false;
187         __isLoadingCompleted = false;
188         __progressPercentage = 0;
189         __touchPoint1 = Point(-1,-1);
190         __touchPoint2 = Point(-1,-1);
191         __longPressPoint = Point(-1,-1);
192         __pWebReader = null;
193         //      __pReaderPopup = null;
194         __pReaderData = null;
195         __pPopUp = null;
196         __pReaderCloseBtn = null;
197         //__pNewWindowButton = null;
198         __pMoreButton = null;
199         __pMultiWindowButton = null;
200         __pArticleReaderPanel = null;
201         __pBlankPanel = null;
202         __pArticleReaderLabel = null;
203         __webControlHeight = 0;
204         __prevAddressBarMode = ADDRESSBAR_MODE_INVALID;
205         __curAddressBarMode = ADDRESSBAR_MODE_INVALID;
206         __pMostVisitedSites = null;
207         __pFooterUrlField = null;
208         __pGoBackBtn = null;
209         __pGoForwardBtn = null;
210         __pRefreshBtn = null;
211         __pProgressbarLabel = null;
212         __pFooterLabel = null;
213         __pStopBtn = null;
214         __pClearBtn = null;
215         __pReaderBtn = null;
216         __isKeypadOpened = false;
217         __fontSize = 44;
218         __pNotification = null;
219 }
220
221 MainForm::~MainForm(void)
222 {
223         SettingPresentationModel::GetInstance()->RemoveSettingsEventListener(*this);
224
225         if(__pAddressbar)
226         {
227                 __pAddressbar->SetAddressbarEventListener(null);
228         }
229
230         if(__pHistory != null)
231         {
232                 delete __pHistory;
233                 __pHistory = null;
234         }
235
236         if (__pReaderData != null)
237         {
238                 delete __pReaderData;
239                 __pReaderData = null;
240         }
241
242         if (__pPopUp != null)
243         {
244                 delete __pPopUp;
245                 __pPopUp = null;
246         }
247
248         if (__pHitElementResult != null)
249         {
250                 delete __pHitElementResult;
251                 __pHitElementResult = null;
252         }
253         if(__pOptionMenu)
254         {
255                 delete __pOptionMenu;
256                 __pOptionMenu = null;
257         }
258
259         String* pSelectedScene = NULL;
260         Object* pValue = NULL;
261         MultipleWindowPresentationModel::GetInstance()->GetValue(SELECTED_SCENE_ID, &pValue);
262         pSelectedScene = (String*) pValue;
263
264         /*if (pSelectedScene != null)
265         {
266                 delete pSelectedScene;
267         }
268         MultiWindowPresentationModel::SetValue(SELECTED_SCENE_ID, null);*/
269 }
270
271 bool
272 MainForm::Initialize(void)
273 {
274         Construct(L"IDL_FORM");
275
276 //      SetFormStyle(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_FOOTER);
277         return true;
278 }
279
280 result
281 MainForm::OnInitializing(void)
282 {
283         AppLog("get client area width = %d",GetClientAreaBounds().width);
284         AppLog("get client area height = %d",GetClientAreaBounds().height);
285         const int WIDTH_CONTEXT_MENU_BUTTON = 336;
286         const int HEIGHT_CONTEXT_MENU_BUTTON = 72;
287
288         __fontSize = CommonUtil::GetFontSize();
289         Panel* pFooterPanel = null;
290
291         __pSaveImage = new Image();
292         __pSaveImage->Construct();
293
294         // Setup back event listener
295         SettingPresentationModel::GetInstance()->AddSettingsEventListener(*this);
296         SceneManager::GetInstance()->AddSceneEventListener(IDSCN_MAIN_VIEW, *this);
297         AddOrientationEventListener(*this);
298
299         AppLogDebug(" MainForm::OnInitializing ended");
300         if (__pMostVisitedSites == null)
301         {
302                 __pMostVisitedSites = new(std::nothrow) ArrayList();
303                 __pMostVisitedSites->Construct();
304         }
305         HistoryPresentationModel::GetInstance()->GetMostVisitedSites(*__pMostVisitedSites);
306
307         __pItemContext= new(std::nothrow) ListContextItem();
308         __pItemContext->Construct();
309
310         __pItemContext->AddElement(IDA_CONTEXT_ITEM_DELETE, CommonUtil::GetString(L"IDS_BR_SK_DELETE_ABB"),true);
311
312
313         __pItemContext->SetElementBackgroundColor(IDA_CONTEXT_ITEM_DELETE,LIST_CONTEXT_ITEM_ELEMENT_STATUS_NORMAL , CONTEXT_ITEM_DELETE_COLOR);
314         __pItemContext->SetElementBackgroundColor(IDA_CONTEXT_ITEM_DELETE,LIST_CONTEXT_ITEM_ELEMENT_STATUS_HIGHLIGHTED , CONTEXT_ITEM_DELETE_COLOR);
315         __pItemContext->SetElementBackgroundColor(IDA_CONTEXT_ITEM_DELETE,LIST_CONTEXT_ITEM_ELEMENT_STATUS_PRESSED , CONTEXT_ITEM_DELETE_COLOR);
316
317         __pItemContextLandscape= new(std::nothrow) ListContextItem();
318         __pItemContextLandscape->Construct();
319
320         __pItemContextLandscape->AddElement(IDA_CONTEXT_ITEM_DELETE, CommonUtil::GetString(L"IDS_BR_SK_DELETE_ABB"), true);
321         __pItemContextLandscape->SetElementBackgroundColor(IDA_CONTEXT_ITEM_DELETE,LIST_CONTEXT_ITEM_ELEMENT_STATUS_NORMAL , CONTEXT_ITEM_DELETE_COLOR);
322         __pItemContextLandscape->SetElementBackgroundColor(IDA_CONTEXT_ITEM_DELETE,LIST_CONTEXT_ITEM_ELEMENT_STATUS_HIGHLIGHTED , CONTEXT_ITEM_DELETE_COLOR);
323         __pItemContextLandscape->SetElementBackgroundColor(IDA_CONTEXT_ITEM_DELETE,LIST_CONTEXT_ITEM_ELEMENT_STATUS_PRESSED , CONTEXT_ITEM_DELETE_COLOR);
324         SetFormMenuEventListener(this);
325         AppLog("SetFormMenuEventListener result %s",GetErrorMessage(GetLastResult()));
326         return E_SUCCESS;
327 }
328
329 result
330 MainForm::InitAddressbar(void)
331 {
332         AppLogDebug("MainForm::InitAddressbar entered");
333
334         result r = E_SUCCESS;
335
336         if (__pAddressbar != null)
337         {
338                 return E_SUCCESS;
339         }
340         __pAddressbar = new(std::nothrow) Addressbar();
341         AppLog("MainForm::InitAddressbar GetClientAreaBounds().width %d",GetClientAreaBounds().width);
342         r = __pAddressbar->Initialize(Tizen::Graphics::Rectangle(0, 0, GetClientAreaBounds().width, 82));
343         if (r != E_SUCCESS)
344         {
345                 AppLogDebug("Addressbar init failed with %s", GetErrorMessage(r));
346                 return r;
347         }
348         __pAddressbar->SetAddressbarEventListener(this);
349         AddControl(__pAddressbar);
350         __pAddressbar->SetBounds(Rectangle(0,0,GetClientAreaBounds().width,__pAddressbar->GetHeight()));
351         SetControlAlwaysOnTop(*__pAddressbar, true);
352         __adressPanelPosition = __pAddressbar->GetPosition();
353
354         AppLogDebug("MainForm::InitAddressbar exit");
355
356         return E_SUCCESS;
357 }
358
359 result
360 MainForm::CreateReaderPanel(void)
361 {
362         AppLogDebug("CreateReaderPanel() width %d",GetClientAreaBounds().width);
363         result r = E_FAILURE;
364         WebSetting settings;
365         Button *pSmallFontBtn = null;
366         Button *pLargeFontBtn = null;
367
368         __pBlankPanel = new (std::nothrow) Panel();
369         __pBlankPanel->Construct(L"IDL_BLANK_PANEL");
370
371         __pArticleReaderPanel = new (std::nothrow) Panel();
372         __pArticleReaderPanel->Construct(L"IDL_ARTICLE_READER");
373
374         __pReaderCloseBtn =  static_cast<Button*>(__pArticleReaderPanel->GetControl(L"IDC_CLOSE_READER",true));
375         if (__pReaderCloseBtn)
376         {
377                 AppLogDebug("CreateReaderPanel() 6");
378                 __pReaderCloseBtn->AddActionEventListener(*this);
379                 __pReaderCloseBtn->SetActionId(IDA_READER_CLOSE_CLICKED);
380         }
381
382         __pWebReader = new (std::nothrow) Web();
383         __pWebReader->Construct(Rectangle(2,2, __pArticleReaderPanel->GetWidth()-2,__pArticleReaderPanel->GetHeight() - 96 -2));
384
385         settings.SetInputStyle(INPUT_STYLE_OVERLAY);
386         settings.SetFontSize(SettingPresentationModel::GetInstance()->GetReaderFontSize());
387
388         r = __pWebReader->SetSetting(settings);
389         if (IsFailed(r))
390                 AppLogDebug("Web setting add failed with %s", GetErrorMessage(r));
391
392
393         __pArticleReaderLabel = new Label();
394         __pArticleReaderLabel->Construct(Rectangle(__pArticleReaderPanel->GetX(),__pArticleReaderPanel->GetY(),__pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight()),L"");
395
396         __pBlankPanel->AddControl(__pArticleReaderLabel);
397         __pBlankPanel->AddControl(__pArticleReaderPanel);
398         AddControl(__pBlankPanel);
399
400         __pBlankPanel->SetBounds(0,0,GetClientAreaBounds().width,GetClientAreaBounds().height);
401         __pArticleReaderPanel->SetBounds((GetClientAreaBounds().width - __pArticleReaderPanel->GetWidth())/2,(GetClientAreaBounds().height - __pArticleReaderPanel->GetHeight())/2, __pArticleReaderPanel->GetWidth(), __pArticleReaderPanel->GetHeight());
402         __pArticleReaderLabel->SetBounds(__pArticleReaderPanel->GetX(),__pArticleReaderPanel->GetY(),__pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight());
403
404         __pArticleReaderPanel->AddControl(__pWebReader);
405         __pWebReader->SetBounds(Rectangle(2,2, __pArticleReaderPanel->GetWidth()-2,__pArticleReaderPanel->GetHeight() - 96 -2));
406         Bitmap* pBitmap = CommonUtil::GetNinepatchedBitmapN(L"I01_popup_bg.9.png",__pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight());
407         Bitmap* pSrcBitmap = CommonUtil::GetNinepatchedBitmapN(L"I01_popup_bottom_bg.9.png",__pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight());
408
409         if (pBitmap != null && pSrcBitmap != null)
410         {
411                 pBitmap->Merge(Point(0,__pArticleReaderPanel->GetHeight() - 96),*pSrcBitmap,Rectangle(0,0,pSrcBitmap->GetWidth(),pSrcBitmap->GetHeight()));
412         }
413         __pArticleReaderLabel->SetBackgroundBitmap(*pBitmap);
414
415         pSmallFontBtn =  static_cast<Button*>(__pArticleReaderPanel->GetControl(L"IDC_SMALL_FONT",true));
416         if (pSmallFontBtn)
417         {
418                 pSmallFontBtn->AddActionEventListener(*this);
419                 pSmallFontBtn->SetActionId(IDA_SMALLFONT_BTN_CLICKED);
420         }
421
422         pLargeFontBtn =  static_cast<Button*>(__pArticleReaderPanel->GetControl(L"IDC_LARGE_FONT",true));
423         if (pLargeFontBtn)
424         {
425                 pLargeFontBtn->AddActionEventListener(*this);
426                 pLargeFontBtn->SetActionId(IDA_LARGEFONT_BTN_CLICKED);
427         }
428
429
430         if (pBitmap != null)
431         {
432                 delete pBitmap;
433                 pBitmap = null;
434         }
435         if (pSrcBitmap != null)
436         {
437                 delete pSrcBitmap;
438                 pSrcBitmap = null;
439         }
440
441         SetControlAlwaysOnTop(*__pBlankPanel, true);
442         //__pBlankPanel->SetControlAlwaysAtBottom(*__pArticleReaderPanel, true);
443         Invalidate(true);
444
445         return E_SUCCESS;
446 }
447
448 result
449 MainForm::InitWebControl()
450 {
451         AppLogDebug("MainForm::InitWebControl enter");
452         result r = E_SUCCESS;
453         AppLogDebug("InitWebControl");
454
455         if (__pAddressbar == null || __pFooterPanel == null)
456                 return E_FAILURE;
457
458         const int Y_WEBCONTROL_POSITION = 0;
459
460         __webControlHeight = GetHeight() - __pFooterPanel->GetHeight();
461
462         if (__pMostVisitedListView)
463         {
464                 __pMostVisitedListView->SetShowState(false);
465         }
466         if (__pWebViewer != null)
467         {
468                 AppLogDebug("Already initialized");
469                 return E_SUCCESS;
470         }
471         __pWebViewer = new(std::nothrow) Web();
472         if(__pWebViewer == NULL)
473         {
474                 AppLogDebug("Initialization failed");
475                 return E_FAILURE;
476         }
477         r = __pWebViewer->Construct(Rectangle(0, Y_WEBCONTROL_POSITION, GetClientAreaBounds().width,__webControlHeight + 12));
478
479         if (IsFailed(r))
480         {
481                 AppLogDebug("Web construct failed with %s", GetErrorMessage(r));
482                 delete __pWebViewer;
483                 __pWebViewer = null;
484                 return r;
485         }
486         else
487         {
488                 r = AddControl(__pWebViewer);
489
490                 if (IsFailed(r))
491                 {
492                         delete __pWebViewer;
493                         __pWebViewer = null;
494                         AppLogDebug("Web addcontrol failed with %s", GetErrorMessage(r));
495                         return r;
496                 }
497                 __webControlPosition = __pWebViewer->GetPosition();
498                 r = __pWebViewer->SetSetting(SettingPresentationModel::GetInstance()->GetWebSettings());
499                 if (IsFailed(r))
500                 {
501                         AppLogDebug("Web setting add failed with %s", GetErrorMessage(r));
502                         return r;
503                 }
504
505                 __pWebViewer->SetLoadingListener(this);
506                 __pWebViewer->SetWebUiEventListenerF(this);
507                 __pWebViewer->SetWebKeypadEventListener(this);
508                 __pWebViewer->SetFocus();
509                 __pWebViewer->AddTouchEventListener(*this);
510
511                 __pWebViewer->SetCookieEnabled(SettingPresentationModel::GetInstance()->IsCookiesEnabled());
512                 __pWebViewer->SetTextSearchListener(this);
513         }
514
515         AppLogDebug("MainForm :before return");
516         Invalidate(true);
517         AppLogDebug("MainForm::InitWebControl Exit");
518
519         return r;
520 }
521
522 void
523 MainForm::SetJavascriptEnabled()
524 {
525         WebSetting settings = __pWebViewer->GetSetting();
526         settings.SetJavascriptEnabled(SettingPresentationModel::GetInstance()->IsRunJavascriptEnabled());
527         __pWebViewer->SetSetting(settings);
528 }
529
530 void
531 MainForm::SetImageLoadEnabled()
532 {
533         WebSetting settings = __pWebViewer->GetSetting();
534         settings.SetAutoImageLoadEnabled(SettingPresentationModel::GetInstance()->IsDisplayImagesEnabled());
535         __pWebViewer->SetSetting(settings);
536 }
537
538 result
539 MainForm::InitFooter(void)
540 {
541         AppLogDebug("MainForm::InitFooter entered");
542         Button* pBackButton = null;
543         Button* pBookmarkButton = null;
544         Button* pMultiWindowButton = null;
545         Bitmap *pIconBitmap = null;
546         Bitmap *pBGBitmap = null;
547         Label *pBGLabel = null;
548
549         if (__pFooterPanel == null)
550         {
551                 __pFooterPanel = static_cast< Panel* >(GetControl(L"IDC_FOOTER_PANEL", true));
552         }
553
554         if (__pFooterPanel == null)
555         {
556                 return E_FAILURE;
557         }
558
559         SetControlAlwaysOnTop(*__pFooterPanel, true);
560
561         __pFooterLabel = static_cast< Label* >(GetControl(L"IDC_FOOTER_LABEL", true));
562         if ( __pFooterLabel == NULL )
563         {
564                 return E_FAILURE;
565         }
566         //__pFooterPanel->SetBackgroundColor(CUSTOM_COLOR_TRANSPARENT);
567         Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_SEARCH_INPUT_FIELD_BG, __pFooterLabel->GetWidth(), __pFooterLabel->GetHeight());
568         if (pBitmap != null)
569         {
570                 __pFooterLabel->SetBackgroundBitmap(*pBitmap);
571                 delete pBitmap;
572         }
573
574         __pMultiWindowButton = static_cast< Button* >(GetControl(L"IDC_MULTIWINDOW_BUTTON", true));
575
576         if ( __pMultiWindowButton == NULL )
577         {
578                 return E_FAILURE;
579         }
580
581
582         SetFormBackEventListener(this);
583         AppLog("SetFormBackEventListener result  %s",GetErrorMessage(GetLastResult()));
584         if (__pMultiWindowButton != null)
585         {
586                 Bitmap* pBitmap = null;
587                 Bitmap* pPressedBitmap = null;
588                 String imagePath = "I01_toolbar_icon_windows_manager_0";
589                 String pressedImagePath = "I01_toolbar_icon_windows_manager_0";
590                 int totalCount = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList()->GetCount();
591                 imagePath.Append(totalCount);
592                 imagePath.Append(".png");
593
594                 pressedImagePath.Append(totalCount);
595                 pressedImagePath.Append("_press.png");
596
597                 pBitmap = AppResource::GetInstance()->GetBitmapN(imagePath);
598                 pPressedBitmap = AppResource::GetInstance()->GetBitmapN(pressedImagePath);
599                 if ( pBitmap == null )
600                 {
601                         return E_FAILURE;
602                 }
603
604                 Point startPoint = Point((__pMultiWindowButton->GetWidth() - pBitmap->GetWidth())/2,(__pMultiWindowButton->GetHeight() - pBitmap->GetHeight())/2);
605                 if (pBitmap != null)
606                 {
607                         __pMultiWindowButton->SetNormalBitmap(startPoint, *pBitmap);
608                         __pMultiWindowButton->SetPressedBitmap(startPoint, *pPressedBitmap);
609
610                         delete pBitmap;
611                 }
612
613                 __pMultiWindowButton->AddActionEventListener(*this);
614                 __pMultiWindowButton->SetActionId(IDA_MULTIWINDOWBTN_CLICKED);
615                 if(pPressedBitmap)
616                 {
617                         delete pPressedBitmap;
618                         pPressedBitmap = null;
619                 }
620         }
621
622         if (__pMoreButton)
623         {
624                 Bitmap* pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_CONTRLBAR_ICON_MORE);
625                 Bitmap* pPressedBitmap = AppResource::GetInstance()->GetBitmapN(IDB_CONTRLBAR_ICON_MORE_PRESS);
626                 if (pBitmap != null)
627                 {
628                         Point startPoint((__pMoreButton->GetWidth() - pBitmap->GetWidth())/2,(__pMoreButton->GetHeight() - pBitmap->GetHeight())/2 );
629                         __pMoreButton->SetNormalBitmap(startPoint, *pBitmap);
630                         __pMoreButton->SetPressedBitmap(startPoint, *pPressedBitmap);
631
632                         delete pBitmap;
633                 }
634                 __pMoreButton->AddActionEventListener(*this);
635                 __pMoreButton->SetActionId(IDA_MOREBTN_CLICKED);
636         }
637
638         //Add the editfield for url
639         __pFooterUrlField =  static_cast<EditField*> (GetControl(L"IDC_URL_EDIT_FIELD",true));
640         if (__pFooterUrlField == NULL)
641         {
642                 return E_INVALID_KEY;
643         }
644
645         __pFooterUrlField->SetOverlayKeypadCommandButtonVisible(false);
646         __pFooterUrlField->SetKeypadAction(KEYPAD_ACTION_GO);
647         __pFooterUrlField->AddKeypadEventListener(*this);
648         __pFooterUrlField->SetPropagatedTouchEventListener(this);
649         __pFooterUrlField->AddFocusEventListener(*this);
650
651         if (SettingPresentationModel::GetInstance()->GetHomepage().CompareTo((L"IDS_BR_BODY_MOST_VISITED_SITES")) == 0)
652         {
653                 __pFooterUrlField->SetGuideText(CommonUtil::GetString(L"IDS_BR_BODY_SEARCH_OR_ENTER_URL"));
654         }
655         else if (SettingPresentationModel::GetInstance()->GetHomepage().CompareTo((L"IDS_BR_BODY_BLANK_PAGE")) == 0)
656         {
657                 __pFooterUrlField->SetGuideText(CommonUtil::GetString(L"IDS_BR_BODY_BLANK_PAGE"));
658         }
659         else
660         {
661                 //__pUrlField->SetText(SettingPresentationModel::GetInstance()->GetFavoriteURL());
662                 __pFooterUrlField->SetGuideText(CommonUtil::GetString(L"IDS_BR_BODY_SEARCH_OR_ENTER_URL"));
663         }
664
665
666         //Add the go Back Button
667         __pGoBackBtn = static_cast<Button*> (GetControl(L"IDC_PAGEBACK_BUTTON",true));
668         if (__pGoBackBtn == NULL)
669         {
670                 AppLogDebug("__pGoBackBtn Control not found returning E_INVALID_KEY");
671                 return E_INVALID_KEY;
672         }
673         __pGoBackBtn->SetActionId(IDA_GO_BACK);
674         __pGoBackBtn->AddActionEventListener(*this);
675
676         //Add the go forward Button
677         __pGoForwardBtn = static_cast<Button*> (GetControl(L"IDC_PAGEFORWARD_BUTTON",true));
678         if (__pGoForwardBtn == NULL)
679         {
680                 AppLogDebug("Control not found returning E_INVALID_KEY");
681                 return E_INVALID_KEY;
682         }
683         __pGoForwardBtn->SetActionId(IDA_GO_FORWARD);
684         __pGoForwardBtn->AddActionEventListener(*this);
685         if (__pWebViewer && __pWebViewer->CanGoForward())
686         {
687                 SetForwardButtonEnabled(true);
688         }
689         else
690         {
691                 SetForwardButtonEnabled(false);
692         }
693
694         __pRefreshBtn = static_cast<Button*> (GetControl(L"IDC_REFRESH_BUTTON",true));
695         if (__pRefreshBtn == NULL)
696         {
697                 AppLogDebug("Control not found returning E_INVALID_KEY");
698                 return E_INVALID_KEY;
699         }
700
701         __pRefreshBtn->SetActionId(IDA_REFRESH_BTN_CLICKED);
702         __pRefreshBtn->AddActionEventListener(*this);
703         __pRefreshBtn->SetShowState(true);
704
705         //Add the backround label for displaying progressbar
706         __pProgressbarLabel = static_cast<Label*> (GetControl(L"IDC_PROGRESS_BAR_LABEL",true));
707         if (__pProgressbarLabel == NULL)
708         {
709                 AppLogDebug("__pProgressbarLabel Control not found returning E_INVALID_KEY");
710                 return E_INVALID_KEY;
711         }
712         __pProgressbarLabel->SetShowState(false);
713
714         __pStopBtn = static_cast<Button*> (GetControl(L"IDC_STOP_BUTTON",true));
715         if (__pStopBtn == NULL)
716         {
717                 AppLogDebug("Control not found returning E_INVALID_KEY");
718                 return E_INVALID_KEY;
719         }
720         __pStopBtn->SetActionId(IDA_STOP_BTN_CLICKED);
721         __pStopBtn->AddActionEventListener(*this);
722         __pStopBtn->SetShowState(false);
723
724         __pClearBtn = static_cast<Button*> (GetControl(L"IDC_CLEAR_BUTTON",true));
725         if (__pClearBtn == NULL)
726         {
727                 AppLogDebug("Control not found returning E_INVALID_KEY");
728                 return E_INVALID_KEY;
729         }
730         __pClearBtn->SetActionId(IDA_CLEAR_URL);
731         __pClearBtn->AddActionEventListener(*this);
732         __pClearBtn->SetShowState(false);
733
734         __pReaderBtn = static_cast<Button*> (GetControl(L"IDC_READER_BUTTON",true));
735         if (__pReaderBtn == NULL)
736         {
737                 AppLogDebug("Control not found returning E_INVALID_KEY");
738                 return E_INVALID_KEY;
739         }
740         __pReaderBtn->SetActionId(IDA_READER_BTN_CLICKED);
741         __pReaderBtn->AddActionEventListener(*this);
742         __pReaderBtn->SetShowState(false);
743
744         //      __pFooterPanel->Invalidate(true);
745         if(__isKeypadOpened == false && __pAddressbar && __pAddressbar->GetShowState() == false)
746         {
747 //              AppLog("asdasdasdasda");
748                 __pFooterPanel->SetShowState(true);
749         }
750         else if(__pAddressbar == null)
751         {
752                 __pFooterPanel->SetShowState(true);
753         }
754         else
755                 __pFooterPanel->SetShowState(false);
756         AppLogDebug("MainForm::InitFooter exit");
757         return E_SUCCESS;
758 }
759
760 result
761 MainForm::InitOptionMenu()
762 {
763         result r = E_SUCCESS;
764         bool isPrivateBrowsing = false;
765         Bitmap* pBitmap = null;
766
767         if (__pOptionMenu != null)
768         {
769                 __pOptionMenu->SetFocusable(true);
770                 __pOptionMenu->Invalidate(true);
771                 return r;
772         }
773
774         __pOptionMenu = new(std::nothrow) OptionMenu();
775         r = __pOptionMenu->Construct();
776         TryCatch(!IsFailed(r),,"Contextmenu creation failed with%s",GetErrorMessage(r));
777
778         __pOptionMenu->SetFocusable(true);
779         isPrivateBrowsing = SettingPresentationModel::GetInstance()->GetPrivateOn();
780
781
782         if (isPrivateBrowsing == true)
783         {
784                 pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_BUTTON_ON);
785         }
786         else
787         {
788                 pBitmap  = AppResource::GetInstance()->GetBitmapN(IDB_BUTTON_OFF);
789         }
790
791         r = __pOptionMenu->AddItem(CommonUtil::GetString(L"IDS_BR_OPT_BOOKMARK"), IDA_BOOKMARKBTN_CLICKED);
792
793         if ( pBitmap != NULL)
794         {
795                 __pOptionMenu->AddItem(CommonUtil::GetString(L"IDS_BR_BODY_PRIVACY_AND_SECURITY_ABB"), IDA_PRIVATEON_CLICKED,*pBitmap);
796                 delete pBitmap;
797         }
798         r = __pOptionMenu->AddItem(CommonUtil::GetString(L"IDS_BR_TAB_HISTORY"), IDA_HISTORY_CLICKED);
799         r = __pOptionMenu->AddItem(CommonUtil::GetString(L"IDS_COM_OPT_BRIGHTNESS"), IDA_BRIGHTNESS_BTN_CLICKED);
800         r = __pOptionMenu->AddItem(CommonUtil::GetString(L"IDS_COM_BODY_SETTINGS"), IDA_SETTINGS_CLICKED);
801
802
803         __pOptionMenu->SetMaxVisibleItemsCount(6);
804         __pOptionMenu->SetShowState(false);
805         __pOptionMenu->AddActionEventListener(*this);
806         SetControlAlwaysOnTop(*__pOptionMenu, true);
807
808         CATCH:
809         return r;
810 }
811
812 result MainForm::InitImageContextMenu(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         if(GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT || GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT_REVERSE)
824         {
825                 p.y = p.y + 54;
826         }
827
828         __pImageMenu = new (std::nothrow) ContextMenu();
829         r = __pImageMenu->Construct(p, CONTEXT_MENU_STYLE_LIST, direction);
830         TryCatch(!IsFailed(r),, "Context image menu creation failed with%s",GetErrorMessage(r));
831
832         r = __pImageMenu->AddItem(CommonUtil::GetString(L"IDS_BR_OPT_COPY_IMAGE"),IDA_COPY_IMAGE_CLICKED);
833         r = __pImageMenu->AddItem(CommonUtil::GetString(L"IDS_BR_OPT_VIEW_IMAGE"),IDA_VIEW_IMAGE_CLICKED);
834         r = __pImageMenu->AddItem(CommonUtil::GetString(L"IDS_BR_OPT_SAVE_IMAGE"),IDA_SAVE_IMAGE_CLICKED);
835         r = __pImageMenu->AddItem(CommonUtil::GetString(L"IDS_BR_OPT_SHARE"),IDA_SHARE_IMAGE_CLICKED);
836         __pImageMenu->SetMaxVisibleItemsCount(4);
837         __pImageMenu->AddActionEventListener(*this);
838         SetControlAlwaysOnTop(*__pImageMenu, true);
839         __pImageMenu->SetFocusable(true);
840
841         CATCH: return r;
842 }
843
844 result
845 MainForm::InitImageLinkContextMenu(Tizen::Graphics::Point p)
846 {
847         result r = E_SUCCESS;
848         ContextMenuAnchorDirection direction = CONTEXT_MENU_ANCHOR_DIRECTION_AUTO;
849
850         AppLog("MainForm::InitImageContextMenu clicked on image");
851         if (__pImageMenu != null)
852         {
853                 delete __pImageMenu;
854                 __pImageMenu = null;
855         }
856
857 //      if(__pAddressbar->GetShowState() == true)
858 //              p.y = p.y + __pAddressbar->GetHeight();
859         if(GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT || GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT_REVERSE)
860         {
861                 p.y = p.y + 54;
862         }
863
864         __pImageMenu = new (std::nothrow) ContextMenu();
865         r = __pImageMenu->Construct(p, CONTEXT_MENU_STYLE_LIST, direction);
866         TryCatch(!IsFailed(r),, "Context image menu creation failed with%s",GetErrorMessage(r));
867
868         r = __pImageMenu->AddItem(CommonUtil::GetString(L"IDS_BR_BODY_OPEN_IN_NEW_WINDOW"),IDA_HYPERLINK_OPEN_CLICKED);
869         r = __pImageMenu->AddItem(CommonUtil::GetString(L"IDS_BR_OPT_COPY_LINK_URL"),IDA_HYPERLINK_COPY_LINK_CLICKED);
870         //r = __pImageMenu->AddItem(CommonUtil::GetString(L"IDS_BR_OPT_SAVE_IMAGE"),IDA_HYPERLINK_SAVE_IMAGE_CLICKED);
871         r = __pImageMenu->AddItem(CommonUtil::GetString(L"IDS_BR_OPT_SHARE"),IDA_HYPERLINK_SHARE_IMAGE_CLICKED);
872
873         __pImageMenu->SetMaxVisibleItemsCount(3);
874         __pImageMenu->AddActionEventListener(*this);
875         SetControlAlwaysOnTop(*__pImageMenu, true);
876         __pImageMenu->SetFocusable(true);
877
878         CATCH: return r;
879
880 }
881
882 result
883 MainForm::InitSelectTextContextMenu(Point p, bool pasteOption, bool onlyPasteOption = false)
884 {
885         result r = E_SUCCESS;
886         bool clipboardAvailable = true;
887         ContextMenuAnchorDirection direction = CONTEXT_MENU_ANCHOR_DIRECTION_AUTO;
888
889         AppLog("MainForm::InitSelectTextContextMenu clicked on text");
890         if (__pImageMenu != null)
891         {
892                 delete __pImageMenu;
893                 __pImageMenu = null;
894         }
895
896         if(p.y < 150)
897         {
898                 p.y = p.y + 50;
899                 direction = CONTEXT_MENU_ANCHOR_DIRECTION_DOWNWARD;
900         }
901         else
902         {
903                 direction = CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD;
904         }
905
906
907         Clipboard* pClipboard = Clipboard::GetInstance();
908
909         if(pClipboard == null)
910         {
911                 clipboardAvailable = false;
912         }
913         else
914         {
915                 // Retrieves a latest item
916                 ClipboardItem* pItem = pClipboard->RetrieveLatestItemN(CLIPBOARD_DATA_TYPE_TEXT | CLIPBOARD_DATA_TYPE_HTML);
917
918                 if(pItem == null)
919                 {
920                         clipboardAvailable = false;
921                 }
922                 else
923                 {
924                         //Gets data from the clipboard item
925                         String* pString = dynamic_cast<String*>(pItem->GetData());
926
927                         if(pString == null)
928                         {
929                                 clipboardAvailable = false;
930                         }
931                 }
932         }
933         if(clipboardAvailable == false && onlyPasteOption == true)
934         {
935                 return E_FAILURE;
936         }
937
938         __pImageMenu = new (std::nothrow) ContextMenu();
939         r = __pImageMenu->Construct(p, CONTEXT_MENU_STYLE_GRID, direction);
940         TryCatch(!IsFailed(r),, "Context image menu creation failed with%s",GetErrorMessage(r));
941
942         if(onlyPasteOption == false)
943         {
944                 r = __pImageMenu->AddItem(CommonUtil::GetString(L"IDS_COM_OPT_COPY"),IDA_COPY_TEXT_CLICKED);
945         }
946         if ((pasteOption || onlyPasteOption) && clipboardAvailable == true)
947         {
948                 r = __pImageMenu->AddItem(CommonUtil::GetString(L"IDS_COM_BODY_PASTE"),IDA_PASTE_TEXT_CLICKED);
949         }
950         if(onlyPasteOption == false)
951         {
952                 r = __pImageMenu->AddItem(CommonUtil::GetString(L"IDS_BR_OPT_FIND_ON_PAGE_ABB"),IDA_FIND_TEXT__CLICKED);
953                 r = __pImageMenu->AddItem(CommonUtil::GetString(L"IDS_BR_OPT_SHARE"),IDA_SHARE_TEXT_CLICKED);
954         }
955
956         __pImageMenu->SetMaxVisibleItemsCount(3);
957         __pImageMenu->AddActionEventListener(*this);
958         SetControlAlwaysOnTop(*__pImageMenu, true);
959         __pImageMenu->SetFocusable(true);
960
961         CATCH: return r;
962
963 }
964
965 result
966 MainForm::InitSelectTextContextMenuF(FloatPoint p, bool pasteOption, bool onlyPasteOption = false)
967 {
968         result r = E_SUCCESS;
969         bool clipboardAvailable = true;
970         ContextMenuAnchorDirection direction = CONTEXT_MENU_ANCHOR_DIRECTION_AUTO;
971
972         AppLog("MainForm::InitSelectTextContextMenu clicked on text");
973         if (__pImageMenu != null)
974         {
975                 delete __pImageMenu;
976                 __pImageMenu = null;
977         }
978
979         if(p.y < 150)
980         {
981                 p.y = p.y + 50;
982                 direction = CONTEXT_MENU_ANCHOR_DIRECTION_DOWNWARD;
983         }
984         else
985         {
986                 if(GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE )
987                 {
988                         AppLog("asdasdafdsfdgfd");
989                         p.y = p.y - 50;
990                 }
991                 direction = CONTEXT_MENU_ANCHOR_DIRECTION_UPWARD;
992         }
993
994
995         Clipboard* pClipboard = Clipboard::GetInstance();
996
997         if(pClipboard == null)
998         {
999                 clipboardAvailable = false;
1000         }
1001         else
1002         {
1003                 // Retrieves a latest item
1004                 ClipboardItem* pItem = pClipboard->RetrieveLatestItemN(CLIPBOARD_DATA_TYPE_TEXT | CLIPBOARD_DATA_TYPE_HTML);
1005
1006                 if(pItem == null)
1007                 {
1008                         clipboardAvailable = false;
1009                 }
1010                 else
1011                 {
1012                         //Gets data from the clipboard item
1013                         String* pString = dynamic_cast<String*>(pItem->GetData());
1014
1015                         if(pString == null)
1016                         {
1017                                 clipboardAvailable = false;
1018                         }
1019                 }
1020         }
1021         if(clipboardAvailable == false && onlyPasteOption == true)
1022         {
1023                 return E_FAILURE;
1024         }
1025         __pImageMenu = new (std::nothrow) ContextMenu();
1026         r = __pImageMenu->Construct(p, CONTEXT_MENU_STYLE_GRID, direction);
1027         TryCatch(!IsFailed(r),, "Context image menu creation failed with%s",GetErrorMessage(r));
1028
1029
1030
1031
1032
1033         if(onlyPasteOption == false)
1034         {
1035                 r = __pImageMenu->AddItem(CommonUtil::GetString(L"IDS_COM_OPT_COPY"),IDA_COPY_TEXT_CLICKED);
1036         }
1037         if ((pasteOption || onlyPasteOption) && clipboardAvailable == true)
1038         {
1039                 r = __pImageMenu->AddItem(CommonUtil::GetString(L"IDS_COM_BODY_PASTE"),IDA_PASTE_TEXT_CLICKED);
1040         }
1041         if(onlyPasteOption == false)
1042         {
1043                 r = __pImageMenu->AddItem(CommonUtil::GetString(L"IDS_BR_OPT_FIND_ON_PAGE_ABB"),IDA_FIND_TEXT__CLICKED);
1044                 r = __pImageMenu->AddItem(CommonUtil::GetString(L"IDS_BR_OPT_SHARE"),IDA_SHARE_TEXT_CLICKED);
1045         }
1046
1047         __pImageMenu->SetMaxVisibleItemsCount(3);
1048         __pImageMenu->AddActionEventListener(*this);
1049         SetControlAlwaysOnTop(*__pImageMenu, true);
1050         __pImageMenu->SetFocusable(true);
1051
1052         CATCH: return r;
1053
1054 }
1055
1056 result
1057 MainForm::InitFindWordPanel(void)
1058 {
1059         result r = E_SUCCESS;
1060         Bitmap *pIconBitmap = null;
1061
1062         if (__pFindWordControl != null)
1063         {
1064                 AppLogDebug("Findword panel already initialized");
1065                 if (__pFindWordBgLabel != null)
1066                 {
1067                         Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_FINDWORD_INPUT_FIELD_BG, __pFindWordBgLabel->GetWidth(), __pFindWordBgLabel->GetHeight());
1068                         if (pBitmap != null)
1069                         {
1070                                 __pFindWordBgLabel->SetBackgroundBitmap(*pBitmap);
1071                                 delete pBitmap;
1072                         }
1073                 }
1074                 if (__pFindWordBgLabelRightToLeft != null)
1075                 {
1076                         Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_FINDWORD_INPUT_FIELD_BG, __pFindWordBgLabelRightToLeft->GetWidth(), __pFindWordBgLabelRightToLeft->GetHeight());
1077                         if (pBitmap != null)
1078                         {
1079                                 __pFindWordBgLabelRightToLeft->SetBackgroundBitmap(*pBitmap);
1080                                 delete pBitmap;
1081                         }
1082                 }
1083                 if(__pAddressbar)
1084                         __pAddressbar->SetShowState(false);
1085
1086                 if(__isKeypadOpened == false)
1087                         __pFooterPanel->SetShowState(true);
1088                 return r;
1089         }
1090
1091         __pFindWordControl = new (std::nothrow) Panel();
1092         r = __pFindWordControl->Construct(L"IDL_FIND_ON_PAGE");
1093         if (IsFailed(r))
1094         {
1095                 AppLogException("There is some problem in the xml file. Please check.");
1096                 return E_FAILURE;
1097         }
1098         AddControl(__pFindWordControl);
1099         __pFindWordControl->SetBounds(0,0, __pFindWordControl->GetWidth(), __pFindWordControl->GetHeight());
1100         SetControlAlwaysOnTop(*__pFindWordControl,true);
1101         __pFindWordControl->SetShowState(false);
1102         __pFindWordControl->Invalidate(false);
1103
1104         __pFindWordPanelLeftToRight = static_cast<Panel*>(__pFindWordControl->GetControl(L"IDC_PANEL1", true));
1105         __pFindWordPanelLeftToRight->SetShowState(true);
1106
1107         __pFindWordPanelRightToLeft = static_cast<Panel*>(__pFindWordControl->GetControl(L"IDC_PANEL2", true));
1108         __pFindWordPanelRightToLeft->SetShowState(false);
1109
1110         __pFindWordBgLabel = static_cast<Label*>(__pFindWordControl->GetControl(L"IDC_LABEL1", true));
1111         if (__pFindWordBgLabel != null)
1112         {
1113                 Panel* pPanel1 = static_cast<Panel*>(__pFindWordControl->GetControl(L"IDC_PANEL1", true));
1114                 Rectangle pRect = pPanel1->GetBounds();
1115                 pRect.x = pRect.y = 0;
1116                 __pFindWordBgLabel->SetBounds(pRect);
1117                 Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(L"I01_search_input_field_bg.9.png", __pFindWordBgLabel->GetWidth(), __pFindWordBgLabel->GetHeight());
1118                 if (pBitmap != null)
1119                 {
1120                         AppLogDebug("InitFindWordPanel: Coming here");
1121                         __pFindWordBgLabel->SetBackgroundBitmap(*pBitmap);
1122                         delete pBitmap;
1123                 }
1124                 else
1125                 {
1126                         AppLogDebug("InitFindWordPanel: shouldn't Come here");
1127                 }
1128         }
1129
1130         __pFindWordBgLabelRightToLeft = static_cast<Label*>(__pFindWordControl->GetControl(L"IDC_LABEL2", true));
1131                 if (__pFindWordBgLabelRightToLeft != null)
1132                 {
1133                         Panel* pPanel1 = static_cast<Panel*>(__pFindWordControl->GetControl(L"IDC_PANEL1", true));
1134                         Rectangle pRect = pPanel1->GetBounds();
1135                         pRect.x = pRect.y = 0;
1136                         __pFindWordBgLabelRightToLeft->SetBounds(pRect);
1137                         Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(L"I01_search_input_field_bg.9.png", __pFindWordBgLabel->GetWidth(), __pFindWordBgLabel->GetHeight());
1138                         if (pBitmap != null)
1139                         {
1140                                 AppLogDebug("InitFindWordPanel: Coming here");
1141                                 __pFindWordBgLabelRightToLeft->SetBackgroundBitmap(*pBitmap);
1142                                 delete pBitmap;
1143                         }
1144                         else
1145                         {
1146                                 AppLogDebug("InitFindWordPanel: shouldn't Come here");
1147                         }
1148                 }
1149
1150         Button* pfindWordCancel = null;
1151         pfindWordCancel = static_cast<Button*>(__pFindWordControl->GetControl(L"IDC_FIND_CANCEL", true));
1152         if (pfindWordCancel == null)
1153         {
1154                 AppLogException("There is some problem in the xml file. Please check.");
1155                 return E_FAILURE;
1156         }
1157         pfindWordCancel->SetActionId(IDA_FINDWORD_CANCEL_CLICKED);
1158         pfindWordCancel->AddActionEventListener(*this);
1159
1160         __pFindWordClear = static_cast<Button*>(__pFindWordControl->GetControl(L"IDC_FIND_CLEAR", true));
1161         if (__pFindWordClear == null)
1162         {
1163                 AppLogException("There is some problem in the xml file. Please check.");
1164                 return E_FAILURE;
1165         }
1166
1167         __pFindWordClearRightToLeft = static_cast<Button*>(__pFindWordControl->GetControl(L"IDC_FIND_CLEAR2", true));
1168                 if (__pFindWordClearRightToLeft == null)
1169                 {
1170                         AppLogException("There is some problem in the xml file. Please check.");
1171                         return E_FAILURE;
1172                 }
1173
1174         __pFindWordClear->SetActionId(IDA_FINDWORD_CLEAR_CLICKED);
1175         __pFindWordClear->AddActionEventListener(*this);
1176
1177         __pFindWordClearRightToLeft->SetActionId(IDA_FINDWORD_CLEAR_RIGHT_TO_LEFT_CLICKED);
1178         __pFindWordClearRightToLeft->AddActionEventListener(*this);
1179
1180         __pFindWordNext = static_cast<Button*>(__pFindWordControl->GetControl(L"IDC_FIND_NEXT", true));
1181         if (__pFindWordNext == null)
1182         {
1183                 AppLogException("There is some problem in the xml file. Please check.");
1184                 return E_FAILURE;
1185         }
1186
1187         __pFindWordNext->SetActionId(IDA_FINDWORD_NEXT_CLICKED);
1188         __pFindWordNext->AddActionEventListener(*this);
1189
1190         __pFindWordPrev = static_cast<Button*>(__pFindWordControl->GetControl(L"IDC_FIND_PREV", true));
1191         if (__pFindWordPrev == null)
1192         {
1193                 AppLogException("There is some problem in the xml file. Please check.");
1194                 return E_FAILURE;
1195         }
1196
1197         __pFindWordPrev->SetActionId(IDA_FINDWORD_PREV_CLICKED);
1198         __pFindWordPrev->AddActionEventListener(*this);
1199
1200         __pFindWordNext->SetEnabled(false);
1201         __pFindWordPrev->SetEnabled(false);
1202
1203         __pFindWordCountLabel = static_cast<Label*>(__pFindWordControl->GetControl(L"IDC_FIND_COUNT_LABEL", true));
1204         if (__pFindWordCountLabel == null)
1205         {
1206                 AppLogException("There is some problem in the xml file. Please check.");
1207                 return E_FAILURE;
1208         }
1209
1210         __pFindWordCountLabelRightToLeft = static_cast<Label*>(__pFindWordControl->GetControl(L"IDC_FIND_COUNT_LABEL2", true));
1211         if (__pFindWordCountLabelRightToLeft == null)
1212         {
1213                 AppLogException("There is some problem in the xml file. Please check.");
1214                 return E_FAILURE;
1215         }
1216
1217         __pFindWordEditField = static_cast<EditField*>(__pFindWordControl->GetControl(L"IDC_FIND_WORD_EDITFIELD", true));
1218         if (__pFindWordEditField == null)
1219         {
1220                 AppLogException("There is some problem in the xml file. Please check.");
1221                 return E_FAILURE;
1222         }
1223         __pFindWordEditField->AddTextEventListener(*this);
1224         __pFindWordEditField->AddKeypadEventListener(*this);
1225         __pFindWordEditField->SetOverlayKeypadCommandButtonVisible(false);
1226         __pFindWordEditField->SetColor(EDIT_STATUS_HIGHLIGHTED, Color(0x00, 0x00, 0x00, 0x00));
1227
1228         __pFindWordEditFieldRightToLeft = static_cast<EditField*>(__pFindWordControl->GetControl(L"IDC_FIND_WORD_EDITFIELD2", true));
1229         if (__pFindWordEditFieldRightToLeft == null)
1230         {
1231                 AppLogException("There is some problem in the xml file. Please check.");
1232                 return E_FAILURE;
1233         }
1234         __pFindWordEditFieldRightToLeft->AddTextEventListener(*this);
1235         __pFindWordEditFieldRightToLeft->AddKeypadEventListener(*this);
1236         __pFindWordEditFieldRightToLeft->SetOverlayKeypadCommandButtonVisible(false);
1237         __pFindWordEditFieldRightToLeft->SetColor(EDIT_STATUS_HIGHLIGHTED, Color(0x00, 0x00, 0x00, 0x00));
1238
1239         if(__pAddressbar)
1240                 __pAddressbar->SetShowState(false);
1241
1242         if(__isKeypadOpened == false)
1243                 __pFooterPanel->SetShowState(true);
1244         return r;
1245 }
1246
1247 ListItemBase*
1248 MainForm::CreateItem (int index, int itemWidth)
1249 {
1250         Rectangle listImageRect;
1251         Rectangle pagetTitleRect;
1252         Rectangle pageURLRect;
1253         Rectangle deleteImageRect;
1254         String pageTitle(L"");
1255         String pageURL(L"");
1256         result r = E_SUCCESS;
1257         Bitmap* pListIconImage = null;
1258
1259
1260         History* pHistory = static_cast < History* >(__pMostVisitedSites->GetAt(index));
1261         if(pHistory == null)
1262         {
1263                 return null;
1264         }
1265         AppResource* pAppResource = Application::GetInstance()->GetAppResource();
1266         if ( pAppResource == NULL )
1267         {
1268                 return null;
1269         }
1270         ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
1271
1272         CustomItem* pItem = new(std::nothrow) CustomItem();
1273         pageTitle = pHistory->GetHistoryTitle();
1274         pageURL = pHistory->GetHistoryUrl();
1275
1276         if (pageURL.GetLength() == 0)
1277         {
1278                 String nourl;
1279                 pAppResource->GetString(L"IDS_BR_BODY_BLANK_PAGE", nourl);
1280                 pageURL = L"<"+ nourl +">";
1281
1282         }
1283
1284         Rectangle screenBounds = GetBounds();
1285         if (pItem != null)
1286         {
1287                 r = pItem->Construct(Dimension(itemWidth, 128 + (__fontSize - 44)), style);
1288         }
1289         if (IsFailed(r))
1290         {
1291                 delete pItem;
1292                 return NULL;
1293         }
1294
1295
1296         Bitmap* pBitmap = pHistory->GetFavIconBitmap();
1297
1298         if ( pBitmap != NULL)
1299         {
1300                 pListIconImage = new Bitmap();
1301                 pListIconImage->Construct(*pBitmap,Rectangle(0,0,pBitmap->GetWidth(),pBitmap->GetHeight()));
1302                 delete pBitmap;
1303         }
1304
1305         if(pListIconImage == null)
1306         {
1307                 pListIconImage = pAppResource->GetBitmapN(L"I01_icon_default_favicon.png");
1308         }
1309
1310         if ( pListIconImage != NULL)
1311         {
1312                 listImageRect.SetBounds(screenBounds.x + 16, screenBounds.y + 28  + (__fontSize - 44)/2 , 72, 72);
1313                 pagetTitleRect.SetBounds(listImageRect.x + 72 + 16,10, screenBounds.width - 2 * pListIconImage->GetWidth() - 120, 72  + (__fontSize - 44));
1314                 pageURLRect.SetBounds(pagetTitleRect.x, pagetTitleRect.y + pagetTitleRect.height, screenBounds.width - 2 * pListIconImage->GetWidth() - 120, 48);
1315
1316
1317                 if (pItem != null && pListIconImage != NULL)
1318                 {
1319                         pItem->AddElement(listImageRect, IDA_FORMAT_BITMAP, *pListIconImage, null, null);
1320                 }
1321         }
1322
1323         if (pageTitle.CompareTo(L"") != 0)
1324         {
1325                 if (pItem != null)
1326                 {
1327                         pItem->AddElement(pagetTitleRect, IDA_FORMAT_TITLE_STRING, pageTitle, __fontSize, CUSTOM_COLOR_TRANSPARENT, CUSTOM_COLOR_TRANSPARENT, CUSTOM_COLOR_TRANSPARENT, true);
1328                 }
1329         }
1330
1331         if (pageURL.CompareTo(L"") != 0)
1332         {
1333                 if (pItem != null)
1334                 {
1335                         pItem->AddElement(pageURLRect, IDA_FORMAT_URL_STRING, pageURL, 32, CUSTOM_COLOR_GREY, CUSTOM_COLOR_GREY, CUSTOM_COLOR_GREY, true);
1336                 }
1337         }
1338
1339
1340         if(GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT || GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT_REVERSE)
1341         {
1342                 if ( __pItemContext!= NULL)
1343                 {
1344                         if (pItem != null)
1345                         {
1346                                 pItem->SetContextItem(__pItemContext);
1347                         }
1348                 }
1349         }
1350         else
1351         {
1352                 if ( __pItemContextLandscape!= NULL)
1353                 {
1354                         if (pItem != null)
1355                         {
1356                                 pItem->SetContextItem(__pItemContextLandscape);
1357                         }
1358                 }
1359         }
1360         if( pListIconImage != NULL)
1361         {
1362                 delete pListIconImage;
1363                 pListIconImage = null;
1364         }
1365
1366         return pItem;
1367 }
1368
1369 bool
1370 MainForm::DeleteItem (int index, Tizen::Ui::Controls::ListItemBase *pItem, int itemWidth)
1371 {
1372         delete pItem;
1373         return true;
1374 }
1375
1376 int
1377 MainForm::GetItemCount (void)
1378 {
1379         if(__pMostVisitedSites != null)
1380         {
1381                 __pMostVisitedSites->RemoveAll(true);
1382         }
1383         HistoryPresentationModel::GetInstance()->GetMostVisitedSites(*__pMostVisitedSites);
1384         if(__pMostVisitedSites != null)
1385         {
1386                 return __pMostVisitedSites->GetCount();
1387         }
1388         else
1389                 return 0;
1390 }
1391
1392 void
1393 MainForm::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state)
1394 {
1395         AppLog("MainForm::OnListViewContextItemStateChanged called");
1396         if(__pMostVisitedSites != null)
1397         {
1398                 History* pHistory = static_cast < History* >(__pMostVisitedSites->GetAt(index));
1399                 if (pHistory != null)
1400                 {
1401                         String url = pHistory->GetHistoryUrl();
1402
1403                         HistoryPresentationModel::GetInstance()->DeleteHistory(url);
1404                         __pMostVisitedListView->UpdateList();
1405                 }
1406         }
1407 }
1408
1409 void
1410 MainForm::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
1411 {
1412         History* pHistory = static_cast < History* >(__pMostVisitedSites->GetAt(index));
1413         String url = pHistory->GetHistoryUrl();
1414         if (url != null)
1415         {
1416                 LoadUrl(url);
1417         }
1418 }
1419
1420 void
1421 MainForm::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction)
1422 {
1423
1424 }
1425
1426 result
1427 MainForm::OnTerminating(void)
1428 {
1429         result r = E_SUCCESS;
1430
1431         RemoveOrientationEventListener(*this);
1432
1433         if(__pAddressbar)
1434         {
1435                 __pAddressbar->SetAddressbarEventListener(null);
1436         }
1437
1438         if(__pWebViewer)
1439         {
1440                 __pWebViewer->RemoveTouchEventListener(*this);
1441                 __pWebViewer->SetWebUiEventListenerF(null);
1442                 __pWebViewer->SetWebKeypadEventListener(null);
1443                 __pWebViewer->SetTextSearchListener(null);
1444         }
1445
1446
1447         if (__pItemContext)
1448         {
1449                 delete __pItemContext;
1450         }
1451         if (__pItemContextLandscape)
1452         {
1453                 delete __pItemContextLandscape;
1454         }
1455         if (__pSaveImage)
1456         {
1457                 delete __pSaveImage;
1458         }
1459         if (__pMostVisitedSites)
1460         {
1461                 __pMostVisitedSites->RemoveAll(true);
1462                 delete __pMostVisitedSites;
1463         }
1464         return r;
1465 }
1466
1467 void
1468 MainForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
1469 {
1470         result r = E_SUCCESS;
1471
1472         AppLogDebug("Clicked : %d", actionId);
1473         switch (actionId)
1474         {
1475         case IDA_BACKBTN_CLICKED:
1476         {
1477                 if(__pImageMenu && __pImageMenu->GetShowState() == true)
1478                 {
1479                         AppLog("Hiding the menu");
1480                         __pImageMenu->SetShowState(false);
1481                 }
1482                 if (__pWebViewer && __pWebViewer->CanGoBack())
1483                 {
1484                         __pWebViewer->GoBack();
1485                 }
1486                 else if(__pWindowInfo->isJavascriptInitiated == false)
1487                 {
1488                         UiApp* pApp = null;
1489                         pApp = UiApp::GetInstance();
1490                         if (pApp != null)
1491                         {
1492                                 r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
1493                                 if (IsFailed(r))
1494                                 {
1495                                         AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
1496                                         return;
1497                                 }
1498                         }
1499                 }
1500                 else
1501                 {
1502                         UiApp* pApp = null;
1503                         WindowInfo* pWindowInfo = null;
1504                         int totalCount = 0;
1505                         SceneManager* pSceneManager = SceneManager::GetInstance();
1506                         if (pSceneManager == null)
1507                         {
1508                                 return;
1509                         }
1510                         ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
1511                         if (pAllWindowList == NULL)
1512                         {
1513                                 pApp = UiApp::GetInstance();
1514                                 if (pApp != null)
1515                                 {
1516                                         r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
1517                                         if (IsFailed(r))
1518                                         {
1519                                                 AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
1520                                                 return;
1521                                         }
1522                                 }
1523                         }
1524                         if (pAllWindowList != null)
1525                         {
1526                                 totalCount = pAllWindowList->GetCount();
1527                         }
1528                         for (int count = 0; count < totalCount; count++)
1529                         {
1530                                 pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count));
1531                                 if (pWindowInfo == null)
1532                                 {
1533                                         pApp = UiApp::GetInstance();
1534                                         if (pApp != null)
1535                                         {
1536                                                 r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
1537                                                 if (IsFailed(r))
1538                                                 {
1539                                                         AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
1540                                                         return;
1541                                                 }
1542                                         }
1543                                 }
1544                                 else
1545                                 {
1546                                         if (pSceneManager->GetCurrentSceneId() == pWindowInfo->sceneID && pWindowInfo->isJavascriptInitiated == true)
1547                                         {
1548                                                 r = SceneRegister::DestroyAndUnRegisterScene(pWindowInfo->sceneID);
1549                                                 if (IsFailed(r))
1550                                                 {
1551                                                         AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
1552                                                         return;
1553                                                 }
1554                                                 r = pAllWindowList->RemoveAt(count, true);
1555                                                 __pWindowInfo = null;
1556                                                 if (IsFailed(r))
1557                                                 {
1558                                                         AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
1559                                                         return;
1560                                                 }
1561                                                 if(count > 0)
1562                                                 {
1563                                                         pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count - 1));
1564                                                 }
1565                                                 else
1566                                                 {
1567                                                         pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(pAllWindowList->GetCount() - 1));
1568                                                 }
1569                                                 if (pWindowInfo == null)
1570                                                 {
1571                                                         pApp = UiApp::GetInstance();
1572                                                         if (pApp != null)
1573                                                         {
1574                                                                 r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
1575                                                                 return;
1576                                                         }
1577                                                 }
1578                                                 else
1579                                                 {
1580                                                         r = pSceneManager->GoBackward(BackwardSceneTransition(pWindowInfo->sceneID ,SCENE_TRANSITION_ANIMATION_TYPE_NONE));
1581                                                         if (IsFailed(r))
1582                                                         {
1583                                                                 AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
1584                                                                 return;
1585                                                         }
1586                                                 }
1587                                                 break;
1588                                         }
1589                                 }
1590                         }
1591                 }
1592         }
1593                 break;
1594
1595         case IDA_FORWARD_CLICKED:
1596                 if (__pWebViewer == null)
1597                         return;
1598
1599                 if (__pWebViewer->CanGoForward())
1600                 {
1601                         __pWebViewer->GoForward();
1602                 }
1603                 __pOptionMenu->SetShowState(false);
1604                 __pOptionMenu->Invalidate(false);
1605                 break;
1606
1607         case IDA_FINDONPAGE_CLICKED:
1608         {
1609                 AppLogDebug("MainForm::OnActionPerformed findword clicked");
1610                 __currentSearchStr.Clear();
1611
1612                 InitFindWordPanel();
1613                 __pOptionMenu->SetShowState(false);
1614                 __pOptionMenu->Invalidate(false);
1615
1616                 ShowFindWordPanel(true);
1617
1618                 if(__pFindWordPanelLeftToRight && __pFindWordPanelLeftToRight->GetShowState() == true)
1619                 {
1620                         __pFindWordEditField->SetFocus();
1621 //                      __pFindWordCountLabel->SetShowState(false);
1622                 }
1623                 else
1624                 {
1625                         __pFindWordEditFieldRightToLeft->SetFocus();
1626                         __pFindWordCountLabelRightToLeft->SetShowState(false);
1627                 }
1628         }
1629         break;
1630         case IDA_PRIVATEON_CLICKED:
1631         {
1632                 result r = E_SUCCESS;
1633                 int itemIndex = 0;
1634                 bool isPrivateBrowsing = SettingPresentationModel::GetInstance()->GetPrivateOn();
1635                 Bitmap* pBitmap = null;
1636                 if (isPrivateBrowsing == true)
1637                 {
1638                         pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_BUTTON_OFF);
1639                         if (IsFailed(r))
1640                         {
1641                                 AppLogException("Contextmenu additem:Find on page failed with %s", GetErrorMessage(r));
1642                                 return ;
1643                         }
1644
1645                         if (__pWebViewer != NULL)
1646                         {
1647                                 __pWebViewer->SetPrivateBrowsingEnabled(false);
1648                         }
1649
1650                         SettingPresentationModel::GetInstance()->SetPrivateOn(false);
1651
1652                         if (__pAddressbar != null)
1653                         {
1654                                 __pAddressbar->UpdateFaviconBitmap(false);
1655                         }
1656
1657                 }
1658                 else
1659                 {
1660                         pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_BUTTON_ON);
1661                         if (IsFailed(r))
1662                         {
1663                                 AppLogException("Contextmenu additem:Find on page failed with %s", GetErrorMessage(r));
1664                                 return ;
1665                         }
1666
1667                         if (__pWebViewer != NULL)
1668                         {
1669                                 __pWebViewer->SetPrivateBrowsingEnabled(true);
1670                         }
1671
1672                         SettingPresentationModel::GetInstance()->SetPrivateOn(true);
1673
1674                         if (__pAddressbar != null)
1675                         {
1676                                 __pAddressbar->UpdateFaviconBitmap(true);
1677                         }
1678                 }
1679
1680                 itemIndex = __pOptionMenu->GetItemIndexFromActionId(IDA_PRIVATEON_CLICKED);
1681                 r = __pOptionMenu->SetItemAt(itemIndex,CommonUtil::GetString(L"IDS_BR_BODY_PRIVACY_AND_SECURITY_ABB"),IDA_PRIVATEON_CLICKED,*pBitmap);
1682                 AppLog("Result:: %s for index = %d", GetErrorMessage(r),itemIndex);
1683                 __pOptionMenu->Invalidate(true);
1684                 if ( pBitmap != NULL )
1685                 {
1686                         delete pBitmap;
1687                 }
1688
1689         }
1690         break;
1691         case IDA_SETTINGS_CLICKED:
1692         {
1693
1694                 ArrayList* pArgList = new(std::nothrow) ArrayList();
1695                 if (pArgList)
1696                 {
1697                         pArgList->Construct();
1698                         pArgList->Add(*__pWindowInfo);
1699                         SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_SETTINGS), pArgList);
1700                 }
1701                 __pOptionMenu->SetShowState(false);
1702                 __pOptionMenu->Invalidate(false);
1703
1704                 if (pArgList != null)
1705                 {
1706                         delete pArgList;
1707                         pArgList = null;
1708                 }
1709
1710         }
1711         break;
1712
1713         case IDA_ADDTOBOOKMARK_CLICKED:
1714         {
1715
1716                 if (__pWindowInfo != NULL && __pWindowInfo->pageUrl != NULL)
1717                 {
1718                         int bookmarkCount=0;
1719                         bool exist = false;
1720                         String url=L"";
1721                         url=__pWindowInfo->pageUrl;
1722                         result r = E_SUCCESS;
1723                         Bitmap* pBitmap = null;
1724                         r=BookmarkPresentationModel::GetInstance()->DoesBookmarkExist(url,exist);
1725
1726                         if (IsFailed(r))
1727                         {
1728                                 return;
1729                         }
1730                         if ( exist == true)
1731                         {
1732                                 String message = CommonUtil::GetString(L"IDS_BR_POP_BOOKMARK_REMOVED");
1733                                 BookmarkPresentationModel::GetInstance()->DeleteBookmark(url);
1734                                 pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ICON_BOOKMARK_OFF_TEMP);
1735
1736                                 if(__pNotification != null)
1737                                 {
1738                                         RemoveControl(__pNotification);
1739                                         __pNotification = null;
1740                                 }
1741                                 __pNotification = new (std::nothrow) NotificationPanel(*this);
1742                                 if (__pNotification != null)
1743                                 {
1744                                         __pNotification->SetText(message);
1745                                         __pNotification->SetPositionDiff(__pFooterPanel->GetHeight() - 12);
1746                                         __pNotification->ShowNotification();
1747                                 }
1748                         }
1749                         else
1750                         {
1751                                 String title=__pWindowInfo->pageTitle;
1752                                 String message = CommonUtil::GetString(L"IDS_BR_POP_BOOKMARK_ADDED");
1753                                 BookmarkData* pBookmark=new (std::nothrow) BookmarkData();
1754
1755                                 pBookmark->SetBookmarkTitle(title);
1756                                 pBookmark->SetUrl(url);
1757                                 if (__pWebViewer != null && __pWebViewer->GetFaviconN() != null)
1758                                 {
1759                                         pBookmark->SetFavIconBitmap(*(__pWebViewer->GetFaviconN()));
1760                                 }
1761                                 String id = FaviconManager::GetInstance()->SaveFavicon(*__pWindowInfo->pFavicon, __pWindowInfo->faviconUrl);
1762                                 pBookmark->SetFaviconId(id);
1763                                 //r = BookmarkPresentationModel::GetInstance()->SaveBookmark(*pBookmark);
1764                                 r = BookmarkPresentationModel::GetInstance()->SaveTempBookmark(*pBookmark);
1765                                 delete pBookmark;
1766                                 if(__pNotification != null)
1767                                 {
1768                                         RemoveControl(__pNotification);
1769                                         __pNotification = null;
1770                                 }
1771                                 __pNotification = new (std::nothrow) NotificationPanel(*this);
1772                                 if (__pNotification != null)
1773                                 {
1774                                         __pNotification->SetText(message);
1775                                         __pNotification->SetPositionDiff(__pFooterPanel->GetHeight() - 12);
1776                                         __pNotification->ShowNotification();
1777                                         pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ICON_BOOKMARK_ON_TEMP);
1778                                 }
1779                         }
1780                         if (pBitmap != null)
1781                         {
1782                                 r = __pOptionMenu->SetItemAt(1,CommonUtil::GetString(L"IDS_BR_OPT_ADDTOBOOKMARKS"), IDA_ADDTOBOOKMARK_CLICKED,*pBitmap);
1783                                 delete pBitmap;
1784                         }
1785
1786
1787                         __pOptionMenu->Invalidate(true);
1788                 }
1789
1790         }
1791         break;
1792         case IDA_PRINT_CLICKED:
1793         {
1794                 r = __pWebViewer->SavePageAsPdf(UiApp::GetInstance()->GetAppRootPath()+"//shared//data//test.pdf");
1795                 AppLog("SavePageAsPdf result %s",GetErrorMessage(r));
1796
1797                 AppLog("RequestPrint called!");
1798                 AppControl* pAc = Tizen::App::AppManager::FindAppControlN(L"org.tizen.mobileprint", L"http://tizen.org/appcontrol/operation/print");
1799                 result nResult = E_FAILURE;
1800                 if (pAc)
1801                 {
1802                         AppLog("TestPrint if (pAc) == true");
1803
1804                         HashMap map;
1805                         map.Construct();
1806
1807                         String fileType = L"service_print_files_type";
1808                         String typeVal = L"DOC";
1809
1810                         String fileCount = L"service_print_files_count";
1811                         String countVal = L"1";
1812                         String fileFolder= L"service_print_files_folder_name";
1813                         String folderVal = UiApp::GetInstance()->GetAppRootPath()+"//shared//data";
1814
1815                         map.Add(&fileCount, &countVal);
1816                         map.Add(&fileFolder, &folderVal);
1817                         map.Add(&fileType, &typeVal);
1818
1819                         String fileName = L"service_print_files_files_name";
1820
1821                         ArrayList fileNameList;
1822                         fileNameList.Construct();
1823                         String file1 = L"test.pdf";
1824
1825                         fileNameList.Add(&file1);
1826                         map.Add(&fileName, &fileNameList);
1827
1828                         nResult = pAc->Start(NULL, NULL, &map, NULL);
1829
1830                         if (nResult == E_SUCCESS) AppLog("TestPrint ret == E_SUCCESS");
1831                         else if (nResult == E_MAX_EXCEEDED)
1832                                 AppLog("TestPrint ret == E_MAX_EXCEEDED");
1833                         else if (nResult == E_OBJ_NOT_FOUND)
1834                                 AppLog("TestPrint ret == E_OBJ_NOT_FOUND");
1835                         else if (nResult == E_IN_PROGRESS)
1836                                 AppLog("TestPrint ret == E_IN_PROGRESS");
1837                         else if (nResult == E_PRIVILEGE_DENIED)
1838                                 AppLog("TestPrint ret == E_PRIVILEGE_DENIED");
1839                         else if(nResult == E_SYSTEM)
1840                                 AppLog("TestPrint ret == E_SYSTEM");
1841
1842                         delete pAc;
1843                 }
1844                 else
1845                 {
1846                         int __modalMsgBoxResult;
1847                         MessageBox* pMsgBox = new MessageBox();
1848                         pMsgBox->Construct("Not Supported","Not Supported",MSGBOX_STYLE_OK,3000);
1849                         pMsgBox->ShowAndWait(__modalMsgBoxResult);
1850                         delete pMsgBox;
1851                         pMsgBox = null;
1852                         __modalMsgBoxResult = 0;
1853                 }
1854         }
1855         break;
1856         case IDA_SHARE_CLICKED:
1857         {
1858                 if(__pPopUp != null)
1859                 {
1860                         delete __pPopUp;
1861                         __pPopUp = null;
1862                 }
1863                 if(__pAddressbar)
1864                 {
1865                         __pAddressbar->HideKeypad();
1866                 }
1867                 __pPopUp = new(std::nothrow) SharePopup();
1868                 __pPopUp->Initialize();
1869                 if (__pWindowInfo != null)
1870                 {
1871                         ShareInfo* pShareInfo = new(std::nothrow) ShareInfo();
1872                         pShareInfo->SetPageTitle(__pWindowInfo->pageTitle);
1873                         pShareInfo->SetPageUrl(__pWindowInfo->pageUrl);
1874                         pShareInfo->SetImageAttached(false);
1875                         __pPopUp->RemoveAllShareInfo();
1876                         __pPopUp->AddShareInfo(pShareInfo);
1877                 }
1878                 __pPopUp->SetShowState(true);
1879                 __pPopUp->Show();
1880         }
1881         break;
1882         case IDA_BOOKMARKBTN_CLICKED:
1883         {
1884                 AppLogDebug("ONACTION_PERFORMED:IDA_BOOKMARKBTN_CLICKED");
1885                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_BOOKMARK_VIEW, SCENE_TRANSITION_ANIMATION_TYPE_NONE));
1886         }
1887         break;
1888         case IDA_ADD_TO_BOOKMARKBTN_CLICKED:
1889         {
1890
1891         }
1892         break;
1893         case IDA_MOREBTN_CLICKED:
1894         {
1895                 AppLog("IDA_MOREBTN_CLICKED");
1896                 InitOptionMenu();
1897                 if (__pWindowInfo != NULL && __pWindowInfo->pageUrl != NULL && __pWebViewer->GetShowState() == true)
1898                 {
1899                         int bookmarkCount=0;
1900                         bool exist = false;
1901                         String url=L"";
1902                         url=__pWindowInfo->pageUrl;
1903                         result r = E_SUCCESS;
1904                         Bitmap* pBitmap = null;
1905
1906                         r=BookmarkPresentationModel::GetInstance()->DoesBookmarkExist(url,exist);
1907                         if (IsFailed(r))
1908                         {
1909                                 AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED failed");
1910                                 return;
1911                         }
1912                         if ( exist == true)
1913                         {
1914                                 pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ICON_BOOKMARK_ON_TEMP);
1915                         }
1916                         else
1917                         {
1918                                 pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ICON_BOOKMARK_OFF_TEMP);
1919                         }
1920                         AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED 3");
1921
1922                         if (__pOptionMenu->GetItemCount() == 9)
1923                         {
1924                                 r = __pOptionMenu->SetItemAt(1,CommonUtil::GetString(L"IDS_BR_OPT_ADDTOBOOKMARKS"), IDA_ADDTOBOOKMARK_CLICKED,*pBitmap);
1925                         }
1926                         else
1927                         {
1928                                 r = __pOptionMenu->InsertItemAt(1,CommonUtil::GetString(L"IDS_BR_OPT_ADDTOBOOKMARKS"), IDA_ADDTOBOOKMARK_CLICKED,*pBitmap);
1929                         }
1930
1931                         if (IsFailed(r))
1932                         {
1933                                 AppLogException("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED Add to Bookmark failed with %s", GetErrorMessage(r));
1934                                 delete pBitmap;
1935                                 return ;
1936                         }
1937                         AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED 4");
1938                         if (__pOptionMenu->GetItemCount() != 9)
1939                         {
1940                                 __pOptionMenu->InsertItemAt(1,CommonUtil::GetString(L"IDS_BR_OPT_ADDTOBOOKMARKS"), IDA_ADDTOBOOKMARK_CLICKED);
1941                                 __pOptionMenu->InsertItemAt(2,CommonUtil::GetString(L"IDS_BR_BODY_PRINT"), IDA_PRINT_CLICKED);
1942         //                              __pOptionMenu->InsertItemAt(2,L"Add to Home"/*CommonUtil::GetString(L"IDS_BR_OPT_SHARE")*/, IDA_ADD_TO_HOME_CLICKED);
1943                                 __pOptionMenu->InsertItemAt(3,CommonUtil::GetString(L"IDS_BR_OPT_SHARE"), IDA_SHARE_CLICKED);
1944                                 __pOptionMenu->InsertItemAt(4,CommonUtil::GetString(L"IDS_BR_OPT_FIND_ON_PAGE_ABB"), IDA_FINDONPAGE_CLICKED);
1945                                 __pOptionMenu->SetMaxVisibleItemsCount(6);
1946                         }
1947                         if( GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
1948                         {
1949                                 AppLog(" Orientation landscape");
1950                                 __pOptionMenu->SetMaxVisibleItemsCount(5);
1951                         }
1952                         else
1953                         {
1954                                 AppLog(" Orientation potrait");
1955                                 __pOptionMenu->SetMaxVisibleItemsCount(6);
1956                         }
1957
1958                         AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED 5");
1959                         delete pBitmap;
1960                 }
1961                 AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED end");
1962                 __pOptionMenu->SetShowState(true);
1963                 __pOptionMenu->Invalidate(true);
1964                 __pOptionMenu->Show();
1965
1966 }
1967         break;
1968         case IDA_HISTORY_CLICKED:
1969         {
1970                 AppLogDebug("ONACTION_PERFORMED:IDA_HISTORYBTN_CLICKED");
1971                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_HISTORY_LIST, SCENE_TRANSITION_ANIMATION_TYPE_NONE));
1972         }
1973         break;
1974         case IDA_SAVED_PAGES_CLICKED:
1975         {
1976
1977         }
1978         break;
1979         case IDA_DESKTOP_VIEW_CLICKED:
1980         {
1981
1982         }
1983         break;
1984         case IDA_SAVE_CLICKED:
1985         {
1986
1987         }
1988         break;
1989         case IDA_MULTIWINDOWBTN_CLICKED:
1990         {
1991                 result r = SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_MULTIPLE_WINDOW, SCENE_TRANSITION_ANIMATION_TYPE_NONE));
1992                 AppLog("IDA_MULTIWINDOWBTN_CLICKED result %s",GetErrorMessage(r));
1993         }
1994         break;
1995
1996         case IDA_NEWWINDOWBTN_CLICKED:
1997         {
1998                 WindowInfo* pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewSceneN();
1999
2000                 if (pNewWindowInfo == null)
2001                 {
2002                         return;
2003                 }
2004                 result r = E_SUCCESS;
2005                 SceneManager* pSceneManager = SceneManager::GetInstance();
2006
2007                 if (pSceneManager == NULL)
2008                 {
2009                         return;
2010                 }
2011                 ArrayList* pArgList = new(std::nothrow) ArrayList();
2012                 if (pArgList == NULL)
2013                 {
2014                         return;
2015                 }
2016                 r = pArgList->Construct();
2017                 if (r == E_SUCCESS)
2018                 {
2019                         pArgList->Add(*pNewWindowInfo);
2020                         r = pSceneManager->GoForward(ForwardSceneTransition(pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
2021                 } 
2022                 delete pArgList;
2023                 pArgList = null;
2024                 if (IsFailed(r))
2025                 {
2026                         AppLogDebug("MainForm::OnActionPerformed Failed to GoBackward %s",GetErrorMessage(r));
2027                         return;
2028                 }
2029         }
2030         break;
2031         case IDA_SMALLFONT_BTN_CLICKED:
2032         {
2033                 WebSetting setting = __pWebReader->GetSetting();
2034                 setting.SetFontSize(15);
2035                 __pWebReader->SetSetting(setting);
2036         }
2037         break;
2038         case IDA_LARGEFONT_BTN_CLICKED:
2039         {
2040                 WebSetting setting = __pWebReader->GetSetting();
2041                 setting.SetFontSize(25);
2042                 __pWebReader->SetSetting(setting);
2043         }
2044         break;
2045         case IDA_READER_CLOSE_CLICKED:
2046         {
2047                 if (__pArticleReaderPanel != null && __pBlankPanel != null)
2048                 {
2049                         RemoveControl(__pBlankPanel);
2050                         __pArticleReaderPanel = null;
2051                         __pBlankPanel = null;
2052                         __pArticleReaderLabel = null;
2053                 }
2054                 SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
2055         }
2056         break;
2057         case IDA_FINDWORD_CANCEL_CLICKED:
2058         {
2059                 __currentSearchStr = L"";
2060                 __currentWordIndex = 0;
2061                 __maxOccurrances = 0;
2062
2063                 if (__pFindWordPanelLeftToRight && __pFindWordPanelLeftToRight->GetShowState() == true)
2064                 {
2065                         __pFindWordEditField->SetText(L"");
2066                         __pFindWordCountLabel->SetText(L"0/0");
2067                 }
2068                 else if (__pFindWordPanelRightToLeft && __pFindWordPanelRightToLeft->GetShowState() == true)
2069                 {
2070                         __pFindWordEditFieldRightToLeft->SetText(L"");
2071                         __pFindWordCountLabelRightToLeft->SetText(L"0/0");
2072                 }
2073
2074                 __pFindWordNext->SetEnabled(false);
2075                 __pFindWordPrev->SetEnabled(false);
2076                 __pFindWordCountLabel->SetText(L"0/0");
2077                 __pWebViewer->SearchTextAllAsync(L"",true);
2078                 AppLog("akjshdasd 1");
2079                 if(__isKeypadOpened == false)
2080                         __pFooterPanel->SetShowState(true);
2081                 ShowFindWordPanel(false);
2082         }
2083         break;
2084         case IDA_FINDWORD_SEARCH_CLICKED:
2085         {
2086                 if (__pFindWordPanelLeftToRight && __pFindWordPanelLeftToRight->GetShowState() == true)
2087                 {
2088                         __currentSearchStr = __pFindWordEditField->GetText();
2089                 }
2090                 else if (__pFindWordPanelRightToLeft && __pFindWordPanelRightToLeft->GetShowState() == true)
2091                 {
2092                         __currentSearchStr = __pFindWordEditFieldRightToLeft->GetText();
2093                 }
2094
2095                 if (__currentSearchStr.GetLength() > 0)
2096                 {
2097                         StartWordSearch();
2098                 }
2099                 else
2100                 {
2101                         AppLogDebug("Enter something");
2102                 }
2103         }
2104         break;
2105         case IDA_FINDWORD_CLEAR_CLICKED:
2106         {
2107                 __pFindWordCountLabel->SetText(L"0/0");
2108                 __pFindWordEditField->SetText(L"");
2109                 __currentSearchStr = L"aaaaaabbbbbbccccccc";
2110                 StartWordSearch();
2111                 __currentSearchStr = L"";
2112                 __pFindWordNext->SetEnabled(false);
2113                 __pFindWordPrev->SetEnabled(false);
2114 //              __pFindWordCountLabel->SetShowState(false);
2115                 __pFindWordControl->Invalidate(true);
2116         }
2117         break;
2118         case IDA_FINDWORD_CLEAR_RIGHT_TO_LEFT_CLICKED:
2119         {
2120                 __pFindWordCountLabelRightToLeft->SetText(L"0/0");
2121                 __pFindWordEditFieldRightToLeft->SetText(L"");
2122                 __currentSearchStr = L"aaaaaabbbbbbccccccc";
2123                 StartWordSearch();
2124                 __currentSearchStr = L"";
2125                 __pFindWordNext->SetEnabled(false);
2126                 __pFindWordPrev->SetEnabled(false);
2127 //              __pFindWordCountLabelRightToLeft->SetShowState(false);
2128                 __pFindWordControl->Invalidate(true);
2129         }
2130         break;
2131         case IDA_FINDWORD_NEXT_CLICKED:
2132         {
2133                 FindNextWord(true);
2134         }
2135         break;
2136         case IDA_FINDWORD_PREV_CLICKED:
2137         {
2138                 FindNextWord(false);
2139         }
2140         break;
2141         case IDA_BRIGHTNESS_BTN_CLICKED:
2142         {
2143                 AppLogDebug("IDA_BRIGHTNESS_BTN_CLICKED");
2144                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_BRIGHTNESS, SCENE_TRANSITION_ANIMATION_TYPE_NONE));
2145         }
2146         break;
2147         case IDA_COPY_IMAGE_CLICKED:
2148         {
2149                 AppLogDebug("IDA_COPY_IMAGE_CLICKED");
2150                 AppLogDebug("IDA_COPY_IMAGE_CLICKED");
2151                 ClipboardItem item;
2152                 const Bitmap* pBitmap = null;
2153                 if (__pHitElementResult != null && __pHitElementResult->HasImage())
2154                 {
2155                         pBitmap = __pHitElementResult->GetImage();
2156                 }
2157
2158                 String resourcePath = App::GetInstance()->GetAppResourcePath();
2159                 r = item.Construct(CLIPBOARD_DATA_TYPE_IMAGE , *pBitmap);
2160                 AppLog("Platofrm construct failed result %s",GetErrorMessage(r));
2161                 // copying the item to clipboard
2162                 Clipboard* pClipboard = Clipboard::GetInstance();
2163                 if (pClipboard != null)
2164                 {
2165                         r = pClipboard->CopyItem(item);
2166                         AppLog("Platofrm copy failed result %s",GetErrorMessage(r));
2167                 }
2168         }
2169         break;
2170         case IDA_VIEW_IMAGE_CLICKED:
2171         {
2172                 AppLogDebug("IDA_VIEW_IMAGE_CLICKED");
2173                 WindowInfo* pNewWindowInfo = null;
2174                 if (__pHitElementResult != null)
2175                 {
2176                         String srcUrl = __pHitElementResult->GetAttributeValue(L"src");
2177                         AppLog("MainForm::OnTouchLongPressed srcUrl is %ls",srcUrl.GetPointer());
2178                         LoadUrl(srcUrl);
2179
2180                 }
2181         }
2182         break;
2183         case IDA_SAVE_IMAGE_CLICKED:
2184         {
2185                 AppLogDebug("IDA_SAVE_IMAGE_CLICKED");
2186                 const Bitmap* pSaveBitmap = null;
2187                 String imageName = GetImagePath();
2188                 AppLog("Content manager image name %ls",imageName.GetPointer());
2189                 String imagePath;
2190                 imagePath.Clear();
2191                 imagePath.Append(imageName);
2192                 imagePath.Format(100, L"%ls/Downloads/%ls.jpg",Tizen::System::Environment::GetMediaPath().GetPointer(),  imageName.GetPointer());
2193                 AppLog("Content manager image path %ls",imagePath.GetPointer());
2194                 if (__pHitElementResult != null)
2195                 {
2196                         pSaveBitmap = __pHitElementResult->GetImage();
2197                 }
2198                 ByteBuffer* pBuffer = __pSaveImage->EncodeToBufferN(*pSaveBitmap, IMG_FORMAT_JPG);
2199
2200                 if(pBuffer)
2201                 {
2202                         UpdateImageContent(pBuffer, imageName);
2203                         delete pBuffer;
2204                         if(__pNotification != null)
2205                         {
2206                                 RemoveControl(__pNotification);
2207                                 __pNotification = null;
2208                         }
2209                         __pNotification = new NotificationPanel(*this);
2210                         String msg;
2211                         AppResource::GetInstance()->GetString("IDS_COM_SK_SAVE", msg);
2212                         msg.Append(imagePath);
2213                         if (__pNotification != null)
2214                         {
2215                                 __pNotification->SetText(msg);
2216                                 if (__pFooterPanel->GetShowState() == true)
2217                                 {
2218                                         __pNotification->SetPositionDiff(__pFooterPanel->GetHeight());
2219                                 }
2220                                 else
2221                                 {
2222                                         __pNotification->SetPositionDiff(0);
2223                                 }
2224                                 __pNotification->ShowNotification();
2225                         }
2226                 }
2227                 else
2228                 {
2229                         int __modalMsgBoxResult;
2230                         MessageBox* pMsgBox = new MessageBox();
2231                         pMsgBox->Construct(CommonUtil::GetString(L"IDS_IMGE_POP_UNABLE_TO_SAVE_IMAGE"),CommonUtil::GetString(L"IDS_IMGE_POP_UNABLE_TO_SAVE_IMAGE"),MSGBOX_STYLE_OK,3000);
2232                         pMsgBox->ShowAndWait(__modalMsgBoxResult);
2233                         delete pMsgBox;
2234                         pMsgBox = null;
2235                         __modalMsgBoxResult = 0;
2236                 }
2237         }
2238         break;
2239         case IDA_SHARE_IMAGE_CLICKED:
2240         {
2241                 AppLogDebug("IDA_SHARE_IMAGE_CLICKED");
2242                 if (__pPopUp != null)
2243                 {
2244                         delete __pPopUp;
2245                         __pPopUp = null;
2246                 }
2247                 if(__pAddressbar)
2248                 {
2249                         __pAddressbar->HideKeypad();
2250                 }
2251                 __pPopUp = new(std::nothrow) SharePopup();
2252                 __pPopUp->Initialize();
2253                 if (__pHitElementResult != null)
2254                 {
2255                         const Bitmap* pSaveBitmap = null;
2256                         String imageName = GetImagePath();
2257                         AppLog("Content manager image name %ls",imageName.GetPointer());
2258                         String imagePath;
2259                         imagePath.Clear();
2260                         imagePath.Append(imageName);
2261                         imagePath.Format(100, L"%lsDownloads/%ls.jpg",Tizen::System::Environment::GetMediaPath().GetPointer(),  imageName.GetPointer());
2262                         AppLog("Content manager image path %ls",imagePath.GetPointer());
2263                         if (__pHitElementResult != null)
2264                         {
2265                                 pSaveBitmap = __pHitElementResult->GetImage();
2266                         }
2267                         __pSaveImage->EncodeToFile(*pSaveBitmap, IMG_FORMAT_JPG, imagePath, true);
2268
2269                         String srcUrl = __pHitElementResult->GetAttributeValue(L"src");
2270                         AppLog("MainForm::OnTouchLongPressed srcUrl is %ls",srcUrl.GetPointer());
2271
2272                         ShareInfo* pShareInfo = new(std::nothrow) ShareInfo();
2273                         pShareInfo->SetPageTitle(L"");
2274                         pShareInfo->SetPageUrl(srcUrl);
2275                         pShareInfo->SetImageAttached(true);
2276                         pShareInfo->SetImagePath(imagePath);
2277                         __pPopUp->RemoveAllShareInfo();
2278                         __pPopUp->AddShareInfo(pShareInfo);
2279                         __pPopUp->SetShowState(true);
2280                         __pPopUp->Show();
2281                 }
2282         }
2283         break;
2284         case IDA_HYPERLINK_OPEN_CLICKED:
2285         {
2286                 if (__pHitElementResult != null)
2287                 {
2288                         String srcUrl = __pHitElementResult->GetUrl();
2289
2290                         WindowInfo* pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewSceneN(srcUrl);
2291
2292                         if (pNewWindowInfo == null)
2293                         {
2294                                 return;
2295                         }
2296                         pNewWindowInfo->isJavascriptInitiated = true;
2297                         result r = E_SUCCESS;
2298                         SceneManager* pSceneManager = SceneManager::GetInstance();
2299                         if (pSceneManager == NULL)
2300                         {
2301                                 return;
2302                         }
2303                         ArrayList* pArgList = new(std::nothrow) ArrayList();
2304                         if (pArgList == NULL)
2305                         {
2306                                 return;
2307                         }
2308                         pArgList->Construct();
2309
2310                         pArgList->Add(*pNewWindowInfo);
2311                         r = pSceneManager->GoForward(ForwardSceneTransition(pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
2312                         if (pArgList != null)
2313                         {
2314                                 delete pArgList;
2315                                 pArgList = null;
2316                         }
2317                         if(IsFailed(r))
2318                         {
2319                                 AppLogDebug("MultipleWindowForm::OnActionPerformed GoForward failed %s",GetErrorMessage(r));
2320                                 return;
2321                         }
2322                 }
2323         }
2324         break;
2325         case IDA_HYPERLINK_SHARE_IMAGE_CLICKED:
2326         {
2327                 if (__pHitElementResult == null)
2328                 {
2329                         return;
2330                 }
2331
2332                 if(__pPopUp != null)
2333                 {
2334                         delete __pPopUp;
2335                         __pPopUp = null;
2336                 }
2337                 if(__pAddressbar)
2338                 {
2339                         __pAddressbar->HideKeypad();
2340                 }
2341                 __pPopUp = new(std::nothrow) SharePopup();
2342                 __pPopUp->Initialize();
2343
2344                 ShareInfo* pShareInfo = new(std::nothrow) ShareInfo();
2345                 pShareInfo->SetPageUrl(__pHitElementResult->GetUrl());
2346                 pShareInfo->SetImageAttached(false);
2347                 __pPopUp->RemoveAllShareInfo();
2348                 __pPopUp->AddShareInfo(pShareInfo);
2349
2350                 __pPopUp->SetShowState(true);
2351                 __pPopUp->Show();
2352         }
2353         break;
2354         case IDA_HYPERLINK_COPY_LINK_CLICKED:
2355         {
2356                 ClipboardItem item;
2357                 String url;
2358                 if (__pHitElementResult != null)
2359                 {
2360                         url = __pHitElementResult->GetUrl();
2361                 }
2362
2363                 String resourcePath = App::GetInstance()->GetAppResourcePath();
2364                 item.Construct(CLIPBOARD_DATA_TYPE_TEXT , url);
2365
2366                 // copying the item to clipboard
2367                 Clipboard* pClipboard = Clipboard::GetInstance();
2368                 if (pClipboard != null)
2369                 {
2370                         pClipboard->CopyItem(item);
2371                 }
2372         }
2373         break;
2374         case IDA_FIND_TEXT__CLICKED:
2375         {
2376 //              AddressBarCancelledClicked(*__pAddressbar);
2377                 RelayoutControls(false);
2378 //              __pFooterPanel->SetShowState(false);
2379                 AppLogDebug("MainForm::OnActionPerformed find word clicked");
2380                 __currentSearchStr.Clear();
2381                 __currentSearchStr.Append(__currentSelectedStr);
2382                 InitFindWordPanel();
2383                 __pFindWordEditField->SetText(__currentSearchStr);
2384
2385                 if(__pOptionMenu != null)
2386                 {
2387                         __pOptionMenu->SetShowState(false);
2388                         __pOptionMenu->Invalidate(false);
2389                 }
2390                 __adressPanelPosition.y = 0;
2391
2392                 if (__pAddressbar != null && __pWebViewer != NULL)
2393                 {
2394                         __webControlPosition.y = __pAddressbar->GetHeight() - 12;
2395                         __webControlHeight = GetClientAreaBounds().height - __pFooterPanel->GetHeight() - ( /*__pAddressbar->GetY() +*/ __pAddressbar->GetHeight() - 12);
2396
2397                         if (__pFooterPanel->GetShowState() == false)
2398                                 __pWebViewer->SetBounds(Rectangle(0,__webControlPosition.y,GetClientAreaBounds().width, GetClientAreaBounds().height - ( /*__pAddressbar->GetY() +*/ __pAddressbar->GetHeight() - 12)));
2399                         else
2400                                 __pWebViewer->SetBounds(Rectangle(0,__webControlPosition.y,GetClientAreaBounds().width, __webControlHeight));
2401                         __pWebViewer->Invalidate(true);
2402                 }
2403
2404                 ShowFindWordPanel(true);
2405                 if (__pFindWordPanelLeftToRight && __pFindWordPanelLeftToRight->GetShowState() == true)
2406                 {
2407                         __pFindWordEditField->SetText(__currentSearchStr);
2408                         __pFindWordEditField->SetFocus();
2409                 }
2410                 else if(__pFindWordPanelRightToLeft && __pFindWordPanelRightToLeft->GetShowState() == true)
2411                 {
2412                         __pFindWordEditFieldRightToLeft->SetText(__currentSearchStr);
2413                         __pFindWordEditFieldRightToLeft->SetFocus();
2414                 }
2415
2416                 if (__currentSearchStr.GetLength() > 0)
2417                 {
2418                         StartWordSearch();
2419                 }
2420                 else
2421                 {
2422                         AppLogDebug("Enter something");
2423                 }
2424
2425                 if (__pWebViewer != null)
2426                 {
2427                         // releasing the set block
2428                         __pWebViewer->ReleaseBlock();
2429                 }
2430
2431         }
2432         break;
2433         case IDA_SHARE_TEXT_CLICKED:
2434         {
2435                 __pWebViewer->ReleaseBlock();
2436                 AppLogDebug("IDA_SHARE_TEXT_CLICKED");
2437                 if(__pPopUp != null)
2438                 {
2439                         delete __pPopUp;
2440                         __pPopUp = null;
2441                 }
2442                 if(__pAddressbar)
2443                 {
2444                         __pAddressbar->HideKeypad();
2445                 }
2446                 __pPopUp = new(std::nothrow) SharePopup();
2447                 __pPopUp->Initialize();
2448                 if (__pHitElementResult != null)
2449                 {
2450                         ShareInfo* pShareInfo = new(std::nothrow) ShareInfo();
2451                         pShareInfo->SetPageTitle(L"");
2452                         pShareInfo->SetPageUrl(__currentSelectedStr);
2453                         pShareInfo->SetImageAttached(false);
2454                         __pPopUp->RemoveAllShareInfo();
2455                         __pPopUp->AddShareInfo(pShareInfo);
2456                         __pPopUp->SetShowState(true);
2457                         __pPopUp->Show();
2458                 }
2459         }
2460         break;
2461         case IDA_COPY_TEXT_CLICKED:
2462         {
2463                 __pWebViewer->ReleaseBlock();
2464                 // need to implement
2465                 //__currentSelectedStr
2466                 // Sets data to a clip board item
2467                 ClipboardItem item;
2468                 String resourcePath = App::GetInstance()->GetAppResourcePath();
2469                 item.Construct(CLIPBOARD_DATA_TYPE_TEXT, __currentSelectedStr);
2470
2471                 // copying the item to clipboard
2472                 Clipboard* pClipboard = Clipboard::GetInstance();
2473                 if (pClipboard != null)
2474                 {
2475                         pClipboard->CopyItem(item);
2476                 }
2477         }
2478         break;
2479         case IDA_PASTE_TEXT_CLICKED:
2480         {
2481                 Clipboard* pClipboard = Clipboard::GetInstance();
2482
2483                 if(pClipboard == null)
2484                 {
2485                         return;
2486                 }
2487                 // Retrieves a latest item
2488                 ClipboardItem* pItem = pClipboard->RetrieveLatestItemN(CLIPBOARD_DATA_TYPE_TEXT | CLIPBOARD_DATA_TYPE_HTML);
2489
2490                 if(pItem == null)
2491                 {
2492                         return;
2493                 }
2494                 //Gets data from the clipboard item
2495                 String* pString = dynamic_cast<String*>(pItem->GetData());
2496
2497                 if (pString != null)
2498                 {
2499                         String idElement = __pHitElementResult->GetAttributeValue(L"id");
2500                         String nameElement = __pHitElementResult->GetAttributeValue(L"name");
2501                         String tagElement  = __pHitElementResult->GetTagName();
2502                         AppLog("MainForm::IDA_PASTE_TEXT_CLICKED id is %ls",idElement.GetPointer());
2503
2504                         String script;
2505                         if(idElement.GetLength() != 0)
2506                         {
2507                                 script = L"function insertAtCursor(myField, myValue) {  if (document.selection) {   document.getElementById(myField).focus();   sel = document.selection.createRange();   sel.text = myValue;  }   else if (document.getElementById(myField).selectionStart || document.getElementById(myField).selectionStart == '0'){   var startPos = document.getElementById(myField).selectionStart;   var endPos = document.getElementById(myField).selectionEnd;   document.getElementById(myField).value = document.getElementById(myField).value.substring(0, startPos)+ myValue + document.getElementById(myField).value.substring(endPos, document.getElementById(myField).value.length);   } else {    document.getElementById(myField).value += myValue;   }  } ";
2508                                 script.Append("insertAtCursor('");
2509                                 script.Append(idElement);
2510                                 script.Append("',");
2511                                 script.Append("\"");
2512                                 script.Append(*pString);
2513                                 script.Append("\");");
2514                         }
2515                         else if (nameElement.GetLength() != 0)
2516                         {
2517                                 script = L"function insertAtCursor(myField, myValue) {  if (document.selection) {   document.getElementByName(myField)[0].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 {    document.getElementByName(myField)[0].value += myValue;   }  } ";
2518                                 script.Append("insertAtCursor(document.getElementsByName('");
2519                                 script.Append(nameElement);
2520                                 script.Append("')[0],");
2521                                 script.Append("\"");
2522                                 script.Append(*pString);
2523                                 script.Append("\");");
2524                         }
2525                         else//adding for twitter post page
2526                         {
2527                                 script = L"function insertAtCursor(myField, myValue) {  if (document.selection) {   document.getElementsByTagName(myField)[0].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 {    document.getElementsByTagName(myField)[0].value += myValue;   }  } ";
2528                                 script.Append("insertAtCursor(document.getElementsByTagName('");
2529                                 script.Append(tagElement);
2530                                 script.Append("')[0],");
2531                                 script.Append("\"");
2532                                 script.Append(*pString);
2533                                 script.Append("\");");
2534                         }
2535                         AppLog("MainForm::OnTouchLongPressed script is %ls",script.GetPointer());
2536                         String* pStr = __pWebViewer->EvaluateJavascriptN(script);
2537                         delete pStr;
2538                 }
2539                 delete pItem;
2540         }
2541         break;
2542         case IDA_GO_BACK:
2543         {
2544                 OnBackClicked();
2545         }
2546         break;
2547         case IDA_GO_FORWARD:
2548         {
2549                 OnForwardClicked();
2550         }
2551         break;
2552         case IDA_REFRESH_BTN_CLICKED:
2553         {
2554                 __isLoadingCompleted = false;
2555                 __isLoadingData = true;
2556                 __progressPercentage = 0;
2557                 __displayUrl = __pFooterUrlField->GetText();
2558
2559                 String url = __pFooterUrlField->GetText();
2560                 AppLog("MainForm::OnUrlSubmitted url is %ls", url.GetPointer());
2561 //              LoadUrl(url);
2562                 if (__pWebViewer != null && __pAddressbar != null)
2563                 {
2564                         __pWebViewer->Reload();
2565                         SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING);
2566                 }
2567
2568                 //OnUrlSubmitted();
2569                 UpdateProgressBitmap();
2570         }
2571         break;
2572         case IDA_STOP_BTN_CLICKED:
2573         {
2574                 __isLoadingCompleted = false;
2575                 __isLoadingData = false;
2576                 __progressPercentage = 0;
2577                 __pFooterUrlField->HideKeypad();
2578                 __displayUrl = __pFooterUrlField->GetText();
2579
2580                 if (__pWebViewer)
2581                 {
2582                         //__pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
2583                         SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
2584                         __pWebViewer->StopLoading();
2585                         RequestRedraw(true);
2586                 }
2587
2588                 UpdateProgressBitmap();
2589         }
2590         break;
2591         case IDA_CLEAR_URL:
2592         {
2593                 if (__pFooterUrlField->GetText().IsEmpty() == false)
2594                 {
2595                         //__displayUrl = __pUrlField->GetText();
2596                         __pFooterUrlField->Clear();
2597
2598                 }
2599         }
2600         break;
2601         case IDA_READER_BTN_CLICKED:
2602         {
2603                 ReaderClicked();
2604         }
2605         break;
2606         default:
2607                 break;
2608         }
2609 }
2610
2611 void
2612 MainForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
2613 {
2614         AppLog("MainForm::OnFormBackRequested entered");
2615         result r = E_FAILURE;
2616         if(__pImageMenu && __pImageMenu->GetShowState() == true)
2617         {
2618                 AppLog("Hiding the menu");
2619                 __pImageMenu->SetShowState(false);
2620         }
2621         if (__pWebViewer && __pWebViewer->CanGoBack())
2622         {
2623                 __pWebViewer->GoBack();
2624         }
2625         else if(__pWindowInfo && __pWindowInfo->isJavascriptInitiated == false)
2626         {
2627                 UiApp* pApp = null;
2628                 pApp = UiApp::GetInstance();
2629                 if (pApp != null)
2630                 {
2631                         r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
2632                         if (IsFailed(r))
2633                         {
2634                                 AppLogException("MainForm::OnFormBackRequested failed with %s", GetErrorMessage(r));
2635                                 return;
2636                         }
2637                 }
2638         }
2639         else
2640         {
2641                 UiApp* pApp = null;
2642                 WindowInfo* pWindowInfo = null;
2643                 int totalCount = 0;
2644                 SceneManager* pSceneManager = SceneManager::GetInstance();
2645                 if (pSceneManager == null)
2646                 {
2647                         return;
2648                 }
2649                 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
2650                 if (pAllWindowList == NULL)
2651                 {
2652                         pApp = UiApp::GetInstance();
2653                         if (pApp != null)
2654                         {
2655                                 r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
2656                                 if (IsFailed(r))
2657                                 {
2658                                         AppLogException("MainForm::OnFormBackRequested failed with %s", GetErrorMessage(r));
2659                                         return;
2660                                 }
2661                         }
2662                 }
2663                 if (pAllWindowList != null)
2664                 {
2665                         totalCount = pAllWindowList->GetCount();
2666                 }
2667                 for (int count = 0; count < totalCount; count++)
2668                 {
2669                         pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count));
2670                         if (pWindowInfo == null)
2671                         {
2672                                 pApp = UiApp::GetInstance();
2673                                 if (pApp != null)
2674                                 {
2675                                         r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
2676                                         if (IsFailed(r))
2677                                         {
2678                                                 AppLogException("MainForm::OnFormBackRequested failed with %s", GetErrorMessage(r));
2679                                                 return;
2680                                         }
2681                                 }
2682                         }
2683                         else
2684                         {
2685                                 if (pWindowInfo && pSceneManager->GetCurrentSceneId() == pWindowInfo->sceneID && pWindowInfo->isJavascriptInitiated == true)
2686                                 {
2687                                         r = SceneRegister::DestroyAndUnRegisterScene(pWindowInfo->sceneID);
2688                                         if (IsFailed(r))
2689                                         {
2690                                                 AppLogException("MainForm::OnFormBackRequested failed with %s", GetErrorMessage(r));
2691                                                 return;
2692                                         }
2693                                         r = pAllWindowList->RemoveAt(count, true);
2694 //                                      __pWindowInfo = null;
2695                                         if (IsFailed(r))
2696                                         {
2697                                                 AppLogException("MainForm::OnFormBackRequested failed with %s", GetErrorMessage(r));
2698                                                 return;
2699                                         }
2700                                         if(count > 0)
2701                                         {
2702                                                 pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count - 1));
2703                                         }
2704                                         else
2705                                         {
2706                                                 pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(pAllWindowList->GetCount() - 1));
2707                                         }
2708                                         if (pWindowInfo == null)
2709                                         {
2710                                                 pApp = UiApp::GetInstance();
2711                                                 if (pApp != null)
2712                                                 {
2713                                                         r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
2714                                                         return;
2715                                                 }
2716                                         }
2717                                         else
2718                                         {
2719                                                 if(pWindowInfo != null)
2720                                                         r = pSceneManager->GoForward(ForwardSceneTransition(pWindowInfo->sceneID ,SCENE_TRANSITION_ANIMATION_TYPE_NONE,SCENE_HISTORY_OPTION_ADD_HISTORY,SCENE_DESTROY_OPTION_DESTROY));
2721                                                 if (IsFailed(r))
2722                                                 {
2723                                                         AppLogException("MainForm::OnFormBackRequested failed with %s", GetErrorMessage(r));
2724                                                         return;
2725                                                 }
2726                                         }
2727                                         break;
2728                                 }
2729 //                              else if (pWindowInfo && pSceneManager->GetCurrentSceneId() == pWindowInfo->sceneID && pWindowInfo->isJavascriptInitiated == false)
2730 //                              {
2731 //                                      UiApp* pApp = null;
2732 //                                      pApp = UiApp::GetInstance();
2733 //                                      if (pApp != null)
2734 //                                      {
2735 //                                              r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
2736 //                                              if (IsFailed(r))
2737 //                                              {
2738 //                                                      AppLogException("MainForm::OnFormBackRequested failed with %s", GetErrorMessage(r));
2739 //                                                      return;
2740 //                                              }
2741 //                                      }
2742 //                              }
2743                         }
2744                 }
2745         }
2746         AppLog("MainForm::OnFormBackRequested exit");
2747 }
2748
2749 void
2750 MainForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
2751                 const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
2752 {
2753
2754         AppLog("MainForm::OnSceneActivatedN called");
2755         String* pSelectedScene = NULL;
2756         Object* pValue = NULL;
2757         String* pUrl = null;
2758         MultipleWindowPresentationModel::GetInstance()->GetValue(SELECTED_SCENE_ID, &pValue);
2759         pSelectedScene = (String*) pValue;
2760
2761         if (pSelectedScene != null)
2762         {
2763                 delete pSelectedScene;
2764         }
2765         MultipleWindowPresentationModel::GetInstance()->SetValue(SELECTED_SCENE_ID, null);
2766         String* selectedSceneID = new(std::nothrow) String(currentSceneId);
2767         AppLogDebug("current scene id is %ls", currentSceneId.GetPointer());
2768         AppLogDebug("selected scene id is %ls", currentSceneId.GetPointer());
2769
2770         // setting the current scene ID
2771         MultipleWindowPresentationModel::GetInstance()->SetCurrentSceneID(currentSceneId);
2772
2773         MultipleWindowPresentationModel::GetInstance()->SetValue(SELECTED_SCENE_ID, (Object*) selectedSceneID);
2774
2775         if(pArgs != null && pArgs->GetCount() > 0 && pArgs->GetCount() == 2)
2776         {
2777                 __pWindowInfo = dynamic_cast< WindowInfo* >(pArgs->GetAt(0));
2778                 if(__pWindowInfo == null)
2779                         return;
2780                 //              if(__pWindowInfo == null)
2781                 {
2782                         pUrl = dynamic_cast< String* >(pArgs->GetAt(1));
2783                 }
2784         }
2785         else if ( pArgs != null && pArgs->GetCount() == 1)
2786         {
2787                 __pWindowInfo = dynamic_cast< WindowInfo* >(pArgs->GetAt(0));
2788         }
2789
2790         InitFooter();
2791         InitAddressbar();
2792
2793         __pFooterPanel->SetBounds(0, GetClientAreaBounds().height - __pFooterPanel->GetHeight(), GetClientAreaBounds().width, __pFooterPanel->GetHeight());
2794
2795         // hiding the address bar
2796         //      __pAddressbar->SetBounds(__pAddressbar->GetX(), __pAddressbar->GetY() - __pAddressbar->GetHeight(), __pAddressbar->GetWidth(), __pAddressbar->GetHeight());
2797         __pAddressbar->SetShowState(false);
2798 //      if(__pWebViewer != null)
2799 //      {
2800 //              __pWebViewer->Resume();
2801 //      }
2802
2803         if(pUrl != null && pUrl->GetLength() > 0)
2804         {
2805                 LoadUrl(*pUrl);
2806         }
2807         else if(__pWindowInfo != null)
2808         {
2809                 if(__pWindowInfo->pageUrl.GetLength() > 0 &&previousSceneId != IDSCN_BRIGHTNESS && previousSceneId != IDSCN_HISTORY_LIST && previousSceneId != IDSCN_MULTIPLE_WINDOW && previousSceneId != IDSCN_MULTIPLE_WINDOW_GRID && previousSceneId != IDSCN_BOOKMARK_VIEW && previousSceneId != IDSCN_SETTINGS && previousSceneId.Contains(IDSCN_MAIN_VIEW) == false)
2810                 {
2811                         LoadUrl(__pWindowInfo->pageUrl);
2812                 }
2813                 else if(__pWindowInfo->pageUrl.GetLength() > 0 && __pWindowInfo->isAppcontrolTriggered == true)
2814                 {
2815                         LoadUrl(__pWindowInfo->pageUrl);
2816                         __pWindowInfo->isAppcontrolTriggered = false;
2817                 }
2818                 else if (__pWindowInfo->isJavascriptInitiated == true && __pWindowInfo->isFirstLaunch == true)
2819                 {
2820                         __pWindowInfo->isFirstLaunch = false;
2821                         AppLog("Called");
2822                         InitWebControl();
2823                         __pWindowInfo->pCurrentWeb = __pWebViewer;
2824                         if(__pWindowInfo->pageUrl.GetLength() > 0)
2825                                 LoadUrl(__pWindowInfo->pageUrl);
2826                 }
2827         }
2828
2829         String homePage = SettingPresentationModel::GetInstance()->GetHomepage();
2830         AppLog("Homepage Value in Onsceneactivated is %ls",homePage.GetPointer());
2831         if(homePage.CompareTo((L"IDS_BR_BODY_MOST_VISITED_SITES")) == 0)
2832         {
2833                 InitMostVisitedSitesView(GetOrientationStatus());
2834         }
2835         else if (homePage.CompareTo((L"IDS_BR_BODY_BLANK_PAGE")) == 0)
2836         {
2837                 if(__pMostVisitedListView != null)
2838                 {
2839                         __pMostVisitedListView->SetShowState(false);
2840                 }
2841         }
2842
2843         if (__pAddressbar != null && pArgs != null && (previousSceneId == IDSCN_BOOKMARK_VIEW || previousSceneId == IDSCN_HISTORY_LIST))
2844         {
2845                 String* pBookmarkUrl = dynamic_cast< String* >(pArgs->GetAt(0));
2846
2847                 if (pBookmarkUrl == null)
2848                         return;
2849                 AppLogDebug("bookmarkUrl = %ls",pBookmarkUrl->GetPointer());
2850                 //__pAddressbar->SetUrl(*pBookmarkUrl);
2851                 SetUrl(*pBookmarkUrl);
2852
2853                 if (__pWebViewer != null && homePage.CompareTo((L"IDS_BR_BODY_BLANK_PAGE")) != 0)
2854                         __pWebViewer->LoadUrl(*pBookmarkUrl);
2855                 delete pBookmarkUrl;
2856         }
2857
2858         bool isPrivateBrowsing = SettingPresentationModel::GetInstance()->GetPrivateOn();
2859         Bitmap* pBitmap = null;
2860         if (isPrivateBrowsing == true)
2861         {
2862                 pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_BUTTON_ON);
2863
2864                 if (__pWebViewer != null)
2865                 {
2866                         __pWebViewer->SetPrivateBrowsingEnabled(true);
2867                 }
2868
2869                 if (__pAddressbar != null)
2870                 {
2871                         //      __pAddressbar->UpdateFaviconBitmap(true);
2872                 }
2873
2874         }
2875         else
2876         {
2877                 pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_BUTTON_OFF);
2878
2879                 if (__pWebViewer != null)
2880                 {
2881                         __pWebViewer->SetPrivateBrowsingEnabled(false);
2882                 }
2883
2884                 if (__pAddressbar != null)
2885                 {
2886                         //      __pAddressbar->UpdateFaviconBitmap(false);
2887                 }
2888         }
2889
2890         if (__pOptionMenu != null && __pOptionMenu->GetItemCount() != 9)
2891         {
2892                 __pOptionMenu->SetItemAt(1,CommonUtil::GetString(L"IDS_BR_BODY_PRIVACY_AND_SECURITY_ABB"),IDA_PRIVATEON_CLICKED,*pBitmap);
2893         }
2894         else if (__pOptionMenu != null )
2895         {
2896                 __pOptionMenu->SetItemAt(5,CommonUtil::GetString(L"IDS_BR_BODY_PRIVACY_AND_SECURITY_ABB"),IDA_PRIVATEON_CLICKED,*pBitmap);
2897         }
2898
2899         if (pBitmap != null)
2900         {
2901                 delete pBitmap;
2902         }
2903
2904         RelayoutControls(false);
2905         AppLog("ABC: OnSceneActivatedN started exit");
2906
2907 }
2908
2909 void
2910 MainForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
2911                 const Tizen::Ui::Scenes::SceneId& nextSceneId)
2912 {
2913         Canvas* pWebCanvas = null;
2914         if (__pWebViewer != null)
2915         {
2916                 pWebCanvas = __pWebViewer->GetCanvasN();
2917
2918         }
2919         if (pWebCanvas == null)
2920         {
2921                 return;
2922         }
2923         if (__pWindowInfo != null)
2924         {
2925                 if (__pWindowInfo->pWebCanvasBitmap != null)
2926                 {
2927                         delete __pWindowInfo->pWebCanvasBitmap;
2928                 }
2929                 __pWindowInfo->pWebCanvasBitmap = new(std::nothrow) Bitmap();
2930                 result r = __pWindowInfo->pWebCanvasBitmap->Construct(*pWebCanvas,Rectangle(0,0,pWebCanvas->GetBounds().width,pWebCanvas->GetBounds().height));
2931                 AppLog("Bitmap Construction result %s",GetErrorMessage(r));
2932         }
2933         Bitmap* pBitmap = GetCapturedBitmapN();
2934         AppLog("Coming here");
2935         Canvas* pCanvas = new(std::nothrow) Canvas();
2936         pCanvas->Construct(GetClientAreaBounds());
2937         if(pBitmap != null)
2938         {
2939                 pCanvas->DrawBitmap(Point(0,0),*pBitmap);
2940                 delete pBitmap;
2941         }
2942         if(__pWebViewer != null && __pWindowInfo != null)
2943                 pCanvas->DrawBitmap(__pWebViewer->GetPosition(),*__pWindowInfo->pWebCanvasBitmap);
2944
2945         WindowInfo::pFormCanvasBitmap = new(std::nothrow) Bitmap();
2946         WindowInfo::pFormCanvasBitmap->Construct(*pCanvas,Rectangle(0,0,GetClientAreaBounds().width,GetClientAreaBounds().height - __pFooterPanel->GetHeight()));
2947         delete pCanvas;
2948         delete pWebCanvas;
2949         if(__pAddressbar)
2950                 __pAddressbar->SetShowState(false);
2951         AppLog("Coming here");
2952 }
2953
2954 bool
2955 MainForm::OnHttpAuthenticationRequestedN(const Tizen::Base::String& host,
2956                 const Tizen::Base::String& realm,
2957                 const Tizen::Web::Controls::AuthenticationChallenge& authentication)
2958 {
2959         return false;
2960 }
2961
2962 void
2963 MainForm::OnHttpAuthenticationCanceled(void)
2964 {
2965 }
2966
2967 void
2968 MainForm::OnLoadingStarted(void)
2969 {
2970         AppLogDebug("MainForm::OnLoadingStarted entered");
2971         __isLoaded = true;
2972         if(__pAddressbar == NULL || __pWebViewer == null)
2973         {
2974                 return;
2975         }
2976
2977         // this is added in case if menu is opened and user load the page
2978         if(__pOptionMenu != null && __pOptionMenu->GetShowState() == true)
2979         {
2980                 __pOptionMenu->SetShowState(false);
2981                 __pOptionMenu->Invalidate(true);
2982         }
2983
2984
2985
2986         if(__pImageMenu != null && __pImageMenu->GetShowState() == true)
2987         {
2988                 __pImageMenu->SetShowState(false);
2989                 __pImageMenu->Invalidate(true);
2990         }
2991         String url = __pWebViewer->GetUrl();
2992         if(url.Contains(IDS_TIZEN_SERVICE))
2993         {
2994                 String appId;
2995                 String delim(L":;,");
2996
2997                 // Creates a StringTokenizer instance
2998                 StringTokenizer strTok(url, delim);
2999
3000                 int count = strTok.GetTokenCount();     // count == 4
3001
3002                 HashMap *pMap = new HashMap();
3003                 pMap->Construct();
3004                 String token;
3005                 String key;
3006                 String value;
3007                 while (strTok.HasMoreTokens())
3008                 {
3009                         AppLog("Token: %ls", token.GetPointer());
3010                         strTok.GetNextToken(token);         // Tizen, StringTokenizer, Sample, code
3011                         if(token.Contains(IDS_APPID))
3012                         {
3013                                 token.SubString(6, appId);
3014                                 AppLog("AppID:%ls", appId.GetPointer());
3015                         }
3016                         else if(token.Contains(IDS_KEY))
3017                         {
3018                                 token.SubString(4, key);
3019                                 AppLog("key:%ls", key.GetPointer());
3020                         }
3021                         else if(token.Contains(IDS_VALUE))
3022                         {
3023                                 token.SubString(6, value);
3024                                 AppLog("value:%ls", value.GetPointer());
3025                         }
3026                 }
3027                 pMap->Add(key, value);
3028
3029                 if(appId != "")
3030                 {
3031                         AppControl *pAppControl = null;
3032                         String operationId = L"http://tizen.org/appcontrol/operation/main";
3033                         pAppControl = dynamic_cast<AppControl*>(AppManager::FindAppControlN(appId, operationId));
3034                         if(pAppControl)
3035                         {
3036                                 AppLog("Starting AppControl");
3037                                 result r = pAppControl->Start(null, null, pMap, null);
3038                                 AppLog("Result of Start %s", GetErrorMessage(r));
3039                         }
3040                         else
3041                         {
3042                                 AppLogException("AppControl not found");
3043                         }
3044                         return;
3045                 }
3046         }
3047         if ( __pAddressbar != null && __pAddressbar->GetShowState() == true)
3048         {
3049                 __pAddressbar->SetShowState(false);
3050                 AddressBarCancelledClicked(*__pAddressbar);
3051                 __pAddressbar->Invalidate(true);
3052         }
3053         Bitmap* pBitmap = FaviconManager::GetInstance()->GetDefaultFaviconN();
3054         if(pBitmap != null)
3055         {
3056                 __pAddressbar->SetFaviconBitmap(*pBitmap);
3057         }
3058         delete pBitmap;
3059         if (__adressPanelPosition.y < (0 - __pAddressbar->GetHeight() + 12))
3060         {
3061                 // updating the address bar position with respect to web control
3062                 __adressPanelPosition.y = 0 - __pAddressbar->GetHeight() + 12; //-12 is for the progress label
3063                 __distanceMoved = 0;
3064                 MoveUiControls();
3065         }
3066
3067         //__pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING);
3068         SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING);
3069         if (__pWebViewer != null)
3070         {
3071                 AppLog("MainForm::OnLoadingStarted __pWebViewer->GetUrl() %ls",__pWebViewer->GetUrl().GetPointer());
3072                 //__pAddressbar->SetUrl(__pWebViewer->GetUrl());
3073                 SetUrl(__pWebViewer->GetUrl());
3074                 if (__pWindowInfo != NULL)
3075                 {
3076                         // resetting the page title to blank, it will be received in OnPageTitleReceived()
3077                         __pWindowInfo->pageTitle = L"";
3078                         __pWindowInfo->pageUrl = __pWebViewer->GetUrl();
3079                 }
3080                 __pAddressbar->Invalidate(true);
3081         }
3082
3083 }
3084
3085 void
3086 MainForm::OnLoadingCanceled(void)
3087 {
3088
3089 }
3090
3091
3092 void
3093 MainForm::OnKeypadWillOpen(Tizen::Ui::Control& source)
3094 {
3095         AppLog("XYZ::MainForm::OnKeypadWillOpen");
3096
3097 }
3098
3099 void
3100 MainForm::OnKeypadOpened(Tizen::Ui::Control& source)
3101 {
3102         AppLog("XYZ::MainForm::OnKeypadOpened");
3103         __isKeypadOpened = true;
3104         __pFooterPanel->SetShowState(false);
3105
3106 }
3107
3108 void
3109 MainForm::OnKeypadClosed(Tizen::Ui::Control& source)
3110 {
3111         AppLog("XYZ::MainForm::OnKeypadClosed");
3112         __isKeypadOpened = false;
3113         __pFooterPanel->SetShowState(true);
3114         RelayoutControls(true);
3115 }
3116
3117 void
3118 MainForm::OnKeypadBoundsChanged(Tizen::Ui::Control &source)
3119 {
3120         AppLog("XYZ::KeypadBoundsChanged");
3121         RelayoutControls(false);
3122 }
3123
3124 void
3125 MainForm::OnLoadingErrorOccurred(LoadingErrorType error,
3126                 const Tizen::Base::String& reason)
3127 {
3128         AppLogDebug("Error: %d, %ls", error, reason.GetPointer());
3129 }
3130
3131 void
3132 MainForm::OnLoadingCompleted(void)
3133 {
3134         AppLog("MainForm::OnLoadingCompleted start");
3135         DateTime date;
3136         result r = E_SUCCESS;
3137
3138         if (__pWebViewer == null)
3139         {
3140                 return;
3141         }
3142
3143         if (__pAddressbar == null)
3144         {
3145                 return;
3146         }
3147
3148         if(__pImageMenu && __pImageMenu->GetShowState())
3149         {
3150                 __pImageMenu->SetShowState(false);
3151                 __pImageMenu->Invalidate(true);
3152         }
3153
3154         if (__pWebViewer->CanGoForward())
3155         {
3156                 //__pAddressbar->SetForwardButtonEnabled(true);
3157                 SetForwardButtonEnabled(true);
3158         }
3159         else
3160         {
3161                 //__pAddressbar->SetForwardButtonEnabled(false);
3162                 SetForwardButtonEnabled(false);
3163         }
3164
3165         /*if (__pAddressbar->GetAddressbarMode() != ADDRESSBAR_MODE_EDIT)
3166         {
3167                 __pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
3168
3169                 //__pAddressbar->UpdateProgress(0);
3170                 UpdateProgress(0);
3171         }*/
3172
3173         if(GetAddressbarMode() != ADDRESSBAR_MODE_EDIT)
3174         {
3175                 SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
3176                 UpdateProgress(0);
3177         }
3178
3179         AppLog("PrivateBrowsing %d",__pWebViewer->IsPrivateBrowsingEnabled());
3180         bool isPrivateBrowsing = SettingPresentationModel::GetInstance()->GetPrivateOn();
3181         if (isPrivateBrowsing == false)
3182         {
3183                 if(__pHistory != null)
3184                 {
3185                         delete __pHistory;
3186                         __pHistory = null;
3187                 }
3188
3189                 __pHistory = new(std::nothrow) History;
3190                 HistoryPresentationModel::GetCurrentDateTime(date);
3191                 if (__pWindowInfo)
3192                 {
3193                         __pHistory->SetHistoryTitle(__pWindowInfo->pageTitle);
3194                         AppLogDebug("MainForm::OnLoadingCompleted pagetitle = %ls", __pWindowInfo->pageTitle.GetPointer());
3195
3196                         __pHistory->SetHistoryUrl(__pWindowInfo->pageUrl);
3197                         AppLogDebug("MainForm::OnLoadingCompleted pageUrl = %ls", __pWindowInfo->pageUrl.GetPointer());
3198                 }
3199                 __pHistory->SetVisitedTime(date);
3200
3201                 if (__pWebViewer != null)
3202                 {
3203                         AppLog("MainForm::OnLoadingCompleted setting the fav icon 0");
3204
3205                         Bitmap* pTempBitmap = __pWebViewer->GetFaviconN();
3206                         if (pTempBitmap != null)
3207                         {
3208                                 AppLog("MainForm::OnLoadingCompleted setting the fav icon 1");
3209                                 __pHistory->SetFavIconBitmap(*pTempBitmap);
3210                         }
3211
3212                         AppLog("MainForm::OnLoadingCompleted setting the fav icon 2");
3213                 }
3214
3215                 Canvas* pCanvas = __pWebViewer->GetCanvasN();
3216                 Bitmap* pBitmap = new(std::nothrow) Bitmap();
3217                 if ( pCanvas != null &&  pCanvas != null && pBitmap != null)
3218                 {
3219                         pBitmap->Construct(*pCanvas, pCanvas->GetBounds());
3220                         pBitmap->Scale(Dimension(pBitmap->GetWidth()/4, pBitmap->GetHeight()/4));
3221                         __pHistory->SetThumbnail(pBitmap);
3222                 }
3223                 Bitmap *pFavIcon = __pWebViewer->GetFaviconN();
3224                 if (pFavIcon)
3225                 {
3226                         __pHistory->SetFavIconBitmap(*pFavIcon);
3227                         delete pFavIcon;
3228                 }
3229
3230                 HistoryPresentationModel::GetInstance()->SaveTempHistory(*__pHistory);
3231                 //delete pHistory;
3232         }
3233         else
3234         {
3235                 return;
3236         }
3237 //      if (__pWindowInfo && __pWindowInfo->faviconUrl == "")
3238         {
3239                 // temperary fixed (webpage can be not loaded)
3240                 UpdateFavicon();
3241         }
3242
3243         bool isReaderEnabled = SettingPresentationModel::GetInstance()->IsRunReaderEnabled();
3244         if (isReaderEnabled == true)
3245         {
3246                 if (__pReaderData)
3247                 {
3248                         delete __pReaderData;
3249                         __pReaderData = null;
3250                 }
3251                 String filePath = Tizen::App::UiApp::GetInstance()->GetAppRootPath();
3252                 filePath.Append(L"data/reader.js");
3253                 File file;
3254                 char buffer[10];
3255                 char buffer2[5];
3256                 int i;
3257                 int readCnt;
3258                 result r = E_SUCCESS;
3259                 FileAttributes attr;
3260
3261                 File::GetAttributes(filePath,attr);
3262                 // Creates file
3263                 r = file.Construct(filePath, L"r+");
3264                 if (IsFailed(r))
3265                 {
3266                         AppLogDebug("File construct failed with %s", GetErrorMessage(r));
3267                         return;
3268                 }
3269                 char* pScript = new(std::nothrow) char[attr.GetFileSize()+1];
3270                 if(pScript == null)
3271                 {
3272                         AppLogDebug("Memory allocation for file failed %s", GetErrorMessage(r));
3273                         return;
3274                 }
3275 //              file.Read(pScript,attr.GetFileSize());
3276 //
3277 //              AppLogDebug("scipt length %d",strlen(pScript));
3278                 String strScript = L"";
3279 //              strScript.Append(pScript);
3280 //              for(int i=0; i<25; i++)
3281                 {
3282                         file.Read(pScript,attr.GetFileSize());
3283 //                      AppLog("xyzz tell %d",file.Tell());
3284 //                      r = strScript.Append(pScript);
3285 //                      AppLog("xyzz append result %s",GetErrorMessage(r));
3286 //                      AppLog("xyzz strScript length %d",strScript.GetLength());
3287                 }
3288 //              AppLog("xyzz final strScript length %d",strScript.GetLength());
3289
3290                 __pReaderData = __pWebViewer->EvaluateJavascriptN(pScript);
3291                 if (__pReaderData == null)
3292                 {
3293                         AppLog("MainScene::data is null Error :%s",GetErrorMessage(GetLastResult()));
3294                         __pReaderData = new String(L"<meta name=\"viewport\" content=\"width=0, initial-scale=1.0, maximum-scale=2.0, minimum-scale=1.0, user-scalable=no, target-densitydpi=medium-dpi\">      <h1>Chinese PM Li Keqiang vows to open up markets to India</h1><div><span class=\"arttle\"><h1>Chinese PM Li Keqiang vows to open up markets to India</h1></span></div>");
3295 //                      return;
3296                 }
3297                 AppLogDebug("evaluateJavascript result %s , __pReaderData %ls",GetErrorMessage(GetLastResult()),__pReaderData->GetPointer());
3298                 if (__pReaderData->CompareTo(L"undefined") != 0 && __pReaderData->CompareTo(L"") != 0)
3299                 {
3300                         //__pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_READER);
3301                         SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_READER);
3302                 }
3303                 delete[] pScript;
3304         }
3305
3306
3307         AppLog("MainForm::OnLoadingCompleted done");
3308 }
3309
3310 void
3311 MainForm::OnEstimatedProgress(int progress)
3312 {
3313         AppLogDebug("MainForm::OnEstimatedProgress entered %d",progress);
3314
3315         if (progress < DEFAULT_PROGRESS_PERCENTAGE)
3316                 progress = DEFAULT_PROGRESS_PERCENTAGE;
3317         //if(__pAddressbar)
3318         //      __pAddressbar->UpdateProgress(progress);
3319         UpdateProgress(progress);
3320 }
3321
3322 void MainForm::OnFaviconReceived(const Tizen::Graphics::Bitmap& favicon)
3323 {
3324         AppLog("MainForm::OnFaviconReceived");
3325         if (__pWebViewer != null && __pHistory != null && __pWindowInfo != null && (__pWindowInfo->pageUrl.CompareTo(__pHistory->GetHistoryUrl()) == 0))
3326         {
3327                 Bitmap* favIcon = __pWebViewer->GetFaviconN();
3328                 if(favIcon != null)
3329                 {
3330                         HistoryPresentationModel::GetInstance()->UpdateHistoryFavIcon(*__pHistory, *favIcon);
3331                         delete favIcon;
3332                 }
3333         }
3334 }
3335
3336 void
3337 MainForm::OnUrlValueChanged(Addressbar&)
3338 {
3339         Invalidate(true);
3340 }
3341
3342 void
3343 MainForm::OnUrlSubmitted(Addressbar& addBar)
3344 {
3345         AppLog("MainForm::OnUrlSubmitted");
3346         String url = addBar.GetUrl();
3347         AppLog("MainForm::OnUrlSubmitted url is %ls", url.GetPointer());
3348
3349         if(__pFooterUrlField)
3350                 __pFooterUrlField->SetCursorPosition(__pFooterUrlField->GetTextLength());
3351         AddressBarCancelledClicked(*__pAddressbar);
3352         LoadUrl(url);
3353 }
3354
3355 void
3356 MainForm::LoadUrl(String& url)
3357 {
3358         url.Trim();
3359         String encodedUrl;
3360 //      UrlEncoder::Encode(url, L"UTF-8", encodedUrl);
3361         AppLogDebug("MainForm::LoadUrl enter");
3362
3363         if (__pWebViewer != null)
3364         {
3365                 __pWebViewer->SetShowState(true);
3366                 __pWebViewer->Invalidate(true);
3367         }
3368
3369         if (url.CompareTo(L"") == 0)
3370         {
3371                 return;
3372         }
3373         if(__pFooterPanel != null)
3374         {
3375                 __pFooterPanel->SetShowState(true);
3376                 __pFooterPanel->Invalidate(true);
3377         }
3378         InitWebControl();
3379
3380         bool ret = false;
3381         bool flag = false;
3382
3383         String firstPattern(L"((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)");
3384         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)
3385
3386         RegularExpression firstRegex;
3387         RegularExpression secondRegex;
3388
3389         firstRegex.Construct(firstPattern, REGEX_CASELESS);
3390         secondRegex.Construct(secondPattern, REGEX_CASELESS);
3391
3392         // Match
3393         ret = firstRegex.Match(url, false); // This returns true value
3394         flag = secondRegex.Match(url, false);  // Checks whether URL typed is of type  abc.com (i.e without protocol in front of it)
3395
3396         if (ret == true && __pWebViewer != null)
3397         {
3398                 SetUrl(url);
3399                 __pWebViewer->LoadUrl(url);
3400         }
3401         else if(__pWebViewer != null)
3402         {
3403                 String tempUrl = L"http://";
3404                 tempUrl.Append(url);
3405
3406                 if (flag == true)
3407                 {
3408                         __pWebViewer->LoadUrl(tempUrl);
3409                 }
3410                 else
3411                 {
3412                                 UrlEncoder::Encode(url, L"UTF-8", encodedUrl);
3413                         __pWebViewer->LoadUrl(SettingPresentationModel::GetInstance()->GetSearchUrl(encodedUrl));
3414                 }
3415         }
3416         if (__pAddressbar != null)
3417         {
3418                 //__pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING);
3419                 SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING);
3420         }
3421
3422         AppLogDebug("MainForm::LoadUrl exit");
3423
3424         return;
3425
3426 }
3427
3428 void
3429 MainForm::OnFocusGained(const Tizen::Ui::Control& source)
3430 {
3431         AppLog("MainForm::OnFocusGained");
3432         if(__pFooterPanel)
3433         {
3434                 __pFooterPanel->SetShowState(false);
3435         }
3436
3437         if(__pAddressbar)
3438         {
3439                 __pAddressbar->SetShowState(true);
3440                 __pAddressbar->SetAddressbarURLFocus();
3441         }
3442         if(__pFindWordControl && __pFindWordControl->GetShowState() == true)
3443         {
3444                 __currentSearchStr = L"";
3445                 __currentWordIndex = 0;
3446                 __maxOccurrances = 0;
3447
3448                 if (__pFindWordPanelLeftToRight && __pFindWordPanelLeftToRight->GetShowState() == true)
3449                 {
3450                         __pFindWordEditField->SetText(L"");
3451                         __pFindWordEditField->HideKeypad();
3452                         __pFindWordControl->SetShowState(false);
3453                         __pFindWordCountLabel->SetText(L"0/0");
3454                 }
3455                 else if(__pFindWordPanelRightToLeft && __pFindWordPanelRightToLeft->GetShowState() == true)
3456                 {
3457                         __pFindWordEditFieldRightToLeft->SetText(L"");
3458                         __pFindWordEditFieldRightToLeft->HideKeypad();
3459                         __pFindWordControl->SetShowState(false);
3460                         __pFindWordCountLabelRightToLeft->SetText(L"0/0");
3461                 }
3462
3463                 __pFindWordNext->SetEnabled(false);
3464                 __pFindWordPrev->SetEnabled(false);
3465
3466                 __pWebViewer->SearchTextAllAsync(L"",true);
3467                 __pFindWordControl->SetShowState(false);
3468         }
3469         RelayoutControls(false);
3470 }
3471
3472 void
3473 MainForm::OnFocusLost(const Tizen::Ui::Control& source)
3474 {
3475         AppLog("MainForm::OnFocusLost called");
3476 }
3477
3478 void
3479 MainForm::OnStopClicked(Addressbar& addBar)
3480 {
3481         AppLogDebug("MainForm::OnStopClicked called");
3482         if (__pWebViewer)
3483         {
3484                 //__pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
3485                 SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
3486                 __pWebViewer->StopLoading();
3487                 RequestRedraw(true);
3488         }
3489 }
3490
3491 void
3492 MainForm::OnBackClicked(/*const Addressbar& addBar*/)
3493 {
3494         //      AppLog("MainForm::OnBackClicked");
3495         result r = E_FAILURE;
3496         if(__pImageMenu && __pImageMenu->GetShowState() == true)
3497         {
3498                 AppLog("Hiding the menu");
3499                 __pImageMenu->SetShowState(false);
3500         }
3501
3502         if (__pWebViewer && __pWebViewer->CanGoBack())
3503         {
3504                 __pWebViewer->GoBack();
3505         }
3506         else if(__pWindowInfo && __pWindowInfo->isJavascriptInitiated == false)
3507         {
3508                 UiApp* pApp = null;
3509                 pApp = UiApp::GetInstance();
3510                 if (pApp != null)
3511                 {
3512                         r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
3513                         if (IsFailed(r))
3514                         {
3515                                 AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
3516                                 return;
3517                         }
3518                 }
3519         }
3520         else
3521         {
3522                 UiApp* pApp = null;
3523                 WindowInfo* pWindowInfo = null;
3524                 int totalCount = 0;
3525                 SceneManager* pSceneManager = SceneManager::GetInstance();
3526                 if (pSceneManager == null)
3527                 {
3528                         return;
3529                 }
3530                 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
3531                 if (pAllWindowList == NULL)
3532                 {
3533                         pApp = UiApp::GetInstance();
3534                         if (pApp != null)
3535                         {
3536                                 r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
3537                                 if (IsFailed(r))
3538                                 {
3539                                         AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
3540                                         return;
3541                                 }
3542                         }
3543                 }
3544                 if (pAllWindowList != null)
3545                 {
3546                         totalCount = pAllWindowList->GetCount();
3547                 }
3548                 for (int count = 0; count < totalCount; count++)
3549                 {
3550                         pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count));
3551                         if (pWindowInfo == null)
3552                         {
3553                                 pApp = UiApp::GetInstance();
3554                                 if (pApp != null)
3555                                 {
3556                                         r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
3557                                         if (IsFailed(r))
3558                                         {
3559                                                 AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
3560                                                 return;
3561                                         }
3562                                 }
3563                         }
3564                         if (pSceneManager != null && pWindowInfo != null && pSceneManager->GetCurrentSceneId() == pWindowInfo->sceneID && pWindowInfo->isJavascriptInitiated == true)
3565                         {
3566                                 r = SceneRegister::DestroyAndUnRegisterScene(pWindowInfo->sceneID);
3567                                 if (IsFailed(r))
3568                                 {
3569                                         AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
3570                                         return;
3571                                 }
3572                                 r = pAllWindowList->RemoveAt(count, true);
3573                                 __pWindowInfo = null;
3574                                 if (IsFailed(r))
3575                                 {
3576                                         AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
3577                                         return;
3578                                 }
3579                                 if(count > 0)
3580                                 {
3581                                         pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count - 1));
3582                                 }
3583                                 else if(pAllWindowList->GetCount() > 0)
3584                                 {
3585                                         pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(pAllWindowList->GetCount() - 1));
3586                                 }
3587                                 else
3588                                 {
3589                                         pApp = UiApp::GetInstance();
3590                                         if (pApp != null)
3591                                         {
3592                                                 r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
3593                                                 return;
3594                                         }
3595
3596                                 }
3597                                 if (pWindowInfo == null)
3598                                 {
3599                                         pApp = UiApp::GetInstance();
3600                                         if (pApp != null)
3601                                         {
3602                                                 r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
3603                                                 return;
3604                                         }
3605                                 }
3606                                 else
3607                                 {
3608                                         r = pSceneManager->GoBackward(BackwardSceneTransition(pWindowInfo->sceneID ,SCENE_TRANSITION_ANIMATION_TYPE_NONE));
3609                                         if (IsFailed(r))
3610                                         {
3611                                                 AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
3612                                                 return;
3613                                         }
3614                                 }
3615                                 break;
3616                         }
3617
3618                 }
3619
3620         }
3621
3622 }
3623
3624 void
3625 MainForm::OnForwardClicked(/*const Addressbar& addBar*/)
3626 {
3627         AppLog("MainForm::OnForwardClicked");
3628         if (__pWebViewer == null)
3629                 return;
3630
3631         if (__pWebViewer->CanGoForward())
3632         {
3633                 __pWebViewer->GoForward();
3634         }
3635 }
3636
3637 void
3638 MainForm::OnAddressBarFocusGained(const Addressbar& addBar)
3639 {
3640         AppLog("XYZ::MainForm::OnAddressBarFocusGained");
3641         if(__pFooterPanel != null)
3642         {
3643                 __pFooterPanel->SetShowState(false);
3644         }
3645
3646         if (__pAddressbar != null && __pAddressbar->GetShowState() == false)
3647         {
3648                 __pAddressbar->SetShowState(true);
3649                 __pAddressbar->SetBounds(Rectangle(0,0,GetClientAreaBounds().width,__pAddressbar->GetHeight()));
3650         }
3651
3652         RelayoutControls(false);
3653 }
3654
3655 void
3656 MainForm::OnAddressBarFocusLost(const Addressbar& addBar, bool addressbarKeyPadState)
3657 {
3658         AppLog("XYZ::MainForm::OnAddressBarFocusLost");
3659
3660         int Height = GetClientAreaBounds().height;
3661         AppLog("MainForm::OnAddressBarFocusLost height is %d",Height);
3662
3663         RelayoutControls(false);
3664 }
3665
3666 void
3667 MainForm::OnAddressCancelledClicked(const Addressbar& addBar)
3668 {
3669         AddressBarCancelledClicked(addBar);
3670 }
3671
3672 void
3673 MainForm::OnAddressBarModeChanged(/*const Addressbar& addBar*/)
3674 {
3675         __prevAddressBarMode = __curAddressBarMode;
3676
3677         if (__pAddressbar != null)
3678         {
3679                 __curAddressBarMode = GetAddressbarMode();
3680         }
3681
3682         if (__curAddressBarMode == ADDRESSBAR_MODE_EDIT)
3683         {
3684                 __adressPanelPosition.y = 0;
3685                 if (__pAddressbar != null)
3686                 {
3687                         __webControlPosition.y = __pAddressbar->GetHeight() - 12;
3688                         __pAddressbar->SetBounds(Rectangle(0,0,GetClientAreaBounds().width,__pAddressbar->GetHeight()));
3689                         __pAddressbar->Invalidate(true);
3690                 }
3691                 if (__pWebViewer != null)
3692                 {
3693                         __pWebViewer->StopLoading();
3694                 }
3695         }
3696         else if(__curAddressBarMode == ADDRESSBAR_MODE_LOADING)
3697         {
3698                 __adressPanelPosition.y = 0;
3699                 if (__pAddressbar != null)
3700                 {
3701                         __webControlPosition.y = 0;
3702                         __pAddressbar->SetBounds(Rectangle(0, __pAddressbar->GetY() - __pAddressbar->GetHeight(), GetClientAreaBounds().width, __pAddressbar->GetHeight()));
3703                         __pAddressbar->Invalidate(true);
3704                 }
3705         }
3706 }
3707
3708 void
3709 MainForm::OnClipboardClosed(const Addressbar& addBar)
3710 {
3711         AppLog("XYZ::MainForm::OnClipboardClosed");
3712         if (__pFooterPanel && __pAddressbar->GetShowState() == false)
3713         {
3714                 AppLog("akjshdasd 3");
3715                 __pFooterPanel->SetShowState(true);
3716         }
3717         __isKeypadOpened = false;
3718         RelayoutControls(false);
3719 }
3720
3721 void
3722 MainForm::OnAddressBarKeypadClosed(const Addressbar& addBar, bool footerState)
3723 {
3724         AppLog("XYZ::MainForm::OnAddressBarKeypadClosed");
3725         if (__pFooterPanel && __pAddressbar->GetShowState() == false)
3726         {
3727                 AppLog("akjshdasd 3");
3728                 __pFooterPanel->SetShowState(true);
3729         }
3730         __isKeypadOpened = false;
3731
3732         RelayoutControls(false,footerState);
3733 }
3734
3735 void
3736 MainForm::OnAddressBarKeypadOpened(const Addressbar& addBar)
3737 {
3738         AppLog("XYZ::MainForm::OnAddressBarKeypadOpened");
3739         __isKeypadOpened = true;
3740         RelayoutControls(false);
3741 }
3742
3743 void
3744 MainForm::OnAddressBarKeypadWillOpen(const Addressbar& addBar)
3745 {
3746         __isKeypadOpened = true;
3747         __pFooterPanel->SetShowState(false);
3748 }
3749
3750 void
3751 MainForm::OnAddressBarKeypadBoundsChanged(const Addressbar& addBar)
3752 {
3753         AppLog("XYZ::MainForm::OnAddressBarKeypadBoundsChanged");
3754         RelayoutControls(false);
3755 }
3756
3757 void
3758 MainForm::OnPageTitleReceived(const Tizen::Base::String& title)
3759 {
3760         AppLog("MainForm::OnPageTitleReceived %ls",title.GetPointer());
3761         if (__pWindowInfo)
3762         {
3763                 __pWindowInfo->pageTitle = title;
3764                 if (__pWebViewer != null)
3765                 {
3766                         __pWindowInfo->pageUrl = __pWebViewer->GetUrl();
3767                         AppLog("MainForm::OnPageTitleReceived url %ls",__pWindowInfo->pageUrl.GetPointer());
3768                 }
3769         }
3770         if (__pAddressbar != null && __pWebViewer != null)
3771         {
3772                 SetUrl(__pWebViewer->GetUrl());
3773                 __pAddressbar->Invalidate(true);
3774         }
3775 }
3776
3777 void
3778 MainForm::UpdateFavicon(void)
3779 {
3780         bool urlImageType = false;
3781         String *tempPath = null;
3782         if(__pWebViewer)
3783                 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();");
3784         Bitmap* pBitmap = null;
3785
3786         if (tempPath && tempPath->GetLength() > 0 && tempPath->CompareTo(L"undefined") != 0)
3787         {
3788                 if (__pWindowInfo != null)
3789                 {
3790                         Uri url;
3791                         url.SetUri(*tempPath);
3792                         if (url.GetHost().GetLength() == 0)
3793                         {
3794                                 Uri webUrl;
3795                                 webUrl.SetUri(__pWebViewer->GetUrl());
3796                                 result r = url.SetHost(webUrl.GetHost());
3797                                 if(IsFailed(r))
3798                                 {
3799                                         delete tempPath;
3800                                         return;
3801                                 }
3802                         }
3803                         if (url.GetScheme().GetLength() == 0)
3804                         {
3805                                 Uri webUrl;
3806                                 webUrl.SetUri(__pWebViewer->GetUrl());
3807                                 url.SetScheme(webUrl.GetScheme());
3808                         }
3809                         __pWindowInfo->faviconUrl = url.ToString();
3810
3811                         pBitmap = __pWebViewer->GetFaviconN();
3812
3813                         if (pBitmap != null)
3814                         {
3815                                 if (__pWindowInfo->pFavicon != NULL)
3816                                 {
3817                                         __pWindowInfo->pFavicon = null;
3818                                 }
3819                                 __pWindowInfo->pFavicon = new(std::nothrow) Bitmap();
3820                                 __pWindowInfo->pFavicon->Construct(*pBitmap,Rectangle(0,0,pBitmap->GetWidth(),pBitmap->GetHeight()));
3821
3822                                 __pAddressbar->SetFaviconBitmap(*__pWindowInfo->pFavicon);
3823
3824                                 FaviconManager::GetInstance()->SaveFavicon(*__pWindowInfo->pFavicon, __pWindowInfo->faviconUrl);
3825                         }
3826                         else if(__pWindowInfo->pFavicon != null)
3827                         {
3828                                 __pAddressbar->SetFaviconBitmap(*__pWindowInfo->pFavicon);
3829                         }
3830                         else
3831                         {
3832                                 Bitmap *pDefaultBmp = FaviconManager::GetInstance()->GetDefaultFaviconN();
3833                                 if(pDefaultBmp != null)
3834                                 {
3835                                         __pAddressbar->SetFaviconBitmap(*pDefaultBmp);
3836                                 }
3837                         }
3838                         if(pBitmap)
3839                         {
3840                                 delete pBitmap;
3841                                 pBitmap = null;
3842                         }
3843                 }
3844                 delete tempPath;
3845         }
3846         else
3847         {
3848                 // do not remove
3849                 if(tempPath != null)
3850                 {
3851                         delete tempPath;
3852                 }
3853                 AppLogDebug("Error occured: %s", GetErrorMessage(GetLastResult()));
3854         }
3855
3856 }
3857
3858 bool
3859 MainForm::OnLoadingRequested(const Tizen::Base::String& url,
3860                 Tizen::Web::Controls::WebNavigationType type)
3861 {
3862         AppLog("urlk %ls",url.GetPointer());
3863         // when load new page if find word panel is open its show state is false
3864         if(__pFindWordControl && __pFindWordControl->GetShowState() == true)
3865         {
3866                 __currentSearchStr = L"";
3867                 __currentWordIndex = 0;
3868                 __maxOccurrances = 0;
3869                 __pFindWordEditField->SetText(L"");
3870                 __pFindWordNext->SetEnabled(false);
3871                 __pFindWordPrev->SetEnabled(false);
3872                 __pFindWordCountLabel->SetText(L"0/0");
3873                 __pFindWordControl->SetShowState(false);
3874                 __pFindWordEditField->HideKeypad();
3875                 RelayoutControls(false);
3876         }
3877
3878         __pFooterPanel->Invalidate(true);
3879
3880         Uri uriInfo;
3881         uriInfo.SetUri(url);
3882
3883         if(url.Contains(IDS_TIZEN_SERVICE))
3884         {
3885                 String appId;
3886                 String delim(L":;,");
3887
3888                 // Creates a StringTokenizer instance
3889                 StringTokenizer strTok(url, delim);
3890
3891                 int count = strTok.GetTokenCount();     // count == 4
3892
3893                 HashMap *pMap = new HashMap();
3894                 pMap->Construct();
3895
3896                 String token;
3897                 String key;
3898                 String value;
3899                 while (strTok.HasMoreTokens())
3900                 {
3901                         AppLog("Token: %ls", token.GetPointer());
3902                         strTok.GetNextToken(token);         // Tizen, StringTokenizer, Sample, code
3903                         if(token.Contains(IDS_APPID))
3904                         {
3905                                 token.SubString(6, appId);
3906                                 AppLog("AppID:%ls", appId.GetPointer());
3907                         }
3908                         else if(token.Contains(IDS_KEY))
3909                         {
3910                                 token.SubString(4, key);
3911                                 AppLog("key:%ls", key.GetPointer());
3912                         }
3913                         else if(token.Contains(IDS_VALUE))
3914                         {
3915                                 token.SubString(6, value);
3916                                 AppLog("value:%ls", value.GetPointer());
3917                         }
3918                 }
3919                 pMap->Add(key, value);
3920
3921                 if(appId != "")
3922                 {
3923                         AppControl *pAppControl = null;
3924                         String operationId = L"http://tizen.org/appcontrol/operation/main";
3925                         pAppControl = dynamic_cast<AppControl*>(AppManager::FindAppControlN(appId, operationId));
3926                         if(pAppControl)
3927                         {
3928                                 result r = pAppControl->Start(null, null, pMap, null);
3929                         }
3930                         else
3931                         {
3932                                 AppLogException("AppControl not found");
3933                         }
3934                         return true;
3935                 }
3936         }
3937
3938         return false;
3939 }
3940
3941 DecisionPolicy
3942 MainForm::OnWebDataReceived(const Tizen::Base::String& mime,
3943                 const Tizen::Net::Http::HttpHeader& httpHeader)
3944 {
3945         return Tizen::Web::Controls::WEB_DECISION_CONTINUE;
3946 }
3947
3948 void
3949 MainForm::OnWebPageBlockSelected(Web& source, FloatPoint& startPoint, FloatPoint& endPoint)
3950 {
3951         AppLog("MainForm::OnWebPageBlockSelected");
3952 //      if(__isLongPressedDone == false)
3953 //              return;
3954
3955         if (__pHitElementResult != null)
3956         {
3957                 delete __pHitElementResult;
3958                 __pHitElementResult = null;
3959         }
3960
3961         if (__pWebViewer != null)
3962         {
3963                 AppLog("MainForm::OnWebPageBlockSelected web not null");
3964                 __pHitElementResult = __pWebViewer->GetElementByPointN(startPoint);
3965
3966                 if(GetLastResult() == E_INVALID_ARG || (__pHitElementResult->GetTagName().Equals(L"INPUT",false) == false && __pHitElementResult->GetTagName().Equals(L"TEXTAREA",false) == false))
3967                 {
3968                         AppLog("datafirst startpoint error %s",GetErrorMessage(GetLastResult()));
3969                         __pHitElementResult = __pWebViewer->GetElementByPointN(endPoint);
3970                         if(GetLastResult() == E_INVALID_ARG || (__pHitElementResult->GetTagName().Equals(L"INPUT",false) == false && __pHitElementResult->GetTagName().Equals(L"TEXTAREA",false) == false))
3971                         {
3972                                 __pHitElementResult = __pWebViewer->GetElementByPointN(__longPressPoint);
3973                         }
3974                         AppLog("datafirst endpoint error %s",GetErrorMessage(GetLastResult()));
3975                 }
3976         }
3977
3978         if (__pHitElementResult == null)
3979         {
3980                 return;
3981         }
3982
3983         if (__pHitElementResult->HasImage() != true)
3984         {
3985                 String tagName = __pHitElementResult->GetTagName();
3986                 String type = __pHitElementResult->GetAttributeValue("type");
3987
3988
3989                 AppLog("TagName %ls",tagName.GetPointer());
3990                 __currentSelectedStr.Clear();
3991                 AppLog("__currentSelectedStr after clear %ls",__currentSelectedStr.GetPointer());
3992                 __currentSelectedStr = __pWebViewer->GetTextFromBlock();
3993                 AppLog("__currentSelectedStr after GetTextFromBlock %ls",__currentSelectedStr.GetPointer());
3994                 if(tagName.Equals(L"TEXTAREA",false) == true)
3995                 {
3996                         AppLog("Tagnameseemstobe TEXTAREA");
3997                 }
3998                 else if(tagName.Equals(L"INPUT",false) == true)
3999                 {
4000                         AppLog("Tagnameseemstobe INPUT");
4001                 }
4002
4003                 if (((tagName.Equals(L"INPUT",false) == true)  || tagName.Equals(L"TEXTAREA",false) == true) /*&& __isLongPressedDone == true*/ && __currentSelectedStr.CompareTo(L"") !=0)
4004                 {
4005                         AppLog("MainForm::OnWebPageBlockSelected show paste option");
4006
4007                         InitSelectTextContextMenuF(FloatPoint(endPoint.x,endPoint.y + __pWebViewer->GetY()),true);
4008                         if(__pImageMenu)
4009                         {
4010                                 __pImageMenu->SetShowState(true);
4011                                 __pImageMenu->Show();
4012                                 __pImageMenu->Invalidate(true);
4013                         }
4014                 }
4015                 else /*if(__isLongPressedDone == true)*/
4016                 {
4017                         AppLog("MainForm::OnWebPageBlockSelected no paste option");
4018
4019                         if(__pHitElementResult->GetUrl().GetLength() > 0)
4020                         {
4021                                 __currentSelectedStr.Clear();
4022                                 __currentSelectedStr = __pHitElementResult->GetUrl();
4023                         }
4024                         InitSelectTextContextMenuF(FloatPoint(endPoint.x,endPoint.y + __pWebViewer->GetY()),false);
4025                         if(__pImageMenu)
4026                         {
4027                                 __pImageMenu->SetShowState(true);
4028                                 __pImageMenu->Show();
4029                                 __pImageMenu->Invalidate(true);
4030                         }
4031                 }
4032
4033                 AppLog("MainForm::OnWebPageBlockSelected block text is %ls",__currentSelectedStr.GetPointer());
4034                 AppLog("MainForm::OnWebPageBlockSelected tag name is %ls",tagName.GetPointer());
4035                 AppLog("MainForm::OnWebPageBlockSelected type name is %ls",type.GetPointer());
4036         }
4037
4038 }
4039
4040 void
4041 MainForm::OnWebPageShowRequested(Tizen::Web::Controls::Web& source)
4042 {
4043
4044 }
4045
4046 Web*
4047 MainForm::OnWebWindowCreateRequested(void)
4048 {
4049         AppLog("MainForm::OnWebWindowCreateRequested entered");
4050         WindowInfo* pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewSceneN();
4051
4052         if (pNewWindowInfo == null)
4053         {
4054                 return null;
4055         }
4056         result r = E_SUCCESS;
4057         SceneManager* pSceneManager = SceneManager::GetInstance();
4058         if (pSceneManager == NULL)
4059         {
4060                 return null;
4061         }
4062         ArrayList* pArgList = new(std::nothrow) ArrayList();
4063         if (pArgList == NULL)
4064         {
4065                 return null;
4066         }
4067         r = pArgList->Construct();
4068         if (r == E_SUCCESS)
4069         {
4070                 pNewWindowInfo->isJavascriptInitiated = true;
4071                 pArgList->Add(*pNewWindowInfo);
4072                 r = pSceneManager->GoForward(ForwardSceneTransition(pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
4073                 delete pArgList;
4074                 if (IsFailed(r))
4075                 {
4076                         AppLogDebug("EditHistoryListForm::OnFormBackRequested Failed to GoBackward %s",GetErrorMessage(r));
4077                         return null;
4078                 }
4079         } else {
4080                 delete pArgList;
4081         }
4082
4083         return pNewWindowInfo->pCurrentWeb;
4084 }
4085
4086 void
4087 MainForm::RelayoutControls(bool showAddressbar,bool relayoutFooter)
4088 {
4089         AppLog("xyz:: MainForm::RelayoutControls called");
4090         __webControlPosition.y = 0;
4091         __webControlHeight = GetClientAreaBounds().height;
4092         AppLog("Client area height: %d", __webControlHeight);
4093
4094         AppLog("Client area height: %d", __webControlHeight);
4095         if(__pAddressbar != null && __pAddressbar->GetShowState() == true)
4096         {
4097                 __webControlPosition.y += __pAddressbar->GetHeight();
4098                 __webControlHeight -= __pAddressbar->GetHeight();
4099                 __pAddressbar->SetBounds(0, 0, __pAddressbar->GetWidth(), __pAddressbar->GetHeight());
4100         }
4101         else if(__pFindWordControl != null && __pFindWordControl->GetShowState() == true)
4102         {
4103                 __webControlPosition.y += __pFindWordControl->GetHeight();
4104                 __webControlHeight -= __pFindWordControl->GetHeight();
4105                 __pFindWordControl->SetBounds(0, 0, GetClientAreaBounds().width, __pFindWordControl->GetHeight());
4106         }
4107
4108         if(__pFooterPanel != null && __pFooterPanel->GetShowState() == true && relayoutFooter == true)
4109         {
4110                 __webControlHeight -= __pFooterPanel->GetHeight();
4111
4112                 __pFooterPanel->SetBounds(0, __webControlPosition.y + __webControlHeight, GetClientAreaBounds().width, __pFooterPanel->GetHeight());
4113                 __webControlHeight = __webControlHeight + 12;
4114         }
4115         if (__pWebViewer != null && __pWebViewer->GetShowState() == true)
4116         {
4117                 if(__pWebViewer->GetX() == 0 && __pWebViewer->GetY() == __webControlPosition.y &&__pWebViewer->GetWidth() == GetClientAreaBounds().width &&__pWebViewer->GetHeight() == __webControlHeight )
4118                 {
4119                 }
4120                 else
4121                 {
4122                         __pWebViewer->SetBounds(0, __webControlPosition.y, GetClientAreaBounds().width, __webControlHeight );
4123                         AppLog("xyz:: MainForm::RelayoutControls called __webControlHeight %d",__webControlHeight);
4124                         __pWebViewer->Invalidate(false);
4125                 }
4126         }
4127         if(__pMostVisitedListView != null && __pAddressbar != null && __pFooterPanel != null)
4128         {
4129                 __pMostVisitedListView->SetBounds(Tizen::Graphics::Rectangle(0,__webControlPosition.y , GetClientAreaBounds().width, __webControlHeight));
4130         }
4131
4132         Invalidate(true);
4133 }
4134
4135 void
4136 MainForm::ShowFindWordPanel(bool show , bool isTouchPressed)
4137 {
4138         if (__pFindWordControl == null)
4139         {
4140                 return;
4141         }
4142
4143         Tizen::Locales::LocaleManager localeManager;
4144         Tizen::Locales::Locale local = localeManager.GetSystemLocale();
4145
4146         String languageCode;
4147         result r = SettingInfo::GetValue(L"Language", languageCode);
4148         // int languagecode = local.GetLanguageCode();
4149         AppLog("rahul language is %S", languageCode.GetPointer());
4150
4151         if (show == true)
4152         {
4153                 InitFindWordPanel();
4154
4155                 if (languageCode.CompareTo("ara") == 0)
4156                 {
4157                         AppLog("rahul language is arabic");
4158
4159                         __pFindWordPanelLeftToRight->SetShowState(false);
4160                         __pFindWordPanelRightToLeft->SetShowState(true);
4161
4162                         __pFindWordClear->SetShowState(false);
4163                         __pFindWordCountLabel->SetShowState(false);
4164                         __pFindWordEditField->SetShowState(false);
4165
4166                         __pFindWordClearRightToLeft->SetShowState(true);
4167                         __pFindWordCountLabelRightToLeft->SetShowState(true);
4168                         __pFindWordEditFieldRightToLeft->SetShowState(true);
4169                 }
4170                 else
4171                 {
4172                         AppLog("rahul language is not arabic");
4173
4174
4175                         __pFindWordPanelLeftToRight->SetShowState(true);
4176                         __pFindWordPanelRightToLeft->SetShowState(false);
4177
4178                         __pFindWordClear->SetShowState(true);
4179                         __pFindWordCountLabel->SetShowState(true);
4180                         __pFindWordEditField->SetShowState(true);
4181
4182                         __pFindWordClearRightToLeft->SetShowState(false);
4183                         __pFindWordCountLabelRightToLeft->SetShowState(false);
4184                         __pFindWordEditFieldRightToLeft->SetShowState(false);
4185                 }
4186                 __pFindWordControl->SetShowState(true);
4187         }
4188         else
4189         {
4190                 if(__pFindWordControl != null)
4191                 {
4192                         __pFindWordControl->SetShowState(false);
4193                 }
4194         }
4195
4196         AppLog("MainForm::ShowFindWordPanel %d",show);
4197         if (show && !isTouchPressed)
4198         {
4199                 if (languageCode.CompareTo("ara") == 0)
4200                 {
4201                         if (__pFindWordEditFieldRightToLeft)
4202                         {
4203                                 __pFindWordEditFieldRightToLeft->SetFocus();
4204                                 __pFindWordEditFieldRightToLeft->ShowKeypad();
4205                         }
4206                 }
4207                 else
4208                 {
4209                         if (__pFindWordEditField)
4210                         {
4211                                 __pFindWordEditField->SetFocus();
4212                                 __pFindWordEditField->ShowKeypad();
4213                         }
4214                 }
4215         }
4216         else
4217         {
4218                 if (languageCode.CompareTo("ara") == 0)
4219                 {
4220                         if (__pFindWordEditFieldRightToLeft)
4221                                 __pFindWordEditFieldRightToLeft->HideKeypad();
4222                 }
4223                 else
4224                 {
4225                         if (__pFindWordEditField)
4226                                 __pFindWordEditField->HideKeypad();
4227                 }
4228         }
4229
4230         RelayoutControls(false);
4231 }
4232
4233 void
4234 MainForm::StartWordSearch()
4235 {
4236         //Get the count of occurances of the word in the current page
4237         __maxOccurrances = 0;
4238         __currentWordIndex = 0;
4239
4240         __pFindWordPrev->SetEnabled(false);
4241         String *pCountStr = null;
4242         result r = __pWebViewer->SearchTextAllAsync(__currentSearchStr, false);
4243         AppLog("Search Result %s",GetErrorMessage(r));
4244         /*__pWebViewer->EvaluateJavascriptN(L"document.body.textContent.match(/"  + __currentSearchStr + "/gi).length;");
4245         if (pCountStr != null)
4246         {
4247                 Integer::Parse(*pCountStr, 10, __maxOccurrances);
4248                 delete pCountStr;
4249         }
4250
4251         AppLogDebug("'%ls' is found %d times", __currentSearchStr.GetPointer(), __maxOccurrances);
4252          */
4253
4254 }
4255
4256 void MainForm::OnTextFound(int totalCount, int currentOrdinal)
4257 {
4258         AppLog("MainForm::OnTextFound totalCount %d",totalCount);
4259         AppLog("MainForm::OnTextFound currentOrdinal %d",currentOrdinal);
4260
4261         if(totalCount == -1 || totalCount == 0)
4262         {
4263                 __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),84,__pFindWordCountLabel->GetHeight());
4264                 __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),214+80,__pFindWordEditField->GetHeight());
4265 //              return;
4266         }
4267         else if(totalCount > 100)
4268         {
4269                 __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),124,__pFindWordCountLabel->GetHeight());
4270                 __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),174,__pFindWordEditField->GetHeight());
4271         }
4272         else
4273         {
4274                 __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),124,__pFindWordCountLabel->GetHeight());
4275                 __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),174,__pFindWordEditField->GetHeight());
4276         }
4277
4278         __maxOccurrances = totalCount;
4279         __currentWordIndex = currentOrdinal;
4280
4281         //Reset the UI controls as per the maxOccurrance value
4282         if (totalCount <= 0)
4283         {
4284                 AppLog("Word not found");
4285                 //Show error notification to user
4286                 __pFindWordNext->SetEnabled(false);
4287                 if(__pFindWordCountLabel && __pFindWordCountLabel->GetShowState() == true)
4288                 {
4289                         __pFindWordCountLabel->SetText(L"0/0");
4290                         __pFindWordCountLabel->Invalidate(false);
4291                 }
4292                 else if(__pFindWordCountLabelRightToLeft && __pFindWordCountLabelRightToLeft->GetShowState() == true)
4293                 {
4294                         __pFindWordCountLabelRightToLeft->SetText(L"0/0");
4295                         __pFindWordCountLabelRightToLeft->Invalidate(false);
4296                 }
4297                 __pFindWordNext->Invalidate(false);
4298                 __pFindWordPrev->Invalidate(false);
4299
4300                 return;
4301         }
4302
4303         if (totalCount == 1 || totalCount == currentOrdinal)
4304         {
4305                 __pFindWordNext->SetEnabled(false);
4306         }
4307         else
4308         {
4309                 __pFindWordNext->SetEnabled(true);
4310         }
4311
4312         String countStr = L"";
4313         countStr.Append(__currentWordIndex);
4314         countStr.Append(L"/");
4315         countStr.Append(__maxOccurrances);
4316         if (__pFindWordCountLabel && __pFindWordCountLabel->GetShowState() == true)
4317         {
4318         __pFindWordCountLabel->SetText(countStr);
4319         __pFindWordCountLabel->Invalidate(false);
4320         __pFindWordCountLabel->Invalidate(false);
4321         }
4322         else if(__pFindWordCountLabelRightToLeft && __pFindWordCountLabelRightToLeft->GetShowState() == true)
4323         {
4324                 __pFindWordCountLabelRightToLeft->SetText(countStr);
4325                 __pFindWordCountLabelRightToLeft->Invalidate(false);
4326                 __pFindWordCountLabelRightToLeft->Invalidate(false);
4327         }
4328         //FindNextWord(true);
4329         //Update the controls
4330         __pFindWordNext->Invalidate(false);
4331         __pFindWordPrev->Invalidate(false);
4332
4333 }
4334
4335 void
4336 MainForm::FindNextWord(bool next)
4337 {
4338         if (next == true)
4339         {
4340                 //if (__pWebViewer->SearchText(__currentSearchStr, true) == true)
4341                         if (__pWebViewer->SearchNextAsync(true) == E_SUCCESS)
4342                         {
4343                                 if (__currentWordIndex < __maxOccurrances)
4344                                 {
4345                                         __currentWordIndex++;
4346                                 }
4347                         }
4348         }
4349         else
4350         {
4351                 //if (__pWebViewer->SearchText(__currentSearchStr, false) == true)
4352                 if (__pWebViewer->SearchNextAsync(false) == E_SUCCESS)
4353                 {
4354                         if(__currentWordIndex > 1)
4355                         {
4356                                 __currentWordIndex--;
4357                         }
4358                 }
4359         }
4360
4361         String countStr = L"";
4362         countStr.Append(__currentWordIndex);
4363         countStr.Append(L"/");
4364         countStr.Append(__maxOccurrances);
4365
4366         if (__pFindWordCountLabel && __pFindWordCountLabel->GetShowState() == true)
4367         {
4368         __pFindWordCountLabel->SetText(countStr);
4369         __pFindWordCountLabel->Invalidate(false);
4370         }
4371         else if(__pFindWordCountLabelRightToLeft && __pFindWordCountLabelRightToLeft->GetShowState() == true)
4372         {
4373                 __pFindWordCountLabelRightToLeft->SetText(countStr);
4374                 __pFindWordCountLabelRightToLeft->Invalidate(false);
4375         }
4376
4377         if (__currentWordIndex >= __maxOccurrances)
4378         {
4379                 __pFindWordNext->SetEnabled(false);
4380         }
4381         else
4382         {
4383                 __pFindWordNext->SetEnabled(true);
4384         }
4385         if (__currentWordIndex <= 1)
4386         {
4387                 __pFindWordPrev->SetEnabled(false);
4388         }
4389         else
4390         {
4391                 __pFindWordPrev->SetEnabled(true);
4392         }
4393         __pFindWordPrev->Invalidate(false);
4394         __pFindWordNext->Invalidate(false);
4395
4396         __pFindWordControl->Invalidate(true);
4397 }
4398
4399 void
4400 MainForm::OnWebKeypadWillOpen(Tizen::Web::Controls::Web& source)
4401 {
4402         AppLog("xyz::MainForm::OnWebKeypadWillOpen");
4403         __isKeypadOpened = true;
4404         __pFooterPanel->SetShowState(false);
4405         //      OnAddressBarKeypadOpened(*__pAddressbar);
4406 }
4407
4408 void
4409 MainForm::OnWebKeypadOpened(Tizen::Web::Controls::Web& source)
4410 {
4411         __isKeypadOpened = true;
4412         AppLog("xyz::MainForm::OnWebKeypadOpened");
4413
4414         if(__pFindWordControl && __pFindWordControl->GetShowState() == true)
4415         {
4416                 __currentSearchStr = L"";
4417                 __currentWordIndex = 0;
4418                 __maxOccurrances = 0;
4419                 __pFindWordEditField->SetText(L"");
4420                 __pFindWordNext->SetEnabled(false);
4421                 __pFindWordPrev->SetEnabled(false);
4422                 __pFindWordCountLabel->SetText(L"0/0");
4423                 __pWebViewer->SearchTextAllAsync(L"",false);
4424                 __pFindWordControl->SetShowState(false);
4425                 __pFindWordEditField->HideKeypad();
4426         }
4427
4428
4429         if (__pWebViewer != null && __pFooterPanel != null)
4430         {
4431                 AppLog("MainForm::OnWebKeypadOpened GetClientAreaBounds().height %d ", GetClientAreaBounds().height);
4432                 if(__pAddressbar != null)
4433                 {
4434                         __pAddressbar->SetShowState(false);
4435                 }
4436                 if(__pFindWordControl != null)
4437                 {
4438                         __pFindWordControl->SetShowState(false);
4439                 }
4440                 __pFooterPanel->SetShowState(false);
4441                 __pWebViewer->SetBounds(Rectangle(0, 0,GetClientAreaBounds().width, GetClientAreaBounds().height));
4442         }
4443 //      if(__pImageMenu && __pImageMenu->GetShowState() == true)
4444 //      {
4445 //              __pImageMenu->SetAnchorPosition(Point(__pImageMenu->GetAnchorPosition().x/2,__pImageMenu->GetAnchorPosition().y/2));
4446 //              AppLog("omgomgomg");
4447 //      }
4448         Invalidate(true);
4449 }
4450
4451 void
4452 MainForm::OnWebKeypadClosed(Tizen::Web::Controls::Web& source)
4453 {
4454         AppLog("xyz::MainForm::OnWebKeypadClosed");
4455         AppLog("akjshdasd 4");
4456         __pFooterPanel->SetShowState(true);
4457 //      OnAddressBarKeypadClosed(*__pAddressbar);
4458         RelayoutControls(false);
4459         __isKeypadOpened = false;
4460 }
4461
4462 void
4463 MainForm::OnWebKeypadBoundsChanged(Tizen::Web::Controls::Web& source)
4464 {
4465         //      RelativeLayout(false);
4466         if(__pWebViewer != null)
4467         {
4468                 __pWebViewer->SetBounds(Rectangle(0,__webControlPosition.y,GetClientAreaBounds().width,GetClientAreaBounds().height));
4469         }
4470 }
4471
4472 void
4473 MainForm::OnTouchDoublePressed(const Control& source, const Point& currentPosition, const TouchEventInfo& touchInfo)
4474 {
4475         Control* temp = const_cast< Control* >(&source);
4476         Header* pHeader = dynamic_cast< Header* >(temp);
4477         if (pHeader != null)
4478         {
4479                 //Header double - clicked
4480                 AppLog("Header double clicked");
4481         }
4482         if(__pFindWordControl)
4483         {
4484                 AppLog("MainForm::OnTouchPressed %d",__pFindWordControl->GetShowState());
4485                 ShowFindWordPanel(__pFindWordControl->GetShowState(), true);
4486         }
4487
4488
4489         AppLog("MainScene::OnTouchDoublePressed");
4490
4491 }
4492
4493 void MainForm::OnTouchLongPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
4494 {
4495         AppLog("abcde::MainForm::OnTouchLongPressed %d, %d" ,currentPosition.x,currentPosition.y);
4496         if(TouchEventManager::GetInstance()->GetTouchInfoListN()->GetCount() >1)
4497         {
4498                 AppLog("Returning because of more than one touch point.");
4499                 return;
4500         }
4501         __longPressPoint = currentPosition;
4502
4503         if (__pHitElementResult != null)
4504         {
4505                 delete __pHitElementResult;
4506                 __pHitElementResult = null;
4507         }
4508
4509         if (__pWebViewer != null)
4510         {
4511                 AppLog("MainForm::OnTouchLongPressed web not null");
4512                 __pHitElementResult = __pWebViewer->GetElementByPointN(currentPosition);
4513         }
4514
4515         if (__pHitElementResult == null)
4516         {
4517                 return;
4518         }
4519
4520         if (__pHitElementResult->HasImage() == true)
4521         {
4522                 if(__pWebViewer != null)
4523                         InitImageContextMenu(Point(currentPosition.x,currentPosition.y + __pWebViewer->GetY()));
4524                 __pImageMenu->SetShowState(true);
4525                 __pImageMenu->Show();
4526                 __pImageMenu->Invalidate(true);
4527         }
4528         else if(__pHitElementResult->HasUrl() == true)
4529         {
4530                 String tempURl = __pHitElementResult->GetUrl();
4531                 AppLog("tempURl is %ls", tempURl.GetPointer());
4532                 const Bitmap* pBitmap = __pHitElementResult->GetImage();
4533                 if (pBitmap != null)
4534                 {
4535                         AppLog("not null");
4536                 }
4537                 else
4538                 {
4539                         AppLog(null);
4540                 }
4541                 InitImageLinkContextMenu(Point(currentPosition.x,currentPosition.y + __pWebViewer->GetY()));
4542                 __pImageMenu->SetShowState(true);
4543                 __pImageMenu->Show();
4544                 __pImageMenu->Invalidate(true);
4545         }
4546         else
4547         {
4548                 String tagName = __pHitElementResult->GetTagName();
4549                 String type = __pHitElementResult->GetAttributeValue("type");
4550                 String value = __pHitElementResult->GetAttributeValue(L"value");
4551                 String innerHtml = __pHitElementResult->GetAttributeValue(L"innerHTML");
4552
4553                 __currentSelectedStr.Clear();
4554                 __currentSelectedStr = __pWebViewer->GetTextFromBlock();
4555
4556                 AppLog("tag name is %ls", tagName.GetPointer());
4557                 AppLog("type is %ls", type.GetPointer());
4558
4559
4560
4561                 __isLongPressedDone = true;
4562                 result r =__pWebViewer->SetBlockSelectionPosition(currentPosition);
4563                 if (((tagName.Equals(L"INPUT",false) == true)  || tagName.Equals(L"TEXTAREA",false) == true) && innerHtml.GetLength() == 0  && type.Equals(L"submit",false) !=true && type.Equals(L"range",false) !=true/*&& __isWebKeypadOpened == true*/ && __currentSelectedStr.Equals(L"",false) == true && r == E_INVALID_ARG)
4564                 {
4565                         AppLog("MainForm::OnWebPageBlockSelected show paste option");
4566
4567                         InitSelectTextContextMenu(Point(currentPosition.x , currentPosition.y + __pWebViewer->GetY()),true, true);
4568                         if(__pImageMenu)
4569                         {
4570                                 __pImageMenu->SetShowState(true);
4571                                 __pImageMenu->Show();
4572                                 __pImageMenu->Invalidate(true);
4573                         }
4574                 }
4575                 AppLog("setselectionselectedornot %s",GetErrorMessage(r));
4576
4577         }
4578 //      __inputEventToBeSupressed = true;
4579 }
4580
4581 void
4582 MainForm::OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
4583 {
4584         AppLog("xyz:: MainForm::OnTouchReleased called");
4585
4586         if (__pAddressbar && __pAddressbar->GetShowState() == true)
4587         {
4588                 __pAddressbar->SetShowState(false);
4589         }
4590         if(__pFooterPanel && __isKeypadOpened == false)
4591         {
4592                 __pFooterPanel->SetShowState(true);
4593         }
4594
4595         // Not reuired now.
4596         /*HitElementResult* pHitElement = __pWebViewer->GetElementByPointN(currentPosition);
4597         if(pHitElement != null && pHitElement->HasUrl() == true && __inputEventToBeSupressed == true)
4598         {
4599                 __pWebViewer->ConsumeInputEvent();
4600         }
4601         if(pHitElement != null)
4602         {
4603                 delete pHitElement;
4604         }
4605         __inputEventToBeSupressed = false;*/
4606 }
4607
4608 bool
4609 MainForm::OnTouchPressed(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4610 {
4611
4612         return true;
4613 }
4614
4615 bool
4616 MainForm::OnTouchReleased(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4617 {
4618         if(__pFindWordControl && __pFindWordControl->GetShowState() == true)
4619         {
4620                 __currentSearchStr = L"";
4621                 __currentWordIndex = 0;
4622                 __maxOccurrances = 0;
4623
4624                 if (__pFindWordPanelLeftToRight && __pFindWordPanelLeftToRight->GetShowState() == true)
4625                 {
4626                         __pFindWordEditField->SetText(L"");
4627                         __pFindWordEditField->HideKeypad();
4628                         __pFindWordControl->SetShowState(false);
4629                         __pFindWordCountLabel->SetText(L"0/0");
4630                 }
4631                 else if(__pFindWordPanelRightToLeft && __pFindWordPanelRightToLeft->GetShowState() == true)
4632                 {
4633                         __pFindWordEditFieldRightToLeft->SetText(L"");
4634                         __pFindWordEditFieldRightToLeft->HideKeypad();
4635                         __pFindWordControl->SetShowState(false);
4636                         __pFindWordCountLabelRightToLeft->SetText(L"0/0");
4637                 }
4638
4639                 __pFindWordNext->SetEnabled(false);
4640                 __pFindWordPrev->SetEnabled(false);
4641
4642                 __pWebViewer->SearchTextAllAsync(L"",true);
4643                 __pFindWordControl->SetShowState(false);
4644         }
4645         AppLog("__pAddressbar->GetShowState() %d",__pAddressbar->GetShowState());
4646         if(__pAddressbar->GetShowState() == false)
4647         {
4648                 __pAddressbar->SetAddressbarURLFocus();
4649                 __pFooterPanel->SetShowState(false);
4650         }
4651
4652         return false;
4653 }
4654
4655 bool
4656 MainForm::OnTouchMoved(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4657 {
4658         return true;
4659 }
4660
4661 bool
4662 MainForm::OnTouchCanceled(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4663 {
4664         return true;
4665 }
4666
4667 bool
4668 MainForm::OnPreviewTouchPressed(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4669 {
4670         return true;
4671 }
4672
4673 bool
4674 MainForm::OnPreviewTouchReleased(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4675 {
4676         return true;
4677 }
4678
4679 bool
4680 MainForm::OnPreviewTouchMoved(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4681 {
4682         return true;
4683 }
4684
4685 void
4686 MainForm::OnOrientationChanged (const Tizen::Ui::Control &source, Tizen::Ui::OrientationStatus orientationStatus)
4687 {
4688         AppLog("MainForm::OnOrientationChanged GetClientAreaBounds %d, %d",GetClientAreaBounds().width,GetClientAreaBounds().height);
4689         int widthContextItem = 0;
4690         if(__pFindWordCountLabel)
4691                 __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),124,__pFindWordCountLabel->GetHeight());
4692         // As per the platform engineer comment removed this line
4693         /*if(__pWebViewer != null)
4694         {
4695                 // this is added because if any text is selected on long press followed by on rotation we are hiding the context menu therefore we should release the text block also
4696                 __pWebViewer->ReleaseBlock();
4697         }*/
4698
4699 //      if(__pFindWordControl != null)
4700 //              ShowFindWordPanel(__pFindWordControl->GetShowState(), false);
4701
4702         if(__pOptionMenu && __pOptionMenu->GetShowState() == true)
4703         {
4704                 if( GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
4705                 {
4706                         AppLog(" Orientation landscape");
4707                         __pOptionMenu->SetMaxVisibleItemsCount(5);
4708                 }
4709                 else
4710                 {
4711                         AppLog(" Orientation potrait");
4712                         __pOptionMenu->SetMaxVisibleItemsCount(6);
4713                 }
4714         }
4715         if(__pNotification && __pNotification->GetShowState() == true)
4716         {
4717                 __pNotification->SetShowState(false);
4718                 __pNotification->Invalidate(false);
4719         }
4720         if ( __pFooterLabel != null)
4721         {
4722                 Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_SEARCH_INPUT_FIELD_BG, __pFooterLabel->GetWidth(), __pFooterLabel->GetHeight());
4723                 if(pBitmap != null)
4724                 {
4725                         __pFooterLabel->SetBackgroundBitmap(*pBitmap);
4726                         delete pBitmap;
4727                 }
4728
4729
4730         }
4731         if (__pFindWordBgLabel != null)
4732         {
4733                 Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_FINDWORD_INPUT_FIELD_BG, __pFindWordBgLabel->GetWidth(), __pFindWordBgLabel->GetHeight());
4734                 if (pBitmap != null)
4735                 {
4736                         __pFindWordBgLabel->SetBackgroundBitmap(*pBitmap);
4737                         delete pBitmap;
4738                 }
4739         }
4740
4741         if (__pFindWordBgLabelRightToLeft != null)
4742         {
4743                 Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_FINDWORD_INPUT_FIELD_BG, __pFindWordBgLabelRightToLeft->GetWidth(), __pFindWordBgLabelRightToLeft->GetHeight());
4744                 if (pBitmap != null)
4745                 {
4746                         __pFindWordBgLabelRightToLeft->SetBackgroundBitmap(*pBitmap);
4747                         delete pBitmap;
4748                 }
4749         }
4750
4751
4752 //      if(__pOptionMenu != null)
4753 //              __pOptionMenu->SetShowState(false);
4754
4755         if( GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
4756         {
4757                 widthContextItem = WIDTH_CONTEXT_MENU_BUTTON_LANDSCAPE;
4758         }
4759         else
4760         {
4761                 widthContextItem = WIDTH_CONTEXT_MENU_BUTTON_PORTRAIT;
4762         }
4763
4764         if (__pFooterPanel)
4765         {
4766                 AppLog("__pFooterPanel->GetShowState() is true");
4767                 InitFooter();
4768                 __pFooterPanel->SetBounds(0, GetClientAreaBounds().height - __pFooterPanel->GetHeight(), __pFooterPanel->GetWidth(), __pFooterPanel->GetHeight());
4769                 __pFooterPanel->Invalidate(true);
4770         }
4771         InitAddressbar();
4772
4773         String homePage = SettingPresentationModel::GetInstance()->GetHomepage();
4774         if (homePage.CompareTo((L"IDS_BR_BODY_MOST_VISITED_SITES")) == 0)
4775         {
4776                 InitMostVisitedSitesView(orientationStatus);
4777         }
4778
4779         RelayoutControls(false);
4780         if (__pArticleReaderPanel != null)
4781         {
4782                 if (__pArticleReaderPanel->GetShowState() == true)
4783                 {
4784                         __pArticleReaderPanel->SetBounds((GetClientAreaBounds().width - __pArticleReaderPanel->GetWidth())/2,(GetClientAreaBounds().height - __pArticleReaderPanel->GetHeight())/2, __pArticleReaderPanel->GetWidth(), __pArticleReaderPanel->GetHeight());
4785
4786                         if (__pBlankPanel != null)
4787                                 __pBlankPanel->SetBounds(0,0,GetClientAreaBounds().width,GetClientAreaBounds().height);
4788
4789                         if (__pWebReader != null)
4790                         {
4791                                 __pWebReader->SetBounds(Rectangle(2,2, __pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight() - 96));
4792                         }
4793                         Bitmap* pBitmap = CommonUtil::GetNinepatchedBitmapN(L"I01_popup_bg.9.png",__pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight());
4794                         Bitmap* pSrcBitmap = CommonUtil::GetNinepatchedBitmapN(L"I01_popup_bottom_bg.9.png",__pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight());
4795
4796                         if ( pBitmap != null && pSrcBitmap != null)
4797                         {
4798                                 AppLog("CreateReaderPanel ninepatchbitmap found");
4799                                 pBitmap->Merge(Point(0,__pArticleReaderPanel->GetHeight() - 96),*pSrcBitmap,Rectangle(0,0,pSrcBitmap->GetWidth(),pSrcBitmap->GetHeight()));
4800                         }
4801
4802                         __pArticleReaderLabel->SetBounds(Rectangle(__pArticleReaderPanel->GetX(),__pArticleReaderPanel->GetY(),__pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight()));
4803                         __pArticleReaderLabel->SetBackgroundBitmap(*pBitmap);
4804                         if (pBitmap != null)
4805                         {
4806                                 delete pBitmap;
4807                                 pBitmap = null;
4808                         }
4809                         if (pSrcBitmap != null)
4810                         {
4811                                 delete pSrcBitmap;
4812                                 pSrcBitmap = null;
4813                         }
4814                 }
4815         }
4816         Invalidate(true);
4817         
4818     if (__pAddressbar != null)
4819         {
4820                 int width = GetClientAreaBounds().width;
4821                 __pAddressbar->OrientationChanged(width);
4822         }
4823 }
4824
4825 void
4826 MainForm::OnSettingsChange(int settingvalue)
4827 {
4828         AppLogDebug("MainForm::OnSettingsChange entered");
4829
4830         if(settingvalue == (int)REGISTRY_SETTING_HOMEPAGE)
4831         {
4832                 __pAddressbar->ResetGuideText();
4833         }
4834         if (__pWebViewer == null)
4835         {
4836                 AppLogDebug("Webviewer is not initialized yet.");
4837                 return;
4838         }
4839
4840         if (settingvalue == (int) REGISTRY_SETTING_DEFAULT_VIEW)
4841         {
4842                 WebSetting settings = __pWebViewer->GetSetting();
4843                 if (SettingPresentationModel::GetInstance()->GetDefaultView().CompareTo((L"IDS_BR_BODY_FIT_TO_WIDTH")) == 0)
4844                 {
4845                         settings.SetAutoFittingEnabled(true);
4846                 }
4847                 else if (SettingPresentationModel::GetInstance()->GetDefaultView().CompareTo((L"IDS_BR_BODY_READABLE")) == 0)
4848                 {
4849                         settings.SetAutoFittingEnabled(false);
4850                 }
4851                 __pWebViewer->SetSetting(settings);
4852         }
4853         else if (settingvalue == (int) REGISTRY_SETTING_RUN_JAVASCRIPT)
4854         {
4855                 WebSetting settings = __pWebViewer->GetSetting();
4856                 settings.SetJavascriptEnabled(SettingPresentationModel::GetInstance()->IsRunJavascriptEnabled());
4857                 __pWebViewer->SetSetting(settings);
4858         }
4859         else if (settingvalue == (int) REGISTRY_SETTING_DISPLAY_IMAGES)
4860         {
4861                 WebSetting settings = __pWebViewer->GetSetting();
4862                 settings.SetAutoImageLoadEnabled(SettingPresentationModel::GetInstance()->IsDisplayImagesEnabled());
4863                 __pWebViewer->SetSetting(settings);
4864                 __pWebViewer->Reload();
4865         }
4866         else if (settingvalue == (int) REGISTRY_SETTING_BLOCK_POPUP)
4867         {
4868                 WebSetting settings = __pWebViewer->GetSetting();
4869                 settings.SetJavaScriptPopupEnabled(SettingPresentationModel::GetInstance()->IsBlockPopUp());
4870                 __pWebViewer->SetSetting(settings);
4871         }
4872         else if (settingvalue == (int) REGISTRY_SETTING_ACCEPT_COOKIES)
4873         {
4874                 if (__pWebViewer)
4875                 {
4876                         __pWebViewer->SetCookieEnabled(SettingPresentationModel::GetInstance()->IsCookiesEnabled());
4877                 }
4878         }
4879         else if(settingvalue == (int) REGISTRY_SETTING_REMEMBER_FORM_DATA)
4880         {
4881                 if (__pWebViewer)
4882                 {
4883                         WebSetting settings = __pWebViewer->GetSetting();
4884                         settings.SetAutoFormDataShowEnabled(SettingPresentationModel::GetInstance()->IsRememberFormData());
4885                         __pWebViewer->SetSetting(settings);
4886                 }
4887         }
4888         else if(settingvalue == (int) REGISTRY_SETTING_REMEMBER_PASSWORD)
4889         {
4890                 if (__pWebViewer)
4891                 {
4892                         WebSetting settings = __pWebViewer->GetSetting();
4893                         settings.SetAutoLoginFormFillEnabled(SettingPresentationModel::GetInstance()->IsRememberPassword());
4894                         __pWebViewer->SetSetting(settings);
4895                 }
4896         }
4897         else if (settingvalue == (int) REGISTRY_SETTING_SHOW_SECURITY_WARNINGS)
4898         {
4899                 WebSetting settings = __pWebViewer->GetSetting();
4900                 if (SettingPresentationModel::GetInstance()->IsSecurityWarningsEnabled() == true)
4901                 {
4902                         settings.SetCertificateErrorHandlingMode(WEB_CERTIFICATE_ERROR_HANDLING_MODE_USER_CONFIRM);
4903                 }
4904                 else
4905                 {
4906                         settings.SetCertificateErrorHandlingMode(WEB_CERTIFICATE_ERROR_HANDLING_MODE_CONTINUE);
4907                 }
4908                 __pWebViewer->SetSetting(settings);
4909         }
4910         else if (settingvalue == (int) REGISTRY_SETTING_READER_FONT_SIZE)
4911         {
4912                 if (__pWebReader)
4913                 {
4914                         AppLogDebug("IntMainForm fontsize Changed to %d",SettingPresentationModel::GetInstance()->GetReaderFontSize());
4915                         WebSetting settings = __pWebReader->GetSetting();
4916                         settings.SetFontSize(SettingPresentationModel::GetInstance()->GetReaderFontSize());
4917                         __pWebReader->SetSetting(settings);
4918                 }
4919         }
4920 }
4921
4922 void
4923 MainForm::OnSettingsReset()
4924 {
4925         if (__pWebViewer)
4926         {
4927                 __pWebViewer->SetCookieEnabled(SettingPresentationModel::GetInstance()->IsCookiesEnabled());
4928                 __pWebViewer->SetSetting(SettingPresentationModel::GetInstance()->GetWebSettings());
4929         }
4930 }
4931
4932 void
4933 MainForm::OnClearCache()
4934 {
4935         result r = E_SUCCESS;
4936
4937         if (__pWebViewer != NULL)
4938         {
4939                 r = __pWebViewer->ClearCache();
4940                 if (r == E_SUCCESS)
4941                 {
4942                         AppLogDebug("Cache cleared success");
4943                 }
4944                 else
4945                 {
4946                         AppLogDebug("Cache cleared fail");
4947                 }
4948         }
4949 }
4950
4951 void
4952 MainForm::OnClearCookie()
4953 {
4954         result r = E_SUCCESS;
4955
4956         if (__pWebViewer != NULL)
4957         {
4958                 __pWebViewer->ClearCookie();
4959         }
4960         if (r == E_SUCCESS)
4961         {
4962                 AppLogDebug("Cookie cleared success");
4963         }
4964         else
4965         {
4966                 AppLogDebug("Cache cleared fail");
4967         }
4968 }
4969
4970 void
4971 MainForm::OnClearFormData()
4972 {
4973         result r = E_SUCCESS;
4974
4975         if (__pWebViewer != NULL)
4976         {
4977                 __pWebViewer->ClearFormData();
4978         }
4979         if (r == E_SUCCESS)
4980         {
4981                 AppLogDebug("Cookie cleared success");
4982         }
4983         else
4984         {
4985                 AppLogDebug("Cache cleared fail");
4986         }
4987 }
4988
4989 void
4990 MainForm::OnClearPasswords()
4991 {
4992         result r = E_SUCCESS;
4993
4994         if (__pWebViewer != NULL)
4995         {
4996                 __pWebViewer->ClearLoginFormData();
4997         }
4998         if (r == E_SUCCESS)
4999         {
5000                 AppLogDebug("Cookie cleared success");
5001         }
5002         else
5003         {
5004                 AppLogDebug("Cache cleared fail");
5005         }
5006 }
5007
5008
5009 double
5010 MainForm::findDistance(int x1,int y1,int x2, int y2)
5011 {
5012         int deltaX = Math::Abs(x2 - x1);
5013         int deltaY = Math::Abs(y2 - y1);
5014         double num = deltaX*deltaX + deltaY*deltaY;
5015
5016         if (num >= 0)
5017         {
5018                 double x = num;
5019                 int i;
5020                 for (i = 0; i < 20; i++)
5021                 {
5022                         x = (((x*x)+ num)/(2*x));
5023                 }
5024                 return num;
5025         }
5026         else
5027         {
5028                 return 0.0;
5029         }
5030 }
5031
5032 void
5033 MainForm::OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
5034 {
5035         AppLog("xyz:: MainForm::OnTouchPressed called");
5036         if(__pFindWordControl)
5037         {
5038                 AppLog("MainForm::OnTouchPressed %d",__pFindWordControl->GetShowState());
5039 //              ShowFindWordPanel(__pFindWordControl->GetShowState(), true);
5040         }
5041         __isLongPressedDone = false;
5042
5043
5044
5045         Touch touch;
5046         IList* pList = null;
5047         pList = touch.GetTouchInfoListN(source);
5048
5049         if (pList != null)
5050         {
5051                 int count = pList->GetCount();
5052                 if (count == 1)
5053                 {
5054                         TouchInfo* pTouchInfo = static_cast<TouchInfo*>(pList->GetAt(0));
5055                         __touchPoint1 = pTouchInfo->position;
5056
5057                         /*if (__pAddressbar != null)
5058                         {
5059                                 if (__pAddressbar->GetAddressbarMode() != ADDRESSBAR_MODE_LOADING_COMPLETE && __pAddressbar->GetAddressbarMode() != ADDRESSBAR_MODE_LOADING)
5060                                 {
5061                                         if (__pAddressbar->GetAddressbarMode() == ADDRESSBAR_MODE_EDIT)
5062                                         {
5063                                                 __pAddressbar->SaveAddressbarEditText();
5064                                         }
5065                                         __pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
5066                                 }
5067
5068                                 __pAddressbar->Invalidate(true);
5069                         }*/
5070                         if (GetAddressbarMode() != ADDRESSBAR_MODE_LOADING_COMPLETE && GetAddressbarMode() != ADDRESSBAR_MODE_LOADING)
5071                         {
5072                                 if (GetAddressbarMode() == ADDRESSBAR_MODE_EDIT)
5073                                 {
5074                                         //__pAddressbar->SaveAddressbarEditText();
5075                                 }
5076                                 SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
5077                         }
5078                 }
5079                 else if (count == 2)
5080                 {
5081                         AppLogDebug("MainForm::OnTouchPressed count is two");
5082                         TouchInfo* pTouchInfo = static_cast<TouchInfo*>(pList->GetAt(0));
5083                         __touchPoint1 = pTouchInfo->position;
5084
5085                         pTouchInfo = static_cast<TouchInfo*>(pList->GetAt(1));
5086                         __touchPoint2 = pTouchInfo->position;
5087                 }
5088         }
5089         if( pList != NULL)
5090         {
5091                 pList->RemoveAll(true);
5092                 delete pList;
5093         }
5094         if(__pAddressbar)
5095         {
5096                 __pAddressbar->SetShowState(false);
5097         }
5098         if(__pFooterPanel && __isKeypadOpened == false)
5099         {
5100                 __pFooterPanel->SetShowState(true);
5101         }
5102         RelayoutControls(false);
5103         return;
5104 }
5105
5106 void
5107 MainForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
5108 {
5109 //      __currentWordIndex = 0;
5110         __isLongPressedDone = false;
5111
5112 }
5113
5114 void
5115 MainForm::MoveUiControls()
5116 {
5117 }
5118
5119 void
5120 MainForm::OnTextValueChanged (const Tizen::Ui::Control &source)
5121 {
5122         if(&source == dynamic_cast<Control*>(__pFooterUrlField) && __pFooterUrlField != null)
5123         {
5124                 if(__pFooterUrlField->GetTextLength() == 0)
5125                 {
5126                         __pFooterUrlField->SetKeypadActionEnabled(false);
5127                 }
5128                 else
5129                 {
5130                         __pFooterUrlField->SetKeypadActionEnabled(true);
5131                 }
5132         }
5133         if (__pFindWordEditField != null && __pFindWordEditField->GetShowState() == true)
5134         {
5135                 __currentSearchStr = __pFindWordEditField->GetText();
5136                 if (__currentSearchStr.GetLength() > 0)
5137                 {
5138                         __pFindWordCountLabel->SetShowState(true);
5139                 }
5140                 else
5141                 {
5142 //                      __pFindWordCountLabel->SetShowState(false);
5143                         __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),84,__pFindWordCountLabel->GetHeight());
5144                         __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),214+80,__pFindWordEditField->GetHeight());
5145
5146                 }
5147                 __pFindWordNext->SetEnabled(false);
5148                 __pFindWordPrev->SetEnabled(false);
5149                 __pFindWordNext->Invalidate(true);
5150                 __pFindWordPrev->Invalidate(true);
5151                 __pFindWordCountLabel->SetText(L"0/0");
5152                 __pFindWordCountLabel->Invalidate(true);
5153         }
5154         else if (__pFindWordEditFieldRightToLeft != null && __pFindWordEditFieldRightToLeft->GetShowState() == true)
5155         {
5156                 __currentSearchStr = __pFindWordEditFieldRightToLeft->GetText();
5157                 if (__currentSearchStr.GetLength() > 0)
5158                 {
5159                         __pFindWordCountLabelRightToLeft->SetShowState(true);
5160                 }
5161                 else
5162                 {
5163                         __pFindWordCountLabelRightToLeft->SetShowState(false);
5164                 }
5165
5166                 __pFindWordNext->SetEnabled(false);
5167                 __pFindWordPrev->SetEnabled(false);
5168                 __pFindWordNext->Invalidate(true);
5169                 __pFindWordPrev->Invalidate(true);
5170                 __pFindWordCountLabelRightToLeft->SetText(L"0/0");
5171                 __pFindWordCountLabelRightToLeft->Invalidate(true);
5172         }
5173         AppLog("__currentSearchStr %ls",__currentSearchStr.GetPointer());
5174         if (__currentSearchStr.GetLength() > 0)
5175         {
5176                 StartWordSearch();
5177         }
5178         else
5179         {
5180                 __currentSearchStr = L"aaaaaaaabbbbbbbccccccc";
5181                 StartWordSearch();
5182                 __currentSearchStr = L"";
5183                 AppLogDebug("Enter something");
5184         }
5185 }
5186
5187 result
5188 MainForm::InitMostVisitedSitesPanel(Tizen::Ui::OrientationStatus orientationStatus)
5189 {
5190         return E_SUCCESS;
5191
5192 }
5193
5194 result
5195 MainForm::InitMostVisitedSitesView(Tizen::Ui::OrientationStatus orientationStatus)
5196 {
5197         if(__pWebViewer != null)
5198                 return E_SUCCESS;
5199
5200         AppLog("MainForm::InitMostVisitedSitesView");
5201         result r = E_SUCCESS;
5202
5203
5204         if (__pWebViewer != null && __pMostVisitedListView != null)
5205         {
5206                 return E_SUCCESS;
5207         }
5208
5209         if (__pMostVisitedListView != null)
5210         {
5211                 RemoveControl(__pMostVisitedListView);
5212         }
5213         if(__pMostVisitedSites != null)
5214         {
5215                 __pMostVisitedSites->RemoveAll(true);
5216         }
5217
5218         HistoryPresentationModel::GetInstance()->GetMostVisitedSites(*__pMostVisitedSites);
5219
5220         __webControlHeight = GetClientAreaBounds().height - __pFooterPanel->GetHeight();
5221         __pMostVisitedListView = new(std::nothrow) ListView();
5222
5223         int height = GetClientAreaBounds().height;
5224
5225         if(__pFooterPanel->GetShowState() == true)
5226         {
5227                 height = height - __pFooterPanel->GetHeight();
5228         }
5229         if(__pAddressbar->GetShowState() == true)
5230         {
5231                 height -= __pAddressbar->GetHeight();
5232         }
5233
5234         r = __pMostVisitedListView->Construct(Tizen::Graphics::Rectangle(0,0 , GetClientAreaBounds().width, height),true,false);
5235
5236         if (r != E_SUCCESS)
5237         {
5238                 delete __pMostVisitedListView;
5239                 AppLogDebug("Addressbar init failed with %s", GetErrorMessage(r));
5240                 return r;
5241         }
5242         __pMostVisitedListView->SetItemProvider(*this);
5243         __pMostVisitedListView->AddListViewItemEventListener(*this);
5244         __pMostVisitedListView->SetTextOfEmptyList(CommonUtil::GetString(L"IDS_BR_BODY_NO_VISITED_SITES"));
5245         AddControl(__pMostVisitedListView);
5246         __pMostVisitedListView->UpdateList();
5247
5248         return E_SUCCESS;
5249
5250 }
5251
5252 String
5253 MainForm::GetImagePath(void)
5254 {
5255
5256         String str;
5257         String formattedTime;
5258         DateTime currentTime;
5259         LocaleManager localManager;
5260         SystemTime::GetCurrentTime(TIME_MODE_WALL, currentTime);
5261
5262         localManager.Construct();
5263         Locale locale = localManager.GetSystemLocale();
5264         //Locale locale(LANGUAGE_ENG, COUNTRY_US);
5265
5266         // Get date formatter
5267         DateTimeFormatter* pTimeFormatter = DateTimeFormatter::CreateDateTimeFormatterN(locale, DATE_TIME_STYLE_DEFAULT);
5268
5269         if (pTimeFormatter)
5270         {
5271                 pTimeFormatter->Format(currentTime, formattedTime);
5272         }
5273
5274         AppLog("current time stamp is %ls", formattedTime.GetPointer());
5275         String delim(L" :");
5276         StringTokenizer strTok(formattedTime, delim);
5277         String token;
5278         String imageName;
5279         String str1("GMT+00");
5280         while (strTok.HasMoreTokens())
5281         {
5282                 strTok.GetNextToken(token); // Osp, StringTokenizer, Sample, code
5283                 if(token.Equals(str1))
5284                         break;
5285                 AppLog("token is %ls", token.GetPointer());
5286                 imageName.Append(token);
5287         }
5288         return imageName;
5289
5290 }
5291
5292 void MainForm::UpdateImageContent(ByteBuffer* aBuffer, String imageName)
5293 {
5294         result r = E_FAILURE;
5295         AppLog("Content manager 1");
5296         ContentId contentId;
5297         ContentManager contentManager;
5298         r = contentManager.Construct();
5299         if(IsFailed(r))
5300         {
5301                 AppLog("Content manager update content result %s" ,GetErrorMessage(r));
5302                 return;
5303         }
5304         Tizen::Base::String contentPath = Tizen::System::Environment::GetMediaPath() + L"Downloads/";
5305         Tizen::Io::Directory::Create(contentPath,true);
5306         if(GetLastResult() == E_FILE_ALREADY_EXIST)
5307         {
5308                 AppLog("Already exists");
5309         }
5310         else if(GetLastResult() == E_SUCCESS)
5311         {
5312                 AppLog("created success");
5313         }
5314         contentPath.Append(imageName);
5315         contentPath.Append(".jpg");
5316         contentId = contentManager.CreateContent(*aBuffer, contentPath);
5317         ShowIndicatorNotification(L"Download Complete",contentPath);
5318         AppLog("Content manager update content result %s" ,GetErrorMessage(GetLastResult()));
5319 }
5320
5321 void
5322 MainForm::ShowIndicatorNotification(const String& messageText, const String& contentPath)
5323 {
5324         AppLogDebug("ENTER");
5325
5326         NotificationRequest request;
5327         request.SetAlertText(messageText);
5328         request.SetTitleText(L"");
5329         request.SetAppMessage(contentPath);
5330         request.SetOngoingActivityType(ONGOING_ACTIVITY_TYPE_TEXT);
5331         request.SetNotificationStyle(NOTIFICATION_STYLE_THUMBNAIL);
5332         Tizen::App::App* pApp = Tizen::App::App::GetInstance();
5333         String homePath = pApp->GetAppRootPath();
5334         String iconPath = homePath + L"res/screen-density-xhigh/Notification_download_complete.png";
5335         AppLog("The iconPath is : %ls", homePath.GetPointer());
5336         request.SetIconFilePath(iconPath);
5337
5338         Tizen::Shell::NotificationManager notiMgr;
5339         notiMgr.Construct();
5340         notiMgr.NotifyOngoingActivity(request);
5341         AppLogDebug("EXIT: %s", GetErrorMessage(GetLastResult()));
5342         return;
5343 }
5344
5345 void
5346 MainForm::SetForwardButtonEnabled(bool isEnabled)
5347 {
5348         __pGoForwardBtn->SetEnabled(isEnabled);
5349         __pGoForwardBtn->Invalidate(true);
5350 }
5351
5352 void
5353 MainForm::SetBackButtonEnabled(bool isEnabled)
5354 {
5355         __pGoBackBtn->SetEnabled(isEnabled);
5356         __pGoBackBtn->Invalidate(true);
5357 }
5358
5359 void
5360 MainForm::UpdateProgress(int percentage)
5361 {
5362         __progressPercentage = percentage;
5363         if (percentage == 0 || percentage == 100)
5364         {
5365                 __isLoadingData = false;
5366                 if (percentage == 100)
5367                 {
5368                         __isLoadingCompleted = true;
5369                         __progressPercentage = 0;
5370                 }
5371                 else
5372                 {
5373                         __isLoadingCompleted = false;
5374                 }
5375         }
5376         else
5377         {
5378                 __isLoadingData = true;
5379         }
5380         UpdateProgressBitmap();
5381 }
5382
5383 int
5384 MainForm::GetProgress(void)
5385 {
5386         return __progressPercentage;
5387 }
5388
5389 void
5390 MainForm::UpdateProgressBitmap(void)
5391 {
5392         result r = E_SUCCESS;
5393         if (__pProgressbarLabel == null)
5394                 return;
5395         int w = __pProgressbarLabel->GetWidth();
5396         int h = __pProgressbarLabel->GetHeight();
5397         Canvas canvas;
5398         int progressWidth = 0;
5399         Bitmap* pRetBitmap = null;
5400
5401         if (__progressPercentage == 0 || __progressPercentage == 100)
5402         {
5403                 __pProgressbarLabel->SetShowState(false);
5404                 __pProgressbarLabel->Invalidate(false);
5405                 return;
5406         }
5407         else
5408         {
5409                 __pProgressbarLabel->SetShowState(true);
5410                 __pProgressbarLabel->Invalidate(false);
5411         }
5412
5413         r = canvas.Construct(Rectangle(0, 0, w, h));
5414
5415         if (r != E_SUCCESS)
5416         {
5417                 AppLogException("Canvas construction failed with %s", GetErrorMessage(r));
5418                 return;
5419         }
5420
5421         canvas.Clear();
5422         Bitmap *pBgBmp = AppResource::GetInstance()->GetBitmapN(IDB_TITLE_PROGRESS_BAR_BG);
5423
5424         if (pBgBmp != null)
5425         {
5426                 pBgBmp->Scale(Dimension(w, h));
5427                 canvas.DrawBitmap(Point(0,0), *pBgBmp);
5428                 delete pBgBmp;
5429         }
5430
5431         progressWidth = (double) (w) * __progressPercentage / 100;
5432         AppLogDebug("progressWidth: %d", progressWidth);
5433         Bitmap *pProgressBmp = AppResource::GetInstance()->GetBitmapN(IDB_TITLE_PROGRESS_BAR);
5434
5435         if (pProgressBmp != null)
5436         {
5437                 pProgressBmp->Scale(Dimension(progressWidth, h));
5438                 canvas.DrawBitmap(Point(0,0), *pProgressBmp);
5439                 delete pProgressBmp;
5440         }
5441
5442         pRetBitmap = new (std::nothrow) Bitmap();
5443
5444         if (pRetBitmap == null)
5445         {
5446                 AppLogException("Bitmap creation failed with %s", GetErrorMessage(r));
5447                 return;
5448         }
5449
5450         pRetBitmap->Construct(canvas, canvas.GetBounds());
5451
5452         if (__pProgressbarLabel != null && pRetBitmap != null)
5453         {
5454                 __pProgressbarLabel->SetBackgroundBitmap(*pRetBitmap);
5455                 __pProgressbarLabel->Invalidate(false);
5456         }
5457
5458         if (pRetBitmap != null)
5459         {
5460                 delete pRetBitmap;
5461                 pRetBitmap = null;
5462         }
5463         return;
5464 }
5465
5466 void
5467 MainForm::ReaderClicked()
5468 {
5469         result r = E_SUCCESS;
5470         ArrayList* pArgList = new(std::nothrow) ArrayList();
5471         if (pArgList != null)
5472         {
5473                 r = pArgList->Construct();
5474                 if (IsFailed(r))
5475                 {
5476                         delete pArgList;
5477                         return;
5478                 }
5479
5480                 r = pArgList->Add(*new(std::nothrow) String(*__pReaderData));
5481                 if (IsFailed(r))
5482                 {
5483                         delete pArgList;
5484                         return;
5485                 }
5486
5487                 r = pArgList->Add(*new(std::nothrow) String(__pWebViewer->GetUrl()));
5488                 if (IsFailed(r))
5489                 {
5490                         delete pArgList;
5491                         return;
5492                 }
5493
5494                 r = pArgList->Add(*new(std::nothrow) String(__pWindowInfo->pageTitle));
5495                 if (IsFailed(r))
5496                 {
5497                         delete pArgList;
5498                         return;
5499                 }
5500         }
5501
5502         SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_ARTICLE_READER, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
5503         return;
5504
5505
5506 }
5507
5508 void MainForm::SetAddressbarMode(AddressBarMode addMode)
5509 {
5510         AppLogDebug("AddressBar::setAddressbarMode to %d",addMode);
5511
5512         __currentAddMode = addMode;
5513
5514         switch(addMode)
5515         {
5516         case ADDRESSBAR_MODE_INVALID:
5517         {
5518                 // do nothing
5519         }
5520         break;
5521         case ADDRESSBAR_MODE_READER:
5522         {
5523                 __pStopBtn->SetShowState(false);
5524                 __pRefreshBtn->SetShowState(false);
5525                 __pClearBtn->SetShowState(false);
5526                 __pReaderBtn->SetShowState(false);
5527         }
5528         break;
5529         case ADDRESSBAR_MODE_LOADING:
5530         {
5531                 __pRefreshBtn->SetShowState(false);
5532                 __pStopBtn->SetShowState(true);
5533                 __pClearBtn->SetShowState(false);
5534                 __pReaderBtn->SetShowState(false);
5535         }
5536         break;
5537         case ADDRESSBAR_MODE_LOADING_COMPLETE:
5538         {
5539 //              SetUrl(__pAddressbar->GetUrl());
5540
5541                 __pRefreshBtn->SetShowState(true);
5542                 __pStopBtn->SetShowState(false);
5543                 __pClearBtn->SetShowState(false);
5544                 __pReaderBtn->SetShowState(false);
5545         }
5546         break;
5547         case ADDRESSBAR_MODE_EDIT:
5548         {
5549                 __pRefreshBtn->SetShowState(false);
5550                 __pStopBtn->SetShowState(false);
5551                 __pReaderBtn->SetShowState(false);
5552                 __pClearBtn->SetShowState(true);
5553         }
5554         break;
5555         }
5556
5557         Invalidate(true);
5558
5559         OnAddressBarModeChanged();
5560 }
5561
5562 AddressBarMode MainForm::GetAddressbarMode(void)
5563 {
5564         return __currentAddMode;
5565 }
5566
5567 void MainForm::SetUrl(const String& url)
5568 {
5569         __displayUrl = url;
5570         if(__displayUrl.GetLength() > 2048)
5571                 __displayUrl.SubString(0,2048,__displayUrl);
5572
5573         if (__pFooterUrlField != NULL)
5574         {
5575                 String removedHttpUrl = RemoveHttpTextFromDisplayURL();
5576                 if (removedHttpUrl.IsEmpty() == false)
5577                 {
5578                         __pFooterUrlField->SetText(removedHttpUrl);
5579                         if(__pAddressbar != NULL && __pAddressbar->HasCurrentFocus() == false)
5580                                 __pAddressbar->SetUrl(__displayUrl);
5581                 }
5582                 else
5583                 {
5584                         __pFooterUrlField->SetText(__displayUrl);
5585                         if(__pAddressbar != NULL && __pAddressbar->HasCurrentFocus() == false)
5586                                 __pAddressbar->SetUrl(__displayUrl);
5587                 }
5588                 if(__pFooterUrlField)
5589                         __pFooterUrlField->SetCursorPosition(__pFooterUrlField->GetTextLength());
5590                 __pFooterUrlField->Invalidate(false);
5591                 if(__pAddressbar != NULL && __pAddressbar->HasFocus())
5592                         __pAddressbar->Invalidate(true);
5593 //              __pFooterUrlField->SetCursorPosition(0);
5594         }
5595 }
5596
5597 String
5598 MainForm::RemoveHttpTextFromDisplayURL(void)
5599 {
5600         AppLog("MainForm::RemoveHttpTextFromDisplayURL __displayUrl %ls",__displayUrl.GetPointer());
5601         int index = -1;
5602 //      bool isHttpText = __displayUrl.Contains(L"http://");
5603         String updatedDisplayUrl;
5604         updatedDisplayUrl.Clear();
5605         if(__displayUrl.IndexOf(L"http://",0,index) == E_SUCCESS && index == 0)
5606         {
5607                 __displayUrl.SubString(7,updatedDisplayUrl);
5608         }
5609         else if(__displayUrl.IndexOf(L"https://",0,index) == E_SUCCESS && index == 0)
5610         {
5611                 __displayUrl.SubString(8,updatedDisplayUrl);
5612         }
5613         return updatedDisplayUrl;
5614 }
5615
5616 void MainForm::OnSharePopupControlStarted(void)
5617 {
5618         __pWebViewer->AddTouchEventListener(*this);
5619 }
5620
5621 void
5622 MainForm::OnUserEventReceivedN (RequestId requestId, Tizen::Base::Collection::IList *pArgs)
5623 {
5624         if (requestId == BACK_GROUND_APP_EVENT)
5625         {
5626                 if(__pWebViewer != null)
5627                 {
5628                         __pWebViewer->Pause();
5629                 }
5630                 if(__pImageMenu)
5631                 {
5632                         __pImageMenu->SetShowState(false);
5633                 }
5634                 if(__pAddressbar != null)
5635                 {
5636                         __pAddressbar->SendUserEvent(BACK_GROUND_APP_EVENT,NULL);
5637                 }
5638         }
5639         else if(requestId == FORE_GROUND_APP_EVENT)
5640         {
5641                 if(__pWebViewer != null)
5642                 {
5643                         __pWebViewer->Resume();
5644                 }
5645                 if(__pAddressbar != null)
5646                 {
5647                         __pAddressbar->SendUserEvent(FORE_GROUND_APP_EVENT,NULL);
5648                 }
5649         }
5650 }
5651
5652 void
5653 MainForm::AddressBarCancelledClicked(const Addressbar& addBar)
5654 {
5655         AppLog("XYZ::MainForm::AddressBarCancelledClicked");
5656         result r = E_SUCCESS;
5657
5658         if (__pAddressbar)
5659                 __pAddressbar->SetShowState(false);
5660
5661         AppLog("akjshdasd 5");
5662         __pFooterPanel->SetShowState(true);
5663
5664         if(__pWebViewer)
5665                 __pWebViewer->SetFocus();
5666         else if(__pMostVisitedListView)
5667                 __pMostVisitedListView->SetFocus();
5668         else if(__pMultiWindowButton)
5669                 __pMultiWindowButton->SetFocus();
5670         else if(__pMoreButton)
5671                 __pMoreButton->SetFocus();
5672
5673         __pAddressbar->SetShowState(false);
5674
5675         RelayoutControls(false);
5676 }
5677
5678 void
5679 MainForm::OnFormMenuRequested (Tizen::Ui::Controls::Form &source)
5680 {
5681         AppLog("MainForm::OnFormMenuRequested called");
5682         InitOptionMenu();
5683         if (__pWindowInfo != NULL && __pWindowInfo->pageUrl != NULL && __pWebViewer && __pWebViewer->GetShowState() == true)
5684         {
5685                 int bookmarkCount=0;
5686                 bool exist = false;
5687                 String url=L"";
5688                 url=__pWindowInfo->pageUrl;
5689                 AppLog("MainForm::OnFormMenuRequested url %ls",url.GetPointer());
5690                 result r = E_SUCCESS;
5691                 Bitmap* pBitmap = null;
5692                 String lastChar = L"";
5693 //              if(url.SubString(url.GetLength()-1,lastChar));
5694 //              if(lastChar == L"/")
5695 //              {
5696 //                      bool exist1 = false;
5697 //                      bool exist2 = false;
5698 //                      r=BookmarkPresentationModel::GetInstance()->DoesBookmarkExist(url,exist1);
5699 //                      url.SubString(0,url.GetLength() - 1,url);
5700 //                      r=BookmarkPresentationModel::GetInstance()->DoesBookmarkExist(url,exist2);
5701 //                      exist = exist1 | exist2;
5702 //              }
5703 //              else
5704 //              {
5705                         r=BookmarkPresentationModel::GetInstance()->DoesBookmarkExist(url,exist);
5706                         if (IsFailed(r))
5707                         {
5708                                 AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED failed");
5709                                 return;
5710                         }
5711 //              }
5712                 if ( exist == true)
5713                 {
5714                         pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ICON_BOOKMARK_ON_TEMP);
5715                 }
5716                 else
5717                 {
5718                         pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ICON_BOOKMARK_OFF_TEMP);
5719                 }
5720                 AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED 3");
5721
5722                 if (__pOptionMenu->GetItemCount() == 9)
5723                 {
5724                         r = __pOptionMenu->SetItemAt(1,CommonUtil::GetString(L"IDS_BR_OPT_ADDTOBOOKMARKS"), IDA_ADDTOBOOKMARK_CLICKED,*pBitmap);
5725                 }
5726                 else
5727                 {
5728                         r = __pOptionMenu->InsertItemAt(1,CommonUtil::GetString(L"IDS_BR_OPT_ADDTOBOOKMARKS"), IDA_ADDTOBOOKMARK_CLICKED,*pBitmap);
5729                 }
5730
5731                 if (IsFailed(r))
5732                 {
5733                         AppLogException("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED Add to Bookmark failed with %s", GetErrorMessage(r));
5734                         delete pBitmap;
5735                         return ;
5736                 }
5737                 AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED 4");
5738                 if (__pOptionMenu->GetItemCount() != 9)
5739                 {
5740                         __pOptionMenu->InsertItemAt(1,CommonUtil::GetString(L"IDS_BR_OPT_ADDTOBOOKMARKS"), IDA_ADDTOBOOKMARK_CLICKED);
5741                         __pOptionMenu->InsertItemAt(2,CommonUtil::GetString(L"IDS_BR_BODY_PRINT"), IDA_PRINT_CLICKED);
5742 //                              __pOptionMenu->InsertItemAt(2,L"Add to Home"/*CommonUtil::GetString(L"IDS_BR_OPT_SHARE")*/, IDA_ADD_TO_HOME_CLICKED);
5743                         __pOptionMenu->InsertItemAt(3,CommonUtil::GetString(L"IDS_BR_OPT_SHARE"), IDA_SHARE_CLICKED);
5744                         __pOptionMenu->InsertItemAt(4,CommonUtil::GetString(L"IDS_BR_OPT_FIND_ON_PAGE_ABB"), IDA_FINDONPAGE_CLICKED);
5745                         __pOptionMenu->SetMaxVisibleItemsCount(6);
5746                 }
5747                 if( GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
5748                 {
5749                         AppLog(" Orientation landscape");
5750                         __pOptionMenu->SetMaxVisibleItemsCount(5);
5751                 }
5752                 else
5753                 {
5754                         AppLog(" Orientation potrait");
5755                         __pOptionMenu->SetMaxVisibleItemsCount(6);
5756                 }
5757
5758                 AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED 5");
5759                 delete pBitmap;
5760         }
5761         AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED end");
5762         if(__pAddressbar)
5763                 __pAddressbar->SetShowState(false);
5764         SetFocus();
5765         __pFooterPanel->SetShowState(true);
5766         result r = __pOptionMenu->SetShowState(true);
5767         AppLog("ajsghd %s",GetErrorMessage(r));
5768         RelayoutControls(false);
5769         __pOptionMenu->Invalidate(true);
5770         __pOptionMenu->Show();
5771
5772 }