Do not insert text if default action was prevented.
authorSangYong Park <sy302.park@samsung.com>
Wed, 26 Jun 2013 10:48:32 +0000 (19:48 +0900)
committerGerrit Code Review <gerrit@gerrit.vlan144.tizendev.org>
Thu, 27 Jun 2013 06:12:51 +0000 (06:12 +0000)
[Title] Do not insert text if default action was prevented.
[Issue#] N_SE-42125
[Problem] Text was inserted, even though default action was prevent.
[Cause] Do not prevent when insert text by ime.
[Solution] Add prevent code for inserting text by ime.

Change-Id: I7347d005e02196f7d5935eeed6f1ac6d5f2ff1f0

Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/efl/InputMethodContextEfl.cpp
Source/WebKit2/UIProcess/efl/WebPageProxyEfl.cpp
Source/WebKit2/WebProcess/WebCoreSupport/efl/WebEditorClientEfl.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h [changed mode: 0644->0755]
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in [changed mode: 0644->0755]
Source/WebKit2/WebProcess/WebPage/efl/WebPageEfl.cpp [changed mode: 0644->0755]

index 4f0db4a..451c527 100755 (executable)
@@ -954,6 +954,7 @@ public:
 #endif
 
 #if ENABLE(TIZEN_ISF_PORT)
+    void prepareKeyDownEvent();
     int getCursorOffset();
     void getSurroundingTextAndCursorOffset(String&, int&);
     WebCore::IntRect getSelectionRect(bool);
index 871ae66..e5db346 100755 (executable)
@@ -324,6 +324,8 @@ void InputMethodContextEfl::handleKeyDownEvent(const Evas_Event_Key_Down* downEv
 #if ENABLE(TIZEN_ISF_PORT)
     if (!m_context)
         return;
+
+    m_viewImpl->page()->prepareKeyDownEvent();
 #endif
 
     Ecore_IMF_Event inputMethodEvent;
index 2db68e0..06e1b17 100755 (executable)
@@ -238,6 +238,14 @@ void WebPageProxy::textChangeInTextField(const String& name, const String& value
 #endif
 
 #if ENABLE(TIZEN_ISF_PORT)
+void WebPageProxy::prepareKeyDownEvent()
+{
+    if (!isValid())
+        return;
+
+    process()->send(Messages::WebPage::PrepareKeyDownEvent(), m_pageID);
+}
+
 int WebPageProxy::getCursorOffset()
 {
     if (!isValid())
index 32f50ce..c14feb7 100755 (executable)
@@ -49,27 +49,72 @@ using namespace WebCore;
 
 namespace WebKit {
 
+#if ENABLE(TIZEN_ISF_PORT)
+static bool handleKeyPressCommands(WebPage* page, KeyboardEvent* event)
+{
+    const NativeWebKeyboardEvent* currentEvent = static_cast<const NativeWebKeyboardEvent*>(WebPage::currentEvent());
+    if (!currentEvent || !currentEvent->isFiltered())
+        return false;
+
+    Vector<OwnPtr<KeyPressCommand> > commands;
+    page->swapKeyPressCommands(commands);
+
+    size_t size = commands.size();
+    if (!size)
+        return true;
+
+    for (size_t i = 0; i < size; ++i) {
+        switch (commands[i]->type) {
+        case KeyPressCommandSetComposition: {
+            const SetCompositionKeyPressCommand* command = reinterpret_cast<const SetCompositionKeyPressCommand*>(commands[i].get());
+            page->setComposition(command->compositionString, command->underlines, command->cursorPosition);
+            break;
+        }
+        case KeyPressCommandConfirmComposition: {
+            const ConfirmCompositionKeyPressCommand* command = reinterpret_cast<const ConfirmCompositionKeyPressCommand*>(commands[i].get());
+            page->confirmComposition(command->compositionString);
+            break;
+        }
+        case KeyPressCommandDeleteText: {
+            const DeleteTextKeyPressCommand* command = reinterpret_cast<const DeleteTextKeyPressCommand*>(commands[i].get());
+            page->deleteSurroundingText(command->offset, command->count);
+            break;
+        }
+        default:
+            break;
+        }
+    }
+
+    event->setDefaultHandled();
+
+    return true;
+}
+#endif
+
 void WebEditorClient::handleKeyboardEvent(KeyboardEvent* event)
 {
+#if ENABLE(TIZEN_ISF_PORT)
+    if (event->type() == eventNames().keypressEvent && handleKeyPressCommands(m_page, event))
+        return;
+#endif
+
     if (m_page->handleEditingKeyboardEvent(event))
         event->setDefaultHandled();
 }
 
 void WebEditorClient::handleInputMethodKeydown(KeyboardEvent* event)
 {
+#if ENABLE(TIZEN_ISF_PORT)
+    return;
+#endif
+
     Frame* frame = m_page->corePage()->focusController()->focusedOrMainFrame();
     if (!frame || !frame->editor()->canEdit())
         return;
 
     // FIXME: sending sync message might make input lagging.
     bool handled = false;
-#if ENABLE(TIZEN_ISF_PORT)
-    const NativeWebKeyboardEvent* currentEvent = static_cast<const NativeWebKeyboardEvent*>(WebPage::currentEvent());
-    ASSERT(currentEvent);
-    handled = currentEvent->isFiltered();
-#else
     m_page->sendSync(Messages::WebPageProxy::HandleInputMethodKeydown(), Messages::WebPageProxy::HandleInputMethodKeydown::Reply(handled));
-#endif
 
     if (handled)
         event->setDefaultHandled();
index a0dcc7a..9a7343e 100755 (executable)
@@ -302,6 +302,9 @@ WebPage::WebPage(uint64_t pageID, const WebPageCreationParameters& parameters)
     , m_suspendedAnimationController(false)
 #endif
     , m_inspectorClient(0)
+#if ENABLE(TIZEN_ISF_PORT)
+    , m_prepareKeyDownEvent(false)
+#endif
 {
     ASSERT(m_pageID);
     // FIXME: This is a non-ideal location for this Setting and
@@ -1799,6 +1802,10 @@ void WebPage::keyEvent(const WebKeyboardEvent& keyboardEvent)
 {
     CurrentEvent currentEvent(keyboardEvent);
 
+#if ENABLE(TIZEN_ISF_PORT)
+    m_prepareKeyDownEvent = false;
+#endif
+
     bool handled = handleKeyEvent(keyboardEvent, m_page.get());
     // FIXME: Platform default behaviors should be performed during normal DOM event dispatch (in most cases, in default keydown event handler).
     if (!handled)
old mode 100644 (file)
new mode 100755 (executable)
index 47d3108..957a49a
@@ -195,6 +195,42 @@ class WebUserMediaClient;
 
 #if ENABLE(TIZEN_ISF_PORT)
 class NativeWebKeyboardEvent;
+
+enum {
+    KeyPressCommandSetComposition,
+    KeyPressCommandConfirmComposition,
+    KeyPressCommandDeleteText
+};
+
+struct KeyPressCommand {
+    KeyPressCommand(int type) : type(type) { }
+
+    int type;
+};
+
+struct SetCompositionKeyPressCommand : public KeyPressCommand {
+    SetCompositionKeyPressCommand(const String& compositionString, const Vector<WebCore::CompositionUnderline>& underlines, uint64_t cursorPosition)
+        : KeyPressCommand(KeyPressCommandSetComposition), compositionString(compositionString), underlines(underlines), cursorPosition(cursorPosition) { }
+
+    String compositionString;
+    Vector<WebCore::CompositionUnderline> underlines;
+    uint64_t cursorPosition;
+};
+
+struct ConfirmCompositionKeyPressCommand : public KeyPressCommand {
+    ConfirmCompositionKeyPressCommand(const String& compositionString)
+        : KeyPressCommand(KeyPressCommandConfirmComposition), compositionString(compositionString) { }
+
+    String compositionString;
+};
+
+struct DeleteTextKeyPressCommand : public KeyPressCommand {
+    DeleteTextKeyPressCommand(int offset, int count)
+        : KeyPressCommand(KeyPressCommandDeleteText), offset(offset), count(count) { }
+
+    int offset;
+    int count;
+};
 #endif
 
 class WebPage : public APIObject, public CoreIPC::MessageSender<WebPage> {
@@ -236,6 +272,9 @@ public:
 #if ENABLE(TIZEN_ISF_PORT)
     void didCancelComposition(WebCore::Node*);
 
+    void prepareKeyDownEvent();
+    void swapKeyPressCommands(Vector<OwnPtr<KeyPressCommand> >&);
+
     void getCursorOffset(int&);
     void getSurroundingTextAndCursorOffset(String&, int&);
     void getSelectionRect(bool, WebCore::IntRect&);
@@ -1146,6 +1185,11 @@ private:
 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
     EditorState m_editorState;
 #endif
+
+#if ENABLE(TIZEN_ISF_PORT)
+    bool m_prepareKeyDownEvent;
+    Vector<OwnPtr<KeyPressCommand> > m_keyPressCommands;
+#endif
 };
 
 #if ENABLE(TIZEN_NATIVE_MEMORY_SNAPSHOT)
old mode 100644 (file)
new mode 100755 (executable)
index c271034..fe713b8
@@ -344,6 +344,7 @@ messages -> WebPage {
     GetCaretPosition() -> (WebCore::IntRect rect)
 #endif
 #if ENABLE(TIZEN_ISF_PORT)
+    PrepareKeyDownEvent()
     GetCursorOffset() -> (int offset)
     GetSurroundingTextAndCursorOffset() -> (String text, int offset)
     GetSelectionRect(bool isOnlyEditable) -> (WebCore::IntRect rect)
old mode 100644 (file)
new mode 100755 (executable)
index 3fdc1ec..2d480de
@@ -290,6 +290,11 @@ void WebPage::confirmComposition(const String& compositionString)
     if (!targetFrame)
         return;
 
+    if (m_prepareKeyDownEvent) {
+        m_keyPressCommands.append(adoptPtr(new ConfirmCompositionKeyPressCommand(compositionString)));
+        return;
+    }
+
     targetFrame->editor()->confirmComposition(compositionString);
 
 #if ENABLE(TIZEN_ISF_PORT)
@@ -303,6 +308,11 @@ void WebPage::setComposition(const String& compositionString, const Vector<WebCo
     if (!targetFrame)
         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());
@@ -661,6 +671,17 @@ void WebPage::didCancelComposition(Node* valueChangedNode)
     send(Messages::WebPageProxy::DidCancelComposition());
 }
 
+void WebPage::prepareKeyDownEvent()
+{
+    m_prepareKeyDownEvent = true;
+    m_keyPressCommands.clear();
+}
+
+void WebPage::swapKeyPressCommands(Vector<OwnPtr<KeyPressCommand> >& commands)
+{
+    m_keyPressCommands.swap(commands);
+}
+
 void WebPage::getCursorOffset(int& offset)
 {
     offset = 0;
@@ -716,6 +737,11 @@ void WebPage::deleteSurroundingText(int offset, int count)
     if (!frame || !frame->editor()->canEdit())
         return;
 
+    if (m_prepareKeyDownEvent) {
+        m_keyPressCommands.append(adoptPtr(new DeleteTextKeyPressCommand(offset, count)));
+        return;
+    }
+
     Position base(frame->selection()->base());
     offset += base.offsetInContainerNode();
     base.moveToOffset(offset);