2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library 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.
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 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 #ifndef StyleResolverState_h
23 #define StyleResolverState_h
25 #include "core/CSSPropertyNames.h"
27 #include "core/css/CSSSVGDocumentValue.h"
28 #include "core/css/CSSToLengthConversionData.h"
29 #include "core/css/resolver/CSSToStyleMap.h"
30 #include "core/css/resolver/ElementResolveContext.h"
31 #include "core/css/resolver/ElementStyleResources.h"
32 #include "core/css/resolver/FontBuilder.h"
33 #include "core/dom/Document.h"
34 #include "core/dom/Element.h"
35 #include "core/rendering/style/CachedUAStyle.h"
36 #include "core/rendering/style/RenderStyle.h"
37 #include "core/rendering/style/StyleInheritedData.h"
41 class CSSAnimationUpdate;
42 class FontDescription;
45 class StyleResolverState {
47 WTF_MAKE_NONCOPYABLE(StyleResolverState);
49 StyleResolverState(Document&, Element*, RenderStyle* parentStyle = 0);
50 ~StyleResolverState();
52 // In FontFaceSet and CanvasRenderingContext2D, we don't have an element to grab the document from.
53 // This is why we have to store the document separately.
54 Document& document() const { return *m_document; }
55 // These are all just pass-through methods to ElementResolveContext.
56 Element* element() const { return m_elementContext.element(); }
57 const ContainerNode* parentNode() const { return m_elementContext.parentNode(); }
58 const RenderStyle* rootElementStyle() const { return m_elementContext.rootElementStyle(); }
59 EInsideLink elementLinkState() const { return m_elementContext.elementLinkState(); }
60 bool distributedToInsertionPoint() const { return m_elementContext.distributedToInsertionPoint(); }
62 const ElementResolveContext& elementContext() const { return m_elementContext; }
64 void setStyle(PassRefPtr<RenderStyle> style) { m_style = style; m_cssToLengthConversionData.setStyle(m_style.get()); }
65 const RenderStyle* style() const { return m_style.get(); }
66 RenderStyle* style() { return m_style.get(); }
67 PassRefPtr<RenderStyle> takeStyle() { return m_style.release(); }
69 const CSSToLengthConversionData& cssToLengthConversionData() const { return m_cssToLengthConversionData; }
71 void setAnimationUpdate(PassOwnPtrWillBeRawPtr<CSSAnimationUpdate>);
72 const CSSAnimationUpdate* animationUpdate() { return m_animationUpdate.get(); }
73 PassOwnPtrWillBeRawPtr<CSSAnimationUpdate> takeAnimationUpdate();
75 void setParentStyle(PassRefPtr<RenderStyle> parentStyle) { m_parentStyle = parentStyle; }
76 const RenderStyle* parentStyle() const { return m_parentStyle.get(); }
77 RenderStyle* parentStyle() { return m_parentStyle.get(); }
79 void setCurrentRule(StyleRule* currentRule) { m_currentRule = currentRule; }
80 const StyleRule* currentRule() const { return m_currentRule; }
82 // FIXME: These are effectively side-channel "out parameters" for the various
83 // map functions. When we map from CSS to style objects we use this state object
84 // to track various meta-data about that mapping (e.g. if it's cache-able).
85 // We need to move this data off of StyleResolverState and closer to the
86 // objects it applies to. Possibly separating (immutable) inputs from (mutable) outputs.
87 void setApplyPropertyToRegularStyle(bool isApply) { m_applyPropertyToRegularStyle = isApply; }
88 void setApplyPropertyToVisitedLinkStyle(bool isApply) { m_applyPropertyToVisitedLinkStyle = isApply; }
89 bool applyPropertyToRegularStyle() const { return m_applyPropertyToRegularStyle; }
90 bool applyPropertyToVisitedLinkStyle() const { return m_applyPropertyToVisitedLinkStyle; }
92 // Holds all attribute names found while applying "content" properties that contain an "attr()" value.
93 Vector<AtomicString>& contentAttrValues() { return m_contentAttrValues; }
95 void setLineHeightValue(CSSValue* value) { m_lineHeightValue = value; }
96 CSSValue* lineHeightValue() { return m_lineHeightValue; }
98 void cacheUserAgentBorderAndBackground()
100 // RenderTheme only needs the cached style if it has an appearance,
101 // and constructing it is expensive so we avoid it if possible.
102 if (!style()->hasAppearance())
105 m_cachedUAStyle = CachedUAStyle::create(style());
108 const CachedUAStyle* cachedUAStyle() const
110 return m_cachedUAStyle.get();
113 ElementStyleResources& elementStyleResources() { return m_elementStyleResources; }
114 const CSSToStyleMap& styleMap() const { return m_styleMap; }
115 CSSToStyleMap& styleMap() { return m_styleMap; }
117 // FIXME: Once styleImage can be made to not take a StyleResolverState
118 // this convenience function should be removed. As-is, without this, call
119 // sites are extremely verbose.
120 PassRefPtr<StyleImage> styleImage(CSSPropertyID propertyId, CSSValue* value)
122 return m_elementStyleResources.styleImage(document(), document().textLinkColors(), style()->color(), propertyId, value);
125 FontBuilder& fontBuilder() { return m_fontBuilder; }
126 // FIXME: These exist as a primitive way to track mutations to font-related properties
127 // on a RenderStyle. As designed, these are very error-prone, as some callers
128 // set these directly on the RenderStyle w/o telling us. Presumably we'll
129 // want to design a better wrapper around RenderStyle for tracking these mutations
130 // and separate it from StyleResolverState.
131 const FontDescription& parentFontDescription() { return m_parentStyle->fontDescription(); }
132 void setZoom(float f) { m_fontBuilder.didChangeFontParameters(m_style->setZoom(f)); }
133 void setEffectiveZoom(float f) { m_fontBuilder.didChangeFontParameters(m_style->setEffectiveZoom(f)); }
134 void setWritingMode(WritingMode writingMode) { m_fontBuilder.didChangeFontParameters(m_style->setWritingMode(writingMode)); }
135 void setTextOrientation(TextOrientation textOrientation) { m_fontBuilder.didChangeFontParameters(m_style->setTextOrientation(textOrientation)); }
138 ElementResolveContext m_elementContext;
139 RawPtrWillBeMember<Document> m_document;
141 // m_style is the primary output for each element's style resolve.
142 RefPtr<RenderStyle> m_style;
144 CSSToLengthConversionData m_cssToLengthConversionData;
146 // m_parentStyle is not always just element->parentNode()->style()
147 // so we keep it separate from m_elementContext.
148 RefPtr<RenderStyle> m_parentStyle;
150 OwnPtrWillBeMember<CSSAnimationUpdate> m_animationUpdate;
152 bool m_applyPropertyToRegularStyle;
153 bool m_applyPropertyToVisitedLinkStyle;
155 RawPtrWillBeMember<CSSValue> m_lineHeightValue;
157 FontBuilder m_fontBuilder;
159 OwnPtr<CachedUAStyle> m_cachedUAStyle;
161 ElementStyleResources m_elementStyleResources;
162 // CSSToStyleMap is a pure-logic class and only contains
163 // a back-pointer to this object.
164 CSSToStyleMap m_styleMap;
165 Vector<AtomicString> m_contentAttrValues;
167 RawPtrWillBeMember<StyleRule> m_currentRule;
172 #endif // StyleResolverState_h