Home | History | Annotate | Download | only in css
      1 /*
      2  * Copyright (C) 2012 Apple Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      7  * 1. Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  * 2. Redistributions in binary form must reproduce the above copyright
     10  *    notice, this list of conditions and the following disclaimer in the
     11  *    documentation and/or other materials provided with the distribution.
     12  *
     13  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
     14  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
     17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
     21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 #ifndef PropertySetCSSStyleDeclaration_h
     27 #define PropertySetCSSStyleDeclaration_h
     28 
     29 #include "core/css/CSSStyleDeclaration.h"
     30 #include "wtf/HashMap.h"
     31 #include "wtf/OwnPtr.h"
     32 
     33 namespace WebCore {
     34 
     35 class CSSProperty;
     36 class CSSRule;
     37 class CSSValue;
     38 class Element;
     39 class ExceptionState;
     40 class MutableStylePropertySet;
     41 class StyleSheetContents;
     42 
     43 class PropertySetCSSStyleDeclaration : public CSSStyleDeclaration {
     44 public:
     45     PropertySetCSSStyleDeclaration(MutableStylePropertySet* propertySet) : m_propertySet(propertySet) { }
     46 
     47     virtual Element* parentElement() const { return 0; }
     48     virtual void clearParentElement() { ASSERT_NOT_REACHED(); }
     49     StyleSheetContents* contextStyleSheet() const;
     50 
     51     virtual void ref() OVERRIDE;
     52     virtual void deref() OVERRIDE;
     53 
     54 private:
     55     virtual CSSRule* parentRule() const OVERRIDE { return 0; };
     56     virtual unsigned length() const OVERRIDE;
     57     virtual String item(unsigned index) const OVERRIDE;
     58     virtual PassRefPtr<CSSValue> getPropertyCSSValue(const String& propertyName) OVERRIDE;
     59     virtual String getPropertyValue(const String& propertyName) OVERRIDE;
     60     virtual String getPropertyPriority(const String& propertyName) OVERRIDE;
     61     virtual String getPropertyShorthand(const String& propertyName) OVERRIDE;
     62     virtual bool isPropertyImplicit(const String& propertyName) OVERRIDE;
     63     virtual void setProperty(const String& propertyName, const String& value, const String& priority, ExceptionState&) OVERRIDE;
     64     virtual String removeProperty(const String& propertyName, ExceptionState&) OVERRIDE;
     65     virtual String cssText() const OVERRIDE;
     66     virtual void setCSSText(const String&, ExceptionState&) OVERRIDE;
     67     virtual PassRefPtr<CSSValue> getPropertyCSSValueInternal(CSSPropertyID) OVERRIDE;
     68     virtual String getPropertyValueInternal(CSSPropertyID) OVERRIDE;
     69     virtual void setPropertyInternal(CSSPropertyID, const String& value, bool important, ExceptionState&) OVERRIDE;
     70 
     71     virtual unsigned variableCount() const OVERRIDE;
     72     virtual String variableValue(const AtomicString& name) const OVERRIDE;
     73     virtual bool setVariableValue(const AtomicString& name, const String& value, ExceptionState&) OVERRIDE;
     74     virtual bool removeVariable(const AtomicString& name) OVERRIDE;
     75     virtual bool clearVariables(ExceptionState&) OVERRIDE;
     76     virtual PassRefPtr<CSSVariablesIterator> variablesIterator() const OVERRIDE;
     77 
     78     virtual bool cssPropertyMatches(CSSPropertyID, const CSSValue*) const OVERRIDE;
     79     virtual PassRefPtr<MutableStylePropertySet> copyProperties() const OVERRIDE;
     80 
     81     CSSValue* cloneAndCacheForCSSOM(CSSValue*);
     82 
     83 protected:
     84     enum MutationType { NoChanges, PropertyChanged };
     85     virtual void willMutate() { }
     86     virtual void didMutate(MutationType) { }
     87 
     88     MutableStylePropertySet* m_propertySet;
     89     OwnPtr<HashMap<CSSValue*, RefPtr<CSSValue> > > m_cssomCSSValueClones;
     90 };
     91 
     92 class StyleRuleCSSStyleDeclaration : public PropertySetCSSStyleDeclaration
     93 {
     94 public:
     95     static PassRefPtr<StyleRuleCSSStyleDeclaration> create(MutableStylePropertySet* propertySet, CSSRule* parentRule)
     96     {
     97         return adoptRef(new StyleRuleCSSStyleDeclaration(propertySet, parentRule));
     98     }
     99 
    100     void clearParentRule() { m_parentRule = 0; }
    101 
    102     virtual void ref() OVERRIDE;
    103     virtual void deref() OVERRIDE;
    104 
    105     void reattach(MutableStylePropertySet*);
    106 
    107 private:
    108     StyleRuleCSSStyleDeclaration(MutableStylePropertySet*, CSSRule*);
    109     virtual ~StyleRuleCSSStyleDeclaration();
    110 
    111     virtual CSSStyleSheet* parentStyleSheet() const OVERRIDE;
    112 
    113     virtual CSSRule* parentRule() const OVERRIDE { return m_parentRule;  }
    114 
    115     virtual void willMutate() OVERRIDE;
    116     virtual void didMutate(MutationType) OVERRIDE;
    117 
    118     unsigned m_refCount;
    119     CSSRule* m_parentRule;
    120 };
    121 
    122 class InlineCSSStyleDeclaration : public PropertySetCSSStyleDeclaration
    123 {
    124 public:
    125     InlineCSSStyleDeclaration(MutableStylePropertySet* propertySet, Element* parentElement)
    126         : PropertySetCSSStyleDeclaration(propertySet)
    127         , m_parentElement(parentElement)
    128     {
    129     }
    130 
    131 private:
    132     virtual CSSStyleSheet* parentStyleSheet() const OVERRIDE;
    133     virtual Element* parentElement() const OVERRIDE { return m_parentElement; }
    134     virtual void clearParentElement() OVERRIDE { m_parentElement = 0; }
    135 
    136     virtual void didMutate(MutationType) OVERRIDE;
    137 
    138     Element* m_parentElement;
    139 };
    140 
    141 } // namespace WebCore
    142 
    143 #endif
    144