OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. | 2 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above | 8 * 1. Redistributions of source code must retain the above |
9 * copyright notice, this list of conditions and the following | 9 * copyright notice, this list of conditions and the following |
10 * disclaimer. | 10 * disclaimer. |
(...skipping 12 matching lines...) Expand all Loading... |
23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 25 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
27 * OF THE POSSIBILITY OF SUCH DAMAGE. | 27 * OF THE POSSIBILITY OF SUCH DAMAGE. |
28 */ | 28 */ |
29 | 29 |
30 #include "platform/geometry/FloatRoundedRect.h" | 30 #include "platform/geometry/FloatRoundedRect.h" |
31 | 31 |
32 #include "platform/geometry/FloatQuad.h" | 32 #include "platform/geometry/FloatQuad.h" |
33 | 33 #include "wtf/text/WTFString.h" |
34 #include <algorithm> | 34 #include <algorithm> |
35 | 35 |
36 #ifndef NDEBUG | |
37 #include <stdio.h> | |
38 #endif | |
39 | |
40 namespace blink { | 36 namespace blink { |
41 | 37 |
42 FloatRoundedRect::FloatRoundedRect(float x, float y, float width, float height) | 38 FloatRoundedRect::FloatRoundedRect(float x, float y, float width, float height) |
43 : m_rect(x, y, width, height) | 39 : m_rect(x, y, width, height) |
44 { | 40 { |
45 } | 41 } |
46 | 42 |
47 FloatRoundedRect::FloatRoundedRect(const FloatRect& rect, const Radii& radii) | 43 FloatRoundedRect::FloatRoundedRect(const FloatRect& rect, const Radii& radii) |
48 : m_rect(rect) | 44 : m_rect(rect) |
49 , m_radii(radii) | 45 , m_radii(radii) |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 if (m_bottomLeft.width() > 0 && m_bottomLeft.height() > 0) { | 129 if (m_bottomLeft.width() > 0 && m_bottomLeft.height() > 0) { |
134 m_bottomLeft.setWidth(m_bottomLeft.width() + leftWidth); | 130 m_bottomLeft.setWidth(m_bottomLeft.width() + leftWidth); |
135 m_bottomLeft.setHeight(m_bottomLeft.height() + bottomWidth); | 131 m_bottomLeft.setHeight(m_bottomLeft.height() + bottomWidth); |
136 } | 132 } |
137 if (m_bottomRight.width() > 0 && m_bottomRight.height() > 0) { | 133 if (m_bottomRight.width() > 0 && m_bottomRight.height() > 0) { |
138 m_bottomRight.setWidth(m_bottomRight.width() + rightWidth); | 134 m_bottomRight.setWidth(m_bottomRight.width() + rightWidth); |
139 m_bottomRight.setHeight(m_bottomRight.height() + bottomWidth); | 135 m_bottomRight.setHeight(m_bottomRight.height() + bottomWidth); |
140 } | 136 } |
141 } | 137 } |
142 | 138 |
143 #ifndef NDEBUG | |
144 void FloatRoundedRect::Radii::show() const | |
145 { | |
146 fprintf(stderr, "topLeft=[%f,%f], topRight=[%f,%f], bottomLeft=[%f,%f], bott
omRight=[%f,%f]\n", | |
147 topLeft().width(), topLeft().height(), topRight().width(), topRight().he
ight(), | |
148 bottomLeft().width(), bottomLeft().height(), bottomRight().width(), bott
omRight().height()); | |
149 } | |
150 #endif | |
151 | |
152 static inline float cornerRectIntercept(float y, const FloatRect& cornerRect) | 139 static inline float cornerRectIntercept(float y, const FloatRect& cornerRect) |
153 { | 140 { |
154 ASSERT(cornerRect.height() > 0); | 141 ASSERT(cornerRect.height() > 0); |
155 return cornerRect.width() * sqrt(1 - (y * y) / (cornerRect.height() * corner
Rect.height())); | 142 return cornerRect.width() * sqrt(1 - (y * y) / (cornerRect.height() * corner
Rect.height())); |
156 } | 143 } |
157 | 144 |
158 FloatRect FloatRoundedRect::radiusCenterRect() const | 145 FloatRect FloatRoundedRect::radiusCenterRect() const |
159 { | 146 { |
160 FloatRectOutsets maximumRadiusInsets( | 147 FloatRectOutsets maximumRadiusInsets( |
161 -std::max(m_radii.topLeft().height(), m_radii.topRight().height()), | 148 -std::max(m_radii.topLeft().height(), m_radii.topRight().height()), |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 | 329 |
343 if (maxRadiusWidth <= 0 || maxRadiusHeight <= 0) { | 330 if (maxRadiusWidth <= 0 || maxRadiusHeight <= 0) { |
344 m_radii.scale(0.0f); | 331 m_radii.scale(0.0f); |
345 return; | 332 return; |
346 } | 333 } |
347 float widthRatio = static_cast<float>(m_rect.width()) / maxRadiusWidth; | 334 float widthRatio = static_cast<float>(m_rect.width()) / maxRadiusWidth; |
348 float heightRatio = static_cast<float>(m_rect.height()) / maxRadiusHeight; | 335 float heightRatio = static_cast<float>(m_rect.height()) / maxRadiusHeight; |
349 m_radii.scale(widthRatio < heightRatio ? widthRatio : heightRatio); | 336 m_radii.scale(widthRatio < heightRatio ? widthRatio : heightRatio); |
350 } | 337 } |
351 | 338 |
352 #ifndef NDEBUG | 339 String FloatRoundedRect::Radii::toString() const |
353 void FloatRoundedRect::show() const | |
354 { | 340 { |
355 fprintf(stderr, "FloatRoundedRect:\n rect: "); | 341 return String::format("tl:%s; tr:%s; bl:%s; br:%s", |
356 m_rect.show(); | 342 topLeft().toString().ascii().data(), |
357 fprintf(stderr, " radii: "); | 343 topRight().toString().ascii().data(), |
358 m_radii.show(); | 344 bottomLeft().toString().ascii().data(), |
| 345 bottomRight().toString().ascii().data()); |
359 } | 346 } |
360 #endif | 347 |
| 348 String FloatRoundedRect::toString() const |
| 349 { |
| 350 return String::format("%s radii:(%s)", |
| 351 rect().toString().ascii().data(), |
| 352 getRadii().toString().ascii().data()); |
| 353 } |
361 | 354 |
362 } // namespace blink | 355 } // namespace blink |
OLD | NEW |