blob: 425b9d201482fd66d9013a75a30c521a133c0b30 [file] [log] [blame]
// 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.
{% from 'templates/macros.tmpl' import source_files_for_generated_file %}
{{source_files_for_generated_file(template_file, input_files)}}
#include "third_party/blink/renderer/core/css/cssom/cssom_types.h"
#include "third_party/blink/renderer/core/css/cssom/cssom_keywords.h"
#include "third_party/blink/renderer/core/css/cssom/css_keyword_value.h"
#include "third_party/blink/renderer/core/css/cssom/css_numeric_value.h"
#include "third_party/blink/renderer/core/css/cssom/css_style_value.h"
#include "third_party/blink/renderer/core/css/cssom/css_unsupported_style_value.h"
#include "third_party/blink/renderer/core/css/properties/css_property.h"
namespace blink {
namespace {
bool IsCSSStyleValueLength(const CSSStyleValue& value) {
if (!value.IsNumericValue())
return false;
return static_cast<const CSSNumericValue&>(value).Type().
MatchesBaseType(CSSNumericValueType::BaseType::kLength);
}
bool IsCSSStyleValueNumber(const CSSStyleValue& value) {
if (!value.IsNumericValue())
return false;
return static_cast<const CSSNumericValue&>(value).Type().
MatchesNumber();
}
bool IsCSSStyleValueTime(const CSSStyleValue& value) {
if (!value.IsNumericValue())
return false;
return static_cast<const CSSNumericValue&>(value).Type().
MatchesBaseType(CSSNumericValueType::BaseType::kTime);
}
bool IsCSSStyleValueAngle(const CSSStyleValue& value) {
if (!value.IsNumericValue())
return false;
return static_cast<const CSSNumericValue&>(value).Type().
MatchesBaseType(CSSNumericValueType::BaseType::kAngle);
}
bool IsCSSStyleValuePercentage(const CSSStyleValue& value) {
if (!value.IsNumericValue())
return false;
return static_cast<const CSSNumericValue&>(value).Type().
MatchesPercentage();
}
bool IsCSSStyleValueFlex(const CSSStyleValue& value) {
if (!value.IsNumericValue())
return false;
return static_cast<const CSSNumericValue&>(value).Type().
MatchesBaseType(CSSNumericValueType::BaseType::kFlex);
}
bool IsCSSStyleValueImage(const CSSStyleValue& value) {
return value.GetType() == CSSStyleValue::kURLImageType;
}
bool IsCSSStyleValueTransform(const CSSStyleValue& value) {
return value.GetType() == CSSStyleValue::kTransformType;
}
bool IsCSSStyleValuePosition(const CSSStyleValue& value) {
return value.GetType() == CSSStyleValue::kPositionType;
}
}
bool CSSOMTypes::IsPropertySupported(CSSPropertyID id) {
switch (id) {
case CSSPropertyVariable:
{% for property in properties if property.typedom_types %}
case {{property.property_id}}:
{% endfor %}
return true;
default:
return false;
}
}
bool CSSOMTypes::PropertyCanTake(CSSPropertyID id,
const CSSStyleValue& value) {
if (value.GetType() == CSSStyleValue::kKeywordType) {
return CSSOMKeywords::ValidKeywordForProperty(
id, ToCSSKeywordValue(value));
}
if (value.GetType() == CSSStyleValue::kUnknownType) {
return ToCSSUnsupportedStyleValue(value).GetProperty() == id;
}
if (value.GetType() == CSSStyleValue::kUnparsedType) {
return true;
}
switch (id) {
case CSSPropertyVariable:
return value.GetType() == CSSStyleValue::kUnparsedType;
{% for property in properties if property.typedom_types %}
{% if property.typedom_types != ['Keyword'] %}
case {{property.property_id}}:
return (
{% for type in property.typedom_types if type != 'Keyword' %}
{{ "|| " if not loop.first }}IsCSSStyleValue{{type}}(value)
{% endfor %}
);
{% endif %}
{% endfor %}
default:
return false;
}
}
} // namespace blink