| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * * Redistributions of source code must retain the above copyright | 4 * * Redistributions of source code must retain the above copyright |
| 5 * notice, this list of conditions and the following disclaimer. | 5 * notice, this list of conditions and the following disclaimer. |
| 6 * * Redistributions in binary form must reproduce the above | 6 * * Redistributions in binary form must reproduce the above |
| 7 * copyright notice, this list of conditions and the following disclaimer | 7 * copyright notice, this list of conditions and the following disclaimer |
| 8 * in the documentation and/or other materials provided with the | 8 * in the documentation and/or other materials provided with the |
| 9 * distribution. | 9 * distribution. |
| 10 * * Neither the name of Google Inc. nor the names of its | 10 * * Neither the name of Google Inc. nor the names of its |
| 11 * contributors may be used to endorse or promote products derived from | 11 * contributors may be used to endorse or promote products derived from |
| 12 * this software without specific prior written permission. | 12 * this software without specific prior written permission. |
| 13 * | 13 * |
| 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 18 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 18 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #ifndef StyleBuilderConverter_h | 27 #ifndef StyleBuilderConverter_h |
| 28 #define StyleBuilderConverter_h | 28 #define StyleBuilderConverter_h |
| 29 | 29 |
| 30 #include "core/css/CSSIdentifierValue.h" |
| 30 #include "core/css/CSSStringValue.h" | 31 #include "core/css/CSSStringValue.h" |
| 31 #include "core/css/CSSValue.h" | 32 #include "core/css/CSSValue.h" |
| 32 #include "core/css/CSSValueList.h" | 33 #include "core/css/CSSValueList.h" |
| 33 #include "core/css/resolver/StyleResolverState.h" | 34 #include "core/css/resolver/StyleResolverState.h" |
| 34 #include "core/style/QuotesData.h" | 35 #include "core/style/QuotesData.h" |
| 35 #include "core/style/ShadowList.h" | 36 #include "core/style/ShadowList.h" |
| 36 #include "core/style/StyleOffsetRotation.h" | 37 #include "core/style/StyleOffsetRotation.h" |
| 37 #include "core/style/StyleReflection.h" | 38 #include "core/style/StyleReflection.h" |
| 38 #include "core/style/StyleScrollSnapData.h" | 39 #include "core/style/StyleScrollSnapData.h" |
| 39 #include "core/style/TransformOrigin.h" | 40 #include "core/style/TransformOrigin.h" |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 T StyleBuilderConverter::convertComputedLength(StyleResolverState& state, | 193 T StyleBuilderConverter::convertComputedLength(StyleResolverState& state, |
| 193 const CSSValue& value) { | 194 const CSSValue& value) { |
| 194 return toCSSPrimitiveValue(value).computeLength<T>( | 195 return toCSSPrimitiveValue(value).computeLength<T>( |
| 195 state.cssToLengthConversionData()); | 196 state.cssToLengthConversionData()); |
| 196 } | 197 } |
| 197 | 198 |
| 198 template <typename T> | 199 template <typename T> |
| 199 T StyleBuilderConverter::convertFlags(StyleResolverState& state, | 200 T StyleBuilderConverter::convertFlags(StyleResolverState& state, |
| 200 const CSSValue& value) { | 201 const CSSValue& value) { |
| 201 T flags = static_cast<T>(0); | 202 T flags = static_cast<T>(0); |
| 202 if (value.isPrimitiveValue() && | 203 if (value.isIdentifierValue() && |
| 203 toCSSPrimitiveValue(value).getValueID() == CSSValueNone) | 204 toCSSIdentifierValue(value).getValueID() == CSSValueNone) |
| 204 return flags; | 205 return flags; |
| 205 for (auto& flagValue : toCSSValueList(value)) | 206 for (auto& flagValue : toCSSValueList(value)) |
| 206 flags |= toCSSPrimitiveValue(*flagValue).convertTo<T>(); | 207 flags |= toCSSIdentifierValue(*flagValue).convertTo<T>(); |
| 207 return flags; | 208 return flags; |
| 208 } | 209 } |
| 209 | 210 |
| 210 template <typename T> | 211 template <typename T> |
| 211 T StyleBuilderConverter::convertLineWidth(StyleResolverState& state, | 212 T StyleBuilderConverter::convertLineWidth(StyleResolverState& state, |
| 212 const CSSValue& value) { | 213 const CSSValue& value) { |
| 214 if (value.isIdentifierValue()) { |
| 215 CSSValueID valueID = toCSSIdentifierValue(value).getValueID(); |
| 216 if (valueID == CSSValueThin) |
| 217 return 1; |
| 218 if (valueID == CSSValueMedium) |
| 219 return 3; |
| 220 if (valueID == CSSValueThick) |
| 221 return 5; |
| 222 NOTREACHED(); |
| 223 return 0; |
| 224 } |
| 213 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value); | 225 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value); |
| 214 CSSValueID valueID = primitiveValue.getValueID(); | 226 // FIXME: We are moving to use the full page zoom implementation to handle hig
h-dpi. |
| 215 if (valueID == CSSValueThin) | 227 // In that case specyfing a border-width of less than 1px would result in a bo
rder that is one device pixel thick. |
| 216 return 1; | 228 // With this change that would instead be rounded up to 2 device pixels. |
| 217 if (valueID == CSSValueMedium) | 229 // Consider clamping it to device pixels or zoom adjusted CSS pixels instead o
f raw CSS pixels. |
| 218 return 3; | 230 // Reference crbug.com/485650 and crbug.com/382483 |
| 219 if (valueID == CSSValueThick) | 231 double result = |
| 220 return 5; | 232 primitiveValue.computeLength<double>(state.cssToLengthConversionData()); |
| 221 if (valueID == CSSValueInvalid) { | 233 if (result > 0.0 && result < 1.0) |
| 222 // FIXME: We are moving to use the full page zoom implementation to handle h
igh-dpi. | 234 return 1.0; |
| 223 // In that case specyfing a border-width of less than 1px would result in a
border that is one device pixel thick. | 235 return clampTo<T>(roundForImpreciseConversion<T>(result), |
| 224 // With this change that would instead be rounded up to 2 device pixels. | 236 defaultMinimumForClamp<T>(), defaultMaximumForClamp<T>()); |
| 225 // Consider clamping it to device pixels or zoom adjusted CSS pixels instead
of raw CSS pixels. | |
| 226 // Reference crbug.com/485650 and crbug.com/382483 | |
| 227 double result = | |
| 228 primitiveValue.computeLength<double>(state.cssToLengthConversionData()); | |
| 229 if (result > 0.0 && result < 1.0) | |
| 230 return 1.0; | |
| 231 return clampTo<T>(roundForImpreciseConversion<T>(result), | |
| 232 defaultMinimumForClamp<T>(), defaultMaximumForClamp<T>()); | |
| 233 } | |
| 234 ASSERT_NOT_REACHED(); | |
| 235 return 0; | |
| 236 } | 237 } |
| 237 | 238 |
| 238 template <CSSValueID IdForNone> | 239 template <CSSValueID IdForNone> |
| 239 AtomicString StyleBuilderConverter::convertString(StyleResolverState&, | 240 AtomicString StyleBuilderConverter::convertString(StyleResolverState&, |
| 240 const CSSValue& value) { | 241 const CSSValue& value) { |
| 241 if (value.isStringValue()) | 242 if (value.isStringValue()) |
| 242 return AtomicString(toCSSStringValue(value).value()); | 243 return AtomicString(toCSSStringValue(value).value()); |
| 243 ASSERT(toCSSPrimitiveValue(value).getValueID() == IdForNone); | 244 DCHECK_EQ(toCSSIdentifierValue(value).getValueID(), IdForNone); |
| 244 return nullAtom; | 245 return nullAtom; |
| 245 } | 246 } |
| 246 | 247 |
| 247 } // namespace blink | 248 } // namespace blink |
| 248 | 249 |
| 249 #endif | 250 #endif |
| OLD | NEW |