Chromium Code Reviews| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 if (primitiveValue->getValueID() == CSSValueMaxContent) | 52 if (primitiveValue->getValueID() == CSSValueMaxContent) |
| 53 return Length(MaxContent); | 53 return Length(MaxContent); |
| 54 | 54 |
| 55 // Fractional unit. | 55 // Fractional unit. |
| 56 if (primitiveValue->isFlex()) | 56 if (primitiveValue->isFlex()) |
| 57 return GridLength(primitiveValue->getDoubleValue()); | 57 return GridLength(primitiveValue->getDoubleValue()); |
| 58 | 58 |
| 59 return StyleBuilderConverter::convertLengthOrAuto(state, primitiveValue); | 59 return StyleBuilderConverter::convertLengthOrAuto(state, primitiveValue); |
| 60 } | 60 } |
| 61 | 61 |
| 62 template <CSSValueID cssValueFor0, CSSValueID cssValueFor100> | |
| 63 static Length convertPositionLength(StyleResolverState& state, CSSPrimitiveValue * primitiveValue) | |
| 64 { | |
| 65 if (Pair* pair = primitiveValue->getPairValue()) { | |
| 66 Length length = StyleBuilderConverter::convertLength(state, pair->second ()); | |
| 67 if (pair->first()->getValueID() == cssValueFor0) | |
| 68 return length; | |
| 69 ASSERT(pair->first()->getValueID() == cssValueFor100); | |
| 70 return length.subtractFromOneHundredPercent(); | |
| 71 } | |
| 72 | |
| 73 return StyleBuilderConverter::convertLength(state, primitiveValue); | |
| 74 } | |
| 75 | |
| 76 static LengthSize convertSnapCoordinatePair(StyleResolverState& state, CSSValue* value) | |
|
Timothy Loh
2015/05/28 07:09:27
I don't think anyone on Blink feels strongly about
majidvp
2015/06/01 20:06:37
Used convertPosition for both.
| |
| 77 { | |
| 78 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); | |
| 79 Pair* pair = primitiveValue->getPairValue(); | |
| 80 return LengthSize( | |
| 81 convertPositionLength<CSSValueLeft, CSSValueRight>(state, pair->first()) , | |
| 82 convertPositionLength<CSSValueTop, CSSValueBottom>(state, pair->second() ) | |
| 83 ); | |
| 84 } | |
| 85 | |
| 86 | |
| 62 } // namespace | 87 } // namespace |
| 63 | 88 |
| 64 PassRefPtr<StyleReflection> StyleBuilderConverter::convertBoxReflect(StyleResolv erState& state, CSSValue* value) | 89 PassRefPtr<StyleReflection> StyleBuilderConverter::convertBoxReflect(StyleResolv erState& state, CSSValue* value) |
| 65 { | 90 { |
| 66 if (value->isPrimitiveValue()) { | 91 if (value->isPrimitiveValue()) { |
| 67 ASSERT(toCSSPrimitiveValue(value)->getValueID() == CSSValueNone); | 92 ASSERT(toCSSPrimitiveValue(value)->getValueID() == CSSValueNone); |
| 68 return ComputedStyle::initialBoxReflect(); | 93 return ComputedStyle::initialBoxReflect(); |
| 69 } | 94 } |
| 70 | 95 |
| 71 CSSReflectValue* reflectValue = toCSSReflectValue(value); | 96 CSSReflectValue* reflectValue = toCSSReflectValue(value); |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 628 | 653 |
| 629 float StyleBuilderConverter::convertNumberOrPercentage(StyleResolverState& state , CSSValue* value) | 654 float StyleBuilderConverter::convertNumberOrPercentage(StyleResolverState& state , CSSValue* value) |
| 630 { | 655 { |
| 631 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); | 656 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); |
| 632 ASSERT(primitiveValue->isNumber() || primitiveValue->isPercentage()); | 657 ASSERT(primitiveValue->isNumber() || primitiveValue->isPercentage()); |
| 633 if (primitiveValue->isNumber()) | 658 if (primitiveValue->isNumber()) |
| 634 return primitiveValue->getFloatValue(); | 659 return primitiveValue->getFloatValue(); |
| 635 return primitiveValue->getFloatValue() / 100.0f; | 660 return primitiveValue->getFloatValue() / 100.0f; |
| 636 } | 661 } |
| 637 | 662 |
| 638 template <CSSValueID cssValueFor0, CSSValueID cssValueFor100> | |
| 639 static Length convertPositionLength(StyleResolverState& state, CSSPrimitiveValue * primitiveValue) | |
| 640 { | |
| 641 if (Pair* pair = primitiveValue->getPairValue()) { | |
| 642 Length length = StyleBuilderConverter::convertLength(state, pair->second ()); | |
| 643 if (pair->first()->getValueID() == cssValueFor0) | |
| 644 return length; | |
| 645 ASSERT(pair->first()->getValueID() == cssValueFor100); | |
| 646 return length.subtractFromOneHundredPercent(); | |
| 647 } | |
| 648 | |
| 649 return StyleBuilderConverter::convertLength(state, primitiveValue); | |
| 650 } | |
| 651 | |
| 652 LengthPoint StyleBuilderConverter::convertObjectPosition(StyleResolverState& sta te, CSSValue* value) | 663 LengthPoint StyleBuilderConverter::convertObjectPosition(StyleResolverState& sta te, CSSValue* value) |
| 653 { | 664 { |
| 654 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); | 665 CSSPrimitiveValue* primitiveValue = toCSSPrimitiveValue(value); |
| 655 Pair* pair = primitiveValue->getPairValue(); | 666 Pair* pair = primitiveValue->getPairValue(); |
| 656 return LengthPoint( | 667 return LengthPoint( |
| 657 convertPositionLength<CSSValueLeft, CSSValueRight>(state, pair->first()) , | 668 convertPositionLength<CSSValueLeft, CSSValueRight>(state, pair->first()) , |
| 658 convertPositionLength<CSSValueTop, CSSValueBottom>(state, pair->second() ) | 669 convertPositionLength<CSSValueTop, CSSValueBottom>(state, pair->second() ) |
| 659 ); | 670 ); |
| 660 } | 671 } |
| 661 | 672 |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 894 CSSPrimitiveValue* primitiveValueY = toCSSPrimitiveValue(list->item(1)); | 905 CSSPrimitiveValue* primitiveValueY = toCSSPrimitiveValue(list->item(1)); |
| 895 CSSPrimitiveValue* primitiveValueZ = toCSSPrimitiveValue(list->item(2)); | 906 CSSPrimitiveValue* primitiveValueZ = toCSSPrimitiveValue(list->item(2)); |
| 896 | 907 |
| 897 return TransformOrigin( | 908 return TransformOrigin( |
| 898 convertOriginLength<CSSValueLeft, CSSValueRight>(state, primitiveValueX) , | 909 convertOriginLength<CSSValueLeft, CSSValueRight>(state, primitiveValueX) , |
| 899 convertOriginLength<CSSValueTop, CSSValueBottom>(state, primitiveValueY) , | 910 convertOriginLength<CSSValueTop, CSSValueBottom>(state, primitiveValueY) , |
| 900 StyleBuilderConverter::convertComputedLength<float>(state, primitiveValu eZ) | 911 StyleBuilderConverter::convertComputedLength<float>(state, primitiveValu eZ) |
| 901 ); | 912 ); |
| 902 } | 913 } |
| 903 | 914 |
| 915 ScrollSnapPoints StyleBuilderConverter::convertSnapPoints(StyleResolverState& st ate, CSSValue* value) | |
| 916 { | |
| 917 // Handles: none | repeat(<length>) | |
| 918 ScrollSnapPoints points; | |
| 919 points.hasRepeat = false; | |
| 920 | |
| 921 if (!value->isFunctionValue()) { | |
| 922 return points; | |
| 923 } | |
|
Timothy Loh
2015/05/28 07:09:27
Nit: No need for braces on single-line ifs
majidvp
2015/06/01 20:06:37
Done.
| |
| 924 | |
| 925 if (CSSFunctionValue* repeatFunction = toCSSFunctionValue(value)) { | |
|
Timothy Loh
2015/05/28 07:09:27
I don't think the condition is ever false here?
majidvp
2015/06/01 20:06:37
Done.
| |
| 926 ASSERT_WITH_SECURITY_IMPLICATION(repeatFunction->length() == 1); | |
| 927 points.repeatOffset = convertLength(state, toCSSPrimitiveValue(repeatFun ction->item(0))); | |
| 928 points.hasRepeat = true; | |
| 929 } | |
| 930 | |
| 931 return points; | |
| 932 } | |
| 933 | |
| 934 Vector<LengthSize> StyleBuilderConverter::convertSnapCoordinates(StyleResolverSt ate& state, CSSValue* value) | |
| 935 { | |
| 936 // Handles: none | <position># | |
| 937 Vector<LengthSize> coordinates; | |
| 938 | |
| 939 if (!value->isValueList()) | |
| 940 return coordinates; | |
| 941 | |
| 942 CSSValueList* valueList = toCSSValueList(value); | |
| 943 coordinates.reserveInitialCapacity(valueList->length()); | |
| 944 for (auto& snapCoordinate : *valueList) { | |
| 945 coordinates.uncheckedAppend(convertSnapCoordinatePair(state, snapCoordin ate.get())); | |
| 946 } | |
| 947 | |
| 948 return coordinates; | |
| 949 } | |
| 950 | |
| 951 LengthSize StyleBuilderConverter::convertSnapDestination(StyleResolverState& sta te, CSSValue* value) | |
| 952 { | |
| 953 return convertSnapCoordinatePair(state, value); | |
| 954 } | |
| 955 | |
| 956 | |
| 904 } // namespace blink | 957 } // namespace blink |
| OLD | NEW |