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