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