Commit 45f985f4 authored by Anders Hartvoll Ruud's avatar Anders Hartvoll Ruud Committed by Commit Bot

Make Variable a Longhand, and implement ApplyValue.

This makes custom properties _almost_ normal w.r.t. style building.
As long as we DCHECK that the value is not initial/inherit before
applying, we can treat it as any other CSSProperty.

R=futhark@chromium.org

Bug: 751354
Change-Id: I2009320d95e1371df550fd2a55d7d561042d2061
Reviewed-on: https://chromium-review.googlesource.com/1076327
Commit-Queue: Anders Ruud <andruud@chromium.org>
Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#562574}
parent 2e6de028
...@@ -48,7 +48,7 @@ void StyleBuilder::ApplyProperty(const CSSProperty& property, ...@@ -48,7 +48,7 @@ void StyleBuilder::ApplyProperty(const CSSProperty& property,
case CSSPropertyVariable: case CSSPropertyVariable:
DCHECK(!isInitial); DCHECK(!isInitial);
DCHECK(!isInherit); DCHECK(!isInherit);
StyleBuilderFunctions::applyValueCSSPropertyVariable(state, value); ToLonghand(property).ApplyValue(state, value);
return; return;
default: default:
NOTREACHED(); NOTREACHED();
......
...@@ -25,9 +25,6 @@ class StyleBuilderFunctions { ...@@ -25,9 +25,6 @@ class StyleBuilderFunctions {
static void applyValue{{property.property_id}}(StyleResolverState&, const CSSValue&); static void applyValue{{property.property_id}}(StyleResolverState&, const CSSValue&);
{% endfor %} {% endfor %}
static void applyValueCSSPropertyVariable(StyleResolverState&,
const CSSValue&);
}; };
} // namespace blink } // namespace blink
......
...@@ -655,6 +655,7 @@ blink_core_sources("css") { ...@@ -655,6 +655,7 @@ blink_core_sources("css") {
"properties/longhands/translate_custom.cc", "properties/longhands/translate_custom.cc",
"properties/longhands/unicode_bidi_custom.cc", "properties/longhands/unicode_bidi_custom.cc",
"properties/longhands/user_select_custom.cc", "properties/longhands/user_select_custom.cc",
"properties/longhands/variable.cc",
"properties/longhands/variable.h", "properties/longhands/variable.h",
"properties/longhands/vector_effect_custom.cc", "properties/longhands/vector_effect_custom.cc",
"properties/longhands/vertical_align_custom.cc", "properties/longhands/vertical_align_custom.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/properties/longhands/variable.h"
#include "third_party/blink/renderer/core/css/css_custom_property_declaration.h"
#include "third_party/blink/renderer/core/css/property_registration.h"
#include "third_party/blink/renderer/core/css/property_registry.h"
#include "third_party/blink/renderer/core/style/computed_style.h"
namespace blink {
void Variable::ApplyValue(StyleResolverState& state,
const CSSValue& value) const {
const CSSCustomPropertyDeclaration& declaration =
ToCSSCustomPropertyDeclaration(value);
const AtomicString& name = declaration.GetName();
const PropertyRegistration* registration = nullptr;
const PropertyRegistry* registry = state.GetDocument().GetPropertyRegistry();
if (registry)
registration = registry->Registration(name);
bool is_inherited_property = !registration || registration->Inherits();
bool initial = declaration.IsInitial(is_inherited_property);
bool inherit = declaration.IsInherit(is_inherited_property);
DCHECK(!(initial && inherit));
if (!initial && !inherit) {
if (declaration.Value()->NeedsVariableResolution()) {
if (is_inherited_property) {
state.Style()->SetUnresolvedInheritedVariable(name,
declaration.Value());
} else {
state.Style()->SetUnresolvedNonInheritedVariable(name,
declaration.Value());
}
return;
}
if (!registration) {
state.Style()->SetResolvedUnregisteredVariable(name, declaration.Value());
return;
}
const CSSValue* parsed_value = declaration.Value()->ParseForSyntax(
registration->Syntax(), state.GetDocument().GetSecureContextMode());
if (parsed_value) {
DCHECK(parsed_value);
if (is_inherited_property) {
state.Style()->SetResolvedInheritedVariable(name, declaration.Value(),
parsed_value);
} else {
state.Style()->SetResolvedNonInheritedVariable(
name, declaration.Value(), parsed_value);
}
return;
}
if (is_inherited_property)
inherit = true;
else
initial = true;
}
DCHECK(initial ^ inherit);
state.Style()->RemoveVariable(name, is_inherited_property);
if (initial) {
return;
}
DCHECK(inherit);
CSSVariableData* parent_value =
state.ParentStyle()->GetVariable(name, is_inherited_property);
const CSSValue* parent_css_value =
registration && parent_value ? state.ParentStyle()->GetRegisteredVariable(
name, is_inherited_property)
: nullptr;
if (!is_inherited_property) {
DCHECK(registration);
if (parent_value) {
state.Style()->SetResolvedNonInheritedVariable(name, parent_value,
parent_css_value);
}
return;
}
if (parent_value) {
if (!registration) {
state.Style()->SetResolvedUnregisteredVariable(name, parent_value);
} else {
state.Style()->SetResolvedInheritedVariable(name, parent_value,
parent_css_value);
}
}
}
} // namespace blink
...@@ -9,13 +9,13 @@ ...@@ -9,13 +9,13 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_CSS_PROPERTIES_LONGHANDS_VARIABLE_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_CSS_PROPERTIES_LONGHANDS_VARIABLE_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_CSS_PROPERTIES_LONGHANDS_VARIABLE_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_CSS_PROPERTIES_LONGHANDS_VARIABLE_H_
#include "third_party/blink/renderer/core/css/properties/css_property.h" #include "third_party/blink/renderer/core/css/properties/longhand.h"
namespace blink { namespace blink {
class Variable final : public CSSProperty { class Variable final : public Longhand {
public: public:
constexpr Variable() : CSSProperty() {} constexpr Variable() : Longhand() {}
bool IsInherited() const override { return true; } bool IsInherited() const override { return true; }
bool IsAffectedByAll() const override { return false; } bool IsAffectedByAll() const override { return false; }
...@@ -34,6 +34,9 @@ class Variable final : public CSSProperty { ...@@ -34,6 +34,9 @@ class Variable final : public CSSProperty {
NOTREACHED(); NOTREACHED();
return nullptr; return nullptr;
} }
void ApplyValue(StyleResolverState& state,
const CSSValue& value) const override;
}; };
} // namespace blink } // namespace blink
......
...@@ -169,87 +169,4 @@ void StyleBuilder::ApplyProperty(const CSSProperty& property, ...@@ -169,87 +169,4 @@ void StyleBuilder::ApplyProperty(const CSSProperty& property,
StyleBuilder::ApplyProperty(property, state, value, is_initial, is_inherit); StyleBuilder::ApplyProperty(property, state, value, is_initial, is_inherit);
} }
void StyleBuilderFunctions::applyValueCSSPropertyVariable(
StyleResolverState& state,
const CSSValue& value) {
const CSSCustomPropertyDeclaration& declaration =
ToCSSCustomPropertyDeclaration(value);
const AtomicString& name = declaration.GetName();
const PropertyRegistration* registration = nullptr;
const PropertyRegistry* registry = state.GetDocument().GetPropertyRegistry();
if (registry)
registration = registry->Registration(name);
bool is_inherited_property = !registration || registration->Inherits();
bool initial = declaration.IsInitial(is_inherited_property);
bool inherit = declaration.IsInherit(is_inherited_property);
DCHECK(!(initial && inherit));
if (!initial && !inherit) {
if (declaration.Value()->NeedsVariableResolution()) {
if (is_inherited_property)
state.Style()->SetUnresolvedInheritedVariable(name,
declaration.Value());
else
state.Style()->SetUnresolvedNonInheritedVariable(name,
declaration.Value());
return;
}
if (!registration) {
state.Style()->SetResolvedUnregisteredVariable(name, declaration.Value());
return;
}
const CSSValue* parsed_value = declaration.Value()->ParseForSyntax(
registration->Syntax(), state.GetDocument().GetSecureContextMode());
if (parsed_value) {
DCHECK(parsed_value);
if (is_inherited_property)
state.Style()->SetResolvedInheritedVariable(name, declaration.Value(),
parsed_value);
else
state.Style()->SetResolvedNonInheritedVariable(
name, declaration.Value(), parsed_value);
return;
}
if (is_inherited_property)
inherit = true;
else
initial = true;
}
DCHECK(initial ^ inherit);
state.Style()->RemoveVariable(name, is_inherited_property);
if (initial) {
return;
}
DCHECK(inherit);
CSSVariableData* parent_value =
state.ParentStyle()->GetVariable(name, is_inherited_property);
const CSSValue* parent_css_value =
registration && parent_value ? state.ParentStyle()->GetRegisteredVariable(
name, is_inherited_property)
: nullptr;
if (!is_inherited_property) {
DCHECK(registration);
if (parent_value) {
state.Style()->SetResolvedNonInheritedVariable(name, parent_value,
parent_css_value);
}
return;
}
if (parent_value) {
if (!registration) {
state.Style()->SetResolvedUnregisteredVariable(name, parent_value);
} else {
state.Style()->SetResolvedInheritedVariable(name, parent_value,
parent_css_value);
}
}
}
} // namespace blink } // 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