1 | /* |
2 | * Copyright (C) 2004 Zack Rusin <zack@kde.org> |
3 | * Copyright (C) 2004-2019 Apple Inc. All rights reserved. |
4 | * |
5 | * This library is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Lesser General Public |
7 | * License as published by the Free Software Foundation; either |
8 | * version 2 of the License, or (at your option) any later version. |
9 | * |
10 | * This library is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Lesser General Public License for more details. |
14 | * |
15 | * You should have received a copy of the GNU Lesser General Public |
16 | * License along with this library; if not, write to the Free Software |
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
18 | * 02110-1301 USA |
19 | */ |
20 | |
21 | #pragma once |
22 | |
23 | #include "CSSStyleDeclaration.h" |
24 | #include "RenderStyleConstants.h" |
25 | #include "SVGRenderStyleDefs.h" |
26 | #include "TextFlags.h" |
27 | #include <wtf/IsoMalloc.h> |
28 | #include <wtf/RefPtr.h> |
29 | #include <wtf/text/WTFString.h> |
30 | |
31 | namespace WebCore { |
32 | |
33 | class CSSFontStyleValue; |
34 | class CSSPrimitiveValue; |
35 | class CSSValueList; |
36 | class Color; |
37 | class Element; |
38 | class FilterOperations; |
39 | class FontSelectionValue; |
40 | class MutableStyleProperties; |
41 | class Node; |
42 | class RenderElement; |
43 | class RenderStyle; |
44 | class SVGPaint; |
45 | class ShadowData; |
46 | class StyleProperties; |
47 | class StylePropertyShorthand; |
48 | |
49 | enum EUpdateLayout { DoNotUpdateLayout = false, UpdateLayout = true }; |
50 | |
51 | enum AdjustPixelValuesForComputedStyle { AdjustPixelValues, DoNotAdjustPixelValues }; |
52 | |
53 | class { |
54 | WTF_MAKE_FAST_ALLOCATED; |
55 | public: |
56 | (Node*, bool allowVisitedStyle = false, PseudoId = PseudoId::None); |
57 | (Element*, bool allowVisitedStyle = false, PseudoId = PseudoId::None); |
58 | |
59 | RefPtr<CSSValue> (CSSPropertyID, EUpdateLayout = UpdateLayout); |
60 | RefPtr<CSSValue> (const RenderStyle&, CSSPropertyID, RenderElement* = nullptr); |
61 | String (const String& propertyName); |
62 | RefPtr<CSSValue> (const String& propertyName); |
63 | |
64 | // Helper methods for HTML editing. |
65 | Ref<MutableStyleProperties> (const CSSPropertyID* set, unsigned length); |
66 | Ref<MutableStyleProperties> (); |
67 | RefPtr<CSSPrimitiveValue> (); |
68 | bool (); |
69 | bool (CSSPropertyID, const CSSValue*); |
70 | |
71 | static Ref<CSSValue> (const RenderStyle&, const FilterOperations&, AdjustPixelValuesForComputedStyle = AdjustPixelValues); |
72 | |
73 | static Ref<CSSPrimitiveValue> (FontSelectionValue); |
74 | static Ref<CSSPrimitiveValue> (FontSelectionValue); |
75 | static Ref<CSSPrimitiveValue> (FontSelectionValue); |
76 | static Ref<CSSPrimitiveValue> (FontSelectionValue); |
77 | static Ref<CSSFontStyleValue> (FontSelectionValue); |
78 | static Ref<CSSFontStyleValue> (Optional<FontSelectionValue>, FontStyleAxis); |
79 | |
80 | private: |
81 | // The styled element is either the element passed into |
82 | // computedPropertyValue, or the PseudoElement for :before and :after if |
83 | // they exist. |
84 | Element* () const; |
85 | |
86 | // The renderer we should use for resolving layout-dependent properties. |
87 | // Note that it differs from styledElement()->renderer() in the case we have |
88 | // no pseudo-element. |
89 | RenderElement* () const; |
90 | |
91 | RefPtr<CSSValue> (CSSPropertyID, EUpdateLayout); |
92 | Ref<CSSValue> (SVGPaintType, const String& url, const Color&, const Color& currentColor) const; |
93 | static Ref<CSSValue> valueForShadow(const ShadowData*, CSSPropertyID, const RenderStyle&, AdjustPixelValuesForComputedStyle = AdjustPixelValues); |
94 | Ref<CSSPrimitiveValue> (const RenderStyle*, const Color&) const; |
95 | |
96 | Ref<CSSValueList> getCSSPropertyValuesForShorthandProperties(const StylePropertyShorthand&); |
97 | RefPtr<CSSValueList> getCSSPropertyValuesFor2SidesShorthand(const StylePropertyShorthand&); |
98 | RefPtr<CSSValueList> getCSSPropertyValuesFor4SidesShorthand(const StylePropertyShorthand&); |
99 | Ref<CSSValueList> getBackgroundShorthandValue(); |
100 | Ref<CSSValueList> getCSSPropertyValuesForGridShorthand(const StylePropertyShorthand&); |
101 | |
102 | RefPtr<Element> ; |
103 | PseudoId ; |
104 | bool ; |
105 | }; |
106 | |
107 | class CSSComputedStyleDeclaration final : public CSSStyleDeclaration { |
108 | WTF_MAKE_ISO_ALLOCATED_EXPORT(CSSComputedStyleDeclaration, WEBCORE_EXPORT); |
109 | public: |
110 | static Ref<CSSComputedStyleDeclaration> create(Element& element, bool allowVisitedStyle = false, const String& pseudoElementName = String()) |
111 | { |
112 | return adoptRef(*new CSSComputedStyleDeclaration(element, allowVisitedStyle, pseudoElementName)); |
113 | } |
114 | virtual ~CSSComputedStyleDeclaration(); |
115 | |
116 | WEBCORE_EXPORT void ref() final; |
117 | WEBCORE_EXPORT void deref() final; |
118 | |
119 | String getPropertyValue(CSSPropertyID) const; |
120 | |
121 | private: |
122 | WEBCORE_EXPORT CSSComputedStyleDeclaration(Element&, bool allowVisitedStyle, const String&); |
123 | |
124 | // CSSOM functions. Don't make these public. |
125 | CSSRule* parentRule() const final; |
126 | unsigned length() const final; |
127 | String item(unsigned index) const final; |
128 | RefPtr<DeprecatedCSSOMValue> getPropertyCSSValue(const String& propertyName) final; |
129 | String getPropertyValue(const String& propertyName) final; |
130 | String getPropertyPriority(const String& propertyName) final; |
131 | String getPropertyShorthand(const String& propertyName) final; |
132 | bool isPropertyImplicit(const String& propertyName) final; |
133 | ExceptionOr<void> setProperty(const String& propertyName, const String& value, const String& priority) final; |
134 | ExceptionOr<String> removeProperty(const String& propertyName) final; |
135 | String cssText() const final; |
136 | ExceptionOr<void> setCssText(const String&) final; |
137 | RefPtr<CSSValue> getPropertyCSSValueInternal(CSSPropertyID) final; |
138 | String getPropertyValueInternal(CSSPropertyID) final; |
139 | ExceptionOr<bool> setPropertyInternal(CSSPropertyID, const String& value, bool important) final; |
140 | Ref<MutableStyleProperties> copyProperties() const final; |
141 | |
142 | RefPtr<CSSValue> getPropertyCSSValue(CSSPropertyID, EUpdateLayout = UpdateLayout) const; |
143 | |
144 | mutable Ref<Element> m_element; |
145 | PseudoId m_pseudoElementSpecifier; |
146 | bool m_allowVisitedStyle; |
147 | unsigned m_refCount; |
148 | }; |
149 | |
150 | } // namespace WebCore |
151 | |