Title: [111672] trunk
Revision
111672
Author
commit-qu...@webkit.org
Date
2012-03-22 05:38:45 -0700 (Thu, 22 Mar 2012)

Log Message

blur() on shadow host should work when a shadow host contains a focused element in its shadow DOM subtrees
https://bugs.webkit.org/show_bug.cgi?id=81102

Patch by Kaustubh Atrawalkar <kaust...@motorola.com> on 2012-03-22
Reviewed by Hajime Morita.

Source/WebCore:

This implementation will support blur for a focused element when its shadowHost's blur() is called.
To achieve this Element::blur() function is modified to blur the focused node in it's treeScope.

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

* dom/Element.cpp:
(WebCore::Element::blur): Modified to blur current treeScope's focused node.
* dom/ShadowRoot.h:
(WebCore::ShadowRoot::activeElement): Rework for code sharing.
* dom/TreeScope.cpp:
(WebCore::TreeScope::focusedNode): Added new function to share code for getting focused node.
* dom/TreeScope.h:
(TreeScope): New function declartion.
* html/HTMLDocument.cpp:
(WebCore::HTMLDocument::activeElement): Rework for code sharing.

LayoutTests:

* fast/dom/shadow/shadow-root-blur-expected.txt: Added.
* fast/dom/shadow/shadow-root-blur.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (111671 => 111672)


--- trunk/LayoutTests/ChangeLog	2012-03-22 12:28:47 UTC (rev 111671)
+++ trunk/LayoutTests/ChangeLog	2012-03-22 12:38:45 UTC (rev 111672)
@@ -1,3 +1,13 @@
+2012-03-22  Kaustubh Atrawalkar  <kaust...@motorola.com>
+
+        blur() on shadow host should work when a shadow host contains a focused element in its shadow DOM subtrees
+        https://bugs.webkit.org/show_bug.cgi?id=81102
+
+        Reviewed by Hajime Morita.
+
+        * fast/dom/shadow/shadow-root-blur-expected.txt: Added.
+        * fast/dom/shadow/shadow-root-blur.html: Added.
+
 2012-03-22  Vsevolod Vlasov  <vse...@chromium.org>
 
         Web Inspector: RawSourceCode does not need uiSourceCode lists because it never has more than one.

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


--- trunk/LayoutTests/fast/dom/shadow/shadow-root-blur-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/shadow/shadow-root-blur-expected.txt	2012-03-22 12:38:45 UTC (rev 111672)
@@ -0,0 +1,43 @@
+This tests the blur() on on shadow host should work when a shadow host contains a focused element in its shadow DOM subtrees property (bug 81102)
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+
+getNodeInShadowTreeStack('shadowHostA/childInTreeOne').focus()
+PASS document.activeElement.id is "shadowHostA"
+getNodeInShadowTreeStack('shadowHostA').blur();
+shadowHostA onblur called!
+PASS document.activeElement is document.body
+PASS getNodeInShadowTreeStack('shadowHostA/').activeElement is null
+PASS getNodeInShadowTreeStack('shadowHostA/shadowHostB/').activeElement is null
+PASS getNodeInShadowTreeStack('shadowHostC/').activeElement is null
+getNodeInShadowTreeStack('shadowHostA/shadowHostB/childInTreeTwo').focus()
+PASS document.activeElement.id is "shadowHostA"
+getNodeInShadowTreeStack('shadowHostA/shadowHostB').blur();
+shadowHostA onblur called!
+shadowHostB onblur called!
+PASS document.activeElement is document.body
+PASS getNodeInShadowTreeStack('shadowHostA/').activeElement is null
+PASS getNodeInShadowTreeStack('shadowHostA/shadowHostB/').activeElement is null
+PASS getNodeInShadowTreeStack('shadowHostC/').activeElement is null
+getNodeInShadowTreeStack('shadowHostA/shadowHostB/childInTreeTwo').focus()
+PASS document.activeElement.id is "shadowHostA"
+getNodeInShadowTreeStack('shadowHostA').blur();
+shadowHostA onblur called!
+shadowHostB onblur called!
+PASS document.activeElement is document.body
+PASS getNodeInShadowTreeStack('shadowHostA/').activeElement is null
+PASS getNodeInShadowTreeStack('shadowHostA/shadowHostB/').activeElement is null
+PASS getNodeInShadowTreeStack('shadowHostC/').activeElement is null
+getNodeInShadowTreeStack('shadowHostC/childInTreeThree').focus()
+PASS document.activeElement.id is "shadowHostC"
+getNodeInShadowTreeStack('shadowHostA').blur();
+PASS document.activeElement.id is "shadowHostC"
+PASS getNodeInShadowTreeStack('shadowHostA/').activeElement is null
+PASS getNodeInShadowTreeStack('shadowHostA/shadowHostB/').activeElement is null
+PASS getNodeInShadowTreeStack('shadowHostC/').activeElement.id is "childInTreeThree"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

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


--- trunk/LayoutTests/fast/dom/shadow/shadow-root-blur.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/shadow/shadow-root-blur.html	2012-03-22 12:38:45 UTC (rev 111672)
@@ -0,0 +1,76 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+<div id="console">
+</div>
+<script>
+description("This tests the blur() on on shadow host should work when a shadow host contains a focused element in its shadow DOM subtrees property (bug 81102)");
+
+if (!window.internals)
+    debug('This test runs on DRT only');
+
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+
+document.body.appendChild(
+    createDOM('div', {'id':'shadowHostA'},
+        createShadowRoot(
+            createDOM('p', {'id':'childInTreeOne', 'tabindex':'1'}),
+            createDOM('div', {'id':'shadowHostB'},
+                createShadowRoot(
+                    createDOM('p', {'id':'childInTreeTwo', 'tabindex':'2'}))))));
+
+document.body.appendChild(
+    createDOM('div', {'id':'shadowHostC'},
+        createShadowRoot(
+            createDOM('p', {'id':'childInTreeThree', 'tabindex':'3'})))
+);
+
+getNodeInShadowTreeStack('shadowHostA')._onblur_ = function() { debug("shadowHostA onblur called!"); }
+getNodeInShadowTreeStack('shadowHostA/shadowHostB')._onblur_ = function() { debug("shadowHostB onblur called!"); }
+
+// childInTreeOne foucsed - shadowHostA blurred
+evalAndLog("getNodeInShadowTreeStack('shadowHostA/childInTreeOne').focus()");
+shouldBeEqualToString("document.activeElement.id", "shadowHostA");
+evalAndLog("getNodeInShadowTreeStack('shadowHostA').blur();");
+shouldBe("document.activeElement", "document.body");
+shouldBe("getNodeInShadowTreeStack('shadowHostA/').activeElement", "null");
+shouldBe("getNodeInShadowTreeStack('shadowHostA/shadowHostB/').activeElement", "null");
+shouldBe("getNodeInShadowTreeStack('shadowHostC/').activeElement", "null");
+
+// childInTreeTwo foucsed - shadowHostB blurred
+evalAndLog("getNodeInShadowTreeStack('shadowHostA/shadowHostB/childInTreeTwo').focus()");
+shouldBeEqualToString("document.activeElement.id", "shadowHostA");
+evalAndLog("getNodeInShadowTreeStack('shadowHostA/shadowHostB').blur();");
+shouldBe("document.activeElement", "document.body");
+shouldBe("getNodeInShadowTreeStack('shadowHostA/').activeElement", "null");
+shouldBe("getNodeInShadowTreeStack('shadowHostA/shadowHostB/').activeElement", "null");
+shouldBe("getNodeInShadowTreeStack('shadowHostC/').activeElement", "null");
+
+// childInTreeTwo foucsed - shadowHostA blurred
+evalAndLog("getNodeInShadowTreeStack('shadowHostA/shadowHostB/childInTreeTwo').focus()");
+shouldBeEqualToString("document.activeElement.id", "shadowHostA");
+evalAndLog("getNodeInShadowTreeStack('shadowHostA').blur();");
+shouldBe("document.activeElement", "document.body");
+shouldBe("getNodeInShadowTreeStack('shadowHostA/').activeElement", "null");
+shouldBe("getNodeInShadowTreeStack('shadowHostA/shadowHostB/').activeElement", "null");
+shouldBe("getNodeInShadowTreeStack('shadowHostC/').activeElement", "null");
+
+// childInTreeThree foucsed - shadowHostA blurred
+evalAndLog("getNodeInShadowTreeStack('shadowHostC/childInTreeThree').focus()");
+shouldBeEqualToString("document.activeElement.id", "shadowHostC");
+evalAndLog("getNodeInShadowTreeStack('shadowHostA').blur();");
+shouldBeEqualToString("document.activeElement.id", "shadowHostC");
+shouldBe("getNodeInShadowTreeStack('shadowHostA/').activeElement", "null");
+shouldBe("getNodeInShadowTreeStack('shadowHostA/shadowHostB/').activeElement", "null");
+shouldBeEqualToString("getNodeInShadowTreeStack('shadowHostC/').activeElement.id", "childInTreeThree");
+
+var successfullyParsed = true;
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (111671 => 111672)


--- trunk/Source/WebCore/ChangeLog	2012-03-22 12:28:47 UTC (rev 111671)
+++ trunk/Source/WebCore/ChangeLog	2012-03-22 12:38:45 UTC (rev 111672)
@@ -1,3 +1,26 @@
+2012-03-22  Kaustubh Atrawalkar  <kaust...@motorola.com>
+
+        blur() on shadow host should work when a shadow host contains a focused element in its shadow DOM subtrees
+        https://bugs.webkit.org/show_bug.cgi?id=81102
+
+        Reviewed by Hajime Morita.
+
+        This implementation will support blur for a focused element when its shadowHost's blur() is called.
+        To achieve this Element::blur() function is modified to blur the focused node in it's treeScope.
+
+        Test: fast/dom/shadow/shadow-root-blur.html
+
+        * dom/Element.cpp:
+        (WebCore::Element::blur): Modified to blur current treeScope's focused node.
+        * dom/ShadowRoot.h:
+        (WebCore::ShadowRoot::activeElement): Rework for code sharing.
+        * dom/TreeScope.cpp:
+        (WebCore::TreeScope::focusedNode): Added new function to share code for getting focused node.
+        * dom/TreeScope.h:
+        (TreeScope): New function declartion.
+        * html/HTMLDocument.cpp:
+        (WebCore::HTMLDocument::activeElement): Rework for code sharing.
+
 2012-03-22  Vsevolod Vlasov  <vse...@chromium.org>
 
         Web Inspector: RawSourceCode does not need uiSourceCode lists because it never has more than one.

Modified: trunk/Source/WebCore/dom/Element.cpp (111671 => 111672)


--- trunk/Source/WebCore/dom/Element.cpp	2012-03-22 12:28:47 UTC (rev 111671)
+++ trunk/Source/WebCore/dom/Element.cpp	2012-03-22 12:38:45 UTC (rev 111672)
@@ -1592,7 +1592,7 @@
 {
     cancelFocusAppearanceUpdate();
     Document* doc = document();
-    if (doc->focusedNode() == this) {
+    if (treeScope()->focusedNode() == this) {
         if (doc->frame())
             doc->frame()->page()->focusController()->setFocusedNode(0, doc->frame());
         else

Modified: trunk/Source/WebCore/dom/ShadowRoot.h (111671 => 111672)


--- trunk/Source/WebCore/dom/ShadowRoot.h	2012-03-22 12:28:47 UTC (rev 111671)
+++ trunk/Source/WebCore/dom/ShadowRoot.h	2012-03-22 12:38:45 UTC (rev 111672)
@@ -29,6 +29,7 @@
 
 #include "Document.h"
 #include "DocumentFragment.h"
+#include "Element.h"
 #include "ExceptionCode.h"
 #include "TreeScope.h"
 #include <wtf/DoublyLinkedList.h>
@@ -122,8 +123,8 @@
 
 inline Element* ShadowRoot::activeElement() const
 {
-    if (document()->isHTMLDocument())
-        return treeScope()->activeElement();
+    if (Node* node = treeScope()->focusedNode())
+        return node->isElementNode() ? toElement(node) : 0;
     return 0;
 }
 

Modified: trunk/Source/WebCore/dom/TreeScope.cpp (111671 => 111672)


--- trunk/Source/WebCore/dom/TreeScope.cpp	2012-03-22 12:28:47 UTC (rev 111671)
+++ trunk/Source/WebCore/dom/TreeScope.cpp	2012-03-22 12:38:45 UTC (rev 111672)
@@ -164,14 +164,14 @@
     return 0;
 }
 
-Element* TreeScope::activeElement()
+Node* TreeScope::focusedNode()
 {
     Document* document = rootNode()->document();
     Node* node = document->focusedNode();
     if (!node && document->page())
         node = focusedFrameOwnerElement(document->page()->focusController()->focusedFrame(), document->frame());
     if (!node)
-        return this == document ? document->body() : 0;
+        return 0;
 
     TreeScope* treeScope = node->treeScope();
 
@@ -181,9 +181,8 @@
     }
     if (this != treeScope)
         return 0;
-    if (node->isElementNode())
-        return toElement(node);
-    return 0;
+
+    return node;
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/dom/TreeScope.h (111671 => 111672)


--- trunk/Source/WebCore/dom/TreeScope.h	2012-03-22 12:28:47 UTC (rev 111671)
+++ trunk/Source/WebCore/dom/TreeScope.h	2012-03-22 12:38:45 UTC (rev 111672)
@@ -47,7 +47,7 @@
     TreeScope* parentTreeScope() const { return m_parentTreeScope; }
     void setParentTreeScope(TreeScope*);
 
-    Element* activeElement();
+    Node* focusedNode();
     Element* getElementById(const AtomicString&) const;
     bool hasElementWithId(AtomicStringImpl* id) const;
     bool containsMultipleElementsWithId(const AtomicString& id) const;

Modified: trunk/Source/WebCore/html/HTMLDocument.cpp (111671 => 111672)


--- trunk/Source/WebCore/html/HTMLDocument.cpp	2012-03-22 12:28:47 UTC (rev 111671)
+++ trunk/Source/WebCore/html/HTMLDocument.cpp	2012-03-22 12:38:45 UTC (rev 111672)
@@ -138,7 +138,9 @@
 
 Element* HTMLDocument::activeElement()
 {
-    return treeScope()->activeElement();
+    if (Node* node = treeScope()->focusedNode())
+        return node->isElementNode() ? toElement(node) : body();
+    return body();
 }
 
 bool HTMLDocument::hasFocus()
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to