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 blink {
     34 
     35 class CSSRule;
     36 class CSSValue;
     37 class Element;
     38 class ExceptionState;
     39 class MutableStylePropertySet;
     40 class StyleSheetContents;
     41 
     42 class AbstractPropertySetCSSStyleDeclaration : public CSSStyleDeclaration {
     43 public:
     44     virtual Element* parentElement() const { return 0; }
     45     StyleSheetContents* contextStyleSheet() const;
     46 
     47     virtual void trace(Visitor*) OVERRIDE;
     48 
     49 private:
     50     virtual CSSRule* parentRule() const OVERRIDE { return 0; }
     51     virtual unsigned length() const OVERRIDE FINAL;
     52     virtual String item(unsigned index) const OVERRIDE FINAL;
     53     virtual PassRefPtrWillBeRawPtr<CSSValue> getPropertyCSSValue(const String& propertyName) OVERRIDE FINAL;
     54     virtual String getPropertyValue(const String& propertyName) OVERRIDE FINAL;
     55     virtual String getPropertyPriority(const String& propertyName) OVERRIDE FINAL;
     56     virtual String getPropertyShorthand(const String& propertyName) OVERRIDE FINAL;
     57     virtual bool isPropertyImplicit(const String& propertyName) OVERRIDE FINAL;
     58     virtual void setProperty(const String& propertyName, const String& value, const String& priority, ExceptionState&) OVERRIDE FINAL;
     59     virtual String removeProperty(const String& propertyName, ExceptionState&) OVERRIDE FINAL;
     60     virtual String cssText() const OVERRIDE FINAL;
     61     virtual void setCSSText(const String&, ExceptionState&) OVERRIDE FINAL;
     62     virtual PassRefPtrWillBeRawPtr<CSSValue> getPropertyCSSValueInternal(CSSPropertyID) OVERRIDE FINAL;
     63     virtual String getPropertyValueInternal(CSSPropertyID) OVERRIDE FINAL;
     64     virtual void setPropertyInternal(CSSPropertyID, const String& value, bool important, ExceptionState&) OVERRIDE FINAL;
     65 
     66     virtual bool cssPropertyMatches(CSSPropertyID, const CSSValue*) const OVERRIDE FINAL;
     67     virtual PassRefPtrWillBeRawPtr<MutableStylePropertySet> copyProperties() const OVERRIDE FINAL;
     68 
     69     CSSValue* cloneAndCacheForCSSOM(CSSValue*);
     70 
     71 protected:
     72     enum MutationType { NoChanges, PropertyChanged };
     73     virtual void willMutate() { }
     74     virtual void didMutate(MutationType) { }
     75     virtual MutableStylePropertySet& propertySet() const = 0;
     76 
     77     OwnPtrWillBeMember<WillBeHeapHashMap<RawPtrWillBeMember<CSSValue>, RefPtrWillBeMember<CSSValue> > > m_cssomCSSValueClones;
     78 };
     79 
     80 class PropertySetCSSStyleDeclaration : public AbstractPropertySetCSSStyleDeclaration {
     81 public:
     82     PropertySetCSSStyleDeclaration(MutableStylePropertySet& propertySet) : m_propertySet(&propertySet) { }
     83 
     84 #if !ENABLE(OILPAN)
     85     virtual void ref() OVERRIDE;
     86     virtual void deref() OVERRIDE;
     87 #endif
     88 
     89     virtual void trace(Visitor*) OVERRIDE;
     90 
     91 protected:
     92     virtual MutableStylePropertySet& propertySet() const OVERRIDE FINAL { ASSERT(m_propertySet); return *m_propertySet; }
     93 
     94     RawPtrWillBeMember<MutableStylePropertySet> m_propertySet; // Cannot be null
     95 };
     96 
     97 class StyleRuleCSSStyleDeclaration FINAL : public PropertySetCSSStyleDeclaration
     98 {
     99 public:
    100     static PassRefPtrWillBeRawPtr<StyleRuleCSSStyleDeclaration> create(MutableStylePropertySet& propertySet, CSSRule* parentRule)
    101     {
    102         return adoptRefWillBeNoop(new StyleRuleCSSStyleDeclaration(propertySet, parentRule));
    103     }
    104 
    105 #if !ENABLE(OILPAN)
    106     void clearParentRule() { m_parentRule = nullptr; }
    107 
    108     virtual void ref() OVERRIDE;
    109     virtual void deref() OVERRIDE;
    110 #endif
    111 
    112     void reattach(MutableStylePropertySet&);
    113 
    114     virtual void trace(Visitor*) OVERRIDE;
    115 
    116 private:
    117     StyleRuleCSSStyleDeclaration(MutableStylePropertySet&, CSSRule*);
    118     virtual ~StyleRuleCSSStyleDeclaration();
    119 
    120     virtual CSSStyleSheet* parentStyleSheet() const OVERRIDE;
    121 
    122     virtual CSSRule* parentRule() const OVERRIDE { return m_parentRule;  }
    123 
    124     virtual void willMutate() OVERRIDE;
    125     virtual void didMutate(MutationType) OVERRIDE;
    126 
    127 #if !ENABLE(OILPAN)
    128     unsigned m_refCount;
    129 #endif
    130     RawPtrWillBeMember<CSSRule> m_parentRule;
    131 };
    132 
    133 class InlineCSSStyleDeclaration FINAL : public AbstractPropertySetCSSStyleDeclaration
    134 {
    135 public:
    136     explicit InlineCSSStyleDeclaration(Element* parentElement)
    137         : m_parentElement(parentElement)
    138     {
    139     }
    140 
    141     virtual void trace(Visitor*) OVERRIDE;
    142 
    143 private:
    144     virtual MutableStylePropertySet& propertySet() const OVERRIDE;
    145 #if !ENABLE(OILPAN)
    146     virtual void ref() OVERRIDE;
    147     virtual void deref() OVERRIDE;
    148 #endif
    149     virtual CSSStyleSheet* parentStyleSheet() const OVERRIDE;
    150     virtual Element* parentElement() const OVERRIDE { return m_parentElement; }
    151 
    152     virtual void didMutate(MutationType) OVERRIDE;
    153 
    154     RawPtrWillBeMember<Element> m_parentElement;
    155 };
    156 
    157 } // namespace blink
    158 
    159 #endif
    160