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