Commit e4dfcbf6 authored by Anders Hartvoll Ruud's avatar Anders Hartvoll Ruud Committed by Commit Bot

[css-properties-values-api] Move CSSSyntaxComponent to a separate file.

This is prerequisite for a subsequent CL.

R=futhark@chromium.org

Bug: 641877
Change-Id: Ifc8c1df0f80f9c18205b103e13ae90b5e2c63b2e
Reviewed-on: https://chromium-review.googlesource.com/c/1290980Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Commit-Queue: Anders Ruud <andruud@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601508}
parent 2b0a606b
......@@ -158,6 +158,8 @@ blink_core_sources("css") {
"css_style_sheet.h",
"css_supports_rule.cc",
"css_supports_rule.h",
"css_syntax_component.cc",
"css_syntax_component.h",
"css_syntax_descriptor.cc",
"css_syntax_descriptor.h",
"css_timing_function_value.cc",
......
// Copyright 2018 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 "third_party/blink/renderer/core/css/css_syntax_component.h"
#include "third_party/blink/renderer/core/css/cssom/css_keyword_value.h"
#include "third_party/blink/renderer/core/css/cssom/css_style_value.h"
#include "third_party/blink/renderer/core/css/cssom/cssom_types.h"
namespace blink {
bool CSSSyntaxComponent::CanTake(const CSSStyleValue& value) const {
switch (type_) {
case CSSSyntaxType::kTokenStream:
return value.GetType() == CSSStyleValue::kUnparsedType;
case CSSSyntaxType::kIdent:
return value.GetType() == CSSStyleValue::kKeywordType &&
static_cast<const CSSKeywordValue&>(value).value() == string_;
case CSSSyntaxType::kLength:
return CSSOMTypes::IsCSSStyleValueLength(value);
case CSSSyntaxType::kInteger:
// TODO(andruud): Support rounding.
// https://drafts.css-houdini.org/css-typed-om-1/#numeric-objects
FALLTHROUGH;
case CSSSyntaxType::kNumber:
return CSSOMTypes::IsCSSStyleValueNumber(value);
case CSSSyntaxType::kPercentage:
return CSSOMTypes::IsCSSStyleValuePercentage(value);
case CSSSyntaxType::kLengthPercentage:
// TODO(andruud): Support calc(X% + Ypx).
return CSSOMTypes::IsCSSStyleValueLength(value) ||
CSSOMTypes::IsCSSStyleValuePercentage(value);
case CSSSyntaxType::kColor:
// TODO(andruud): Support custom properties in CSSUnsupportedStyleValue.
return false;
case CSSSyntaxType::kImage:
case CSSSyntaxType::kUrl:
return value.GetType() == CSSStyleValue::kURLImageType;
case CSSSyntaxType::kAngle:
return CSSOMTypes::IsCSSStyleValueAngle(value);
case CSSSyntaxType::kTime:
return CSSOMTypes::IsCSSStyleValueTime(value);
case CSSSyntaxType::kResolution:
return CSSOMTypes::IsCSSStyleValueResolution(value);
case CSSSyntaxType::kTransformFunction:
// TODO(andruud): Currently not supported by Typed OM.
// https://github.com/w3c/css-houdini-drafts/issues/290
// For now, this should accept a CSSUnsupportedStyleValue, such that
// <transform-function> values can be moved from one registered property
// to another.
// TODO(andruud): Support custom properties in CSSUnsupportedStyleValue.
return false;
case CSSSyntaxType::kTransformList:
return value.GetType() == CSSStyleValue::kTransformType;
case CSSSyntaxType::kCustomIdent:
return value.GetType() == CSSStyleValue::kKeywordType;
default:
return false;
}
}
} // namespace blink
// Copyright 2018 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 THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSS_SYNTAX_COMPONENT_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSS_SYNTAX_COMPONENT_H_
#include "base/macros.h"
#include "third_party/blink/renderer/core/css/css_value.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
namespace blink {
class CSSStyleValue;
enum class CSSSyntaxType {
kTokenStream,
kIdent,
kLength,
kNumber,
kPercentage,
kLengthPercentage,
kColor,
kImage,
kUrl,
kInteger,
kAngle,
kTime,
kResolution,
kTransformFunction,
kTransformList,
kCustomIdent,
};
enum class CSSSyntaxRepeat { kNone, kSpaceSeparated, kCommaSeparated };
class CSSSyntaxComponent {
public:
CSSSyntaxComponent(CSSSyntaxType type,
const String& string,
CSSSyntaxRepeat repeat)
: type_(type), string_(string), repeat_(repeat) {}
bool operator==(const CSSSyntaxComponent& a) const {
return type_ == a.type_ && string_ == a.string_ && repeat_ == a.repeat_;
}
CSSSyntaxType GetType() const { return type_; }
const String& GetString() const { return string_; }
CSSSyntaxRepeat GetRepeat() const { return repeat_; }
bool IsRepeatable() const { return repeat_ != CSSSyntaxRepeat::kNone; }
bool IsInteger() const { return type_ == CSSSyntaxType::kInteger; }
char Separator() const {
DCHECK(IsRepeatable());
return repeat_ == CSSSyntaxRepeat::kSpaceSeparated ? ' ' : ',';
}
bool CanTake(const CSSStyleValue&) const;
private:
CSSSyntaxType type_;
String string_; // Only used when type_ is CSSSyntaxType::kIdent
CSSSyntaxRepeat repeat_;
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSS_SYNTAX_COMPONENT_H_
......@@ -5,12 +5,10 @@
#include "third_party/blink/renderer/core/css/css_syntax_descriptor.h"
#include "third_party/blink/renderer/core/css/css_custom_property_declaration.h"
#include "third_party/blink/renderer/core/css/css_syntax_component.h"
#include "third_party/blink/renderer/core/css/css_uri_value.h"
#include "third_party/blink/renderer/core/css/css_value_list.h"
#include "third_party/blink/renderer/core/css/css_variable_reference_value.h"
#include "third_party/blink/renderer/core/css/cssom/css_keyword_value.h"
#include "third_party/blink/renderer/core/css/cssom/css_style_value.h"
#include "third_party/blink/renderer/core/css/cssom/cssom_types.h"
#include "third_party/blink/renderer/core/css/parser/css_parser_idioms.h"
#include "third_party/blink/renderer/core/css/parser/css_property_parser_helpers.h"
#include "third_party/blink/renderer/core/css/parser/css_variable_parser.h"
......@@ -228,56 +226,6 @@ const CSSValue* ConsumeSyntaxComponent(const CSSSyntaxComponent& syntax,
return result;
}
bool CSSSyntaxComponent::CanTake(const CSSStyleValue& value) const {
switch (type_) {
case CSSSyntaxType::kTokenStream:
return value.GetType() == CSSStyleValue::kUnparsedType;
case CSSSyntaxType::kIdent:
return value.GetType() == CSSStyleValue::kKeywordType &&
static_cast<const CSSKeywordValue&>(value).value() == string_;
case CSSSyntaxType::kLength:
return CSSOMTypes::IsCSSStyleValueLength(value);
case CSSSyntaxType::kInteger:
// TODO(andruud): Support rounding.
// https://drafts.css-houdini.org/css-typed-om-1/#numeric-objects
FALLTHROUGH;
case CSSSyntaxType::kNumber:
return CSSOMTypes::IsCSSStyleValueNumber(value);
case CSSSyntaxType::kPercentage:
return CSSOMTypes::IsCSSStyleValuePercentage(value);
case CSSSyntaxType::kLengthPercentage:
// TODO(andruud): Support calc(X% + Ypx).
return CSSOMTypes::IsCSSStyleValueLength(value) ||
CSSOMTypes::IsCSSStyleValuePercentage(value);
case CSSSyntaxType::kColor:
// TODO(andruud): Support custom properties in CSSUnsupportedStyleValue.
return false;
case CSSSyntaxType::kImage:
case CSSSyntaxType::kUrl:
return value.GetType() == CSSStyleValue::kURLImageType;
case CSSSyntaxType::kAngle:
return CSSOMTypes::IsCSSStyleValueAngle(value);
case CSSSyntaxType::kTime:
return CSSOMTypes::IsCSSStyleValueTime(value);
case CSSSyntaxType::kResolution:
return CSSOMTypes::IsCSSStyleValueResolution(value);
case CSSSyntaxType::kTransformFunction:
// TODO(andruud): Currently not supported by Typed OM.
// https://github.com/w3c/css-houdini-drafts/issues/290
// For now, this should accept a CSSUnsupportedStyleValue, such that
// <transform-function> values can be moved from one registered property
// to another.
// TODO(andruud): Support custom properties in CSSUnsupportedStyleValue.
return false;
case CSSSyntaxType::kTransformList:
return value.GetType() == CSSStyleValue::kTransformType;
case CSSSyntaxType::kCustomIdent:
return value.GetType() == CSSStyleValue::kKeywordType;
default:
return false;
}
}
const CSSSyntaxComponent* CSSSyntaxDescriptor::Match(
const CSSStyleValue& value) const {
for (const CSSSyntaxComponent& component : syntax_components_) {
......
......@@ -5,64 +5,14 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSS_SYNTAX_DESCRIPTOR_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSS_SYNTAX_DESCRIPTOR_H_
#include "third_party/blink/renderer/core/css/css_syntax_component.h"
#include "third_party/blink/renderer/core/css/parser/css_parser_token_range.h"
namespace blink {
class CSSParserContext;
class CSSStyleValue;
class CSSValue;
enum class CSSSyntaxType {
kTokenStream,
kIdent,
kLength,
kNumber,
kPercentage,
kLengthPercentage,
kColor,
kImage,
kUrl,
kInteger,
kAngle,
kTime,
kResolution,
kTransformFunction,
kTransformList,
kCustomIdent,
};
enum class CSSSyntaxRepeat { kNone, kSpaceSeparated, kCommaSeparated };
class CSSSyntaxComponent {
public:
CSSSyntaxComponent(CSSSyntaxType type,
const String& string,
CSSSyntaxRepeat repeat)
: type_(type), string_(string), repeat_(repeat) {}
bool operator==(const CSSSyntaxComponent& a) const {
return type_ == a.type_ && string_ == a.string_ && repeat_ == a.repeat_;
}
CSSSyntaxType GetType() const { return type_; }
const String& GetString() const { return string_; }
CSSSyntaxRepeat GetRepeat() const { return repeat_; }
bool IsRepeatable() const { return repeat_ != CSSSyntaxRepeat::kNone; }
bool IsInteger() const { return type_ == CSSSyntaxType::kInteger; }
char Separator() const {
DCHECK(IsRepeatable());
return repeat_ == CSSSyntaxRepeat::kSpaceSeparated ? ' ' : ',';
}
bool CanTake(const CSSStyleValue&) const;
private:
CSSSyntaxType type_;
String string_; // Only used when type_ is CSSSyntaxType::kIdent
CSSSyntaxRepeat repeat_;
};
class CORE_EXPORT CSSSyntaxDescriptor {
public:
explicit CSSSyntaxDescriptor(const String& syntax);
......
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