fix gbs/obs build failure
[framework/osp/web.git] / src / controls / FWebCtrl_PromptPopup.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 <ewk_view.h>
23 #include <FBaseColIList.h>
24 #include <FBaseSysLog.h>
25 #include <FGrpColor.h>
26 #include <FGrpDimension.h>
27 #include <FGrpRectangle.h>
28 #include <FUiCtrlButton.h>
29 #include <FUiCtrlEditField.h>
30 #include <FUiCtrlLabel.h>
31 #include <FUiCtrlPanel.h>
32 #include <FUiCtrlTextBox.h>
33 #include <FUiKeyEventInfo.h>
34 #include <FUiLayout.h>
35 #include <FUiVerticalBoxLayout.h>
36 #include <FWebCtrlAuthenticationChallenge.h>
37 #include <FBase_StringConverter.h>
38 #include <FSys_SystemResource.h>
39 #include <FUi_ControlManager.h>
40 #include <FUi_ResourceManager.h>
41 #include <FUiCtrl_TextBoxImpl.h>
42 #include "FWebCtrl_PromptPopup.h"
43 #include "FWebCtrl_WebImpl.h"
44
45
46 using namespace Tizen::Base;
47 using namespace Tizen::Base::Collection;
48 using namespace Tizen::Graphics;
49 using namespace Tizen::System;
50 using namespace Tizen::Ui;
51 using namespace Tizen::Ui::Controls;
52
53
54 namespace Tizen { namespace Web { namespace Controls
55 {
56
57
58 static const int EDIT_TEXT_SIZE = 35;
59
60
61 _PromptPopup::_PromptPopup(void)
62         : __pEditField(null)
63         , __pWebView(null)
64         , __pImpl(null)
65 {
66 }
67
68
69 _PromptPopup::~_PromptPopup(void)
70 {
71 }
72
73
74 // Prompt popup
75 result
76 _PromptPopup::Construct(const String& message, const String& defaultVale,  Evas_Object* pView, _WebImpl* pImpl)
77 {
78         result r = E_SUCCESS;
79         Rectangle rect(0, 0, 0, 0);
80
81         int popupHeight = 0;
82
83         __pImpl = pImpl;
84         __pWebView = pView;
85
86         _WebPopupData* pPopupData = _WebPopup::GetPopupData();
87         SysTryReturn(NID_WEB_CTRL, pPopupData, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
88
89         popupHeight = pPopupData->editDim.height + pPopupData->labelDim.height  + pPopupData->btnDim.height + (2 * pPopupData->spacePad);
90
91         r = _WebPopup::Construct(true, Dimension(pPopupData->popupDim.width, popupHeight));
92         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
93         SetTitleText("Prompt Dialog");
94
95         //Text box
96         rect = GetClientAreaBounds();
97         rect.width = pPopupData->labelDim.width;
98         rect.y = 0;
99         rect.height = pPopupData->labelDim.height;
100
101         std::unique_ptr<TextBox> pTextBox(new (std::nothrow) TextBox());
102         SysTryReturnResult(NID_WEB_CTRL, pTextBox.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
103
104         r = pTextBox->Construct(rect, TEXT_BOX_BORDER_ROUNDED);
105         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
106
107         pTextBox->SetTextSize(EDIT_TEXT_SIZE);
108         pTextBox->SetText(message);
109         pTextBox->SetColor(TEXT_BOX_STATUS_NORMAL, GetColor());
110         pTextBox->SetColor(TEXT_BOX_STATUS_HIGHLIGHTED, GetColor());
111
112         r = AddControl(*pTextBox);
113         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
114
115         TextBox* pTmpTextBox = pTextBox.release();
116
117         //Edit Field
118         rect.y = 0;
119         rect.height = pPopupData->editDim.height;
120
121         std::unique_ptr<EditField> pEditField(new (std::nothrow) EditField());
122         SysTryReturnResult(NID_WEB_CTRL, pEditField.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
123
124         r = pEditField->Construct(rect, EDIT_FIELD_STYLE_NORMAL);
125         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
126
127         pEditField->SetTextSize(EDIT_TEXT_SIZE);
128         pEditField->SetText(defaultVale);
129
130         r = AddControl(*pEditField);
131         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
132
133         __pEditField = pEditField.release();
134         __pEditField->SetFocus();
135
136         //Panel
137         Panel* pButtonPanel = CreateAndAddPanel();
138         SysTryReturn(NID_WEB_CTRL, pButtonPanel, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
139
140         _SystemResource* pSysResource = _SystemResource::GetInstance();
141         SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
142
143         ArrayList idList;
144         r = idList.Construct();
145         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
146         idList.Add(*(new Integer(ID_BUTTON_PROMPT_CANCEL)));
147         idList.Add(*(new Integer(ID_BUTTON_PROMPT_OK)));
148
149         ArrayList titleList;
150         r = titleList.Construct();
151         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
152         titleList.Add(*(new String(pSysResource->GetString("sys_string", "IDS_COM_POP_CANCEL"))));
153         titleList.Add(*(new String(pSysResource->GetString("sys_string", "IDS_COM_SK_OK"))));
154
155         r = CreateAndAddButtons(idList, titleList, pButtonPanel);
156         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
157
158         std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(GetLayoutN()));
159         SysTryReturn(NID_WEB_CTRL, pLayout.get(), r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
160
161         pLayout->SetHorizontalAlignment(*pTmpTextBox, LAYOUT_HORIZONTAL_ALIGN_CENTER);
162         pLayout->SetHorizontalAlignment(*__pEditField, LAYOUT_HORIZONTAL_ALIGN_CENTER);
163         pLayout->SetHorizontalAlignment(*pButtonPanel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
164
165         pLayout->SetSpacing(*__pEditField, pPopupData->spacePad);
166         pLayout->SetSpacing(*pButtonPanel, pPopupData->spacePad);
167
168         SetPropagatedKeyEventListener(this);
169         
170         return r;
171 }
172
173
174 const String
175 _PromptPopup::GetPromptText()
176 {
177         return __pEditField->GetText();
178 }
179
180
181 void
182 _PromptPopup::OnActionPerformed(const Control& source, int actionId)
183 {
184         switch (actionId)
185         {
186         case ID_BUTTON_PROMPT_OK:
187         {
188                 HidePopup(ID_BUTTON_PROMPT_OK);
189                 std::unique_ptr<char[]> pResult(_StringConverter::CopyToCharArrayN(GetPromptText()));
190                 ewk_view_javascript_prompt_reply(__pWebView, pResult.get());
191                 break;
192         }
193         case ID_BUTTON_PROMPT_CANCEL:
194                 HidePopup(ID_BUTTON_PROMPT_CANCEL);
195                 ewk_view_javascript_prompt_reply(__pWebView, null);
196                 break;
197
198         default:
199                 SysAssertf(false, "unknown action ID used");
200                 break;
201         }
202         __pImpl->SendUserEvent(ID_PROMPT_POPUP_CLOSE, null);
203 }
204
205 bool
206 _PromptPopup::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
207 {
208         return true;
209 }
210
211 bool
212 _PromptPopup::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
213 {
214         if ((keyEventInfo.GetKeyCode() == KEY_ESC || keyEventInfo.GetKeyCode() == KEY_BACK) && source.GetShowState() == true)
215         {
216                 HidePopup(ID_BUTTON_PROMPT_CANCEL);
217                 ewk_view_javascript_prompt_reply(__pWebView, null);
218                 __pImpl->SendUserEvent(ID_PROMPT_POPUP_CLOSE, null);
219         }
220
221         return true;
222 }
223
224 bool
225 _PromptPopup::OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
226 {
227         return false;
228 }
229
230 bool
231 _PromptPopup::OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
232 {
233         return false;
234 }
235
236 bool
237 _PromptPopup::TranslateKeyEventInfo(Control& source, KeyEventInfo& keyEventInfo)
238 {
239         return false;
240 }
241
242
243 }}} // Tizen::Web::Controls