1/*
2 * Copyright (C) 2004 Zack Rusin <zack@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2008, 2012, 2013 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 "CSSStyleDeclaration.h"
25#include "RenderStyleConstants.h"
26#include <wtf/RefPtr.h>
27#include <wtf/text/WTFString.h>
28
29namespace WebCore {
30
31class CSSPrimitiveValue;
32class CSSValueList;
33class Color;
34class MutableStylePropertySet;
35class Node;
36class RenderObject;
37class RenderStyle;
38class SVGPaint;
39class ShadowData;
40class StylePropertySet;
41class StylePropertyShorthand;
42
43#if ENABLE(CSS_SHADERS)
44class CustomFilterNumberParameter;
45class CustomFilterParameter;
46#endif
47
48enum EUpdateLayout { DoNotUpdateLayout = false, UpdateLayout = true };
49
50class ComputedStyleExtractor {
51public:
52    ComputedStyleExtractor(PassRefPtr<Node>, bool allowVisitedStyle = false, PseudoId = NOPSEUDO);
53
54    PassRefPtr<CSSValue> propertyValue(CSSPropertyID, EUpdateLayout = UpdateLayout) const;
55
56    // Helper methods for HTML editing.
57    PassRefPtr<MutableStylePropertySet> copyPropertiesInSet(const CSSPropertyID* set, unsigned length) const;
58    PassRefPtr<MutableStylePropertySet> copyProperties() const;
59    PassRefPtr<CSSPrimitiveValue> getFontSizeCSSValuePreferringKeyword() const;
60    bool useFixedFontDefaultSize() const;
61    bool propertyMatches(CSSPropertyID, const CSSValue*) const;
62
63private:
64    // The styled node is either the node passed into computedPropertyValue, or the
65    // PseudoElement for :before and :after if they exist.
66    // FIXME: This should be styledElement since in JS getComputedStyle only works
67    // on Elements, but right now editing creates these for text nodes. We should fix that.
68    Node* styledNode() const;
69
70#if ENABLE(SVG)
71    PassRefPtr<CSSValue> svgPropertyValue(CSSPropertyID, EUpdateLayout) const;
72    PassRefPtr<SVGPaint> adjustSVGPaintForCurrentColor(PassRefPtr<SVGPaint>, RenderStyle*) const;
73#endif
74
75    PassRefPtr<CSSValue> valueForShadow(const ShadowData*, CSSPropertyID, const RenderStyle*) const;
76    PassRefPtr<CSSPrimitiveValue> currentColorOrValidColor(RenderStyle*, const Color&) const;
77
78#if ENABLE(CSS_FILTERS)
79    PassRefPtr<CSSValue> valueForFilter(const RenderObject*, const RenderStyle*) const;
80#endif
81
82    PassRefPtr<CSSValueList> getCSSPropertyValuesForShorthandProperties(const StylePropertyShorthand&) const;
83    PassRefPtr<CSSValueList> getCSSPropertyValuesForSidesShorthand(const StylePropertyShorthand&) const;
84    PassRefPtr<CSSValueList> getBackgroundShorthandValue() const;
85    PassRefPtr<CSSValueList> getCSSPropertyValuesForGridShorthand(const StylePropertyShorthand&) const;
86
87    RefPtr<Node> m_node;
88    PseudoId m_pseudoElementSpecifier;
89    bool m_allowVisitedStyle;
90};
91
92class CSSComputedStyleDeclaration : public CSSStyleDeclaration {
93public:
94    static PassRefPtr<CSSComputedStyleDeclaration> create(PassRefPtr<Node> node, bool allowVisitedStyle = false, const String& pseudoElementName = String())
95    {
96        return adoptRef(new CSSComputedStyleDeclaration(node, allowVisitedStyle, pseudoElementName));
97    }
98    virtual ~CSSComputedStyleDeclaration();
99
100    virtual void ref() OVERRIDE;
101    virtual void deref() OVERRIDE;
102
103    String getPropertyValue(CSSPropertyID) const;
104
105private:
106    CSSComputedStyleDeclaration(PassRefPtr<Node>, bool allowVisitedStyle, const String&);
107
108    // CSSOM functions. Don't make these public.
109    virtual CSSRule* parentRule() const;
110    virtual unsigned length() const;
111    virtual String item(unsigned index) const;
112    virtual PassRefPtr<CSSValue> getPropertyCSSValue(const String& propertyName);
113    virtual String getPropertyValue(const String& propertyName);
114    virtual String getPropertyPriority(const String& propertyName);
115    virtual String getPropertyShorthand(const String& propertyName);
116    virtual bool isPropertyImplicit(const String& propertyName);
117    virtual void setProperty(const String& propertyName, const String& value, const String& priority, ExceptionCode&);
118    virtual String removeProperty(const String& propertyName, ExceptionCode&);
119    virtual String cssText() const;
120    virtual void setCssText(const String&, ExceptionCode&);
121    virtual PassRefPtr<CSSValue> getPropertyCSSValueInternal(CSSPropertyID);
122    virtual String getPropertyValueInternal(CSSPropertyID);
123    virtual void setPropertyInternal(CSSPropertyID, const String& value, bool important, ExceptionCode&);
124    virtual PassRefPtr<MutableStylePropertySet> copyProperties() const OVERRIDE;
125
126    PassRefPtr<CSSValue> getPropertyCSSValue(CSSPropertyID, EUpdateLayout = UpdateLayout) const;
127
128    RefPtr<Node> m_node;
129    PseudoId m_pseudoElementSpecifier;
130    bool m_allowVisitedStyle;
131    unsigned m_refCount;
132};
133
134} // namespace WebCore
135
136#endif // CSSComputedStyleDeclaration_h
137