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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 inline bool operator==(const FloatRoundedRect::Radii& a, const FloatRoundedRect:
:Radii& b) | 125 inline bool operator==(const FloatRoundedRect::Radii& a, const FloatRoundedRect:
:Radii& b) |
126 { | 126 { |
127 return a.topLeft() == b.topLeft() && a.topRight() == b.topRight() && a.botto
mLeft() == b.bottomLeft() && a.bottomRight() == b.bottomRight(); | 127 return a.topLeft() == b.topLeft() && a.topRight() == b.topRight() && a.botto
mLeft() == b.bottomLeft() && a.bottomRight() == b.bottomRight(); |
128 } | 128 } |
129 | 129 |
130 inline bool operator==(const FloatRoundedRect& a, const FloatRoundedRect& b) | 130 inline bool operator==(const FloatRoundedRect& a, const FloatRoundedRect& b) |
131 { | 131 { |
132 return a.rect() == b.rect() && a.radii() == b.radii(); | 132 return a.rect() == b.rect() && a.radii() == b.radii(); |
133 } | 133 } |
134 | 134 |
| 135 inline float calcBorderRadiiConstraintScaleFor(const FloatRect& rect, const Floa
tRoundedRect::Radii& radii) |
| 136 { |
| 137 // Constrain corner radii using CSS3 rules: |
| 138 // http://www.w3.org/TR/css3-background/#the-border-radius |
| 139 |
| 140 float factor = 1; |
| 141 float radiiSum; |
| 142 |
| 143 // top |
| 144 radiiSum = radii.topLeft().width() + radii.topRight().width(); // Casts to a
void integer overflow. |
| 145 if (radiiSum > rect.width()) |
| 146 factor = std::min(rect.width() / radiiSum, factor); |
| 147 |
| 148 // bottom |
| 149 radiiSum = radii.bottomLeft().width() + radii.bottomRight().width(); |
| 150 if (radiiSum > rect.width()) |
| 151 factor = std::min(rect.width() / radiiSum, factor); |
| 152 |
| 153 // left |
| 154 radiiSum = radii.topLeft().height() + radii.bottomLeft().height(); |
| 155 if (radiiSum > rect.height()) |
| 156 factor = std::min(rect.height() / radiiSum, factor); |
| 157 |
| 158 // right |
| 159 radiiSum = radii.topRight().height() + radii.bottomRight().height(); |
| 160 if (radiiSum > rect.height()) |
| 161 factor = std::min(rect.height() / radiiSum, factor); |
| 162 |
| 163 ASSERT(factor <= 1); |
| 164 return factor; |
| 165 } |
| 166 |
135 } // namespace WebCore | 167 } // namespace WebCore |
136 | 168 |
137 #endif // FloatRoundedRect_h | 169 #endif // FloatRoundedRect_h |
OLD | NEW |