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

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 19 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
« no previous file with comments | « LayoutTests/svg/text/select-svg-text-with-collapsed-whitespace-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..2ef5ee2f707a659c7c1c8d14f1a689f038fda1ba 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)
@@ -155,7 +163,8 @@ PositionWithAffinity LayoutSVGInlineText::positionForPoint(const LayoutPoint& po
if (!firstTextBox() || !textLength())
return createPositionWithAffinity(0, DOWNSTREAM);
- float baseline = m_scaledFont.fontMetrics().floatAscent();
+ ASSERT(m_scalingFactor);
+ float baseline = m_scaledFont.fontMetrics().floatAscent() / m_scalingFactor;
LayoutBlock* containingBlock = this->containingBlock();
ASSERT(containingBlock);
@@ -182,12 +191,14 @@ PositionWithAffinity LayoutSVGInlineText::positionForPoint(const LayoutPoint& po
const SVGTextFragment& fragment = fragments.at(i);
FloatRect fragmentRect(fragment.x, fragment.y - baseline, fragment.width, fragment.height);
fragment.buildFragmentTransform(fragmentTransform);
- fragmentRect = fragmentTransform.mapRect(fragmentRect);
+ if (!fragmentTransform.isIdentity())
+ 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);
- if (distance < closestDistance) {
+ if (distance <= closestDistance) {
closestDistance = distance;
closestDistanceBox = textBox;
closestDistanceFragment = &fragment;
« no previous file with comments | « LayoutTests/svg/text/select-svg-text-with-collapsed-whitespace-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698