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..a26dad3f23a742216c9a3b372dbb937404f48199 100644 |
--- a/third_party/WebKit/Source/core/layout/svg/SVGLayoutSupport.cpp |
+++ b/third_party/WebKit/Source/core/layout/svg/SVGLayoutSupport.cpp |
@@ -476,4 +476,59 @@ float SVGLayoutSupport::calculateScreenFontSizeScalingFactor(const LayoutObject* |
return narrowPrecisionToFloat(sqrt((pow(ctm.xScale(), 2) + pow(ctm.yScale(), 2)) / 2)); |
} |
+LayoutObject* SVGLayoutSupport::findSelectedLayoutSVGText(LayoutObject* layoutObject, const FloatPoint point) |
fs
2016/01/18 12:44:11
"Selected" doesn't seem like the correct term here
|
+{ |
+ 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->isSVGContainer() && child->isSVGHiddenContainer()) |
fs
2016/01/18 12:44:11
No need to check isSVGContainer() again. It would
|
+ continue; |
+ |
+ FloatRect bound = child->objectBoundingBox(); |
fs
2016/01/18 12:44:11
Move down to just before you need it and rename to
|
+ |
+ if (!child->localToParentTransform().isInvertible()) |
+ continue; |
+ |
+ FloatPoint childLocalPoint = child->localToParentTransform().inverse().mapPoint(point); |
+ float distance = bound.squaredDistanceTo(childLocalPoint); |
+ |
+ if (distance < closestDistance) { |
+ // If child is overlapped by closesLayoutObject, It's candiate to search sub-tree. |
fs
2016/01/18 12:44:11
Lot's of typos that needs fixing here ("closesLayo
|
+ // When closestLayoutObject' sub-tree hasn't LayoutSVGText object, try to search |
+ // on the sub-tree which store on vector called `overlappedObjects`. |
+ if (closestLayoutObject && bound.contains(closestLayoutObject->objectBoundingBox())) { |
fs
2016/01/18 12:44:11
I don't quite see why the "overlapped" property ma
|
+ overlappedObjects.append(child); |
+ continue; |
+ } |
+ |
+ overlappedObjects.clear(); |
+ |
+ closestLayoutObject = child; |
+ closestDistance = distance; |
+ } |
+ } |
+ |
+ if (!closestLayoutObject || closestLayoutObject->isSVGText()) |
+ return closestLayoutObject; |
+ |
+ FloatPoint absolutePoint = closestLayoutObject->localToParentTransform().inverse().mapPoint(point); |
+ LayoutObject* result = findSelectedLayoutSVGText(closestLayoutObject, absolutePoint); |
fs
2016/01/18 12:44:11
if (LayoutObject* result = ...)
return result;
|
+ |
+ // No found LayoutSVGText on closest subtree, after all try to search on the sub-tree which store |
+ // on vector called `overlappedObjects`. |
+ if (!result) { |
+ for (LayoutObject* overlappedObject : overlappedObjects) { |
+ absolutePoint = overlappedObject->localToParentTransform().inverse().mapPoint(point); |
+ result = findSelectedLayoutSVGText(overlappedObject, absolutePoint); |
+ if (result) |
+ break; |
+ } |
+ } |
+ |
+ return result; |
+} |
+ |
} |