2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FWebCtrl_AuthConfirmPopup.cpp
20 * @brief The file contains the definition of _AuthConfirmPopup class.
22 #include <FBaseColArrayList.h>
23 #include <FBaseSysLog.h>
24 #include <FGrpDimension.h>
25 #include <FGrpRectangle.h>
26 #include <FSysVibrator.h>
27 #include <FUiCtrlButton.h>
28 #include <FUiCtrlEditField.h>
29 #include <FUiCtrlLabel.h>
30 #include <FUiCtrlPanel.h>
31 #include <FUiKeyEventInfo.h>
32 #include <FUiLayout.h>
33 #include <FUiVerticalBoxLayout.h>
34 #include <FWebCtrlAuthenticationChallenge.h>
35 #include <FSys_SystemResource.h>
36 #include <FSys_VibratorImpl.h>
37 #include <FUi_ControlManager.h>
38 #include <FUi_ResourceManager.h>
39 #include "FWebCtrl_AuthConfirmPopup.h"
40 #include "FWebCtrl_WebImpl.h"
43 using namespace Tizen::Base;
44 using namespace Tizen::Base::Collection;
45 using namespace Tizen::Graphics;
46 using namespace Tizen::System;
47 using namespace Tizen::Ui;
48 using namespace Tizen::Ui::Controls;
51 namespace Tizen { namespace Web { namespace Controls
55 static const int EDIT_TEXT_SIZE = 35;
58 _AuthConfirmPopup::_AuthConfirmPopup(void)
59 : __pIdEditField(null)
60 , __pPwdEditField(null)
61 , __pAuthHandler(null)
66 _AuthConfirmPopup::~_AuthConfirmPopup(void)
70 __pAuthHandler->Cancel();
75 // Authentication popup
77 _AuthConfirmPopup::Construct(const String& host, const String& realm, AuthenticationChallenge* pAuth)
79 SysTryReturnResult(NID_WEB_CTRL, pAuth != null, E_INVALID_ARG, "invalid argument(s) is used. The AuthenticationChallenge is null.");
81 __pAuthHandler = pAuth;
83 _SystemResource* pSysResource = _SystemResource::GetInstance();
84 SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
87 _WebPopupData* pPopupData = _WebPopup::GetPopupData();
88 SysTryReturn(NID_WEB_CTRL, pPopupData, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
90 Rectangle rect(0, 0, 0, 0);
91 rect.width = pPopupData->popupDim.width;
92 rect.height = (2*pPopupData->spacePad) + (pPopupData->editDim.height*2) + pPopupData->panelHeight + (2*pPopupData->labelDim.height);
93 r = _WebPopup::Construct(true, Dimension(rect.width, rect.height));
94 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
96 SetTitleText(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_HEADER_ENTER_CREDENTIALS_ABB"));
99 rect.height = 2*pPopupData->labelDim.height;
101 std::unique_ptr<Label> pLabel(new (std::nothrow) Label());
102 SysTryReturnResult(NID_WEB_CTRL, pLabel.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
104 String hostRealm(host);
105 hostRealm.Append(L": \n ");
106 hostRealm.Append(realm);
107 r = pLabel->Construct(rect, hostRealm);
108 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
110 pLabel->SetTextConfig(pPopupData->labelFontSize, LABEL_TEXT_STYLE_NORMAL);
112 r = AddControl(*pLabel);
113 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
115 Label* pHostLabel = pLabel.release();
120 rect.height = pPopupData->editDim.height;
121 rect.width = pPopupData->labelDim.width;
123 std::unique_ptr<EditField> pIdEditField(new (std::nothrow) EditField());
124 SysTryReturnResult(NID_WEB_CTRL, pIdEditField.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
126 r = pIdEditField->Construct(rect, EDIT_FIELD_STYLE_NORMAL);
127 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
129 pIdEditField->SetGuideText(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_WIFI_BODY_ENTER_YOUR_ID"));
130 pIdEditField->SetGuideTextColor(Color::GetColor(COLOR_ID_GREY));
131 pIdEditField->SetTextSize(EDIT_TEXT_SIZE);;
133 r = AddControl(*pIdEditField);
134 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
136 __pIdEditField = pIdEditField.release();
138 std::unique_ptr<EditField> pPwdEditField(new (std::nothrow) EditField());
139 SysTryReturnResult(NID_WEB_CTRL, pPwdEditField.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
141 r = pPwdEditField->Construct(rect, EDIT_FIELD_STYLE_PASSWORD);
142 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
144 pPwdEditField->SetGuideText(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_BODY_ENTER_YOUR_PASSWORD_ABB"));
145 pPwdEditField->SetGuideTextColor(Color::GetColor(COLOR_ID_GREY));
146 pPwdEditField->SetTextSize(EDIT_TEXT_SIZE);;
148 r = AddControl(*pPwdEditField);
149 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
151 __pPwdEditField = pPwdEditField.release();
152 __pIdEditField->SetFocus();
154 Panel* pButtonPanel = CreateAndAddPanel();
155 SysTryReturn(NID_WEB_CTRL, pButtonPanel, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
159 r = idList.Construct();
160 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
161 idList.Add(*(new Integer(ID_BUTTON_AUTH_CANCEL)));
162 idList.Add(*(new Integer(ID_BUTTON_AUTH_PROCESS)));
165 r = titleList.Construct();
166 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
167 titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_BUTTON_CANCEL_ABB"))));
168 titleList.Add(*(new String(pSysResource->GetString(_RESOURCE_DOMAIN_ID_OSP, "IDS_TPLATFORM_BUTTON_CONTINUE_ABB"))));
170 r = CreateAndAddButtons(idList, titleList, pButtonPanel);
171 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
173 std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(GetLayoutN()));
174 SysTryReturn(NID_WEB_CTRL, pLayout.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
176 pLayout->SetHorizontalAlignment(*pHostLabel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
177 pLayout->SetHorizontalAlignment(*__pIdEditField, LAYOUT_HORIZONTAL_ALIGN_CENTER);
178 pLayout->SetHorizontalAlignment(*__pPwdEditField, LAYOUT_HORIZONTAL_ALIGN_CENTER);
180 pLayout->SetSpacing(*__pPwdEditField, pPopupData->spacePad);
181 pLayout->SetSpacing(*pButtonPanel, pPopupData->spacePad);
183 SetPropagatedKeyEventListener(this);
190 _AuthConfirmPopup::OnActionPerformed(const Control& source, int actionId)
192 result r = E_SUCCESS;
195 SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
199 case ID_BUTTON_AUTH_PROCESS:
200 __pAuthHandler->Process(__pIdEditField->GetText(), __pPwdEditField->GetText());
203 case ID_BUTTON_AUTH_CANCEL:
204 __pAuthHandler->Cancel();
213 _AuthConfirmPopup::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
219 _AuthConfirmPopup::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
221 result r = E_SUCCESS;
222 if ((keyEventInfo.GetKeyCode() == KEY_ESC || keyEventInfo.GetKeyCode() == KEY_BACK) && source.GetShowState() == true)
224 __pAuthHandler->Cancel();
228 SysLogException(NID_WEB_CTRL, r, "[%s] Propagating.", GetErrorMessage(r));
236 _AuthConfirmPopup::OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
242 _AuthConfirmPopup::OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
248 _AuthConfirmPopup::TranslateKeyEventInfo(Control& source, KeyEventInfo& keyEventInfo)
254 }}} // Tizen::Web::Controls