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