2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.1 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
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.
18 /*@file: IntAddressbar
19 *@brief: This class defines common behaviour of Addressbar control.
22 #include "IntAddressbar.h"
23 #include "IntCommonLib.h"
25 #include "IntMultipleWindowPresentationModel.h"
26 #include "IntSettingPresentationModel.h"
27 #include "IntMultipleWindowPresentationModel.h"
29 using namespace Tizen::App;
30 using namespace Tizen::Base;
31 using namespace Tizen::Graphics;
32 using namespace Tizen::System;
33 using namespace Tizen::Ui;
34 using namespace Tizen::Ui::Controls;
36 static const wchar_t* IDB_SEARCH_INPUT_FIELD_BG = L"I01_toolbar_input_field.9.png";
37 static const wchar_t* IDB_TITLE_PROGRESS_BAR_BG = L"I01_title_progress_bar_bg.png";
38 static const wchar_t* IDB_TITLE_PROGRESS_BAR = L"I01_title_progress_bar.png";
39 static const wchar_t* IDB_ICON_PRIVATE = L"I01_icon_private.png";
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;
49 Addressbar::Addressbar(void)
51 //__currentAddMode = ADDRESSBAR_MODE_LOADING_COMPLETE;
53 // __editTextUrl = L"";
54 __isLoadingData = false;
55 __isLoadingCompleted = false;
56 __progressPercentage = 0;
57 __pAddressbarBg = null;
60 __pFavIcon = FaviconManager::GetInstance()->GetDefaultFaviconN();
61 __pFaviconLabel = null;
62 __pLabelPrivateOn = null;
64 __pPrivateIconLabel = null;
65 __pProgressbarLabel = null;
66 __pPrivateIconLabel = null ;
68 __pSearchLabel = null;
69 __pAddressbarUrlField = null;
70 __pToolBarLabel = null;
71 __pAddressbarURLLabel = null;
72 __pAddressBackBtn = null;
73 __isClipboardOpen = false;
74 __isKeyboardConnected = false;
75 __isKeyPadOpened = false;
78 Addressbar::~Addressbar(void)
80 if (__pFavIcon != null)
88 Addressbar::OnTerminating(void)
90 DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_USB_CLIENT, *this);
94 Addressbar::Initialize(const Rectangle& rect)
98 AppLogDebug("Addressbar::Initialize entered");
99 //Construct the base first
100 r = Construct(L"IDL_ADDRESSBAR");
102 //Add background label
103 Label* pBgLabel = static_cast<Label*> (GetControl(L"IDC_BG_LABEL",true));
104 if (pBgLabel == NULL)
106 AppLogDebug("Control not found returning E_INVALID_KEY");
107 return E_INVALID_KEY;
110 //Add inner panel for border
111 __pBgPanel = static_cast<Panel*> (GetControl(L"IDC_BG_PANEL",true));
112 if (__pBgPanel == NULL)
114 AppLogDebug("Control not found returning E_INVALID_KEY");
115 return E_INVALID_KEY;
118 __pAddressbarBg = static_cast<Label*> (GetControl(L"IDC_ADDRESSBAR_BG_LABEL",true));
119 if (__pAddressbarBg == NULL)
121 AppLogDebug("Control not found returning E_INVALID_KEY");
122 return E_INVALID_KEY;
124 __pBgPanel->SetBackgroundColor(CUSTOM_COLOR_TRANSPARENT);
125 Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_SEARCH_INPUT_FIELD_BG, __pAddressbarBg->GetWidth(), __pAddressbarBg->GetHeight());
128 __pAddressbarBg->SetBackgroundBitmap(*pBitmap);
132 __pClearBtn = static_cast<Button*> (GetControl(L"IDC_CLEAR_BUTTON",true));
133 if (__pClearBtn == NULL)
135 AppLogDebug("Control not found returning E_INVALID_KEY");
136 return E_INVALID_KEY;
138 __pClearBtn->SetActionId(IDA_CLEAR_URL);
139 __pClearBtn->AddActionEventListener(*this);
140 __pClearBtn->SetShowState(true);
142 //Add the editfield for url
143 __pAddressbarUrlField = static_cast<EditField*> (GetControl(L"IDC_URL_EDITFIELD",true));
144 if (__pAddressbarUrlField == NULL)
146 AppLogDebug("Control not found returning E_INVALID_KEY");
147 return E_INVALID_KEY;
150 __pAddressbarUrlField->SetOverlayKeypadCommandButtonVisible(false);
151 __pAddressbarUrlField->SetKeypadAction(KEYPAD_ACTION_GO);
152 __pAddressbarUrlField->AddFocusEventListener(*this);
153 __pAddressbarUrlField->AddTextEventListener(*this);
154 if(__pAddressbarUrlField->GetTextLength() == 0)
156 __pAddressbarUrlField->SetKeypadActionEnabled(false);
160 __pAddressbarUrlField->SetKeypadActionEnabled(true);
163 __pToolBarLabel = static_cast<Label*> (GetControl(L"IDC_TOOLBAR_LABEL",true));
164 if (__pToolBarLabel == NULL)
166 AppLogDebug("Control not found returning E_INVALID_KEY");
167 return E_INVALID_KEY;
169 __pToolBarLabel->SetShowState(true);
171 __pAddressbarURLLabel = static_cast<Label*> (GetControl(L"IDC_URL_LABEL",true));
172 if (__pAddressbarURLLabel == NULL)
174 AppLogDebug("__pURLLabel Control not found returning E_INVALID_KEY");
175 return E_INVALID_KEY;
177 __pAddressbarURLLabel->SetShowState(true);
179 __pAddressBackBtn = static_cast<Button*> (GetControl(L"IDC_ADDRESS_BACK_BUTTON",true));
180 if (__pAddressBackBtn == NULL)
182 AppLogDebug("__pAddressBackBtn Control not found returning E_INVALID_KEY");
183 return E_INVALID_KEY;
185 __pAddressBackBtn->SetActionId(IDA_CANCEL);
186 __pAddressBackBtn->AddActionEventListener(*this);
187 __pAddressBackBtn->SetShowState(true);
188 //IDC_ADDRESS_BACK_BUTTON
190 // Added to get the favorite url if not set then address bar is about blank
192 if (SettingPresentationModel::GetInstance()->GetHomepage().CompareTo((L"IDS_BR_BODY_MOST_VISITED_SITES")) == 0)
194 __pAddressbarUrlField->SetGuideText(CommonUtil::GetString(L"IDS_BR_BODY_SEARCH_OR_ENTER_URL"));
196 else if (SettingPresentationModel::GetInstance()->GetHomepage().CompareTo((L"IDS_BR_BODY_BLANK_PAGE")) == 0)
198 __pAddressbarUrlField->SetGuideText(CommonUtil::GetString(L"IDS_BR_BODY_ABOUT_C_BLANK"));
202 //__pUrlField->SetText(SettingPresentationModel::GetInstance()->GetFavoriteURL());
203 __pAddressbarUrlField->SetGuideText(CommonUtil::GetString(L"IDS_BR_BODY_SEARCH_OR_ENTER_URL"));
205 __pAddressbarUrlField->AddKeypadEventListener(*this);
207 r = DeviceManager::AddDeviceEventListener(DEVICE_TYPE_USB_CLIENT,*this);
208 AppLog("1234:: DeviceManager::AddDeviceEventListener result %s",GetErrorMessage(r));
209 AppLogDebug("Addressbar::Initialize exit");
214 Addressbar::UpdateProgressBitmap(void)
216 result r = E_SUCCESS;
217 if (__pProgressbarLabel == null)
219 int w = __pProgressbarLabel->GetWidth();
220 int h = __pProgressbarLabel->GetHeight();
222 int progressWidth = 0;
223 Bitmap* pRetBitmap = null;
225 if (__progressPercentage == 0 || __progressPercentage == 100)
227 __pProgressbarLabel->SetShowState(false);
228 __pProgressbarLabel->Invalidate(false);
233 __pProgressbarLabel->SetShowState(true);
234 __pProgressbarLabel->Invalidate(false);
237 r = canvas.Construct(Rectangle(0, 0, w, h));
241 AppLogException("Canvas construction failed with %s", GetErrorMessage(r));
246 Bitmap *pBgBmp = AppResource::GetInstance()->GetBitmapN(IDB_TITLE_PROGRESS_BAR_BG);
250 pBgBmp->Scale(Dimension(w, h));
251 canvas.DrawBitmap(Point(0,0), *pBgBmp);
255 progressWidth = (double) (w) * __progressPercentage / 100;
256 AppLogDebug("progressWidth: %d", progressWidth);
257 Bitmap *pProgressBmp = AppResource::GetInstance()->GetBitmapN(IDB_TITLE_PROGRESS_BAR);
259 if (pProgressBmp != null)
261 pProgressBmp->Scale(Dimension(progressWidth, h));
262 canvas.DrawBitmap(Point(0,0), *pProgressBmp);
266 pRetBitmap = new (std::nothrow) Bitmap();
268 if (pRetBitmap == null)
270 AppLogException("Bitmap creation failed with %s", GetErrorMessage(r));
274 pRetBitmap->Construct(canvas, canvas.GetBounds());
276 if (__pProgressbarLabel != null && pRetBitmap != null)
278 __pProgressbarLabel->SetBackgroundBitmap(*pRetBitmap);
279 __pProgressbarLabel->Invalidate(false);
283 if (pRetBitmap != null)
292 Addressbar::ResetGuideText(void)
294 AppLog("Addressbar::ResetGuideText called");
296 if (SettingPresentationModel::GetInstance()->GetHomepage().CompareTo((L"IDS_BR_BODY_MOST_VISITED_SITES")) == 0)
298 __pAddressbarUrlField->SetGuideText(CommonUtil::GetString(L"IDS_BR_BODY_SEARCH_OR_ENTER_URL"));
300 else if (SettingPresentationModel::GetInstance()->GetHomepage().CompareTo((L"IDS_BR_BODY_BLANK_PAGE")) == 0)
302 __pAddressbarUrlField->SetGuideText(CommonUtil::GetString(L"IDS_BR_BODY_ABOUT_C_BLANK"));
306 //__pUrlField->SetText(SettingPresentationModel::GetInstance()->GetFavoriteURL());
307 __pAddressbarUrlField->SetGuideText(CommonUtil::GetString(L"IDS_BR_BODY_SEARCH_OR_ENTER_URL"));
309 __pAddressbarUrlField->Invalidate(true);
313 Addressbar::SetUrl(const String& url)
316 String updatedDisplayUrl;
317 updatedDisplayUrl.Clear();
319 if (__pAddressbarUrlField != NULL)
321 String removedHttpUrl = RemoveHttpTextFromDisplayURL();
322 if (removedHttpUrl.IsEmpty() == false)
324 __pAddressbarUrlField->SetText(removedHttpUrl);
328 __pAddressbarUrlField->SetText(__displayUrl);
331 __pAddressbarUrlField->Invalidate(false);
332 __pAddressbarUrlField->SetCursorPosition(__pAddressbarUrlField->GetTextLength());
337 Addressbar::GetUrl(void)
343 Addressbar::SetFaviconBitmap(const Tizen::Graphics::Bitmap& favicon)
346 String url =__pAddressbarUrlField->GetText();
347 String secureSiteText = "https://";
349 flag = url.StartsWith(secureSiteText,0);
351 if (__pFavIcon != null)
356 __pFavIcon = new(std::nothrow) Bitmap();
357 __pFavIcon->Construct(favicon,Rectangle(0,0,favicon.GetWidth(),favicon.GetHeight()));
360 void Addressbar::SaveAddressbarEditText()
362 // __editTextUrl = __pAddressbarUrlField->GetText();
366 Addressbar::UpdateFaviconBitmap(bool isPrivateOn)
369 String url =__pAddressbarUrlField->GetText();
370 String secureSiteText = "https://";
372 flag = url.StartsWith(secureSiteText,0);
374 __pAddressbarBg->Invalidate(true);
378 Addressbar::SetForwardButtonEnabled(bool isEnabled)
383 Addressbar::SetBackButtonEnabled(bool isEnabled)
388 Addressbar::SetAddressbarEventListener(IAddressbarEventListener* plistener)
390 __pListener = plistener;
394 Addressbar::UpdateProgress(int percentage)
396 __progressPercentage = percentage;
397 if (percentage == 0 || percentage == 100)
399 __isLoadingData = false;
400 if (percentage == 100)
402 __isLoadingCompleted = true;
403 __progressPercentage = 0;
407 __isLoadingCompleted = false;
412 __isLoadingData = true;
414 UpdateProgressBitmap();
418 Addressbar::GetProgress(void)
420 return __progressPercentage;
424 Addressbar::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
426 AppLogDebug("Addressbar::OnActionPerformed action %d",actionId);
432 // __pAddressbarUrlField->HideKeypad();
433 __pListener->OnAddressCancelledClicked(*this);
434 //SetAddressbarMode(ADDRESSBAR_MODE_LOADING_COMPLETE);
440 if (__pAddressbarUrlField->GetText().IsEmpty() == false)
442 //__displayUrl = __pUrlField->GetText();
443 __pAddressbarUrlField->Clear();
444 __pAddressbarUrlField->SetKeypadActionEnabled(false);
445 __pAddressbarUrlField->Invalidate(true);
455 Addressbar::OnKeypadActionPerformed(Tizen::Ui::Control& source, Tizen::Ui::KeypadAction keypadAction)
457 AppLog("XYZ::Addressbar::OnKeypadActionPerformed keypadAction %d",keypadAction);
458 switch (keypadAction)
460 case KEYPAD_ACTION_GO:
461 case KEYPAD_ACTION_ENTER:
462 case KEYPAD_ACTION_SEND:
464 if (__pAddressbarUrlField->GetText().IsEmpty() == false)
466 //SetAddressbarMode(ADDRESSBAR_MODE_LOADING);
467 __displayUrl = __pAddressbarUrlField->GetText();
469 __isLoadingCompleted = false;
470 __isLoadingData = true;
471 __progressPercentage = 0;
472 __pAddressbarUrlField->HideKeypad();
474 if (__pListener != NULL)
476 __pListener->OnUrlSubmitted(*this);
479 //UpdateProgressBitmap();
490 Addressbar::OnKeypadClosed(Tizen::Ui::Control& source)
492 AppLog("XYZ::Addressbar::OnKeypadClosed");
494 __isKeyPadOpened = false;
496 if (__isKeyboardConnected == true)
500 if (__isClipboardOpen == true)
502 __isClipboardOpen = false;
503 __pListener->OnClipboardClosed(*this);
508 // if(__pAddressbarUrlField)
510 // String removedHttpUrl = RemoveHttpTextFromDisplayURL();
511 // if (removedHttpUrl.IsEmpty() == false)
513 // __pAddressbarUrlField->SetText(removedHttpUrl);
517 // __pAddressbarUrlField->SetText(__displayUrl);
520 // __editTextUrl = L"";
521 if(__pListener != null)
523 __pListener->OnAddressBarKeypadClosed(*this,true);
528 Addressbar::OnKeypadOpened(Tizen::Ui::Control& source)
530 AppLog("XYZ::Addressbar::OnKeypadOpened");
531 AppLog("Addressbar::OnKeypadOpened %d",Clipboard::GetInstance()->IsPopupVisible());
533 __isKeyPadOpened = true;
535 __isClipboardOpen = Clipboard::GetInstance()->IsPopupVisible();
537 if(__pListener != null)
539 __pListener->OnAddressBarKeypadOpened(*this);
544 Addressbar::OnKeypadWillOpen(Tizen::Ui::Control& source)
546 AppLog("XYZ::Addressbar::OnKeypadWillOpen");
551 Addressbar::OnKeypadBoundsChanged(Tizen::Ui::Control &source)
553 AppLog("Coming here");
554 if(__pListener != null)
556 __pListener->OnAddressBarKeypadBoundsChanged(*this);
561 Addressbar::OrientationChanged( int& width)
564 __pBgPanel->SetBounds(__pBgPanel->GetX(),__pBgPanel->GetY(), width - __pAddressBackBtn->GetWidth() - gap -__pBgPanel->GetX() ,__pBgPanel->GetHeight());
565 __pAddressBackBtn->SetBounds(width - __pAddressBackBtn->GetWidth() - 6,__pAddressBackBtn->GetY(),__pAddressBackBtn->GetWidth(),__pAddressBackBtn->GetHeight());
566 __pClearBtn->SetBounds(__pBgPanel->GetWidth() - __pClearBtn->GetWidth() ,__pClearBtn->GetY(),__pClearBtn->GetWidth(),__pClearBtn->GetHeight());
568 Bitmap *pBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_SEARCH_INPUT_FIELD_BG, __pAddressbarBg->GetWidth(), __pAddressbarBg->GetHeight());
571 __pAddressbarBg->SetBackgroundBitmap(*pBitmap);
579 Addressbar::RemoveHttpTextFromDisplayURL(void)
581 bool isHttpText = __displayUrl.Contains(L"http://");
582 String updatedDisplayUrl;
583 updatedDisplayUrl.Clear();
585 if (isHttpText == true)
587 __displayUrl.SubString(7,updatedDisplayUrl);
589 return updatedDisplayUrl;
593 Addressbar::GetLockedImageN(void)
595 Bitmap* pIconImage = null;
597 AppResource* pAppResource = Application::GetInstance()->GetAppResource();
600 pIconImage = pAppResource->GetBitmapN(IDB_ICON_PRIVATE);
603 Bitmap* pLockImage = new (std::nothrow) Bitmap();
605 Canvas* pCanvas = new (std::nothrow) Canvas();
606 pCanvas->Construct(Rectangle(0,0,__pFaviconLabel->GetWidth(),__pFaviconLabel->GetHeight()));
608 if(__pFavIcon != null)
610 pCanvas->DrawBitmap(Rectangle(0,0,__pFaviconLabel->GetWidth(),__pFaviconLabel->GetHeight()),*__pFavIcon);
612 if(pIconImage != null)
614 pCanvas->DrawBitmap(Rectangle(__pFaviconLabel->GetWidth()/2,__pFaviconLabel->GetHeight()/2,__pFaviconLabel->GetWidth()/2,__pFaviconLabel->GetHeight()/2),*pIconImage);
616 pLockImage->Construct(*pCanvas,Rectangle(0,0,__pFaviconLabel->GetWidth(),__pFaviconLabel->GetHeight()));
623 Addressbar::OnFocusGained(const Control& source)
625 AppLog("XYZ::Addressbar::OnFocusGained");
626 if(__pAddressbarUrlField != null)
628 __pAddressbarUrlField->SetCursorPosition(__pAddressbarUrlField->GetTextLength());
629 if(__pAddressbarUrlField->GetTextLength() == 0)
631 __pAddressbarUrlField->SetKeypadActionEnabled(false);
635 __pAddressbarUrlField->SetKeypadActionEnabled(true);
638 if (__pListener != null)
640 __pListener->OnAddressBarFocusGained(*this);
645 Addressbar::OnFocusLost(const Tizen::Ui::Control& source)
647 AppLog("XYZ::Addressbar::OnFocusLost");
648 if(__pAddressbarUrlField)
650 String removedHttpUrl = RemoveHttpTextFromDisplayURL();
651 if (removedHttpUrl.IsEmpty() == false)
653 __pAddressbarUrlField->SetText(removedHttpUrl);
657 __pAddressbarUrlField->SetText(__displayUrl);
660 // __editTextUrl = L"";
661 if(__pListener != null)
663 __pListener->OnAddressBarFocusLost(*this, __isKeyPadOpened);
668 Addressbar::OnTextValueChanged(const Control& source)
670 if(__pAddressbarUrlField != null)
672 if(__pAddressbarUrlField->GetTextLength() == 0)
674 __pAddressbarUrlField->SetKeypadActionEnabled(false);
678 __pAddressbarUrlField->SetKeypadActionEnabled(true);
684 Addressbar::OnDeviceStateChanged(DeviceType deviceType, const String &state)
686 AppLog("1234:: Addressbar::OnDeviceStateChanged %ls %d",state.GetPointer(),(int)deviceType);
687 if(deviceType == DEVICE_TYPE_KEYBOARD && state.Equals(L"Closed",true) == 0)
689 __isKeyboardConnected = true;
693 Addressbar::SetAddressbarURLFocus()
695 __pAddressbarUrlField->SetFocus();
699 Addressbar::GetAddressbarURL()
701 return __pAddressbarUrlField->GetText();