Title: [86707] trunk
Revision
86707
Author
[email protected]
Date
2011-05-17 14:33:23 -0700 (Tue, 17 May 2011)

Log Message

2011-05-17  Erik Arvidsson  <[email protected]>

        Reviewed by Ryosuke Niwa.

        document.activeElement doesn't point to the focused frame
        https://bugs.webkit.org/show_bug.cgi?id=49509

        This tests that an iframe is the activeElement when focus is inside that frame.

        * fast/dom/HTMLDocument/active-element-frames-expected.txt: Added.
        * fast/dom/HTMLDocument/active-element-frames.html: Added.
2011-05-17  Erik Arvidsson  <[email protected]>

        Reviewed by Ryosuke Niwa.

        document.activeElement doesn't point to the focused frame
        https://bugs.webkit.org/show_bug.cgi?id=49509

        This makes us match IE and Firefox and there is an ongoing WHATWG discussion to make the spec match this.

        Test: fast/dom/HTMLDocument/active-element-frames.html

        * html/HTMLDocument.cpp:
        (WebCore::HTMLDocument::activeElement): Walk up the frame tree from the focusedFrame to find the active frame if any.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (86706 => 86707)


--- trunk/LayoutTests/ChangeLog	2011-05-17 20:57:56 UTC (rev 86706)
+++ trunk/LayoutTests/ChangeLog	2011-05-17 21:33:23 UTC (rev 86707)
@@ -1,3 +1,15 @@
+2011-05-17  Erik Arvidsson  <[email protected]>
+
+        Reviewed by Ryosuke Niwa.
+
+        document.activeElement doesn't point to the focused frame
+        https://bugs.webkit.org/show_bug.cgi?id=49509
+
+        This tests that an iframe is the activeElement when focus is inside that frame.
+
+        * fast/dom/HTMLDocument/active-element-frames-expected.txt: Added.
+        * fast/dom/HTMLDocument/active-element-frames.html: Added.
+
 2011-05-16  Robert Hogan  <[email protected]>
 
         Reviewed by Kenneth Rohde Christiansen.

Added: trunk/LayoutTests/fast/dom/HTMLDocument/active-element-frames-expected.txt (0 => 86707)


--- trunk/LayoutTests/fast/dom/HTMLDocument/active-element-frames-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/HTMLDocument/active-element-frames-expected.txt	2011-05-17 21:33:23 UTC (rev 86707)
@@ -0,0 +1,38 @@
+When the contents of an iframe have focus, the activeElement in the parent document should be the iframe element.
+
+  
+Focusing top/input-0
+PASS: top document.activeElement is top/input-0
+PASS: top/iframe-1 document.activeElement is top/iframe-1/body-1
+PASS: top/iframe-2 document.activeElement is top/iframe-2/body-2
+PASS: top/iframe-1/iframe-3 document.activeElement is top/iframe-1/iframe-3/body-3
+PASS: top/iframe-2/iframe-4 document.activeElement is top/iframe-2/iframe-4/body-4
+
+Focusing top/iframe-1/input-1
+PASS: top document.activeElement is top/iframe-1
+PASS: top/iframe-1 document.activeElement is top/iframe-1/input-1
+PASS: top/iframe-2 document.activeElement is top/iframe-2/body-2
+PASS: top/iframe-1/iframe-3 document.activeElement is top/iframe-1/iframe-3/body-3
+PASS: top/iframe-2/iframe-4 document.activeElement is top/iframe-2/iframe-4/body-4
+
+Focusing top/iframe-2/input-2
+PASS: top document.activeElement is top/iframe-2
+PASS: top/iframe-1 document.activeElement is top/iframe-1/body-1
+PASS: top/iframe-2 document.activeElement is top/iframe-2/input-2
+PASS: top/iframe-1/iframe-3 document.activeElement is top/iframe-1/iframe-3/body-3
+PASS: top/iframe-2/iframe-4 document.activeElement is top/iframe-2/iframe-4/body-4
+
+Focusing top/iframe-1/iframe-3/input-3
+PASS: top document.activeElement is top/iframe-1
+PASS: top/iframe-1 document.activeElement is top/iframe-1/iframe-3
+PASS: top/iframe-2 document.activeElement is top/iframe-2/body-2
+PASS: top/iframe-1/iframe-3 document.activeElement is top/iframe-1/iframe-3/input-3
+PASS: top/iframe-2/iframe-4 document.activeElement is top/iframe-2/iframe-4/body-4
+
+Focusing top/iframe-2/iframe-4/input-4
+PASS: top document.activeElement is top/iframe-2
+PASS: top/iframe-1 document.activeElement is top/iframe-1/body-1
+PASS: top/iframe-2 document.activeElement is top/iframe-2/iframe-4
+PASS: top/iframe-1/iframe-3 document.activeElement is top/iframe-1/iframe-3/body-3
+PASS: top/iframe-2/iframe-4 document.activeElement is top/iframe-2/iframe-4/input-4
+
Property changes on: trunk/LayoutTests/fast/dom/HTMLDocument/active-element-frames-expected.txt
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/fast/dom/HTMLDocument/active-element-frames.html (0 => 86707)


--- trunk/LayoutTests/fast/dom/HTMLDocument/active-element-frames.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/HTMLDocument/active-element-frames.html	2011-05-17 21:33:23 UTC (rev 86707)
@@ -0,0 +1,103 @@
+<!DOCTYPE html>
+<body>
+<p>When the contents of an iframe have focus, the activeElement in the parent document should be the iframe element.</p>
+<input id="input-0">
+<iframe id="frame-1"></iframe>
+<iframe id="frame-2"></iframe>
+<pre id="out"></pre>
+<script>
+
+var doc0 = document;
+var input0 = doc0.getElementById('input-0');
+
+var iframe1 = doc0.getElementById('frame-1');
+var doc1 = iframe1.contentDocument;
+var input1 = doc1.body.appendChild(doc1.createElement('input'));
+
+var iframe2 = doc0.getElementById('frame-2');
+var doc2 = iframe2.contentDocument;
+var input2 = doc2.body.appendChild(doc2.createElement('input'));
+
+var iframe3 = doc1.body.appendChild(doc1.createElement('iframe'));
+var doc3 = iframe3.contentDocument;
+var input3 = doc3.body.appendChild(doc3.createElement('input'));
+
+var iframe4 = doc2.body.appendChild(doc2.createElement('iframe'));
+var doc4 = iframe4.contentDocument;
+var input4 = doc4.body.appendChild(doc4.createElement('input'));
+
+// Set up IDs for logging.
+for (var i = 0; i < 5; i++) {
+    window['doc' + i].body.id = 'body-' + i;
+    if (i > 0)
+        window['iframe' + i].id = 'iframe-' + i;
+    window['input' + i].id = 'input-' + i;
+}
+
+function describe(obj)
+{
+    if (obj === document)
+        return 'top';
+    if (obj.defaultView && obj.defaultView.frameElement)
+        return describe(obj.defaultView.frameElement);
+    return describe(obj.ownerDocument) + '/' + obj.id;
+}
+
+function print(s)
+{
+    document.getElementById('out').textContent += s + '\n';
+}
+
+function assertActiveElement(doc, expected)
+{
+    if (doc.activeElement === expected)
+        print('PASS: ' + describe(doc) + ' document.activeElement is ' + describe(doc.activeElement));
+    else
+        print('FAIL: ' + describe(doc) + ' document.activeElement is ' + describe(doc.activeElement) + ' but expected ' + describe(expected));
+}
+
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+print('Focusing ' + describe(input0));
+input0.focus();
+assertActiveElement(doc0, input0);
+assertActiveElement(doc1, doc1.body);
+assertActiveElement(doc2, doc2.body);
+assertActiveElement(doc3, doc3.body);
+assertActiveElement(doc4, doc4.body);
+
+print('\nFocusing ' + describe(input1));
+input1.focus();
+assertActiveElement(doc0, iframe1);
+assertActiveElement(doc1, input1);
+assertActiveElement(doc2, doc2.body);
+assertActiveElement(doc3, doc3.body);
+assertActiveElement(doc4, doc4.body);
+
+print('\nFocusing ' + describe(input2));
+input2.focus();
+assertActiveElement(doc0, iframe2);
+assertActiveElement(doc1, doc1.body);
+assertActiveElement(doc2, input2);
+assertActiveElement(doc3, doc3.body);
+assertActiveElement(doc4, doc4.body);
+
+print('\nFocusing ' + describe(input3));
+input3.focus();
+assertActiveElement(doc0, iframe1);
+assertActiveElement(doc1, iframe3);
+assertActiveElement(doc2, doc2.body);
+assertActiveElement(doc3, input3);
+assertActiveElement(doc4, doc4.body);
+
+print('\nFocusing ' + describe(input4));
+input4.focus();
+assertActiveElement(doc0, iframe2);
+assertActiveElement(doc1, doc1.body);
+assertActiveElement(doc2, iframe4);
+assertActiveElement(doc3, doc3.body);
+assertActiveElement(doc4, input4);
+
+</script>
+</body>
Property changes on: trunk/LayoutTests/fast/dom/HTMLDocument/active-element-frames.html
___________________________________________________________________

Added: svn:mime-type

Modified: trunk/Source/WebCore/ChangeLog (86706 => 86707)


--- trunk/Source/WebCore/ChangeLog	2011-05-17 20:57:56 UTC (rev 86706)
+++ trunk/Source/WebCore/ChangeLog	2011-05-17 21:33:23 UTC (rev 86707)
@@ -1,3 +1,17 @@
+2011-05-17  Erik Arvidsson  <[email protected]>
+
+        Reviewed by Ryosuke Niwa.
+
+        document.activeElement doesn't point to the focused frame
+        https://bugs.webkit.org/show_bug.cgi?id=49509
+
+        This makes us match IE and Firefox and there is an ongoing WHATWG discussion to make the spec match this.
+
+        Test: fast/dom/HTMLDocument/active-element-frames.html
+
+        * html/HTMLDocument.cpp:
+        (WebCore::HTMLDocument::activeElement): Walk up the frame tree from the focusedFrame to find the active frame if any.
+
 2011-05-17  Emil A Eklund  <[email protected]>
 
         Reviewed by Eric Seidel.

Modified: trunk/Source/WebCore/html/HTMLDocument.cpp (86706 => 86707)


--- trunk/Source/WebCore/html/HTMLDocument.cpp	2011-05-17 20:57:56 UTC (rev 86706)
+++ trunk/Source/WebCore/html/HTMLDocument.cpp	2011-05-17 21:33:23 UTC (rev 86707)
@@ -68,6 +68,7 @@
 #include "HTMLDocumentParser.h"
 #include "HTMLBodyElement.h"
 #include "HTMLElementFactory.h"
+#include "HTMLFrameOwnerElement.h"
 #include "HTMLNames.h"
 #include "InspectorInstrumentation.h"
 #include "KURL.h"
@@ -137,9 +138,15 @@
 
 Element* HTMLDocument::activeElement()
 {
-    if (Node* node = focusedNode())
+    if (Node* node = focusedNode()) {
         if (node->isElementNode())
             return static_cast<Element*>(node);
+    } else if (Page* page = this->page()) {
+        for (Frame* focusedFrame = page->focusController()->focusedFrame(); focusedFrame; focusedFrame = focusedFrame->tree()->parent()) {
+            if (focusedFrame->tree()->parent() == frame())
+                return focusedFrame->ownerElement();
+        }
+    }
     return body();
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to