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 static const int MAX_LIST_ITEM_COUNT = 3;
51 _FormDataWindow::_FormDataWindow(void)
60 _FormDataWindow::~_FormDataWindow(void)
62 __listElementArray.RemoveAll(true);
67 _FormDataWindow::Construct(const Rectangle& rect, _WebImpl* pImpl, Evas_Object* pWebView)
69 VerticalBoxLayout layout;
71 result r = layout.Construct(VERTICAL_DIRECTION_DOWNWARD);
72 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
74 GET_SHAPE_CONFIG(CONTEXTMENU::LIST_ITEM_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, __listItemHeight);
75 Rectangle windowRect(rect);
76 windowRect.height = MAX_LIST_ITEM_COUNT*__listItemHeight;
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 r = pItem->AddElement(Rectangle(0, 0, itemWidth, __listItemHeight), ID_FORMAT_STRING, *pListElement, true);
129 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
131 return pItem.release();
136 _FormDataWindow::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
145 _FormDataWindow::GetItemCount(void)
147 return __listElementArray.GetCount();
151 // IListViewItemEventListener
153 _FormDataWindow::OnListViewContextItemStateChanged(ListView& listView, int index, int elementId, ListContextItemStatus state)
159 _FormDataWindow::OnListViewItemStateChanged(ListView& listView, int index, int elementId, ListItemStatus status)
161 std::unique_ptr< char[] > pInputValue;
163 String* pListElement = static_cast< String* >(__listElementArray.GetAt(index));
164 SysTryCatch(NID_WEB_CTRL, pListElement, , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
166 pInputValue = std::unique_ptr< char[] >(_StringConverter::CopyToCharArrayN(*pListElement));
167 SysTryCatch(NID_WEB_CTRL, pInputValue.get(), , GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
169 ewk_view_focused_input_element_value_set(__pWebView, pInputValue.get());
173 __pWebImpl->HideFormDataWindow(false);
178 _FormDataWindow::OnListViewItemSwept(ListView& listView, int index, SweepDirection direction)
184 _FormDataWindow::UpdateList(Eina_List* pDataList, const Rectangle& rect)
186 SysTryReturnResult(NID_WEB_CTRL, pDataList, E_INVALID_ARG, "Invalid argument(s) is used. data list pointer should not be null.");
188 __listElementArray.RemoveAll(true);
190 int itemCount = eina_list_count(pDataList);
192 for (int itemIndex = 0; itemIndex < itemCount; itemIndex++)
194 char* pItemText = static_cast<char*>(eina_list_nth(pDataList, itemIndex));
196 std::unique_ptr<String> pListElement(new (std::nothrow) String(pItemText));
197 SysTryReturnResult(NID_WEB_CTRL, pListElement.get(), E_OUT_OF_MEMORY, "Memory Allocation failed.");
199 result r = __listElementArray.Add(*pListElement);
200 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
202 pListElement.release();
205 __pListView->UpdateList();
208 rec.height = (itemCount >= MAX_LIST_ITEM_COUNT) ? (MAX_LIST_ITEM_COUNT*__listItemHeight) : (itemCount*__listItemHeight);
216 _FormDataWindow::LaunchFormDataWindow(void)
218 result r = SetFocusable(false);
219 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
221 r = SetShowState(true);
222 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
225 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
231 }}} // Tizen::Web::Controls