Ignore contiguous composition event.
authorSangYong Park <sy302.park@samsung.com>
Wed, 3 Jul 2013 13:05:51 +0000 (22:05 +0900)
committerSangYong Park <sy302.park@samsung.com>
Thu, 4 Jul 2013 04:07:11 +0000 (13:07 +0900)
[Title] Ignore contiguous composition event.
[Issue#] P130605-7046
[Problem] Text style was not applied.
[Cause] Text style was initialized when set empty text before confirm composition.
[Solution] Ignore contiguous composition event.

Change-Id: Id4cf6caed3b8e0361160acc63f43250978acfef4

Source/WebKit2/UIProcess/efl/InputMethodContextEfl.cpp
Source/WebKit2/UIProcess/efl/InputMethodContextEfl.h
Source/WebKit2/WebProcess/WebCoreSupport/efl/WebEditorClientEfl.cpp
Source/WebKit2/WebProcess/WebPage/efl/WebPageEfl.cpp

index 4a0a7af..8bd8ee1 100755 (executable)
@@ -42,6 +42,8 @@ InputMethodContextEfl::InputMethodContextEfl(EwkViewImpl* viewImpl, PassOwnPtr<E
     , m_contextID(0)
     , m_state(ECORE_IMF_INPUT_PANEL_STATE_HIDE)
     , m_inputPickerType(-1)
+    , m_handleKeyDownEvent(false)
+    , m_fakeKeyEventTimer(this, &InputMethodContextEfl::fakeKeyEventTimerFired)
 #endif
 {
 #if !ENABLE(TIZEN_ISF_PORT)
@@ -141,6 +143,9 @@ void InputMethodContextEfl::onIMFDeleteSurrounding(void* data, Ecore_IMF_Context
     if (!eventInfo || !inputMethodContext->m_viewImpl->page()->focusedFrame() || !inputMethodContext->m_focused)
         return;
 
+    if (!inputMethodContext->m_handleKeyDownEvent)
+        inputMethodContext->requestFakeKeyEvent();
+
     Ecore_IMF_Event_Delete_Surrounding* event = static_cast<Ecore_IMF_Event_Delete_Surrounding*>(eventInfo);
     inputMethodContext->m_viewImpl->page()->deleteSurroundingText(event->offset, event->n_chars);
 }
@@ -151,6 +156,9 @@ void InputMethodContextEfl::onIMFInputSequenceComplete(void* data, Ecore_IMF_Con
     if (!eventInfo || !inputMethodContext->m_focused)
         return;
 
+    if (!inputMethodContext->m_handleKeyDownEvent)
+        inputMethodContext->requestFakeKeyEvent();
+
     inputMethodContext->m_viewImpl->page()->confirmComposition(String::fromUTF8(static_cast<char*>(eventInfo)));
 }
 
@@ -198,6 +206,9 @@ void InputMethodContextEfl::onIMFPreeditSequenceChanged(void* data, Ecore_IMF_Co
     if (!page->focusedFrame())
         return;
 
+    if (!inputMethodContext->m_handleKeyDownEvent)
+        inputMethodContext->requestFakeKeyEvent();
+
     PageClientImpl* pageClient = inputMethodContext->m_viewImpl->pageClient.get();
     IntRect caretRect;
     page->getCaretPosition(caretRect);
@@ -325,13 +336,22 @@ void InputMethodContextEfl::handleKeyDownEvent(const Evas_Event_Key_Down* downEv
     if (!m_context)
         return;
 
-    m_viewImpl->page()->prepareKeyDownEvent();
+    if (m_fakeKeyEventTimer.isActive())
+        m_fakeKeyEventTimer.stop();
+    else
+        m_viewImpl->page()->prepareKeyDownEvent();
+
+    m_handleKeyDownEvent = true;
 #endif
 
     Ecore_IMF_Event inputMethodEvent;
     ecore_imf_evas_event_key_down_wrap(const_cast<Evas_Event_Key_Down*>(downEvent), &inputMethodEvent.key_down);
 
     *isFiltered = ecore_imf_context_filter_event(m_context.get(), ECORE_IMF_EVENT_KEY_DOWN, &inputMethodEvent);
+
+#if ENABLE(TIZEN_ISF_PORT)
+    m_handleKeyDownEvent = false;
+#endif
 }
 
 #if ENABLE(TIZEN_ISF_PORT)
@@ -703,6 +723,32 @@ void InputMethodContextEfl::setKeyboardMode(bool isOn)
         parent = elm_object_parent_widget_get(parent);
     }
 }
+
+void InputMethodContextEfl::requestFakeKeyEvent()
+{
+    if (m_handleKeyDownEvent || m_fakeKeyEventTimer.isActive())
+        return;
+
+    m_fakeKeyEventTimer.startOneShot(0);
+    m_viewImpl->page()->prepareKeyDownEvent();
+}
+
+void InputMethodContextEfl::fakeKeyEventTimerFired(WebCore::Timer<InputMethodContextEfl>*)
+{
+    const char* text = " ";
+
+    Evas_Event_Key_Down downEvent;
+    memset(&downEvent, 0, sizeof(Evas_Event_Key_Down));
+    downEvent.key = text;
+    downEvent.string = text;
+    m_viewImpl->page()->handleKeyboardEvent(NativeWebKeyboardEvent(&downEvent, true));
+
+    Evas_Event_Key_Up upEvent;
+    memset(&upEvent, 0, sizeof(Evas_Event_Key_Up));
+    upEvent.key = text;
+    upEvent.string = text;
+    m_viewImpl->page()->handleKeyboardEvent(NativeWebKeyboardEvent(&upEvent));
+}
 #endif // #if ENABLE(TIZEN_ISF_PORT)
 
 }
index 9449278..f95c79c 100755 (executable)
@@ -93,6 +93,9 @@ private:
 #endif
 
     void setKeyboardMode(bool);
+
+    void requestFakeKeyEvent();
+    void fakeKeyEventTimerFired(WebCore::Timer<InputMethodContextEfl>*);
 #endif
 
     EwkViewImpl* m_viewImpl;
@@ -107,6 +110,8 @@ private:
     int m_state;
     WebCore::IntRect m_imeRect;
     int m_inputPickerType;
+    bool m_handleKeyDownEvent;
+    WebCore::Timer<InputMethodContextEfl> m_fakeKeyEventTimer;
 #endif
 };
 
index c14feb7..a7c528f 100755 (executable)
@@ -56,6 +56,9 @@ static bool handleKeyPressCommands(WebPage* page, KeyboardEvent* event)
     if (!currentEvent || !currentEvent->isFiltered())
         return false;
 
+    if (event->type() != eventNames().keypressEvent)
+        return true;
+
     Vector<OwnPtr<KeyPressCommand> > commands;
     page->swapKeyPressCommands(commands);
 
@@ -67,6 +70,11 @@ static bool handleKeyPressCommands(WebPage* page, KeyboardEvent* event)
         switch (commands[i]->type) {
         case KeyPressCommandSetComposition: {
             const SetCompositionKeyPressCommand* command = reinterpret_cast<const SetCompositionKeyPressCommand*>(commands[i].get());
+            if (i + 1 < size) {
+                int nextType = commands[i + 1]->type;
+                if (nextType == KeyPressCommandSetComposition || nextType == KeyPressCommandConfirmComposition)
+                    break;
+            }
             page->setComposition(command->compositionString, command->underlines, command->cursorPosition);
             break;
         }
@@ -94,7 +102,7 @@ static bool handleKeyPressCommands(WebPage* page, KeyboardEvent* event)
 void WebEditorClient::handleKeyboardEvent(KeyboardEvent* event)
 {
 #if ENABLE(TIZEN_ISF_PORT)
-    if (event->type() == eventNames().keypressEvent && handleKeyPressCommands(m_page, event))
+    if (handleKeyPressCommands(m_page, event))
         return;
 #endif
 
index 56a46ec..a9a42e9 100755 (executable)
@@ -290,10 +290,12 @@ void WebPage::confirmComposition(const String& compositionString)
     if (!targetFrame)
         return;
 
+#if ENABLE(TIZEN_ISF_PORT)
     if (m_prepareKeyDownEvent) {
         m_keyPressCommands.append(adoptPtr(new ConfirmCompositionKeyPressCommand(compositionString)));
         return;
     }
+#endif
 
     targetFrame->editor()->confirmComposition(compositionString);
 
@@ -308,12 +310,15 @@ void WebPage::setComposition(const String& compositionString, const Vector<WebCo
     if (!targetFrame)
         return;
 
+#if ENABLE(TIZEN_ISF_PORT)
+    if (!targetFrame->editor()->hasComposition() && compositionString.isEmpty())
+        return;
+
     if (m_prepareKeyDownEvent) {
         m_keyPressCommands.append(adoptPtr(new SetCompositionKeyPressCommand(compositionString, underlines, cursorPosition)));
         return;
     }
 
-#if ENABLE(TIZEN_ISF_PORT)
     if (targetFrame->selection()->rootEditableElement()) {
         HTMLTextFormControlElement* textFormControl = toTextFormControl(targetFrame->selection()->rootEditableElement()->shadowAncestorNode());
         if (textFormControl && textFormControl->maxLength() >= 0) {