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

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

Issue 1397553003: Move size property into CSSPropertyParser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Patch for review Created 5 years, 2 months 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 // 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 "config.h" 5 #include "config.h"
6 #include "core/css/parser/CSSPropertyParser.h" 6 #include "core/css/parser/CSSPropertyParser.h"
7 7
8 #include "core/StylePropertyShorthand.h" 8 #include "core/StylePropertyShorthand.h"
9 #include "core/css/CSSCalculationValue.h" 9 #include "core/css/CSSCalculationValue.h"
10 #include "core/css/CSSCustomIdentValue.h" 10 #include "core/css/CSSCustomIdentValue.h"
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 for (unsigned i = 0; i < 3; i++) { // 3 dimensions of rotation 634 for (unsigned i = 0; i < 3; i++) { // 3 dimensions of rotation
635 RefPtrWillBeRawPtr<CSSValue> dimension = consumeNumber(range, ValueRange All); 635 RefPtrWillBeRawPtr<CSSValue> dimension = consumeNumber(range, ValueRange All);
636 if (!dimension) 636 if (!dimension)
637 return nullptr; 637 return nullptr;
638 list->append(dimension.release()); 638 list->append(dimension.release());
639 } 639 }
640 640
641 return list.release(); 641 return list.release();
642 } 642 }
643 643
644 enum class SizeParameter {
645 None,
646 Auto,
647 Length,
648 PageSize,
649 Orientation,
650 };
651
652 static SizeParameter parseSizeParameter(CSSParserTokenRange& range, CSSParserMod e cssParserMode, CSSValueList* parsedValues, SizeParameter prevParamType)
653 {
654 switch (range.peek().id()) {
655 case CSSValueAuto:
656 if (prevParamType == SizeParameter::None) {
657 parsedValues->append(consumeIdent(range));
658 return SizeParameter::Auto;
659 }
660 return SizeParameter::None;
661 case CSSValueLandscape:
662 case CSSValuePortrait:
663 if (prevParamType == SizeParameter::None || prevParamType == SizeParamet er::PageSize) {
664 parsedValues->append(consumeIdent(range));
665 return SizeParameter::Orientation;
666 }
667 return SizeParameter::None;
668 case CSSValueA3:
669 case CSSValueA4:
670 case CSSValueA5:
671 case CSSValueB4:
672 case CSSValueB5:
673 case CSSValueLedger:
674 case CSSValueLegal:
675 case CSSValueLetter:
676 if (prevParamType == SizeParameter::None || prevParamType == SizeParamet er::Orientation) {
677 // Normalize to Page Size then Orientation order by prepending for s impler StyleBuilder handling
678 parsedValues->prepend(consumeIdent(range));
679 return SizeParameter::PageSize;
680 }
681 return SizeParameter::None;
682 case 0: {
683 RefPtrWillBeRawPtr<CSSValue> parsedValue = consumeLength(range, cssParse rMode, ValueRangeNonNegative);
684 if (parsedValue && (prevParamType == SizeParameter::None || prevParamTyp e == SizeParameter::Length)) {
685 parsedValues->append(parsedValue.release());
686 return SizeParameter::Length;
687 }
688 return SizeParameter::None;
689 }
690 default:
691 return SizeParameter::None;
692 }
693 }
694
695 static PassRefPtrWillBeRawPtr<CSSValueList> consumeSize(CSSParserTokenRange& ran ge, CSSParserMode cssParserMode)
696 {
697 RefPtrWillBeRawPtr<CSSValueList> parsedValues = CSSValueList::createSpaceSep arated();
698
699 // First parameter.
Timothy Loh 2015/10/08 23:36:38 This can be lots simpler I think. Sorry for code d
rwlbuis 2015/10/12 17:13:19 I like it! But the part where height is set to wid
700 SizeParameter paramType = parseSizeParameter(range, cssParserMode, parsedVal ues.get(), SizeParameter::None);
701 if (paramType == SizeParameter::None)
702 return nullptr;
703
704 // Second parameter, if any.
705 if (!range.atEnd()) {
706 paramType = parseSizeParameter(range, cssParserMode, parsedValues.get(), paramType);
707 if (paramType == SizeParameter::None)
708 return nullptr;
709 }
710
711 return parsedValues.release();
712 }
713
644 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID propId) 714 PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty ID propId)
645 { 715 {
646 m_range.consumeWhitespace(); 716 m_range.consumeWhitespace();
647 switch (propId) { 717 switch (propId) {
648 case CSSPropertyWillChange: 718 case CSSPropertyWillChange:
649 return consumeWillChange(m_range); 719 return consumeWillChange(m_range);
650 case CSSPropertyPage: 720 case CSSPropertyPage:
651 return consumePage(m_range); 721 return consumePage(m_range);
652 case CSSPropertyQuotes: 722 case CSSPropertyQuotes:
653 return consumeQuotes(m_range); 723 return consumeQuotes(m_range);
(...skipping 16 matching lines...) Expand all
670 return consumeTabSize(m_range, m_context.mode()); 740 return consumeTabSize(m_range, m_context.mode());
671 case CSSPropertyFontSize: 741 case CSSPropertyFontSize:
672 return consumeFontSize(m_range, m_context.mode(), UnitlessQuirk::Allow); 742 return consumeFontSize(m_range, m_context.mode(), UnitlessQuirk::Allow);
673 case CSSPropertyLineHeight: 743 case CSSPropertyLineHeight:
674 return consumeLineHeight(m_range, m_context.mode()); 744 return consumeLineHeight(m_range, m_context.mode());
675 case CSSPropertyRotate: 745 case CSSPropertyRotate:
676 return consumeRotation(m_range); 746 return consumeRotation(m_range);
677 case CSSPropertyWebkitBorderHorizontalSpacing: 747 case CSSPropertyWebkitBorderHorizontalSpacing:
678 case CSSPropertyWebkitBorderVerticalSpacing: 748 case CSSPropertyWebkitBorderVerticalSpacing:
679 return consumeLength(m_range, m_context.mode(), ValueRangeNonNegative); 749 return consumeLength(m_range, m_context.mode(), ValueRangeNonNegative);
750 case CSSPropertySize:
751 return consumeSize(m_range, m_context.mode());
680 default: 752 default:
681 return nullptr; 753 return nullptr;
682 } 754 }
683 } 755 }
684 756
685 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse rTokenRange& range) 757 static PassRefPtrWillBeRawPtr<CSSValueList> consumeFontFaceUnicodeRange(CSSParse rTokenRange& range)
686 { 758 {
687 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated (); 759 RefPtrWillBeRawPtr<CSSValueList> values = CSSValueList::createCommaSeparated ();
688 760
689 do { 761 do {
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 } 1136 }
1065 case CSSPropertyBorderSpacing: 1137 case CSSPropertyBorderSpacing:
1066 return consumeBorderSpacing(important); 1138 return consumeBorderSpacing(important);
1067 default: 1139 default:
1068 m_currentShorthand = oldShorthand; 1140 m_currentShorthand = oldShorthand;
1069 return false; 1141 return false;
1070 } 1142 }
1071 } 1143 }
1072 1144
1073 } // namespace blink 1145 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698