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_FormDataWindow.cpp
20 * @brief The file contains the definition of _FormDataWindow class.
23 #include <unique_ptr.h>
24 #include <FBaseSysLog.h>
25 #include <FSysVibrator.h>
26 #include <FUiCtrlCustomItem.h>
27 #include <FUiCtrlListView.h>
28 #include <FUiVerticalBoxLayout.h>
29 #include <FBase_StringConverter.h>
30 #include <FUi_ResourceManager.h>
31 #include "FWebCtrl_FormDataWindow.h"
32 #include "FWebCtrl_WebImpl.h"
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::Base::Utility;
38 using namespace Tizen::Graphics;
39 using namespace Tizen::System;
40 using namespace Tizen::Ui;
41 using namespace Tizen::Ui::Controls;
44 namespace Tizen { namespace Web { namespace Controls
48 _FormDataWindow::_FormDataWindow(void)
57 _FormDataWindow::~_FormDataWindow(void)
59 __listElementArray.RemoveAll(true);
64 _FormDataWindow::Construct(const Rectangle& rect, _WebImpl* pImpl, Evas_Object* pWebView)
66 VerticalBoxLayout layout;
68 result r = layout.Construct(VERTICAL_DIRECTION_DOWNWARD);
69 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
71 GET_COLOR_CONFIG(LIST::ELEMENT_TEXT_NORMAL, __normalColor);
72 GET_COLOR_CONFIG(LIST::ELEMENT_TEXT_PRESSED, __pressedColor);
73 GET_COLOR_CONFIG(LIST::ELEMENT_TEXT_HIGHLIGHTED, __highlightedColor);
75 __listItemHeight = rect.height;
76 Rectangle windowRect(rect);
78 r = Window::Construct(layout, windowRect, true, true);
79 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Error Propogating.", GetErrorMessage(r));
82 Window::SetOwner(&pImpl->GetPublic());
84 std::unique_ptr<ListView> pListView(new (std::nothrow) ListView());
85 SysTryReturnResult(NID_WEB_CTRL, pListView.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
87 r = pListView->Construct(Rectangle(0, 0, windowRect.width, windowRect.height), true, SCROLL_STYLE_FADE_OUT);
88 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
90 r = __listElementArray.Construct();
91 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
93 pListView->SetItemProvider(*this);
94 pListView->AddListViewItemEventListener(*this);
95 pListView->SetTextOfEmptyList(L"");
97 r = AddControl(*pListView);
98 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
100 __pListView = pListView.release();
102 std::unique_ptr< VerticalBoxLayout > pLayout(dynamic_cast< VerticalBoxLayout* >(GetLayoutN()));
103 SysTryReturn(NID_WEB_CTRL, pLayout.get(), r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
105 pLayout->SetHorizontalAlignment(*__pListView, LAYOUT_HORIZONTAL_ALIGN_CENTER);
106 pLayout->SetHorizontalFitPolicy(*__pListView, FIT_POLICY_PARENT);
109 __pWebView = pWebView;
115 //IListViewItemProvider
117 _FormDataWindow::CreateItem(int index, int itemWidth)
119 String* pListElement = static_cast< String* >(__listElementArray.GetAt(index));
120 SysTryReturn(NID_WEB_CTRL, pListElement, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
122 std::unique_ptr<CustomItem> pItem(new (std::nothrow) CustomItem());
123 SysTryReturn(NID_WEB_CTRL, pItem.get(), null, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.",GetErrorMessage(E_OUT_OF_MEMORY));
125 result r = pItem->Construct(Dimension(itemWidth, __listItemHeight), LIST_ANNEX_STYLE_NORMAL);
126 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
128 int listItemHeight = 0;
129 int listItemTextSize = 0;
130 int listItemLeftMargin = 0;
132 GET_SHAPE_CONFIG(LIST::LIST_DEFAULT_ITEM_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, listItemHeight);
133 GET_SHAPE_CONFIG(LIST::LIST_ITEM_TEXT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, listItemTextSize);
134 GET_SHAPE_CONFIG(LIST::LIST_ITEM_LEFT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, listItemLeftMargin);
136 if (__listItemHeight > listItemHeight)
138 __listItemHeight = listItemHeight;
141 if (__listItemHeight*2/3 < listItemTextSize)
143 listItemTextSize = __listItemHeight*2/3;
146 Rectangle itemRect = Rectangle(listItemLeftMargin, 0, itemWidth, __listItemHeight);
147 r = pItem->AddElement(itemRect, ID_FORMAT_STRING, *pListElement, listItemTextSize, __normalColor, __pressedColor, __highlightedColor);
148 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
150 return pItem.release();
155 _FormDataWindow::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
164 _FormDataWindow::GetItemCount(void)
166 return __listElementArray.GetCount();
170 // IListViewItemEventListener
172 _FormDataWindow::OnListViewContextItemStateChanged(ListView& listView, int index, int elementId, ListContextItemStatus state)
178 _FormDataWindow::OnListViewItemStateChanged(ListView& listView, int index, int elementId, ListItemStatus status)
180 std::unique_ptr< char[] > pInputValue;
182 String* pListElement = static_cast< String* >(__listElementArray.GetAt(index));
183 SysTryCatch(NID_WEB_CTRL, pListElement, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
185 pInputValue = std::unique_ptr< char[] >(_StringConverter::CopyToCharArrayN(*pListElement));
186 SysTryCatch(NID_WEB_CTRL, pInputValue.get(), , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
188 ewk_view_focused_input_element_value_set(__pWebView, pInputValue.get());
192 __pWebImpl->HideFormDataWindow(false);
197 _FormDataWindow::OnListViewItemSwept(ListView& listView, int index, SweepDirection direction)
203 _FormDataWindow::UpdateList(Eina_List* pDataList, const Rectangle& rect)
205 SysTryReturnResult(NID_WEB_CTRL, pDataList, E_INVALID_ARG, "Invalid argument(s) is used. data list pointer should not be null.");
207 __listElementArray.RemoveAll(true);
209 __listItemHeight = rect.height;
211 int itemCount = eina_list_count(pDataList);
213 for (int itemIndex = 0; itemIndex < itemCount; itemIndex++)
215 char* pItemText = static_cast<char*>(eina_list_nth(pDataList, itemIndex));
217 std::unique_ptr<String> pListElement(new (std::nothrow) String(pItemText));
218 SysTryReturnResult(NID_WEB_CTRL, pListElement.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
220 result r = __listElementArray.Add(*pListElement);
221 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
223 pListElement.release();
226 __pListView->UpdateList();
228 int windowHeight = itemCount*__listItemHeight;
230 Rectangle webRect = __pWebImpl->GetBounds();//is it better to take application rect
231 int bottomLimit = webRect.y + webRect.height;
232 int topLimit = webRect.y;
233 Rectangle windowRect(rect);
235 if (__pWebImpl->IsKeypadVisible())
237 Rectangle keyRect = __pWebImpl->GetPreviousKeypadBounds();
238 bottomLimit = keyRect.y;
241 int windowBottom = rect.y + windowHeight;
245 if (windowBottom > bottomLimit)
247 int newWindowTop = rect.y - rect.height - windowHeight;
248 if (newWindowTop < topLimit)//check in reverse direction
252 windowHeight = itemCount*__listItemHeight;
253 windowBottom = rect.y + windowHeight;
261 {//reverse direction is good
262 windowRect.y = rect.y - rect.height - windowHeight;
273 windowRect.height = windowHeight;
274 __pListView->SetBounds(Rectangle(0, 0, windowRect.width, windowRect.height));
275 SetBounds(windowRect);
282 _FormDataWindow::LaunchFormDataWindow(void)
284 result r = SetFocusable(false);
285 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
287 r = SetShowState(true);
288 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
291 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
297 }}} // Tizen::Web::Controls