blob: c0f01765a2e7946babfda0f5deac24c1bb91e26a [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/css_property_name.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/cssom/cssom_keywords.h"
#include "third_party/blink/renderer/core/css/properties/css_property.h"
namespace blink {
bool CSSOMTypes::IsCSSStyleValueLength(const CSSStyleValue& value) {
if (!value.IsNumericValue())
return false;
return static_cast<const CSSNumericValue&>(value).Type().
MatchesBaseType(CSSNumericValueType::BaseType::kLength);
}
bool CSSOMTypes::IsCSSStyleValueNumber(const CSSStyleValue& value) {
if (!value.IsNumericValue())
return false;
return static_cast<const CSSNumericValue&>(value).Type().
MatchesNumber();
}
bool CSSOMTypes::IsCSSStyleValueTime(const CSSStyleValue& value) {
if (!value.IsNumericValue())
return false;
return static_cast<const CSSNumericValue&>(value).Type().
MatchesBaseType(CSSNumericValueType::BaseType::kTime);
}
bool CSSOMTypes::IsCSSStyleValueAngle(const CSSStyleValue& value) {
if (!value.IsNumericValue())
return false;
return static_cast<const CSSNumericValue&>(value).Type().
MatchesBaseType(CSSNumericValueType::BaseType::kAngle);
}
bool CSSOMTypes::IsCSSStyleValuePercentage(const CSSStyleValue& value) {
if (!value.IsNumericValue())
return false;
return static_cast<const CSSNumericValue&>(value).Type().
MatchesPercentage();
}
bool CSSOMTypes::IsCSSStyleValueResolution(const CSSStyleValue& value) {
if (!value.IsNumericValue())
return false;
return static_cast<const CSSNumericValue&>(value).Type().
MatchesBaseType(CSSNumericValueType::BaseType::kResolution);
}
bool CSSOMTypes::IsCSSStyleValueFlex(const CSSStyleValue& value) {
if (!value.IsNumericValue())
return false;
return static_cast<const CSSNumericValue&>(value).Type().
MatchesBaseType(CSSNumericValueType::BaseType::kFlex);
}
bool CSSOMTypes::IsCSSStyleValueImage(const CSSStyleValue& value) {
return value.GetType() == CSSStyleValue::kURLImageType;
}
bool CSSOMTypes::IsCSSStyleValueTransform(const CSSStyleValue& value) {
return value.GetType() == CSSStyleValue::kTransformType;
}
bool CSSOMTypes::IsCSSStyleValuePosition(const CSSStyleValue& value) {
return value.GetType() == CSSStyleValue::kPositionType;
}
bool CSSOMTypes::IsPropertySupported(CSSPropertyID id) {
switch (id) {
case CSSPropertyID::kVariable:
{% for property in properties if property.typedom_types %}
case CSSPropertyID::{{property.enum_key}}:
{% endfor %}
return true;
default:
return false;
}
}
bool CSSOMTypes::PropertyCanTake(CSSPropertyID id,
const AtomicString& custom_property_name,
const CSSStyleValue& value) {
DCHECK_EQ(id == CSSPropertyID::kVariable, !custom_property_name.IsNull());
if (auto* css_keyword_value = DynamicTo<CSSKeywordValue>(value)) {
return CSSOMKeywords::ValidKeywordForProperty(id, *css_keyword_value);
}
if (auto* unsupported_style_value =
DynamicTo<CSSUnsupportedStyleValue>(value)) {
auto name = (id == CSSPropertyID::kVariable)
? CSSPropertyName(custom_property_name)
: CSSPropertyName(id);
return unsupported_style_value->IsValidFor(name);
}
if (value.GetType() == CSSStyleValue::kUnparsedType) {
return true;
}
switch (id) {
case CSSPropertyID::kVariable:
return value.GetType() == CSSStyleValue::kUnparsedType;
{% for property in properties if property.typedom_types %}
{% if property.typedom_types != ['Keyword'] %}
case CSSPropertyID::{{property.enum_key}}:
return (
{% for type in property.typedom_types if type != 'Keyword' %}
{{ "|| " if not loop.first }}CSSOMTypes::IsCSSStyleValue{{type}}(value)
{% endfor %}
);
{% endif %}
{% endfor %}
default:
return false;
}
}
} // namespace blink