2 * Copyright (C) 2012 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef PropertySetCSSStyleDeclaration_h
27 #define PropertySetCSSStyleDeclaration_h
29 #include "core/css/CSSStyleDeclaration.h"
30 #include "wtf/HashMap.h"
31 #include "wtf/OwnPtr.h"
40 class MutableStylePropertySet;
41 class StyleSheetContents;
43 class AbstractPropertySetCSSStyleDeclaration : public CSSStyleDeclaration {
45 virtual Element* parentElement() const { return 0; }
46 StyleSheetContents* contextStyleSheet() const;
48 virtual void trace(Visitor*) OVERRIDE;
51 virtual CSSRule* parentRule() const OVERRIDE { return 0; }
52 virtual unsigned length() const OVERRIDE FINAL;
53 virtual String item(unsigned index) const OVERRIDE FINAL;
54 virtual PassRefPtrWillBeRawPtr<CSSValue> getPropertyCSSValue(const String& propertyName) OVERRIDE FINAL;
55 virtual String getPropertyValue(const String& propertyName) OVERRIDE FINAL;
56 virtual String getPropertyPriority(const String& propertyName) OVERRIDE FINAL;
57 virtual String getPropertyShorthand(const String& propertyName) OVERRIDE FINAL;
58 virtual bool isPropertyImplicit(const String& propertyName) OVERRIDE FINAL;
59 virtual void setProperty(const String& propertyName, const String& value, const String& priority, ExceptionState&) OVERRIDE FINAL;
60 virtual String removeProperty(const String& propertyName, ExceptionState&) OVERRIDE FINAL;
61 virtual String cssText() const OVERRIDE FINAL;
62 virtual void setCSSText(const String&, ExceptionState&) OVERRIDE FINAL;
63 virtual PassRefPtrWillBeRawPtr<CSSValue> getPropertyCSSValueInternal(CSSPropertyID) OVERRIDE FINAL;
64 virtual String getPropertyValueInternal(CSSPropertyID) OVERRIDE FINAL;
65 virtual void setPropertyInternal(CSSPropertyID, const String& value, bool important, ExceptionState&) OVERRIDE FINAL;
67 virtual bool cssPropertyMatches(CSSPropertyID, const CSSValue*) const OVERRIDE FINAL;
68 virtual PassRefPtrWillBeRawPtr<MutableStylePropertySet> copyProperties() const OVERRIDE FINAL;
70 CSSValue* cloneAndCacheForCSSOM(CSSValue*);
73 enum MutationType { NoChanges, PropertyChanged };
74 virtual void willMutate() { }
75 virtual void didMutate(MutationType) { }
76 virtual MutableStylePropertySet& propertySet() const = 0;
78 OwnPtrWillBeMember<WillBeHeapHashMap<RawPtrWillBeMember<CSSValue>, RefPtrWillBeMember<CSSValue> > > m_cssomCSSValueClones;
81 class PropertySetCSSStyleDeclaration : public AbstractPropertySetCSSStyleDeclaration {
83 PropertySetCSSStyleDeclaration(MutableStylePropertySet& propertySet) : m_propertySet(&propertySet) { }
86 virtual void ref() OVERRIDE;
87 virtual void deref() OVERRIDE;
90 virtual void trace(Visitor*) OVERRIDE;
93 virtual MutableStylePropertySet& propertySet() const OVERRIDE FINAL { ASSERT(m_propertySet); return *m_propertySet; }
95 RawPtrWillBeMember<MutableStylePropertySet> m_propertySet; // Cannot be null
98 class StyleRuleCSSStyleDeclaration FINAL : public PropertySetCSSStyleDeclaration
101 static PassRefPtrWillBeRawPtr<StyleRuleCSSStyleDeclaration> create(MutableStylePropertySet& propertySet, CSSRule* parentRule)
103 return adoptRefWillBeNoop(new StyleRuleCSSStyleDeclaration(propertySet, parentRule));
107 void clearParentRule() { m_parentRule = nullptr; }
109 virtual void ref() OVERRIDE;
110 virtual void deref() OVERRIDE;
113 void reattach(MutableStylePropertySet&);
115 virtual void trace(Visitor*) OVERRIDE;
118 StyleRuleCSSStyleDeclaration(MutableStylePropertySet&, CSSRule*);
119 virtual ~StyleRuleCSSStyleDeclaration();
121 virtual CSSStyleSheet* parentStyleSheet() const OVERRIDE;
123 virtual CSSRule* parentRule() const OVERRIDE { return m_parentRule; }
125 virtual void willMutate() OVERRIDE;
126 virtual void didMutate(MutationType) OVERRIDE;
131 RawPtrWillBeMember<CSSRule> m_parentRule;
134 class InlineCSSStyleDeclaration FINAL : public AbstractPropertySetCSSStyleDeclaration
137 explicit InlineCSSStyleDeclaration(Element* parentElement)
138 : m_parentElement(parentElement)
142 virtual void trace(Visitor*) OVERRIDE;
145 virtual MutableStylePropertySet& propertySet() const OVERRIDE;
147 virtual void ref() OVERRIDE;
148 virtual void deref() OVERRIDE;
150 virtual CSSStyleSheet* parentStyleSheet() const OVERRIDE;
151 virtual Element* parentElement() const OVERRIDE { return m_parentElement; }
153 virtual void didMutate(MutationType) OVERRIDE;
155 RawPtrWillBeMember<Element> m_parentElement;