Title: [113667] trunk
Revision
113667
Author
[email protected]
Date
2012-04-09 20:05:24 -0700 (Mon, 09 Apr 2012)

Log Message

ShadowRoot should have selection attribute.
https://bugs.webkit.org/show_bug.cgi?id=82429

Reviewed by Hajime Morita.

Source/WebCore:

This patch makes ShadowRoot have selection attribute. Currently the selection returns
the same object as what window.getSelection() returns.

We will extend DOMSelection to have TreeScope. It will adjust Node into TreeScope.
This will be tracked in Bug 82698.

Test: fast/dom/shadow/selection-in-shadow.html

* dom/ShadowRoot.cpp:
(WebCore::ShadowRoot::selection):
(WebCore):
* dom/ShadowRoot.h:
(WebCore):
(ShadowRoot):
* dom/ShadowRoot.idl:

LayoutTests:

Checks ShadowRoot.selection returns the same selection as what window.getSelection() returns.

* fast/dom/shadow/selection-in-shadow.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (113666 => 113667)


--- trunk/LayoutTests/ChangeLog	2012-04-10 03:02:40 UTC (rev 113666)
+++ trunk/LayoutTests/ChangeLog	2012-04-10 03:05:24 UTC (rev 113667)
@@ -1,3 +1,14 @@
+2012-04-09  Shinya Kawanaka  <[email protected]>
+
+        ShadowRoot should have selection attribute.
+        https://bugs.webkit.org/show_bug.cgi?id=82429
+
+        Reviewed by Hajime Morita.
+
+        Checks ShadowRoot.selection returns the same selection as what window.getSelection() returns.
+
+        * fast/dom/shadow/selection-in-shadow.html: Added.
+
 2012-04-09  Raphael Kubo da Costa  <[email protected]>
 
         [EFL] Gardening in fast/text/whitespace.

Added: trunk/LayoutTests/fast/dom/shadow/selection-in-shadow.html (0 => 113667)


--- trunk/LayoutTests/fast/dom/shadow/selection-in-shadow.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/shadow/selection-in-shadow.html	2012-04-10 03:05:24 UTC (rev 113667)
@@ -0,0 +1,78 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+</head>
+<body>
+
+<div id="container"></div>
+
+<script>
+function moveTo(element) {
+    var x = element.offsetLeft + element.offsetWidth / 2;
+    var y = element.offsetTop + element.offsetHeight / 2;
+    eventSender.mouseMoveTo(x, y);
+}
+
+function dragFromTo(elementFrom, elementTo) {
+    moveTo(elementFrom);
+    eventSender.mouseDown();
+    moveTo(elementTo);
+    eventSender.mouseUp();
+}
+
+var container = document.getElementById('container');
+
+var shadowRoot1 = new WebKitShadowRoot(container);
+shadowRoot1.innerHTML =
+    '<div id="div1" title="div1">DIV1</div>' +
+    '<div id="div2" title="div2">DIV2</div>' +
+    '<div id="div3" title="div3">DIV3</div>';
+var div1 = shadowRoot1.getElementById('div1');
+var div2 = shadowRoot1.getElementById('div2');
+var div3 = shadowRoot1.getElementById('div3');
+
+var shadowRoot2 = new WebKitShadowRoot(div2);
+shadowRoot2.innerHTML =
+    '<div id="div4" title="div4">DIV4</div>' +
+    '<div id="div5" title="div5">DIV5</div>' +
+    '<div id="div6" title="div6">DIV6</div>';
+var div4 = shadowRoot2.getElementById('div4');
+var div5 = shadowRoot2.getElementById('div5');
+var div6 = shadowRoot2.getElementById('div6');
+
+var shadowRoot3 = new WebKitShadowRoot(div5);
+shadowRoot3.innerHTML =
+    '<div id="div7" title="div7">DIV7</div>' +
+    '<div id="div8" title="div8">DIV8</div>' +
+    '<div id="div9" title="div9">DIV9</div>';
+var div7 = shadowRoot3.getElementById('div7');
+var div8 = shadowRoot3.getElementById('div8');
+var div9 = shadowRoot3.getElementById('div9');
+
+
+dragFromTo(div4, div6);
+var selectionFromWindow = window.getSelection();
+var selectionFromShadowRoot1 = shadowRoot1.selection;
+var selectionFromShadowRoot2 = shadowRoot2.selection;
+var selectionFromShadowRoot3 = shadowRoot3.selection;
+
+// Since there are these bugs, shadowRoot.selection won't return the correct selection now.
+// Currently it is the same as window.getSelection().
+// FIXME: VisibleSelection in ShadowRoot is not intuitive.
+// http://wkb.ug/82683
+// FIXME: ShadowRoot.selection should return selection whose range is in a shadow tree.
+// http://wkb.ug/82698
+
+shouldBe('selectionFromWindow.anchorNode', 'selectionFromShadowRoot1.anchorNode');
+shouldBe('selectionFromWindow.anchorNode', 'selectionFromShadowRoot2.anchorNode');
+shouldBe('selectionFromWindow.anchorNode', 'selectionFromShadowRoot3.anchorNode');
+
+shouldBe('selectionFromWindow.focusNode', 'selectionFromShadowRoot1.focusNode');
+shouldBe('selectionFromWindow.focusNode', 'selectionFromShadowRoot2.focusNode');
+shouldBe('selectionFromWindow.focusNode', 'selectionFromShadowRoot3.focusNode');
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (113666 => 113667)


--- trunk/Source/WebCore/ChangeLog	2012-04-10 03:02:40 UTC (rev 113666)
+++ trunk/Source/WebCore/ChangeLog	2012-04-10 03:05:24 UTC (rev 113667)
@@ -1,3 +1,26 @@
+2012-04-09  Shinya Kawanaka  <[email protected]>
+
+        ShadowRoot should have selection attribute.
+        https://bugs.webkit.org/show_bug.cgi?id=82429
+
+        Reviewed by Hajime Morita.
+
+        This patch makes ShadowRoot have selection attribute. Currently the selection returns
+        the same object as what window.getSelection() returns.
+
+        We will extend DOMSelection to have TreeScope. It will adjust Node into TreeScope.
+        This will be tracked in Bug 82698.
+
+        Test: fast/dom/shadow/selection-in-shadow.html
+
+        * dom/ShadowRoot.cpp:
+        (WebCore::ShadowRoot::selection):
+        (WebCore):
+        * dom/ShadowRoot.h:
+        (WebCore):
+        (ShadowRoot):
+        * dom/ShadowRoot.idl:
+
 2012-04-09  Emil A Eklund  <[email protected]>
 
         Replace numeric_limits<LayoutUnit>::min/max with constants

Modified: trunk/Source/WebCore/dom/ShadowRoot.cpp (113666 => 113667)


--- trunk/Source/WebCore/dom/ShadowRoot.cpp	2012-04-10 03:02:40 UTC (rev 113666)
+++ trunk/Source/WebCore/dom/ShadowRoot.cpp	2012-04-10 03:05:24 UTC (rev 113667)
@@ -28,6 +28,8 @@
 #include "ShadowRoot.h"
 
 #include "CSSStyleSelector.h"
+#include "DOMSelection.h"
+#include "DOMWindow.h"
 #include "Document.h"
 #include "DocumentFragment.h"
 #include "Element.h"
@@ -147,6 +149,13 @@
         replaceChildrenWithFragment(this, fragment.release(), ec);
 }
 
+DOMSelection* ShadowRoot::selection()
+{
+    if (document() && document()->domWindow())
+        return document()->domWindow()->getSelection();
+    return 0;
+}
+
 bool ShadowRoot::childTypeAllowed(NodeType type) const
 {
     switch (type) {

Modified: trunk/Source/WebCore/dom/ShadowRoot.h (113666 => 113667)


--- trunk/Source/WebCore/dom/ShadowRoot.h	2012-04-10 03:02:40 UTC (rev 113666)
+++ trunk/Source/WebCore/dom/ShadowRoot.h	2012-04-10 03:05:24 UTC (rev 113667)
@@ -37,6 +37,7 @@
 namespace WebCore {
 
 class Document;
+class DOMSelection;
 class HTMLContentElement;
 class HTMLContentSelector;
 class InsertionPoint;
@@ -77,6 +78,8 @@
 
     Element* activeElement() const;
 
+    DOMSelection* selection();
+
     ShadowRoot* youngerShadowRoot() const { return prev(); }
     ShadowRoot* olderShadowRoot() const { return next(); }
 

Modified: trunk/Source/WebCore/dom/ShadowRoot.idl (113666 => 113667)


--- trunk/Source/WebCore/dom/ShadowRoot.idl	2012-04-10 03:02:40 UTC (rev 113666)
+++ trunk/Source/WebCore/dom/ShadowRoot.idl	2012-04-10 03:05:24 UTC (rev 113667)
@@ -34,6 +34,7 @@
     ] ShadowRoot : DocumentFragment {
         readonly attribute Element host;
         readonly attribute Element activeElement;
+        readonly attribute DOMSelection selection;
 
         attribute [TreatNullAs=NullString] DOMString innerHTML
             setter raises(DOMException);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to