Title: [138379] trunk
Revision
138379
Author
[email protected]
Date
2012-12-21 08:01:59 -0800 (Fri, 21 Dec 2012)

Log Message

Implement ShadowRoot::elementFromPoint
https://bugs.webkit.org/show_bug.cgi?id=104579

Reviewed by Dimitri Glazkov.

Source/WebCore:

Move elementFromPoint and nodeFromPoint to TreeScope from Document so that ShadowRoot can call it.
In the elementFromPoint(), the element taken by nodeFromPoint is not in the same tree scope, its ancestor is returned.

Since nodeFromPoint does not return the shadow ancestor of the result node, I don't make it TreeScope method.

Test: fast/dom/shadow/elementfrompoint.html

* dom/Document.cpp:
(WebCore::Document::elementFromPoint): Code is shared with TreeScope.
(WebCore::Document::caretRangeFromPoint):
* dom/ShadowRoot.idl:
* dom/TreeScope.cpp:
(WebCore::nodeFromPoint): Moved from Document.cpp
(WebCore):
(WebCore::TreeScope::elementFromPoint):
* dom/TreeScope.h:
(WebCore):
(TreeScope):

LayoutTests:

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

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (138378 => 138379)


--- trunk/LayoutTests/ChangeLog	2012-12-21 15:55:43 UTC (rev 138378)
+++ trunk/LayoutTests/ChangeLog	2012-12-21 16:01:59 UTC (rev 138379)
@@ -1,3 +1,13 @@
+2012-12-21  Shinya Kawanaka  <[email protected]>
+
+        Implement ShadowRoot::elementFromPoint
+        https://bugs.webkit.org/show_bug.cgi?id=104579
+
+        Reviewed by Dimitri Glazkov.
+
+        * fast/dom/shadow/elementfrompoint-expected.txt: Added.
+        * fast/dom/shadow/elementfrompoint.html: Added.
+
 2012-12-21  Ilya Tikhonovsky  <[email protected]>
 
         Unreviewed. Add Crash test expectation to the media/track/ tests which have explicit expectations.

Added: trunk/LayoutTests/fast/dom/shadow/elementfrompoint-expected.txt (0 => 138379)


--- trunk/LayoutTests/fast/dom/shadow/elementfrompoint-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/shadow/elementfrompoint-expected.txt	2012-12-21 16:01:59 UTC (rev 138379)
@@ -0,0 +1,8 @@
+PASS shadowRoot.elementFromPoint(x12, y12) is box12
+PASS nestedShadowRoot.elementFromPoint(x22, y22) is box22
+PASS shadowRoot.elementFromPoint(x22, y22) is nestedHost
+PASS document.elementFromPoint(x22, y22) is host
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/shadow/elementfrompoint.html (0 => 138379)


--- trunk/LayoutTests/fast/dom/shadow/elementfrompoint.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/shadow/elementfrompoint.html	2012-12-21 16:01:59 UTC (rev 138379)
@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+<script src=""
+<script src=""
+</head>
+<body>
+
+<div id="host"></div>
+<pre id="console"></pre>
+
+<script>
+function createBox() {
+    var div = document.createElement('div');
+    div.style.width = '100px';
+    div.style.height = '100px';
+    return div;
+}
+
+var shadowRoot = host.webkitCreateShadowRoot();
+var box11 = createBox();
+var box12 = createBox();
+var box13 = createBox();
+shadowRoot.appendChild(box11);
+shadowRoot.appendChild(box12);
+shadowRoot.appendChild(box13);
+
+var nestedHost = document.createElement('div');
+var nestedShadowRoot = nestedHost.webkitCreateShadowRoot();
+var box21 = createBox();
+var box22 = createBox();
+var box23 = createBox();
+nestedShadowRoot.appendChild(box21);
+nestedShadowRoot.appendChild(box22);
+nestedShadowRoot.appendChild(box23);
+
+shadowRoot.appendChild(nestedHost);
+
+var x12 = box12.offsetLeft + box12.offsetWidth / 2;
+var y12 = box12.offsetTop + box12.offsetHeight / 2;
+var x22 = box22.offsetLeft + box22.offsetWidth / 2;
+var y22 = box22.offsetTop + box22.offsetHeight / 2;
+
+shouldBe('shadowRoot.elementFromPoint(x12, y12)', 'box12');
+shouldBe('nestedShadowRoot.elementFromPoint(x22, y22)', 'box22');
+
+shouldBe('shadowRoot.elementFromPoint(x22, y22)', 'nestedHost');
+shouldBe('document.elementFromPoint(x22, y22)', 'host');
+</script>
+
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (138378 => 138379)


--- trunk/Source/WebCore/ChangeLog	2012-12-21 15:55:43 UTC (rev 138378)
+++ trunk/Source/WebCore/ChangeLog	2012-12-21 16:01:59 UTC (rev 138379)
@@ -1,3 +1,29 @@
+2012-12-21  Shinya Kawanaka  <[email protected]>
+
+        Implement ShadowRoot::elementFromPoint
+        https://bugs.webkit.org/show_bug.cgi?id=104579
+
+        Reviewed by Dimitri Glazkov.
+
+        Move elementFromPoint and nodeFromPoint to TreeScope from Document so that ShadowRoot can call it.
+        In the elementFromPoint(), the element taken by nodeFromPoint is not in the same tree scope, its ancestor is returned.
+
+        Since nodeFromPoint does not return the shadow ancestor of the result node, I don't make it TreeScope method.
+
+        Test: fast/dom/shadow/elementfrompoint.html
+
+        * dom/Document.cpp:
+        (WebCore::Document::elementFromPoint): Code is shared with TreeScope.
+        (WebCore::Document::caretRangeFromPoint):
+        * dom/ShadowRoot.idl:
+        * dom/TreeScope.cpp:
+        (WebCore::nodeFromPoint): Moved from Document.cpp
+        (WebCore):
+        (WebCore::TreeScope::elementFromPoint):
+        * dom/TreeScope.h:
+        (WebCore):
+        (TreeScope):
+
 2012-12-21  Kenneth Rohde Christiansen  <[email protected]>
 
         [EFL][WK2] Never create WebCore scrollbars for EFL/WK2

Modified: trunk/Source/WebCore/dom/Document.cpp (138378 => 138379)


--- trunk/Source/WebCore/dom/Document.cpp	2012-12-21 15:55:43 UTC (rev 138378)
+++ trunk/Source/WebCore/dom/Document.cpp	2012-12-21 16:01:59 UTC (rev 138379)
@@ -1418,40 +1418,12 @@
     return StaticHashSetNodeList::adopt(list);
 }
 
-static Node* nodeFromPoint(Frame* frame, RenderView* renderView, int x, int y, LayoutPoint* localPoint = 0)
-{
-    if (!frame)
-        return 0;
-    FrameView* frameView = frame->view();
-    if (!frameView)
-        return 0;
-
-    float scaleFactor = frame->pageZoomFactor() * frame->frameScaleFactor();
-    IntPoint point = roundedIntPoint(FloatPoint(x * scaleFactor  + frameView->scrollX(), y * scaleFactor + frameView->scrollY()));
-
-    if (!frameView->visibleContentRect().contains(point))
-        return 0;
-
-    HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active);
-    HitTestResult result(point);
-    renderView->hitTest(request, result);
-
-    if (localPoint)
-        *localPoint = result.localPoint();
-
-    return result.innerNode();
-}
-
 Element* Document::elementFromPoint(int x, int y) const
 {
     if (!renderer())
         return 0;
-    Node* node = nodeFromPoint(frame(), renderView(), x, y);
-    while (node && !node->isElementNode())
-        node = node->parentNode();
-    if (node)
-        node = ancestorInThisScope(node);
-    return static_cast<Element*>(node);
+
+    return TreeScope::elementFromPoint(x, y);
 }
 
 PassRefPtr<Range> Document::caretRangeFromPoint(int x, int y)
@@ -1459,7 +1431,7 @@
     if (!renderer())
         return 0;
     LayoutPoint localPoint;
-    Node* node = nodeFromPoint(frame(), renderView(), x, y, &localPoint);
+    Node* node = nodeFromPoint(this, x, y, &localPoint);
     if (!node)
         return 0;
 

Modified: trunk/Source/WebCore/dom/ShadowRoot.idl (138378 => 138379)


--- trunk/Source/WebCore/dom/ShadowRoot.idl	2012-12-21 15:55:43 UTC (rev 138378)
+++ trunk/Source/WebCore/dom/ShadowRoot.idl	2012-12-21 16:01:59 UTC (rev 138379)
@@ -44,4 +44,7 @@
     NodeList getElementsByTagName(in [Optional=DefaultIsUndefined] DOMString tagName);
     NodeList getElementsByTagNameNS(in [TreatNullAs=NullString,Optional=DefaultIsUndefined] DOMString namespaceURI,
                                     in [Optional=DefaultIsUndefined] DOMString localName);
+
+    Element elementFromPoint(in [Optional=DefaultIsUndefined] long x, 
+                             in [Optional=DefaultIsUndefined] long y);
 };

Modified: trunk/Source/WebCore/dom/TreeScope.cpp (138378 => 138379)


--- trunk/Source/WebCore/dom/TreeScope.cpp	2012-12-21 15:55:43 UTC (rev 138378)
+++ trunk/Source/WebCore/dom/TreeScope.cpp	2012-12-21 16:01:59 UTC (rev 138379)
@@ -35,15 +35,18 @@
 #include "Element.h"
 #include "FocusController.h"
 #include "Frame.h"
+#include "FrameView.h"
 #include "HTMLAnchorElement.h"
 #include "HTMLFrameOwnerElement.h"
 #include "HTMLLabelElement.h"
 #include "HTMLMapElement.h"
 #include "HTMLNames.h"
+#include "HitTestResult.h"
 #include "IdTargetObserverRegistry.h"
 #include "InsertionPoint.h"
 #include "NodeTraversal.h"
 #include "Page.h"
+#include "RenderView.h"
 #include "RuntimeEnabledFeatures.h"
 #include "ShadowRoot.h"
 #include "TreeScopeAdopter.h"
@@ -167,6 +170,42 @@
     return static_cast<HTMLMapElement*>(m_imageMapsByName->getElementByMapName(AtomicString(name).impl(), this));
 }
 
+Node* nodeFromPoint(Document* document, int x, int y, LayoutPoint* localPoint)
+{
+    Frame* frame = document->frame();
+
+    if (!frame)
+        return 0;
+    FrameView* frameView = frame->view();
+    if (!frameView)
+        return 0;
+
+    float scaleFactor = frame->pageZoomFactor() * frame->frameScaleFactor();
+    IntPoint point = roundedIntPoint(FloatPoint(x * scaleFactor  + frameView->scrollX(), y * scaleFactor + frameView->scrollY()));
+
+    if (!frameView->visibleContentRect().contains(point))
+        return 0;
+
+    HitTestRequest request(HitTestRequest::ReadOnly | HitTestRequest::Active);
+    HitTestResult result(point);
+    document->renderView()->hitTest(request, result);
+
+    if (localPoint)
+        *localPoint = result.localPoint();
+
+    return result.innerNode();
+}
+
+Element* TreeScope::elementFromPoint(int x, int y) const
+{
+    Node* node = nodeFromPoint(rootNode()->document(), x, y);
+    while (node && !node->isElementNode())
+        node = node->parentNode();
+    if (node)
+        node = ancestorInThisScope(node);
+    return toElement(node);
+}
+
 void TreeScope::addLabel(const AtomicString& forAttributeValue, HTMLLabelElement* element)
 {
     ASSERT(m_labelsByForAttribute);

Modified: trunk/Source/WebCore/dom/TreeScope.h (138378 => 138379)


--- trunk/Source/WebCore/dom/TreeScope.h	2012-12-21 15:55:43 UTC (rev 138378)
+++ trunk/Source/WebCore/dom/TreeScope.h	2012-12-21 16:01:59 UTC (rev 138379)
@@ -35,9 +35,11 @@
 
 class ContainerNode;
 class DOMSelection;
+class Document;
 class Element;
 class HTMLLabelElement;
 class HTMLMapElement;
+class LayoutPoint;
 class IdTargetObserverRegistry;
 class Node;
 
@@ -64,6 +66,8 @@
     void removeImageMap(HTMLMapElement*);
     HTMLMapElement* getImageMap(const String& url) const;
 
+    Element* elementFromPoint(int x, int y) const;
+
     // For accessibility.
     bool shouldCacheLabelsByForAttribute() const { return m_labelsByForAttribute; }
     void addLabel(const AtomicString& forAttributeValue, HTMLLabelElement*);
@@ -121,6 +125,7 @@
     return m_elementsById && m_elementsById->containsMultiple(id.impl());
 }
 
+Node* nodeFromPoint(Document*, int x, int y, LayoutPoint* localPoint = 0);
 TreeScope* commonTreeScope(Node*, Node*);
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to