Chromium Code Reviews| Index: Source/core/layout/svg/LayoutSVGInlineText.cpp |
| diff --git a/Source/core/layout/svg/LayoutSVGInlineText.cpp b/Source/core/layout/svg/LayoutSVGInlineText.cpp |
| index 69553b53f7abf9be827f39d611b7d3ff8fb6bca5..a8bb95ee11e954e1435e6663a6b3507900ff0bb7 100644 |
| --- a/Source/core/layout/svg/LayoutSVGInlineText.cpp |
| +++ b/Source/core/layout/svg/LayoutSVGInlineText.cpp |
| @@ -59,6 +59,14 @@ static PassRefPtr<StringImpl> applySVGWhitespaceRules(PassRefPtr<StringImpl> str |
| return newString.release(); |
| } |
| +static float squaredDistanceToClosestPoint(const FloatRect& rect, const FloatPoint& point) |
| +{ |
| + FloatPoint closestPoint; |
| + closestPoint.setX(std::max(std::min(point.x(), rect.maxX()), rect.x())); |
| + closestPoint.setY(std::max(std::min(point.y(), rect.maxY()), rect.y())); |
| + return (point - closestPoint).diagonalLengthSquared(); |
| +} |
| + |
| LayoutSVGInlineText::LayoutSVGInlineText(Node* n, PassRefPtr<StringImpl> string) |
| : LayoutText(n, applySVGWhitespaceRules(string, false)) |
| , m_scalingFactor(1) |
| @@ -184,10 +192,12 @@ PositionWithAffinity LayoutSVGInlineText::positionForPoint(const LayoutPoint& po |
| fragment.buildFragmentTransform(fragmentTransform); |
| fragmentRect = fragmentTransform.mapRect(fragmentRect); |
| - float distance = powf(fragmentRect.x() - absolutePoint.x(), 2) + |
| - powf(fragmentRect.y() + fragmentRect.height() / 2 - absolutePoint.y(), 2); |
| + float distance = 0; |
| + if (!fragmentRect.contains(absolutePoint)) { |
| + distance = squaredDistanceToClosestPoint(fragmentRect, absolutePoint); |
| + } |
|
fs
2015/04/28 08:57:03
Drop the {}
|
| - if (distance < closestDistance) { |
| + if (distance <= closestDistance) { |
| closestDistance = distance; |
| closestDistanceBox = textBox; |
| closestDistanceFragment = &fragment; |