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

Side by Side Diff: Source/core/layout/svg/line/SVGInlineTextBox.cpp

Issue 1049673002: Simplify range mapping computation in SVGTextQuery/SVGInlineTextBox (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/layout/svg/SVGTextQuery.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /** 1 /**
2 * Copyright (C) 2007 Rob Buis <buis@kde.org> 2 * Copyright (C) 2007 Rob Buis <buis@kde.org>
3 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> 3 * Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
4 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 4 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 run.disableSpacing(); 195 run.disableSpacing();
196 196
197 // Propagate the maximum length of the characters buffer to the TextRun, eve n when we're only processing a substring. 197 // Propagate the maximum length of the characters buffer to the TextRun, eve n when we're only processing a substring.
198 run.setCharactersLength(text->textLength() - fragment.characterOffset); 198 run.setCharactersLength(text->textLength() - fragment.characterOffset);
199 ASSERT(run.charactersLength() >= run.length()); 199 ASSERT(run.charactersLength() >= run.length());
200 return run; 200 return run;
201 } 201 }
202 202
203 bool SVGInlineTextBox::mapStartEndPositionsIntoFragmentCoordinates(const SVGText Fragment& fragment, int& startPosition, int& endPosition) const 203 bool SVGInlineTextBox::mapStartEndPositionsIntoFragmentCoordinates(const SVGText Fragment& fragment, int& startPosition, int& endPosition) const
204 { 204 {
205 if (startPosition >= endPosition) 205 int fragmentOffsetInBox = static_cast<int>(fragment.characterOffset) - start ();
206 return false;
207 206
208 int offset = static_cast<int>(fragment.characterOffset) - start(); 207 // Compute positions relative to the fragment.
Erik Dahlström (inactive) 2015/04/01 14:04:20 This used to leave startPosition and endPosition u
fs 2015/04/01 14:16:24 The common pattern in callers are: int startPos =
209 int length = static_cast<int>(fragment.length); 208 startPosition -= fragmentOffsetInBox;
209 endPosition -= fragmentOffsetInBox;
210 210
211 if (startPosition >= offset + length || endPosition <= offset) 211 // Intersect with the fragment range.
212 return false; 212 startPosition = std::max(startPosition, 0);
213 endPosition = std::min(endPosition, static_cast<int>(fragment.length));
213 214
214 if (startPosition < offset) 215 return startPosition < endPosition;
215 startPosition = 0;
216 else
217 startPosition -= offset;
218
219 if (endPosition > offset + length) {
220 endPosition = length;
221 } else {
222 ASSERT(endPosition >= offset);
223 endPosition -= offset;
224 }
225
226 ASSERT(startPosition < endPosition);
227 return true;
228 } 216 }
229 217
230 void SVGInlineTextBox::paintDocumentMarker(GraphicsContext*, const FloatPointWil lBeLayoutPoint&, DocumentMarker*, const ComputedStyle&, const Font&, bool) 218 void SVGInlineTextBox::paintDocumentMarker(GraphicsContext*, const FloatPointWil lBeLayoutPoint&, DocumentMarker*, const ComputedStyle&, const Font&, bool)
231 { 219 {
232 // SVG does not have support for generic document markers (e.g., spellchecki ng, etc). 220 // SVG does not have support for generic document markers (e.g., spellchecki ng, etc).
233 } 221 }
234 222
235 void SVGInlineTextBox::paintTextMatchMarker(GraphicsContext* context, const Floa tPointWillBeLayoutPoint& point, DocumentMarker* marker, const ComputedStyle& sty le, const Font& font) 223 void SVGInlineTextBox::paintTextMatchMarker(GraphicsContext* context, const Floa tPointWillBeLayoutPoint& point, DocumentMarker* marker, const ComputedStyle& sty le, const Font& font)
236 { 224 {
237 SVGInlineTextBoxPainter(*this).paintTextMatchMarker(context, point.toFloatPo int(), marker, style, font); 225 SVGInlineTextBoxPainter(*this).paintTextMatchMarker(context, point.toFloatPo int(), marker, style, font);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 layoutObject().updateHitTestResult(result, locationInContainer.p oint() - toLayoutSize(accumulatedOffset)); 270 layoutObject().updateHitTestResult(result, locationInContainer.p oint() - toLayoutSize(accumulatedOffset));
283 if (!result.addNodeToListBasedTestResult(layoutObject().node(), request, locationInContainer, rect.rawValue())) 271 if (!result.addNodeToListBasedTestResult(layoutObject().node(), request, locationInContainer, rect.rawValue()))
284 return true; 272 return true;
285 } 273 }
286 } 274 }
287 } 275 }
288 return false; 276 return false;
289 } 277 }
290 278
291 } // namespace blink 279 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/layout/svg/SVGTextQuery.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698