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)
68 _PromptPopup::~_PromptPopup(void)
75 _PromptPopup::Construct(const String& message, const String& defaultVale, Evas_Object* pView)
78 Rectangle rect(0, 0, 0, 0);
84 _WebPopupData* pPopupData = _WebPopup::GetPopupData();
85 SysTryReturn(NID_WEB_CTRL, pPopupData, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
87 popupHeight = pPopupData->editDim.height + pPopupData->labelDim.height + pPopupData->btnDim.height + (2 * pPopupData->spacePad);
89 r = _WebPopup::Construct(true, Dimension(pPopupData->popupDim.width, popupHeight));
90 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
91 SetTitleText("Prompt Dialog");
94 rect = GetClientAreaBounds();
95 rect.width = pPopupData->labelDim.width;
97 rect.height = pPopupData->labelDim.height;
99 std::unique_ptr<TextBox> pTextBox(new (std::nothrow) TextBox());
100 SysTryReturnResult(NID_WEB_CTRL, pTextBox.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
102 r = pTextBox->Construct(rect, TEXT_BOX_BORDER_ROUNDED);
103 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
105 pTextBox->SetTextSize(EDIT_TEXT_SIZE);
106 pTextBox->SetText(message);
107 pTextBox->SetColor(TEXT_BOX_STATUS_NORMAL, GetColor());
108 pTextBox->SetColor(TEXT_BOX_STATUS_HIGHLIGHTED, GetColor());
110 r = AddControl(*pTextBox);
111 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
113 TextBox* pTmpTextBox = pTextBox.release();
117 rect.height = pPopupData->editDim.height;
119 std::unique_ptr<EditField> pEditField(new (std::nothrow) EditField());
120 SysTryReturnResult(NID_WEB_CTRL, pEditField.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
122 r = pEditField->Construct(rect, EDIT_FIELD_STYLE_NORMAL);
123 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
125 pEditField->SetTextSize(EDIT_TEXT_SIZE);
126 pEditField->SetText(defaultVale);
128 r = AddControl(*pEditField);
129 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
131 __pEditField = pEditField.release();
132 __pEditField->SetFocus();
135 Panel* pButtonPanel = CreateAndAddPanel();
136 SysTryReturn(NID_WEB_CTRL, pButtonPanel, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
138 _SystemResource* pSysResource = _SystemResource::GetInstance();
139 SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
142 r = idList.Construct();
143 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
144 idList.Add(*(new Integer(ID_BUTTON_PROMPT_CANCEL)));
145 idList.Add(*(new Integer(ID_BUTTON_PROMPT_OK)));
148 r = titleList.Construct();
149 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
150 titleList.Add(*(new String(pSysResource->GetString("sys_string", "IDS_COM_POP_CANCEL"))));
151 titleList.Add(*(new String(pSysResource->GetString("sys_string", "IDS_COM_SK_OK"))));
153 r = CreateAndAddButtons(idList, titleList, pButtonPanel);
154 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
156 std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(GetLayoutN()));
157 SysTryReturn(NID_WEB_CTRL, pLayout.get(), r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
159 pLayout->SetHorizontalAlignment(*pTmpTextBox, LAYOUT_HORIZONTAL_ALIGN_CENTER);
160 pLayout->SetHorizontalAlignment(*__pEditField, LAYOUT_HORIZONTAL_ALIGN_CENTER);
161 pLayout->SetHorizontalAlignment(*pButtonPanel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
163 pLayout->SetSpacing(*__pEditField, pPopupData->spacePad);
164 pLayout->SetSpacing(*pButtonPanel, pPopupData->spacePad);
166 SetPropagatedKeyEventListener(this);
173 _PromptPopup::GetPromptText()
175 return __pEditField->GetText();
180 _PromptPopup::OnActionPerformed(const Control& source, int actionId)
184 case ID_BUTTON_PROMPT_OK:
186 HidePopup(ID_BUTTON_PROMPT_OK);
187 std::unique_ptr<char[]> pResult(_StringConverter::CopyToCharArrayN(GetPromptText()));
188 ewk_view_javascript_prompt_reply(__pWebView, pResult.get());
191 case ID_BUTTON_PROMPT_CANCEL:
192 HidePopup(ID_BUTTON_PROMPT_CANCEL);
193 ewk_view_javascript_prompt_reply(__pWebView, null);
197 SysAssertf(false, "unknown action ID used");
200 GetOwner()->SendUserEvent(ID_PROMPT_POPUP_CLOSE, null);
204 _PromptPopup::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
210 _PromptPopup::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
212 if ((keyEventInfo.GetKeyCode() == KEY_ESC || keyEventInfo.GetKeyCode() == KEY_BACK) && source.GetShowState() == true)
214 HidePopup(ID_BUTTON_PROMPT_CANCEL);
215 ewk_view_javascript_prompt_reply(__pWebView, null);
216 GetOwner()->SendUserEvent(ID_PROMPT_POPUP_CLOSE, null);
223 _PromptPopup::OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
229 _PromptPopup::OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
235 _PromptPopup::TranslateKeyEventInfo(Control& source, KeyEventInfo& keyEventInfo)
241 }}} // Tizen::Web::Controls