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

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: add a line. 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..dfdcd684c0f49037cac0fe7601916e084d382add 100644
--- a/Source/core/layout/svg/LayoutSVGInlineText.cpp
+++ b/Source/core/layout/svg/LayoutSVGInlineText.cpp
@@ -177,15 +177,22 @@ PositionWithAffinity LayoutSVGInlineText::positionForPoint(const LayoutPoint& po
SVGInlineTextBox* textBox = toSVGInlineTextBox(box);
Vector<SVGTextFragment>& fragments = textBox->textFragments();
- unsigned textFragmentsSize = fragments.size();
+ unsigned textFragmentsSize = fragments.size();
for (unsigned i = 0; i < textFragmentsSize; ++i) {
const SVGTextFragment& fragment = fragments.at(i);
FloatRect fragmentRect(fragment.x, fragment.y - baseline, fragment.width, fragment.height);
fragment.buildFragmentTransform(fragmentTransform);
fragmentRect = fragmentTransform.mapRect(fragmentRect);
+ // This is edge selection. If there is absolute-point between center and right edge of fragmentRect,
+ // selects rightEndge. In other cases selects left edge.
+ FloatPoint selectedEdge;
+ if (absolutePoint.x() > fragmentRect.center().x() && absolutePoint.x() < fragmentRect.maxX()) {
fs 2015/04/23 16:29:51 Why not just pick the closest edge? Using the left
+ selectedEdge = fragmentRect.rightEdgeMidPoint();
fs 2015/04/23 16:29:51 Rather than adding these new methods, you could do
+ } else {
+ selectedEdge = fragmentRect.leftEdgeMidPoint();
+ }
- float distance = powf(fragmentRect.x() - absolutePoint.x(), 2) +
- powf(fragmentRect.y() + fragmentRect.height() / 2 - absolutePoint.y(), 2);
+ float distance = (selectedEdge - absolutePoint).diagonalLengthSquared();
if (distance < closestDistance) {
closestDistance = distance;
« no previous file with comments | « LayoutTests/svg/text/select-svg-text-with-collapsed-whitespace-expected.txt ('k') | Source/platform/geometry/FloatRect.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698