1/*
2 * Copyright (C) 2004 Zack Rusin <zack@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2008, 2012 Apple Inc. All rights reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301  USA
19 */
20
21#ifndef CSSComputedStyleDeclaration_h
22#define CSSComputedStyleDeclaration_h
23
24#include "core/css/CSSStyleDeclaration.h"
25#include "core/rendering/style/RenderStyleConstants.h"
26#include "wtf/HashMap.h"
27#include "wtf/RefPtr.h"
28#include "wtf/text/AtomicString.h"
29#include "wtf/text/AtomicStringHash.h"
30#include "wtf/text/WTFString.h"
31
32namespace WebCore {
33
34class CSSPrimitiveValue;
35class CSSValueList;
36class Color;
37class CustomFilterNumberParameter;
38class CustomFilterParameter;
39class ExceptionState;
40class MutableStylePropertySet;
41class Node;
42class RenderObject;
43class RenderStyle;
44class SVGPaint;
45class ShadowData;
46class ShadowList;
47class StylePropertySet;
48class StylePropertyShorthand;
49
50enum EUpdateLayout { DoNotUpdateLayout = false, UpdateLayout = true };
51
52class CSSComputedStyleDeclaration : public CSSStyleDeclaration {
53private:
54    class ComputedCSSVariablesIterator : public CSSVariablesIterator {
55    public:
56        virtual ~ComputedCSSVariablesIterator() { }
57        static PassRefPtr<ComputedCSSVariablesIterator> create(const HashMap<AtomicString, String>* variableMap) { return adoptRef(new ComputedCSSVariablesIterator(variableMap)); }
58    private:
59        explicit ComputedCSSVariablesIterator(const HashMap<AtomicString, String>* variableMap);
60        virtual void advance() OVERRIDE;
61        virtual bool atEnd() const OVERRIDE { return m_it == m_end; }
62        virtual AtomicString name() const OVERRIDE;
63        virtual String value() const OVERRIDE;
64        bool m_active;
65        typedef HashMap<AtomicString, String>::const_iterator VariablesMapIterator;
66        VariablesMapIterator m_it;
67        VariablesMapIterator m_end;
68    };
69
70public:
71    static PassRefPtr<CSSComputedStyleDeclaration> create(PassRefPtr<Node> node, bool allowVisitedStyle = false, const String& pseudoElementName = String())
72    {
73        return adoptRef(new CSSComputedStyleDeclaration(node, allowVisitedStyle, pseudoElementName));
74    }
75    virtual ~CSSComputedStyleDeclaration();
76
77    virtual void ref() OVERRIDE;
78    virtual void deref() OVERRIDE;
79
80    PassRefPtr<CSSValue> getPropertyCSSValue(CSSPropertyID) const;
81    String getPropertyValue(CSSPropertyID) const;
82    bool getPropertyPriority(CSSPropertyID) const;
83
84    virtual PassRefPtr<MutableStylePropertySet> copyProperties() const OVERRIDE;
85
86    PassRefPtr<CSSValue> getPropertyCSSValue(CSSPropertyID, EUpdateLayout) const;
87    PassRefPtr<CSSValue> getFontSizeCSSValuePreferringKeyword() const;
88    bool useFixedFontDefaultSize() const;
89    PassRefPtr<CSSValue> getSVGPropertyCSSValue(CSSPropertyID, EUpdateLayout) const;
90
91    PassRefPtr<MutableStylePropertySet> copyPropertiesInSet(const Vector<CSSPropertyID>&) const;
92
93private:
94    CSSComputedStyleDeclaration(PassRefPtr<Node>, bool allowVisitedStyle, const String&);
95
96    // The styled node is either the node passed into getComputedStyle, or the
97    // PseudoElement for :before and :after if they exist.
98    // FIXME: This should be styledElement since in JS getComputedStyle only works
99    // on Elements, but right now editing creates these for text nodes. We should fix
100    // that.
101    Node* styledNode() const;
102
103    // CSSOM functions. Don't make these public.
104    virtual CSSRule* parentRule() const;
105    virtual unsigned length() const;
106    virtual String item(unsigned index) const;
107    PassRefPtr<RenderStyle> computeRenderStyle(CSSPropertyID) const;
108    virtual PassRefPtr<CSSValue> getPropertyCSSValue(const String& propertyName);
109    virtual String getPropertyValue(const String& propertyName);
110    virtual String getPropertyPriority(const String& propertyName);
111    virtual String getPropertyShorthand(const String& propertyName);
112    virtual bool isPropertyImplicit(const String& propertyName);
113    virtual void setProperty(const String& propertyName, const String& value, const String& priority, ExceptionState&);
114    virtual String removeProperty(const String& propertyName, ExceptionState&);
115    virtual String cssText() const;
116    virtual void setCSSText(const String&, ExceptionState&);
117    virtual PassRefPtr<CSSValue> getPropertyCSSValueInternal(CSSPropertyID);
118    virtual String getPropertyValueInternal(CSSPropertyID);
119    virtual void setPropertyInternal(CSSPropertyID, const String& value, bool important, ExceptionState&);
120
121    const HashMap<AtomicString, String>* variableMap() const;
122    virtual unsigned variableCount() const OVERRIDE;
123    virtual String variableValue(const AtomicString& name) const OVERRIDE;
124    virtual bool setVariableValue(const AtomicString& name, const String& value, ExceptionState&) OVERRIDE;
125    virtual bool removeVariable(const AtomicString& name) OVERRIDE;
126    virtual bool clearVariables(ExceptionState&) OVERRIDE;
127    virtual PassRefPtr<CSSVariablesIterator> variablesIterator() const OVERRIDE { return ComputedCSSVariablesIterator::create(variableMap()); }
128
129    virtual bool cssPropertyMatches(CSSPropertyID, const CSSValue*) const OVERRIDE;
130
131    PassRefPtr<CSSValue> valueForShadowData(const ShadowData&, const RenderStyle&, bool useSpread) const;
132    PassRefPtr<CSSValue> valueForShadowList(const ShadowList*, const RenderStyle&, bool useSpread) const;
133    PassRefPtr<CSSPrimitiveValue> currentColorOrValidColor(const RenderStyle&, const Color&) const;
134    PassRefPtr<SVGPaint> adjustSVGPaintForCurrentColor(PassRefPtr<SVGPaint>, RenderStyle&) const;
135
136    PassRefPtr<CSSValue> valueForFilter(const RenderObject*, const RenderStyle&) const;
137
138    PassRefPtr<CSSValueList> valuesForShorthandProperty(const StylePropertyShorthand&) const;
139    PassRefPtr<CSSValueList> valuesForSidesShorthand(const StylePropertyShorthand&) const;
140    PassRefPtr<CSSValueList> valuesForBackgroundShorthand() const;
141    PassRefPtr<CSSValueList> valuesForGridShorthand(const StylePropertyShorthand&) const;
142
143    RefPtr<Node> m_node;
144    PseudoId m_pseudoElementSpecifier;
145    bool m_allowVisitedStyle;
146    unsigned m_refCount;
147};
148
149} // namespace WebCore
150
151#endif // CSSComputedStyleDeclaration_h
152