1 /*
2  * Copyright (C) 2004 Zack Rusin <zack@kde.org>
3  * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc.
4  * All rights reserved.
5  * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
6  * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
7  * Copyright (C) 2011 Sencha, Inc. All rights reserved.
8  * Copyright (C) 2015 Google Inc. All rights reserved.
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23  * 02110-1301  USA
24  */
25 
26 #include "third_party/blink/renderer/core/css/computed_style_css_value_mapping.h"
27 
28 #include "third_party/blink/renderer/core/css/css_custom_property_declaration.h"
29 #include "third_party/blink/renderer/core/css/css_value.h"
30 #include "third_party/blink/renderer/core/css/properties/longhands/custom_property.h"
31 #include "third_party/blink/renderer/core/css/property_registry.h"
32 #include "third_party/blink/renderer/core/style/computed_style.h"
33 
34 namespace blink {
35 
Get(const AtomicString custom_property_name,const ComputedStyle & style,const PropertyRegistry * registry)36 const CSSValue* ComputedStyleCSSValueMapping::Get(
37     const AtomicString custom_property_name,
38     const ComputedStyle& style,
39     const PropertyRegistry* registry) {
40   CustomProperty custom_property(custom_property_name, registry);
41   return custom_property.CSSValueFromComputedStyle(
42       style, nullptr /* layout_object */, false /* allow_visited_style */);
43 }
44 
45 HeapHashMap<AtomicString, Member<const CSSValue>>
GetVariables(const ComputedStyle & style,const PropertyRegistry * registry)46 ComputedStyleCSSValueMapping::GetVariables(const ComputedStyle& style,
47                                            const PropertyRegistry* registry) {
48   HeapHashMap<AtomicString, Member<const CSSValue>> variables;
49 
50   for (const AtomicString& name : style.GetVariableNames()) {
51     const CSSValue* value =
52         ComputedStyleCSSValueMapping::Get(name, style, registry);
53     if (value)
54       variables.Set(name, value);
55   }
56 
57   return variables;
58 }
59 
60 }  // namespace blink
61