Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(740)

Unified Diff: third_party/WebKit/Source/core/events/MouseRelatedEvent.cpp

Issue 2124283002: Use the outermost SVG as base when computing offsetX/Y for SVG elements (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/events/offsetX-offsetY-svg.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/events/MouseRelatedEvent.cpp
diff --git a/third_party/WebKit/Source/core/events/MouseRelatedEvent.cpp b/third_party/WebKit/Source/core/events/MouseRelatedEvent.cpp
index 1fdb6af7ccde04e444c48f450b542e6aa2cc20b3..8f0ff4f641ba5ac09afa471e3a31b380f3835e83 100644
--- a/third_party/WebKit/Source/core/events/MouseRelatedEvent.cpp
+++ b/third_party/WebKit/Source/core/events/MouseRelatedEvent.cpp
@@ -132,6 +132,22 @@ void MouseRelatedEvent::receivedTarget()
m_hasCachedRelativePosition = false;
}
+static const LayoutObject* findTargetLayoutObject(Node*& targetNode)
+{
+ LayoutObject* layoutObject = targetNode->layoutObject();
+ if (!layoutObject || !layoutObject->isSVG())
+ return layoutObject;
+ // If this is an SVG node, compute the offset to the padding box of the
+ // outermost SVG root (== the closest ancestor that has a CSS layout box.)
+ while (!layoutObject->isSVGRoot())
+ layoutObject = layoutObject->parent();
+ // Update the target node to point to the SVG root.
+ targetNode = layoutObject->node();
+ DCHECK(!targetNode
+ || (targetNode->isSVGElement() && toSVGElement(*targetNode).isOutermostSVGSVGElement()));
+ return layoutObject;
+}
+
void MouseRelatedEvent::computeRelativePosition()
{
Node* targetNode = target() ? target()->toNode() : nullptr;
@@ -146,13 +162,13 @@ void MouseRelatedEvent::computeRelativePosition()
targetNode->document().updateStyleAndLayoutIgnorePendingStylesheets();
// Adjust offsetLocation to be relative to the target's padding box.
- if (LayoutObject* r = targetNode->layoutObject()) {
- FloatPoint localPos = r->absoluteToLocal(FloatPoint(absoluteLocation()), UseTransforms);
+ if (const LayoutObject* layoutObject = findTargetLayoutObject(targetNode)) {
+ FloatPoint localPos = layoutObject->absoluteToLocal(FloatPoint(absoluteLocation()), UseTransforms);
// Adding this here to address crbug.com/570666. Basically we'd like to
// find the local coordinates relative to the padding box not the border box.
- if (r->isBoxModelObject()) {
- LayoutBoxModelObject* layoutBox = toLayoutBoxModelObject(r);
+ if (layoutObject->isBoxModelObject()) {
+ const LayoutBoxModelObject* layoutBox = toLayoutBoxModelObject(layoutObject);
localPos.move(-layoutBox->borderLeft(), -layoutBox->borderTop());
}
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/events/offsetX-offsetY-svg.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698