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