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