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