namespace WebKit {
InputPicker::InputPicker(Evas_Object* ewkView)
-: m_ewkView(ewkView)
-, m_pickerLayout(0)
+ : m_ewkView(ewkView)
+ , m_pickerLayout(0)
+ , m_dataList(0)
{
}
}
#if ENABLE(TIZEN_DATALIST_ELEMENT)
+void InputPicker::_data_list_popup_response_cb(void* data, Evas_Object* obj, void* eventInfo)
+{
+ InputPicker* inputPicker = static_cast<InputPicker*>(data);
+ const char* selectedItem = elm_entry_entry_get(inputPicker->m_pickerLayout->dataListEditField);
+ ewk_view_data_list_close(inputPicker->m_ewkView, selectedItem);
+
+ if (inputPicker->m_pickerLayout->popup) {
+ evas_object_del(inputPicker->m_pickerLayout->popup);
+ inputPicker->m_pickerLayout->popup = 0;
+ }
+
+ delete inputPicker->m_pickerLayout;
+ inputPicker->m_pickerLayout = 0;
+
+ inputPicker->m_dataList = 0;
+}
+
+void InputPicker::_data_list_popup_response_cancel_cb(void* data, Evas_Object* obj, void* eventInfo)
+{
+ InputPicker* inputPicker = static_cast<InputPicker*>(data);
+
+ if (inputPicker->m_pickerLayout->popup) {
+ evas_object_del(inputPicker->m_pickerLayout->popup);
+ inputPicker->m_pickerLayout->popup = 0;
+ }
+
+ delete inputPicker->m_pickerLayout;
+ inputPicker->m_pickerLayout = 0;
+
+ inputPicker->m_dataList = 0;
+}
+
+void InputPicker::_data_list_selected_cb(void* data, Evas_Object* obj, void* eventInfo)
+{
+ InputPicker* inputPicker = static_cast<InputPicker*>(data);
+ Elm_Object_Item* selectedItem = static_cast<Elm_Object_Item*>(eventInfo);
+ Elm_Object_Item* item = elm_list_first_item_get(obj);
+
+ int index = 0;
+ while (item) {
+ if (item == selectedItem)
+ break;
+ index++;
+ item = elm_list_item_next(item);
+ }
+
+ Eina_List* list = 0;
+ void* listItem = 0;
+ int listIndex = 0;
+ EINA_LIST_FOREACH(inputPicker->m_dataList, list, listItem) {
+ if (listItem && index == listIndex)
+ elm_entry_entry_set(inputPicker->m_pickerLayout->dataListEditField, static_cast<char*>(listItem));
+
+ listIndex++;
+ }
+}
+
+static void _eraser_clicked_cb(void* data, Evas_Object* obj, const char* emission, const char* source)
+{
+ Evas_Object* entry = static_cast<Evas_Object*>(data);
+ elm_entry_entry_set(entry, "");
+}
+
+static void _changed_cb(void* data, Evas_Object* obj, void* eventInfo)
+{
+ Evas_Object* layout = static_cast<Evas_Object*>(data);
+
+ if (elm_object_focus_get(layout)) {
+ if (elm_entry_is_empty(obj))
+ elm_object_signal_emit(layout, "elm,state,eraser,hide", "elm");
+ else
+ elm_object_signal_emit(layout, "elm,state,eraser,show", "elm");
+ }
+}
+
+static void _focused_cb(void* data, Evas_Object* obj, void* eventInfo)
+{
+ Evas_Object* layout = static_cast<Evas_Object*>(data);
+
+ if (!elm_entry_is_empty(obj))
+ elm_object_signal_emit(layout, "elm,state,eraser,show", "elm");
+}
+
+static void _unfocused_cb(void* data, Evas_Object* obj, void* eventInfo)
+{
+ Evas_Object* layout = static_cast<Evas_Object*>(data);
+ elm_object_signal_emit(layout, "elm,state,eraser,hide", "elm");
+}
+
void InputPicker::showDataList(Ewk_Input_Type inputType, Eina_List* optionList)
{
- // FIXME: Show DataList UI.
+ Evas_Object* parent = elm_object_parent_widget_get(m_ewkView);
+ Evas_Object* win = parent;
+
+ m_dataList = optionList;
+
+ if (m_pickerLayout)
+ delete m_pickerLayout;
+
+ m_pickerLayout = static_cast<Input_Picker_Layout*>(new Input_Picker_Layout);
+ memset(m_pickerLayout, 0, sizeof(m_pickerLayout));
+
+ while (parent) {
+ const char* type = elm_object_widget_type_get(parent);
+ if (type) {
+ if (!strcmp(type, "win")) {
+ win = parent;
+ break;
+ }
+ }
+ parent = elm_object_parent_widget_get(parent);
+ }
+
+ if (!win)
+ win = m_ewkView;
+
+ Evas_Object* conformant = elm_conformant_add(win);
+ elm_win_resize_object_add(win, conformant);
+ evas_object_size_hint_weight_set(conformant, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(conformant, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(conformant);
+
+ Evas_Object* dummyLaout = elm_layout_add(conformant);
+ elm_object_content_set(conformant, dummyLaout);
+
+ m_pickerLayout->popup = elm_popup_add(dummyLaout);
+ elm_object_part_text_set(m_pickerLayout->popup, "title,text", "Select data list");
+
+ m_pickerLayout->layout = elm_layout_add(m_pickerLayout->popup);
+ elm_layout_file_set(m_pickerLayout->layout, EDJE_DIR"/control.edj","data_list_picker");
+ evas_object_size_hint_weight_set(m_pickerLayout->layout, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_show(m_pickerLayout->layout);
+ elm_object_content_set(m_pickerLayout->popup, m_pickerLayout->layout);
+
+ Evas_Object* elmList = elm_list_add(m_pickerLayout->layout);
+ Eina_List* list = 0;
+ void* listItem = 0;
+ EINA_LIST_FOREACH(optionList, list, listItem) {
+ if (listItem)
+ elm_list_item_append(elmList, static_cast<char*>(listItem), 0, 0, _data_list_selected_cb, this);
+ }
+ evas_object_size_hint_weight_set(elmList, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_show(elmList);
+ elm_object_part_content_set(m_pickerLayout->layout, "data_list", elmList);
+
+ Evas_Object* editFieldLayout = elm_layout_add(m_pickerLayout->layout);
+ elm_layout_theme_set(editFieldLayout, "layout", "editfield", "default");
+
+ m_pickerLayout->dataListEditField = elm_entry_add(editFieldLayout);
+ elm_object_part_content_set(editFieldLayout, "elm.swallow.content", m_pickerLayout->dataListEditField);
+
+ elm_object_signal_emit(editFieldLayout, "elm,state,guidetext,hide", "elm");
+ elm_object_signal_callback_add(editFieldLayout, "elm,eraser,clicked", "elm", _eraser_clicked_cb, m_pickerLayout->dataListEditField);
+ evas_object_smart_callback_add(m_pickerLayout->dataListEditField, "changed", _changed_cb, editFieldLayout);
+ evas_object_smart_callback_add(m_pickerLayout->dataListEditField, "focused", _focused_cb, editFieldLayout);
+ evas_object_smart_callback_add(m_pickerLayout->dataListEditField, "unfocused", _unfocused_cb, editFieldLayout);
+
+ elm_object_part_content_set(m_pickerLayout->layout, "selected_item", editFieldLayout);
+ evas_object_show(editFieldLayout);
+
+ m_pickerLayout->okButton = elm_button_add(m_pickerLayout->popup);
+ elm_object_style_set(m_pickerLayout->okButton, "popup_button/default");
+ elm_object_text_set(m_pickerLayout->okButton, "OK");
+ elm_object_part_content_set(m_pickerLayout->popup, "button1", m_pickerLayout->okButton);
+ evas_object_smart_callback_add(m_pickerLayout->okButton, "clicked", _data_list_popup_response_cb, this);
+ evas_object_show(m_pickerLayout->popup);
+
+ Evas_Object* cancelButton = elm_button_add(m_pickerLayout->popup);
+ elm_object_style_set(cancelButton, "popup_button/default");
+ elm_object_text_set(cancelButton, "Cancel");
+ elm_object_part_content_set(m_pickerLayout->popup, "button2", cancelButton);
+ evas_object_smart_callback_add(cancelButton, "clicked", _data_list_popup_response_cancel_cb, this);
+ evas_object_show(cancelButton);
}
void InputPicker::hideDataList(Ewk_Input_Type inputType)
{
- // FIXME: Close DataList UI.
+ if (!m_dataList)
+ return;
+
+ if(m_pickerLayout->popup){
+ evas_object_del(m_pickerLayout->popup);
+ m_pickerLayout->popup = 0;
+ }
+
+ delete m_pickerLayout;
+ m_pickerLayout = 0;
+
+ m_dataList = 0;
}
#endif