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