Commit dee07d3f authored by aazzam's avatar aazzam Committed by Commit bot

Implements CSSPropertyAPI for the paint-order property.

A part of Project Ribbon, separating the parsing logic for CSS
properties from the parser into an API. This patch removes
CSSPropertyPaintOrder from the switch statement in parseSingleValue,
and calls the API instead.

A function pointer to the parseSingleValue function from the API for the
page property is stored in a CSSPropertyDescriptor, and is called from
CSSPropertyParser.

This patch:
- Adds CSSPropertyAPIPaintOrder.cpp to the BUILD.gn file.
- Adds api_class flag to CSSProperties.in, which indicates that
  CSSPropertyAPIPaintOrder.h is generated.
- Moves the parsing logic for page from CSSPropertyParser.cpp to
  CSSPropertyAPIPaintOrder.cpp, which implements CSSPropertyAPI.h.

BUG=668012

Review-Url: https://codereview.chromium.org/2612103003
Cr-Commit-Position: refs/heads/master@{#442890}
parent 6ae87012
......@@ -353,6 +353,7 @@ blink_core_sources("css") {
"properties/CSSPropertyAPIOffsetPosition.cpp",
"properties/CSSPropertyAPIOutlineOffset.cpp",
"properties/CSSPropertyAPIPage.cpp",
"properties/CSSPropertyAPIPaintOrder.cpp",
"properties/CSSPropertyAPISize.cpp",
"properties/CSSPropertyAPITextDecorationColor.cpp",
"properties/CSSPropertyAPITextDecorationSkip.cpp",
......
......@@ -332,7 +332,7 @@ padding-bottom interpolable, initial=initialPadding, converter=convertLength
padding-left interpolable, initial=initialPadding, converter=convertLength
padding-right interpolable, initial=initialPadding, converter=convertLength
padding-top interpolable, initial=initialPadding, converter=convertLength
paint-order inherited, svg, converter=convertPaintOrder
paint-order inherited, svg, converter=convertPaintOrder, api_class
perspective interpolable, converter=convertPerspective
perspective-origin interpolable, converter=convertPosition
pointer-events inherited, independent, keyword_only, keywords=[none|auto|stroke|fill|painted|visible|visibleStroke|visibleFill|visiblePainted|bounding-box|all], initial_keyword=auto
......
......@@ -1756,56 +1756,6 @@ static CSSValue* consumePaintStroke(CSSParserTokenRange& range,
return consumeColor(range, cssParserMode);
}
static CSSValue* consumePaintOrder(CSSParserTokenRange& range) {
if (range.peek().id() == CSSValueNormal)
return consumeIdent(range);
Vector<CSSValueID, 3> paintTypeList;
CSSIdentifierValue* fill = nullptr;
CSSIdentifierValue* stroke = nullptr;
CSSIdentifierValue* markers = nullptr;
do {
CSSValueID id = range.peek().id();
if (id == CSSValueFill && !fill)
fill = consumeIdent(range);
else if (id == CSSValueStroke && !stroke)
stroke = consumeIdent(range);
else if (id == CSSValueMarkers && !markers)
markers = consumeIdent(range);
else
return nullptr;
paintTypeList.push_back(id);
} while (!range.atEnd());
// After parsing we serialize the paint-order list. Since it is not possible
// to pop a last list items from CSSValueList without bigger cost, we create
// the list after parsing.
CSSValueID firstPaintOrderType = paintTypeList.at(0);
CSSValueList* paintOrderList = CSSValueList::createSpaceSeparated();
switch (firstPaintOrderType) {
case CSSValueFill:
case CSSValueStroke:
paintOrderList->append(firstPaintOrderType == CSSValueFill ? *fill
: *stroke);
if (paintTypeList.size() > 1) {
if (paintTypeList.at(1) == CSSValueMarkers)
paintOrderList->append(*markers);
}
break;
case CSSValueMarkers:
paintOrderList->append(*markers);
if (paintTypeList.size() > 1) {
if (paintTypeList.at(1) == CSSValueStroke)
paintOrderList->append(*stroke);
}
break;
default:
ASSERT_NOT_REACHED();
}
return paintOrderList;
}
static CSSValue* consumeNoneOrURI(CSSParserTokenRange& range) {
if (range.peek().id() == CSSValueNone)
return consumeIdent(range);
......@@ -3449,8 +3399,6 @@ const CSSValue* CSSPropertyParser::parseSingleValue(
case CSSPropertyFill:
case CSSPropertyStroke:
return consumePaintStroke(m_range, m_context.mode());
case CSSPropertyPaintOrder:
return consumePaintOrder(m_range);
case CSSPropertyMarkerStart:
case CSSPropertyMarkerMid:
case CSSPropertyMarkerEnd:
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "core/css/properties/CSSPropertyAPIPaintOrder.h"
#include "core/css/CSSValueList.h"
#include "core/css/parser/CSSPropertyParserHelpers.h"
namespace blink {
const CSSValue* CSSPropertyAPIPaintOrder::parseSingleValue(
CSSParserTokenRange& range,
const CSSParserContext& context) {
if (range.peek().id() == CSSValueNormal)
return CSSPropertyParserHelpers::consumeIdent(range);
Vector<CSSValueID, 3> paintTypeList;
CSSIdentifierValue* fill = nullptr;
CSSIdentifierValue* stroke = nullptr;
CSSIdentifierValue* markers = nullptr;
do {
CSSValueID id = range.peek().id();
if (id == CSSValueFill && !fill)
fill = CSSPropertyParserHelpers::consumeIdent(range);
else if (id == CSSValueStroke && !stroke)
stroke = CSSPropertyParserHelpers::consumeIdent(range);
else if (id == CSSValueMarkers && !markers)
markers = CSSPropertyParserHelpers::consumeIdent(range);
else
return nullptr;
paintTypeList.push_back(id);
} while (!range.atEnd());
// After parsing we serialize the paint-order list. Since it is not possible
// to pop a last list items from CSSValueList without bigger cost, we create
// the list after parsing.
CSSValueID firstPaintOrderType = paintTypeList.at(0);
CSSValueList* paintOrderList = CSSValueList::createSpaceSeparated();
switch (firstPaintOrderType) {
case CSSValueFill:
case CSSValueStroke:
paintOrderList->append(firstPaintOrderType == CSSValueFill ? *fill
: *stroke);
if (paintTypeList.size() > 1) {
if (paintTypeList.at(1) == CSSValueMarkers)
paintOrderList->append(*markers);
}
break;
case CSSValueMarkers:
paintOrderList->append(*markers);
if (paintTypeList.size() > 1) {
if (paintTypeList.at(1) == CSSValueStroke)
paintOrderList->append(*stroke);
}
break;
default:
NOTREACHED();
}
return paintOrderList;
}
} // namespace blink
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment