NABI issues
[apps/osp/Internet.git] / src / IntAddressbar.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
18 /*@file:    IntAddressbar
19  *@brief:       This class defines common behaviour of Addressbar control.
20  *
21  */
22 #include "IntAddressbar.h"
23 #include "IntCommonLib.h"
24 #include "IntTypes.h"
25 #include "IntMultipleWindowPresentationModel.h"
26 #include "IntSettingPresentationModel.h"
27 #include "IntMultipleWindowPresentationModel.h"
28
29 using namespace Tizen::App;
30 using namespace Tizen::Base;
31 using namespace Tizen::Ui;
32 using namespace Tizen::Ui::Controls;
33 using namespace Tizen::Graphics;
34
35 static const wchar_t* IDB_SEARCH_INPUT_FIELD_BG = L"I01_toolbar_input_field.9.png";
36 static const wchar_t* IDB_TITLE_PROGRESS_BAR_BG = L"I01_title_progress_bar_bg.png";
37 static const wchar_t* IDB_TITLE_PROGRESS_BAR = L"I01_title_progress_bar.png";
38 static const wchar_t* IDB_ICON_PRIVATE = L"I01_icon_private.png";
39
40 //Action IDs
41 const int Addressbar::IDA_REFRESH_BTN_CLICKED = 101;
42 const int Addressbar::IDA_READER_BTN_CLICKED = 102;
43 const int Addressbar::IDA_STOP_BTN_CLICKED = 103;
44 const int Addressbar::IDA_GO_BACK = 104;
45 const int Addressbar::IDA_GO_FORWARD = 105;
46 const int Addressbar::IDA_CANCEL = 106;
47 const int Addressbar::IDA_CLEAR_URL = 107;
48
49 Addressbar::Addressbar(void)
50 {
51         //__currentAddMode = ADDRESSBAR_MODE_LOADING_COMPLETE;
52         __displayUrl = L"";
53         __editTextUrl = L"";
54         __isLoadingData = false;
55         __isLoadingCompleted = false;
56         __progressPercentage = 0;
57         __pAddressbarBg = null;
58         __pBgPanel = null;
59         //__pCancelBtn = null;
60         __pClearBtn = null;
61         __pFavIcon = FaviconManager::GetInstance()->GetDefaultFaviconN();
62         __pFaviconLabel = null;
63         //__pGoBackBtn = null;
64         //__pGoForwardBtn = null;
65         __pLabelPrivateOn = null;
66         __pListener = null;
67         __pPrivateIconLabel = null;
68         __pProgressbarLabel = null;
69         __pPrivateIconLabel = null ;
70         //__pReaderBtn = null;
71         //__pRefreshBtn = null;
72         __pStopBtn = null;
73         __pClearBtn = null ;
74         __pSearchLabel = null;
75         __pAddressbarUrlField = null;
76         __pToolBarLabel = null;
77         __pAddressbarURLLabel = null;
78         __pAddressBackBtn = null;
79 }
80
81 Addressbar::~Addressbar(void)
82 {
83         if (__pFavIcon != null)
84         {
85                 delete __pFavIcon;
86                 __pFavIcon = null;
87         }
88 }
89
90 result
91 Addressbar::Initialize(const Rectangle& rect)
92 {
93         result r = E_SUCCESS;
94
95         AppLogDebug("Addressbar::Initialize entered");
96         //Construct the base first
97         r = Construct(L"IDL_ADDRESSBAR");
98
99         //Add background label
100         Label* pBgLabel = static_cast<Label*> (GetControl(L"IDC_BG_LABEL",true));
101         if (pBgLabel == NULL)
102         {
103                 AppLogDebug("Control not found returning E_INVALID_KEY");
104                 return E_INVALID_KEY;
105         }
106
107         //Add inner panel for border
108         __pBgPanel = static_cast<Panel*> (GetControl(L"IDC_BG_PANEL",true));
109         if (__pBgPanel == NULL)
110         {
111                 AppLogDebug("Control not found returning E_INVALID_KEY");
112                 return E_INVALID_KEY;
113         }
114
115         /*__pLabelPrivateOn = static_cast<Label*> (GetControl(L"IDC_LABEL_PRIVATE_ON",true));
116
117         if (__pLabelPrivateOn == NULL)
118         {
119                 AppLogDebug("Control not found returning E_INVALID_KEY");
120                 return E_INVALID_KEY;
121         }
122         __pLabelPrivateOn->SetShowState(false);*/
123
124         __pAddressbarBg = static_cast<Label*> (GetControl(L"IDC_ADDRESSBAR_BG_LABEL",true));
125         if (__pAddressbarBg == NULL)
126         {
127                 AppLogDebug("Control not found returning E_INVALID_KEY");
128                 return E_INVALID_KEY;
129         }
130         __pBgPanel->SetBackgroundColor(CUSTOM_COLOR_TRANSPARENT);
131         Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_SEARCH_INPUT_FIELD_BG, __pAddressbarBg->GetWidth(), __pAddressbarBg->GetHeight());
132         if (pBitmap != null)
133         {
134                 __pAddressbarBg->SetBackgroundBitmap(*pBitmap);
135                 delete pBitmap;
136         }
137
138         //Add the backround label for displaying progressbar
139         __pProgressbarLabel = static_cast<Label*> (GetControl(L"IDC_PROGRESS_BAR_LABEL",true));
140         if (__pProgressbarLabel == NULL)
141         {
142                 AppLogDebug("Control not found returning E_INVALID_KEY");
143                 return E_INVALID_KEY;
144         }
145         __pProgressbarLabel->SetShowState(false);
146
147         //Add the stop button
148         __pStopBtn = static_cast<Button*> (GetControl(L"IDC_STOP_BUTTON",true));
149         if (__pStopBtn == NULL)
150         {
151                 AppLogDebug("Control not found returning E_INVALID_KEY");
152                 return E_INVALID_KEY;
153         }
154         __pStopBtn->SetActionId(IDA_STOP_BTN_CLICKED);
155         __pStopBtn->AddActionEventListener(*this);
156         __pStopBtn->SetShowState(false);
157
158
159         __pClearBtn = static_cast<Button*> (GetControl(L"IDC_CLEAR_BUTTON",true));
160         if (__pClearBtn == NULL)
161         {
162                 AppLogDebug("Control not found returning E_INVALID_KEY");
163                 return E_INVALID_KEY;
164         }
165         __pClearBtn->SetActionId(IDA_CLEAR_URL);
166         __pClearBtn->AddActionEventListener(*this);
167         __pClearBtn->SetShowState(true);
168
169         //Add the editfield for url
170         __pAddressbarUrlField =  static_cast<EditField*> (GetControl(L"IDC_URL_EDITFIELD",true));
171         if (__pAddressbarUrlField == NULL)
172         {
173                 AppLogDebug("Control not found returning E_INVALID_KEY");
174                 return E_INVALID_KEY;
175         }
176
177         __pAddressbarUrlField->SetOverlayKeypadCommandButtonVisible(false);
178         __pAddressbarUrlField->SetKeypadAction(KEYPAD_ACTION_GO);
179         __pAddressbarUrlField->AddFocusEventListener(*this);
180         __pAddressbarUrlField->AddTextEventListener(*this);
181         if(__pAddressbarUrlField->GetTextLength() == 0)
182         {
183                 __pAddressbarUrlField->SetKeypadActionEnabled(false);
184         }
185         else
186         {
187                 __pAddressbarUrlField->SetKeypadActionEnabled(true);
188         }
189
190         __pToolBarLabel = static_cast<Label*> (GetControl(L"IDC_TOOLBAR_LABEL",true));
191         if (__pToolBarLabel == NULL)
192         {
193                 AppLogDebug("Control not found returning E_INVALID_KEY");
194                 return E_INVALID_KEY;
195         }
196         __pToolBarLabel->SetShowState(true);
197
198         __pAddressbarURLLabel = static_cast<Label*> (GetControl(L"IDC_URL_LABEL",true));
199         if (__pAddressbarURLLabel == NULL)
200         {
201                 AppLogDebug("__pURLLabel Control not found returning E_INVALID_KEY");
202                 return E_INVALID_KEY;
203         }
204         __pAddressbarURLLabel->SetShowState(true);
205
206         __pAddressBackBtn = static_cast<Button*> (GetControl(L"IDC_ADDRESS_BACK_BUTTON",true));
207         if (__pAddressBackBtn == NULL)
208         {
209                 AppLogDebug("__pAddressBackBtn Control not found returning E_INVALID_KEY");
210                 return E_INVALID_KEY;
211         }
212         __pAddressBackBtn->SetActionId(IDA_CANCEL);
213         __pAddressBackBtn->AddActionEventListener(*this);
214         __pAddressBackBtn->SetShowState(true);
215         //IDC_ADDRESS_BACK_BUTTON
216
217         // Added to get the favorite url if not set then address bar is about blank
218
219         if (SettingPresentationModel::GetInstance()->GetHomepage().CompareTo((L"IDS_BR_BODY_MOST_VISITED_SITES")) == 0)
220         {
221                 __pAddressbarUrlField->SetGuideText(CommonUtil::GetString(L"IDS_BR_BODY_SEARCH_OR_ENTER_URL"));
222         }
223         else if (SettingPresentationModel::GetInstance()->GetHomepage().CompareTo((L"IDS_BR_BODY_BLANK_PAGE")) == 0)
224         {
225                 __pAddressbarUrlField->SetGuideText(CommonUtil::GetString(L"IDS_BR_BODY_ABOUT_C_BLANK"));
226         }
227         else
228         {
229                 //__pUrlField->SetText(SettingPresentationModel::GetInstance()->GetFavoriteURL());
230                 __pAddressbarUrlField->SetGuideText(CommonUtil::GetString(L"IDS_BR_BODY_SEARCH_OR_ENTER_URL"));
231         }
232         __pAddressbarUrlField->AddKeypadEventListener(*this);
233
234         AppLogDebug("Addressbar::Initialize exit");
235         return r;
236 }
237
238 void
239 Addressbar::UpdateProgressBitmap(void)
240 {
241         result r = E_SUCCESS;
242         if (__pProgressbarLabel == null)
243                 return;
244         int w = __pProgressbarLabel->GetWidth();
245         int h = __pProgressbarLabel->GetHeight();
246         Canvas canvas;
247         int progressWidth = 0;
248         Bitmap* pRetBitmap = null;
249
250         if (__progressPercentage == 0 || __progressPercentage == 100)
251         {
252                 __pProgressbarLabel->SetShowState(false);
253                 __pProgressbarLabel->Invalidate(false);
254                 return;
255         }
256         else
257         {
258                 __pProgressbarLabel->SetShowState(true);
259                 __pProgressbarLabel->Invalidate(false);
260         }
261
262         r = canvas.Construct(Rectangle(0, 0, w, h));
263
264         if (r != E_SUCCESS)
265         {
266                 AppLogException("Canvas construction failed with %s", GetErrorMessage(r));
267                 return;
268         }
269
270         canvas.Clear();
271         Bitmap *pBgBmp = AppResource::GetInstance()->GetBitmapN(IDB_TITLE_PROGRESS_BAR_BG);
272
273         if (pBgBmp != null)
274         {
275                 pBgBmp->Scale(Dimension(w, h));
276                 canvas.DrawBitmap(Point(0,0), *pBgBmp);
277                 delete pBgBmp;
278         }
279
280         progressWidth = (double) (w) * __progressPercentage / 100;
281         AppLogDebug("progressWidth: %d", progressWidth);
282         Bitmap *pProgressBmp = AppResource::GetInstance()->GetBitmapN(IDB_TITLE_PROGRESS_BAR);
283
284         if (pProgressBmp != null)
285         {
286                 pProgressBmp->Scale(Dimension(progressWidth, h));
287                 canvas.DrawBitmap(Point(0,0), *pProgressBmp);
288                 delete pProgressBmp;
289         }
290
291         pRetBitmap = new (std::nothrow) Bitmap();
292
293         if (pRetBitmap == null)
294         {
295                 AppLogException("Bitmap creation failed with %s", GetErrorMessage(r));
296                 return;
297         }
298
299         pRetBitmap->Construct(canvas, canvas.GetBounds());
300
301         if (__pProgressbarLabel != null && pRetBitmap != null)
302         {
303                 __pProgressbarLabel->SetBackgroundBitmap(*pRetBitmap);
304                 __pProgressbarLabel->Invalidate(false);
305         }
306
307
308         if (pRetBitmap != null)
309         {
310                 delete pRetBitmap;
311                 pRetBitmap = null;
312         }
313         return;
314 }
315
316 void
317 Addressbar::SetUrl(const String& url)
318 {
319         __displayUrl = url;
320         String updatedDisplayUrl;
321         updatedDisplayUrl.Clear();
322
323         if (__pAddressbarUrlField != NULL)
324         {
325                 String removedHttpUrl = RemoveHttpTextFromDisplayURL();
326                 if (removedHttpUrl.IsEmpty() == false)
327                 {
328                         __pAddressbarUrlField->SetText(removedHttpUrl);
329                 }
330                 else
331                 {
332                         __pAddressbarUrlField->SetText(__displayUrl);
333                 }
334
335                 __pAddressbarUrlField->Invalidate(false);
336                 __pAddressbarUrlField->SetCursorPosition(0);
337         }
338 }
339
340 String
341 Addressbar::GetUrl(void)
342 {
343         return __displayUrl;
344 }
345
346 /*AddressBarMode
347 Addressbar::GetAddressbarMode(void)
348 {
349         return __currentAddMode;
350 }*/
351
352 /*void
353 Addressbar::SetAddressbarMode(AddressBarMode addMode)
354 {
355         AppLogDebug("AddressBar::setAddressbarMode to %d",addMode);
356
357         __currentAddMode = addMode;
358
359         switch(addMode)
360         {
361         case ADDRESSBAR_MODE_INVALID:
362         {
363                 // do nothing
364         }
365         break;
366         case ADDRESSBAR_MODE_READER:
367         {
368         //      __pBgPanel->SetPosition(__pGoBackBtn->GetPosition().x + 2* __pGoBackBtn->GetWidth() + 13,__pBgPanel->GetPosition().y);
369         //      __pSearchLabel->SetShowState(false);
370         //      __pFaviconLabel->SetShowState(true);
371         //      __pCancelBtn->SetShowState(false);
372         //      __pRefreshBtn->SetShowState(false);
373                 __pStopBtn->SetShowState(false);
374         //      __pReaderBtn->SetShowState(true);
375         //      __pReaderBtn->Invalidate(true);
376         //      __pGoForwardBtn->SetShowState(true);
377         //      __pGoBackBtn->SetShowState(true);
378                 __pClearBtn->SetShowState(false);
379         }
380         break;
381         case ADDRESSBAR_MODE_LOADING:
382         {
383         //      __pBgPanel->SetPosition(__pGoBackBtn->GetPosition().x + 2* __pGoBackBtn->GetWidth() + 13,__pBgPanel->GetPosition().y);
384         //      __pSearchLabel->SetShowState(false);
385         //      __pFaviconLabel->SetShowState(true);
386         //      __pCancelBtn->SetShowState(false);
387         //      __pRefreshBtn->SetShowState(false);
388                 __pStopBtn->SetShowState(true);
389         //      __pReaderBtn->SetShowState(false);
390         //      __pGoForwardBtn->SetShowState(true);
391         //      __pGoBackBtn->SetShowState(true);
392                 __pClearBtn->SetShowState(false);
393         }
394         break;
395
396         case ADDRESSBAR_MODE_LOADING_COMPLETE:
397         {
398         //      __pBgPanel->SetPosition(__pGoBackBtn->GetPosition().x + 2* __pGoBackBtn->GetWidth() + 13,__pBgPanel->GetPosition().y);
399         //      __pCancelBtn->SetShowState(false);
400
401                 if (__pAddressbarUrlField && __pAddressbarUrlField->GetText().IsEmpty() == false)
402                 {
403                 //      __pSearchLabel->SetShowState(false);
404                 //      __pFaviconLabel->SetShowState(true);
405                 }
406                 else
407                 {
408                 //      __pSearchLabel->SetShowState(true);
409                 //      __pFaviconLabel->SetShowState(false);
410                 }
411
412                 if (__pAddressbarUrlField != NULL)
413                 {
414                         __pAddressbarUrlField->SetText(__displayUrl);
415                         __pAddressbarUrlField->HideKeypad();
416                 }
417
418         //      __pRefreshBtn->SetShowState(true);
419                 __pStopBtn->SetShowState(false);
420         //      __pReaderBtn->SetShowState(false);
421         //      __pGoForwardBtn->SetShowState(true);
422         //      __pGoBackBtn->SetShowState(true);
423                 __pClearBtn->SetShowState(false);
424         }
425         break;
426         case ADDRESSBAR_MODE_EDIT:
427         {
428                 Form *pForm = static_cast<Form*>(GetParent());
429                 if (pForm!= null && (pForm->GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT ||pForm->GetOrientationStatus() == ORIENTATION_STATUS_PORTRAIT_REVERSE ))
430                 {
431                 //      __pBgPanel->SetBounds(__pBgPanel->GetX(),__pBgPanel->GetY(),static_cast<Form*>(GetParent())->GetClientAreaBounds().width - __pCancelBtn->GetWidth() - 30,__pBgPanel->GetHeight());
432                 //      __pAddressbarBg->SetBounds(__pAddressbarBg->GetX(),__pAddressbarBg->GetY(),static_cast<Form*>(GetParent())->GetClientAreaBounds().width - __pCancelBtn->GetWidth() - 30,__pAddressbarBg->GetHeight());
433                         __pClearBtn->SetBounds(__pBgPanel->GetWidth() - __pClearBtn->GetWidth(),__pClearBtn->GetY(),__pClearBtn->GetWidth(),__pClearBtn->GetHeight());
434                 }
435                 else
436                 {
437                 //      __pBgPanel->SetBounds(__pBgPanel->GetX(),__pBgPanel->GetY(),static_cast<Form*>(GetParent())->GetClientAreaBounds().width - __pCancelBtn->GetWidth() - 48,__pBgPanel->GetHeight());
438                 //      __pAddressbarBg->SetBounds(__pAddressbarBg->GetX(),__pAddressbarBg->GetY(),static_cast<Form*>(GetParent())->GetClientAreaBounds().width - __pCancelBtn->GetWidth() - 48,__pAddressbarBg->GetHeight());
439                         __pClearBtn->SetBounds(__pBgPanel->GetWidth() - __pClearBtn->GetWidth(),__pClearBtn->GetY(),__pClearBtn->GetWidth(),__pClearBtn->GetHeight());
440                 }
441
442         //      __pBgPanel->SetPosition(__pGoBackBtn->GetPosition().x,__pBgPanel->GetPosition().y);
443         //      __pCancelBtn->SetShowState(true);
444         //      __pRefreshBtn->SetShowState(false);
445                 __pStopBtn->SetShowState(false);
446         //      __pReaderBtn->SetShowState(false);
447         //      __pGoForwardBtn->SetShowState(false);
448         //      __pGoBackBtn->SetShowState(false);
449                 __pClearBtn->SetShowState(true);
450
451
452 //              __pCancelBtn->SetBounds(__pBgPanel->GetWidth(), __pCancelBtn->GetY(), GetWidth() - 48 - __pBgPanel->GetWidth(), __pCancelBtn->GetHeight());
453
454                 if (__pAddressbarUrlField && __pAddressbarUrlField->GetText().IsEmpty() == true)
455                 {
456                 //      __pSearchLabel->SetShowState(true);
457                 //      __pFaviconLabel->SetShowState(false);
458                 }
459                 else
460                 {
461                 //      __pSearchLabel->SetShowState(false);
462                 //      __pFaviconLabel->SetShowState(true);
463                 }
464                 if (__pAddressbarUrlField != NULL)
465                 {
466                         __pAddressbarUrlField->SetCursorPosition(__pAddressbarUrlField->GetTextLength());
467                 }
468
469         }
470         break;
471         }
472
473         if (__pAddressbarBg->GetWidth() != __pBgPanel->GetWidth())
474         {
475                 __pAddressbarBg->SetBounds(Rectangle(0, 0, __pBgPanel->GetWidth(), __pBgPanel->GetHeight()));
476                 Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(L"I01_search_input_field_bg.9.png", __pAddressbarBg->GetWidth(), __pAddressbarBg->GetHeight());
477                 if (pBitmap != null)
478                 {
479                         __pAddressbarBg->SetBackgroundBitmap(*pBitmap);
480                         delete pBitmap;
481                 }
482         }
483
484         Invalidate(true);
485
486         if (__pListener != null)
487         {
488                 __pListener->OnAddressBarModeChanged(*this);
489         }
490 }*/
491
492 void
493 Addressbar::SetFaviconBitmap(const Tizen::Graphics::Bitmap& favicon)
494 {
495
496         String url =__pAddressbarUrlField->GetText();
497         String secureSiteText = "https://";
498         bool flag = false;
499         flag = url.StartsWith(secureSiteText,0);
500
501         if (__pFavIcon != null)
502         {
503                 delete __pFavIcon;
504         }
505
506         __pFavIcon = new(std::nothrow) Bitmap();
507         __pFavIcon->Construct(favicon,Rectangle(0,0,favicon.GetWidth(),favicon.GetHeight()));
508
509         if (flag == true)
510         {
511                 Bitmap* pButtonImage = GetLockedImageN();
512
513                 if (pButtonImage != null)
514                 {
515                 //      __pFaviconLabel->SetBackgroundBitmap(*pButtonImage);
516                 //      __pFaviconLabel->Invalidate(true);
517                         delete pButtonImage;
518                 }
519         }
520         else
521         {
522                 /*if (__pFaviconLabel != null)
523                 {
524                         __pFaviconLabel->SetBackgroundBitmap(*__pFavIcon);
525                         __pFaviconLabel->Invalidate(true);
526                 }*/
527         }
528 }
529
530 void Addressbar::SaveAddressbarEditText()
531 {
532         __editTextUrl = __pAddressbarUrlField->GetText();
533 }
534
535 void
536 Addressbar::UpdateFaviconBitmap(bool isPrivateOn)
537 {
538
539         String url =__pAddressbarUrlField->GetText();
540         String secureSiteText = "https://";
541         bool flag = false;
542         flag = url.StartsWith(secureSiteText,0);
543
544         /*if (isPrivateOn == true)
545         {
546                 __pUrlField->SetBounds(__pLabelPrivateOn->GetBounds().x + __pLabelPrivateOn->GetBounds().width,__pUrlField->GetBounds().y , __pAddressbarBg->GetBounds().width - __pLabelPrivateOn->GetBounds().width - __pRefreshBtn->GetBounds().width - __pSearchLabel->GetBounds().width,__pUrlField->GetBounds().height );
547                 __pLabelPrivateOn->SetShowState(true);
548
549         }
550         else
551         {
552                 __pUrlField->SetBounds(__pLabelPrivateOn->GetBounds().x ,__pUrlField->GetBounds().y , __pAddressbarBg->GetBounds().width - __pRefreshBtn->GetBounds().width - __pSearchLabel->GetBounds().width,__pUrlField->GetBounds().height );
553                 __pLabelPrivateOn->SetShowState(false);
554         }*/
555
556
557         if (flag == true)
558                 {
559                         Bitmap* pButtonImage = GetLockedImageN();
560
561                         if (pButtonImage != null)
562                         {
563                         //      __pFaviconLabel->SetBackgroundBitmap(*pButtonImage);
564                         //      __pFaviconLabel->Invalidate(true);
565                                 delete pButtonImage;
566                         }
567                 }
568                 else
569                 {
570                         /*if (__pFaviconLabel != null)
571                         {
572                                 __pFaviconLabel->SetBackgroundBitmap(*__pFavIcon);
573                                 __pFaviconLabel->Invalidate(true);
574                         }*/
575                 }
576
577
578         __pAddressbarBg->Invalidate(true);
579 }
580
581 void
582 Addressbar::SetForwardButtonEnabled(bool isEnabled)
583 {
584 //      __pGoForwardBtn->SetEnabled(isEnabled);
585 //      __pGoBackBtn->Invalidate(true);
586 }
587
588 void
589 Addressbar::SetBackButtonEnabled(bool isEnabled)
590 {
591 //      __pGoBackBtn->SetEnabled(isEnabled);
592 //      __pGoBackBtn->Invalidate(true);
593 }
594
595 void
596 Addressbar::SetAddressbarEventListener(IAddressbarEventListener* plistener)
597 {
598         __pListener = plistener;
599 }
600
601 void
602 Addressbar::UpdateProgress(int percentage)
603 {
604         __progressPercentage = percentage;
605         if (percentage == 0 || percentage == 100)
606         {
607                 __isLoadingData = false;
608                 if (percentage == 100)
609                 {
610                         __isLoadingCompleted = true;
611                         __progressPercentage = 0;
612                 }
613                 else
614                 {
615                         __isLoadingCompleted = false;
616                 }
617         }
618         else
619         {
620                 __isLoadingData = true;
621         }
622         UpdateProgressBitmap();
623 }
624
625 int
626 Addressbar::GetProgress(void)
627 {
628         return __progressPercentage;
629 }
630
631 void
632 Addressbar::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
633 {
634         AppLogDebug("Addressbar::OnActionPerformed action %d",actionId);
635
636         switch (actionId)
637         {
638         case IDA_REFRESH_BTN_CLICKED:
639                 __isLoadingCompleted = false;
640                 __isLoadingData = true;
641                 __progressPercentage = 0;
642                 __pAddressbarUrlField->HideKeypad();
643                 __displayUrl = __pAddressbarUrlField->GetText();
644
645                 /*if (__pListener != NULL)
646                 {
647                         __pListener->OnUrlSubmitted(*this);
648                 }*/
649
650                 UpdateProgressBitmap();
651                 break;
652
653         case IDA_STOP_BTN_CLICKED:
654                 __isLoadingCompleted = false;
655                 __isLoadingData = false;
656                 __progressPercentage = 0;
657                 __pAddressbarUrlField->HideKeypad();
658                 __displayUrl = __pAddressbarUrlField->GetText();
659
660                 if (__pListener != NULL)
661                 {
662                         __pListener->OnStopClicked(*this);
663                 }
664
665                 UpdateProgressBitmap();
666                 break;
667         case IDA_READER_BTN_CLICKED:
668                 __pAddressbarUrlField->HideKeypad();
669                 __displayUrl = __pAddressbarUrlField->GetText();
670
671                 if (__pListener != NULL)
672                 {
673                         __pListener->OnReaderClicked(*this);
674                 }
675
676                 break;
677
678         /*case IDA_GO_BACK:
679         {
680                 if (__pListener != NULL)
681                 {
682                         __pListener->OnBackClicked(*this);
683
684                 }
685         }
686         break;
687
688         case IDA_GO_FORWARD:
689         {
690                 if (__pListener != NULL )
691                         __pListener->OnForwardClicked(*this);
692         }
693         break;*/
694
695         case IDA_CANCEL:
696         {
697                 __pListener->OnAddressCancelledClicked(*this);
698                 __pAddressbarUrlField->SetText(__displayUrl);
699                 __editTextUrl = L"";
700                 __pAddressbarUrlField->HideKeypad();
701                 //SetAddressbarMode(ADDRESSBAR_MODE_LOADING_COMPLETE);
702         }
703         break;
704
705         case IDA_CLEAR_URL:
706         {
707                 if (__pAddressbarUrlField->GetText().IsEmpty() == false)
708                 {
709                         //__displayUrl = __pUrlField->GetText();
710                         __pAddressbarUrlField->Clear();
711                         __pAddressbarUrlField->Invalidate(true);
712                 }
713         }
714         break;
715         default:
716                 break;
717         }
718 }
719
720 void
721 Addressbar::OnKeypadActionPerformed(Tizen::Ui::Control& source, Tizen::Ui::KeypadAction keypadAction)
722 {
723         AppLog("Addressbar::OnKeypadActionPerformed keypadAction %d",keypadAction);
724         switch (keypadAction)
725         {
726         case KEYPAD_ACTION_GO:
727         case KEYPAD_ACTION_ENTER:
728         case KEYPAD_ACTION_SEND:
729         {
730                 if (__pAddressbarUrlField->GetText().IsEmpty() == false)
731                 {
732                         //SetAddressbarMode(ADDRESSBAR_MODE_LOADING);
733                         __displayUrl = __pAddressbarUrlField->GetText();
734
735                         __isLoadingCompleted = false;
736                         __isLoadingData = true;
737                         __progressPercentage = 0;
738                         __pAddressbarUrlField->HideKeypad();
739
740                         if (__pListener != NULL)
741                         {
742                                 __pListener->OnUrlSubmitted(*this);
743                         }
744                         //UpdateProgressBitmap();
745                 }
746         }
747         break;
748
749         default:
750                 break;
751         }
752 }
753
754 void
755 Addressbar::OnKeypadClosed(Tizen::Ui::Control& source)
756 {
757         __pListener->OnAddressBarKeypadClosed(*this);
758 }
759
760 void
761 Addressbar::OnKeypadOpened(Tizen::Ui::Control& source)
762 {
763
764         __pListener->OnAddressBarKeypadClosed(*this,false);
765 }
766
767 void
768 Addressbar::OnKeypadWillOpen(Tizen::Ui::Control& source)
769 {
770         //SetAddressbarMode(ADDRESSBAR_MODE_EDIT);
771         //      SetAddressbarMode(__prevAddMode);
772         if(__pListener != null)
773         {
774                 __pListener->OnAddressBarKeypadWillOpen(*this);
775         }
776 }
777
778 void
779 Addressbar::OrientationChanged(void)
780 {
781         Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_SEARCH_INPUT_FIELD_BG, __pAddressbarBg->GetWidth(), __pAddressbarBg->GetHeight());
782         if (pBitmap != null)
783         {
784                 __pAddressbarBg->SetBackgroundBitmap(*pBitmap);
785                 delete pBitmap;
786         }
787         Invalidate(true);
788 }
789
790 String
791 Addressbar::RemoveHttpTextFromDisplayURL(void)
792 {
793         bool isHttpText = __displayUrl.Contains(L"http://");
794         String updatedDisplayUrl;
795         updatedDisplayUrl.Clear();
796
797         if (isHttpText == true)
798         {
799                 __displayUrl.SubString(7,updatedDisplayUrl);
800         }
801         return updatedDisplayUrl;
802 }
803
804 Bitmap*
805 Addressbar::GetLockedImageN(void)
806 {
807         Bitmap* pIconImage = null;
808
809         AppResource* pAppResource = Application::GetInstance()->GetAppResource();
810         if (pAppResource)
811         {
812                 pIconImage = pAppResource->GetBitmapN(IDB_ICON_PRIVATE);
813         }
814
815         Bitmap* pLockImage = new (std::nothrow) Bitmap();
816
817         Canvas* pCanvas = new (std::nothrow) Canvas();
818         pCanvas->Construct(Rectangle(0,0,__pFaviconLabel->GetWidth(),__pFaviconLabel->GetHeight()));
819         pCanvas->Clear();
820         pCanvas->DrawBitmap(Rectangle(0,0,__pFaviconLabel->GetWidth(),__pFaviconLabel->GetHeight()),*__pFavIcon);
821         pCanvas->DrawBitmap(Rectangle(__pFaviconLabel->GetWidth()/2,__pFaviconLabel->GetHeight()/2,__pFaviconLabel->GetWidth()/2,__pFaviconLabel->GetHeight()/2),*pIconImage);
822         pLockImage->Construct(*pCanvas,Rectangle(0,0,__pFaviconLabel->GetWidth(),__pFaviconLabel->GetHeight()));
823
824         delete pCanvas;
825         return pLockImage;
826 }
827
828 void
829 Addressbar::OnFocusGained(const Control& source)
830 {
831         //SetAddressbarMode(ADDRESSBAR_MODE_EDIT);
832         //      SetAddressbarMode(__prevAddMode);
833         if (__pListener != null)
834         {
835                 __pListener->OnAddressBarKeypadWillOpen(*this);
836                 __pListener->OnAddressBarKeypadOpened(*this);
837         }
838 }
839
840 void
841 Addressbar::OnTextValueChanged(const Control& source)
842 {
843         if(__pAddressbarUrlField != null)
844         {
845                 if(__pAddressbarUrlField->GetTextLength() == 0)
846                 {
847                         if(__pAddressbarUrlField->IsKeypadActionEnabled() == true)
848                         {
849                                 __pAddressbarUrlField->SetKeypadActionEnabled(false);
850                                 GetParent()->GetParent()->Invalidate(true);
851                         }
852                 }
853                 else
854                 {
855                         if(__pAddressbarUrlField->IsKeypadActionEnabled() == false)
856                         {
857                                 __pAddressbarUrlField->SetKeypadActionEnabled(true);
858                                 GetParent()->GetParent()->Invalidate(true);
859                         }
860                 }
861         }
862
863 }
864
865 void
866 Addressbar::SetAddressbarURLFocus()
867 {
868         __pAddressbarUrlField->SetFocus();
869 }
870
871 String
872 Addressbar::GetAddressbarURL()
873 {
874         return __pAddressbarUrlField->GetText();
875 }