blob: 3eb73efe0841cc9edadadca07c26027e1fb4c84d [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.
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSSOM_CSS_UNSUPPORTED_STYLE_VALUE_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSSOM_CSS_UNSUPPORTED_STYLE_VALUE_H_
#include "base/macros.h"
#include "base/optional.h"
#include "third_party/blink/renderer/core/css/css_property_name.h"
#include "third_party/blink/renderer/core/css/cssom/css_style_value.h"
namespace blink {
// CSSUnsupportedStyleValue is the internal representation of a base
// CSSStyleValue that is returned when we do not yet support a CSS Typed OM type
// for a given CSS Value.
//
// It is either:
//
// * Tied to a specific CSS property, and therefore only valid for that
// property, or
// * Tied to no CSS property at all, in which case it's not valid for any
// property.
class CORE_EXPORT CSSUnsupportedStyleValue final : public CSSStyleValue {
public:
static CSSUnsupportedStyleValue* Create(const CSSValue& value) {
return MakeGarbageCollected<CSSUnsupportedStyleValue>(value.CssText());
}
static CSSUnsupportedStyleValue* Create(const String& css_text) {
return MakeGarbageCollected<CSSUnsupportedStyleValue>(css_text);
}
static CSSUnsupportedStyleValue* Create(const CSSPropertyName& name,
const String& css_text) {
return MakeGarbageCollected<CSSUnsupportedStyleValue>(name, css_text);
}
static CSSUnsupportedStyleValue* Create(const CSSPropertyName& name,
const CSSValue& value) {
return MakeGarbageCollected<CSSUnsupportedStyleValue>(name,
value.CssText());
}
CSSUnsupportedStyleValue(const String& css_text) { SetCSSText(css_text); }
CSSUnsupportedStyleValue(const CSSPropertyName& name, const String& css_text)
: name_(name) {
SetCSSText(css_text);
}
StyleValueType GetType() const override {
return StyleValueType::kUnknownType;
}
bool IsValidFor(const CSSPropertyName& name) const {
return name_ && *name_ == name;
}
const CSSValue* ToCSSValue() const override {
NOTREACHED();
return nullptr;
}
String toString() const final { return CSSText(); }
private:
base::Optional<CSSPropertyName> name_;
DISALLOW_COPY_AND_ASSIGN(CSSUnsupportedStyleValue);
};
DEFINE_TYPE_CASTS(CSSUnsupportedStyleValue,
CSSStyleValue,
value,
value->GetType() ==
CSSStyleValue::StyleValueType::kUnknownType,
value.GetType() ==
CSSStyleValue::StyleValueType::kUnknownType);
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_CSS_CSSOM_CSS_UNSUPPORTED_STYLE_VALUE_H_