[Title] Implement input data list picker.
authorHyerim Bae <hyerim.bae@samsung.com>
Mon, 13 Aug 2012 10:10:21 +0000 (19:10 +0900)
committerHyerim Bae <hyerim.bae@samsung.com>
Mon, 27 Aug 2012 13:03:50 +0000 (22:03 +0900)
[Issue#] N/A
[Problem] Input data list picker was not supported.
[Cause] Not implemented.
[Solution] Implement input data list picker.
[Team] Browser UI
[Developer] Hyerim Bae (hyerim.bae)
[Request] N/A

Change-Id: Id6193e60978b78c5b5e4e02db67952e230aabcb3

Source/WebKit2/UIProcess/API/efl/InputPicker.cpp
Source/WebKit2/UIProcess/API/efl/InputPicker.h
Source/WebKit2/UIProcess/API/efl/tizen/control.edc

index fe5f895..81e8397 100644 (file)
@@ -34,8 +34,9 @@
 namespace WebKit {
 
 InputPicker::InputPicker(Evas_Object* ewkView)
-: m_ewkView(ewkView)
-, m_pickerLayout(0)
+    : m_ewkView(ewkView)
+    , m_pickerLayout(0)
+    , m_dataList(0)
 {
 }
 
@@ -67,14 +68,195 @@ void InputPicker::show(Ewk_Input_Type inputType, const char* inputValue)
 }
 
 #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
 
index 521f160..8f88972 100644 (file)
@@ -52,6 +52,7 @@ struct Input_Picker_Layout {
     Evas_Object* datePicker;
     Evas_Object* colorRect;
     Evas_Object* okButton;
+    Evas_Object* dataListEditField;
     bool datetimeLocal;
 };
 
@@ -82,10 +83,14 @@ namespace WebKit {
         static void _week_popup_response_cb(void*, Evas_Object*, void*);
         static void _datetime_popup_response_cb(void*, Evas_Object*, void*);
         static void _color_popup_response_cb(void*, Evas_Object*, void*);
+        static void _data_list_popup_response_cb(void*, Evas_Object*, void*);
+        static void _data_list_popup_response_cancel_cb(void*, Evas_Object*, void*);
+        static void _data_list_selected_cb(void*, Evas_Object*, void*);
         static void _color_selected_cb(void*, Evas*, Evas_Object*, void*);
 
         Evas_Object* m_ewkView;
         Input_Picker_Layout* m_pickerLayout;
+        Eina_List* m_dataList;
     };
 } // namespace WebKit
 
index 517d696..ea15979 100644 (file)
@@ -622,6 +622,48 @@ collections {
             }
         }
     }
+    group { name: "data_list_picker";
+        parts {
+            part { name: "bg";
+                type: RECT;
+                mouse_events: 1;
+                repeat_events: 0;
+                scale: 1;
+                description { state: "default" 0.0;
+                    min : 0 400;
+                    fixed: 0 0;
+                    align: 0.0 0.0;
+                    rel1 { relative: 0.0 0.0; }
+                    rel2 { relative: 1.0 1.0; }
+                    color: 0 0 0 0;
+                }
+            }
+            part { name: "selected_item";
+                type: SWALLOW;
+                mouse_events: 1;
+                repeat_events: 0;
+                scale: 1;
+                description { state: "default" 0.0;
+                    align: 0.0 1.0;
+                    min: 0 80;
+                    fixed: 0 1;
+                    rel1 { relative: 0.0 1.0; to: "bg"; }
+                    rel2 { relative: 1.0 1.0; to: "bg"; }
+                }
+            }
+            part { name: "data_list";
+                type: SWALLOW;
+                mouse_events: 1;
+                repeat_events: 0;
+                scale: 1;
+                description { state: "default" 0.0;
+                    align: 0.0 0.0;
+                    rel1 { relative: 0.0 0.0; to: "bg"; }
+                    rel2 { relative: 1.0 0.0; to_x: "bg"; to_y: "selected_item"; }
+                }
+            }
+        }
+    }
     group { name: "elm/picker";
         images {
             image: "I01_picker_panel_bg.png" COMP;