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

Side by Side Diff: third_party/WebKit/Source/core/layout/svg/LayoutSVGRoot.cpp

Issue 1541083002: Fix invalid selection produced when dragging mouse outside the SVG text element (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> 2 * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2007, 2008, 2009 Rob Buis <buis@kde.org> 3 * Copyright (C) 2004, 2005, 2007, 2008, 2009 Rob Buis <buis@kde.org>
4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org> 4 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
5 * Copyright (C) 2009 Google, Inc. 5 * Copyright (C) 2009 Google, Inc.
6 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 6 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 10 matching lines...) Expand all
21 * Boston, MA 02110-1301, USA. 21 * Boston, MA 02110-1301, USA.
22 */ 22 */
23 23
24 #include "core/layout/svg/LayoutSVGRoot.h" 24 #include "core/layout/svg/LayoutSVGRoot.h"
25 25
26 #include "core/frame/LocalFrame.h" 26 #include "core/frame/LocalFrame.h"
27 #include "core/layout/HitTestResult.h" 27 #include "core/layout/HitTestResult.h"
28 #include "core/layout/LayoutAnalyzer.h" 28 #include "core/layout/LayoutAnalyzer.h"
29 #include "core/layout/LayoutPart.h" 29 #include "core/layout/LayoutPart.h"
30 #include "core/layout/LayoutView.h" 30 #include "core/layout/LayoutView.h"
31 #include "core/layout/svg/LayoutSVGText.h"
31 #include "core/layout/svg/SVGLayoutSupport.h" 32 #include "core/layout/svg/SVGLayoutSupport.h"
32 #include "core/layout/svg/SVGResourcesCache.h" 33 #include "core/layout/svg/SVGResourcesCache.h"
33 #include "core/paint/PaintLayer.h" 34 #include "core/paint/PaintLayer.h"
34 #include "core/paint/SVGRootPainter.h" 35 #include "core/paint/SVGRootPainter.h"
35 #include "core/svg/SVGElement.h" 36 #include "core/svg/SVGElement.h"
36 #include "core/svg/SVGSVGElement.h" 37 #include "core/svg/SVGSVGElement.h"
37 #include "core/svg/graphics/SVGImage.h" 38 #include "core/svg/graphics/SVGImage.h"
38 #include "platform/LengthFunctions.h" 39 #include "platform/LengthFunctions.h"
39 40
40 namespace blink { 41 namespace blink {
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 LayoutReplaced::insertedIntoTree(); 275 LayoutReplaced::insertedIntoTree();
275 SVGResourcesCache::clientWasAddedToTree(this, styleRef()); 276 SVGResourcesCache::clientWasAddedToTree(this, styleRef());
276 } 277 }
277 278
278 void LayoutSVGRoot::willBeRemovedFromTree() 279 void LayoutSVGRoot::willBeRemovedFromTree()
279 { 280 {
280 SVGResourcesCache::clientWillBeRemovedFromTree(this); 281 SVGResourcesCache::clientWillBeRemovedFromTree(this);
281 LayoutReplaced::willBeRemovedFromTree(); 282 LayoutReplaced::willBeRemovedFromTree();
282 } 283 }
283 284
285 PositionWithAffinity LayoutSVGRoot::positionForPoint(const LayoutPoint& point)
286 {
287 LayoutObject* closestDescendant = nullptr;
fs 2016/01/12 17:40:17 Since this is always LayoutSVGText it could be tha
288 float closestDistance = std::numeric_limits<float>::max();
289 FloatPoint absolutePoint(point);
290 AffineTransform transformToParent;
291 transformToParent.makeIdentity();
fs 2016/01/12 17:40:17 The AffineTransform constructor does this.
fs 2016/01/12 17:40:17 The AffineTransform constructor does this.
292 for (LayoutObject* descendant = firstChild(); descendant; descendant = desce ndant->nextInPreOrder(this)) {
fs 2016/01/12 17:40:17 This will walk the entire SVG fragment. I think we
pdr. 2016/01/12 23:52:47 +1, LayoutBox::positionForPoint is a good starting
293 if (descendant->isSVGText()) {
294 FloatRect boundaries = toLayoutSVGText(descendant)->objectBoundingBo x();
295 FloatPoint closestPoint;
296 AffineTransform transform;
297 transform.makeIdentity();
fs 2016/01/12 17:40:17 Done by the constructor.
298
299 LayoutObject* layoutObject = descendant;
300 while (layoutObject) {
301 layoutObject = layoutObject->parent();
302 if (layoutObject->isSVGRoot())
303 break;
304 transform = layoutObject->localToParentTransform() * transform;
305 }
306 transform = m_localToBorderBoxTransform * transform;
307
308 boundaries = transform.mapRect(boundaries);
fs 2016/01/12 17:40:17 |transform| here does not include any transform fr
309 closestPoint.setX(std::max(std::min(absolutePoint.x(), boundaries.ma xX()), boundaries.x()));
fs 2016/01/12 17:40:17 Could also use clampTo(...) here instead of max(mi
310 closestPoint.setY(std::max(std::min(absolutePoint.y(), boundaries.ma xY()), boundaries.y()));
311 float distance = (absolutePoint - closestPoint).diagonalLengthSquare d();
312
313 if (distance < closestDistance) {
314 closestDistance = distance;
315 closestDescendant = descendant;
316 transformToParent = transform;
317 }
318 }
319 }
320
321 if (!closestDescendant)
322 return createPositionWithAffinity(0);
fs 2016/01/12 17:40:17 There are most likely cases where we should be cal
323
324 AffineTransform transform;
325 transform.makeIdentity();
326 if (toLayoutSVGText(closestDescendant)->location().x())
327 transform.setE(toLayoutSVGText(closestDescendant)->location().x());
328 if (toLayoutSVGText(closestDescendant)->location().y())
329 transform.setF(toLayoutSVGText(closestDescendant)->location().y());
330 transformToParent = transformToParent * closestDescendant->localToParentTran sform() * transform;
fs 2016/01/12 17:40:17 This reinforces the comment above. Also, location(
331
332 absolutePoint = transformToParent.inverse().mapPoint(absolutePoint);
333
334 if (absolutePoint.x() < 0)
fs 2016/01/12 17:40:17 Why?
335 absolutePoint.setX(0);
336 if (absolutePoint.y() < 0)
337 absolutePoint.setY(0);
338
339 return closestDescendant->positionForPoint(LayoutPoint(absolutePoint.x(), ab solutePoint.y()));
340 }
341
284 // LayoutBox methods will expect coordinates w/o any transforms in coordinates 342 // LayoutBox methods will expect coordinates w/o any transforms in coordinates
285 // relative to our borderBox origin. This method gives us exactly that. 343 // relative to our borderBox origin. This method gives us exactly that.
286 void LayoutSVGRoot::buildLocalToBorderBoxTransform() 344 void LayoutSVGRoot::buildLocalToBorderBoxTransform()
287 { 345 {
288 SVGSVGElement* svg = toSVGSVGElement(node()); 346 SVGSVGElement* svg = toSVGSVGElement(node());
289 ASSERT(svg); 347 ASSERT(svg);
290 float scale = style()->effectiveZoom(); 348 float scale = style()->effectiveZoom();
291 FloatPoint translate = svg->currentTranslate(); 349 FloatPoint translate = svg->currentTranslate();
292 LayoutSize borderAndPadding(borderLeft() + paddingLeft(), borderTop() + padd ingTop()); 350 LayoutSize borderAndPadding(borderLeft() + paddingLeft(), borderTop() + padd ingTop());
293 m_localToBorderBoxTransform = svg->viewBoxToViewTransform(contentWidth() / s cale, contentHeight() / scale); 351 m_localToBorderBoxTransform = svg->viewBoxToViewTransform(contentWidth() / s cale, contentHeight() / scale);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 updateHitTestResult(result, pointInBorderBox); 467 updateHitTestResult(result, pointInBorderBox);
410 if (!result.addNodeToListBasedTestResult(node(), locationInContainer , boundsRect)) 468 if (!result.addNodeToListBasedTestResult(node(), locationInContainer , boundsRect))
411 return true; 469 return true;
412 } 470 }
413 } 471 }
414 472
415 return false; 473 return false;
416 } 474 }
417 475
418 } 476 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698