popup modifications as a result of client area change
[framework/osp/web.git] / src / controls / FWebCtrl_AuthConfirmPopup.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file                FWebCtrl_AuthConfirmPopup.cpp
20  * @brief               The file contains the definition of _AuthConfirmPopup class.
21  */
22 #include <FBaseColArrayList.h>
23 #include <FBaseSysLog.h>
24 #include <FGrpDimension.h>
25 #include <FGrpRectangle.h>
26 #include <FUiCtrlButton.h>
27 #include <FUiCtrlEditField.h>
28 #include <FUiCtrlLabel.h>
29 #include <FUiCtrlPanel.h>
30 #include <FUiLayout.h>
31 #include <FUiVerticalBoxLayout.h>
32 #include <FWebCtrlAuthenticationChallenge.h>
33 #include <FSys_SystemResource.h>
34 #include <FUi_ControlManager.h>
35 #include <FUi_ResourceManager.h>
36 #include "FWebCtrl_WebImpl.h"
37 #include "FWebCtrl_AuthConfirmPopup.h"
38
39
40 using namespace Tizen::Base;
41 using namespace Tizen::Base::Collection;
42 using namespace Tizen::Graphics;
43 using namespace Tizen::System;
44 using namespace Tizen::Ui;
45 using namespace Tizen::Ui::Controls;
46
47
48 static const int AUTH_POPUP_TMP_LABLE_HEIGHT = 10;
49
50
51 namespace Tizen { namespace Web { namespace Controls
52 {
53
54
55 _AuthConfirmPopup::_AuthConfirmPopup(void)
56         : __pIdEditField(null)
57         , __pPwdEditField(null)
58         , __pAuthHandler(null)
59 {
60 }
61
62
63 _AuthConfirmPopup::~_AuthConfirmPopup(void)
64 {
65 }
66
67
68 // Authentication popup
69 result
70 _AuthConfirmPopup::Construct(const String& host, const String& realm, AuthenticationChallenge* pAuth)
71 {
72         SysTryReturnResult(NID_WEB_CTRL, pAuth != null, E_INVALID_ARG, "invalid argument(s) is used. The AuthenticationChallenge is null.");
73
74         __pAuthHandler = pAuth;
75
76         _SystemResource* pSysResource = _SystemResource::GetInstance();
77         SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
78
79         result r = E_SUCCESS;
80         _WebPopupData* pPopupData = _WebPopup::GetPopupData();
81         SysTryReturn(NID_WEB_CTRL, pPopupData, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
82
83         Rectangle rect(0, 0, 0, 0);
84         rect.width = pPopupData->popupDim.width;
85         rect.height = (5*pPopupData->spacePad) + (pPopupData->editDim.height*2) + pPopupData->btnDim.height + 2*pPopupData->labelDim.height;
86         r = _WebPopup::Construct(true, Dimension(rect.width, rect.height));
87         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
88
89         SetTitleText("Authentication Required");
90
91         //host realm label
92         rect.height = 2*pPopupData->labelDim.height;
93
94         std::unique_ptr<Label> pLabel(new (std::nothrow) Label());
95         SysTryReturnResult(NID_WEB_CTRL, pLabel.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
96
97         String hostRealm(L"A username and password are being requested by ");
98         hostRealm.Append(host);
99         hostRealm.Append(L". The site says: \"");
100         hostRealm.Append(realm);
101         hostRealm.Append(L"\"");
102         r = pLabel->Construct(rect, hostRealm);
103         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
104
105         pLabel->SetTextConfig(pPopupData->labelFontSize, LABEL_TEXT_STYLE_NORMAL);
106
107         r = AddControl(*pLabel);
108         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
109
110         Label* pHostLabel = pLabel.release();
111
112         // Id Edit Field
113         rect.x = 0;
114         rect.y = 0;
115         rect.height = pPopupData->editDim.height;
116         rect.width = pPopupData->labelDim.width;
117
118         std::unique_ptr<EditField> pIdEditField(new (std::nothrow) EditField());
119         SysTryReturnResult(NID_WEB_CTRL, pIdEditField.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
120
121         r = pIdEditField->Construct(rect, EDIT_FIELD_STYLE_NORMAL);
122         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
123
124         pIdEditField->SetGuideText(L"User name");
125         pIdEditField->SetGuideTextColor(Color::GetColor(COLOR_ID_GREY));
126         pIdEditField->SetTextSize(35);;
127
128         r = AddControl(*pIdEditField);
129         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
130
131         __pIdEditField = pIdEditField.release();
132
133         std::unique_ptr<EditField> pPwdEditField(new (std::nothrow) EditField());
134         SysTryReturnResult(NID_WEB_CTRL, pPwdEditField.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
135
136         r = pPwdEditField->Construct(rect, EDIT_FIELD_STYLE_PASSWORD);
137         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
138
139         pPwdEditField->SetGuideText(L"Password");
140         pPwdEditField->SetGuideTextColor(Color::GetColor(COLOR_ID_GREY));
141         pPwdEditField->SetTextSize(35);;
142
143         r = AddControl(*pPwdEditField);
144         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
145
146         __pPwdEditField = pPwdEditField.release();
147         __pIdEditField->SetFocus();
148
149         Panel* pButtonPanel = CreateAndAddPanel();
150         SysTryReturn(NID_WEB_CTRL, pButtonPanel, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
151
152         //Add Buttons
153         ArrayList idList;
154         r = idList.Construct();
155         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
156         idList.Add(*(new Integer(ID_BUTTON_AUTH_PROCESS)));
157         idList.Add(*(new Integer(ID_BUTTON_AUTH_CANCEL)));
158
159         ArrayList titleList;
160         r = titleList.Construct();
161         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
162         titleList.Add(*(new String(pSysResource->GetString("sys_string", "IDS_COM_SK_OK"))));
163         titleList.Add(*(new String(pSysResource->GetString("sys_string", "IDS_COM_POP_CANCEL"))));
164
165         r = CreateAndAddButtons(idList, titleList, pButtonPanel);
166         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
167
168         std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(GetLayoutN()));
169         SysTryReturn(NID_WEB_CTRL, pLayout.get(), GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
170
171         pLayout->SetHorizontalAlignment(*pHostLabel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
172         pLayout->SetHorizontalAlignment(*__pIdEditField, LAYOUT_HORIZONTAL_ALIGN_CENTER);
173         pLayout->SetHorizontalAlignment(*__pPwdEditField, LAYOUT_HORIZONTAL_ALIGN_CENTER);
174         pLayout->SetHorizontalAlignment(*pButtonPanel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
175
176         pLayout->SetSpacing(*__pPwdEditField, pPopupData->spacePad);
177         pLayout->SetSpacing(*pButtonPanel, pPopupData->spacePad);
178
179         return E_SUCCESS;
180 }
181
182
183 void
184 _AuthConfirmPopup::OnActionPerformed(const Control& source, int actionId)
185 {
186         result r = E_SUCCESS;
187
188         switch (actionId)
189         {
190         case ID_BUTTON_AUTH_PROCESS:
191                 __pAuthHandler->Process(__pIdEditField->GetText(), __pPwdEditField->GetText());
192                 break;
193
194         case ID_BUTTON_AUTH_CANCEL:
195                 __pAuthHandler->Cancel();
196                 break;
197
198         default:
199                 break;
200         }
201
202         r = HidePopup();
203         SysTryReturnVoidResult(NID_WEB_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
204 }
205
206
207 }}} // Tizen::Web::Controls