Refine input method code
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / efl / InputMethodContextEfl.cpp
index 24d2a8e..a720eab 100755 (executable)
@@ -35,7 +35,7 @@ InputMethodContextEfl::InputMethodContextEfl(EwkViewImpl* viewImpl, PassOwnPtr<E
     , m_context(context)
     , m_focused(false)
 #if ENABLE(TIZEN_ISF_PORT)
-    , m_tryToShow(false)
+    , m_useInputMethod(false)
     , m_state(ECORE_IMF_INPUT_PANEL_STATE_HIDE)
 #endif
 {
@@ -322,31 +322,21 @@ void InputMethodContextEfl::handleKeyDownEvent(const Evas_Event_Key_Down* downEv
     *isFiltered = ecore_imf_context_filter_event(m_context.get(), ECORE_IMF_EVENT_KEY_DOWN, &inputMethodEvent);
 }
 
+#if ENABLE(TIZEN_ISF_PORT)
 void InputMethodContextEfl::updateTextInputState()
 {
-#if !ENABLE(TIZEN_ISF_PORT)
-    if (!m_context)
-        return;
-#endif
-
     const EditorState& editor = m_viewImpl->page()->editorState();
 
-#if ENABLE(TIZEN_ISF_PORT)
-    bool isActive = !editor.selectionIsNone && (editor.isContentEditable || m_tryToShow);
-#else
-    bool isActive = editor.isContentEditable;
-#endif
+    if (m_focused)
+        ecore_imf_context_cursor_position_set(m_context.get(), editor.cursorPosition);
 
-    if (isActive) {
-#if ENABLE(TIZEN_ISF_PORT)
-        if (m_context)
-            ecore_imf_context_cursor_position_set(m_context.get(), editor.cursorPosition);
-#endif
+    if (editor.shouldIgnoreCompositionSelectionChange)
+        return;
 
+    if (editor.isContentEditable && m_useInputMethod) {
         if (m_focused)
             return;
 
-#if ENABLE(TIZEN_ISF_PORT)
         Ewk_Settings* settings = ewk_view_settings_get(m_viewImpl->view());
         bool defaultKeypadEnabled = ewk_settings_default_keypad_enabled_get(settings);
 
@@ -417,16 +407,31 @@ void InputMethodContextEfl::updateTextInputState()
             m_focused = true;
             return;
         }
-#endif
 
         ecore_imf_context_reset(m_context.get());
         ecore_imf_context_focus_in(m_context.get());
-#if ENABLE(TIZEN_ISF_PORT)
         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);
-#endif
+        m_focused = true;
+    } else
+        hideIMFContext();
+}
+#else
+void InputMethodContextEfl::updateTextInputState()
+{
+    if (!m_context)
+        return;
+
+    const EditorState& editor = m_viewImpl->page()->editorState();
+
+    if (editor.isContentEditable) {
+        if (m_focused)
+            return;
+
+        ecore_imf_context_reset(m_context.get());
+        ecore_imf_context_focus_in(m_context.get());
         m_focused = true;
     } else {
         if (!m_focused)
@@ -438,12 +443,9 @@ void InputMethodContextEfl::updateTextInputState()
         m_focused = false;
         ecore_imf_context_reset(m_context.get());
         ecore_imf_context_focus_out(m_context.get());
-#if ENABLE(TIZEN_ISF_PORT)
-        ecore_imf_context_input_panel_hide(m_context.get());
-        revertIMFContext();
-#endif
     }
 }
+#endif
 
 #if ENABLE(TIZEN_ISF_PORT)
 void InputMethodContextEfl::initializeIMFContext(Ecore_IMF_Context* context, Ecore_IMF_Input_Panel_Layout layout)
@@ -460,6 +462,12 @@ void InputMethodContextEfl::initializeIMFContext(Ecore_IMF_Context* context, Eco
     ecore_imf_context_input_panel_layout_set(m_context.get(), layout);
 }
 
+void InputMethodContextEfl::setUseInputMethod(bool use)
+{
+    m_useInputMethod = use;
+    updateTextInputState();
+}
+
 void InputMethodContextEfl::setType(const String& type)
 {
     Ecore_IMF_Input_Panel_Layout layout;
@@ -546,9 +554,14 @@ void InputMethodContextEfl::resetIMFContext()
 
 void InputMethodContextEfl::hideIMFContext()
 {
-    if (!m_context)
+    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) {
         ecore_imf_context_reset(m_context.get());
         ecore_imf_context_input_panel_hide(m_context.get());