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"
39 class MutableStylePropertySet;
40 class StyleSheetContents;
42 class AbstractPropertySetCSSStyleDeclaration : public CSSStyleDeclaration {
44 virtual Element* parentElement() const { return 0; }
45 StyleSheetContents* contextStyleSheet() const;
47 virtual void trace(Visitor*) OVERRIDE;
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;
66 virtual bool cssPropertyMatches(CSSPropertyID, const CSSValue*) const OVERRIDE FINAL;
67 virtual PassRefPtrWillBeRawPtr<MutableStylePropertySet> copyProperties() const OVERRIDE FINAL;
69 CSSValue* cloneAndCacheForCSSOM(CSSValue*);
72 enum MutationType { NoChanges, PropertyChanged };
73 virtual void willMutate() { }
74 virtual void didMutate(MutationType) { }
75 virtual MutableStylePropertySet& propertySet() const = 0;
77 OwnPtrWillBeMember<WillBeHeapHashMap<RawPtrWillBeMember<CSSValue>, RefPtrWillBeMember<CSSValue> > > m_cssomCSSValueClones;
80 class PropertySetCSSStyleDeclaration : public AbstractPropertySetCSSStyleDeclaration {
82 PropertySetCSSStyleDeclaration(MutableStylePropertySet& propertySet) : m_propertySet(&propertySet) { }
85 virtual void ref() OVERRIDE;
86 virtual void deref() OVERRIDE;
89 virtual void trace(Visitor*) OVERRIDE;
92 virtual MutableStylePropertySet& propertySet() const OVERRIDE FINAL { ASSERT(m_propertySet); return *m_propertySet; }
94 RawPtrWillBeMember<MutableStylePropertySet> m_propertySet; // Cannot be null
97 class StyleRuleCSSStyleDeclaration FINAL : public PropertySetCSSStyleDeclaration
100 static PassRefPtrWillBeRawPtr<StyleRuleCSSStyleDeclaration> create(MutableStylePropertySet& propertySet, CSSRule* parentRule)
102 return adoptRefWillBeNoop(new StyleRuleCSSStyleDeclaration(propertySet, parentRule));
106 void clearParentRule() { m_parentRule = nullptr; }
108 virtual void ref() OVERRIDE;
109 virtual void deref() OVERRIDE;
112 void reattach(MutableStylePropertySet&);
114 virtual void trace(Visitor*) OVERRIDE;
117 StyleRuleCSSStyleDeclaration(MutableStylePropertySet&, CSSRule*);
118 virtual ~StyleRuleCSSStyleDeclaration();
120 virtual CSSStyleSheet* parentStyleSheet() const OVERRIDE;
122 virtual CSSRule* parentRule() const OVERRIDE { return m_parentRule; }
124 virtual void willMutate() OVERRIDE;
125 virtual void didMutate(MutationType) OVERRIDE;
130 RawPtrWillBeMember<CSSRule> m_parentRule;
133 class InlineCSSStyleDeclaration FINAL : public AbstractPropertySetCSSStyleDeclaration
136 explicit InlineCSSStyleDeclaration(Element* parentElement)
137 : m_parentElement(parentElement)
141 virtual void trace(Visitor*) OVERRIDE;
144 virtual MutableStylePropertySet& propertySet() const OVERRIDE;
146 virtual void ref() OVERRIDE;
147 virtual void deref() OVERRIDE;
149 virtual CSSStyleSheet* parentStyleSheet() const OVERRIDE;
150 virtual Element* parentElement() const OVERRIDE { return m_parentElement; }
152 virtual void didMutate(MutationType) OVERRIDE;
154 RawPtrWillBeMember<Element> m_parentElement;