Bug 501496 part.4 Don't dispatch keypress events if defaultPrevent() of the keydown event is called on Qt r=smaug+romaxa
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 25 Jul 2013 15:09:28 +0900
changeset 152201 bd7f9080d3904dcb5501275671f4995b34a7dbd2
parent 152200 48788ac2e02f29d8b0e39dcdb8c95ac30e8b7657
child 152202 0ab0b048dbad5ccdaf800f6527d4eae2ea03405b
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs501496
milestone25.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 501496 part.4 Don't dispatch keypress events if defaultPrevent() of the keydown event is called on Qt r=smaug+romaxa
widget/qt/nsWindow.cpp
--- a/widget/qt/nsWindow.cpp
+++ b/widget/qt/nsWindow.cpp
@@ -1518,18 +1518,16 @@ nsWindow::DispatchContentCommandEvent(in
 nsEventStatus
 nsWindow::OnKeyPressEvent(QKeyEvent *aEvent)
 {
     LOGFOCUS(("OnKeyPressEvent [%p]\n", (void *)this));
 
     // The user has done something.
     UserActivity();
 
-    bool setNoDefault = false;
-
     if (aEvent->key() == Qt::Key_AltGr) {
         sAltGrModifier = true;
     }
 
 #ifdef MOZ_X11
     // before we dispatch a key, check if it's the context menu key.
     // If so, send a context menu key event instead.
     if (isContextMenuKeyEvent(aEvent)) {
@@ -1628,35 +1626,34 @@ nsWindow::OnKeyPressEvent(QKeyEvent *aEv
         nsEventStatus status = DispatchEvent(&downEvent);
 
         // DispatchEvent can Destroy us (bug 378273)
         if (MOZ_UNLIKELY(mIsDestroyed)) {
             qWarning() << "Returning[" << __LINE__ << "]: " << "Window destroyed";
             return status;
         }
 
-        // If prevent default on keydown, do same for keypress
-        if (status == nsEventStatus_eConsumeNoDefault)
-            setNoDefault = true;
+        // If prevent default on keydown, don't dispatch keypress event
+        if (status == nsEventStatus_eConsumeNoDefault) {
+            return nsEventStatus_eConsumeNoDefault;
+        }
     }
 
     // Don't pass modifiers as NS_KEY_PRESS events.
     // Instead of selectively excluding some keys from NS_KEY_PRESS events,
     // we instead selectively include (as per MSDN spec
     // ( http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress%28VS.71%29.aspx );
     // no official spec covers KeyPress events).
     if (aEvent->key() == Qt::Key_Shift   ||
         aEvent->key() == Qt::Key_Control ||
         aEvent->key() == Qt::Key_Meta    ||
         aEvent->key() == Qt::Key_Alt     ||
         aEvent->key() == Qt::Key_AltGr) {
 
-        return setNoDefault ?
-            nsEventStatus_eConsumeNoDefault :
-            nsEventStatus_eIgnore;
+        return nsEventStatus_eIgnore;
     }
 
     // Look for specialized app-command keys
     switch (aEvent->key()) {
         case Qt::Key_Back:
             return DispatchCommandEvent(nsGkAtoms::Back);
         case Qt::Key_Forward:
             return DispatchCommandEvent(nsGkAtoms::Forward);
@@ -1690,21 +1687,16 @@ nsWindow::OnKeyPressEvent(QKeyEvent *aEv
     }
     if (aEvent->nativeVirtualKey() == 0xff65) {
         return DispatchContentCommandEvent(NS_CONTENT_COMMAND_UNDO);
     }
 
     nsKeyEvent event(true, NS_KEY_PRESS, this);
     InitKeyEvent(event, aEvent);
 
-    // If prevent default on keydown, do same for keypress
-    if (setNoDefault) {
-        event.mFlags.mDefaultPrevented = true;
-    }
-
     // If there is no charcode attainable from the text, try to
     // generate it from the keycode. Check shift state for case
     // Also replace the charcode if ControlModifier is the only
     // pressed Modifier
     if ((!domCharCode) &&
         (QApplication::keyboardModifiers() &
         (Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier))) {
 
@@ -1870,32 +1862,30 @@ nsWindow::OnKeyPressEvent(QKeyEvent *aEv
         nsKeyEvent downEvent(true, NS_KEY_DOWN, this);
         InitKeyEvent(downEvent, aEvent);
 
         downEvent.keyCode = domKeyCode;
         downEvent.mKeyNameIndex = keyNameIndex;
 
         nsEventStatus status = DispatchEvent(&downEvent);
 
-        // If prevent default on keydown, do same for keypress
-        if (status == nsEventStatus_eConsumeNoDefault)
-            setNoDefault = true;
+        // If prevent default on keydown, don't dispatch keypress event
+        if (status == nsEventStatus_eConsumeNoDefault) {
+            return nsEventStatus_eConsumeNoDefault;
+        }
     }
 
     nsKeyEvent event(true, NS_KEY_PRESS, this);
     InitKeyEvent(event, aEvent);
 
     event.charCode = domCharCode;
 
     event.keyCode = domCharCode ? 0 : domKeyCode;
     event.mKeyNameIndex = keyNameIndex;
 
-    if (setNoDefault)
-        event.mFlags.mDefaultPrevented = true;
-
     // send the key press event
     return DispatchEvent(&event);
 #endif
 }
 
 nsEventStatus
 nsWindow::OnKeyReleaseEvent(QKeyEvent *aEvent)
 {