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

Unified Diff: third_party/WebKit/Source/core/layout/svg/SVGLayoutSupport.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/layout/svg/SVGLayoutSupport.h ('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/layout/svg/SVGLayoutSupport.cpp
diff --git a/third_party/WebKit/Source/core/layout/svg/SVGLayoutSupport.cpp b/third_party/WebKit/Source/core/layout/svg/SVGLayoutSupport.cpp
index 32073042bd914cd8999f8fd2c593feade0f70a23..2a9786c55d498747fdc3c80db32de1a7d788475f 100644
--- a/third_party/WebKit/Source/core/layout/svg/SVGLayoutSupport.cpp
+++ b/third_party/WebKit/Source/core/layout/svg/SVGLayoutSupport.cpp
@@ -476,4 +476,61 @@ float SVGLayoutSupport::calculateScreenFontSizeScalingFactor(const LayoutObject*
return narrowPrecisionToFloat(sqrt((pow(ctm.xScale(), 2) + pow(ctm.yScale(), 2)) / 2));
}
+LayoutObject* SVGLayoutSupport::findSelectedLayoutSVGText(LayoutObject* layoutObject, AffineTransform& localToParentTransform, const FloatPoint point)
+{
+ LayoutObject* closestLayoutObject = nullptr;
+ float closestDistance = std::numeric_limits<float>::max();
+ Vector<LayoutObject*> overlappedObjects;
+ for (LayoutObject* child = layoutObject->slowLastChild(); child; child = child->previousSibling()) {
+ if (child->style()->visibility() != VISIBLE)
fs 2016/01/15 10:34:16 This is not correct at this level - 'visibility' c
+ continue;
+
+ if (!child->isSVGContainer() && !child->isSVGText())
fs 2016/01/15 10:34:16 "Hidden containers" still return true for isSVGCon
+ continue;
+
+ FloatRect bound = child->objectBoundingBox();
+ float distance = bound.squaredDistanceTo(child->localToParentTransform().inverse().mapPoint(point));
fs 2016/01/15 10:34:16 Since you're using the inverse transform you shoul
+
+ if (distance < closestDistance) {
+ AffineTransform transform;
+
+ if (closestLayoutObject) {
+ transform = localToParentTransform * closestLayoutObject->localToParentTransform();
fs 2016/01/15 10:34:16 No need to transform by |localToParentTransform| s
+ bound = (localToParentTransform * child->localToParentTransform()).mapRect(bound);
+ }
+
+ if (closestLayoutObject && bound.intersects(transform.mapRect(closestLayoutObject->objectBoundingBox()))) {
fs 2016/01/15 10:34:16 Not quite sure why you'd need to check overlap bet
+ overlappedObjects.append(child);
+ continue;
+ }
+ overlappedObjects.clear();
+
+ closestLayoutObject = child;
+ closestDistance = distance;
+ }
+ }
+
+ if (closestLayoutObject && !closestLayoutObject->isSVGText()) {
fs 2016/01/15 10:34:16 Use "early-out style" when possible - i.e here you
+ FloatPoint absolutePoint = closestLayoutObject->localToParentTransform().inverse().mapPoint(point);
+ localToParentTransform = localToParentTransform * closestLayoutObject->localToParentTransform();
+ LayoutObject* result = findSelectedLayoutSVGText(closestLayoutObject, localToParentTransform, absolutePoint);
+
+ if (!result) {
+ localToParentTransform = localToParentTransform * closestLayoutObject->localToParentTransform().inverse();
fs 2016/01/15 10:34:16 Maintaining the transform like this looks really e
+ for (LayoutObject* overlappedObject : overlappedObjects) {
+ absolutePoint = overlappedObject->localToParentTransform().inverse().mapPoint(point);
+ localToParentTransform = localToParentTransform * overlappedObject->localToParentTransform();
+ result = findSelectedLayoutSVGText(overlappedObject, localToParentTransform, absolutePoint);
+ if (result)
+ break;
+ localToParentTransform = localToParentTransform * overlappedObject->localToParentTransform().inverse();
+ }
+ }
+
+ closestLayoutObject = result;
+ }
+
+ return closestLayoutObject;
+}
+
}
« no previous file with comments | « third_party/WebKit/Source/core/layout/svg/SVGLayoutSupport.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698