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

Side by Side Diff: third_party/WebKit/Source/core/layout/svg/LayoutSVGInlineText.cpp

Issue 1612453002: [Refactoring] Remove squaredDistanceToClosestPoint function on LayoutSVGInlineText.cpp (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « no previous file | 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) 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // copy of the original character data content. First, it will remove all ne wline 51 // copy of the original character data content. First, it will remove all ne wline
52 // characters. Then it will convert all tab characters into space characters . 52 // characters. Then it will convert all tab characters into space characters .
53 // Then, it will strip off all leading and trailing space characters. 53 // Then, it will strip off all leading and trailing space characters.
54 // Then, all contiguous space characters will be consolidated. 54 // Then, all contiguous space characters will be consolidated.
55 RefPtr<StringImpl> newString = string->replace('\n', StringImpl::empty()); 55 RefPtr<StringImpl> newString = string->replace('\n', StringImpl::empty());
56 newString = newString->replace('\r', StringImpl::empty()); 56 newString = newString->replace('\r', StringImpl::empty());
57 newString = newString->replace('\t', ' '); 57 newString = newString->replace('\t', ' ');
58 return newString.release(); 58 return newString.release();
59 } 59 }
60 60
61 static float squaredDistanceToClosestPoint(const FloatRect& rect, const FloatPoi nt& point)
62 {
63 FloatPoint closestPoint;
64 closestPoint.setX(std::max(std::min(point.x(), rect.maxX()), rect.x()));
65 closestPoint.setY(std::max(std::min(point.y(), rect.maxY()), rect.y()));
66 return (point - closestPoint).diagonalLengthSquared();
67 }
68
69 LayoutSVGInlineText::LayoutSVGInlineText(Node* n, PassRefPtr<StringImpl> string) 61 LayoutSVGInlineText::LayoutSVGInlineText(Node* n, PassRefPtr<StringImpl> string)
70 : LayoutText(n, applySVGWhitespaceRules(string, false)) 62 : LayoutText(n, applySVGWhitespaceRules(string, false))
71 , m_scalingFactor(1) 63 , m_scalingFactor(1)
72 , m_layoutAttributes(this) 64 , m_layoutAttributes(this)
73 { 65 {
74 } 66 }
75 67
76 void LayoutSVGInlineText::setTextInternal(PassRefPtr<StringImpl> text) 68 void LayoutSVGInlineText::setTextInternal(PassRefPtr<StringImpl> text)
77 { 69 {
78 LayoutText::setTextInternal(text); 70 LayoutText::setTextInternal(text);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 for (InlineTextBox* box = firstTextBox(); box; box = box->nextTextBox()) { 172 for (InlineTextBox* box = firstTextBox(); box; box = box->nextTextBox()) {
181 if (!box->isSVGInlineTextBox()) 173 if (!box->isSVGInlineTextBox())
182 continue; 174 continue;
183 175
184 SVGInlineTextBox* textBox = toSVGInlineTextBox(box); 176 SVGInlineTextBox* textBox = toSVGInlineTextBox(box);
185 for (const SVGTextFragment& fragment : textBox->textFragments()) { 177 for (const SVGTextFragment& fragment : textBox->textFragments()) {
186 FloatRect fragmentRect = fragment.boundingBox(baseline); 178 FloatRect fragmentRect = fragment.boundingBox(baseline);
187 179
188 float distance = 0; 180 float distance = 0;
189 if (!fragmentRect.contains(absolutePoint)) 181 if (!fragmentRect.contains(absolutePoint))
190 distance = squaredDistanceToClosestPoint(fragmentRect, absoluteP oint); 182 distance = fragmentRect.squaredDistanceTo(absolutePoint);
191 183
192 if (distance <= closestDistance) { 184 if (distance <= closestDistance) {
193 closestDistance = distance; 185 closestDistance = distance;
194 closestDistanceBox = textBox; 186 closestDistanceBox = textBox;
195 closestDistanceFragment = &fragment; 187 closestDistanceFragment = &fragment;
196 closestDistancePosition = fragmentRect.x(); 188 closestDistancePosition = fragmentRect.x();
197 } 189 }
198 } 190 }
199 } 191 }
200 192
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 239
248 PassRefPtr<StringImpl> LayoutSVGInlineText::originalText() const 240 PassRefPtr<StringImpl> LayoutSVGInlineText::originalText() const
249 { 241 {
250 RefPtr<StringImpl> result = LayoutText::originalText(); 242 RefPtr<StringImpl> result = LayoutText::originalText();
251 if (!result) 243 if (!result)
252 return nullptr; 244 return nullptr;
253 return applySVGWhitespaceRules(result, style() && style()->whiteSpace() == P RE); 245 return applySVGWhitespaceRules(result, style() && style()->whiteSpace() == P RE);
254 } 246 }
255 247
256 } 248 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698