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.
24 #include <unique_ptr.h>
25 #include <FBaseSysLog.h>
26 #include <FSysVibrator.h>
27 #include <FUiCtrlCustomItem.h>
28 #include <FUiCtrlListView.h>
29 #include <FUiVerticalBoxLayout.h>
30 #include <FBase_StringConverter.h>
31 #include <FUi_ResourceManager.h>
32 #include "FWebCtrl_WebImpl.h"
33 #include "FWebCtrl_FormDataWindow.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;
43 namespace Tizen { namespace Web { namespace Controls
46 static const int MAX_LIST_ITEM_COUNT = 3;
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_SHAPE_CONFIG(CONTEXTMENU::LIST_ITEM_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, __listItemHeight);
72 Rectangle windowRect(rect);
73 windowRect.height = MAX_LIST_ITEM_COUNT*__listItemHeight;
75 r = Window::Construct(layout, windowRect, true, true);
76 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Error Propogating.", GetErrorMessage(r));
79 Window::SetOwner(&pImpl->GetPublic());
81 std::unique_ptr<ListView> pListView(new (std::nothrow) ListView());
82 SysTryReturnResult(NID_WEB_CTRL, pListView.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
84 r = pListView->Construct(Rectangle(0, 0, windowRect.width, windowRect.height), true, SCROLL_STYLE_FADE_OUT);
85 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
87 r = __listElementArray.Construct();
88 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
90 pListView->SetItemProvider(*this);
91 pListView->AddListViewItemEventListener(*this);
92 pListView->SetTextOfEmptyList(L"");
94 r = AddControl(*pListView);
95 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
97 __pListView = pListView.release();
99 std::unique_ptr< VerticalBoxLayout > pLayout(dynamic_cast< VerticalBoxLayout* >(GetLayoutN()));
100 SysTryReturn(NID_WEB_CTRL, pLayout.get(), r = GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
102 pLayout->SetHorizontalAlignment(*__pListView, LAYOUT_HORIZONTAL_ALIGN_CENTER);
103 pLayout->SetHorizontalFitPolicy(*__pListView, FIT_POLICY_PARENT);
106 __pWebView = pWebView;
112 //IListViewItemProvider
114 _FormDataWindow::CreateItem(int index, int itemWidth)
116 String* pListElement = static_cast< String* >(__listElementArray.GetAt(index));
117 SysTryReturn(NID_WEB_CTRL, pListElement, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
119 std::unique_ptr<CustomItem> pItem(new (std::nothrow) CustomItem());
120 SysTryReturn(NID_WEB_CTRL, pItem.get(), null, E_OUT_OF_MEMORY, "[%s] Memory Allocation failed.",GetErrorMessage(E_OUT_OF_MEMORY));
122 result r = pItem->Construct(Dimension(itemWidth, __listItemHeight), LIST_ANNEX_STYLE_NORMAL);
123 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
125 r = pItem->AddElement(Rectangle(0, 0, itemWidth, __listItemHeight), ID_FORMAT_STRING, *pListElement, true);
126 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
128 return pItem.release();
133 _FormDataWindow::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
142 _FormDataWindow::GetItemCount(void)
144 return __listElementArray.GetCount();
148 // IListViewItemEventListener
150 _FormDataWindow::OnListViewContextItemStateChanged(ListView& listView, int index, int elementId, ListContextItemStatus state)
156 _FormDataWindow::OnListViewItemStateChanged(ListView& listView, int index, int elementId, ListItemStatus status)
158 std::unique_ptr< char[] > pInputValue;
160 String* pListElement = static_cast< String* >(__listElementArray.GetAt(index));
161 SysTryCatch(NID_WEB_CTRL, pListElement, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
163 pInputValue = std::unique_ptr< char[] >(_StringConverter::CopyToCharArrayN(*pListElement));
164 SysTryCatch(NID_WEB_CTRL, pInputValue.get(), , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
166 ewk_view_focused_input_element_value_set(__pWebView, pInputValue.get());
170 __pWebImpl->HideFormDataWindow(false);
175 _FormDataWindow::OnListViewItemSwept(ListView& listView, int index, SweepDirection direction)
181 _FormDataWindow::UpdateList(Eina_List* pDataList, const Rectangle& rect)
183 SysTryReturnResult(NID_WEB_CTRL, pDataList, E_INVALID_ARG, "Invalid argument(s) is used. data list pointer should not be null.");
185 __listElementArray.RemoveAll(true);
187 int itemCount = eina_list_count(pDataList);
189 for (int itemIndex = 0; itemIndex < itemCount; itemIndex++)
191 char* pItemText = static_cast<char*>(eina_list_nth(pDataList, itemIndex));
193 std::unique_ptr<String> pListElement(new (std::nothrow) String(pItemText));
194 SysTryReturnResult(NID_WEB_CTRL, pListElement.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
196 result r = __listElementArray.Add(*pListElement);
197 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
199 pListElement.release();
202 __pListView->UpdateList();
205 rec.height = (itemCount >= MAX_LIST_ITEM_COUNT) ? (MAX_LIST_ITEM_COUNT*__listItemHeight) : (itemCount*__listItemHeight);
213 _FormDataWindow::LaunchFormDataWindow(void)
215 result r = SetFocusable(false);
216 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
218 r = SetShowState(true);
219 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
222 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
228 }}} // Tizen::Web::Controls