apply html5 vibration feature
[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 <FBaseColIList.h>
23 #include <FBaseSysLog.h>
24 #include <FGrpColor.h>
25 #include <FGrpDimension.h>
26 #include <FGrpRectangle.h>
27 #include <FUiCtrlButton.h>
28 #include <FUiCtrlEditField.h>
29 #include <FUiCtrlLabel.h>
30 #include <FUiCtrlPanel.h>
31 #include <FUiCtrlTextBox.h>
32 #include <FUiLayout.h>
33 #include <FUiVerticalBoxLayout.h>
34 #include <FWebCtrlAuthenticationChallenge.h>
35 #include <FSys_SystemResource.h>
36 #include <FUi_ControlManager.h>
37 #include <FUi_ResourceManager.h>
38 #include <FUiCtrl_TextBoxImpl.h>
39 #include "FWebCtrl_PromptPopup.h"
40
41
42 using namespace Tizen::Base;
43 using namespace Tizen::Base::Collection;
44 using namespace Tizen::Graphics;
45 using namespace Tizen::System;
46 using namespace Tizen::Ui;
47 using namespace Tizen::Ui::Controls;
48
49
50 static const int LABEL_HEIGHT = 10;
51
52
53 namespace Tizen { namespace Web { namespace Controls
54 {
55
56
57 _PromptPopup::_PromptPopup(void)
58         : __pEditField(null)
59 {
60 }
61
62 _PromptPopup::~_PromptPopup(void)
63 {
64 }
65
66
67 // Prompt popup
68 result
69 _PromptPopup::Construct(const String& message, const String& defaultVale)
70 {
71         result r = E_SUCCESS;
72         Rectangle rect(0, 0, 0, 0);
73
74         int popupHeight = 0;
75
76         _WebPopupData* pPopupData = _WebPopup::GetPopupData();
77         SysTryReturn(NID_WEB_CTRL, pPopupData, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
78
79         popupHeight = LABEL_HEIGHT + (2 * pPopupData->editDim.height + pPopupData->spacePad)  + pPopupData->btnDim.height + (4 * pPopupData->spacePad) ;
80
81         r = _WebPopup::Construct(true, Dimension(pPopupData->popupDim.width, popupHeight));
82         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
83         SetTitleText("Prompt Dialog");
84
85         //Text box
86         rect = GetClientAreaBounds();
87         rect.width = pPopupData->popupDim.width - 2 * pPopupData->sideMargin;
88         rect.y = 0;
89         rect.height = pPopupData->editDim.height + 10;
90
91         std::unique_ptr<TextBox> pTextBox(new (std::nothrow) TextBox());
92         SysTryReturnResult(NID_WEB_CTRL, pTextBox.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
93
94         r = pTextBox->Construct(rect, TEXT_BOX_BORDER_ROUNDED);
95         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
96
97         pTextBox->SetText(message);
98         pTextBox->SetColor(TEXT_BOX_STATUS_NORMAL, GetColor());
99         pTextBox->SetColor(TEXT_BOX_STATUS_HIGHLIGHTED, GetColor());
100
101         r = AddControl(*pTextBox);
102         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
103
104         TextBox* pTmpTextBox = pTextBox.release();
105
106
107         //Edit Field
108         rect.y = 0;
109         rect.height = pPopupData->editDim.height + 10;
110
111         std::unique_ptr<EditField> pEditField(new (std::nothrow) EditField());
112         SysTryReturnResult(NID_WEB_CTRL, pEditField.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
113
114         r = pEditField->Construct(rect, EDIT_FIELD_STYLE_NORMAL);
115         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
116
117         pEditField->SetText(defaultVale);
118
119         r = AddControl(*pEditField);
120         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
121
122         __pEditField = pEditField.release();
123         __pEditField->SetFocus();
124
125         //Panel
126         Panel* pButtonPanel = CreateAndAddPanel();
127         SysTryReturn(NID_WEB_CTRL, pButtonPanel, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
128
129         _SystemResource* pSysResource = _SystemResource::GetInstance();
130         SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
131
132         ArrayList idList;
133         r = idList.Construct();
134         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
135         idList.Add(*(new Integer(ID_BUTTON_PROMPT_OK)));
136         idList.Add(*(new Integer(ID_BUTTON_PROMPT_CANCEL)));
137
138         ArrayList titleList;
139         r = titleList.Construct();
140         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
141         titleList.Add(*(new String(pSysResource->GetString("sys_string", "IDS_COM_SK_OK"))));
142         titleList.Add(*(new String(pSysResource->GetString("sys_string", "IDS_COM_POP_CANCEL"))));
143
144         r = CreateAndAddButtons(idList, titleList, pButtonPanel);
145         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
146
147         std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(GetLayoutN()));
148         SysTryReturn(NID_WEB_CTRL, pLayout.get(), r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
149
150         pLayout->SetHorizontalAlignment(*pTmpTextBox, LAYOUT_HORIZONTAL_ALIGN_CENTER);
151         pLayout->SetHorizontalAlignment(*__pEditField, LAYOUT_HORIZONTAL_ALIGN_CENTER);
152         pLayout->SetHorizontalAlignment(*pButtonPanel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
153
154         pLayout->SetSpacing(*pTmpTextBox, pPopupData->spacePad);
155         pLayout->SetSpacing(*__pEditField, pPopupData->spacePad);
156         pLayout->SetSpacing(*pButtonPanel, pPopupData->spacePad);
157
158         return r;
159 }
160
161 const String
162 _PromptPopup::GetPromptText()
163 {
164         return __pEditField->GetText();
165 }
166
167
168 void
169 _PromptPopup::OnActionPerformed(const Control& source, int actionId)
170 {
171         switch (actionId)
172         {
173         case ID_BUTTON_PROMPT_OK:
174                 SetShowState(false);
175                 HidePopup(ID_BUTTON_PROMPT_OK);
176                 break;
177
178         case ID_BUTTON_PROMPT_CANCEL:
179                 SetShowState(false);
180                 HidePopup(ID_BUTTON_PROMPT_CANCEL);
181                 break;
182
183         default:
184                 break;
185         }
186 }
187
188
189 }}} // Tizen::Web::Controls