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