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.
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"
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;
54 namespace Tizen { namespace Web { namespace Controls
58 static const int EDIT_TEXT_SIZE = 35;
61 _PromptPopup::_PromptPopup(void)
69 _PromptPopup::~_PromptPopup(void)
76 _PromptPopup::Construct(const String& message, const String& defaultVale, Evas_Object* pView, _WebImpl* pImpl)
79 Rectangle rect(0, 0, 0, 0);
86 _WebPopupData* pPopupData = _WebPopup::GetPopupData();
87 SysTryReturn(NID_WEB_CTRL, pPopupData, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
89 popupHeight = pPopupData->editDim.height + pPopupData->labelDim.height + pPopupData->btnDim.height + (2 * pPopupData->spacePad);
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");
96 rect = GetClientAreaBounds();
97 rect.width = pPopupData->labelDim.width;
99 rect.height = pPopupData->labelDim.height;
101 std::unique_ptr<TextBox> pTextBox(new (std::nothrow) TextBox());
102 SysTryReturnResult(NID_WEB_CTRL, pTextBox.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
104 r = pTextBox->Construct(rect, TEXT_BOX_BORDER_ROUNDED);
105 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
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());
112 r = AddControl(*pTextBox);
113 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
115 TextBox* pTmpTextBox = pTextBox.release();
119 rect.height = pPopupData->editDim.height;
121 std::unique_ptr<EditField> pEditField(new (std::nothrow) EditField());
122 SysTryReturnResult(NID_WEB_CTRL, pEditField.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
124 r = pEditField->Construct(rect, EDIT_FIELD_STYLE_NORMAL);
125 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
127 pEditField->SetTextSize(EDIT_TEXT_SIZE);
128 pEditField->SetText(defaultVale);
130 r = AddControl(*pEditField);
131 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
133 __pEditField = pEditField.release();
134 __pEditField->SetFocus();
137 Panel* pButtonPanel = CreateAndAddPanel();
138 SysTryReturn(NID_WEB_CTRL, pButtonPanel, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
140 _SystemResource* pSysResource = _SystemResource::GetInstance();
141 SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
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)));
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"))));
155 r = CreateAndAddButtons(idList, titleList, pButtonPanel);
156 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
158 std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(GetLayoutN()));
159 SysTryReturn(NID_WEB_CTRL, pLayout.get(), r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
161 pLayout->SetHorizontalAlignment(*pTmpTextBox, LAYOUT_HORIZONTAL_ALIGN_CENTER);
162 pLayout->SetHorizontalAlignment(*__pEditField, LAYOUT_HORIZONTAL_ALIGN_CENTER);
163 pLayout->SetHorizontalAlignment(*pButtonPanel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
165 pLayout->SetSpacing(*__pEditField, pPopupData->spacePad);
166 pLayout->SetSpacing(*pButtonPanel, pPopupData->spacePad);
168 SetPropagatedKeyEventListener(this);
175 _PromptPopup::GetPromptText()
177 return __pEditField->GetText();
182 _PromptPopup::OnActionPerformed(const Control& source, int actionId)
186 case ID_BUTTON_PROMPT_OK:
188 HidePopup(ID_BUTTON_PROMPT_OK);
189 std::unique_ptr<char[]> pResult(_StringConverter::CopyToCharArrayN(GetPromptText()));
190 ewk_view_javascript_prompt_reply(__pWebView, pResult.get());
193 case ID_BUTTON_PROMPT_CANCEL:
194 HidePopup(ID_BUTTON_PROMPT_CANCEL);
195 ewk_view_javascript_prompt_reply(__pWebView, null);
199 SysAssertf(false, "unknown action ID used");
202 __pImpl->SendUserEvent(ID_PROMPT_POPUP_CLOSE, null);
206 _PromptPopup::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
212 _PromptPopup::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
214 if ((keyEventInfo.GetKeyCode() == KEY_ESC || keyEventInfo.GetKeyCode() == KEY_BACK) && source.GetShowState() == true)
216 HidePopup(ID_BUTTON_PROMPT_CANCEL);
217 ewk_view_javascript_prompt_reply(__pWebView, null);
218 __pImpl->SendUserEvent(ID_PROMPT_POPUP_CLOSE, null);
225 _PromptPopup::OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
231 _PromptPopup::OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
237 _PromptPopup::TranslateKeyEventInfo(Control& source, KeyEventInfo& keyEventInfo)
243 }}} // Tizen::Web::Controls