blob: 6910a968e99830d272e0e1cf42f19a3026b75ad9 [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.
#include "third_party/blink/renderer/core/css/property_registry.h"
#include "third_party/blink/renderer/core/css/css_custom_property_declaration.h"
namespace blink {
void PropertyRegistry::RegisterProperty(const AtomicString& name,
PropertyRegistration& registration) {
DCHECK(!Registration(name));
registrations_.Set(name, &registration);
}
const PropertyRegistration* PropertyRegistry::Registration(
const AtomicString& name) const {
return registrations_.at(name);
}
const CSSValue* PropertyRegistry::ParseIfRegistered(
const Document& document,
const AtomicString& property_name,
const CSSValue* value) {
if (!value || !value->IsCustomPropertyDeclaration())
return value;
const PropertyRegistry* registry = document.GetPropertyRegistry();
if (!registry)
return value;
const PropertyRegistration* registration =
registry->Registration(property_name);
if (!registration)
return value;
CSSVariableData* tokens = ToCSSCustomPropertyDeclaration(value)->Value();
if (!tokens || tokens->NeedsVariableResolution())
return value;
const CSSValue* parsed_value = tokens->ParseForSyntax(
registration->Syntax(), document.GetSecureContextMode());
return parsed_value ? parsed_value : value;
}
} // namespace blink