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