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