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..568ebd694085286b1009ecd107a99b76b57dee73 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) |
| +{ |
| + // Try to search closest LayoutSVGText on sub-tree of `layoutObject`. |
|
fs
2016/01/19 16:12:46
"Try to find the closest LayoutSVGText in the subt
|
| + // When closest LayoutObject hasn't LayoutSVGText object, try to search on other LayoutObjects |
|
fs
2016/01/19 16:12:46
LayoutSVGText's are not treat specially in any way
|
| + // overlapped which store on the vector called `overlappedObjects` that they are candidates. |
| + // If not find LayoutSVGText object on candidates, After all return nullptr. |
| + 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; |
| + if (!child->localToParentTransform().isInvertible()) |
| + continue; |
| + |
| + FloatRect boundingBox = child->objectBoundingBox(); |
| + 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())) { |
|
fs
2016/01/19 16:12:46
To re-iterate: I don't think that 'overlaps' is a
|
| + overlappedObjects.append(child); |
| + continue; |
| + } |
| + |
| + overlappedObjects.clear(); |
| + |
| + closestLayoutObject = child; |
| + closestDistance = distance; |
| + } |
| + } |
| + |
| + if (!closestLayoutObject || closestLayoutObject->isSVGText()) |
| + return closestLayoutObject; |
| + |
| + FloatPoint childLocalPoint = closestLayoutObject->localToParentTransform().inverse().mapPoint(point); |
| + if (LayoutObject* result = findClosestLayoutSVGText(closestLayoutObject, childLocalPoint)) |
| + return result; |
| + |
| + // No find LayoutSVGText on closest LayoutObject, after all try to search on other LayoutObjects which store |
| + // on vector called `overlappedObjects`. |
| + for (LayoutObject* overlappedObject : overlappedObjects) { |
| + childLocalPoint = overlappedObject->localToParentTransform().inverse().mapPoint(point); |
| + if (LayoutObject* result = findClosestLayoutSVGText(overlappedObject, childLocalPoint)) |
| + return result; |
| + } |
| + |
| + return nullptr; |
| +} |
| + |
| } |