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

Unified Diff: Source/core/layout/svg/LayoutSVGInlineText.cpp

Issue 1072403007: Fixup a bug about SVG text selection. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Draft 16 (remove floor) Created 5 years, 8 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
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;

Powered by Google App Engine
This is Rietveld 408576698