Bug 17670: Key events may improperly propagate from iframe to parent frame
authoroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 23 Mar 2008 10:48:18 +0000 (10:48 +0000)
committeroliver@apple.com <oliver@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 23 Mar 2008 10:48:18 +0000 (10:48 +0000)
Bug 16381: REGRESSION: Shift, command, option, ctrl keys in Gmail Rich Text changes focus

Reviewed by Maciej

Prevent the Cocoa event system from propagating key events to the parent WebHTMLView,
as that results in us dispatching the key events for each frame going up the frame
tree.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@31236 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/events/key-events-in-frame-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/key-events-in-frame.html [new file with mode: 0644]
WebKit/mac/ChangeLog
WebKit/mac/WebView/WebHTMLView.mm

index 793ca6c..d803844 100644 (file)
@@ -1,3 +1,12 @@
+2008-03-23  Oliver Hunt  <oliver@apple.com>
+
+        Reviewed by Maciej.
+
+        Test to ensure key events don't propagate up the frame tree.
+
+        * fast/events/key-events-in-frame-expected.txt: Added.
+        * fast/events/key-events-in-frame.html: Added.
+
 2008-03-22  Eric Seidel  <eric@webkit.org>
 
         Update a (passing) result I missed in my last checkin.  No review.
diff --git a/LayoutTests/fast/events/key-events-in-frame-expected.txt b/LayoutTests/fast/events/key-events-in-frame-expected.txt
new file mode 100644 (file)
index 0000000..e1999ea
--- /dev/null
@@ -0,0 +1,3 @@
+This tests that key events targeting a frame do not propagate up the frame tree. This will only produce output if the test fails. 
+To test manually click in the empty frame and press any key. If you receive any output the test has failed.
+
diff --git a/LayoutTests/fast/events/key-events-in-frame.html b/LayoutTests/fast/events/key-events-in-frame.html
new file mode 100644 (file)
index 0000000..3acd8bb
--- /dev/null
@@ -0,0 +1,17 @@
+<div>
+    This tests that key events targeting a frame do not propagate up the frame tree.  This will only produce output if the test fails.
+    <br />
+    To test manually click in the empty frame and press any key. If you receive any output the test has failed.
+</div>
+<pre id="log"></pre>
+<iframe id="targetFrame" src="data:text/html,"></iframe>
+<script>
+onkeydown=function(){document.getElementById("log").innerHTML += 'FAIL: outerFrame received keydown\n'; };
+onkeypress=function(){document.getElementById("log").innerHTML += 'FAIL: outerFrame received keypress\n'; };
+onkeyup=function(){document.getElementById("log").innerHTML += 'FAIL: outerFrame received keyup\n'; };
+document.getElementById("targetFrame").focus();
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+    eventSender.keyDown("a");
+}
+</script>
index 4560770..50f2a05 100644 (file)
@@ -1,3 +1,21 @@
+2008-03-23  Oliver Hunt  <oliver@apple.com>
+
+        Reviewed by Maciej.
+
+        Bug 17670: Key events may improperly propagate from iframe to parent frame
+        <http://bugs.webkit.org/show_bug.cgi?id=17670>
+        Bug 16381: REGRESSION: Shift, command, option, ctrl keys in Gmail Rich Text changes focus
+        <http://bugs.webkit.org/show_bug.cgi?id=16381>
+
+        Prevent the Cocoa event system from propagating key events to the parent WebHTMLView,
+        as that results in us dispatching the key events for each frame going up the frame
+        tree.
+
+        * WebView/WebHTMLView.mm:
+        (-[WebHTMLView keyDown:]):
+        (-[WebHTMLView keyUp:]):
+        (-[WebHTMLView flagsChanged:]):
+
 2008-03-21  Timothy Hatcher  <timothy@apple.com>
 
         Bug 17980: Regression: Inspector highlighting of webpage not cleared when going to new URL
index 02a2a6e..6b6f5f6 100644 (file)
@@ -3533,7 +3533,8 @@ noPromisedData:
 
     BOOL completionPopupWasOpen = _private->compController && [_private->compController popupWindowIsOpen];
     Frame* coreFrame = core([self _frame]);
-    if (!eventWasSentToWebCore && coreFrame && coreFrame->eventHandler()->keyEvent(event)) {
+    if (!eventWasSentToWebCore && coreFrame) {
+        coreFrame->eventHandler()->keyEvent(event);
         // WebCore processed a key event, bail on any preexisting complete: UI
         if (completionPopupWasOpen)
             [_private->compController endRevertingChange:YES moveLeft:NO];
@@ -3552,11 +3553,12 @@ noPromisedData:
 {
     BOOL eventWasSentToWebCore = (_private->keyDownEvent == event);
 
-    [self retain];
+    RetainPtr<WebHTMLView> selfProtector = self;
     Frame* coreFrame = core([self _frame]);
-    if (eventWasSentToWebCore || !coreFrame || !coreFrame->eventHandler()->keyEvent(event))
-        [super keyUp:event];    
-    [self release];
+    if (coreFrame && !eventWasSentToWebCore)
+        coreFrame->eventHandler()->keyEvent(event);
+    else
+        [super keyUp:event];
 }
 
 - (void)flagsChanged:(NSEvent *)event
@@ -3568,9 +3570,12 @@ noPromisedData:
     RetainPtr<WebHTMLView> selfProtector = self;
 
     unsigned short keyCode = [event keyCode];
+
     //Don't make an event from the num lock and function keys
-    if (coreFrame && keyCode != 0 && keyCode != 10 && keyCode != 63)
+    if (coreFrame && keyCode != 0 && keyCode != 10 && keyCode != 63) {
         coreFrame->eventHandler()->keyEvent(PlatformKeyboardEvent(event));
+        return;
+    }
         
     [super flagsChanged:event];
 }