Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "core/css/properties/CSSPropertyAPITransform.h" | |
| 6 | |
| 7 #include "core/css/CSSFunctionValue.h" | |
| 8 #include "core/css/CSSValueList.h" | |
| 9 #include "core/css/parser/CSSParserContext.h" | |
| 10 #include "core/css/parser/CSSPropertyParserHelpers.h" | |
| 11 #include "platform/Length.h" | |
| 12 | |
| 13 namespace blink { | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 bool ConsumeNumbers(CSSParserTokenRange& args, | |
| 18 CSSFunctionValue*& transform_value, | |
| 19 unsigned number_of_arguments) { | |
| 20 do { | |
| 21 CSSValue* parsed_value = | |
| 22 CSSPropertyParserHelpers::ConsumeNumber(args, kValueRangeAll); | |
| 23 if (!parsed_value) | |
| 24 return false; | |
| 25 transform_value->Append(*parsed_value); | |
| 26 if (--number_of_arguments && | |
| 27 !CSSPropertyParserHelpers::ConsumeCommaIncludingWhitespace(args)) | |
|
alancutter (OOO until 2018)
2017/04/20 03:33:12
Let's give multiline ifs braces in this file (and
Bugs Nash
2017/04/20 04:01:51
Done.
| |
| 28 return false; | |
| 29 } while (number_of_arguments); | |
| 30 return true; | |
| 31 } | |
| 32 | |
| 33 bool ConsumePerspective(CSSParserTokenRange& args, | |
| 34 const CSSParserContext* context, | |
| 35 CSSFunctionValue*& transform_value, | |
| 36 bool use_legacy_parsing) { | |
| 37 CSSPrimitiveValue* parsed_value = CSSPropertyParserHelpers::ConsumeLength( | |
| 38 args, context->Mode(), kValueRangeNonNegative); | |
| 39 if (!parsed_value && use_legacy_parsing) { | |
| 40 double perspective; | |
| 41 if (!CSSPropertyParserHelpers::ConsumeNumberRaw(args, perspective) || | |
| 42 perspective < 0) | |
| 43 return false; | |
| 44 context->Count(UseCounter::kUnitlessPerspectiveInTransformProperty); | |
| 45 parsed_value = CSSPrimitiveValue::Create( | |
| 46 perspective, CSSPrimitiveValue::UnitType::kPixels); | |
| 47 } | |
| 48 if (!parsed_value) | |
| 49 return false; | |
| 50 transform_value->Append(*parsed_value); | |
| 51 return true; | |
| 52 } | |
| 53 | |
| 54 bool ConsumeTranslate3d(CSSParserTokenRange& args, | |
| 55 CSSParserMode css_parser_mode, | |
| 56 CSSFunctionValue*& transform_value) { | |
| 57 unsigned number_of_arguments = 2; | |
| 58 CSSValue* parsed_value = nullptr; | |
| 59 do { | |
| 60 parsed_value = CSSPropertyParserHelpers::ConsumeLengthOrPercent( | |
| 61 args, css_parser_mode, kValueRangeAll); | |
| 62 if (!parsed_value) | |
| 63 return false; | |
| 64 transform_value->Append(*parsed_value); | |
| 65 if (!CSSPropertyParserHelpers::ConsumeCommaIncludingWhitespace(args)) | |
| 66 return false; | |
| 67 } while (--number_of_arguments); | |
| 68 parsed_value = CSSPropertyParserHelpers::ConsumeLength(args, css_parser_mode, | |
| 69 kValueRangeAll); | |
| 70 if (!parsed_value) | |
| 71 return false; | |
| 72 transform_value->Append(*parsed_value); | |
| 73 return true; | |
| 74 } | |
| 75 | |
| 76 CSSValue* ConsumeTransformValue(CSSParserTokenRange& range, | |
| 77 const CSSParserContext* context, | |
| 78 bool use_legacy_parsing) { | |
| 79 CSSValueID function_id = range.Peek().FunctionId(); | |
| 80 if (function_id == CSSValueInvalid) | |
| 81 return nullptr; | |
| 82 CSSParserTokenRange args = CSSPropertyParserHelpers::ConsumeFunction(range); | |
| 83 if (args.AtEnd()) | |
| 84 return nullptr; | |
| 85 CSSFunctionValue* transform_value = CSSFunctionValue::Create(function_id); | |
| 86 CSSValue* parsed_value = nullptr; | |
| 87 switch (function_id) { | |
| 88 case CSSValueRotate: | |
| 89 case CSSValueRotateX: | |
| 90 case CSSValueRotateY: | |
| 91 case CSSValueRotateZ: | |
| 92 case CSSValueSkewX: | |
| 93 case CSSValueSkewY: | |
| 94 case CSSValueSkew: | |
| 95 parsed_value = CSSPropertyParserHelpers::ConsumeAngle(args); | |
| 96 if (!parsed_value) | |
| 97 return nullptr; | |
| 98 if (function_id == CSSValueSkew && | |
| 99 CSSPropertyParserHelpers::ConsumeCommaIncludingWhitespace(args)) { | |
| 100 transform_value->Append(*parsed_value); | |
| 101 parsed_value = CSSPropertyParserHelpers::ConsumeAngle(args); | |
| 102 if (!parsed_value) | |
| 103 return nullptr; | |
| 104 } | |
| 105 break; | |
| 106 case CSSValueScaleX: | |
| 107 case CSSValueScaleY: | |
| 108 case CSSValueScaleZ: | |
| 109 case CSSValueScale: | |
| 110 parsed_value = | |
| 111 CSSPropertyParserHelpers::ConsumeNumber(args, kValueRangeAll); | |
| 112 if (!parsed_value) | |
| 113 return nullptr; | |
| 114 if (function_id == CSSValueScale && | |
| 115 CSSPropertyParserHelpers::ConsumeCommaIncludingWhitespace(args)) { | |
| 116 transform_value->Append(*parsed_value); | |
| 117 parsed_value = | |
| 118 CSSPropertyParserHelpers::ConsumeNumber(args, kValueRangeAll); | |
| 119 if (!parsed_value) | |
| 120 return nullptr; | |
| 121 } | |
| 122 break; | |
| 123 case CSSValuePerspective: | |
| 124 if (!ConsumePerspective(args, context, transform_value, | |
| 125 use_legacy_parsing)) | |
| 126 return nullptr; | |
| 127 break; | |
| 128 case CSSValueTranslateX: | |
| 129 case CSSValueTranslateY: | |
| 130 case CSSValueTranslate: | |
| 131 parsed_value = CSSPropertyParserHelpers::ConsumeLengthOrPercent( | |
| 132 args, context->Mode(), kValueRangeAll); | |
| 133 if (!parsed_value) | |
| 134 return nullptr; | |
| 135 if (function_id == CSSValueTranslate && | |
| 136 CSSPropertyParserHelpers::ConsumeCommaIncludingWhitespace(args)) { | |
| 137 transform_value->Append(*parsed_value); | |
| 138 parsed_value = CSSPropertyParserHelpers::ConsumeLengthOrPercent( | |
| 139 args, context->Mode(), kValueRangeAll); | |
| 140 if (!parsed_value) | |
| 141 return nullptr; | |
| 142 } | |
| 143 break; | |
| 144 case CSSValueTranslateZ: | |
| 145 parsed_value = CSSPropertyParserHelpers::ConsumeLength( | |
| 146 args, context->Mode(), kValueRangeAll); | |
| 147 break; | |
| 148 case CSSValueMatrix: | |
| 149 case CSSValueMatrix3d: | |
| 150 if (!ConsumeNumbers(args, transform_value, | |
| 151 (function_id == CSSValueMatrix3d) ? 16 : 6)) | |
| 152 return nullptr; | |
| 153 break; | |
| 154 case CSSValueScale3d: | |
| 155 if (!ConsumeNumbers(args, transform_value, 3)) | |
| 156 return nullptr; | |
| 157 break; | |
| 158 case CSSValueRotate3d: | |
| 159 if (!ConsumeNumbers(args, transform_value, 3) || | |
| 160 !CSSPropertyParserHelpers::ConsumeCommaIncludingWhitespace(args)) | |
| 161 return nullptr; | |
| 162 parsed_value = CSSPropertyParserHelpers::ConsumeAngle(args); | |
| 163 if (!parsed_value) | |
| 164 return nullptr; | |
| 165 break; | |
| 166 case CSSValueTranslate3d: | |
| 167 if (!ConsumeTranslate3d(args, context->Mode(), transform_value)) | |
| 168 return nullptr; | |
| 169 break; | |
| 170 default: | |
| 171 return nullptr; | |
| 172 } | |
| 173 if (parsed_value) | |
| 174 transform_value->Append(*parsed_value); | |
| 175 if (!args.AtEnd()) | |
| 176 return nullptr; | |
| 177 return transform_value; | |
| 178 } | |
| 179 | |
| 180 } // namespace | |
| 181 | |
| 182 const CSSValue* CSSPropertyAPITransform::parseSingleValue( | |
| 183 CSSParserTokenRange& range, | |
| 184 const CSSParserContext& context, | |
| 185 CSSPropertyID unresolved_property) { | |
| 186 if (range.Peek().Id() == CSSValueNone) | |
| 187 return CSSPropertyParserHelpers::ConsumeIdent(range); | |
| 188 | |
| 189 CSSValueList* list = CSSValueList::CreateSpaceSeparated(); | |
| 190 do { | |
| 191 CSSValue* parsed_transform_value = ConsumeTransformValue( | |
| 192 range, &context, | |
| 193 unresolved_property == CSSPropertyAliasWebkitTransform); | |
| 194 if (!parsed_transform_value) | |
| 195 return nullptr; | |
| 196 list->Append(*parsed_transform_value); | |
| 197 } while (!range.AtEnd()); | |
| 198 | |
| 199 return list; | |
| 200 } | |
| 201 | |
| 202 } // namespace blink | |
| OLD | NEW |