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