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

Side by Side Diff: third_party/WebKit/Source/core/events/MouseRelatedEvent.cpp

Issue 2158793002: Use the outermost SVG as base when computing offsetX/Y for SVG elements (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2001 Peter Kelly (pmk@post.com) 2 * Copyright (C) 2001 Peter Kelly (pmk@post.com)
3 * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de) 3 * Copyright (C) 2001 Tobias Anton (anton@stud.fbi.fh-darmstadt.de)
4 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com) 4 * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
5 * Copyright (C) 2003, 2005, 2006, 2008 Apple Inc. All rights reserved. 5 * Copyright (C) 2003, 2005, 2006, 2008 Apple Inc. All rights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 { 125 {
126 float scaleFactor = pageZoomFactor(this); 126 float scaleFactor = pageZoomFactor(this);
127 setAbsoluteLocation(roundedLayoutPoint(FloatPoint(pageX() * scaleFactor, pag eY() * scaleFactor))); 127 setAbsoluteLocation(roundedLayoutPoint(FloatPoint(pageX() * scaleFactor, pag eY() * scaleFactor)));
128 } 128 }
129 129
130 void MouseRelatedEvent::receivedTarget() 130 void MouseRelatedEvent::receivedTarget()
131 { 131 {
132 m_hasCachedRelativePosition = false; 132 m_hasCachedRelativePosition = false;
133 } 133 }
134 134
135 static const LayoutObject* findTargetLayoutObject(Node*& targetNode)
136 {
137 LayoutObject* layoutObject = targetNode->layoutObject();
138 if (!layoutObject || !layoutObject->isSVG())
139 return layoutObject;
140 // If this is an SVG node, compute the offset to the padding box of the
141 // outermost SVG root (== the closest ancestor that has a CSS layout box.)
142 while (!layoutObject->isSVGRoot())
143 layoutObject = layoutObject->parent();
144 // Update the target node to point to the SVG root.
145 targetNode = layoutObject->node();
146 DCHECK(!targetNode
147 || (targetNode->isSVGElement() && toSVGElement(*targetNode).isOutermostS VGSVGElement()));
148 return layoutObject;
149 }
150
135 void MouseRelatedEvent::computeRelativePosition() 151 void MouseRelatedEvent::computeRelativePosition()
136 { 152 {
137 Node* targetNode = target() ? target()->toNode() : nullptr; 153 Node* targetNode = target() ? target()->toNode() : nullptr;
138 if (!targetNode) 154 if (!targetNode)
139 return; 155 return;
140 156
141 // Compute coordinates that are based on the target. 157 // Compute coordinates that are based on the target.
142 m_layerLocation = m_pageLocation; 158 m_layerLocation = m_pageLocation;
143 m_offsetLocation = m_pageLocation; 159 m_offsetLocation = m_pageLocation;
144 160
145 // Must have an updated layout tree for this math to work correctly. 161 // Must have an updated layout tree for this math to work correctly.
146 targetNode->document().updateStyleAndLayoutIgnorePendingStylesheets(); 162 targetNode->document().updateStyleAndLayoutIgnorePendingStylesheets();
147 163
148 // Adjust offsetLocation to be relative to the target's padding box. 164 // Adjust offsetLocation to be relative to the target's padding box.
149 if (LayoutObject* r = targetNode->layoutObject()) { 165 if (const LayoutObject* layoutObject = findTargetLayoutObject(targetNode)) {
150 FloatPoint localPos = r->absoluteToLocal(FloatPoint(absoluteLocation()), UseTransforms); 166 FloatPoint localPos = layoutObject->absoluteToLocal(FloatPoint(absoluteL ocation()), UseTransforms);
151 167
152 // Adding this here to address crbug.com/570666. Basically we'd like to 168 // Adding this here to address crbug.com/570666. Basically we'd like to
153 // find the local coordinates relative to the padding box not the border box. 169 // find the local coordinates relative to the padding box not the border box.
154 if (r->isBoxModelObject()) { 170 if (layoutObject->isBoxModelObject()) {
155 LayoutBoxModelObject* layoutBox = toLayoutBoxModelObject(r); 171 const LayoutBoxModelObject* layoutBox = toLayoutBoxModelObject(layou tObject);
156 localPos.move(-layoutBox->borderLeft(), -layoutBox->borderTop()); 172 localPos.move(-layoutBox->borderLeft(), -layoutBox->borderTop());
157 } 173 }
158 174
159 m_offsetLocation = roundedLayoutPoint(localPos); 175 m_offsetLocation = roundedLayoutPoint(localPos);
160 float scaleFactor = 1 / pageZoomFactor(this); 176 float scaleFactor = 1 / pageZoomFactor(this);
161 if (scaleFactor != 1.0f) 177 if (scaleFactor != 1.0f)
162 m_offsetLocation.scale(scaleFactor, scaleFactor); 178 m_offsetLocation.scale(scaleFactor, scaleFactor);
163 } 179 }
164 180
165 // Adjust layerLocation to be relative to the layer. 181 // Adjust layerLocation to be relative to the layer.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 // See Microsoft documentation and <http://www.quirksmode.org/dom/w3c_events .html>. 250 // See Microsoft documentation and <http://www.quirksmode.org/dom/w3c_events .html>.
235 return m_clientLocation.y(); 251 return m_clientLocation.y();
236 } 252 }
237 253
238 DEFINE_TRACE(MouseRelatedEvent) 254 DEFINE_TRACE(MouseRelatedEvent)
239 { 255 {
240 UIEventWithKeyState::trace(visitor); 256 UIEventWithKeyState::trace(visitor);
241 } 257 }
242 258
243 } // namespace blink 259 } // namespace blink
OLDNEW
« 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