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