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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006 Oliver Hunt <ojh16@student.canterbury.ac.nz> 2 * Copyright (C) 2006 Oliver Hunt <ojh16@student.canterbury.ac.nz>
3 * Copyright (C) 2006 Apple Computer Inc. 3 * Copyright (C) 2006 Apple Computer Inc.
4 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> 4 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
5 * Copyright (C) 2008 Rob Buis <buis@kde.org> 5 * Copyright (C) 2008 Rob Buis <buis@kde.org>
6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 SVGInlineTextBox* closestDistanceBox = 0; 170 SVGInlineTextBox* closestDistanceBox = 0;
171 171
172 AffineTransform fragmentTransform; 172 AffineTransform fragmentTransform;
173 for (InlineTextBox* box = firstTextBox(); box; box = box->nextTextBox()) { 173 for (InlineTextBox* box = firstTextBox(); box; box = box->nextTextBox()) {
174 if (!box->isSVGInlineTextBox()) 174 if (!box->isSVGInlineTextBox())
175 continue; 175 continue;
176 176
177 SVGInlineTextBox* textBox = toSVGInlineTextBox(box); 177 SVGInlineTextBox* textBox = toSVGInlineTextBox(box);
178 Vector<SVGTextFragment>& fragments = textBox->textFragments(); 178 Vector<SVGTextFragment>& fragments = textBox->textFragments();
179 179
180 unsigned textFragmentsSize = fragments.size(); 180 unsigned textFragmentsSize = fragments.size();
181 for (unsigned i = 0; i < textFragmentsSize; ++i) { 181 for (unsigned i = 0; i < textFragmentsSize; ++i) {
182 const SVGTextFragment& fragment = fragments.at(i); 182 const SVGTextFragment& fragment = fragments.at(i);
183 FloatRect fragmentRect(fragment.x, fragment.y - baseline, fragment.w idth, fragment.height); 183 FloatRect fragmentRect(fragment.x, fragment.y - baseline, fragment.w idth, fragment.height);
184 fragment.buildFragmentTransform(fragmentTransform); 184 fragment.buildFragmentTransform(fragmentTransform);
185 fragmentRect = fragmentTransform.mapRect(fragmentRect); 185 fragmentRect = fragmentTransform.mapRect(fragmentRect);
186 // This is edge selection. If there is absolute-point between center and right edge of fragmentRect,
187 // selects rightEndge. In other cases selects left edge.
188 FloatPoint selectedEdge;
189 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
190 selectedEdge = fragmentRect.rightEdgeMidPoint();
fs 2015/04/23 16:29:51 Rather than adding these new methods, you could do
191 } else {
192 selectedEdge = fragmentRect.leftEdgeMidPoint();
193 }
186 194
187 float distance = powf(fragmentRect.x() - absolutePoint.x(), 2) + 195 float distance = (selectedEdge - absolutePoint).diagonalLengthSquare d();
188 powf(fragmentRect.y() + fragmentRect.height() / 2 - absolutePoin t.y(), 2);
189 196
190 if (distance < closestDistance) { 197 if (distance < closestDistance) {
191 closestDistance = distance; 198 closestDistance = distance;
192 closestDistanceBox = textBox; 199 closestDistanceBox = textBox;
193 closestDistanceFragment = &fragment; 200 closestDistanceFragment = &fragment;
194 closestDistancePosition = fragmentRect.x(); 201 closestDistancePosition = fragmentRect.x();
195 } 202 }
196 } 203 }
197 } 204 }
198 205
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 251
245 PassRefPtr<StringImpl> LayoutSVGInlineText::originalText() const 252 PassRefPtr<StringImpl> LayoutSVGInlineText::originalText() const
246 { 253 {
247 RefPtr<StringImpl> result = LayoutText::originalText(); 254 RefPtr<StringImpl> result = LayoutText::originalText();
248 if (!result) 255 if (!result)
249 return nullptr; 256 return nullptr;
250 return applySVGWhitespaceRules(result, style() && style()->whiteSpace() == P RE); 257 return applySVGWhitespaceRules(result, style() && style()->whiteSpace() == P RE);
251 } 258 }
252 259
253 } 260 }
OLDNEW
« 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