| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/animation/CSSFontWeightInterpolationType.h" | 5 #include "core/animation/CSSFontWeightInterpolationType.h" |
| 6 | 6 |
| 7 #include <memory> |
| 8 #include "core/animation/FontWeightConversion.h" |
| 7 #include "core/css/CSSPrimitiveValueMappings.h" | 9 #include "core/css/CSSPrimitiveValueMappings.h" |
| 8 #include "core/css/resolver/StyleResolverState.h" | 10 #include "core/css/resolver/StyleResolverState.h" |
| 9 #include "wtf/PtrUtil.h" | 11 #include "wtf/PtrUtil.h" |
| 10 #include <memory> | |
| 11 | 12 |
| 12 namespace blink { | 13 namespace blink { |
| 13 | 14 |
| 14 static double fontWeightToDouble(FontWeight fontWeight) { | |
| 15 switch (fontWeight) { | |
| 16 case FontWeight100: | |
| 17 return 100; | |
| 18 case FontWeight200: | |
| 19 return 200; | |
| 20 case FontWeight300: | |
| 21 return 300; | |
| 22 case FontWeight400: | |
| 23 return 400; | |
| 24 case FontWeight500: | |
| 25 return 500; | |
| 26 case FontWeight600: | |
| 27 return 600; | |
| 28 case FontWeight700: | |
| 29 return 700; | |
| 30 case FontWeight800: | |
| 31 return 800; | |
| 32 case FontWeight900: | |
| 33 return 900; | |
| 34 default: | |
| 35 NOTREACHED(); | |
| 36 return 400; | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 static FontWeight doubleToFontWeight(double value) { | |
| 41 static const FontWeight fontWeights[] = { | |
| 42 FontWeight100, FontWeight200, FontWeight300, FontWeight400, FontWeight500, | |
| 43 FontWeight600, FontWeight700, FontWeight800, FontWeight900, | |
| 44 }; | |
| 45 | |
| 46 int index = round(value / 100 - 1); | |
| 47 int clampedIndex = clampTo<int>(index, 0, WTF_ARRAY_LENGTH(fontWeights) - 1); | |
| 48 return fontWeights[clampedIndex]; | |
| 49 } | |
| 50 | |
| 51 class InheritedFontWeightChecker : public InterpolationType::ConversionChecker { | 15 class InheritedFontWeightChecker : public InterpolationType::ConversionChecker { |
| 52 public: | 16 public: |
| 53 static std::unique_ptr<InheritedFontWeightChecker> create( | 17 static std::unique_ptr<InheritedFontWeightChecker> create( |
| 54 FontWeight fontWeight) { | 18 FontWeight fontWeight) { |
| 55 return WTF::wrapUnique(new InheritedFontWeightChecker(fontWeight)); | 19 return WTF::wrapUnique(new InheritedFontWeightChecker(fontWeight)); |
| 56 } | 20 } |
| 57 | 21 |
| 58 private: | 22 private: |
| 59 InheritedFontWeightChecker(FontWeight fontWeight) | 23 InheritedFontWeightChecker(FontWeight fontWeight) |
| 60 : m_fontWeight(fontWeight) {} | 24 : m_fontWeight(fontWeight) {} |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 100 |
| 137 void CSSFontWeightInterpolationType::applyStandardPropertyValue( | 101 void CSSFontWeightInterpolationType::applyStandardPropertyValue( |
| 138 const InterpolableValue& interpolableValue, | 102 const InterpolableValue& interpolableValue, |
| 139 const NonInterpolableValue*, | 103 const NonInterpolableValue*, |
| 140 StyleResolverState& state) const { | 104 StyleResolverState& state) const { |
| 141 state.fontBuilder().setWeight( | 105 state.fontBuilder().setWeight( |
| 142 doubleToFontWeight(toInterpolableNumber(interpolableValue).value())); | 106 doubleToFontWeight(toInterpolableNumber(interpolableValue).value())); |
| 143 } | 107 } |
| 144 | 108 |
| 145 } // namespace blink | 109 } // namespace blink |
| OLD | NEW |