Chromium Code Reviews| 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..0289cc6445b20c54b23fb13a87c6e31da73bedea 100644 |
| --- a/third_party/WebKit/Source/core/layout/svg/SVGLayoutSupport.cpp |
| +++ b/third_party/WebKit/Source/core/layout/svg/SVGLayoutSupport.cpp |
| @@ -476,4 +476,58 @@ float SVGLayoutSupport::calculateScreenFontSizeScalingFactor(const LayoutObject* |
| return narrowPrecisionToFloat(sqrt((pow(ctm.xScale(), 2) + pow(ctm.yScale(), 2)) / 2)); |
| } |
| +LayoutObject* SVGLayoutSupport::findClosestLayoutSVGText(LayoutObject* layoutObject, 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->isSVGContainer() && !child->isSVGText()) |
| + continue; |
| + if (child->isSVGHiddenContainer()) |
| + continue; |
| + |
| + FloatRect boundingBox = child->objectBoundingBox(); |
|
fs
2016/01/19 13:30:04
Move down.
|
| + |
| + if (!child->localToParentTransform().isInvertible()) |
| + continue; |
| + |
| + FloatPoint childLocalPoint = child->localToParentTransform().inverse().mapPoint(point); |
| + float distance = boundingBox.squaredDistanceTo(childLocalPoint); |
| + |
| + if (distance <= closestDistance) { |
| + // The reason is that if the closest LayoutObject is not found LayoutSVGText, try to find |
| + // LayoutSVGText object on other LayoutObjects overlapped by closest LayoutObject |
| + if (closestLayoutObject && boundingBox.contains(closestLayoutObject->objectBoundingBox())) { |
| + overlappedObjects.append(child); |
| + continue; |
| + } |
| + |
| + overlappedObjects.clear(); |
| + |
| + closestLayoutObject = child; |
| + closestDistance = distance; |
| + } |
| + } |
| + |
| + if (!closestLayoutObject || closestLayoutObject->isSVGText()) |
| + return closestLayoutObject; |
| + |
| + FloatPoint absolutePoint = closestLayoutObject->localToParentTransform().inverse().mapPoint(point); |
|
fs
2016/01/19 13:30:04
Calling this "pointInChild" or "childLocalPoint" l
|
| + if (LayoutObject* result = findClosestLayoutSVGText(closestLayoutObject, absolutePoint)) |
| + return result; |
| + |
| + // No found LayoutSVGText on closest LayoutObject, after all try to search on other LayoutObjects which store |
| + // on vector called `overlappedObjects`. |
| + LayoutObject* result; |
| + for (LayoutObject* overlappedObject : overlappedObjects) { |
| + absolutePoint = overlappedObject->localToParentTransform().inverse().mapPoint(point); |
| + result = findClosestLayoutSVGText(overlappedObject, absolutePoint); |
| + if (result) |
|
fs
2016/01/19 13:30:04
You could write this like the previous version bef
|
| + break; |
| + } |
| + |
| + return result; |
| +} |
| + |
| } |