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

Add variable set/get utilities on CSSVariableResolver.

R=futhark@chromium.org

Bug: 641877
Change-Id: I0b4dc43b29f7e30dbc3eab89f22ffa5505e6a333
Reviewed-on: https://chromium-review.googlesource.com/1235999
Commit-Queue: Anders Ruud <andruud@chromium.org>
Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#592788}
parent befcd8a0
...@@ -78,14 +78,8 @@ scoped_refptr<CSSVariableData> CSSVariableResolver::ValueForCustomProperty( ...@@ -78,14 +78,8 @@ scoped_refptr<CSSVariableData> CSSVariableResolver::ValueForCustomProperty(
const PropertyRegistration* registration = const PropertyRegistration* registration =
registry_ ? registry_->Registration(name) : nullptr; registry_ ? registry_->Registration(name) : nullptr;
CSSVariableData* variable_data = nullptr; CSSVariableData* variable_data = GetVariable(name, registration);
if (!registration || registration->Inherits()) {
if (inherited_variables_)
variable_data = inherited_variables_->GetVariable(name);
} else {
if (non_inherited_variables_)
variable_data = non_inherited_variables_->GetVariable(name);
}
if (!variable_data) if (!variable_data)
return registration ? registration->InitialVariableData() : nullptr; return registration ? registration->InitialVariableData() : nullptr;
...@@ -102,7 +96,7 @@ scoped_refptr<CSSVariableData> CSSVariableResolver::ValueForCustomProperty( ...@@ -102,7 +96,7 @@ scoped_refptr<CSSVariableData> CSSVariableResolver::ValueForCustomProperty(
scoped_refptr<CSSVariableData> new_variable_data = ResolveCustomProperty( scoped_refptr<CSSVariableData> new_variable_data = ResolveCustomProperty(
name, *variable_data, options, resolve_urls, unused_cycle_detected); name, *variable_data, options, resolve_urls, unused_cycle_detected);
if (!registration) { if (!registration) {
inherited_variables_->SetVariable(name, new_variable_data); SetVariable(name, registration, new_variable_data);
return new_variable_data; return new_variable_data;
} }
...@@ -113,13 +107,8 @@ scoped_refptr<CSSVariableData> CSSVariableResolver::ValueForCustomProperty( ...@@ -113,13 +107,8 @@ scoped_refptr<CSSVariableData> CSSVariableResolver::ValueForCustomProperty(
if (!parsed_value) if (!parsed_value)
new_variable_data = nullptr; new_variable_data = nullptr;
} }
if (registration->Inherits()) { SetVariable(name, registration, new_variable_data);
inherited_variables_->SetVariable(name, new_variable_data); SetRegisteredVariable(name, *registration, parsed_value);
inherited_variables_->SetRegisteredVariable(name, parsed_value);
} else {
non_inherited_variables_->SetVariable(name, new_variable_data);
non_inherited_variables_->SetRegisteredVariable(name, parsed_value);
}
if (!new_variable_data) if (!new_variable_data)
return registration->InitialVariableData(); return registration->InitialVariableData();
return new_variable_data; return new_variable_data;
...@@ -202,6 +191,55 @@ bool CSSVariableResolver::IsVariableDisallowed( ...@@ -202,6 +191,55 @@ bool CSSVariableResolver::IsVariableDisallowed(
variable_data.HasRootFontUnits()); variable_data.HasRootFontUnits());
} }
CSSVariableData* CSSVariableResolver::GetVariable(
const AtomicString& name,
const PropertyRegistration* registration) {
if (!registration || registration->Inherits()) {
return inherited_variables_ ? inherited_variables_->GetVariable(name)
: nullptr;
}
return non_inherited_variables_ ? non_inherited_variables_->GetVariable(name)
: nullptr;
}
const CSSValue* CSSVariableResolver::GetRegisteredVariable(
const AtomicString& name,
const PropertyRegistration& registration) {
if (registration.Inherits()) {
return inherited_variables_ ? inherited_variables_->RegisteredVariable(name)
: nullptr;
}
return non_inherited_variables_
? non_inherited_variables_->RegisteredVariable(name)
: nullptr;
}
void CSSVariableResolver::SetVariable(
const AtomicString& name,
const PropertyRegistration* registration,
scoped_refptr<CSSVariableData> variable_data) {
if (!registration || registration->Inherits()) {
DCHECK(inherited_variables_);
inherited_variables_->SetVariable(name, std::move(variable_data));
} else {
DCHECK(non_inherited_variables_);
non_inherited_variables_->SetVariable(name, std::move(variable_data));
}
}
void CSSVariableResolver::SetRegisteredVariable(
const AtomicString& name,
const PropertyRegistration& registration,
const CSSValue* value) {
if (registration.Inherits()) {
DCHECK(inherited_variables_);
inherited_variables_->SetRegisteredVariable(name, value);
} else {
DCHECK(non_inherited_variables_);
non_inherited_variables_->SetRegisteredVariable(name, value);
}
}
bool CSSVariableResolver::ResolveVariableReference(CSSParserTokenRange range, bool CSSVariableResolver::ResolveVariableReference(CSSParserTokenRange range,
const Options& options, const Options& options,
bool is_env_variable, bool is_env_variable,
......
...@@ -143,6 +143,20 @@ class CORE_EXPORT CSSVariableResolver { ...@@ -143,6 +143,20 @@ class CORE_EXPORT CSSVariableResolver {
const Options&, const Options&,
const PropertyRegistration*); const PropertyRegistration*);
// The following utilities get/set variables on either StyleInheritedVariables
// or StyleNonInheritedVariables, according to their PropertyRegistration.
CSSVariableData* GetVariable(const AtomicString& name,
const PropertyRegistration*);
const CSSValue* GetRegisteredVariable(const AtomicString& name,
const PropertyRegistration&);
void SetVariable(const AtomicString& name,
const PropertyRegistration*,
scoped_refptr<CSSVariableData>);
void SetRegisteredVariable(const AtomicString& name,
const PropertyRegistration&,
const CSSValue*);
const StyleResolverState& state_; const StyleResolverState& state_;
StyleInheritedVariables* inherited_variables_; StyleInheritedVariables* inherited_variables_;
StyleNonInheritedVariables* non_inherited_variables_; StyleNonInheritedVariables* non_inherited_variables_;
......
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