Fix surrounding text issue
authorSangYong Park <sy302.park@samsung.com>
Wed, 16 Oct 2013 08:57:10 +0000 (17:57 +0900)
committerSangYong Park <sy302.park@samsung.com>
Thu, 17 Oct 2013 01:20:54 +0000 (10:20 +0900)
[Title] Fix surrounding text issue
[Issue#] P131014-04048
[Problem] Candidate text was invalid by IME.
[Cause] Set invalid surrounding text by webkit.
[Solution] Provide valid surrounding text

Change-Id: I31ceaa625d45df15dcbdc0cd18e9fdc5b012e731

Source/WebKit2/UIProcess/efl/InputMethodContextEfl.cpp
Source/WebKit2/UIProcess/efl/InputMethodContextEfl.h
Source/WebKit2/WebProcess/WebPage/WebPage.cpp

index 48c960e..3aa2011 100755 (executable)
@@ -99,6 +99,7 @@ InputMethodContextEfl::InputMethodContextEfl(EwkViewImpl* viewImpl, PassOwnPtr<E
     , m_doNotHandleFakeKeyEvent(false)
     , m_fakeKeyEventTimer(this, &InputMethodContextEfl::fakeKeyEventTimerFired)
     , m_approximateCursorPosition(0)
+    , m_isLastKeyEventFiltered(false)
 #endif
 {
 #if ENABLE(TIZEN_ISF_PORT)
@@ -418,6 +419,11 @@ void InputMethodContextEfl::handleKeyDownEvent(const Evas_Event_Key_Down* downEv
     if (!m_context)
         return;
 
+    const EditorState& state = m_viewImpl->page()->editorState();
+
+    if (!m_isLastKeyEventFiltered && !m_approximateSurroundingText.isNull() && !state.hasComposition)
+        ecore_imf_context_cursor_position_set(m_context.get(), m_approximateCursorPosition);
+
     if (m_fakeKeyEventTimer.isActive())
         m_fakeKeyEventTimer.stop();
     else
@@ -433,22 +439,18 @@ void InputMethodContextEfl::handleKeyDownEvent(const Evas_Event_Key_Down* downEv
 
 #if ENABLE(TIZEN_ISF_PORT)
     m_doNotHandleFakeKeyEvent = false;
+    m_isLastKeyEventFiltered = *isFiltered;
 
-    const EditorState& state = m_viewImpl->page()->editorState();
-
-    if (m_approximateSurroundingText.isNull() && downEvent->compose) {
-        if (downEvent->compose[0] == 0x8) {
+    if (!*isFiltered) {
+        if (!strcmp(downEvent->key, "BackSpace")) {
             if (state.cursorPosition > 0)
                 updateApproximateText(String(), state.cursorPosition - 1, 1);
-        } else if (downEvent->compose[0] == 0x7f) {
+        } else if (!strcmp(downEvent->key, "Delete")) {
             if (state.cursorPosition < state.surroundingText.length())
                 updateApproximateText(String(), state.cursorPosition, 1);
         } else
             updateApproximateText(String::fromUTF8(downEvent->compose), 0, 0);
     }
-
-    if (!state.hasComposition)
-        ecore_imf_context_cursor_position_set(m_context.get(), m_approximateCursorPosition);
 #endif
 }
 
@@ -464,10 +466,10 @@ void InputMethodContextEfl::updateTextInputState()
     else
         hideIMFContext();
 
+    m_approximateSurroundingText = String();
+
     if (m_context && !editor.hasComposition)
         ecore_imf_context_cursor_position_set(m_context.get(), editor.cursorPosition);
-
-    m_approximateSurroundingText = String();
 }
 
 void InputMethodContextEfl::updateTextInputStateByUserAction(bool setFocus)
@@ -844,7 +846,9 @@ void InputMethodContextEfl::fakeKeyEventTimerFired(WebCore::Timer<InputMethodCon
     memset(&downEvent, 0, sizeof(Evas_Event_Key_Down));
     downEvent.key = data;
     downEvent.string = data;
-    m_viewImpl->page()->handleKeyboardEvent(NativeWebKeyboardEvent(&downEvent, true));
+    NativeWebKeyboardEvent nativeEvent(&downEvent, true);
+    nativeEvent.setInputMethodContextID(m_viewImpl->page()->editorState().inputMethodContextID);
+    m_viewImpl->page()->handleKeyboardEvent(nativeEvent);
 
     Evas_Event_Key_Up upEvent;
     memset(&upEvent, 0, sizeof(Evas_Event_Key_Up));
index 3cd4cfc..837f4b2 100755 (executable)
@@ -131,6 +131,7 @@ private:
     WebCore::Timer<InputMethodContextEfl> m_fakeKeyEventTimer;
     String m_approximateSurroundingText;
     unsigned m_approximateCursorPosition;
+    bool m_isLastKeyEventFiltered;
 #endif
 };
 
index b8340f5..814aa42 100755 (executable)
@@ -578,11 +578,10 @@ EditorState WebPage::editorState() const
     if (!rootEditableElement)
         return result;
 
+    result.inputMethodContextID = reinterpret_cast<uintptr_t>(rootEditableElement);
     updateEditorStateRect(frame, result);
 
     if (!result.shouldIgnoreCompositionSelectionChange && result.isContentEditable) {
-        result.inputMethodContextID = reinterpret_cast<uintptr_t>(rootEditableElement);
-
         Node* hostNode = rootEditableElement->shadowHost();
         if (!hostNode)
             hostNode = rootEditableElement;