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

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

Issue 1399003004: Move columns related properties into CSSPropertyParser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp
diff --git a/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp b/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp
index 1632103e4cafc7b748d2e315ce72d290646585bc..1579ccc4e48640374aac12d9977b4d7822449dfd 100644
--- a/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp
+++ b/third_party/WebKit/Source/core/css/parser/CSSPropertyParser.cpp
@@ -170,7 +170,7 @@ private:
RefPtrWillBeMember<CSSCalcValue> m_calcValue;
};
-static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeInteger(CSSParserTokenRange& range, CSSParserMode cssParserMode, double minimumValue = -std::numeric_limits<double>::max())
+static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeInteger(CSSParserTokenRange& range, double minimumValue = -std::numeric_limits<double>::max())
{
const CSSParserToken& token = range.peek();
if (token.type() == NumberToken) {
@@ -190,6 +190,11 @@ static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeInteger(CSSParserTokenRa
return nullptr;
}
+static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumePositiveInteger(CSSParserTokenRange& range)
+{
+ return consumeInteger(range, 1);
+}
+
static PassRefPtrWillBeRawPtr<CSSPrimitiveValue> consumeNumber(CSSParserTokenRange& range, ValueRange valueRange)
{
const CSSParserToken& token = range.peek();
@@ -596,7 +601,7 @@ static PassRefPtrWillBeRawPtr<CSSValue> consumeSpacing(CSSParserTokenRange& rang
static PassRefPtrWillBeRawPtr<CSSValue> consumeTabSize(CSSParserTokenRange& range, CSSParserMode cssParserMode)
{
- RefPtrWillBeRawPtr<CSSPrimitiveValue> parsedValue = consumeInteger(range, cssParserMode, 0);
+ RefPtrWillBeRawPtr<CSSPrimitiveValue> parsedValue = consumeInteger(range, 0);
if (parsedValue)
return parsedValue;
return consumeLength(range, cssParserMode, ValueRangeNonNegative);
@@ -655,7 +660,7 @@ static PassRefPtrWillBeRawPtr<CSSValue> consumeCounter(CSSParserTokenRange& rang
if (!counterName)
return nullptr;
int i = defaultValue;
- if (RefPtrWillBeRawPtr<CSSPrimitiveValue> counterValue = consumeInteger(range, cssParserMode))
+ if (RefPtrWillBeRawPtr<CSSPrimitiveValue> counterValue = consumeInteger(range))
i = clampTo<int>(counterValue->getDoubleValue());
list->append(CSSValuePair::create(counterName.release(),
cssValuePool().createValue(i, CSSPrimitiveValue::UnitType::Number),
@@ -875,6 +880,47 @@ static PassRefPtrWillBeRawPtr<CSSValue> consumeTouchAction(CSSParserTokenRange&
return list.release();
}
+static PassRefPtrWillBeRawPtr<CSSValue> consumeColumnWidth(CSSParserTokenRange& range)
+{
+ if (range.peek().id() == CSSValueAuto)
+ return consumeIdent(range);
+ // Always parse lengths in strict mode here, since it would be ambiguous otherwise when used in
+ // the 'columns' shorthand property.
+ RefPtrWillBeRawPtr<CSSPrimitiveValue> columnWidth = consumeLength(range, HTMLStandardMode, ValueRangeNonNegative);
+ if (!columnWidth || (!columnWidth->isCalculated() && columnWidth->getDoubleValue() == 0))
+ return nullptr;
+ return columnWidth.release();
+}
+
+static PassRefPtrWillBeRawPtr<CSSValue> consumeColumnCount(CSSParserTokenRange& range)
+{
+ if (range.peek().id() == CSSValueAuto)
+ return consumeIdent(range);
+ return consumePositiveInteger(range);
+}
+
+static PassRefPtrWillBeRawPtr<CSSValue> consumeColumnGap(CSSParserTokenRange& range, CSSParserMode cssParserMode)
+{
+ if (range.peek().id() == CSSValueNormal)
+ return consumeIdent(range);
+ return consumeLength(range, cssParserMode, ValueRangeNonNegative);
+}
+
+static PassRefPtrWillBeRawPtr<CSSValue> consumeColumnSpan(CSSParserTokenRange& range, CSSParserMode cssParserMode)
+{
+ CSSValueID id = range.peek().id();
+ if (id == CSSValueAll || id == CSSValueNone)
+ return consumeIdent(range);
+ if (range.peek().type() != NumberToken)
+ return nullptr;
+ if (RefPtrWillBeRawPtr<CSSPrimitiveValue> spanValue = consumeInteger(range)) {
+ // 1 (will be dropped in the unprefixed property).
+ if (spanValue->getIntValue() == 1)
+ return spanValue.release();
+ }
+ return nullptr;
+}
+
PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSPropertyID propId)
{
m_range.consumeWhitespace();
@@ -938,6 +984,14 @@ PassRefPtrWillBeRawPtr<CSSValue> CSSPropertyParser::parseSingleValue(CSSProperty
return consumeClip(m_range, m_context.mode());
case CSSPropertyTouchAction:
return consumeTouchAction(m_range);
+ case CSSPropertyWebkitColumnWidth:
+ return consumeColumnWidth(m_range);
+ case CSSPropertyWebkitColumnCount:
+ return consumeColumnCount(m_range);
+ case CSSPropertyWebkitColumnGap:
+ return consumeColumnGap(m_range, m_context.mode());
+ case CSSPropertyWebkitColumnSpan:
+ return consumeColumnSpan(m_range, m_context.mode());
default:
return nullptr;
}
@@ -1272,6 +1326,37 @@ bool CSSPropertyParser::parseViewportDescriptor(CSSPropertyID propId, bool impor
}
}
+static void consumeColumnWidthOrCount(CSSParserTokenRange& range, CSSParserMode cssParserMode, RefPtrWillBeRawPtr<CSSValue> &columnWidth, RefPtrWillBeRawPtr<CSSValue> &columnCount)
+{
+ if (range.peek().id() == CSSValueAuto) {
+ consumeIdent(range);
+ return;
+ }
+ if (!columnWidth) {
+ if ((columnWidth = consumeColumnWidth(range)))
+ return;
+ }
+ if (!columnCount)
+ columnCount = consumeColumnCount(range);
+}
+
+bool CSSPropertyParser::consumeColumns(bool important)
+{
+ RefPtrWillBeRawPtr<CSSValue> columnWidth = nullptr;
+ RefPtrWillBeRawPtr<CSSValue> columnCount = nullptr;
+ consumeColumnWidthOrCount(m_range, m_context.mode(), columnWidth, columnCount);
+ consumeColumnWidthOrCount(m_range, m_context.mode(), columnWidth, columnCount);
+ if (!m_range.atEnd())
+ return false;
+ if (!columnWidth)
+ columnWidth = cssValuePool().createIdentifierValue(CSSValueAuto);
+ if (!columnCount)
+ columnCount = cssValuePool().createIdentifierValue(CSSValueAuto);
+ addProperty(CSSPropertyWebkitColumnWidth, columnWidth.release(), important);
+ addProperty(CSSPropertyWebkitColumnCount, columnCount.release(), important);
+ return true;
+}
+
bool CSSPropertyParser::parseShorthand(CSSPropertyID propId, bool important)
{
m_range.consumeWhitespace();
@@ -1325,6 +1410,10 @@ bool CSSPropertyParser::parseShorthand(CSSPropertyID propId, bool important)
}
case CSSPropertyBorderSpacing:
return consumeBorderSpacing(important);
+ case CSSPropertyWebkitColumns: {
+ m_currentShorthand = oldShorthand;
Timothy Loh 2015/10/19 04:55:59 ok, but TODO to remove this
+ return consumeColumns(important);
+ }
default:
m_currentShorthand = oldShorthand;
return false;

Powered by Google App Engine
This is Rietveld 408576698