Fixed Nabi Issues
[apps/osp/Internet.git] / src / IntMainForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 //!Internet MainForm class
18 /*@file:        MainForm.cpp
19  *@brief:       The %MainForm provides the common functionalities for the Main View of the Browser including the addressbar,
20  *                      loading,handling events etc.
21  */
22
23 #include <FApp.h>
24 #include <FGraphics.h>
25 #include <FMedia.h>
26 #include <FUi.h>
27 #include <FContent.h>
28 #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)
2749                 {
2750                         AppLog("Called");
2751                         InitWebControl();
2752                         __pWindowInfo->pCurrentWeb = __pWebViewer;
2753                         if(__pWindowInfo->pageUrl.GetLength() > 0)
2754                                 LoadUrl(__pWindowInfo->pageUrl);
2755                 }
2756         }
2757
2758         String homePage = SettingPresentationModel::GetInstance()->GetHomepage();
2759         AppLog("Homepage Value in Onsceneactivated is %ls",homePage.GetPointer());
2760         if(homePage.CompareTo((L"IDS_BR_BODY_MOST_VISITED_SITES")) == 0)
2761         {
2762                 InitMostVisitedSitesView(GetOrientationStatus());
2763         }
2764         else if (homePage.CompareTo((L"IDS_BR_BODY_BLANK_PAGE")) == 0)
2765         {
2766                 if(__pMostVisitedListView != null)
2767                 {
2768                         __pMostVisitedListView->SetShowState(false);
2769                 }
2770         }
2771
2772         if (__pAddressbar != null && pArgs != null && (previousSceneId == IDSCN_BOOKMARK_VIEW || previousSceneId == IDSCN_HISTORY_LIST))
2773         {
2774                 String* pBookmarkUrl = dynamic_cast< String* >(pArgs->GetAt(0));
2775
2776                 if (pBookmarkUrl == null)
2777                         return;
2778                 AppLogDebug("bookmarkUrl = %ls",pBookmarkUrl->GetPointer());
2779                 //__pAddressbar->SetUrl(*pBookmarkUrl);
2780                 SetUrl(*pBookmarkUrl);
2781
2782                 if (__pWebViewer != null && homePage.CompareTo((L"IDS_BR_BODY_BLANK_PAGE")) != 0)
2783                         __pWebViewer->LoadUrl(*pBookmarkUrl);
2784                 delete pBookmarkUrl;
2785         }
2786
2787         bool isPrivateBrowsing = SettingPresentationModel::GetInstance()->GetPrivateOn();
2788         Bitmap* pBitmap = null;
2789         if (isPrivateBrowsing == true)
2790         {
2791                 pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_BUTTON_ON);
2792
2793                 if (__pWebViewer != null)
2794                 {
2795                         __pWebViewer->SetPrivateBrowsingEnabled(true);
2796                 }
2797
2798                 if (__pAddressbar != null)
2799                 {
2800                         //      __pAddressbar->UpdateFaviconBitmap(true);
2801                 }
2802
2803         }
2804         else
2805         {
2806                 pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_BUTTON_OFF);
2807
2808                 if (__pWebViewer != null)
2809                 {
2810                         __pWebViewer->SetPrivateBrowsingEnabled(false);
2811                 }
2812
2813                 if (__pAddressbar != null)
2814                 {
2815                         //      __pAddressbar->UpdateFaviconBitmap(false);
2816                 }
2817         }
2818
2819         if (__pOptionMenu != null && __pOptionMenu->GetItemCount() != 9)
2820         {
2821                 __pOptionMenu->SetItemAt(1,CommonUtil::GetString(L"IDS_BR_BODY_PRIVACY_AND_SECURITY_ABB"),IDA_PRIVATEON_CLICKED,*pBitmap);
2822         }
2823         else if (__pOptionMenu != null )
2824         {
2825                 __pOptionMenu->SetItemAt(5,CommonUtil::GetString(L"IDS_BR_BODY_PRIVACY_AND_SECURITY_ABB"),IDA_PRIVATEON_CLICKED,*pBitmap);
2826         }
2827
2828         if (pBitmap != null)
2829         {
2830                 delete pBitmap;
2831         }
2832
2833         RelayoutControls(false);
2834         AppLog("ABC: OnSceneActivatedN started exit");
2835
2836 }
2837
2838 void
2839 MainForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
2840                 const Tizen::Ui::Scenes::SceneId& nextSceneId)
2841 {
2842         Canvas* pWebCanvas = null;
2843         if (__pWebViewer != null)
2844         {
2845                 pWebCanvas = __pWebViewer->GetCanvasN();
2846
2847         }
2848         if (pWebCanvas == null)
2849         {
2850                 return;
2851         }
2852         if (__pWindowInfo != null)
2853         {
2854                 if (__pWindowInfo->pWebCanvasBitmap != null)
2855                 {
2856                         delete __pWindowInfo->pWebCanvasBitmap;
2857                 }
2858                 __pWindowInfo->pWebCanvasBitmap = new(std::nothrow) Bitmap();
2859                 result r = __pWindowInfo->pWebCanvasBitmap->Construct(*pWebCanvas,Rectangle(0,0,pWebCanvas->GetBounds().width,pWebCanvas->GetBounds().height));
2860                 AppLog("Bitmap Construction result %s",GetErrorMessage(r));
2861         }
2862         Bitmap* pBitmap = GetCapturedBitmapN();
2863         AppLog("Coming here");
2864         Canvas* pCanvas = new(std::nothrow) Canvas();
2865         pCanvas->Construct(GetClientAreaBounds());
2866         if(pBitmap != null)
2867         {
2868                 pCanvas->DrawBitmap(Point(0,0),*pBitmap);
2869                 delete pBitmap;
2870         }
2871         if(__pWebViewer != null && __pWindowInfo != null)
2872                 pCanvas->DrawBitmap(__pWebViewer->GetPosition(),*__pWindowInfo->pWebCanvasBitmap);
2873
2874         WindowInfo::pFormCanvasBitmap = new(std::nothrow) Bitmap();
2875         WindowInfo::pFormCanvasBitmap->Construct(*pCanvas,Rectangle(0,0,GetClientAreaBounds().width,GetClientAreaBounds().height - __pFooterPanel->GetHeight()));
2876         delete pCanvas;
2877         delete pWebCanvas;
2878         if(__pAddressbar)
2879                 __pAddressbar->SetShowState(false);
2880         AppLog("Coming here");
2881 }
2882
2883 bool
2884 MainForm::OnHttpAuthenticationRequestedN(const Tizen::Base::String& host,
2885                 const Tizen::Base::String& realm,
2886                 const Tizen::Web::Controls::AuthenticationChallenge& authentication)
2887 {
2888         return false;
2889 }
2890
2891 void
2892 MainForm::OnHttpAuthenticationCanceled(void)
2893 {
2894 }
2895
2896 void
2897 MainForm::OnLoadingStarted(void)
2898 {
2899         AppLogDebug("MainForm::OnLoadingStarted entered");
2900         __isLoaded = true;
2901         if(__pAddressbar == NULL || __pWebViewer == null)
2902         {
2903                 return;
2904         }
2905
2906         // this is added in case if menu is opened and user load the page
2907         if(__pOptionMenu != null && __pOptionMenu->GetShowState() == true)
2908         {
2909                 __pOptionMenu->SetShowState(false);
2910                 __pOptionMenu->Invalidate(true);
2911         }
2912
2913
2914
2915         if(__pImageMenu != null && __pImageMenu->GetShowState() == true)
2916         {
2917                 __pImageMenu->SetShowState(false);
2918                 __pImageMenu->Invalidate(true);
2919         }
2920         String url = __pWebViewer->GetUrl();
2921         if(url.Contains(IDS_TIZEN_SERVICE))
2922         {
2923                 String appId;
2924                 String delim(L":;,");
2925
2926                 // Creates a StringTokenizer instance
2927                 StringTokenizer strTok(url, delim);
2928
2929                 int count = strTok.GetTokenCount();     // count == 4
2930
2931                 HashMap *pMap = new HashMap();
2932                 pMap->Construct();
2933                 String token;
2934                 String key;
2935                 String value;
2936                 while (strTok.HasMoreTokens())
2937                 {
2938                         AppLog("Token: %ls", token.GetPointer());
2939                         strTok.GetNextToken(token);         // Tizen, StringTokenizer, Sample, code
2940                         if(token.Contains(IDS_APPID))
2941                         {
2942                                 token.SubString(6, appId);
2943                                 AppLog("AppID:%ls", appId.GetPointer());
2944                         }
2945                         else if(token.Contains(IDS_KEY))
2946                         {
2947                                 token.SubString(4, key);
2948                                 AppLog("key:%ls", key.GetPointer());
2949                         }
2950                         else if(token.Contains(IDS_VALUE))
2951                         {
2952                                 token.SubString(6, value);
2953                                 AppLog("value:%ls", value.GetPointer());
2954                         }
2955                 }
2956                 pMap->Add(key, value);
2957
2958                 if(appId != "")
2959                 {
2960                         AppControl *pAppControl = null;
2961                         String operationId = L"http://tizen.org/appcontrol/operation/main";
2962                         pAppControl = dynamic_cast<AppControl*>(AppManager::FindAppControlN(appId, operationId));
2963                         if(pAppControl)
2964                         {
2965                                 AppLog("Starting AppControl");
2966                                 result r = pAppControl->Start(null, null, pMap, null);
2967                                 AppLog("Result of Start %s", GetErrorMessage(r));
2968                         }
2969                         else
2970                         {
2971                                 AppLogException("AppControl not found");
2972                         }
2973                         return;
2974                 }
2975         }
2976         if ( __pAddressbar != null && __pAddressbar->GetShowState() == true)
2977         {
2978                 __pAddressbar->SetShowState(false);
2979                 AddressBarCancelledClicked(*__pAddressbar);
2980                 __pAddressbar->Invalidate(true);
2981         }
2982         Bitmap* pBitmap = FaviconManager::GetInstance()->GetDefaultFaviconN();
2983         if(pBitmap != null)
2984         {
2985                 __pAddressbar->SetFaviconBitmap(*pBitmap);
2986         }
2987         delete pBitmap;
2988         if (__adressPanelPosition.y < (0 - __pAddressbar->GetHeight() + 12))
2989         {
2990                 // updating the address bar position with respect to web control
2991                 __adressPanelPosition.y = 0 - __pAddressbar->GetHeight() + 12; //-12 is for the progress label
2992                 __distanceMoved = 0;
2993                 MoveUiControls();
2994         }
2995
2996         //__pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING);
2997         SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING);
2998         if (__pWebViewer != null)
2999         {
3000                 AppLog("MainForm::OnLoadingStarted __pWebViewer->GetUrl() %ls",__pWebViewer->GetUrl().GetPointer());
3001                 //__pAddressbar->SetUrl(__pWebViewer->GetUrl());
3002                 SetUrl(__pWebViewer->GetUrl());
3003                 if (__pWindowInfo != NULL)
3004                 {
3005                         // resetting the page title to blank, it will be received in OnPageTitleReceived()
3006                         __pWindowInfo->pageTitle = L"";
3007                         __pWindowInfo->pageUrl = __pWebViewer->GetUrl();
3008                 }
3009                 __pAddressbar->Invalidate(true);
3010         }
3011
3012 }
3013
3014 void
3015 MainForm::OnLoadingCanceled(void)
3016 {
3017
3018 }
3019
3020
3021 void
3022 MainForm::OnKeypadWillOpen(Tizen::Ui::Control& source)
3023 {
3024         AppLog("XYZ::MainForm::OnKeypadWillOpen");
3025
3026 }
3027
3028 void
3029 MainForm::OnKeypadOpened(Tizen::Ui::Control& source)
3030 {
3031         AppLog("XYZ::MainForm::OnKeypadOpened");
3032         __isKeypadOpened = true;
3033         __pFooterPanel->SetShowState(false);
3034
3035 }
3036
3037 void
3038 MainForm::OnKeypadClosed(Tizen::Ui::Control& source)
3039 {
3040         AppLog("XYZ::MainForm::OnKeypadClosed");
3041         __isKeypadOpened = false;
3042         __pFooterPanel->SetShowState(true);
3043         RelayoutControls(true);
3044 }
3045
3046 void
3047 MainForm::OnKeypadBoundsChanged(Tizen::Ui::Control &source)
3048 {
3049         AppLog("XYZ::KeypadBoundsChanged");
3050         RelayoutControls(false);
3051 }
3052
3053 void
3054 MainForm::OnLoadingErrorOccurred(LoadingErrorType error,
3055                 const Tizen::Base::String& reason)
3056 {
3057         AppLogDebug("Error: %d, %ls", error, reason.GetPointer());
3058 }
3059
3060 void
3061 MainForm::OnLoadingCompleted(void)
3062 {
3063         AppLog("MainForm::OnLoadingCompleted start");
3064         DateTime date;
3065         result r = E_SUCCESS;
3066
3067         if (__pWebViewer == null)
3068         {
3069                 return;
3070         }
3071
3072         if (__pAddressbar == null)
3073         {
3074                 return;
3075         }
3076
3077         if(__pImageMenu && __pImageMenu->GetShowState())
3078         {
3079                 __pImageMenu->SetShowState(false);
3080                 __pImageMenu->Invalidate(true);
3081         }
3082
3083         if (__pWebViewer->CanGoForward())
3084         {
3085                 //__pAddressbar->SetForwardButtonEnabled(true);
3086                 SetForwardButtonEnabled(true);
3087         }
3088         else
3089         {
3090                 //__pAddressbar->SetForwardButtonEnabled(false);
3091                 SetForwardButtonEnabled(false);
3092         }
3093
3094         /*if (__pAddressbar->GetAddressbarMode() != ADDRESSBAR_MODE_EDIT)
3095         {
3096                 __pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
3097
3098                 //__pAddressbar->UpdateProgress(0);
3099                 UpdateProgress(0);
3100         }*/
3101
3102         if(GetAddressbarMode() != ADDRESSBAR_MODE_EDIT)
3103         {
3104                 SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
3105                 UpdateProgress(0);
3106         }
3107
3108         AppLog("PrivateBrowsing %d",__pWebViewer->IsPrivateBrowsingEnabled());
3109         bool isPrivateBrowsing = SettingPresentationModel::GetInstance()->GetPrivateOn();
3110         if (isPrivateBrowsing == false)
3111         {
3112                 if(__pHistory != null)
3113                 {
3114                         delete __pHistory;
3115                         __pHistory = null;
3116                 }
3117
3118                 __pHistory = new(std::nothrow) History;
3119                 HistoryPresentationModel::GetCurrentDateTime(date);
3120                 if (__pWindowInfo)
3121                 {
3122                         __pHistory->SetHistoryTitle(__pWindowInfo->pageTitle);
3123                         AppLogDebug("MainForm::OnLoadingCompleted pagetitle = %ls", __pWindowInfo->pageTitle.GetPointer());
3124
3125                         __pHistory->SetHistoryUrl(__pWindowInfo->pageUrl);
3126                         AppLogDebug("MainForm::OnLoadingCompleted pageUrl = %ls", __pWindowInfo->pageUrl.GetPointer());
3127                 }
3128                 __pHistory->SetVisitedTime(date);
3129
3130                 if (__pWebViewer != null)
3131                 {
3132                         AppLog("MainForm::OnLoadingCompleted setting the fav icon 0");
3133
3134                         Bitmap* pTempBitmap = __pWebViewer->GetFaviconN();
3135                         if (pTempBitmap != null)
3136                         {
3137                                 AppLog("MainForm::OnLoadingCompleted setting the fav icon 1");
3138                                 __pHistory->SetFavIconBitmap(*pTempBitmap);
3139                         }
3140
3141                         AppLog("MainForm::OnLoadingCompleted setting the fav icon 2");
3142                 }
3143
3144                 Canvas* pCanvas = __pWebViewer->GetCanvasN();
3145                 Bitmap* pBitmap = new(std::nothrow) Bitmap();
3146                 if ( pCanvas != null &&  pCanvas != null && pBitmap != null)
3147                 {
3148                         pBitmap->Construct(*pCanvas, pCanvas->GetBounds());
3149                         pBitmap->Scale(Dimension(pBitmap->GetWidth()/4, pBitmap->GetHeight()/4));
3150                         __pHistory->SetThumbnail(pBitmap);
3151                 }
3152                 Bitmap *pFavIcon = __pWebViewer->GetFaviconN();
3153                 if (pFavIcon)
3154                 {
3155                         __pHistory->SetFavIconBitmap(*pFavIcon);
3156                         delete pFavIcon;
3157                 }
3158
3159                 HistoryPresentationModel::GetInstance()->SaveTempHistory(*__pHistory);
3160                 //delete pHistory;
3161         }
3162         else
3163         {
3164                 return;
3165         }
3166 //      if (__pWindowInfo && __pWindowInfo->faviconUrl == "")
3167         {
3168                 // temperary fixed (webpage can be not loaded)
3169                 UpdateFavicon();
3170         }
3171
3172         bool isReaderEnabled = SettingPresentationModel::GetInstance()->IsRunReaderEnabled();
3173         if (isReaderEnabled == true)
3174         {
3175                 if (__pReaderData)
3176                 {
3177                         delete __pReaderData;
3178                         __pReaderData = null;
3179                 }
3180                 String filePath = Tizen::App::UiApp::GetInstance()->GetAppRootPath();
3181                 filePath.Append(L"data/reader.js");
3182                 File file;
3183                 char buffer[10];
3184                 char buffer2[5];
3185                 int i;
3186                 int readCnt;
3187                 result r = E_SUCCESS;
3188                 FileAttributes attr;
3189
3190                 File::GetAttributes(filePath,attr);
3191                 // Creates file
3192                 r = file.Construct(filePath, L"r+");
3193                 if (IsFailed(r))
3194                 {
3195                         AppLogDebug("File construct failed with %s", GetErrorMessage(r));
3196                         return;
3197                 }
3198                 char* pScript = new(std::nothrow) char[attr.GetFileSize()+1];
3199                 if(pScript == null)
3200                 {
3201                         AppLogDebug("Memory allocation for file failed %s", GetErrorMessage(r));
3202                         return;
3203                 }
3204 //              file.Read(pScript,attr.GetFileSize());
3205 //
3206 //              AppLogDebug("scipt length %d",strlen(pScript));
3207                 String strScript = L"";
3208 //              strScript.Append(pScript);
3209 //              for(int i=0; i<25; i++)
3210                 {
3211                         file.Read(pScript,attr.GetFileSize());
3212 //                      AppLog("xyzz tell %d",file.Tell());
3213 //                      r = strScript.Append(pScript);
3214 //                      AppLog("xyzz append result %s",GetErrorMessage(r));
3215 //                      AppLog("xyzz strScript length %d",strScript.GetLength());
3216                 }
3217 //              AppLog("xyzz final strScript length %d",strScript.GetLength());
3218
3219                 __pReaderData = __pWebViewer->EvaluateJavascriptN(pScript);
3220                 if (__pReaderData == null)
3221                 {
3222                         AppLog("MainScene::data is null Error :%s",GetErrorMessage(GetLastResult()));
3223                         __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>");
3224 //                      return;
3225                 }
3226                 AppLogDebug("evaluateJavascript result %s , __pReaderData %ls",GetErrorMessage(GetLastResult()),__pReaderData->GetPointer());
3227                 if (__pReaderData->CompareTo(L"undefined") != 0 && __pReaderData->CompareTo(L"") != 0)
3228                 {
3229                         //__pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_READER);
3230                         SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_READER);
3231                 }
3232                 delete[] pScript;
3233         }
3234
3235
3236         AppLog("MainForm::OnLoadingCompleted done");
3237 }
3238
3239 void
3240 MainForm::OnEstimatedProgress(int progress)
3241 {
3242         AppLogDebug("MainForm::OnEstimatedProgress entered %d",progress);
3243
3244         if (progress < DEFAULT_PROGRESS_PERCENTAGE)
3245                 progress = DEFAULT_PROGRESS_PERCENTAGE;
3246         //if(__pAddressbar)
3247         //      __pAddressbar->UpdateProgress(progress);
3248         UpdateProgress(progress);
3249 }
3250
3251 void MainForm::OnFaviconReceived(const Tizen::Graphics::Bitmap& favicon)
3252 {
3253         AppLog("MainForm::OnFaviconReceived");
3254         if (__pWebViewer != null && __pHistory != null && __pWindowInfo != null && (__pWindowInfo->pageUrl.CompareTo(__pHistory->GetHistoryUrl()) == 0))
3255         {
3256                 Bitmap* favIcon = __pWebViewer->GetFaviconN();
3257                 if(favIcon != null)
3258                 {
3259                         HistoryPresentationModel::GetInstance()->UpdateHistoryFavIcon(*__pHistory, *favIcon);
3260                         delete favIcon;
3261                 }
3262         }
3263 }
3264
3265 void
3266 MainForm::OnUrlValueChanged(Addressbar&)
3267 {
3268         Invalidate(true);
3269 }
3270
3271 void
3272 MainForm::OnUrlSubmitted(Addressbar& addBar)
3273 {
3274         AppLog("MainForm::OnUrlSubmitted");
3275         String url = addBar.GetUrl();
3276         AppLog("MainForm::OnUrlSubmitted url is %ls", url.GetPointer());
3277
3278         if(__pFooterUrlField)
3279                 __pFooterUrlField->SetCursorPosition(__pFooterUrlField->GetTextLength());
3280         AddressBarCancelledClicked(*__pAddressbar);
3281         LoadUrl(url);
3282 }
3283
3284 void
3285 MainForm::LoadUrl(String& url)
3286 {
3287         url.Trim();
3288         String encodedUrl;
3289 //      UrlEncoder::Encode(url, L"UTF-8", encodedUrl);
3290         AppLogDebug("MainForm::LoadUrl enter");
3291
3292         if (__pWebViewer != null)
3293         {
3294                 __pWebViewer->SetShowState(true);
3295                 __pWebViewer->Invalidate(true);
3296         }
3297
3298         if (url.CompareTo(L"") == 0)
3299         {
3300                 return;
3301         }
3302         if(__pFooterPanel != null)
3303         {
3304                 __pFooterPanel->SetShowState(true);
3305                 __pFooterPanel->Invalidate(true);
3306         }
3307         InitWebControl();
3308
3309         bool ret = false;
3310         bool flag = false;
3311
3312         String firstPattern(L"((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))+[\w\d:#@%/;$()~_?\+-=\\\.&]*)");
3313         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)
3314
3315         RegularExpression firstRegex;
3316         RegularExpression secondRegex;
3317
3318         firstRegex.Construct(firstPattern, REGEX_CASELESS);
3319         secondRegex.Construct(secondPattern, REGEX_CASELESS);
3320
3321         // Match
3322         ret = firstRegex.Match(url, false); // This returns true value
3323         flag = secondRegex.Match(url, false);  // Checks whether URL typed is of type  abc.com (i.e without protocol in front of it)
3324
3325         if (ret == true && __pWebViewer != null)
3326         {
3327                 SetUrl(url);
3328                 __pWebViewer->LoadUrl(url);
3329         }
3330         else if(__pWebViewer != null)
3331         {
3332                 String tempUrl = L"http://";
3333                 tempUrl.Append(url);
3334
3335                 if (flag == true)
3336                 {
3337                         __pWebViewer->LoadUrl(tempUrl);
3338                 }
3339                 else
3340                 {
3341                                 UrlEncoder::Encode(url, L"UTF-8", encodedUrl);
3342                         __pWebViewer->LoadUrl(SettingPresentationModel::GetInstance()->GetSearchUrl(encodedUrl));
3343                 }
3344         }
3345         if (__pAddressbar != null)
3346         {
3347                 //__pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING);
3348                 SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING);
3349         }
3350
3351         AppLogDebug("MainForm::LoadUrl exit");
3352
3353         return;
3354
3355 }
3356
3357 void
3358 MainForm::OnFocusGained(const Tizen::Ui::Control& source)
3359 {
3360         AppLog("MainForm::OnFocusGained");
3361         if(__pFooterPanel)
3362         {
3363                 __pFooterPanel->SetShowState(false);
3364         }
3365
3366         if(__pAddressbar)
3367         {
3368                 __pAddressbar->SetShowState(true);
3369                 __pAddressbar->SetAddressbarURLFocus();
3370         }
3371         if(__pFindWordControl && __pFindWordControl->GetShowState() == true)
3372         {
3373                 __currentSearchStr = L"";
3374                 __currentWordIndex = 0;
3375                 __maxOccurrances = 0;
3376
3377                 if (__pFindWordPanelLeftToRight && __pFindWordPanelLeftToRight->GetShowState() == true)
3378                 {
3379                         __pFindWordEditField->SetText(L"");
3380                         __pFindWordEditField->HideKeypad();
3381                         __pFindWordControl->SetShowState(false);
3382                         __pFindWordCountLabel->SetText(L"0/0");
3383                 }
3384                 else if(__pFindWordPanelRightToLeft && __pFindWordPanelRightToLeft->GetShowState() == true)
3385                 {
3386                         __pFindWordEditFieldRightToLeft->SetText(L"");
3387                         __pFindWordEditFieldRightToLeft->HideKeypad();
3388                         __pFindWordControl->SetShowState(false);
3389                         __pFindWordCountLabelRightToLeft->SetText(L"0/0");
3390                 }
3391
3392                 __pFindWordNext->SetEnabled(false);
3393                 __pFindWordPrev->SetEnabled(false);
3394
3395                 __pWebViewer->SearchText(L"aaaabbbbcccc",true);
3396                 __pFindWordControl->SetShowState(false);
3397         }
3398         RelayoutControls(false);
3399 }
3400
3401 void
3402 MainForm::OnFocusLost(const Tizen::Ui::Control& source)
3403 {
3404         AppLog("MainForm::OnFocusLost called");
3405 }
3406
3407 void
3408 MainForm::OnStopClicked(Addressbar& addBar)
3409 {
3410         AppLogDebug("MainForm::OnStopClicked called");
3411         if (__pWebViewer)
3412         {
3413                 //__pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
3414                 SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
3415                 __pWebViewer->StopLoading();
3416                 RequestRedraw(true);
3417         }
3418 }
3419
3420 void
3421 MainForm::OnBackClicked(/*const Addressbar& addBar*/)
3422 {
3423         //      AppLog("MainForm::OnBackClicked");
3424         result r = E_FAILURE;
3425         if(__pImageMenu && __pImageMenu->GetShowState() == true)
3426         {
3427                 AppLog("Hiding the menu");
3428                 __pImageMenu->SetShowState(false);
3429         }
3430
3431         if (__pWebViewer && __pWebViewer->CanGoBack())
3432         {
3433                 __pWebViewer->GoBack();
3434         }
3435         else if(__pWindowInfo && __pWindowInfo->isJavascriptInitiated == false)
3436         {
3437                 UiApp* pApp = null;
3438                 pApp = UiApp::GetInstance();
3439                 if (pApp != null)
3440                 {
3441                         r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
3442                         if (IsFailed(r))
3443                         {
3444                                 AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
3445                                 return;
3446                         }
3447                 }
3448         }
3449         else
3450         {
3451                 UiApp* pApp = null;
3452                 WindowInfo* pWindowInfo = null;
3453                 int totalCount = 0;
3454                 SceneManager* pSceneManager = SceneManager::GetInstance();
3455                 if (pSceneManager == null)
3456                 {
3457                         return;
3458                 }
3459                 ArrayList* pAllWindowList = MultipleWindowPresentationModel::GetInstance()->GetAllWindowArrayList();
3460                 if (pAllWindowList == NULL)
3461                 {
3462                         pApp = UiApp::GetInstance();
3463                         if (pApp != null)
3464                         {
3465                                 r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
3466                                 if (IsFailed(r))
3467                                 {
3468                                         AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
3469                                         return;
3470                                 }
3471                         }
3472                 }
3473                 if (pAllWindowList != null)
3474                 {
3475                         totalCount = pAllWindowList->GetCount();
3476                 }
3477                 for (int count = 0; count < totalCount; count++)
3478                 {
3479                         pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count));
3480                         if (pWindowInfo == null)
3481                         {
3482                                 pApp = UiApp::GetInstance();
3483                                 if (pApp != null)
3484                                 {
3485                                         r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
3486                                         if (IsFailed(r))
3487                                         {
3488                                                 AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
3489                                                 return;
3490                                         }
3491                                 }
3492                         }
3493                         if (pSceneManager != null && pWindowInfo != null && pSceneManager->GetCurrentSceneId() == pWindowInfo->sceneID && pWindowInfo->isJavascriptInitiated == true)
3494                         {
3495                                 r = SceneRegister::DestroyAndUnRegisterScene(pWindowInfo->sceneID);
3496                                 if (IsFailed(r))
3497                                 {
3498                                         AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
3499                                         return;
3500                                 }
3501                                 r = pAllWindowList->RemoveAt(count, true);
3502                                 __pWindowInfo = null;
3503                                 if (IsFailed(r))
3504                                 {
3505                                         AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
3506                                         return;
3507                                 }
3508                                 if(count > 0)
3509                                 {
3510                                         pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(count - 1));
3511                                 }
3512                                 else if(pAllWindowList->GetCount() > 0)
3513                                 {
3514                                         pWindowInfo = dynamic_cast< WindowInfo* >(pAllWindowList->GetAt(pAllWindowList->GetCount() - 1));
3515                                 }
3516                                 else
3517                                 {
3518                                         pApp = UiApp::GetInstance();
3519                                         if (pApp != null)
3520                                         {
3521                                                 r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
3522                                                 return;
3523                                         }
3524
3525                                 }
3526                                 if (pWindowInfo == null)
3527                                 {
3528                                         pApp = UiApp::GetInstance();
3529                                         if (pApp != null)
3530                                         {
3531                                                 r = pApp->GetFrameAt(0)->SetShowMode(FRAME_SHOW_MODE_MINIMIZED);
3532                                                 return;
3533                                         }
3534                                 }
3535                                 else
3536                                 {
3537                                         r = pSceneManager->GoBackward(BackwardSceneTransition(pWindowInfo->sceneID ,SCENE_TRANSITION_ANIMATION_TYPE_NONE));
3538                                         if (IsFailed(r))
3539                                         {
3540                                                 AppLogException("OnActionPerformed failed with %s", GetErrorMessage(r));
3541                                                 return;
3542                                         }
3543                                 }
3544                                 break;
3545                         }
3546
3547                 }
3548
3549         }
3550
3551 }
3552
3553 void
3554 MainForm::OnForwardClicked(/*const Addressbar& addBar*/)
3555 {
3556         AppLog("MainForm::OnForwardClicked");
3557         if (__pWebViewer == null)
3558                 return;
3559
3560         if (__pWebViewer->CanGoForward())
3561         {
3562                 __pWebViewer->GoForward();
3563         }
3564 }
3565
3566 void
3567 MainForm::OnAddressBarFocusGained(const Addressbar& addBar)
3568 {
3569         AppLog("XYZ::MainForm::OnAddressBarFocusGained");
3570         if(__pFooterPanel != null)
3571         {
3572                 __pFooterPanel->SetShowState(false);
3573         }
3574
3575         if (__pAddressbar != null && __pAddressbar->GetShowState() == false)
3576         {
3577                 __pAddressbar->SetShowState(true);
3578                 __pAddressbar->SetBounds(Rectangle(0,0,GetClientAreaBounds().width,__pAddressbar->GetHeight()));
3579         }
3580
3581         RelayoutControls(false);
3582 }
3583
3584 void
3585 MainForm::OnAddressBarFocusLost(const Addressbar& addBar, bool addressbarKeyPadState)
3586 {
3587         AppLog("XYZ::MainForm::OnAddressBarFocusLost");
3588
3589         int Height = GetClientAreaBounds().height;
3590         AppLog("MainForm::OnAddressBarFocusLost height is %d",Height);
3591
3592         RelayoutControls(false);
3593 }
3594
3595 void
3596 MainForm::OnAddressCancelledClicked(const Addressbar& addBar)
3597 {
3598         AddressBarCancelledClicked(addBar);
3599 }
3600
3601 void
3602 MainForm::OnAddressBarModeChanged(/*const Addressbar& addBar*/)
3603 {
3604         __prevAddressBarMode = __curAddressBarMode;
3605
3606         if (__pAddressbar != null)
3607         {
3608                 __curAddressBarMode = GetAddressbarMode();
3609         }
3610
3611         if (__curAddressBarMode == ADDRESSBAR_MODE_EDIT)
3612         {
3613                 __adressPanelPosition.y = 0;
3614                 if (__pAddressbar != null)
3615                 {
3616                         __webControlPosition.y = __pAddressbar->GetHeight() - 12;
3617                         __pAddressbar->SetBounds(Rectangle(0,0,GetClientAreaBounds().width,__pAddressbar->GetHeight()));
3618                         __pAddressbar->Invalidate(true);
3619                 }
3620                 if (__pWebViewer != null)
3621                 {
3622                         __pWebViewer->StopLoading();
3623                 }
3624         }
3625         else if(__curAddressBarMode == ADDRESSBAR_MODE_LOADING)
3626         {
3627                 __adressPanelPosition.y = 0;
3628                 if (__pAddressbar != null)
3629                 {
3630                         __webControlPosition.y = 0;
3631                         __pAddressbar->SetBounds(Rectangle(0, __pAddressbar->GetY() - __pAddressbar->GetHeight(), GetClientAreaBounds().width, __pAddressbar->GetHeight()));
3632                         __pAddressbar->Invalidate(true);
3633                 }
3634         }
3635 }
3636
3637 void
3638 MainForm::OnClipboardClosed(const Addressbar& addBar)
3639 {
3640         AppLog("XYZ::MainForm::OnClipboardClosed");
3641         if (__pFooterPanel && __pAddressbar->GetShowState() == false)
3642         {
3643                 AppLog("akjshdasd 3");
3644                 __pFooterPanel->SetShowState(true);
3645         }
3646         __isKeypadOpened = false;
3647         RelayoutControls(false);
3648 }
3649
3650 void
3651 MainForm::OnAddressBarKeypadClosed(const Addressbar& addBar, bool footerState)
3652 {
3653         AppLog("XYZ::MainForm::OnAddressBarKeypadClosed");
3654         if (__pFooterPanel && __pAddressbar->GetShowState() == false)
3655         {
3656                 AppLog("akjshdasd 3");
3657                 __pFooterPanel->SetShowState(true);
3658         }
3659         __isKeypadOpened = false;
3660
3661         RelayoutControls(false,footerState);
3662 }
3663
3664 void
3665 MainForm::OnAddressBarKeypadOpened(const Addressbar& addBar)
3666 {
3667         AppLog("XYZ::MainForm::OnAddressBarKeypadOpened");
3668         __isKeypadOpened = true;
3669         RelayoutControls(false);
3670 }
3671
3672 void
3673 MainForm::OnAddressBarKeypadWillOpen(const Addressbar& addBar)
3674 {
3675         __isKeypadOpened = true;
3676         __pFooterPanel->SetShowState(false);
3677 }
3678
3679 void
3680 MainForm::OnAddressBarKeypadBoundsChanged(const Addressbar& addBar)
3681 {
3682         AppLog("XYZ::MainForm::OnAddressBarKeypadBoundsChanged");
3683         RelayoutControls(false);
3684 }
3685
3686 void
3687 MainForm::OnPageTitleReceived(const Tizen::Base::String& title)
3688 {
3689         AppLog("MainForm::OnPageTitleReceived %ls",title.GetPointer());
3690         if (__pWindowInfo)
3691         {
3692                 __pWindowInfo->pageTitle = title;
3693                 if (__pWebViewer != null)
3694                 {
3695                         __pWindowInfo->pageUrl = __pWebViewer->GetUrl();
3696                         AppLog("MainForm::OnPageTitleReceived url %ls",__pWindowInfo->pageUrl.GetPointer());
3697                 }
3698         }
3699         if (__pAddressbar != null && __pWebViewer != null)
3700         {
3701                 SetUrl(__pWebViewer->GetUrl());
3702                 __pAddressbar->Invalidate(true);
3703         }
3704 }
3705
3706 void
3707 MainForm::UpdateFavicon(void)
3708 {
3709         bool urlImageType = false;
3710         String *tempPath = null;
3711         if(__pWebViewer)
3712                 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();");
3713         Bitmap* pBitmap = null;
3714
3715         if (tempPath && tempPath->GetLength() > 0 && tempPath->CompareTo(L"undefined") != 0)
3716         {
3717                 if (__pWindowInfo != null)
3718                 {
3719                         Uri url;
3720                         url.SetUri(*tempPath);
3721                         if (url.GetHost().GetLength() == 0)
3722                         {
3723                                 Uri webUrl;
3724                                 webUrl.SetUri(__pWebViewer->GetUrl());
3725                                 result r = url.SetHost(webUrl.GetHost());
3726                                 if(IsFailed(r))
3727                                 {
3728                                         delete tempPath;
3729                                         return;
3730                                 }
3731                         }
3732                         if (url.GetScheme().GetLength() == 0)
3733                         {
3734                                 Uri webUrl;
3735                                 webUrl.SetUri(__pWebViewer->GetUrl());
3736                                 url.SetScheme(webUrl.GetScheme());
3737                         }
3738                         __pWindowInfo->faviconUrl = url.ToString();
3739
3740                         pBitmap = __pWebViewer->GetFaviconN();
3741
3742                         if (pBitmap != null)
3743                         {
3744                                 if (__pWindowInfo->pFavicon != NULL)
3745                                 {
3746                                         __pWindowInfo->pFavicon = null;
3747                                 }
3748                                 __pWindowInfo->pFavicon = new(std::nothrow) Bitmap();
3749                                 __pWindowInfo->pFavicon->Construct(*pBitmap,Rectangle(0,0,pBitmap->GetWidth(),pBitmap->GetHeight()));
3750
3751                                 __pAddressbar->SetFaviconBitmap(*__pWindowInfo->pFavicon);
3752
3753                                 FaviconManager::GetInstance()->SaveFavicon(*__pWindowInfo->pFavicon, __pWindowInfo->faviconUrl);
3754                         }
3755                         else if(__pWindowInfo->pFavicon != null)
3756                         {
3757                                 __pAddressbar->SetFaviconBitmap(*__pWindowInfo->pFavicon);
3758                         }
3759                         else
3760                         {
3761                                 Bitmap *pDefaultBmp = FaviconManager::GetInstance()->GetDefaultFaviconN();
3762                                 if(pDefaultBmp != null)
3763                                 {
3764                                         __pAddressbar->SetFaviconBitmap(*pDefaultBmp);
3765                                 }
3766                         }
3767                         if(pBitmap)
3768                         {
3769                                 delete pBitmap;
3770                                 pBitmap = null;
3771                         }
3772                 }
3773                 delete tempPath;
3774         }
3775         else
3776         {
3777                 // do not remove
3778                 if(tempPath != null)
3779                 {
3780                         delete tempPath;
3781                 }
3782                 AppLogDebug("Error occured: %s", GetErrorMessage(GetLastResult()));
3783         }
3784
3785 }
3786
3787 bool
3788 MainForm::OnLoadingRequested(const Tizen::Base::String& url,
3789                 Tizen::Web::Controls::WebNavigationType type)
3790 {
3791         AppLog("urlk %ls",url.GetPointer());
3792         // when load new page if find word panel is open its show state is false
3793         if(__pFindWordControl && __pFindWordControl->GetShowState() == true)
3794         {
3795                 __currentSearchStr = L"";
3796                 __currentWordIndex = 0;
3797                 __maxOccurrances = 0;
3798                 __pFindWordEditField->SetText(L"");
3799                 __pFindWordNext->SetEnabled(false);
3800                 __pFindWordPrev->SetEnabled(false);
3801                 __pFindWordCountLabel->SetText(L"0/0");
3802                 __pFindWordControl->SetShowState(false);
3803                 __pFindWordEditField->HideKeypad();
3804                 RelayoutControls(false);
3805         }
3806
3807         __pFooterPanel->Invalidate(true);
3808
3809         Uri uriInfo;
3810         uriInfo.SetUri(url);
3811
3812         if(url.Contains(IDS_TIZEN_SERVICE))
3813         {
3814                 String appId;
3815                 String delim(L":;,");
3816
3817                 // Creates a StringTokenizer instance
3818                 StringTokenizer strTok(url, delim);
3819
3820                 int count = strTok.GetTokenCount();     // count == 4
3821
3822                 HashMap *pMap = new HashMap();
3823                 pMap->Construct();
3824
3825                 String token;
3826                 String key;
3827                 String value;
3828                 while (strTok.HasMoreTokens())
3829                 {
3830                         AppLog("Token: %ls", token.GetPointer());
3831                         strTok.GetNextToken(token);         // Tizen, StringTokenizer, Sample, code
3832                         if(token.Contains(IDS_APPID))
3833                         {
3834                                 token.SubString(6, appId);
3835                                 AppLog("AppID:%ls", appId.GetPointer());
3836                         }
3837                         else if(token.Contains(IDS_KEY))
3838                         {
3839                                 token.SubString(4, key);
3840                                 AppLog("key:%ls", key.GetPointer());
3841                         }
3842                         else if(token.Contains(IDS_VALUE))
3843                         {
3844                                 token.SubString(6, value);
3845                                 AppLog("value:%ls", value.GetPointer());
3846                         }
3847                 }
3848                 pMap->Add(key, value);
3849
3850                 if(appId != "")
3851                 {
3852                         AppControl *pAppControl = null;
3853                         String operationId = L"http://tizen.org/appcontrol/operation/main";
3854                         pAppControl = dynamic_cast<AppControl*>(AppManager::FindAppControlN(appId, operationId));
3855                         if(pAppControl)
3856                         {
3857                                 result r = pAppControl->Start(null, null, pMap, null);
3858                         }
3859                         else
3860                         {
3861                                 AppLogException("AppControl not found");
3862                         }
3863                         return true;
3864                 }
3865         }
3866
3867         return false;
3868 }
3869
3870 DecisionPolicy
3871 MainForm::OnWebDataReceived(const Tizen::Base::String& mime,
3872                 const Tizen::Net::Http::HttpHeader& httpHeader)
3873 {
3874         return Tizen::Web::Controls::WEB_DECISION_CONTINUE;
3875 }
3876
3877 void
3878 MainForm::OnWebPageBlockSelected(Web& source, FloatPoint& startPoint, FloatPoint& endPoint)
3879 {
3880         if(__isLongPressedDone == false)
3881                 return;
3882         AppLog("MainForm::OnWebPageBlockSelected");
3883         if (__pHitElementResult != null)
3884         {
3885                 delete __pHitElementResult;
3886                 __pHitElementResult = null;
3887         }
3888
3889         if (__pWebViewer != null)
3890         {
3891                 AppLog("MainForm::OnWebPageBlockSelected web not null");
3892                 __pHitElementResult = __pWebViewer->GetElementByPointN(startPoint);
3893
3894                 if(GetLastResult() == E_INVALID_ARG || (__pHitElementResult->GetTagName().CompareTo(L"INPUT") != 0 && __pHitElementResult->GetTagName().CompareTo(L"TEXTAREA") != 0))
3895                 {
3896                         AppLog("datafirst startpoint error %s",GetErrorMessage(GetLastResult()));
3897                         __pHitElementResult = __pWebViewer->GetElementByPointN(endPoint);
3898                         if(GetLastResult() == E_INVALID_ARG || (__pHitElementResult->GetTagName().CompareTo(L"INPUT") != 0 && __pHitElementResult->GetTagName().CompareTo(L"TEXTAREA") != 0))
3899                         {
3900                                 __pHitElementResult = __pWebViewer->GetElementByPointN(__longPressPoint);
3901                         }
3902                         AppLog("datafirst endpoint error %s",GetErrorMessage(GetLastResult()));
3903                 }
3904         }
3905
3906         if (__pHitElementResult == null)
3907         {
3908                 return;
3909         }
3910
3911         if (__pHitElementResult->HasImage() != true)
3912         {
3913                 String tagName = __pHitElementResult->GetTagName();
3914                 String type = __pHitElementResult->GetAttributeValue("type");
3915
3916
3917                 AppLog("TagName %ls",tagName.GetPointer());
3918                 __currentSelectedStr.Clear();
3919                 AppLog("__currentSelectedStr after clear %ls",__currentSelectedStr.GetPointer());
3920                 __currentSelectedStr = __pWebViewer->GetTextFromBlock();
3921                 AppLog("__currentSelectedStr after GetTextFromBlock %ls",__currentSelectedStr.GetPointer());
3922                 if(tagName.Equals(L"TEXTAREA",false) == true)
3923                 {
3924                         AppLog("Tagnameseemstobe TEXTAREA");
3925                 }
3926                 else if(tagName.Equals(L"INPUT",false) == true)
3927                 {
3928                         AppLog("Tagnameseemstobe INPUT");
3929                 }
3930
3931                 if (((tagName.Equals(L"INPUT",false) == true)  || tagName.Equals(L"TEXTAREA",false) == true) /*&& __isLongPressedDone == true*/ && __currentSelectedStr.CompareTo(L"") !=0)
3932                 {
3933                         AppLog("MainForm::OnWebPageBlockSelected show paste option");
3934
3935                         InitSelectTextContextMenuF(FloatPoint(endPoint.x,endPoint.y + __pWebViewer->GetY()),true);
3936                         __pImageMenu->SetShowState(true);
3937                         __pImageMenu->Show();
3938                         __pImageMenu->Invalidate(true);
3939                 }
3940                 else /*if(__isLongPressedDone == true)*/
3941                 {
3942                         AppLog("MainForm::OnWebPageBlockSelected no paste option");
3943
3944                         if(__pHitElementResult->GetUrl().GetLength() > 0)
3945                         {
3946                                 __currentSelectedStr.Clear();
3947                                 __currentSelectedStr = __pHitElementResult->GetUrl();
3948                         }
3949                         InitSelectTextContextMenuF(FloatPoint(endPoint.x,endPoint.y + __pWebViewer->GetY()),false);
3950                         __pImageMenu->SetShowState(true);
3951                         __pImageMenu->Show();
3952                         __pImageMenu->Invalidate(true);
3953                 }
3954
3955                 AppLog("MainForm::OnWebPageBlockSelected block text is %ls",__currentSelectedStr.GetPointer());
3956                 AppLog("MainForm::OnWebPageBlockSelected tag name is %ls",tagName.GetPointer());
3957                 AppLog("MainForm::OnWebPageBlockSelected type name is %ls",type.GetPointer());
3958         }
3959
3960 }
3961
3962 void
3963 MainForm::OnWebPageShowRequested(Tizen::Web::Controls::Web& source)
3964 {
3965
3966 }
3967
3968 Web*
3969 MainForm::OnWebWindowCreateRequested(void)
3970 {
3971         WindowInfo* pNewWindowInfo = MultipleWindowPresentationModel::GetInstance()->CreateNewMainViewSceneN();
3972
3973         if (pNewWindowInfo == null)
3974         {
3975                 return null;
3976         }
3977         result r = E_SUCCESS;
3978         SceneManager* pSceneManager = SceneManager::GetInstance();
3979         if (pSceneManager == NULL)
3980         {
3981                 return null;
3982         }
3983         ArrayList* pArgList = new(std::nothrow) ArrayList();
3984         if (pArgList == NULL)
3985         {
3986                 return null;
3987         }
3988         r = pArgList->Construct();
3989         if (r == E_SUCCESS)
3990         {
3991                 pNewWindowInfo->isJavascriptInitiated = true;
3992                 pArgList->Add(*pNewWindowInfo);
3993                 r = pSceneManager->GoForward(ForwardSceneTransition(pNewWindowInfo->sceneID, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
3994                 delete pArgList;
3995                 if (IsFailed(r))
3996                 {
3997                         AppLogDebug("EditHistoryListForm::OnFormBackRequested Failed to GoBackward %s",GetErrorMessage(r));
3998                         return null;
3999                 }
4000         } else {
4001                 delete pArgList;
4002         }
4003
4004         return pNewWindowInfo->pCurrentWeb;
4005 }
4006
4007 void
4008 MainForm::RelayoutControls(bool showAddressbar,bool relayoutFooter)
4009 {
4010         AppLog("xyz:: MainForm::RelayoutControls called");
4011         __webControlPosition.y = 0;
4012         __webControlHeight = GetClientAreaBounds().height;
4013         AppLog("Client area height: %d", __webControlHeight);
4014
4015         AppLog("Client area height: %d", __webControlHeight);
4016         if(__pAddressbar != null && __pAddressbar->GetShowState() == true)
4017         {
4018                 __webControlPosition.y += __pAddressbar->GetHeight();
4019                 __webControlHeight -= __pAddressbar->GetHeight();
4020                 __pAddressbar->SetBounds(0, 0, __pAddressbar->GetWidth(), __pAddressbar->GetHeight());
4021         }
4022         else if(__pFindWordControl != null && __pFindWordControl->GetShowState() == true)
4023         {
4024                 __webControlPosition.y += __pFindWordControl->GetHeight();
4025                 __webControlHeight -= __pFindWordControl->GetHeight();
4026                 __pFindWordControl->SetBounds(0, 0, GetClientAreaBounds().width, __pFindWordControl->GetHeight());
4027         }
4028
4029         if(__pFooterPanel != null && __pFooterPanel->GetShowState() == true && relayoutFooter == true)
4030         {
4031                 __webControlHeight -= __pFooterPanel->GetHeight();
4032
4033                 __pFooterPanel->SetBounds(0, __webControlPosition.y + __webControlHeight, GetClientAreaBounds().width, __pFooterPanel->GetHeight());
4034         }
4035         if (__pWebViewer != null && __pWebViewer->GetShowState() == true)
4036         {
4037                 if(__pWebViewer->GetX() == 0 && __pWebViewer->GetY() == __webControlPosition.y &&__pWebViewer->GetWidth() == GetClientAreaBounds().width &&__pWebViewer->GetHeight() == __webControlHeight + 12 )
4038                 {
4039                 }
4040                 else
4041                 {
4042                         __pWebViewer->SetBounds(0, __webControlPosition.y, GetClientAreaBounds().width, __webControlHeight + 12);
4043                         AppLog("xyz:: MainForm::RelayoutControls called __webControlHeight %d",__webControlHeight);
4044                         __pWebViewer->Invalidate(false);
4045                 }
4046         }
4047         if(__pMostVisitedListView != null && __pAddressbar != null && __pFooterPanel != null)
4048         {
4049                 __pMostVisitedListView->SetBounds(Tizen::Graphics::Rectangle(0,__webControlPosition.y , GetClientAreaBounds().width, __webControlHeight));
4050         }
4051
4052         Invalidate(true);
4053 }
4054
4055 void
4056 MainForm::ShowFindWordPanel(bool show , bool isTouchPressed)
4057 {
4058         if (__pFindWordControl == null)
4059         {
4060                 return;
4061         }
4062
4063         Tizen::Locales::LocaleManager localeManager;
4064         Tizen::Locales::Locale local = localeManager.GetSystemLocale();
4065
4066         String languageCode;
4067         result r = SettingInfo::GetValue(L"Language", languageCode);
4068         // int languagecode = local.GetLanguageCode();
4069         AppLog("rahul language is %S", languageCode.GetPointer());
4070
4071         if (show == true)
4072         {
4073                 InitFindWordPanel();
4074
4075                 if (languageCode.CompareTo("ara") == 0)
4076                 {
4077                         AppLog("rahul language is arabic");
4078
4079                         __pFindWordPanelLeftToRight->SetShowState(false);
4080                         __pFindWordPanelRightToLeft->SetShowState(true);
4081
4082                         __pFindWordClear->SetShowState(false);
4083                         __pFindWordCountLabel->SetShowState(false);
4084                         __pFindWordEditField->SetShowState(false);
4085
4086                         __pFindWordClearRightToLeft->SetShowState(true);
4087                         __pFindWordCountLabelRightToLeft->SetShowState(true);
4088                         __pFindWordEditFieldRightToLeft->SetShowState(true);
4089                 }
4090                 else
4091                 {
4092                         AppLog("rahul language is not arabic");
4093
4094
4095                         __pFindWordPanelLeftToRight->SetShowState(true);
4096                         __pFindWordPanelRightToLeft->SetShowState(false);
4097
4098                         __pFindWordClear->SetShowState(true);
4099                         __pFindWordCountLabel->SetShowState(true);
4100                         __pFindWordEditField->SetShowState(true);
4101
4102                         __pFindWordClearRightToLeft->SetShowState(false);
4103                         __pFindWordCountLabelRightToLeft->SetShowState(false);
4104                         __pFindWordEditFieldRightToLeft->SetShowState(false);
4105                 }
4106                 __pFindWordControl->SetShowState(true);
4107         }
4108         else
4109         {
4110                 if(__pFindWordControl != null)
4111                 {
4112                         __pFindWordControl->SetShowState(false);
4113                 }
4114         }
4115
4116         AppLog("MainForm::ShowFindWordPanel %d",show);
4117         if (show && !isTouchPressed)
4118         {
4119                 if (languageCode.CompareTo("ara") == 0)
4120                 {
4121                         if (__pFindWordEditFieldRightToLeft)
4122                         {
4123                                 __pFindWordEditFieldRightToLeft->SetFocus();
4124                                 __pFindWordEditFieldRightToLeft->ShowKeypad();
4125                         }
4126                 }
4127                 else
4128                 {
4129                         if (__pFindWordEditField)
4130                         {
4131                                 __pFindWordEditField->SetFocus();
4132                                 __pFindWordEditField->ShowKeypad();
4133                         }
4134                 }
4135         }
4136         else
4137         {
4138                 if (languageCode.CompareTo("ara") == 0)
4139                 {
4140                         if (__pFindWordEditFieldRightToLeft)
4141                                 __pFindWordEditFieldRightToLeft->HideKeypad();
4142                 }
4143                 else
4144                 {
4145                         if (__pFindWordEditField)
4146                                 __pFindWordEditField->HideKeypad();
4147                 }
4148         }
4149
4150         RelayoutControls(false);
4151 }
4152
4153 void
4154 MainForm::StartWordSearch()
4155 {
4156         //Get the count of occurances of the word in the current page
4157         __maxOccurrances = 0;
4158         __currentWordIndex = 0;
4159
4160         __pFindWordPrev->SetEnabled(false);
4161         String *pCountStr = null;
4162         result r = __pWebViewer->SearchTextAllAsync(__currentSearchStr, false);
4163         AppLog("Search Result %s",GetErrorMessage(r));
4164         /*__pWebViewer->EvaluateJavascriptN(L"document.body.textContent.match(/"  + __currentSearchStr + "/gi).length;");
4165         if (pCountStr != null)
4166         {
4167                 Integer::Parse(*pCountStr, 10, __maxOccurrances);
4168                 delete pCountStr;
4169         }
4170
4171         AppLogDebug("'%ls' is found %d times", __currentSearchStr.GetPointer(), __maxOccurrances);
4172          */
4173
4174 }
4175
4176 void MainForm::OnTextFound(int totalCount, int currentOrdinal)
4177 {
4178         AppLog("MainForm::OnTextFound totalCount %d",totalCount);
4179         AppLog("MainForm::OnTextFound currentOrdinal %d",currentOrdinal);
4180
4181         if(totalCount == -1 || totalCount == 0)
4182         {
4183                 __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),84,__pFindWordCountLabel->GetHeight());
4184                 __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),214+80,__pFindWordEditField->GetHeight());
4185 //              return;
4186         }
4187         else if(totalCount > 100)
4188         {
4189                 __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),124,__pFindWordCountLabel->GetHeight());
4190                 __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),174,__pFindWordEditField->GetHeight());
4191         }
4192         else
4193         {
4194                 __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),124,__pFindWordCountLabel->GetHeight());
4195                 __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),174,__pFindWordEditField->GetHeight());
4196         }
4197
4198         __maxOccurrances = totalCount;
4199         __currentWordIndex = currentOrdinal;
4200
4201         //Reset the UI controls as per the maxOccurrance value
4202         if (totalCount <= 0)
4203         {
4204                 AppLog("Word not found");
4205                 //Show error notification to user
4206                 __pFindWordNext->SetEnabled(false);
4207                 if(__pFindWordCountLabel && __pFindWordCountLabel->GetShowState() == true)
4208                 {
4209                         __pFindWordCountLabel->SetText(L"0/0");
4210                         __pFindWordCountLabel->Invalidate(false);
4211                 }
4212                 else if(__pFindWordCountLabelRightToLeft && __pFindWordCountLabelRightToLeft->GetShowState() == true)
4213                 {
4214                         __pFindWordCountLabelRightToLeft->SetText(L"0/0");
4215                         __pFindWordCountLabelRightToLeft->Invalidate(false);
4216                 }
4217                 __pFindWordNext->Invalidate(false);
4218                 __pFindWordPrev->Invalidate(false);
4219
4220                 return;
4221         }
4222
4223         if (totalCount == 1)
4224         {
4225                 __pFindWordNext->SetEnabled(false);
4226         }
4227         else
4228         {
4229                 __pFindWordNext->SetEnabled(true);
4230         }
4231
4232         String countStr = L"";
4233         countStr.Append(__currentWordIndex);
4234         countStr.Append(L"/");
4235         countStr.Append(__maxOccurrances);
4236         if (__pFindWordCountLabel && __pFindWordCountLabel->GetShowState() == true)
4237         {
4238         __pFindWordCountLabel->SetText(countStr);
4239         __pFindWordCountLabel->Invalidate(false);
4240         __pFindWordCountLabel->Invalidate(false);
4241         }
4242         else if(__pFindWordCountLabelRightToLeft && __pFindWordCountLabelRightToLeft->GetShowState() == true)
4243         {
4244                 __pFindWordCountLabelRightToLeft->SetText(countStr);
4245                 __pFindWordCountLabelRightToLeft->Invalidate(false);
4246                 __pFindWordCountLabelRightToLeft->Invalidate(false);
4247         }
4248         //FindNextWord(true);
4249         //Update the controls
4250         __pFindWordNext->Invalidate(false);
4251         __pFindWordPrev->Invalidate(false);
4252
4253 }
4254
4255 void
4256 MainForm::FindNextWord(bool next)
4257 {
4258         if (next == true)
4259         {
4260                 //if (__pWebViewer->SearchText(__currentSearchStr, true) == true)
4261                         if (__pWebViewer->SearchNextAsync(true) == E_SUCCESS)
4262                         {
4263                                 if (__currentWordIndex < __maxOccurrances)
4264                                 {
4265                                         __currentWordIndex++;
4266                                 }
4267                         }
4268         }
4269         else
4270         {
4271                 //if (__pWebViewer->SearchText(__currentSearchStr, false) == true)
4272                 if (__pWebViewer->SearchNextAsync(false) == E_SUCCESS)
4273                 {
4274                         if(__currentWordIndex > 1)
4275                         {
4276                                 __currentWordIndex--;
4277                         }
4278                 }
4279         }
4280
4281         String countStr = L"";
4282         countStr.Append(__currentWordIndex);
4283         countStr.Append(L"/");
4284         countStr.Append(__maxOccurrances);
4285
4286         if (__pFindWordCountLabel && __pFindWordCountLabel->GetShowState() == true)
4287         {
4288         __pFindWordCountLabel->SetText(countStr);
4289         __pFindWordCountLabel->Invalidate(false);
4290         }
4291         else if(__pFindWordCountLabelRightToLeft && __pFindWordCountLabelRightToLeft->GetShowState() == true)
4292         {
4293                 __pFindWordCountLabelRightToLeft->SetText(countStr);
4294                 __pFindWordCountLabelRightToLeft->Invalidate(false);
4295         }
4296
4297         if (__currentWordIndex >= __maxOccurrances)
4298         {
4299                 __pFindWordNext->SetEnabled(false);
4300         }
4301         else
4302         {
4303                 __pFindWordNext->SetEnabled(true);
4304         }
4305         if (__currentWordIndex <= 1)
4306         {
4307                 __pFindWordPrev->SetEnabled(false);
4308         }
4309         else
4310         {
4311                 __pFindWordPrev->SetEnabled(true);
4312         }
4313         __pFindWordPrev->Invalidate(false);
4314         __pFindWordNext->Invalidate(false);
4315
4316         __pFindWordControl->Invalidate(true);
4317 }
4318
4319 void
4320 MainForm::OnWebKeypadWillOpen(Tizen::Web::Controls::Web& source)
4321 {
4322         AppLog("xyz::MainForm::OnWebKeypadWillOpen");
4323         __isKeypadOpened = true;
4324         __pFooterPanel->SetShowState(false);
4325         //      OnAddressBarKeypadOpened(*__pAddressbar);
4326 }
4327
4328 void
4329 MainForm::OnWebKeypadOpened(Tizen::Web::Controls::Web& source)
4330 {
4331         __isKeypadOpened = true;
4332         AppLog("xyz::MainForm::OnWebKeypadOpened");
4333
4334         if(__pFindWordControl && __pFindWordControl->GetShowState() == true)
4335         {
4336                 __currentSearchStr = L"";
4337                 __currentWordIndex = 0;
4338                 __maxOccurrances = 0;
4339                 __pFindWordEditField->SetText(L"");
4340                 __pFindWordNext->SetEnabled(false);
4341                 __pFindWordPrev->SetEnabled(false);
4342                 __pFindWordCountLabel->SetText(L"0/0");
4343                 __pWebViewer->SearchTextAllAsync(L"",false);
4344                 __pFindWordControl->SetShowState(false);
4345                 __pFindWordEditField->HideKeypad();
4346         }
4347
4348
4349         if (__pWebViewer != null && __pFooterPanel != null)
4350         {
4351                 AppLog("MainForm::OnWebKeypadOpened GetClientAreaBounds().height %d ", GetClientAreaBounds().height);
4352                 if(__pAddressbar != null)
4353                 {
4354                         __pAddressbar->SetShowState(false);
4355                 }
4356                 if(__pFindWordControl != null)
4357                 {
4358                         __pFindWordControl->SetShowState(false);
4359                 }
4360                 __pFooterPanel->SetShowState(false);
4361                 __pWebViewer->SetBounds(Rectangle(0, 0,GetClientAreaBounds().width, GetClientAreaBounds().height));
4362         }
4363 //      if(__pImageMenu && __pImageMenu->GetShowState() == true)
4364 //      {
4365 //              __pImageMenu->SetAnchorPosition(Point(__pImageMenu->GetAnchorPosition().x/2,__pImageMenu->GetAnchorPosition().y/2));
4366 //              AppLog("omgomgomg");
4367 //      }
4368         Invalidate(true);
4369 }
4370
4371 void
4372 MainForm::OnWebKeypadClosed(Tizen::Web::Controls::Web& source)
4373 {
4374         AppLog("xyz::MainForm::OnWebKeypadClosed");
4375         AppLog("akjshdasd 4");
4376         __pFooterPanel->SetShowState(true);
4377 //      OnAddressBarKeypadClosed(*__pAddressbar);
4378         RelayoutControls(false);
4379         __isKeypadOpened = false;
4380 }
4381
4382 void
4383 MainForm::OnWebKeypadBoundsChanged(Tizen::Web::Controls::Web& source)
4384 {
4385         //      RelativeLayout(false);
4386         if(__pWebViewer != null)
4387         {
4388                 __pWebViewer->SetBounds(Rectangle(0,__webControlPosition.y,GetClientAreaBounds().width,GetClientAreaBounds().height));
4389         }
4390 }
4391
4392 void
4393 MainForm::OnTouchDoublePressed(const Control& source, const Point& currentPosition, const TouchEventInfo& touchInfo)
4394 {
4395         Control* temp = const_cast< Control* >(&source);
4396         Header* pHeader = dynamic_cast< Header* >(temp);
4397         if (pHeader != null)
4398         {
4399                 //Header double - clicked
4400                 AppLog("Header double clicked");
4401         }
4402         if(__pFindWordControl)
4403         {
4404                 AppLog("MainForm::OnTouchPressed %d",__pFindWordControl->GetShowState());
4405                 ShowFindWordPanel(__pFindWordControl->GetShowState(), true);
4406         }
4407
4408
4409         AppLog("MainScene::OnTouchDoublePressed");
4410
4411 }
4412
4413 void MainForm::OnTouchLongPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
4414 {
4415         AppLog("abcde::MainForm::OnTouchLongPressed %d, %d" ,currentPosition.x,currentPosition.y);
4416         if(TouchEventManager::GetInstance()->GetTouchInfoListN()->GetCount() >1)
4417         {
4418                 AppLog("Returning because of more than one touch point.");
4419                 return;
4420         }
4421         __longPressPoint = currentPosition;
4422
4423         if (__pHitElementResult != null)
4424         {
4425                 delete __pHitElementResult;
4426                 __pHitElementResult = null;
4427         }
4428
4429         if (__pWebViewer != null)
4430         {
4431                 AppLog("MainForm::OnTouchLongPressed web not null");
4432                 __pHitElementResult = __pWebViewer->GetElementByPointN(currentPosition);
4433         }
4434
4435         if (__pHitElementResult == null)
4436         {
4437                 return;
4438         }
4439
4440         if (__pHitElementResult->HasImage() == true)
4441         {
4442                 if(__pWebViewer != null)
4443                         InitImageContextMenu(Point(currentPosition.x,currentPosition.y + __pWebViewer->GetY()));
4444                 __pImageMenu->SetShowState(true);
4445                 __pImageMenu->Show();
4446                 __pImageMenu->Invalidate(true);
4447         }
4448         else if(__pHitElementResult->HasUrl() == true)
4449         {
4450                 String tempURl = __pHitElementResult->GetUrl();
4451                 AppLog("tempURl is %ls", tempURl.GetPointer());
4452                 const Bitmap* pBitmap = __pHitElementResult->GetImage();
4453                 if (pBitmap != null)
4454                 {
4455                         AppLog("not null");
4456                 }
4457                 else
4458                 {
4459                         AppLog(null);
4460                 }
4461                 InitImageLinkContextMenu(Point(currentPosition.x,currentPosition.y + __pWebViewer->GetY()));
4462                 __pImageMenu->SetShowState(true);
4463                 __pImageMenu->Show();
4464                 __pImageMenu->Invalidate(true);
4465         }
4466         else
4467         {
4468                 String tagName = __pHitElementResult->GetTagName();
4469                 String type = __pHitElementResult->GetAttributeValue("type");
4470                 String value = __pHitElementResult->GetAttributeValue(L"value");
4471                 String innerHtml = __pHitElementResult->GetAttributeValue(L"innerHTML");
4472
4473                 __currentSelectedStr.Clear();
4474                 __currentSelectedStr = __pWebViewer->GetTextFromBlock();
4475
4476                 AppLog("tag name is %ls", tagName.GetPointer());
4477                 AppLog("type is %ls", type.GetPointer());
4478
4479
4480
4481                 __isLongPressedDone = true;
4482                 result r =__pWebViewer->SetBlockSelectionPosition(currentPosition);
4483                 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)
4484                 {
4485                         AppLog("MainForm::OnWebPageBlockSelected show paste option");
4486
4487                         InitSelectTextContextMenu(Point(currentPosition.x , currentPosition.y + __pWebViewer->GetY()),true, true);
4488                         if(__pImageMenu)
4489                         {
4490                                 __pImageMenu->SetShowState(true);
4491                                 __pImageMenu->Show();
4492                                 __pImageMenu->Invalidate(true);
4493                         }
4494                 }
4495                 AppLog("setselectionselectedornot %s",GetErrorMessage(r));
4496
4497         }
4498 //      __inputEventToBeSupressed = true;
4499 }
4500
4501 void
4502 MainForm::OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
4503 {
4504         AppLog("xyz:: MainForm::OnTouchReleased called");
4505
4506         if (__pAddressbar && __pAddressbar->GetShowState() == true)
4507         {
4508                 __pAddressbar->SetShowState(false);
4509         }
4510         if(__pFooterPanel && __isKeypadOpened == false)
4511         {
4512                 __pFooterPanel->SetShowState(true);
4513         }
4514
4515         // Not reuired now.
4516         /*HitElementResult* pHitElement = __pWebViewer->GetElementByPointN(currentPosition);
4517         if(pHitElement != null && pHitElement->HasUrl() == true && __inputEventToBeSupressed == true)
4518         {
4519                 __pWebViewer->ConsumeInputEvent();
4520         }
4521         if(pHitElement != null)
4522         {
4523                 delete pHitElement;
4524         }
4525         __inputEventToBeSupressed = false;*/
4526 }
4527
4528 bool
4529 MainForm::OnTouchPressed(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4530 {
4531
4532         return true;
4533 }
4534
4535 bool
4536 MainForm::OnTouchReleased(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4537 {
4538         if(__pFindWordControl && __pFindWordControl->GetShowState() == true)
4539         {
4540                 __currentSearchStr = L"";
4541                 __currentWordIndex = 0;
4542                 __maxOccurrances = 0;
4543
4544                 if (__pFindWordPanelLeftToRight && __pFindWordPanelLeftToRight->GetShowState() == true)
4545                 {
4546                         __pFindWordEditField->SetText(L"");
4547                         __pFindWordEditField->HideKeypad();
4548                         __pFindWordControl->SetShowState(false);
4549                         __pFindWordCountLabel->SetText(L"0/0");
4550                 }
4551                 else if(__pFindWordPanelRightToLeft && __pFindWordPanelRightToLeft->GetShowState() == true)
4552                 {
4553                         __pFindWordEditFieldRightToLeft->SetText(L"");
4554                         __pFindWordEditFieldRightToLeft->HideKeypad();
4555                         __pFindWordControl->SetShowState(false);
4556                         __pFindWordCountLabelRightToLeft->SetText(L"0/0");
4557                 }
4558
4559                 __pFindWordNext->SetEnabled(false);
4560                 __pFindWordPrev->SetEnabled(false);
4561
4562                 __pWebViewer->SearchText(L"aaaabbbbcccc",true);
4563                 __pFindWordControl->SetShowState(false);
4564         }
4565         AppLog("__pAddressbar->GetShowState() %d",__pAddressbar->GetShowState());
4566         if(__pAddressbar->GetShowState() == false)
4567         {
4568                 __pAddressbar->SetAddressbarURLFocus();
4569                 __pFooterPanel->SetShowState(false);
4570         }
4571
4572         return false;
4573 }
4574
4575 bool
4576 MainForm::OnTouchMoved(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4577 {
4578         return true;
4579 }
4580
4581 bool
4582 MainForm::OnTouchCanceled(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4583 {
4584         return true;
4585 }
4586
4587 bool
4588 MainForm::OnPreviewTouchPressed(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4589 {
4590         return true;
4591 }
4592
4593 bool
4594 MainForm::OnPreviewTouchReleased(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4595 {
4596         return true;
4597 }
4598
4599 bool
4600 MainForm::OnPreviewTouchMoved(Tizen::Ui::Control& source, const Tizen::Ui::TouchEventInfo& touchEventInfo)
4601 {
4602         return true;
4603 }
4604
4605 void
4606 MainForm::OnOrientationChanged (const Tizen::Ui::Control &source, Tizen::Ui::OrientationStatus orientationStatus)
4607 {
4608         AppLog("MainForm::OnOrientationChanged GetClientAreaBounds %d, %d",GetClientAreaBounds().width,GetClientAreaBounds().height);
4609         int widthContextItem = 0;
4610         if(__pFindWordCountLabel)
4611                 __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),124,__pFindWordCountLabel->GetHeight());
4612         // As per the platform engineer comment removed this line
4613         /*if(__pWebViewer != null)
4614         {
4615                 // 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
4616                 __pWebViewer->ReleaseBlock();
4617         }*/
4618
4619 //      if(__pFindWordControl != null)
4620 //              ShowFindWordPanel(__pFindWordControl->GetShowState(), false);
4621
4622         if(__pOptionMenu && __pOptionMenu->GetShowState() == true)
4623         {
4624                 if( GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE)
4625                 {
4626                         AppLog(" Orientation landscape");
4627                         __pOptionMenu->SetMaxVisibleItemsCount(5);
4628                 }
4629                 else
4630                 {
4631                         AppLog(" Orientation potrait");
4632                         __pOptionMenu->SetMaxVisibleItemsCount(6);
4633                 }
4634         }
4635         if(__pNotification && __pNotification->GetShowState() == true)
4636         {
4637                 __pNotification->SetShowState(false);
4638                 __pNotification->Invalidate(false);
4639         }
4640         if ( __pFooterLabel != null)
4641         {
4642                 Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_SEARCH_INPUT_FIELD_BG, __pFooterLabel->GetWidth(), __pFooterLabel->GetHeight());
4643                 if(pBitmap != null)
4644                 {
4645                         __pFooterLabel->SetBackgroundBitmap(*pBitmap);
4646                         delete pBitmap;
4647                 }
4648
4649
4650         }
4651         if (__pFindWordBgLabel != null)
4652         {
4653                 Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_FINDWORD_INPUT_FIELD_BG, __pFindWordBgLabel->GetWidth(), __pFindWordBgLabel->GetHeight());
4654                 if (pBitmap != null)
4655                 {
4656                         __pFindWordBgLabel->SetBackgroundBitmap(*pBitmap);
4657                         delete pBitmap;
4658                 }
4659         }
4660
4661         if (__pFindWordBgLabelRightToLeft != null)
4662         {
4663                 Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_FINDWORD_INPUT_FIELD_BG, __pFindWordBgLabelRightToLeft->GetWidth(), __pFindWordBgLabelRightToLeft->GetHeight());
4664                 if (pBitmap != null)
4665                 {
4666                         __pFindWordBgLabelRightToLeft->SetBackgroundBitmap(*pBitmap);
4667                         delete pBitmap;
4668                 }
4669         }
4670
4671
4672 //      if(__pOptionMenu != null)
4673 //              __pOptionMenu->SetShowState(false);
4674
4675         if( GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE_REVERSE)
4676         {
4677                 widthContextItem = WIDTH_CONTEXT_MENU_BUTTON_LANDSCAPE;
4678         }
4679         else
4680         {
4681                 widthContextItem = WIDTH_CONTEXT_MENU_BUTTON_PORTRAIT;
4682         }
4683
4684         if (__pFooterPanel)
4685         {
4686                 AppLog("__pFooterPanel->GetShowState() is true");
4687                 InitFooter();
4688                 __pFooterPanel->SetBounds(0, GetClientAreaBounds().height - __pFooterPanel->GetHeight(), __pFooterPanel->GetWidth(), __pFooterPanel->GetHeight());
4689                 __pFooterPanel->Invalidate(true);
4690         }
4691         InitAddressbar();
4692
4693         String homePage = SettingPresentationModel::GetInstance()->GetHomepage();
4694         if (homePage.CompareTo((L"IDS_BR_BODY_MOST_VISITED_SITES")) == 0)
4695         {
4696                 InitMostVisitedSitesView(orientationStatus);
4697         }
4698
4699         RelayoutControls(false);
4700         if (__pArticleReaderPanel != null)
4701         {
4702                 if (__pArticleReaderPanel->GetShowState() == true)
4703                 {
4704                         __pArticleReaderPanel->SetBounds((GetClientAreaBounds().width - __pArticleReaderPanel->GetWidth())/2,(GetClientAreaBounds().height - __pArticleReaderPanel->GetHeight())/2, __pArticleReaderPanel->GetWidth(), __pArticleReaderPanel->GetHeight());
4705
4706                         if (__pBlankPanel != null)
4707                                 __pBlankPanel->SetBounds(0,0,GetClientAreaBounds().width,GetClientAreaBounds().height);
4708
4709                         if (__pWebReader != null)
4710                         {
4711                                 __pWebReader->SetBounds(Rectangle(2,2, __pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight() - 96));
4712                         }
4713                         Bitmap* pBitmap = CommonUtil::GetNinepatchedBitmapN(L"I01_popup_bg.9.png",__pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight());
4714                         Bitmap* pSrcBitmap = CommonUtil::GetNinepatchedBitmapN(L"I01_popup_bottom_bg.9.png",__pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight());
4715
4716                         if ( pBitmap != null && pSrcBitmap != null)
4717                         {
4718                                 AppLog("CreateReaderPanel ninepatchbitmap found");
4719                                 pBitmap->Merge(Point(0,__pArticleReaderPanel->GetHeight() - 96),*pSrcBitmap,Rectangle(0,0,pSrcBitmap->GetWidth(),pSrcBitmap->GetHeight()));
4720                         }
4721
4722                         __pArticleReaderLabel->SetBounds(Rectangle(__pArticleReaderPanel->GetX(),__pArticleReaderPanel->GetY(),__pArticleReaderPanel->GetWidth(),__pArticleReaderPanel->GetHeight()));
4723                         __pArticleReaderLabel->SetBackgroundBitmap(*pBitmap);
4724                         if (pBitmap != null)
4725                         {
4726                                 delete pBitmap;
4727                                 pBitmap = null;
4728                         }
4729                         if (pSrcBitmap != null)
4730                         {
4731                                 delete pSrcBitmap;
4732                                 pSrcBitmap = null;
4733                         }
4734                 }
4735         }
4736         Invalidate(true);
4737         
4738     if (__pAddressbar != null)
4739         {
4740                 int width = GetClientAreaBounds().width;
4741                 __pAddressbar->OrientationChanged(width);
4742         }
4743 }
4744
4745 void
4746 MainForm::OnSettingsChange(int settingvalue)
4747 {
4748         AppLogDebug("MainForm::OnSettingsChange entered");
4749
4750         if(settingvalue == (int)REGISTRY_SETTING_HOMEPAGE)
4751         {
4752                 __pAddressbar->ResetGuideText();
4753         }
4754         if (__pWebViewer == null)
4755         {
4756                 AppLogDebug("Webviewer is not initialized yet.");
4757                 return;
4758         }
4759
4760         if (settingvalue == (int) REGISTRY_SETTING_DEFAULT_VIEW)
4761         {
4762                 WebSetting settings = __pWebViewer->GetSetting();
4763                 if (SettingPresentationModel::GetInstance()->GetDefaultView().CompareTo((L"IDS_BR_BODY_FIT_TO_WIDTH")) == 0)
4764                 {
4765                         settings.SetAutoFittingEnabled(true);
4766                 }
4767                 else if (SettingPresentationModel::GetInstance()->GetDefaultView().CompareTo((L"IDS_BR_BODY_READABLE")) == 0)
4768                 {
4769                         settings.SetAutoFittingEnabled(false);
4770                 }
4771                 __pWebViewer->SetSetting(settings);
4772         }
4773         else if (settingvalue == (int) REGISTRY_SETTING_RUN_JAVASCRIPT)
4774         {
4775                 WebSetting settings = __pWebViewer->GetSetting();
4776                 settings.SetJavascriptEnabled(SettingPresentationModel::GetInstance()->IsRunJavascriptEnabled());
4777                 __pWebViewer->SetSetting(settings);
4778         }
4779         else if (settingvalue == (int) REGISTRY_SETTING_DISPLAY_IMAGES)
4780         {
4781                 WebSetting settings = __pWebViewer->GetSetting();
4782                 settings.SetAutoImageLoadEnabled(SettingPresentationModel::GetInstance()->IsDisplayImagesEnabled());
4783                 __pWebViewer->SetSetting(settings);
4784                 __pWebViewer->Reload();
4785         }
4786         else if (settingvalue == (int) REGISTRY_SETTING_BLOCK_POPUP)
4787         {
4788                 WebSetting settings = __pWebViewer->GetSetting();
4789                 settings.SetJavaScriptPopupEnabled(SettingPresentationModel::GetInstance()->IsBlockPopUp());
4790                 __pWebViewer->SetSetting(settings);
4791         }
4792         else if (settingvalue == (int) REGISTRY_SETTING_ACCEPT_COOKIES)
4793         {
4794                 if (__pWebViewer)
4795                 {
4796                         __pWebViewer->SetCookieEnabled(SettingPresentationModel::GetInstance()->IsCookiesEnabled());
4797                 }
4798         }
4799         else if(settingvalue == (int) REGISTRY_SETTING_REMEMBER_FORM_DATA)
4800         {
4801                 if (__pWebViewer)
4802                 {
4803                         WebSetting settings = __pWebViewer->GetSetting();
4804                         settings.SetAutoFormDataShowEnabled(SettingPresentationModel::GetInstance()->IsRememberFormData());
4805                         __pWebViewer->SetSetting(settings);
4806                 }
4807         }
4808         else if(settingvalue == (int) REGISTRY_SETTING_REMEMBER_PASSWORD)
4809         {
4810                 if (__pWebViewer)
4811                 {
4812                         WebSetting settings = __pWebViewer->GetSetting();
4813                         settings.SetAutoLoginFormFillEnabled(SettingPresentationModel::GetInstance()->IsRememberPassword());
4814                         __pWebViewer->SetSetting(settings);
4815                 }
4816         }
4817         else if (settingvalue == (int) REGISTRY_SETTING_SHOW_SECURITY_WARNINGS)
4818         {
4819                 WebSetting settings = __pWebViewer->GetSetting();
4820                 if (SettingPresentationModel::GetInstance()->IsSecurityWarningsEnabled() == true)
4821                 {
4822                         settings.SetCertificateErrorHandlingMode(WEB_CERTIFICATE_ERROR_HANDLING_MODE_USER_CONFIRM);
4823                 }
4824                 else
4825                 {
4826                         settings.SetCertificateErrorHandlingMode(WEB_CERTIFICATE_ERROR_HANDLING_MODE_CONTINUE);
4827                 }
4828                 __pWebViewer->SetSetting(settings);
4829         }
4830         else if (settingvalue == (int) REGISTRY_SETTING_READER_FONT_SIZE)
4831         {
4832                 if (__pWebReader)
4833                 {
4834                         AppLogDebug("IntMainForm fontsize Changed to %d",SettingPresentationModel::GetInstance()->GetReaderFontSize());
4835                         WebSetting settings = __pWebReader->GetSetting();
4836                         settings.SetFontSize(SettingPresentationModel::GetInstance()->GetReaderFontSize());
4837                         __pWebReader->SetSetting(settings);
4838                 }
4839         }
4840 }
4841
4842 void
4843 MainForm::OnSettingsReset()
4844 {
4845         if (__pWebViewer)
4846         {
4847                 __pWebViewer->SetCookieEnabled(SettingPresentationModel::GetInstance()->IsCookiesEnabled());
4848                 __pWebViewer->SetSetting(SettingPresentationModel::GetInstance()->GetWebSettings());
4849         }
4850 }
4851
4852 void
4853 MainForm::OnClearCache()
4854 {
4855         result r = E_SUCCESS;
4856
4857         if (__pWebViewer != NULL)
4858         {
4859                 r = __pWebViewer->ClearCache();
4860                 if (r == E_SUCCESS)
4861                 {
4862                         AppLogDebug("Cache cleared success");
4863                 }
4864                 else
4865                 {
4866                         AppLogDebug("Cache cleared fail");
4867                 }
4868         }
4869 }
4870
4871 void
4872 MainForm::OnClearCookie()
4873 {
4874         result r = E_SUCCESS;
4875
4876         if (__pWebViewer != NULL)
4877         {
4878                 __pWebViewer->ClearCookie();
4879         }
4880         if (r == E_SUCCESS)
4881         {
4882                 AppLogDebug("Cookie cleared success");
4883         }
4884         else
4885         {
4886                 AppLogDebug("Cache cleared fail");
4887         }
4888 }
4889
4890 void
4891 MainForm::OnClearFormData()
4892 {
4893         result r = E_SUCCESS;
4894
4895         if (__pWebViewer != NULL)
4896         {
4897                 __pWebViewer->ClearFormData();
4898         }
4899         if (r == E_SUCCESS)
4900         {
4901                 AppLogDebug("Cookie cleared success");
4902         }
4903         else
4904         {
4905                 AppLogDebug("Cache cleared fail");
4906         }
4907 }
4908
4909 void
4910 MainForm::OnClearPasswords()
4911 {
4912         result r = E_SUCCESS;
4913
4914         if (__pWebViewer != NULL)
4915         {
4916                 __pWebViewer->ClearLoginFormData();
4917         }
4918         if (r == E_SUCCESS)
4919         {
4920                 AppLogDebug("Cookie cleared success");
4921         }
4922         else
4923         {
4924                 AppLogDebug("Cache cleared fail");
4925         }
4926 }
4927
4928
4929 double
4930 MainForm::findDistance(int x1,int y1,int x2, int y2)
4931 {
4932         int deltaX = Math::Abs(x2 - x1);
4933         int deltaY = Math::Abs(y2 - y1);
4934         double num = deltaX*deltaX + deltaY*deltaY;
4935
4936         if (num >= 0)
4937         {
4938                 double x = num;
4939                 int i;
4940                 for (i = 0; i < 20; i++)
4941                 {
4942                         x = (((x*x)+ num)/(2*x));
4943                 }
4944                 return num;
4945         }
4946         else
4947         {
4948                 return 0.0;
4949         }
4950 }
4951
4952 void
4953 MainForm::OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
4954 {
4955         AppLog("xyz:: MainForm::OnTouchPressed called");
4956         if(__pFindWordControl)
4957         {
4958                 AppLog("MainForm::OnTouchPressed %d",__pFindWordControl->GetShowState());
4959 //              ShowFindWordPanel(__pFindWordControl->GetShowState(), true);
4960         }
4961         __isLongPressedDone = false;
4962
4963
4964
4965         Touch touch;
4966         IList* pList = null;
4967         pList = touch.GetTouchInfoListN(source);
4968
4969         if (pList != null)
4970         {
4971                 int count = pList->GetCount();
4972                 if (count == 1)
4973                 {
4974                         TouchInfo* pTouchInfo = static_cast<TouchInfo*>(pList->GetAt(0));
4975                         __touchPoint1 = pTouchInfo->position;
4976
4977                         /*if (__pAddressbar != null)
4978                         {
4979                                 if (__pAddressbar->GetAddressbarMode() != ADDRESSBAR_MODE_LOADING_COMPLETE && __pAddressbar->GetAddressbarMode() != ADDRESSBAR_MODE_LOADING)
4980                                 {
4981                                         if (__pAddressbar->GetAddressbarMode() == ADDRESSBAR_MODE_EDIT)
4982                                         {
4983                                                 __pAddressbar->SaveAddressbarEditText();
4984                                         }
4985                                         __pAddressbar->SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
4986                                 }
4987
4988                                 __pAddressbar->Invalidate(true);
4989                         }*/
4990                         if (GetAddressbarMode() != ADDRESSBAR_MODE_LOADING_COMPLETE && GetAddressbarMode() != ADDRESSBAR_MODE_LOADING)
4991                         {
4992                                 if (GetAddressbarMode() == ADDRESSBAR_MODE_EDIT)
4993                                 {
4994                                         //__pAddressbar->SaveAddressbarEditText();
4995                                 }
4996                                 SetAddressbarMode((AddressBarMode)ADDRESSBAR_MODE_LOADING_COMPLETE);
4997                         }
4998                 }
4999                 else if (count == 2)
5000                 {
5001                         AppLogDebug("MainForm::OnTouchPressed count is two");
5002                         TouchInfo* pTouchInfo = static_cast<TouchInfo*>(pList->GetAt(0));
5003                         __touchPoint1 = pTouchInfo->position;
5004
5005                         pTouchInfo = static_cast<TouchInfo*>(pList->GetAt(1));
5006                         __touchPoint2 = pTouchInfo->position;
5007                 }
5008         }
5009         if( pList != NULL)
5010         {
5011                 pList->RemoveAll(true);
5012                 delete pList;
5013         }
5014         if(__pAddressbar)
5015         {
5016                 __pAddressbar->SetShowState(false);
5017         }
5018         if(__pFooterPanel && __isKeypadOpened == false)
5019         {
5020                 __pFooterPanel->SetShowState(true);
5021         }
5022         RelayoutControls(false);
5023         return;
5024 }
5025
5026 void
5027 MainForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
5028 {
5029 //      __currentWordIndex = 0;
5030         __isLongPressedDone = false;
5031
5032 }
5033
5034 void
5035 MainForm::MoveUiControls()
5036 {
5037 }
5038
5039 void
5040 MainForm::OnTextValueChanged (const Tizen::Ui::Control &source)
5041 {
5042         if(&source == dynamic_cast<Control*>(__pFooterUrlField) && __pFooterUrlField != null)
5043         {
5044                 if(__pFooterUrlField->GetTextLength() == 0)
5045                 {
5046                         __pFooterUrlField->SetKeypadActionEnabled(false);
5047                 }
5048                 else
5049                 {
5050                         __pFooterUrlField->SetKeypadActionEnabled(true);
5051                 }
5052         }
5053         if (__pFindWordEditField != null && __pFindWordEditField->GetShowState() == true)
5054         {
5055                 __currentSearchStr = __pFindWordEditField->GetText();
5056                 if (__currentSearchStr.GetLength() > 0)
5057                 {
5058                         __pFindWordCountLabel->SetShowState(true);
5059                 }
5060                 else
5061                 {
5062 //                      __pFindWordCountLabel->SetShowState(false);
5063                         __pFindWordCountLabel->SetBounds(__pFindWordCountLabel->GetX(),__pFindWordCountLabel->GetY(),84,__pFindWordCountLabel->GetHeight());
5064                         __pFindWordEditField->SetBounds(__pFindWordEditField->GetX(),__pFindWordEditField->GetY(),214+80,__pFindWordEditField->GetHeight());
5065
5066                 }
5067                 __pFindWordNext->SetEnabled(false);
5068                 __pFindWordPrev->SetEnabled(false);
5069                 __pFindWordNext->Invalidate(true);
5070                 __pFindWordPrev->Invalidate(true);
5071                 __pFindWordCountLabel->SetText(L"0/0");
5072                 __pFindWordCountLabel->Invalidate(true);
5073         }
5074         else if (__pFindWordEditFieldRightToLeft != null && __pFindWordEditFieldRightToLeft->GetShowState() == true)
5075         {
5076                 __currentSearchStr = __pFindWordEditFieldRightToLeft->GetText();
5077                 if (__currentSearchStr.GetLength() > 0)
5078                 {
5079                         __pFindWordCountLabelRightToLeft->SetShowState(true);
5080                 }
5081                 else
5082                 {
5083                         __pFindWordCountLabelRightToLeft->SetShowState(false);
5084                 }
5085
5086                 __pFindWordNext->SetEnabled(false);
5087                 __pFindWordPrev->SetEnabled(false);
5088                 __pFindWordNext->Invalidate(true);
5089                 __pFindWordPrev->Invalidate(true);
5090                 __pFindWordCountLabelRightToLeft->SetText(L"0/0");
5091                 __pFindWordCountLabelRightToLeft->Invalidate(true);
5092         }
5093         AppLog("__currentSearchStr %ls",__currentSearchStr.GetPointer());
5094         if (__currentSearchStr.GetLength() > 0)
5095         {
5096                 StartWordSearch();
5097         }
5098         else
5099         {
5100                 __currentSearchStr = L"aaaaaaaabbbbbbbccccccc";
5101                 StartWordSearch();
5102                 __currentSearchStr = L"";
5103                 AppLogDebug("Enter something");
5104         }
5105 }
5106
5107 result
5108 MainForm::InitMostVisitedSitesPanel(Tizen::Ui::OrientationStatus orientationStatus)
5109 {
5110         return E_SUCCESS;
5111
5112 }
5113
5114 result
5115 MainForm::InitMostVisitedSitesView(Tizen::Ui::OrientationStatus orientationStatus)
5116 {
5117         if(__pWebViewer != null)
5118                 return E_SUCCESS;
5119
5120         AppLog("MainForm::InitMostVisitedSitesView");
5121         result r = E_SUCCESS;
5122
5123
5124         if (__pWebViewer != null && __pMostVisitedListView != null)
5125         {
5126                 return E_SUCCESS;
5127         }
5128
5129         if (__pMostVisitedListView != null)
5130         {
5131                 RemoveControl(__pMostVisitedListView);
5132         }
5133         if(__pMostVisitedSites != null)
5134         {
5135                 __pMostVisitedSites->RemoveAll(true);
5136         }
5137
5138         HistoryPresentationModel::GetInstance()->GetMostVisitedSites(*__pMostVisitedSites);
5139
5140         __webControlHeight = GetClientAreaBounds().height - __pFooterPanel->GetHeight();
5141         __pMostVisitedListView = new(std::nothrow) ListView();
5142
5143         int height = GetClientAreaBounds().height;
5144
5145         if(__pFooterPanel->GetShowState() == true)
5146         {
5147                 height = height - __pFooterPanel->GetHeight();
5148         }
5149         if(__pAddressbar->GetShowState() == true)
5150         {
5151                 height -= __pAddressbar->GetHeight();
5152         }
5153
5154         r = __pMostVisitedListView->Construct(Tizen::Graphics::Rectangle(0,0 , GetClientAreaBounds().width, height),true,false);
5155
5156         if (r != E_SUCCESS)
5157         {
5158                 delete __pMostVisitedListView;
5159                 AppLogDebug("Addressbar init failed with %s", GetErrorMessage(r));
5160                 return r;
5161         }
5162         __pMostVisitedListView->SetItemProvider(*this);
5163         __pMostVisitedListView->AddListViewItemEventListener(*this);
5164         __pMostVisitedListView->SetTextOfEmptyList(CommonUtil::GetString(L"IDS_BR_BODY_NO_VISITED_SITES"));
5165         AddControl(__pMostVisitedListView);
5166         __pMostVisitedListView->UpdateList();
5167
5168         return E_SUCCESS;
5169
5170 }
5171
5172 String
5173 MainForm::GetImagePath(void)
5174 {
5175
5176         String str;
5177         String formattedTime;
5178         DateTime currentTime;
5179         LocaleManager localManager;
5180         SystemTime::GetCurrentTime(TIME_MODE_WALL, currentTime);
5181
5182         localManager.Construct();
5183         Locale locale = localManager.GetSystemLocale();
5184         //Locale locale(LANGUAGE_ENG, COUNTRY_US);
5185
5186         // Get date formatter
5187         DateTimeFormatter* pTimeFormatter = DateTimeFormatter::CreateDateTimeFormatterN(locale, DATE_TIME_STYLE_DEFAULT);
5188
5189         if (pTimeFormatter)
5190         {
5191                 pTimeFormatter->Format(currentTime, formattedTime);
5192         }
5193
5194         AppLog("current time stamp is %ls", formattedTime.GetPointer());
5195         String delim(L" :");
5196         StringTokenizer strTok(formattedTime, delim);
5197         String token;
5198         String imageName;
5199         String str1("GMT+00");
5200         while (strTok.HasMoreTokens())
5201         {
5202                 strTok.GetNextToken(token); // Osp, StringTokenizer, Sample, code
5203                 if(token.Equals(str1))
5204                         break;
5205                 AppLog("token is %ls", token.GetPointer());
5206                 imageName.Append(token);
5207         }
5208         return imageName;
5209
5210 }
5211
5212 void MainForm::UpdateImageContent(ByteBuffer* aBuffer, String imageName)
5213 {
5214         result r = E_FAILURE;
5215         AppLog("Content manager 1");
5216         ContentId contentId;
5217         ContentManager contentManager;
5218         r = contentManager.Construct();
5219         if(IsFailed(r))
5220         {
5221                 AppLog("Content manager update content result %s" ,GetErrorMessage(r));
5222                 return;
5223         }
5224         Tizen::Base::String contentPath = Tizen::System::Environment::GetMediaPath() + L"Downloads/";
5225         Tizen::Io::Directory::Create(contentPath,true);
5226         if(GetLastResult() == E_FILE_ALREADY_EXIST)
5227         {
5228                 AppLog("Already exists");
5229         }
5230         else if(GetLastResult() == E_SUCCESS)
5231         {
5232                 AppLog("created success");
5233         }
5234         contentPath.Append(imageName);
5235         contentPath.Append(".jpg");
5236         contentId = contentManager.CreateContent(*aBuffer, contentPath);
5237         ShowIndicatorNotification(L"Download Complete",contentPath);
5238         AppLog("Content manager update content result %s" ,GetErrorMessage(GetLastResult()));
5239 }
5240
5241 void
5242 MainForm::ShowIndicatorNotification(const String& messageText, const String& contentPath)
5243 {
5244         AppLogDebug("ENTER");
5245
5246         NotificationRequest request;
5247         request.SetAlertText(messageText);
5248         request.SetTitleText(L"");
5249         request.SetAppMessage(contentPath);
5250         request.SetOngoingActivityType(ONGOING_ACTIVITY_TYPE_TEXT);
5251         request.SetNotificationStyle(NOTIFICATION_STYLE_THUMBNAIL);
5252         Tizen::App::App* pApp = Tizen::App::App::GetInstance();
5253         String homePath = pApp->GetAppRootPath();
5254         String iconPath = homePath + L"res/screen-density-xhigh/Notification_download_complete.png";
5255         AppLog("The iconPath is : %ls", homePath.GetPointer());
5256         request.SetIconFilePath(iconPath);
5257
5258         Tizen::Shell::NotificationManager notiMgr;
5259         notiMgr.Construct();
5260         notiMgr.NotifyOngoingActivity(request);
5261         AppLogDebug("EXIT: %s", GetErrorMessage(GetLastResult()));
5262         return;
5263 }
5264
5265 void
5266 MainForm::SetForwardButtonEnabled(bool isEnabled)
5267 {
5268         __pGoForwardBtn->SetEnabled(isEnabled);
5269         __pGoForwardBtn->Invalidate(true);
5270 }
5271
5272 void
5273 MainForm::SetBackButtonEnabled(bool isEnabled)
5274 {
5275         __pGoBackBtn->SetEnabled(isEnabled);
5276         __pGoBackBtn->Invalidate(true);
5277 }
5278
5279 void
5280 MainForm::UpdateProgress(int percentage)
5281 {
5282         __progressPercentage = percentage;
5283         if (percentage == 0 || percentage == 100)
5284         {
5285                 __isLoadingData = false;
5286                 if (percentage == 100)
5287                 {
5288                         __isLoadingCompleted = true;
5289                         __progressPercentage = 0;
5290                 }
5291                 else
5292                 {
5293                         __isLoadingCompleted = false;
5294                 }
5295         }
5296         else
5297         {
5298                 __isLoadingData = true;
5299         }
5300         UpdateProgressBitmap();
5301 }
5302
5303 int
5304 MainForm::GetProgress(void)
5305 {
5306         return __progressPercentage;
5307 }
5308
5309 void
5310 MainForm::UpdateProgressBitmap(void)
5311 {
5312         result r = E_SUCCESS;
5313         if (__pProgressbarLabel == null)
5314                 return;
5315         int w = __pProgressbarLabel->GetWidth();
5316         int h = __pProgressbarLabel->GetHeight();
5317         Canvas canvas;
5318         int progressWidth = 0;
5319         Bitmap* pRetBitmap = null;
5320
5321         if (__progressPercentage == 0 || __progressPercentage == 100)
5322         {
5323                 __pProgressbarLabel->SetShowState(false);
5324                 __pProgressbarLabel->Invalidate(false);
5325                 return;
5326         }
5327         else
5328         {
5329                 __pProgressbarLabel->SetShowState(true);
5330                 __pProgressbarLabel->Invalidate(false);
5331         }
5332
5333         r = canvas.Construct(Rectangle(0, 0, w, h));
5334
5335         if (r != E_SUCCESS)
5336         {
5337                 AppLogException("Canvas construction failed with %s", GetErrorMessage(r));
5338                 return;
5339         }
5340
5341         canvas.Clear();
5342         Bitmap *pBgBmp = AppResource::GetInstance()->GetBitmapN(IDB_TITLE_PROGRESS_BAR_BG);
5343
5344         if (pBgBmp != null)
5345         {
5346                 pBgBmp->Scale(Dimension(w, h));
5347                 canvas.DrawBitmap(Point(0,0), *pBgBmp);
5348                 delete pBgBmp;
5349         }
5350
5351         progressWidth = (double) (w) * __progressPercentage / 100;
5352         AppLogDebug("progressWidth: %d", progressWidth);
5353         Bitmap *pProgressBmp = AppResource::GetInstance()->GetBitmapN(IDB_TITLE_PROGRESS_BAR);
5354
5355         if (pProgressBmp != null)
5356         {
5357                 pProgressBmp->Scale(Dimension(progressWidth, h));
5358                 canvas.DrawBitmap(Point(0,0), *pProgressBmp);
5359                 delete pProgressBmp;
5360         }
5361
5362         pRetBitmap = new (std::nothrow) Bitmap();
5363
5364         if (pRetBitmap == null)
5365         {
5366                 AppLogException("Bitmap creation failed with %s", GetErrorMessage(r));
5367                 return;
5368         }
5369
5370         pRetBitmap->Construct(canvas, canvas.GetBounds());
5371
5372         if (__pProgressbarLabel != null && pRetBitmap != null)
5373         {
5374                 __pProgressbarLabel->SetBackgroundBitmap(*pRetBitmap);
5375                 __pProgressbarLabel->Invalidate(false);
5376         }
5377
5378         if (pRetBitmap != null)
5379         {
5380                 delete pRetBitmap;
5381                 pRetBitmap = null;
5382         }
5383         return;
5384 }
5385
5386 void
5387 MainForm::ReaderClicked()
5388 {
5389         result r = E_SUCCESS;
5390         ArrayList* pArgList = new(std::nothrow) ArrayList();
5391         if (pArgList != null)
5392         {
5393                 r = pArgList->Construct();
5394                 if (IsFailed(r))
5395                 {
5396                         delete pArgList;
5397                         return;
5398                 }
5399
5400                 r = pArgList->Add(*new(std::nothrow) String(*__pReaderData));
5401                 if (IsFailed(r))
5402                 {
5403                         delete pArgList;
5404                         return;
5405                 }
5406
5407                 r = pArgList->Add(*new(std::nothrow) String(__pWebViewer->GetUrl()));
5408                 if (IsFailed(r))
5409                 {
5410                         delete pArgList;
5411                         return;
5412                 }
5413
5414                 r = pArgList->Add(*new(std::nothrow) String(__pWindowInfo->pageTitle));
5415                 if (IsFailed(r))
5416                 {
5417                         delete pArgList;
5418                         return;
5419                 }
5420         }
5421
5422         SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_ARTICLE_READER, SCENE_TRANSITION_ANIMATION_TYPE_NONE),pArgList);
5423         return;
5424
5425
5426 }
5427
5428 void MainForm::SetAddressbarMode(AddressBarMode addMode)
5429 {
5430         AppLogDebug("AddressBar::setAddressbarMode to %d",addMode);
5431
5432         __currentAddMode = addMode;
5433
5434         switch(addMode)
5435         {
5436         case ADDRESSBAR_MODE_INVALID:
5437         {
5438                 // do nothing
5439         }
5440         break;
5441         case ADDRESSBAR_MODE_READER:
5442         {
5443                 __pStopBtn->SetShowState(false);
5444                 __pRefreshBtn->SetShowState(false);
5445                 __pClearBtn->SetShowState(false);
5446                 __pReaderBtn->SetShowState(false);
5447         }
5448         break;
5449         case ADDRESSBAR_MODE_LOADING:
5450         {
5451                 __pRefreshBtn->SetShowState(false);
5452                 __pStopBtn->SetShowState(true);
5453                 __pClearBtn->SetShowState(false);
5454                 __pReaderBtn->SetShowState(false);
5455         }
5456         break;
5457         case ADDRESSBAR_MODE_LOADING_COMPLETE:
5458         {
5459 //              SetUrl(__pAddressbar->GetUrl());
5460
5461                 __pRefreshBtn->SetShowState(true);
5462                 __pStopBtn->SetShowState(false);
5463                 __pClearBtn->SetShowState(false);
5464                 __pReaderBtn->SetShowState(false);
5465         }
5466         break;
5467         case ADDRESSBAR_MODE_EDIT:
5468         {
5469                 __pRefreshBtn->SetShowState(false);
5470                 __pStopBtn->SetShowState(false);
5471                 __pReaderBtn->SetShowState(false);
5472                 __pClearBtn->SetShowState(true);
5473         }
5474         break;
5475         }
5476
5477         Invalidate(true);
5478
5479         OnAddressBarModeChanged();
5480 }
5481
5482 AddressBarMode MainForm::GetAddressbarMode(void)
5483 {
5484         return __currentAddMode;
5485 }
5486
5487 void MainForm::SetUrl(const String& url)
5488 {
5489         __displayUrl = url;
5490         if(__displayUrl.GetLength() > 2048)
5491                 __displayUrl.SubString(0,2048,__displayUrl);
5492
5493         if (__pFooterUrlField != NULL)
5494         {
5495                 String removedHttpUrl = RemoveHttpTextFromDisplayURL();
5496                 if (removedHttpUrl.IsEmpty() == false)
5497                 {
5498                         __pFooterUrlField->SetText(removedHttpUrl);
5499                         if(__pAddressbar != NULL && __pAddressbar->HasCurrentFocus() == false)
5500                                 __pAddressbar->SetUrl(__displayUrl);
5501                 }
5502                 else
5503                 {
5504                         __pFooterUrlField->SetText(__displayUrl);
5505                         if(__pAddressbar != NULL && __pAddressbar->HasCurrentFocus() == false)
5506                                 __pAddressbar->SetUrl(__displayUrl);
5507                 }
5508                 if(__pFooterUrlField)
5509                         __pFooterUrlField->SetCursorPosition(__pFooterUrlField->GetTextLength());
5510                 __pFooterUrlField->Invalidate(false);
5511                 if(__pAddressbar != NULL && __pAddressbar->HasFocus())
5512                         __pAddressbar->Invalidate(true);
5513 //              __pFooterUrlField->SetCursorPosition(0);
5514         }
5515 }
5516
5517 String
5518 MainForm::RemoveHttpTextFromDisplayURL(void)
5519 {
5520         AppLog("MainForm::RemoveHttpTextFromDisplayURL __displayUrl %ls",__displayUrl.GetPointer());
5521         int index = -1;
5522 //      bool isHttpText = __displayUrl.Contains(L"http://");
5523         String updatedDisplayUrl;
5524         updatedDisplayUrl.Clear();
5525         if(__displayUrl.IndexOf(L"http://",0,index) == E_SUCCESS && index == 0)
5526         {
5527                 __displayUrl.SubString(7,updatedDisplayUrl);
5528         }
5529         else if(__displayUrl.IndexOf(L"https://",0,index) == E_SUCCESS && index == 0)
5530         {
5531                 __displayUrl.SubString(8,updatedDisplayUrl);
5532         }
5533         return updatedDisplayUrl;
5534 }
5535
5536 void MainForm::OnSharePopupControlStarted(void)
5537 {
5538         __pWebViewer->AddTouchEventListener(*this);
5539 }
5540
5541 void
5542 MainForm::OnUserEventReceivedN (RequestId requestId, Tizen::Base::Collection::IList *pArgs)
5543 {
5544         if (requestId == BACK_GROUND_APP_EVENT)
5545         {
5546                 if(__pWebViewer != null)
5547                 {
5548                         __pWebViewer->Pause();
5549                 }
5550                 if(__pImageMenu)
5551                 {
5552                         __pImageMenu->SetShowState(false);
5553                 }
5554                 if(__pAddressbar != null)
5555                 {
5556                         __pAddressbar->SendUserEvent(BACK_GROUND_APP_EVENT,NULL);
5557                 }
5558         }
5559         else if(requestId == FORE_GROUND_APP_EVENT)
5560         {
5561                 if(__pWebViewer != null)
5562                 {
5563                         __pWebViewer->Resume();
5564                 }
5565                 if(__pAddressbar != null)
5566                 {
5567                         __pAddressbar->SendUserEvent(FORE_GROUND_APP_EVENT,NULL);
5568                 }
5569         }
5570 }
5571
5572 void
5573 MainForm::AddressBarCancelledClicked(const Addressbar& addBar)
5574 {
5575         AppLog("XYZ::MainForm::AddressBarCancelledClicked");
5576         result r = E_SUCCESS;
5577
5578         if (__pAddressbar)
5579                 __pAddressbar->SetShowState(false);
5580
5581         AppLog("akjshdasd 5");
5582         __pFooterPanel->SetShowState(true);
5583
5584         if(__pWebViewer)
5585                 __pWebViewer->SetFocus();
5586         else if(__pMostVisitedListView)
5587                 __pMostVisitedListView->SetFocus();
5588         else if(__pMultiWindowButton)
5589                 __pMultiWindowButton->SetFocus();
5590         else if(__pMoreButton)
5591                 __pMoreButton->SetFocus();
5592
5593         __pAddressbar->SetShowState(false);
5594
5595         RelayoutControls(false);
5596 }
5597
5598 void
5599 MainForm::OnFormMenuRequested (Tizen::Ui::Controls::Form &source)
5600 {
5601         AppLog("MainForm::OnFormMenuRequested called");
5602         InitOptionMenu();
5603         if (__pWindowInfo != NULL && __pWindowInfo->pageUrl != NULL && __pWebViewer && __pWebViewer->GetShowState() == true)
5604         {
5605                 int bookmarkCount=0;
5606                 bool exist = false;
5607                 String url=L"";
5608                 url=__pWindowInfo->pageUrl;
5609                 AppLog("MainForm::OnFormMenuRequested url %ls",url.GetPointer());
5610                 result r = E_SUCCESS;
5611                 Bitmap* pBitmap = null;
5612                 String lastChar = L"";
5613 //              if(url.SubString(url.GetLength()-1,lastChar));
5614 //              if(lastChar == L"/")
5615 //              {
5616 //                      bool exist1 = false;
5617 //                      bool exist2 = false;
5618 //                      r=BookmarkPresentationModel::GetInstance()->DoesBookmarkExist(url,exist1);
5619 //                      url.SubString(0,url.GetLength() - 1,url);
5620 //                      r=BookmarkPresentationModel::GetInstance()->DoesBookmarkExist(url,exist2);
5621 //                      exist = exist1 | exist2;
5622 //              }
5623 //              else
5624 //              {
5625                         r=BookmarkPresentationModel::GetInstance()->DoesBookmarkExist(url,exist);
5626                         if (IsFailed(r))
5627                         {
5628                                 AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED failed");
5629                                 return;
5630                         }
5631 //              }
5632                 if ( exist == true)
5633                 {
5634                         pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ICON_BOOKMARK_ON_TEMP);
5635                 }
5636                 else
5637                 {
5638                         pBitmap = AppResource::GetInstance()->GetBitmapN(IDB_ICON_BOOKMARK_OFF_TEMP);
5639                 }
5640                 AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED 3");
5641
5642                 if (__pOptionMenu->GetItemCount() == 9)
5643                 {
5644                         r = __pOptionMenu->SetItemAt(1,CommonUtil::GetString(L"IDS_BR_OPT_ADDTOBOOKMARKS"), IDA_ADDTOBOOKMARK_CLICKED,*pBitmap);
5645                 }
5646                 else
5647                 {
5648                         r = __pOptionMenu->InsertItemAt(1,CommonUtil::GetString(L"IDS_BR_OPT_ADDTOBOOKMARKS"), IDA_ADDTOBOOKMARK_CLICKED,*pBitmap);
5649                 }
5650
5651                 if (IsFailed(r))
5652                 {
5653                         AppLogException("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED Add to Bookmark failed with %s", GetErrorMessage(r));
5654                         delete pBitmap;
5655                         return ;
5656                 }
5657                 AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED 4");
5658                 if (__pOptionMenu->GetItemCount() != 9)
5659                 {
5660                         __pOptionMenu->InsertItemAt(1,CommonUtil::GetString(L"IDS_BR_OPT_ADDTOBOOKMARKS"), IDA_ADDTOBOOKMARK_CLICKED);
5661                         __pOptionMenu->InsertItemAt(2,CommonUtil::GetString(L"IDS_BR_BODY_PRINT"), IDA_PRINT_CLICKED);
5662 //                              __pOptionMenu->InsertItemAt(2,L"Add to Home"/*CommonUtil::GetString(L"IDS_BR_OPT_SHARE")*/, IDA_ADD_TO_HOME_CLICKED);
5663                         __pOptionMenu->InsertItemAt(3,CommonUtil::GetString(L"IDS_BR_OPT_SHARE"), IDA_SHARE_CLICKED);
5664                         __pOptionMenu->InsertItemAt(4,CommonUtil::GetString(L"IDS_BR_OPT_FIND_ON_PAGE_ABB"), IDA_FINDONPAGE_CLICKED);
5665                         __pOptionMenu->SetMaxVisibleItemsCount(6);
5666                 }
5667                 if( GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE || GetOrientationStatus() == ORIENTATION_STATUS_LANDSCAPE)
5668                 {
5669                         AppLog(" Orientation landscape");
5670                         __pOptionMenu->SetMaxVisibleItemsCount(5);
5671                 }
5672                 else
5673                 {
5674                         AppLog(" Orientation potrait");
5675                         __pOptionMenu->SetMaxVisibleItemsCount(6);
5676                 }
5677
5678                 AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED 5");
5679                 delete pBitmap;
5680         }
5681         AppLogDebug("ONACTION_PERFORMED:IDA_MOREBTN_CLICKED end");
5682         if(__pAddressbar)
5683                 __pAddressbar->SetShowState(false);
5684         SetFocus();
5685         __pFooterPanel->SetShowState(true);
5686         result r = __pOptionMenu->SetShowState(true);
5687         AppLog("ajsghd %s",GetErrorMessage(r));
5688         RelayoutControls(false);
5689         __pOptionMenu->Invalidate(true);
5690         __pOptionMenu->Show();
5691
5692 }