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 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 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 | #pragma once
|
---|
27 |
|
---|
28 | #include "CSSParserContext.h"
|
---|
29 | #include "CSSStyleDeclaration.h"
|
---|
30 | #include "DeprecatedCSSOMValue.h"
|
---|
31 | #include <memory>
|
---|
32 | #include <wtf/HashMap.h>
|
---|
33 | #include <wtf/RefPtr.h>
|
---|
34 | #include <wtf/WeakPtr.h>
|
---|
35 |
|
---|
36 | namespace WebCore {
|
---|
37 |
|
---|
38 | class CSSRule;
|
---|
39 | class CSSProperty;
|
---|
40 | class CSSValue;
|
---|
41 | class MutableStyleProperties;
|
---|
42 | class StyleSheetContents;
|
---|
43 | class StyledElement;
|
---|
44 |
|
---|
45 | class PropertySetCSSStyleDeclaration : public CSSStyleDeclaration {
|
---|
46 | WTF_MAKE_ISO_ALLOCATED(PropertySetCSSStyleDeclaration);
|
---|
47 | public:
|
---|
48 | explicit PropertySetCSSStyleDeclaration(MutableStyleProperties& propertySet)
|
---|
49 | : m_propertySet(&propertySet)
|
---|
50 | { }
|
---|
51 |
|
---|
52 | virtual void clearParentElement() { ASSERT_NOT_REACHED(); }
|
---|
53 |
|
---|
54 | StyleSheetContents* contextStyleSheet() const;
|
---|
55 |
|
---|
56 | protected:
|
---|
57 | enum MutationType { NoChanges, PropertyChanged };
|
---|
58 |
|
---|
59 | virtual CSSParserContext cssParserContext() const;
|
---|
60 |
|
---|
61 | MutableStyleProperties* m_propertySet;
|
---|
62 | HashMap<CSSValue*, WeakPtr<DeprecatedCSSOMValue>> m_cssomValueWrappers;
|
---|
63 |
|
---|
64 | private:
|
---|
65 | void ref() override;
|
---|
66 | void deref() override;
|
---|
67 |
|
---|
68 | CSSRule* parentRule() const override { return nullptr; }
|
---|
69 | unsigned length() const final;
|
---|
70 | String item(unsigned index) const final;
|
---|
71 | RefPtr<DeprecatedCSSOMValue> getPropertyCSSValue(const String& propertyName) final;
|
---|
72 | String getPropertyValue(const String& propertyName) final;
|
---|
73 | String getPropertyPriority(const String& propertyName) final;
|
---|
74 | String getPropertyShorthand(const String& propertyName) final;
|
---|
75 | bool isPropertyImplicit(const String& propertyName) final;
|
---|
76 | ExceptionOr<void> setProperty(const String& propertyName, const String& value, const String& priority) final;
|
---|
77 | ExceptionOr<String> removeProperty(const String& propertyName) final;
|
---|
78 | String cssText() const final;
|
---|
79 | ExceptionOr<void> setCssText(const String&) final;
|
---|
80 | RefPtr<CSSValue> getPropertyCSSValueInternal(CSSPropertyID) final;
|
---|
81 | String getPropertyValueInternal(CSSPropertyID) final;
|
---|
82 | ExceptionOr<void> setPropertyInternal(CSSPropertyID, const String& value, bool important) final;
|
---|
83 |
|
---|
84 | Ref<MutableStyleProperties> copyProperties() const final;
|
---|
85 |
|
---|
86 | RefPtr<DeprecatedCSSOMValue> wrapForDeprecatedCSSOM(CSSValue*);
|
---|
87 |
|
---|
88 | virtual bool willMutate() WARN_UNUSED_RETURN { return true; }
|
---|
89 | virtual void didMutate(MutationType) { }
|
---|
90 | };
|
---|
91 |
|
---|
92 | class StyleRuleCSSStyleDeclaration final : public PropertySetCSSStyleDeclaration {
|
---|
93 | WTF_MAKE_ISO_ALLOCATED(StyleRuleCSSStyleDeclaration);
|
---|
94 | public:
|
---|
95 | static Ref<StyleRuleCSSStyleDeclaration> create(MutableStyleProperties& propertySet, CSSRule& parentRule)
|
---|
96 | {
|
---|
97 | return adoptRef(*new StyleRuleCSSStyleDeclaration(propertySet, parentRule));
|
---|
98 | }
|
---|
99 | virtual ~StyleRuleCSSStyleDeclaration();
|
---|
100 |
|
---|
101 | void clearParentRule() { m_parentRule = nullptr; }
|
---|
102 |
|
---|
103 | void ref() final;
|
---|
104 | void deref() final;
|
---|
105 |
|
---|
106 | void reattach(MutableStyleProperties&);
|
---|
107 |
|
---|
108 | private:
|
---|
109 | StyleRuleCSSStyleDeclaration(MutableStyleProperties&, CSSRule&);
|
---|
110 |
|
---|
111 | CSSStyleSheet* parentStyleSheet() const final;
|
---|
112 |
|
---|
113 | CSSRule* parentRule() const final { return m_parentRule; }
|
---|
114 |
|
---|
115 | bool willMutate() final WARN_UNUSED_RETURN;
|
---|
116 | void didMutate(MutationType) final;
|
---|
117 | CSSParserContext cssParserContext() const final;
|
---|
118 |
|
---|
119 | unsigned m_refCount;
|
---|
120 | StyleRuleType m_parentRuleType;
|
---|
121 | CSSRule* m_parentRule;
|
---|
122 | };
|
---|
123 |
|
---|
124 | class InlineCSSStyleDeclaration final : public PropertySetCSSStyleDeclaration {
|
---|
125 | WTF_MAKE_ISO_ALLOCATED(InlineCSSStyleDeclaration);
|
---|
126 | public:
|
---|
127 | InlineCSSStyleDeclaration(MutableStyleProperties& propertySet, StyledElement& parentElement)
|
---|
128 | : PropertySetCSSStyleDeclaration(propertySet)
|
---|
129 | , m_parentElement(&parentElement)
|
---|
130 | {
|
---|
131 | }
|
---|
132 |
|
---|
133 | private:
|
---|
134 | CSSStyleSheet* parentStyleSheet() const final;
|
---|
135 | StyledElement* parentElement() const final { return m_parentElement; }
|
---|
136 | void clearParentElement() final { m_parentElement = nullptr; }
|
---|
137 |
|
---|
138 | bool willMutate() final WARN_UNUSED_RETURN;
|
---|
139 | void didMutate(MutationType) final;
|
---|
140 | CSSParserContext cssParserContext() const final;
|
---|
141 |
|
---|
142 | StyledElement* m_parentElement;
|
---|
143 | };
|
---|
144 |
|
---|
145 | } // namespace WebCore
|
---|