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