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