IME show properly after disappear the clipboard.
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / efl / InputMethodContextEfl.cpp
index cdd0035..d810116 100755 (executable)
@@ -37,6 +37,7 @@ InputMethodContextEfl::InputMethodContextEfl(EwkViewImpl* viewImpl, PassOwnPtr<E
 #if ENABLE(TIZEN_ISF_PORT)
     , m_useInputMethod(false)
     , m_state(ECORE_IMF_INPUT_PANEL_STATE_HIDE)
+    , m_inputPickerType(-1)
 #endif
 {
     ASSERT(context);
@@ -324,97 +325,20 @@ void InputMethodContextEfl::handleKeyDownEvent(const Evas_Event_Key_Down* downEv
 void InputMethodContextEfl::updateTextInputState()
 {
     const EditorState& editor = m_viewImpl->page()->editorState();
-
-    if (m_focused)
-        ecore_imf_context_cursor_position_set(m_context.get(), editor.cursorPosition);
-
     if (editor.shouldIgnoreCompositionSelectionChange)
         return;
 
     if (editor.isContentEditable && m_useInputMethod) {
-        if (m_state != ECORE_IMF_INPUT_PANEL_STATE_HIDE)
-            return;
-
-        Ewk_Settings* settings = ewk_view_settings_get(m_viewImpl->view());
-        bool defaultKeypadEnabled = ewk_settings_default_keypad_enabled_get(settings);
-
-#if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
-        if (editor.inputMethodHints == "date") {
-            showInputPicker(EWK_INPUT_TYPE_DATE, editor);
-            return;
-        } else if (editor.inputMethodHints == "datetime") {
-            showInputPicker(EWK_INPUT_TYPE_DATETIME, editor);
-            return;
-        } else if (editor.inputMethodHints == "datetime-local") {
-            showInputPicker(EWK_INPUT_TYPE_DATETIMELOCAL, editor);
-            return;
-        } else if (editor.inputMethodHints == "month") {
-            showInputPicker(EWK_INPUT_TYPE_MONTH, editor);
-            return;
-        } else if (editor.inputMethodHints == "time") {
-            showInputPicker(EWK_INPUT_TYPE_TIME, editor);
-            return;
-        } else if (editor.inputMethodHints == "week") {
-            showInputPicker(EWK_INPUT_TYPE_WEEK, editor);
-            return;
-        }
-
-#if ENABLE(TIZEN_DATALIST_ELEMENT)
-        Vector<String> optionList = m_viewImpl->page()->getFocusedInputElementDataList();
-        if (optionList.size() > 0) {
-            if (editor.selectionIsRange || !evas_object_focus_get(m_viewImpl->view()))
-                return;
-
-            if (editor.inputMethodHints == "tel")
-                ewkViewDataListShowRequest(m_viewImpl->view(), EWK_INPUT_TYPE_TELEPHONE, optionList);
-            else if (editor.inputMethodHints == "number")
-                ewkViewDataListShowRequest(m_viewImpl->view(), EWK_INPUT_TYPE_NUMBER, optionList);
-            else if (editor.inputMethodHints == "email")
-                ewkViewDataListShowRequest(m_viewImpl->view(), EWK_INPUT_TYPE_EMAIL, optionList);
-            else if (editor.inputMethodHints == "url")
-                ewkViewDataListShowRequest(m_viewImpl->view(), EWK_INPUT_TYPE_URL, optionList);
-            else
-                ewkViewDataListShowRequest(m_viewImpl->view(), EWK_INPUT_TYPE_TEXT, optionList);
-
-            return;
-        }
-#endif
-#endif // ENABLE(TIZEN_INPUT_TAG_EXTENSION)
-
 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_CLIPBOARD)
-        if (m_viewImpl->pageClient->isClipboardWindowOpened()) {
-            LOG(ISF, "[FAIL] Clipboard\n");
-            return;
-        }
+        if (m_viewImpl->pageClient->isClipboardWindowOpened())
+            m_viewImpl->pageClient->closeClipboardWindow();
 #endif
-
-        bool hasFocus = evas_object_focus_get(m_viewImpl->view());
-
-        if (!defaultKeypadEnabled) {
-            if (hasFocus) {
-                Eina_Rectangle dummyRectForCustomKeypadCallback;
-                memset(&dummyRectForCustomKeypadCallback, 0, sizeof(Eina_Rectangle));
-                evas_object_smart_callback_call(m_viewImpl->view(), "inputmethod,changed", &dummyRectForCustomKeypadCallback);
-            }
-            return;
-        }
-
-        setType(editor.inputMethodHints);
-
-        if (!hasFocus) {
-            m_focused = true;
-            return;
-        }
-
-        ecore_imf_context_reset(m_context.get());
-        ecore_imf_context_focus_in(m_context.get());
-        ecore_imf_context_input_panel_show(m_context.get());
-
-        // input field zoom for external keyboard
-        ewk_view_focused_node_adjust(m_viewImpl->view(), EINA_TRUE);
-        m_focused = true;
+        showIMFContext(editor);
     } else
         hideIMFContext();
+
+    if (m_context)
+        ecore_imf_context_cursor_position_set(m_context.get(), editor.cursorPosition);
 }
 #else
 void InputMethodContextEfl::updateTextInputState()
@@ -466,22 +390,24 @@ void InputMethodContextEfl::setUseInputMethod(bool use)
     updateTextInputState();
 }
 
-void InputMethodContextEfl::setType(const String& type)
+Ecore_IMF_Input_Panel_Layout InputMethodContextEfl::layoutType(const String& type)
 {
-    Ecore_IMF_Input_Panel_Layout layout;
     if (type == "number")
-        layout = ECORE_IMF_INPUT_PANEL_LAYOUT_NUMBER;
+        return ECORE_IMF_INPUT_PANEL_LAYOUT_NUMBER;
     else if (type == "email")
-        layout = ECORE_IMF_INPUT_PANEL_LAYOUT_EMAIL;
+        return ECORE_IMF_INPUT_PANEL_LAYOUT_EMAIL;
     else if (type == "url")
-        layout = ECORE_IMF_INPUT_PANEL_LAYOUT_URL;
+        return ECORE_IMF_INPUT_PANEL_LAYOUT_URL;
     else if (type == "tel")
-        layout = ECORE_IMF_INPUT_PANEL_LAYOUT_PHONENUMBER;
+        return ECORE_IMF_INPUT_PANEL_LAYOUT_PHONENUMBER;
     else if (type == "password")
-        layout = ECORE_IMF_INPUT_PANEL_LAYOUT_PASSWORD;
+        return ECORE_IMF_INPUT_PANEL_LAYOUT_PASSWORD;
     else
-        layout = ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL;
+        return ECORE_IMF_INPUT_PANEL_LAYOUT_NORMAL;
+}
 
+void InputMethodContextEfl::setIMFContext(Ecore_IMF_Input_Panel_Layout layout, const String& type)
+{
     if (m_contextList.contains(layout)) {
         revertIMFContext();
         m_context = m_contextList.take(layout);
@@ -516,6 +442,11 @@ Ecore_IMF_Autocapital_Type InputMethodContextEfl::autoCapitalType()
 
 void InputMethodContextEfl::onFocusIn()
 {
+    if (m_inputPickerType >= 0) {
+        showInputPicker(m_viewImpl->page()->editorState());
+        return;
+    }
+
     if (!m_context || !m_focused)
         return;
 
@@ -525,9 +456,6 @@ void InputMethodContextEfl::onFocusIn()
 
 void InputMethodContextEfl::onFocusOut()
 {
-    if (!m_context || !m_focused)
-        return;
-
 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_CLIPBOARD)
     if (m_state != ECORE_IMF_INPUT_PANEL_STATE_SHOW) {
         if (m_viewImpl->pageClient->isClipboardWindowOpened())
@@ -535,6 +463,9 @@ void InputMethodContextEfl::onFocusOut()
     }
 #endif
 
+    if (!m_context || !m_focused)
+        return;
+
     ecore_imf_context_input_panel_hide(m_context.get());
     ecore_imf_context_focus_out(m_context.get());
 }
@@ -557,11 +488,90 @@ void InputMethodContextEfl::resetIMFContext()
     ecore_imf_context_reset(m_context.get());
 }
 
-void InputMethodContextEfl::hideIMFContext()
+void InputMethodContextEfl::showIMFContext(const EditorState& editor)
 {
-    if (!m_context || !m_focused)
+    Ecore_IMF_Input_Panel_Layout layout = layoutType(editor.inputMethodHints);
+
+    if (m_context && m_state != ECORE_IMF_INPUT_PANEL_STATE_HIDE && layout == ecore_imf_context_input_panel_layout_get(m_context.get()))
+        return;
+
+    Ewk_Settings* settings = ewk_view_settings_get(m_viewImpl->view());
+    bool defaultKeypadEnabled = ewk_settings_default_keypad_enabled_get(settings);
+
+#if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
+    if (editor.inputMethodHints == "date")
+        m_inputPickerType = EWK_INPUT_TYPE_DATE;
+    else if (editor.inputMethodHints == "datetime")
+        m_inputPickerType = EWK_INPUT_TYPE_DATETIME;
+    else if (editor.inputMethodHints == "datetime-local")
+        m_inputPickerType = EWK_INPUT_TYPE_DATETIMELOCAL;
+    else if (editor.inputMethodHints == "month")
+        m_inputPickerType = EWK_INPUT_TYPE_MONTH;
+    else if (editor.inputMethodHints == "time")
+        m_inputPickerType = EWK_INPUT_TYPE_TIME;
+    else if (editor.inputMethodHints == "week")
+        m_inputPickerType = EWK_INPUT_TYPE_WEEK;
+    else
+        m_inputPickerType = -1;
+
+    if (m_inputPickerType >= 0) {
+        showInputPicker(editor);
+        return;
+    }
+
+#if ENABLE(TIZEN_DATALIST_ELEMENT)
+    Vector<String> optionList = m_viewImpl->page()->getFocusedInputElementDataList();
+    if (optionList.size() > 0) {
+        if (editor.selectionIsRange || !evas_object_focus_get(m_viewImpl->view()))
+            return;
+
+        if (editor.inputMethodHints == "tel")
+            ewkViewDataListShowRequest(m_viewImpl->view(), EWK_INPUT_TYPE_TELEPHONE, optionList);
+        else if (editor.inputMethodHints == "number")
+            ewkViewDataListShowRequest(m_viewImpl->view(), EWK_INPUT_TYPE_NUMBER, optionList);
+        else if (editor.inputMethodHints == "email")
+            ewkViewDataListShowRequest(m_viewImpl->view(), EWK_INPUT_TYPE_EMAIL, optionList);
+        else if (editor.inputMethodHints == "url")
+            ewkViewDataListShowRequest(m_viewImpl->view(), EWK_INPUT_TYPE_URL, optionList);
+        else
+            ewkViewDataListShowRequest(m_viewImpl->view(), EWK_INPUT_TYPE_TEXT, optionList);
+
+        return;
+    }
+#endif
+#endif // ENABLE(TIZEN_INPUT_TAG_EXTENSION)
+
+    bool hasFocus = evas_object_focus_get(m_viewImpl->view());
+
+    if (!defaultKeypadEnabled) {
+        if (hasFocus) {
+            Eina_Rectangle dummyRectForCustomKeypadCallback;
+            memset(&dummyRectForCustomKeypadCallback, 0, sizeof(Eina_Rectangle));
+            evas_object_smart_callback_call(m_viewImpl->view(), "inputmethod,changed", &dummyRectForCustomKeypadCallback);
+        }
+        return;
+    }
+
+    setIMFContext(layout, editor.inputMethodHints);
+
+    if (!hasFocus) {
+        m_focused = true;
         return;
+    }
+
+    ecore_imf_context_reset(m_context.get());
+    ecore_imf_context_focus_in(m_context.get());
+    ecore_imf_context_input_panel_show(m_context.get());
+
+    // input field zoom for external keyboard
+    ewk_view_focused_node_adjust(m_viewImpl->view(), EINA_TRUE);
+
+    m_focused = true;
+    m_state = ECORE_IMF_INPUT_PANEL_STATE_WILL_SHOW;
+}
 
+void InputMethodContextEfl::hideIMFContext()
+{
 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_CLIPBOARD)
     if (m_state != ECORE_IMF_INPUT_PANEL_STATE_SHOW) {
         if (m_viewImpl->pageClient->isClipboardWindowOpened())
@@ -569,12 +579,18 @@ void InputMethodContextEfl::hideIMFContext()
     }
 #endif
 
+    m_inputPickerType = -1;
+
+    if (!m_context || !m_focused)
+        return;
+
     if (m_viewImpl->page()->editorState().hasComposition)
         m_viewImpl->page()->cancelComposition();
 
     m_focused = false;
 
-    if (ecore_imf_context_input_panel_state_get(m_context.get()) != ECORE_IMF_INPUT_PANEL_STATE_HIDE) {
+    if (ecore_imf_context_input_panel_state_get(m_context.get()) != ECORE_IMF_INPUT_PANEL_STATE_HIDE
+        && evas_object_focus_get(m_viewImpl->view())) {
         ecore_imf_context_reset(m_context.get());
         ecore_imf_context_input_panel_hide(m_context.get());
         ecore_imf_context_focus_out(m_context.get());
@@ -589,12 +605,13 @@ void InputMethodContextEfl::destroyIMFContextList()
 }
 
 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
-void InputMethodContextEfl::showInputPicker(Ewk_Input_Type type, const EditorState& editorState)
+void InputMethodContextEfl::showInputPicker(const EditorState& editorState)
 {
     if (editorState.selectionIsRange || !evas_object_focus_get(m_viewImpl->view()))
         return;
 
-    ewkViewInputPickerRequest(m_viewImpl->view(), type, editorState.surroundingText);
+    ewkViewInputPickerRequest(m_viewImpl->view(), static_cast<Ewk_Input_Type>(m_inputPickerType), editorState.surroundingText);
+    m_inputPickerType = -1;
 }
 #endif