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