Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: third_party/WebKit/Source/core/css/parser/LegacyCSSPropertyParser.cpp

Issue 1421963006: Move transform property into CSSPropertyParser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: V3 Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 2003 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved. 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com> 5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> 6 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
8 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. 8 * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved.
9 * Copyright (C) 2012 Intel Corporation. All rights reserved. 9 * Copyright (C) 2012 Intel Corporation. All rights reserved.
10 * 10 *
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 else 766 else
767 validPrimitive = validUnit(value, FLength | FPercent | FNonNeg); 767 validPrimitive = validUnit(value, FLength | FPercent | FNonNeg);
768 break; 768 break;
769 case CSSPropertyFlexGrow: 769 case CSSPropertyFlexGrow:
770 case CSSPropertyFlexShrink: 770 case CSSPropertyFlexShrink:
771 validPrimitive = validUnit(value, FNumber | FNonNeg); 771 validPrimitive = validUnit(value, FNumber | FNonNeg);
772 break; 772 break;
773 case CSSPropertyOrder: 773 case CSSPropertyOrder:
774 validPrimitive = validUnit(value, FInteger); 774 validPrimitive = validUnit(value, FInteger);
775 break; 775 break;
776 case CSSPropertyTransform:
777 if (id == CSSValueNone)
778 validPrimitive = true;
779 else
780 parsedValue = parseTransform(unresolvedProperty == CSSPropertyAliasW ebkitTransform);
781 break;
782 case CSSPropertyTransformOrigin: { 776 case CSSPropertyTransformOrigin: {
783 RefPtrWillBeRawPtr<CSSValueList> list = parseTransformOrigin(); 777 RefPtrWillBeRawPtr<CSSValueList> list = parseTransformOrigin();
784 if (!list) 778 if (!list)
785 return false; 779 return false;
786 // These values are added to match gecko serialization. 780 // These values are added to match gecko serialization.
787 if (list->length() == 1) 781 if (list->length() == 1)
788 list->append(cssValuePool().createValue(50, CSSPrimitiveValue::UnitT ype::Percentage)); 782 list->append(cssValuePool().createValue(50, CSSPrimitiveValue::UnitT ype::Percentage));
789 if (list->length() == 2) 783 if (list->length() == 2)
790 list->append(cssValuePool().createValue(0, CSSPrimitiveValue::UnitTy pe::Pixels)); 784 list->append(cssValuePool().createValue(0, CSSPrimitiveValue::UnitTy pe::Pixels));
791 addProperty(propId, list.release(), important); 785 addProperty(propId, list.release(), important);
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
1165 case CSSPropertyWebkitBorderEndWidth: 1159 case CSSPropertyWebkitBorderEndWidth:
1166 case CSSPropertyWebkitBorderBeforeWidth: 1160 case CSSPropertyWebkitBorderBeforeWidth:
1167 case CSSPropertyWebkitBorderAfterWidth: 1161 case CSSPropertyWebkitBorderAfterWidth:
1168 case CSSPropertyWebkitBorderStart: 1162 case CSSPropertyWebkitBorderStart:
1169 case CSSPropertyWebkitBorderEnd: 1163 case CSSPropertyWebkitBorderEnd:
1170 case CSSPropertyWebkitBorderBefore: 1164 case CSSPropertyWebkitBorderBefore:
1171 case CSSPropertyWebkitBorderAfter: 1165 case CSSPropertyWebkitBorderAfter:
1172 case CSSPropertyWebkitTextStroke: 1166 case CSSPropertyWebkitTextStroke:
1173 case CSSPropertyWebkitTextStrokeColor: 1167 case CSSPropertyWebkitTextStrokeColor:
1174 case CSSPropertyWebkitTextStrokeWidth: 1168 case CSSPropertyWebkitTextStrokeWidth:
1169 case CSSPropertyTransform:
1175 validPrimitive = false; 1170 validPrimitive = false;
1176 break; 1171 break;
1177 1172
1178 case CSSPropertyScrollSnapPointsX: 1173 case CSSPropertyScrollSnapPointsX:
1179 case CSSPropertyScrollSnapPointsY: 1174 case CSSPropertyScrollSnapPointsY:
1180 parsedValue = parseScrollSnapPoints(); 1175 parsedValue = parseScrollSnapPoints();
1181 break; 1176 break;
1182 case CSSPropertyScrollSnapCoordinate: 1177 case CSSPropertyScrollSnapCoordinate:
1183 parsedValue = parseScrollSnapCoordinate(); 1178 parsedValue = parseScrollSnapCoordinate();
1184 break; 1179 break;
(...skipping 4500 matching lines...) Expand 10 before | Expand all | Expand 10 after
5685 paintOrderList->append(stroke.release()); 5680 paintOrderList->append(stroke.release());
5686 } 5681 }
5687 break; 5682 break;
5688 default: 5683 default:
5689 ASSERT_NOT_REACHED(); 5684 ASSERT_NOT_REACHED();
5690 } 5685 }
5691 5686
5692 return paintOrderList.release(); 5687 return paintOrderList.release();
5693 } 5688 }
5694 5689
5695 class TransformOperationInfo {
5696 public:
5697 TransformOperationInfo(CSSValueID id)
5698 : m_validID(true)
5699 , m_allowSingleArgument(false)
5700 , m_argCount(1)
5701 , m_unit(CSSPropertyParser::FUnknown)
5702 {
5703 switch (id) {
5704 case CSSValueSkew:
5705 m_unit = CSSPropertyParser::FAngle;
5706 m_allowSingleArgument = true;
5707 m_argCount = 3;
5708 break;
5709 case CSSValueScale:
5710 m_unit = CSSPropertyParser::FNumber;
5711 m_allowSingleArgument = true;
5712 m_argCount = 3;
5713 break;
5714 case CSSValueSkewX:
5715 m_unit = CSSPropertyParser::FAngle;
5716 break;
5717 case CSSValueSkewY:
5718 m_unit = CSSPropertyParser::FAngle;
5719 break;
5720 case CSSValueMatrix:
5721 m_unit = CSSPropertyParser::FNumber;
5722 m_argCount = 11;
5723 break;
5724 case CSSValueRotate:
5725 m_unit = CSSPropertyParser::FAngle;
5726 break;
5727 case CSSValueScaleX:
5728 m_unit = CSSPropertyParser::FNumber;
5729 break;
5730 case CSSValueScaleY:
5731 m_unit = CSSPropertyParser::FNumber;
5732 break;
5733 case CSSValueScaleZ:
5734 m_unit = CSSPropertyParser::FNumber;
5735 break;
5736 case CSSValueScale3d:
5737 m_unit = CSSPropertyParser::FNumber;
5738 m_argCount = 5;
5739 break;
5740 case CSSValueRotateX:
5741 m_unit = CSSPropertyParser::FAngle;
5742 break;
5743 case CSSValueRotateY:
5744 m_unit = CSSPropertyParser::FAngle;
5745 break;
5746 case CSSValueRotateZ:
5747 m_unit = CSSPropertyParser::FAngle;
5748 break;
5749 case CSSValueMatrix3d:
5750 m_unit = CSSPropertyParser::FNumber;
5751 m_argCount = 31;
5752 break;
5753 case CSSValueRotate3d:
5754 m_unit = CSSPropertyParser::FNumber;
5755 m_argCount = 7;
5756 break;
5757 case CSSValueTranslate:
5758 m_unit = CSSPropertyParser::FLength | CSSPropertyParser::FPercent;
5759 m_allowSingleArgument = true;
5760 m_argCount = 3;
5761 break;
5762 case CSSValueTranslateX:
5763 m_unit = CSSPropertyParser::FLength | CSSPropertyParser::FPercent;
5764 break;
5765 case CSSValueTranslateY:
5766 m_unit = CSSPropertyParser::FLength | CSSPropertyParser::FPercent;
5767 break;
5768 case CSSValueTranslateZ:
5769 m_unit = CSSPropertyParser::FLength | CSSPropertyParser::FPercent;
5770 break;
5771 case CSSValuePerspective:
5772 m_unit = CSSPropertyParser::FNumber;
5773 break;
5774 case CSSValueTranslate3d:
5775 m_unit = CSSPropertyParser::FLength | CSSPropertyParser::FPercent;
5776 m_argCount = 5;
5777 break;
5778 default:
5779 m_validID = false;
5780 break;
5781 }
5782 }
5783
5784 bool validID() const { return m_validID; }
5785 unsigned argCount() const { return m_argCount; }
5786 CSSPropertyParser::Units unit() const { return m_unit; }
5787
5788 bool hasCorrectArgCount(unsigned argCount) { return m_argCount == argCount | | (m_allowSingleArgument && argCount == 1); }
5789
5790 private:
5791 bool m_validID;
5792 bool m_allowSingleArgument;
5793 unsigned m_argCount;
5794 CSSPropertyParser::Units m_unit;
5795 };
5796
5797 PassRefPtrWillBeRawPtr<CSSValueList> CSSPropertyParser::parseTransform(bool useL egacyParsing)
5798 {
5799 if (!m_valueList)
5800 return nullptr;
5801
5802 RefPtrWillBeRawPtr<CSSValueList> list = CSSValueList::createSpaceSeparated() ;
5803 for (CSSParserValue* value = m_valueList->current(); value; value = m_valueL ist->next()) {
5804 RefPtrWillBeRawPtr<CSSValue> parsedTransformValue = parseTransformValue( useLegacyParsing, value);
5805 if (!parsedTransformValue)
5806 return nullptr;
5807
5808 list->append(parsedTransformValue.release());
5809 }
5810
5811 return list.release();
5812 }
5813
5814 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseTransformValue(bool use LegacyParsing, CSSParserValue *value)
5815 {
5816 if (value->m_unit != CSSParserValue::Function || !value->function)
5817 return nullptr;
5818
5819 // Every primitive requires at least one argument.
5820 CSSParserValueList* args = value->function->args.get();
5821 if (!args)
5822 return nullptr;
5823
5824 // See if the specified primitive is one we understand.
5825 CSSValueID type = value->function->id;
5826 TransformOperationInfo info(type);
5827 if (!info.validID())
5828 return nullptr;
5829
5830 if (!info.hasCorrectArgCount(args->size()))
5831 return nullptr;
5832
5833 // The transform is a list of functional primitives that specify transform o perations.
5834 // We collect a list of CSSFunctionValues, where each value specifies a sing le operation.
5835
5836 // Create the new CSSFunctionValue for this operation and add it to our list .
5837 RefPtrWillBeRawPtr<CSSFunctionValue> transformValue = CSSFunctionValue::crea te(type);
5838
5839 // Snag our values.
5840 CSSParserValue* a = args->current();
5841 unsigned argNumber = 0;
5842 while (a) {
5843 CSSPropertyParser::Units unit = info.unit();
5844
5845 if (type == CSSValueRotate3d && argNumber == 3) {
5846 // 4th param of rotate3d() is an angle rather than a bare number, va lidate it as such
5847 if (!validUnit(a, FAngle, HTMLStandardMode))
5848 return nullptr;
5849 } else if (type == CSSValueTranslate3d && argNumber == 2) {
5850 // 3rd param of translate3d() cannot be a percentage
5851 if (!validUnit(a, FLength, HTMLStandardMode))
5852 return nullptr;
5853 } else if (type == CSSValueTranslateZ && !argNumber) {
5854 // 1st param of translateZ() cannot be a percentage
5855 if (!validUnit(a, FLength, HTMLStandardMode))
5856 return nullptr;
5857 } else if (type == CSSValuePerspective && !argNumber) {
5858 // 1st param of perspective() must be a non-negative number (depreca ted) or length.
5859 if (!validUnit(a, FLength | FNonNeg, HTMLStandardMode)) {
5860 if (useLegacyParsing && validUnit(a, FNumber | FNonNeg, HTMLStan dardMode)) {
5861 a->setUnit(CSSPrimitiveValue::UnitType::Pixels);
5862 } else {
5863 return nullptr;
5864 }
5865 }
5866 } else if (!validUnit(a, unit, HTMLStandardMode)) {
5867 return nullptr;
5868 }
5869
5870 // Add the value to the current transform operation.
5871 transformValue->append(createPrimitiveNumericValue(a));
5872
5873 a = args->next();
5874 if (!a)
5875 break;
5876 if (!isComma(a))
5877 return nullptr;
5878 a = args->next();
5879
5880 argNumber++;
5881 }
5882
5883 return transformValue.release();
5884 }
5885
5886 } // namespace blink 5690 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698