ui corrections to popups and notification window
[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 <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"
43
44
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;
51
52
53 namespace Tizen { namespace Web { namespace Controls
54 {
55
56
57 static const int EDIT_TEXT_SIZE = 35;
58
59
60 _PromptPopup::_PromptPopup(void)
61         : __pEditField(null)
62         , __pWebView(null)
63 {
64 }
65
66
67 _PromptPopup::~_PromptPopup(void)
68 {
69 }
70
71
72 // Prompt popup
73 result
74 _PromptPopup::Construct(const String& message, const String& defaultVale,  Evas_Object* pView)
75 {
76         result r = E_SUCCESS;
77         Rectangle rect(0, 0, 0, 0);
78
79         int popupHeight = 0;
80
81         __pWebView = pView;
82
83         _WebPopupData* pPopupData = _WebPopup::GetPopupData();
84         SysTryReturn(NID_WEB_CTRL, pPopupData, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
85
86         popupHeight = pPopupData->editDim.height + pPopupData->labelDim.height  + pPopupData->btnDim.height + (2 * pPopupData->spacePad);
87
88         r = _WebPopup::Construct(true, Dimension(pPopupData->popupDim.width, popupHeight));
89         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
90         SetTitleText("Prompt Dialog");
91
92         //Text box
93         rect = GetClientAreaBounds();
94         rect.width = pPopupData->labelDim.width;
95         rect.y = 0;
96         rect.height = pPopupData->labelDim.height;
97
98         std::unique_ptr<TextBox> pTextBox(new (std::nothrow) TextBox());
99         SysTryReturnResult(NID_WEB_CTRL, pTextBox.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
100
101         r = pTextBox->Construct(rect, TEXT_BOX_BORDER_ROUNDED);
102         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
103
104         pTextBox->SetTextSize(EDIT_TEXT_SIZE);
105         pTextBox->SetText(message);
106         pTextBox->SetColor(TEXT_BOX_STATUS_NORMAL, GetColor());
107         pTextBox->SetColor(TEXT_BOX_STATUS_HIGHLIGHTED, GetColor());
108
109         r = AddControl(*pTextBox);
110         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
111
112         TextBox* pTmpTextBox = pTextBox.release();
113
114         //Edit Field
115         rect.y = 0;
116         rect.height = pPopupData->editDim.height;
117
118         std::unique_ptr<EditField> pEditField(new (std::nothrow) EditField());
119         SysTryReturnResult(NID_WEB_CTRL, pEditField.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
120
121         r = pEditField->Construct(rect, EDIT_FIELD_STYLE_NORMAL);
122         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
123
124         pEditField->SetTextSize(EDIT_TEXT_SIZE);
125         pEditField->SetText(defaultVale);
126
127         r = AddControl(*pEditField);
128         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
129
130         __pEditField = pEditField.release();
131         __pEditField->SetFocus();
132
133         //Panel
134         Panel* pButtonPanel = CreateAndAddPanel();
135         SysTryReturn(NID_WEB_CTRL, pButtonPanel, r = GetLastResult(), r, "[%s] Propagating.", GetErrorMessage(r));
136
137         _SystemResource* pSysResource = _SystemResource::GetInstance();
138         SysAssertf(pSysResource != null, "Failed to get _SystemResource instance");
139
140         ArrayList idList;
141         r = idList.Construct();
142         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
143         idList.Add(*(new Integer(ID_BUTTON_PROMPT_OK)));
144         idList.Add(*(new Integer(ID_BUTTON_PROMPT_CANCEL)));
145
146         ArrayList titleList;
147         r = titleList.Construct();
148         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
149         titleList.Add(*(new String(pSysResource->GetString("sys_string", "IDS_COM_SK_OK"))));
150         titleList.Add(*(new String(pSysResource->GetString("sys_string", "IDS_COM_POP_CANCEL"))));
151
152         r = CreateAndAddButtons(idList, titleList, pButtonPanel);
153         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
154
155         std::unique_ptr<VerticalBoxLayout> pLayout(dynamic_cast< VerticalBoxLayout* >(GetLayoutN()));
156         SysTryReturn(NID_WEB_CTRL, pLayout.get(), r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
157
158         pLayout->SetHorizontalAlignment(*pTmpTextBox, LAYOUT_HORIZONTAL_ALIGN_CENTER);
159         pLayout->SetHorizontalAlignment(*__pEditField, LAYOUT_HORIZONTAL_ALIGN_CENTER);
160         pLayout->SetHorizontalAlignment(*pButtonPanel, LAYOUT_HORIZONTAL_ALIGN_CENTER);
161
162         pLayout->SetSpacing(*__pEditField, pPopupData->spacePad);
163         pLayout->SetSpacing(*pButtonPanel, pPopupData->spacePad);
164
165         return r;
166 }
167
168
169 const String
170 _PromptPopup::GetPromptText()
171 {
172         return __pEditField->GetText();
173 }
174
175
176 void
177 _PromptPopup::OnActionPerformed(const Control& source, int actionId)
178 {
179         switch (actionId)
180         {
181         case ID_BUTTON_PROMPT_OK:
182         {
183                 HidePopup(ID_BUTTON_PROMPT_OK);
184                 std::unique_ptr<char[]> pResult(_StringConverter::CopyToCharArrayN(GetPromptText()));
185                 ewk_view_javascript_prompt_reply(__pWebView, pResult.get());
186                 break;
187         }
188         case ID_BUTTON_PROMPT_CANCEL:
189                 HidePopup(ID_BUTTON_PROMPT_CANCEL);
190                 ewk_view_javascript_prompt_reply(__pWebView, null);
191                 break;
192
193         default:
194                 SysAssertf(false, "unknown action ID used");
195                 break;
196         }
197         GetOwner()->SendUserEvent(ID_PROMPT_POPUP_CLOSE, null);
198 }
199
200
201 }}} // Tizen::Web::Controls