Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 // copy of the original character data content. First, it will remove all ne wline | 52 // copy of the original character data content. First, it will remove all ne wline |
| 53 // characters. Then it will convert all tab characters into space characters . | 53 // characters. Then it will convert all tab characters into space characters . |
| 54 // Then, it will strip off all leading and trailing space characters. | 54 // Then, it will strip off all leading and trailing space characters. |
| 55 // Then, all contiguous space characters will be consolidated. | 55 // Then, all contiguous space characters will be consolidated. |
| 56 RefPtr<StringImpl> newString = string->replace('\n', StringImpl::empty()); | 56 RefPtr<StringImpl> newString = string->replace('\n', StringImpl::empty()); |
| 57 newString = newString->replace('\r', StringImpl::empty()); | 57 newString = newString->replace('\r', StringImpl::empty()); |
| 58 newString = newString->replace('\t', ' '); | 58 newString = newString->replace('\t', ' '); |
| 59 return newString.release(); | 59 return newString.release(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 static float squaredDistanceToClosestPoint(const FloatRect& rect, const FloatPoi nt& point) | |
| 63 { | |
| 64 FloatPoint closestPoint; | |
| 65 closestPoint.setX(std::max(std::min(point.x(), rect.maxX()), rect.x())); | |
| 66 closestPoint.setY(std::max(std::min(point.y(), rect.maxY()), rect.y())); | |
| 67 return (point - closestPoint).diagonalLengthSquared(); | |
| 68 } | |
| 69 | |
| 62 LayoutSVGInlineText::LayoutSVGInlineText(Node* n, PassRefPtr<StringImpl> string) | 70 LayoutSVGInlineText::LayoutSVGInlineText(Node* n, PassRefPtr<StringImpl> string) |
| 63 : LayoutText(n, applySVGWhitespaceRules(string, false)) | 71 : LayoutText(n, applySVGWhitespaceRules(string, false)) |
| 64 , m_scalingFactor(1) | 72 , m_scalingFactor(1) |
| 65 , m_layoutAttributes(this) | 73 , m_layoutAttributes(this) |
| 66 { | 74 { |
| 67 } | 75 } |
| 68 | 76 |
| 69 void LayoutSVGInlineText::setTextInternal(PassRefPtr<StringImpl> text) | 77 void LayoutSVGInlineText::setTextInternal(PassRefPtr<StringImpl> text) |
| 70 { | 78 { |
| 71 LayoutText::setTextInternal(text); | 79 LayoutText::setTextInternal(text); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 SVGInlineTextBox* textBox = toSVGInlineTextBox(box); | 185 SVGInlineTextBox* textBox = toSVGInlineTextBox(box); |
| 178 Vector<SVGTextFragment>& fragments = textBox->textFragments(); | 186 Vector<SVGTextFragment>& fragments = textBox->textFragments(); |
| 179 | 187 |
| 180 unsigned textFragmentsSize = fragments.size(); | 188 unsigned textFragmentsSize = fragments.size(); |
| 181 for (unsigned i = 0; i < textFragmentsSize; ++i) { | 189 for (unsigned i = 0; i < textFragmentsSize; ++i) { |
| 182 const SVGTextFragment& fragment = fragments.at(i); | 190 const SVGTextFragment& fragment = fragments.at(i); |
| 183 FloatRect fragmentRect(fragment.x, fragment.y - baseline, fragment.w idth, fragment.height); | 191 FloatRect fragmentRect(fragment.x, fragment.y - baseline, fragment.w idth, fragment.height); |
| 184 fragment.buildFragmentTransform(fragmentTransform); | 192 fragment.buildFragmentTransform(fragmentTransform); |
| 185 fragmentRect = fragmentTransform.mapRect(fragmentRect); | 193 fragmentRect = fragmentTransform.mapRect(fragmentRect); |
| 186 | 194 |
| 187 float distance = powf(fragmentRect.x() - absolutePoint.x(), 2) + | 195 float distance = 0; |
| 188 powf(fragmentRect.y() + fragmentRect.height() / 2 - absolutePoin t.y(), 2); | 196 if (!fragmentRect.contains(absolutePoint)) { |
| 197 distance = squaredDistanceToClosestPoint(fragmentRect, absoluteP oint); | |
| 198 } | |
|
fs
2015/04/28 08:57:03
Drop the {}
| |
| 189 | 199 |
| 190 if (distance < closestDistance) { | 200 if (distance <= closestDistance) { |
| 191 closestDistance = distance; | 201 closestDistance = distance; |
| 192 closestDistanceBox = textBox; | 202 closestDistanceBox = textBox; |
| 193 closestDistanceFragment = &fragment; | 203 closestDistanceFragment = &fragment; |
| 194 closestDistancePosition = fragmentRect.x(); | 204 closestDistancePosition = fragmentRect.x(); |
| 195 } | 205 } |
| 196 } | 206 } |
| 197 } | 207 } |
| 198 | 208 |
| 199 if (!closestDistanceFragment) | 209 if (!closestDistanceFragment) |
| 200 return createPositionWithAffinity(0, DOWNSTREAM); | 210 return createPositionWithAffinity(0, DOWNSTREAM); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 | 254 |
| 245 PassRefPtr<StringImpl> LayoutSVGInlineText::originalText() const | 255 PassRefPtr<StringImpl> LayoutSVGInlineText::originalText() const |
| 246 { | 256 { |
| 247 RefPtr<StringImpl> result = LayoutText::originalText(); | 257 RefPtr<StringImpl> result = LayoutText::originalText(); |
| 248 if (!result) | 258 if (!result) |
| 249 return nullptr; | 259 return nullptr; |
| 250 return applySVGWhitespaceRules(result, style() && style()->whiteSpace() == P RE); | 260 return applySVGWhitespaceRules(result, style() && style()->whiteSpace() == P RE); |
| 251 } | 261 } |
| 252 | 262 |
| 253 } | 263 } |
| OLD | NEW |