| 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 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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 #include "core/css/resolver/StyleBuilderConverter.h" | 27 #include "core/css/resolver/StyleBuilderConverter.h" |
| 28 | 28 |
| 29 #include "core/css/BasicShapeFunctions.h" | 29 #include "core/css/BasicShapeFunctions.h" |
| 30 #include "core/css/CSSBasicShapeValues.h" | 30 #include "core/css/CSSBasicShapeValues.h" |
| 31 #include "core/css/CSSColorValue.h" |
| 31 #include "core/css/CSSContentDistributionValue.h" | 32 #include "core/css/CSSContentDistributionValue.h" |
| 32 #include "core/css/CSSCustomIdentValue.h" | 33 #include "core/css/CSSCustomIdentValue.h" |
| 33 #include "core/css/CSSFontFamilyValue.h" | 34 #include "core/css/CSSFontFamilyValue.h" |
| 34 #include "core/css/CSSFontFeatureValue.h" | 35 #include "core/css/CSSFontFeatureValue.h" |
| 35 #include "core/css/CSSFontVariationValue.h" | 36 #include "core/css/CSSFontVariationValue.h" |
| 36 #include "core/css/CSSFunctionValue.h" | 37 #include "core/css/CSSFunctionValue.h" |
| 37 #include "core/css/CSSGridAutoRepeatValue.h" | 38 #include "core/css/CSSGridAutoRepeatValue.h" |
| 38 #include "core/css/CSSGridLineNamesValue.h" | 39 #include "core/css/CSSGridLineNamesValue.h" |
| 39 #include "core/css/CSSIdentifierValue.h" | 40 #include "core/css/CSSIdentifierValue.h" |
| 40 #include "core/css/CSSPathValue.h" | 41 #include "core/css/CSSPathValue.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 toCSSIdentifierValue(value).getValueID() == CSSValueNone); | 150 toCSSIdentifierValue(value).getValueID() == CSSValueNone); |
| 150 return nullptr; | 151 return nullptr; |
| 151 } | 152 } |
| 152 | 153 |
| 153 FilterOperations StyleBuilderConverter::convertFilterOperations( | 154 FilterOperations StyleBuilderConverter::convertFilterOperations( |
| 154 StyleResolverState& state, | 155 StyleResolverState& state, |
| 155 const CSSValue& value) { | 156 const CSSValue& value) { |
| 156 return FilterOperationResolver::createFilterOperations(state, value); | 157 return FilterOperationResolver::createFilterOperations(state, value); |
| 157 } | 158 } |
| 158 | 159 |
| 160 FilterOperations StyleBuilderConverter::convertOffscreenFilterOperations( |
| 161 const CSSValue& value) { |
| 162 return FilterOperationResolver::createOffscreenFilterOperations(value); |
| 163 } |
| 164 |
| 159 static FontDescription::GenericFamilyType convertGenericFamily( | 165 static FontDescription::GenericFamilyType convertGenericFamily( |
| 160 CSSValueID valueID) { | 166 CSSValueID valueID) { |
| 161 switch (valueID) { | 167 switch (valueID) { |
| 162 case CSSValueWebkitBody: | 168 case CSSValueWebkitBody: |
| 163 return FontDescription::StandardFamily; | 169 return FontDescription::StandardFamily; |
| 164 case CSSValueSerif: | 170 case CSSValueSerif: |
| 165 return FontDescription::SerifFamily; | 171 return FontDescription::SerifFamily; |
| 166 case CSSValueSansSerif: | 172 case CSSValueSansSerif: |
| 167 return FontDescription::SansSerifFamily; | 173 return FontDescription::SansSerifFamily; |
| 168 case CSSValueCursive: | 174 case CSSValueCursive: |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 const CSSValue& value) { | 327 const CSSValue& value) { |
| 322 if (value.isIdentifierValue() && | 328 if (value.isIdentifierValue() && |
| 323 toCSSIdentifierValue(value).getValueID() == CSSValueNone) | 329 toCSSIdentifierValue(value).getValueID() == CSSValueNone) |
| 324 return FontBuilder::initialSizeAdjust(); | 330 return FontBuilder::initialSizeAdjust(); |
| 325 | 331 |
| 326 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value); | 332 const CSSPrimitiveValue& primitiveValue = toCSSPrimitiveValue(value); |
| 327 ASSERT(primitiveValue.isNumber()); | 333 ASSERT(primitiveValue.isNumber()); |
| 328 return primitiveValue.getFloatValue(); | 334 return primitiveValue.getFloatValue(); |
| 329 } | 335 } |
| 330 | 336 |
| 337 double StyleBuilderConverter::convertValueToNumber( |
| 338 const CSSFunctionValue* filter, |
| 339 const CSSPrimitiveValue* value) { |
| 340 switch (filter->functionType()) { |
| 341 case CSSValueGrayscale: |
| 342 case CSSValueSepia: |
| 343 case CSSValueSaturate: |
| 344 case CSSValueInvert: |
| 345 case CSSValueBrightness: |
| 346 case CSSValueContrast: |
| 347 case CSSValueOpacity: { |
| 348 double amount = (filter->functionType() == CSSValueBrightness) ? 0 : 1; |
| 349 if (filter->length() == 1) { |
| 350 amount = value->getDoubleValue(); |
| 351 if (value->isPercentage()) |
| 352 amount /= 100; |
| 353 } |
| 354 return amount; |
| 355 } |
| 356 case CSSValueHueRotate: { |
| 357 double angle = 0; |
| 358 if (filter->length() == 1) |
| 359 angle = value->computeDegrees(); |
| 360 return angle; |
| 361 } |
| 362 default: |
| 363 return 0; |
| 364 } |
| 365 } |
| 366 |
| 331 FontWeight StyleBuilderConverter::convertFontWeight(StyleResolverState& state, | 367 FontWeight StyleBuilderConverter::convertFontWeight(StyleResolverState& state, |
| 332 const CSSValue& value) { | 368 const CSSValue& value) { |
| 333 const CSSIdentifierValue& identifierValue = toCSSIdentifierValue(value); | 369 const CSSIdentifierValue& identifierValue = toCSSIdentifierValue(value); |
| 334 switch (identifierValue.getValueID()) { | 370 switch (identifierValue.getValueID()) { |
| 335 case CSSValueBolder: | 371 case CSSValueBolder: |
| 336 return FontDescription::bolderWeight( | 372 return FontDescription::bolderWeight( |
| 337 state.parentStyle()->getFontDescription().weight()); | 373 state.parentStyle()->getFontDescription().weight()); |
| 338 case CSSValueLighter: | 374 case CSSValueLighter: |
| 339 return FontDescription::lighterWeight( | 375 return FontDescription::lighterWeight( |
| 340 state.parentStyle()->getFontDescription().weight()); | 376 state.parentStyle()->getFontDescription().weight()); |
| (...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 LengthSize StyleBuilderConverter::convertRadius(StyleResolverState& state, | 1029 LengthSize StyleBuilderConverter::convertRadius(StyleResolverState& state, |
| 994 const CSSValue& value) { | 1030 const CSSValue& value) { |
| 995 const CSSValuePair& pair = toCSSValuePair(value); | 1031 const CSSValuePair& pair = toCSSValuePair(value); |
| 996 Length radiusWidth = toCSSPrimitiveValue(pair.first()) | 1032 Length radiusWidth = toCSSPrimitiveValue(pair.first()) |
| 997 .convertToLength(state.cssToLengthConversionData()); | 1033 .convertToLength(state.cssToLengthConversionData()); |
| 998 Length radiusHeight = toCSSPrimitiveValue(pair.second()) | 1034 Length radiusHeight = toCSSPrimitiveValue(pair.second()) |
| 999 .convertToLength(state.cssToLengthConversionData()); | 1035 .convertToLength(state.cssToLengthConversionData()); |
| 1000 return LengthSize(radiusWidth, radiusHeight); | 1036 return LengthSize(radiusWidth, radiusHeight); |
| 1001 } | 1037 } |
| 1002 | 1038 |
| 1003 ShadowData StyleBuilderConverter::convertShadow(StyleResolverState& state, | 1039 ShadowData StyleBuilderConverter::convertShadow( |
| 1004 const CSSValue& value) { | 1040 const CSSToLengthConversionData& conversionData, |
| 1041 StyleResolverState* state, |
| 1042 const CSSValue& value) { |
| 1005 const CSSShadowValue& shadow = toCSSShadowValue(value); | 1043 const CSSShadowValue& shadow = toCSSShadowValue(value); |
| 1006 float x = shadow.x->computeLength<float>(state.cssToLengthConversionData()); | 1044 float x = shadow.x->computeLength<float>(conversionData); |
| 1007 float y = shadow.y->computeLength<float>(state.cssToLengthConversionData()); | 1045 float y = shadow.y->computeLength<float>(conversionData); |
| 1008 float blur = | 1046 float blur = |
| 1009 shadow.blur | 1047 shadow.blur ? shadow.blur->computeLength<float>(conversionData) : 0; |
| 1010 ? shadow.blur->computeLength<float>(state.cssToLengthConversionData()) | 1048 float spread = |
| 1011 : 0; | 1049 shadow.spread ? shadow.spread->computeLength<float>(conversionData) : 0; |
| 1012 float spread = shadow.spread | |
| 1013 ? shadow.spread->computeLength<float>( | |
| 1014 state.cssToLengthConversionData()) | |
| 1015 : 0; | |
| 1016 ShadowStyle shadowStyle = | 1050 ShadowStyle shadowStyle = |
| 1017 shadow.style && shadow.style->getValueID() == CSSValueInset ? Inset | 1051 shadow.style && shadow.style->getValueID() == CSSValueInset ? Inset |
| 1018 : Normal; | 1052 : Normal; |
| 1019 StyleColor color = StyleColor::currentColor(); | 1053 StyleColor color = StyleColor::currentColor(); |
| 1020 if (shadow.color) | 1054 if (shadow.color) { |
| 1021 color = convertStyleColor(state, *shadow.color); | 1055 if (state) { |
| 1056 color = convertStyleColor(*state, *shadow.color); |
| 1057 } else { |
| 1058 // For OffScreen canvas, we default to black and only parse non |
| 1059 // Document dependent CSS colors. |
| 1060 color = StyleColor(Color::black); |
| 1061 if (shadow.color->isColorValue()) { |
| 1062 color = toCSSColorValue(*shadow.color).value(); |
| 1063 } else { |
| 1064 CSSValueID valueID = toCSSIdentifierValue(*shadow.color).getValueID(); |
| 1065 switch (valueID) { |
| 1066 case CSSValueInvalid: |
| 1067 NOTREACHED(); |
| 1068 case CSSValueInternalQuirkInherit: |
| 1069 case CSSValueWebkitLink: |
| 1070 case CSSValueWebkitActivelink: |
| 1071 case CSSValueWebkitFocusRingColor: |
| 1072 case CSSValueCurrentcolor: |
| 1073 break; |
| 1074 default: |
| 1075 color = StyleColor::colorFromKeyword(valueID); |
| 1076 } |
| 1077 } |
| 1078 } |
| 1079 } |
| 1080 |
| 1022 return ShadowData(FloatPoint(x, y), blur, spread, shadowStyle, color); | 1081 return ShadowData(FloatPoint(x, y), blur, spread, shadowStyle, color); |
| 1023 } | 1082 } |
| 1024 | 1083 |
| 1025 PassRefPtr<ShadowList> StyleBuilderConverter::convertShadowList( | 1084 PassRefPtr<ShadowList> StyleBuilderConverter::convertShadowList( |
| 1026 StyleResolverState& state, | 1085 StyleResolverState& state, |
| 1027 const CSSValue& value) { | 1086 const CSSValue& value) { |
| 1028 if (value.isIdentifierValue()) { | 1087 if (value.isIdentifierValue()) { |
| 1029 DCHECK_EQ(toCSSIdentifierValue(value).getValueID(), CSSValueNone); | 1088 DCHECK_EQ(toCSSIdentifierValue(value).getValueID(), CSSValueNone); |
| 1030 return PassRefPtr<ShadowList>(); | 1089 return PassRefPtr<ShadowList>(); |
| 1031 } | 1090 } |
| 1032 | 1091 |
| 1033 ShadowDataVector shadows; | 1092 ShadowDataVector shadows; |
| 1034 for (const auto& item : toCSSValueList(value)) | 1093 for (const auto& item : toCSSValueList(value)) { |
| 1035 shadows.push_back(convertShadow(state, *item)); | 1094 shadows.push_back( |
| 1095 convertShadow(state.cssToLengthConversionData(), &state, *item)); |
| 1096 } |
| 1036 | 1097 |
| 1037 return ShadowList::adopt(shadows); | 1098 return ShadowList::adopt(shadows); |
| 1038 } | 1099 } |
| 1039 | 1100 |
| 1040 ShapeValue* StyleBuilderConverter::convertShapeValue(StyleResolverState& state, | 1101 ShapeValue* StyleBuilderConverter::convertShapeValue(StyleResolverState& state, |
| 1041 const CSSValue& value) { | 1102 const CSSValue& value) { |
| 1042 if (value.isIdentifierValue()) { | 1103 if (value.isIdentifierValue()) { |
| 1043 DCHECK_EQ(toCSSIdentifierValue(value).getValueID(), CSSValueNone); | 1104 DCHECK_EQ(toCSSIdentifierValue(value).getValueID(), CSSValueNone); |
| 1044 return nullptr; | 1105 return nullptr; |
| 1045 } | 1106 } |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1324 } | 1385 } |
| 1325 | 1386 |
| 1326 const CSSValue& StyleBuilderConverter::convertRegisteredPropertyValue( | 1387 const CSSValue& StyleBuilderConverter::convertRegisteredPropertyValue( |
| 1327 const StyleResolverState& state, | 1388 const StyleResolverState& state, |
| 1328 const CSSValue& value) { | 1389 const CSSValue& value) { |
| 1329 return computeRegisteredPropertyValue(state.cssToLengthConversionData(), | 1390 return computeRegisteredPropertyValue(state.cssToLengthConversionData(), |
| 1330 value); | 1391 value); |
| 1331 } | 1392 } |
| 1332 | 1393 |
| 1333 } // namespace blink | 1394 } // namespace blink |
| OLD | NEW |