Commit 13f6e06e authored by aazzam's avatar aazzam Committed by Commit bot

Added CSSPropertyAPI and CSS padding properties which implement this API

Added the CSSPropertyAPI for a single method parseSingleValue. Made
CSSPaddingProperties which implements this API for a few css
properties. Added CSS property descriptor which uses a struct to store
function pointers for the property's functions.

BUG=668012

Review-Url: https://codereview.chromium.org/2533673002
Cr-Commit-Position: refs/heads/master@{#438057}
parent 286de02c
......@@ -344,6 +344,11 @@ blink_core_sources("css") {
"parser/MediaQueryParser.cpp",
"parser/SizesAttributeParser.cpp",
"parser/SizesCalcParser.cpp",
"properties/CSSPropertyAPI.h",
"properties/CSSPropertyAPIPadding.cpp",
"properties/CSSPropertyAPIPadding.h",
"properties/CSSPropertyDescriptor.cpp",
"properties/CSSPropertyDescriptor.h",
"resolver/AnimatedStyleBuilder.cpp",
"resolver/AnimatedStyleBuilder.h",
"resolver/CSSToStyleMap.cpp",
......
......@@ -41,6 +41,7 @@
#include "core/css/parser/CSSParserIdioms.h"
#include "core/css/parser/CSSPropertyParserHelpers.h"
#include "core/css/parser/CSSVariableParser.h"
#include "core/css/properties/CSSPropertyDescriptor.h"
#include "core/frame/UseCounter.h"
#include "core/layout/LayoutTheme.h"
#include "core/svg/SVGPathUtilities.h"
......@@ -3465,6 +3466,17 @@ const CSSValue* CSSPropertyParser::parseSingleValue(
m_range.peek().id());
return consumeIdent(m_range);
}
// Gets the parsing function for our current property from the property API.
// If it has been implemented, we call this function, otherwise we manually
// parse this value in the switch statement below. As we implement APIs for
// other properties, those properties will be taken out of the switch
// statement.
const CSSPropertyDescriptor& cssPropertyDesc =
CSSPropertyDescriptor::get(property);
if (cssPropertyDesc.temporaryCanReadValue)
return cssPropertyDesc.parseSingleValue(m_range, m_context);
switch (property) {
case CSSPropertyWillChange:
return consumeWillChange(m_range);
......@@ -3558,13 +3570,6 @@ const CSSValue* CSSPropertyParser::parseSingleValue(
return consumeLengthOrPercent(m_range, m_context.mode(),
ValueRangeNonNegative,
UnitlessQuirk::Allow);
case CSSPropertyWebkitPaddingStart:
case CSSPropertyWebkitPaddingEnd:
case CSSPropertyWebkitPaddingBefore:
case CSSPropertyWebkitPaddingAfter:
return consumeLengthOrPercent(m_range, m_context.mode(),
ValueRangeNonNegative,
UnitlessQuirk::Forbid);
case CSSPropertyClip:
return consumeClip(m_range, m_context.mode());
case CSSPropertyTouchAction:
......
// Copyright 2016 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.
#ifndef CSSPropertyAPI_h
#define CSSPropertyAPI_h
#include "core/CSSPropertyNames.h"
#include "core/css/CSSValue.h"
#include "core/css/parser/CSSParserMode.h"
#include "core/css/parser/CSSParserTokenRange.h"
namespace blink {
// We will use this API to represent all functions used for property-specific
// logic inside the blink style engine. All specific properties are subclasses
// of CSSPropertyAPI.
//
// To add a new property using this API:
// - Make a class that implements CSSPropertyAPI, and implement the static
// methods.
// - Update the cssPropertyDescriptors array in CSSPropertyDescriptor.cpp to
// call GET_DESCRIPTOR(classname).
//
// To add new functions using this API:
// - New functions and static variables can be added in this class. A default
// implementation of functions can optionally be provided.
// - When adding new functions, also add them to GET_DESCRIPTOR, and the get()
// method in CSSPropertyDescriptors.cpp, and the descriptor struct in
// CSSPropertyDescriptor.h.
class CSSPropertyAPI {
STATIC_ONLY(CSSPropertyAPI);
public:
// Parses a single CSS property and returns the corresponding CSSValue. If the
// input is invalid it returns nullptr.
static const CSSValue* parseSingleValue(CSSParserTokenRange&,
const CSSParserContext&);
};
} // namespace blink
#endif // CSSPropertyAPI_h
// Copyright 2016 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/CSSPropertyAPIPadding.h"
#include "core/css/parser/CSSParserTokenRange.h"
#include "core/css/parser/CSSPropertyParserHelpers.h"
namespace blink {
const CSSValue* CSSPropertyAPIWebkitPadding::parseSingleValue(
CSSParserTokenRange& range,
const CSSParserContext& context) {
return consumeLengthOrPercent(
range, context.mode(), ValueRangeNonNegative,
CSSPropertyParserHelpers::UnitlessQuirk::Forbid);
}
} // namespace blink
// Copyright 2016 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.
#ifndef CSSPropertyAPIPadding_h
#define CSSPropertyAPIPadding_h
#include "core/CSSPropertyNames.h"
#include "core/css/properties/CSSPropertyAPI.h"
namespace blink {
// TODO(aazzam): Generate API .h files
class CSSParserTokenRange;
class CSSParserContext;
class CSSPropertyAPIWebkitPadding : public CSSPropertyAPI {
public:
static const CSSValue* parseSingleValue(CSSParserTokenRange&,
const CSSParserContext&);
};
} // namespace blink
#endif // CSSPropertyAPIPadding_h
// Copyright 2016 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/CSSPropertyDescriptor.h"
#include "core/css/properties/CSSPropertyAPIPadding.h"
namespace blink {
// Initialises a CSSPropertyDescriptor. When functions are added to
// CSSPropertyAPI, also add them to the struct initaliser below.
#define GET_DESCRIPTOR(X) \
{ X::parseSingleValue, true }
// Initialises an invalid CSSPropertyDescriptor. When functions are added to
// CSSPropertyAPI, add a nullptr to represent their function pointers in the
// struct initaliser.
#define GET_INVALID_DESCRIPTOR() \
{ nullptr, false }
static_assert(
std::is_pod<CSSPropertyDescriptor>::value,
"CSSPropertyDescriptor must be a POD to support using initializer lists.");
static CSSPropertyDescriptor cssPropertyDescriptors[] = {
GET_INVALID_DESCRIPTOR(), GET_DESCRIPTOR(CSSPropertyAPIWebkitPadding),
};
const CSSPropertyDescriptor& CSSPropertyDescriptor::get(CSSPropertyID id) {
// TODO(aazzam): We are currently using hard-coded indexes for
// cssPropertyDescriptor since we have only implemented a few properties.
// Later, generate this switch statement, or alternatively return
// cssPropertyDescriptors[id], and generate the cssPropertyDescriptors array
// to hold invalid descriptors for methods which haven't been implemented yet.
switch (id) {
case CSSPropertyWebkitPaddingEnd:
return cssPropertyDescriptors[1];
case CSSPropertyWebkitPaddingStart:
return cssPropertyDescriptors[1];
case CSSPropertyWebkitPaddingBefore:
return cssPropertyDescriptors[1];
case CSSPropertyWebkitPaddingAfter:
return cssPropertyDescriptors[1];
default:
return cssPropertyDescriptors[0];
}
}
} // namespace blink
// Copyright 2016 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/CSSPropertyNames.h"
namespace blink {
class CSSValue;
class CSSParserTokenRange;
class CSSParserContext;
// Stores function pointers matching those declared in CSSPropertyAPI.
struct CSSPropertyDescriptor {
const CSSValue* (*parseSingleValue)(CSSParserTokenRange&,
const CSSParserContext&);
// Stores whether or not this descriptor is for a valid property. Do not
// access the contents of this descriptor unless this value is true.
// TODO(aazzam): Remove this once the switch in
// CSSPropertyParser::parseSingleValue() has been completely replaced by
// CSSPropertyDescriptors.
bool temporaryCanReadValue;
// Returns the corresponding CSSPropertyDescriptor for a given CSSPropertyID.
// Use this function to access the API for a property. Returns a descriptor
// with isValid set to false if no descriptor exists for this ID.
static const CSSPropertyDescriptor& get(CSSPropertyID);
};
} // 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