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 void setVariableValue(const AtomicString& name, const String& value, ExceptionState&) OVERRIDE;
     74     virtual bool removeVariable(const AtomicString& name) OVERRIDE;
     75     virtual void clearVariables(ExceptionState&) OVERRIDE;
     76 
     77     virtual bool cssPropertyMatches(CSSPropertyID, const CSSValue*) const OVERRIDE;
     78     virtual PassRefPtr<MutableStylePropertySet> copyProperties() const OVERRIDE;
     79 
     80     CSSValue* cloneAndCacheForCSSOM(CSSValue*);
     81 
     82 protected:
     83     enum MutationType { NoChanges, PropertyChanged };
     84     virtual void willMutate() { }
     85     virtual void didMutate(MutationType) { }
     86 
     87     MutableStylePropertySet* m_propertySet;
     88     OwnPtr<HashMap<CSSValue*, RefPtr<CSSValue> > > m_cssomCSSValueClones;
     89 };
     90 
     91 class StyleRuleCSSStyleDeclaration : public PropertySetCSSStyleDeclaration
     92 {
     93 public:
     94     static PassRefPtr<StyleRuleCSSStyleDeclaration> create(MutableStylePropertySet* propertySet, CSSRule* parentRule)
     95     {
     96         return adoptRef(new StyleRuleCSSStyleDeclaration(propertySet, parentRule));
     97     }
     98 
     99     void clearParentRule() { m_parentRule = 0; }
    100 
    101     virtual void ref() OVERRIDE;
    102     virtual void deref() OVERRIDE;
    103 
    104     void reattach(MutableStylePropertySet*);
    105 
    106 private:
    107     StyleRuleCSSStyleDeclaration(MutableStylePropertySet*, CSSRule*);
    108     virtual ~StyleRuleCSSStyleDeclaration();
    109 
    110     virtual CSSStyleSheet* parentStyleSheet() const OVERRIDE;
    111 
    112     virtual CSSRule* parentRule() const OVERRIDE { return m_parentRule;  }
    113 
    114     virtual void willMutate() OVERRIDE;
    115     virtual void didMutate(MutationType) OVERRIDE;
    116 
    117     unsigned m_refCount;
    118     CSSRule* m_parentRule;
    119 };
    120 
    121 class InlineCSSStyleDeclaration : public PropertySetCSSStyleDeclaration
    122 {
    123 public:
    124     InlineCSSStyleDeclaration(MutableStylePropertySet* propertySet, Element* parentElement)
    125         : PropertySetCSSStyleDeclaration(propertySet)
    126         , m_parentElement(parentElement)
    127     {
    128     }
    129 
    130 private:
    131     virtual CSSStyleSheet* parentStyleSheet() const OVERRIDE;
    132     virtual Element* parentElement() const OVERRIDE { return m_parentElement; }
    133     virtual void clearParentElement() OVERRIDE { m_parentElement = 0; }
    134 
    135     virtual void didMutate(MutationType) OVERRIDE;
    136 
    137     Element* m_parentElement;
    138 };
    139 
    140 } // namespace WebCore
    141 
    142 #endif
    143