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 <FUiLayout.h>
34 #include <FUiVerticalBoxLayout.h>
35 #include <FWebCtrlAuthenticationChallenge.h>
36 #include <FBase_StringConverter.h>
37 #include <FSys_SystemResource.h>
38 #include <FUi_ControlManager.h>
39 #include <FUi_ResourceManager.h>
40 #include <FUiCtrl_TextBoxImpl.h>
41 #include "FWebCtrl_PromptPopup.h"
42 #include "FWebCtrl_WebImpl.h"
45 using namespace Tizen::Base;
46 using namespace Tizen::Base::Collection;
47 using namespace Tizen::Graphics;
48 using namespace Tizen::System;
49 using namespace Tizen::Ui;
50 using namespace Tizen::Ui::Controls;
53 static const int LABEL_HEIGHT = 10;
56 namespace Tizen { namespace Web { namespace Controls
60 _PromptPopup::_PromptPopup(void)
66 _PromptPopup::~_PromptPopup(void)
73 _PromptPopup::Construct(const String& message, const String& defaultVale, Evas_Object* pView)
76 Rectangle rect(0, 0, 0, 0);
82 _WebPopupData* pPopupData = _WebPopup::GetPopupData();
83 SysTryReturn(NID_WEB_CTRL, pPopupData, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
85 popupHeight = LABEL_HEIGHT + (2 * pPopupData->editDim.height + pPopupData->spacePad) + pPopupData->btnDim.height + (4 * pPopupData->spacePad) ;
87 r = _WebPopup::Construct(true, Dimension(pPopupData->popupDim.width, popupHeight));
88 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
89 SetTitleText("Prompt Dialog");
92 rect = GetClientAreaBounds();
93 rect.width = pPopupData->popupDim.width - 2 * pPopupData->sideMargin;
95 rect.height = pPopupData->editDim.height + 10;
97 std::unique_ptr<TextBox> pTextBox(new (std::nothrow) TextBox());
98 SysTryReturnResult(NID_WEB_CTRL, pTextBox.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
100 r = pTextBox->Construct(rect, TEXT_BOX_BORDER_ROUNDED);
101 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
103 pTextBox->SetText(message);
104 pTextBox->SetColor(TEXT_BOX_STATUS_NORMAL, GetColor());
105 pTextBox->SetColor(TEXT_BOX_STATUS_HIGHLIGHTED, GetColor());
107 r = AddControl(*pTextBox);
108 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
110 TextBox* pTmpTextBox = pTextBox.release();
115 rect.height = pPopupData->editDim.height + 10;
117 std::unique_ptr<EditField> pEditField(new (std::nothrow) EditField());
118 SysTryReturnResult(NID_WEB_CTRL, pEditField.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
120 r = pEditField->Construct(rect, EDIT_FIELD_STYLE_NORMAL);
121 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
123 pEditField->SetText(defaultVale);
125 r = AddControl(*pEditField);
126 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
128 __pEditField = pEditField.release();
129 __pEditField->SetFocus();
132 Panel* pButtonPanel = CreateAndAddPanel();
133 SysTryReturn(NID_WEB_CTRL, pButtonPanel, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
135 _SystemResource* pSysResource = _SystemResource::GetInstance();
136 SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
139 r = idList.Construct();
140 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
141 idList.Add(*(new Integer(ID_BUTTON_PROMPT_OK)));
142 idList.Add(*(new Integer(ID_BUTTON_PROMPT_CANCEL)));
145 r = titleList.Construct();
146 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
147 titleList.Add(*(new String(pSysResource->GetString("sys_string", "IDS_COM_SK_OK"))));
148 titleList.Add(*(new String(pSysResource->GetString("sys_string", "IDS_COM_POP_CANCEL"))));
150 r = CreateAndAddButtons(idList, titleList, pButtonPanel);
151 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
153 std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(GetLayoutN()));
154 SysTryReturn(NID_WEB_CTRL, pLayout.get(), r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
156 pLayout->SetHorizontalAlignment(*pTmpTextBox, LAYOUT_HORIZONTAL_ALIGN_CENTER);
157 pLayout->SetHorizontalAlignment(*__pEditField, LAYOUT_HORIZONTAL_ALIGN_CENTER);
158 pLayout->SetHorizontalAlignment(*pButtonPanel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
160 pLayout->SetSpacing(*pTmpTextBox, pPopupData->spacePad);
161 pLayout->SetSpacing(*__pEditField, pPopupData->spacePad);
162 pLayout->SetSpacing(*pButtonPanel, pPopupData->spacePad);
168 _PromptPopup::GetPromptText()
170 return __pEditField->GetText();
175 _PromptPopup::OnActionPerformed(const Control& source, int actionId)
179 case ID_BUTTON_PROMPT_OK:
181 HidePopup(ID_BUTTON_PROMPT_OK);
182 std::unique_ptr<char[]> pResult(_StringConverter::CopyToCharArrayN(GetPromptText()));
183 ewk_view_javascript_prompt_reply(__pWebView, pResult.get());
186 case ID_BUTTON_PROMPT_CANCEL:
187 HidePopup(ID_BUTTON_PROMPT_CANCEL);
188 ewk_view_javascript_prompt_reply(__pWebView, null);
192 SysAssertf(false, "unknown action ID used");
195 GetOwner()->SendUserEvent(ID_PROMPT_POPUP_CLOSE, null);
199 }}} // Tizen::Web::Controls