Title: [110310] trunk
Revision
110310
Author
[email protected]
Date
2012-03-09 11:38:21 -0800 (Fri, 09 Mar 2012)

Log Message

ShadowRoot should implement activeElement.
https://bugs.webkit.org/show_bug.cgi?id=79886

Patch by Kaustubh Atrawalkar <[email protected]> on 2012-03-09
Reviewed by Ryosuke Niwa.

Source/WebCore:

Implement the activeElement attribute for ShadowRoot to return the
currently focused element in the shadow DOM subtree.

Test: fast/dom/shadow/shadow-root-activeElement.html

* dom/ShadowRoot.cpp:
(WebCore::ShadowRoot::activeElement):
(WebCore):
* dom/ShadowRoot.h:
(ShadowRoot):
* dom/ShadowRoot.idl:
* dom/TreeScope.cpp:
(WebCore::TreeScope::adoptIfNeeded):
(WebCore):
(WebCore::focusedFrameOwnerElement):
(WebCore::TreeScope::activeElement):
* dom/TreeScope.h:
(TreeScope):
* html/HTMLDocument.cpp:
(WebCore):
(WebCore::HTMLDocument::activeElement):

LayoutTests:

Added test case for activeElement attribute of ShadowRoot.

* fast/dom/shadow/shadow-root-activeElement-expected.txt: Added.
* fast/dom/shadow/shadow-root-activeElement.html: Added.
* platform/mac/Skipped: Added test case in Skipped as ShadowRoot is supported by Chromium only.
* platform/qt/Skipped: ditto.
* platform/win/Skipped: ditto.
* platform/wincairo/Skipped: ditto.
* platform/wk2/Skipped: ditto.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (110309 => 110310)


--- trunk/LayoutTests/ChangeLog	2012-03-09 19:21:53 UTC (rev 110309)
+++ trunk/LayoutTests/ChangeLog	2012-03-09 19:38:21 UTC (rev 110310)
@@ -1,3 +1,20 @@
+2012-03-09  Kaustubh Atrawalkar  <[email protected]>
+
+        ShadowRoot should implement activeElement.
+        https://bugs.webkit.org/show_bug.cgi?id=79886
+
+        Reviewed by Ryosuke Niwa.
+
+        Added test case for activeElement attribute of ShadowRoot.
+
+        * fast/dom/shadow/shadow-root-activeElement-expected.txt: Added.
+        * fast/dom/shadow/shadow-root-activeElement.html: Added.
+        * platform/mac/Skipped: Added test case in Skipped as ShadowRoot is supported by Chromium only.
+        * platform/qt/Skipped: ditto.
+        * platform/win/Skipped: ditto.
+        * platform/wincairo/Skipped: ditto.
+        * platform/wk2/Skipped: ditto.
+
 2012-03-09  Victor Carbune  <[email protected]>
 
         Added relevant layout tests to verify that the fragment can be appended

Added: trunk/LayoutTests/fast/dom/shadow/shadow-root-activeElement-expected.txt (0 => 110310)


--- trunk/LayoutTests/fast/dom/shadow/shadow-root-activeElement-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/shadow/shadow-root-activeElement-expected.txt	2012-03-09 19:38:21 UTC (rev 110310)
@@ -0,0 +1,18 @@
+This tests the activeElement property of a ShadowRoot.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+
+PASS shadowRoot.activeElement is defined.
+PASS shadowRootInside.activeElement is defined.
+PASS firstChildInTreeOne.focus();shadowRoot.activeElement is firstChildInTreeOne
+PASS secondChildInTreeOne.focus();shadowRoot.activeElement is secondChildInTreeOne
+PASS secondChildInTreeOne.blur();shadowRoot.activeElement is document.body
+PASS firstChildInTreeTwo.focus();shadowRootInside.activeElement is firstChildInTreeTwo
+PASS secondChildInTreeTwo.focus();shadowRootInside.activeElement is secondChildInTreeTwo
+PASS secondChildInTreeTwo.blur();shadowRootInside.activeElement is document.body
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/shadow/shadow-root-activeElement.html (0 => 110310)


--- trunk/LayoutTests/fast/dom/shadow/shadow-root-activeElement.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/shadow/shadow-root-activeElement.html	2012-03-09 19:38:21 UTC (rev 110310)
@@ -0,0 +1,65 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<div id="console">
+</div>
+<script>
+description("This tests the activeElement property of a ShadowRoot.");
+
+if (!window.internals)
+    debug('This test runs on DRT only');
+
+if (window.layoutTestController) {
+    layoutTestController.dumpAsText();
+
+
+// First ShodowHost
+shadowHost = document.createElement("div");
+document.body.appendChild(shadowHost);
+shadowRoot = new WebKitShadowRoot(shadowHost);
+
+// Second ShadowHost
+shadowHostInside = document.createElement("div");
+shadowRoot.appendChild(shadowHostInside);
+shadowRootInside = new WebKitShadowRoot(shadowHostInside);
+
+// Add two children inside first Shadow host
+var firstChildInTreeOne = document.createElement("p");
+firstChildInTreeOne.setAttribute("id", "firstChildInTreeOne");
+firstChildInTreeOne.tabIndex = "1";
+shadowRoot.appendChild(firstChildInTreeOne);
+
+var secondChildInTreeOne = document.createElement("p");
+secondChildInTreeOne.setAttribute("id", "secondChildInTreeOne");
+secondChildInTreeOne.tabIndex = "2";
+shadowRoot.appendChild(secondChildInTreeOne);
+
+// Add two children inside second shadow host
+var firstChildInTreeTwo = document.createElement("p");
+firstChildInTreeTwo.setAttribute("id", "firstChildInTreeTwo");
+firstChildInTreeTwo.tabIndex = "3";
+shadowRootInside.appendChild(firstChildInTreeTwo);
+
+var secondChildInTreeTwo = document.createElement("p");
+secondChildInTreeTwo.setAttribute("id", "secondChildInTreeTwo");
+secondChildInTreeTwo.tabIndex = "4";
+shadowRootInside.appendChild(secondChildInTreeTwo);
+
+shouldBeDefined("shadowRoot.activeElement");
+shouldBeDefined("shadowRootInside.activeElement");
+shouldBe("firstChildInTreeOne.focus();shadowRoot.activeElement", "firstChildInTreeOne");
+shouldBe("secondChildInTreeOne.focus();shadowRoot.activeElement", "secondChildInTreeOne");
+shouldBe("secondChildInTreeOne.blur();shadowRoot.activeElement", "document.body");
+shouldBe("firstChildInTreeTwo.focus();shadowRootInside.activeElement", "firstChildInTreeTwo");
+shouldBe("secondChildInTreeTwo.focus();shadowRootInside.activeElement", "secondChildInTreeTwo");
+shouldBe("secondChildInTreeTwo.blur();shadowRootInside.activeElement", "document.body");
+
+}
+var successfullyParsed = true;
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/LayoutTests/platform/mac/Skipped (110309 => 110310)


--- trunk/LayoutTests/platform/mac/Skipped	2012-03-09 19:21:53 UTC (rev 110309)
+++ trunk/LayoutTests/platform/mac/Skipped	2012-03-09 19:38:21 UTC (rev 110310)
@@ -431,6 +431,7 @@
 fast/dom/shadow/content-element-outside-shadow-style.html
 fast/dom/shadow/shadow-root-js-api.html
 fast/dom/shadow/shadow-disable.html
+fast/dom/shadow/shadow-root-activeElement.html
 fast/dom/shadow/shadow-root-attached.html
 fast/dom/shadow/shadow-root-innerHTML.html
 fast/dom/shadow/shadow-root-new.html

Modified: trunk/LayoutTests/platform/qt/Skipped (110309 => 110310)


--- trunk/LayoutTests/platform/qt/Skipped	2012-03-09 19:21:53 UTC (rev 110309)
+++ trunk/LayoutTests/platform/qt/Skipped	2012-03-09 19:38:21 UTC (rev 110310)
@@ -170,6 +170,7 @@
 fast/dom/shadow/shadow-root-js-api.html
 fast/dom/shadow/shadow-disable.html
 fast/dom/shadow/shadow-on-image.html
+fast/dom/shadow/shadow-root-activeElement.html
 fast/dom/shadow/shadow-root-attached.html
 fast/dom/shadow/shadow-root-innerHTML.html
 fast/dom/shadow/shadow-root-new.html

Modified: trunk/LayoutTests/platform/win/Skipped (110309 => 110310)


--- trunk/LayoutTests/platform/win/Skipped	2012-03-09 19:21:53 UTC (rev 110309)
+++ trunk/LayoutTests/platform/win/Skipped	2012-03-09 19:38:21 UTC (rev 110310)
@@ -1457,6 +1457,7 @@
 fast/dom/shadow/content-element-outside-shadow-style.html
 fast/dom/shadow/shadow-root-js-api.html
 fast/dom/shadow/shadow-disable.html
+fast/dom/shadow/shadow-root-activeElement.html
 fast/dom/shadow/shadow-root-attached.html
 fast/dom/shadow/shadow-root-innerHTML.html
 fast/dom/shadow/shadow-root-new.html

Modified: trunk/LayoutTests/platform/wincairo/Skipped (110309 => 110310)


--- trunk/LayoutTests/platform/wincairo/Skipped	2012-03-09 19:21:53 UTC (rev 110309)
+++ trunk/LayoutTests/platform/wincairo/Skipped	2012-03-09 19:38:21 UTC (rev 110310)
@@ -1971,6 +1971,7 @@
 fast/dom/shadow/content-element-outside-shadow.html
 fast/dom/shadow/shadow-root-js-api.html
 fast/dom/shadow/shadow-disable.html
+fast/dom/shadow/shadow-root-activeElement.html
 fast/dom/shadow/shadow-root-attached.html
 fast/dom/shadow/shadow-root-innerHTML.html
 fast/dom/shadow/shadow-root-new.html

Modified: trunk/LayoutTests/platform/wk2/Skipped (110309 => 110310)


--- trunk/LayoutTests/platform/wk2/Skipped	2012-03-09 19:21:53 UTC (rev 110309)
+++ trunk/LayoutTests/platform/wk2/Skipped	2012-03-09 19:38:21 UTC (rev 110310)
@@ -1068,6 +1068,7 @@
 fast/dom/shadow/content-element-outside-shadow-style.html
 fast/dom/shadow/shadow-root-js-api.html
 fast/dom/shadow/shadow-disable.html
+fast/dom/shadow/shadow-root-activeElement.html
 fast/dom/shadow/shadow-root-attached.html
 fast/dom/shadow/shadow-root-innerHTML.html
 fast/dom/shadow/shadow-root-new.html

Modified: trunk/Source/WebCore/ChangeLog (110309 => 110310)


--- trunk/Source/WebCore/ChangeLog	2012-03-09 19:21:53 UTC (rev 110309)
+++ trunk/Source/WebCore/ChangeLog	2012-03-09 19:38:21 UTC (rev 110310)
@@ -1,3 +1,32 @@
+2012-03-09  Kaustubh Atrawalkar  <[email protected]>
+
+        ShadowRoot should implement activeElement.
+        https://bugs.webkit.org/show_bug.cgi?id=79886
+
+        Reviewed by Ryosuke Niwa.
+
+        Implement the activeElement attribute for ShadowRoot to return the
+        currently focused element in the shadow DOM subtree.
+
+        Test: fast/dom/shadow/shadow-root-activeElement.html
+
+        * dom/ShadowRoot.cpp:
+        (WebCore::ShadowRoot::activeElement):
+        (WebCore):
+        * dom/ShadowRoot.h:
+        (ShadowRoot):
+        * dom/ShadowRoot.idl:
+        * dom/TreeScope.cpp:
+        (WebCore::TreeScope::adoptIfNeeded):
+        (WebCore):
+        (WebCore::focusedFrameOwnerElement):
+        (WebCore::TreeScope::activeElement):
+        * dom/TreeScope.h:
+        (TreeScope):
+        * html/HTMLDocument.cpp:
+        (WebCore):
+        (WebCore::HTMLDocument::activeElement):
+
 2012-03-09  Tim Horton  <[email protected]>
 
         Infinite repaint loop with SVGImageCache and deferred repaint timers

Modified: trunk/Source/WebCore/dom/ShadowRoot.h (110309 => 110310)


--- trunk/Source/WebCore/dom/ShadowRoot.h	2012-03-09 19:21:53 UTC (rev 110309)
+++ trunk/Source/WebCore/dom/ShadowRoot.h	2012-03-09 19:38:21 UTC (rev 110310)
@@ -27,6 +27,7 @@
 #ifndef ShadowRoot_h
 #define ShadowRoot_h
 
+#include "Document.h"
 #include "DocumentFragment.h"
 #include "ExceptionCode.h"
 #include "TreeScope.h"
@@ -73,6 +74,8 @@
     String innerHTML() const;
     void setInnerHTML(const String&, ExceptionCode&);
 
+    Element* activeElement() const;
+
     ShadowRoot* youngerShadowRoot() const { return prev(); }
     ShadowRoot* olderShadowRoot() const { return next(); }
 
@@ -117,6 +120,13 @@
     return isYoungest() || assignedTo();
 }
 
+inline Element* ShadowRoot::activeElement() const
+{
+    if (document()->isHTMLDocument())
+        return treeScope()->activeElement();
+    return 0;
+}
+
 inline const ShadowRoot* toShadowRoot(const Node* node)
 {
     ASSERT(!node || node->isShadowRoot());

Modified: trunk/Source/WebCore/dom/ShadowRoot.idl (110309 => 110310)


--- trunk/Source/WebCore/dom/ShadowRoot.idl	2012-03-09 19:21:53 UTC (rev 110309)
+++ trunk/Source/WebCore/dom/ShadowRoot.idl	2012-03-09 19:38:21 UTC (rev 110310)
@@ -33,6 +33,7 @@
         ConstructorRaisesException
     ] ShadowRoot : DocumentFragment {
         readonly attribute Element host;
+        readonly attribute Element activeElement;
 
         attribute [TreatNullAs=NullString] DOMString innerHTML
             setter raises(DOMException);

Modified: trunk/Source/WebCore/dom/TreeScope.cpp (110309 => 110310)


--- trunk/Source/WebCore/dom/TreeScope.cpp	2012-03-09 19:21:53 UTC (rev 110309)
+++ trunk/Source/WebCore/dom/TreeScope.cpp	2012-03-09 19:38:21 UTC (rev 110310)
@@ -29,9 +29,13 @@
 #include "ContainerNode.h"
 #include "Document.h"
 #include "Element.h"
+#include "FocusController.h"
+#include "Frame.h"
 #include "HTMLAnchorElement.h"
+#include "HTMLFrameOwnerElement.h"
 #include "HTMLMapElement.h"
 #include "HTMLNames.h"
+#include "Page.h"
 #include "TreeScopeAdopter.h"
 #include <wtf/text/AtomicString.h>
 #include <wtf/text/CString.h>
@@ -151,5 +155,36 @@
         adopter.execute();
 }
 
+static Node* focusedFrameOwnerElement(Frame* focusedFrame, Frame* currentFrame)
+{
+    for (; focusedFrame; focusedFrame = focusedFrame->tree()->parent()) {
+        if (focusedFrame->tree()->parent() == currentFrame)
+            return focusedFrame->ownerElement();
+    }
+    return 0;
+}
+
+Element* TreeScope::activeElement()
+{
+    Document* document = rootNode()->document();
+    Node* node = document->focusedNode();
+    if (!node && document->page())
+        node = focusedFrameOwnerElement(document->page()->focusController()->focusedFrame(), document->frame());
+    if (!node)
+        return document->body();
+
+    ASSERT(node->document() == this);
+    TreeScope* treeScope = node->treeScope();
+
+    while (treeScope != this && treeScope != document) {
+        node = treeScope->rootNode()->shadowHost();
+        treeScope = node->treeScope();
+    }
+
+    if (node->isElementNode())
+        return toElement(node);
+    return 0;
+}
+
 } // namespace WebCore
 

Modified: trunk/Source/WebCore/dom/TreeScope.h (110309 => 110310)


--- trunk/Source/WebCore/dom/TreeScope.h	2012-03-09 19:21:53 UTC (rev 110309)
+++ trunk/Source/WebCore/dom/TreeScope.h	2012-03-09 19:38:21 UTC (rev 110310)
@@ -47,6 +47,7 @@
     TreeScope* parentTreeScope() const { return m_parentTreeScope; }
     void setParentTreeScope(TreeScope*);
 
+    Element* activeElement();
     Element* getElementById(const AtomicString&) const;
     bool hasElementWithId(AtomicStringImpl* id) const;
     bool containsMultipleElementsWithId(const AtomicString& id) const;

Modified: trunk/Source/WebCore/html/HTMLDocument.cpp (110309 => 110310)


--- trunk/Source/WebCore/html/HTMLDocument.cpp	2012-03-09 19:21:53 UTC (rev 110309)
+++ trunk/Source/WebCore/html/HTMLDocument.cpp	2012-03-09 19:38:21 UTC (rev 110310)
@@ -136,30 +136,9 @@
     Document::setDesignMode(mode);
 }
 
-static Node* focusedFrameOwnerElement(Frame* focusedFrame, Frame* currentFrame)
-{
-    for (; focusedFrame; focusedFrame = focusedFrame->tree()->parent()) {
-        if (focusedFrame->tree()->parent() == currentFrame)
-            return focusedFrame->ownerElement();
-    }
-    return 0;
-}
-
 Element* HTMLDocument::activeElement()
 {
-    Node* node = focusedNode();
-    if (!node && page())
-        node = focusedFrameOwnerElement(page()->focusController()->focusedFrame(), frame());
-    if (!node)
-        return body();
-    ASSERT(node->document() == this);
-    while (node->treeScope() != this) {
-        node = node->parentOrHostNode();
-        ASSERT(node);
-    }
-    if (node->isElementNode())
-        return toElement(node);
-    return body();
+    return treeScope()->activeElement();
 }
 
 bool HTMLDocument::hasFocus()
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to