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