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