| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 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. | 3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc.
All rights reserved. |
| 4 * | 4 * |
| 5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
| 6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
| 7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
| 8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
| 9 * | 9 * |
| 10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
| 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
| 14 * | 14 * |
| 15 * You should have received a copy of the GNU Library General Public License | 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 | 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, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
| 19 * | 19 * |
| 20 */ | 20 */ |
| 21 | 21 |
| 22 #ifndef StyleResolver_h | 22 #ifndef StyleResolver_h |
| 23 #define StyleResolver_h | 23 #define StyleResolver_h |
| 24 | 24 |
| 25 #include "core/CoreExport.h" | 25 #include "core/CoreExport.h" |
| 26 #include "core/animation/PropertyHandle.h" | 26 #include "core/animation/PropertyHandle.h" |
| 27 #include "core/css/ElementRuleCollector.h" | 27 #include "core/css/ElementRuleCollector.h" |
| 28 #include "core/css/PseudoStyleRequest.h" | 28 #include "core/css/PseudoStyleRequest.h" |
| 29 #include "core/css/RuleFeature.h" | |
| 30 #include "core/css/RuleSet.h" | |
| 31 #include "core/css/SelectorChecker.h" | 29 #include "core/css/SelectorChecker.h" |
| 32 #include "core/css/SelectorFilter.h" | 30 #include "core/css/SelectorFilter.h" |
| 33 #include "core/css/resolver/CSSPropertyPriority.h" | 31 #include "core/css/resolver/CSSPropertyPriority.h" |
| 34 #include "core/css/resolver/MatchedPropertiesCache.h" | 32 #include "core/css/resolver/MatchedPropertiesCache.h" |
| 35 #include "core/css/resolver/StyleBuilder.h" | 33 #include "core/css/resolver/StyleBuilder.h" |
| 36 #include "core/dom/DocumentOrderedList.h" | |
| 37 #include "core/style/CachedUAStyle.h" | 34 #include "core/style/CachedUAStyle.h" |
| 38 #include "platform/heap/Handle.h" | 35 #include "platform/heap/Handle.h" |
| 39 #include "wtf/Deque.h" | 36 #include "wtf/Deque.h" |
| 40 #include "wtf/HashMap.h" | 37 #include "wtf/HashMap.h" |
| 41 #include "wtf/HashSet.h" | 38 #include "wtf/HashSet.h" |
| 42 #include "wtf/ListHashSet.h" | 39 #include "wtf/ListHashSet.h" |
| 43 #include "wtf/RefPtr.h" | 40 #include "wtf/RefPtr.h" |
| 44 #include "wtf/Vector.h" | 41 #include "wtf/Vector.h" |
| 45 | 42 |
| 46 namespace blink { | 43 namespace blink { |
| 47 | 44 |
| 48 class AnimatableValue; | 45 class AnimatableValue; |
| 49 class CSSRuleList; | 46 class CSSRuleList; |
| 50 class CSSStyleSheet; | 47 class CSSStyleSheet; |
| 51 class CSSValue; | 48 class CSSValue; |
| 52 class ContainerNode; | 49 class ContainerNode; |
| 53 class Document; | 50 class Document; |
| 54 class Element; | 51 class Element; |
| 55 class Interpolation; | 52 class Interpolation; |
| 56 class MatchResult; | 53 class MatchResult; |
| 57 class MediaQueryEvaluator; | 54 class RuleSet; |
| 58 class ScopedStyleResolver; | 55 class ScopedStyleResolver; |
| 59 class StylePropertySet; | 56 class StylePropertySet; |
| 60 class StyleRule; | 57 class StyleRule; |
| 61 class ViewportStyleResolver; | |
| 62 | 58 |
| 63 enum StyleSharingBehavior { | 59 enum StyleSharingBehavior { |
| 64 AllowStyleSharing, | 60 AllowStyleSharing, |
| 65 DisallowStyleSharing, | 61 DisallowStyleSharing, |
| 66 }; | 62 }; |
| 67 | 63 |
| 68 enum RuleMatchingBehavior { | 64 enum RuleMatchingBehavior { |
| 69 MatchAllRules, | 65 MatchAllRules, |
| 70 MatchAllRulesExcludingSMIL | 66 MatchAllRulesExcludingSMIL |
| 71 }; | 67 }; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 92 static PassRefPtr<AnimatableValue> createAnimatableValueSnapshot(Element&, c
onst ComputedStyle* baseStyle, CSSPropertyID, CSSValue*); | 88 static PassRefPtr<AnimatableValue> createAnimatableValueSnapshot(Element&, c
onst ComputedStyle* baseStyle, CSSPropertyID, CSSValue*); |
| 93 static PassRefPtr<AnimatableValue> createAnimatableValueSnapshot(StyleResolv
erState&, CSSPropertyID, CSSValue*); | 89 static PassRefPtr<AnimatableValue> createAnimatableValueSnapshot(StyleResolv
erState&, CSSPropertyID, CSSValue*); |
| 94 | 90 |
| 95 PassRefPtr<ComputedStyle> pseudoStyleForElement(Element*, const PseudoStyleR
equest&, const ComputedStyle* parentStyle); | 91 PassRefPtr<ComputedStyle> pseudoStyleForElement(Element*, const PseudoStyleR
equest&, const ComputedStyle* parentStyle); |
| 96 | 92 |
| 97 PassRefPtr<ComputedStyle> styleForPage(int pageIndex); | 93 PassRefPtr<ComputedStyle> styleForPage(int pageIndex); |
| 98 PassRefPtr<ComputedStyle> styleForText(Text*); | 94 PassRefPtr<ComputedStyle> styleForText(Text*); |
| 99 | 95 |
| 100 static PassRefPtr<ComputedStyle> styleForDocument(Document&); | 96 static PassRefPtr<ComputedStyle> styleForDocument(Document&); |
| 101 | 97 |
| 102 // FIXME: It could be better to call appendAuthorStyleSheets() directly afte
r we factor StyleResolver further. | |
| 103 // https://bugs.webkit.org/show_bug.cgi?id=108890 | |
| 104 void appendAuthorStyleSheets(const HeapVector<Member<CSSStyleSheet>>&); | |
| 105 void resetAuthorStyle(TreeScope&); | |
| 106 void resetRuleFeatures(); | |
| 107 void finishAppendAuthorStyleSheets(); | |
| 108 | |
| 109 void lazyAppendAuthorStyleSheets(unsigned firstNew, const HeapVector<Member<
CSSStyleSheet>>&); | |
| 110 void removePendingAuthorStyleSheets(const HeapVector<Member<CSSStyleSheet>>&
); | |
| 111 void appendPendingAuthorStyleSheets(); | |
| 112 bool hasPendingAuthorStyleSheets() const { return m_pendingStyleSheets.size(
) > 0 || m_needCollectFeatures; } | |
| 113 | |
| 114 // TODO(esprehn): StyleResolver should probably not contain tree walking | 98 // TODO(esprehn): StyleResolver should probably not contain tree walking |
| 115 // state, instead we should pass a context object during recalcStyle. | 99 // state, instead we should pass a context object during recalcStyle. |
| 116 SelectorFilter& selectorFilter() { return m_selectorFilter; } | 100 SelectorFilter& selectorFilter() { return m_selectorFilter; } |
| 117 | 101 |
| 118 StyleRuleKeyframes* findKeyframesRule(const Element*, const AtomicString& an
imationName); | 102 StyleRuleKeyframes* findKeyframesRule(const Element*, const AtomicString& an
imationName); |
| 119 | 103 |
| 120 // These methods will give back the set of rules that matched for a given el
ement (or a pseudo-element). | 104 // These methods will give back the set of rules that matched for a given el
ement (or a pseudo-element). |
| 121 enum CSSRuleFilter { | 105 enum CSSRuleFilter { |
| 122 UAAndUserCSSRules = 1 << 1, | 106 UAAndUserCSSRules = 1 << 1, |
| 123 AuthorCSSRules = 1 << 2, | 107 AuthorCSSRules = 1 << 2, |
| 124 EmptyCSSRules = 1 << 3, | 108 EmptyCSSRules = 1 << 3, |
| 125 CrossOriginCSSRules = 1 << 4, | 109 CrossOriginCSSRules = 1 << 4, |
| 126 AllButEmptyCSSRules = UAAndUserCSSRules | AuthorCSSRules | CrossOriginCS
SRules, | 110 AllButEmptyCSSRules = UAAndUserCSSRules | AuthorCSSRules | CrossOriginCS
SRules, |
| 127 AllCSSRules = AllButEmptyCSSRules | EmptyCSSRules, | 111 AllCSSRules = AllButEmptyCSSRules | EmptyCSSRules, |
| 128 }; | 112 }; |
| 129 CSSRuleList* cssRulesForElement(Element*, unsigned rulesToInclude = AllButEm
ptyCSSRules); | 113 CSSRuleList* cssRulesForElement(Element*, unsigned rulesToInclude = AllButEm
ptyCSSRules); |
| 130 CSSRuleList* pseudoCSSRulesForElement(Element*, PseudoId, unsigned rulesToIn
clude = AllButEmptyCSSRules); | 114 CSSRuleList* pseudoCSSRulesForElement(Element*, PseudoId, unsigned rulesToIn
clude = AllButEmptyCSSRules); |
| 131 StyleRuleList* styleRulesForElement(Element*, unsigned rulesToInclude); | 115 StyleRuleList* styleRulesForElement(Element*, unsigned rulesToInclude); |
| 132 | 116 |
| 133 void computeFont(ComputedStyle*, const StylePropertySet&); | 117 void computeFont(ComputedStyle*, const StylePropertySet&); |
| 134 | 118 |
| 135 ViewportStyleResolver* viewportStyleResolver() { return m_viewportStyleResol
ver.get(); } | |
| 136 | |
| 137 void addViewportDependentMediaQueries(const MediaQueryResultList&); | |
| 138 bool hasViewportDependentMediaQueries() const { return !m_viewportDependentM
ediaQueryResults.isEmpty(); } | |
| 139 bool mediaQueryAffectedByViewportChange() const; | |
| 140 void addDeviceDependentMediaQueries(const MediaQueryResultList&); | |
| 141 bool mediaQueryAffectedByDeviceChange() const; | |
| 142 | |
| 143 // FIXME: Rename to reflect the purpose, like didChangeFontSize or something
. | 119 // FIXME: Rename to reflect the purpose, like didChangeFontSize or something
. |
| 144 void invalidateMatchedPropertiesCache(); | 120 void invalidateMatchedPropertiesCache(); |
| 145 | 121 |
| 146 void notifyResizeForViewportUnits(); | 122 void notifyResizeForViewportUnits(); |
| 147 | 123 |
| 148 // Exposed for ComputedStyle::isStyleAvilable(). | 124 // Exposed for ComputedStyle::isStyleAvilable(). |
| 149 static ComputedStyle* styleNotYetAvailable() { return s_styleNotYetAvailable
; } | 125 static ComputedStyle* styleNotYetAvailable() { return s_styleNotYetAvailable
; } |
| 150 | 126 |
| 151 RuleFeatureSet& ensureUpdatedRuleFeatureSet() | |
| 152 { | |
| 153 if (hasPendingAuthorStyleSheets()) | |
| 154 appendPendingAuthorStyleSheets(); | |
| 155 return m_features; | |
| 156 } | |
| 157 | |
| 158 RuleFeatureSet& ruleFeatureSet() | |
| 159 { | |
| 160 return m_features; | |
| 161 } | |
| 162 | |
| 163 StyleSharingList& styleSharingList(); | 127 StyleSharingList& styleSharingList(); |
| 164 | |
| 165 bool hasRulesForId(const AtomicString&) const; | |
| 166 bool hasFullscreenUAStyle() const { return m_hasFullscreenUAStyle; } | |
| 167 | |
| 168 void addToStyleSharingList(Element&); | 128 void addToStyleSharingList(Element&); |
| 169 void clearStyleSharingList(); | 129 void clearStyleSharingList(); |
| 170 | 130 |
| 171 void increaseStyleSharingDepth() { ++m_styleSharingDepth; } | 131 void increaseStyleSharingDepth() { ++m_styleSharingDepth; } |
| 172 void decreaseStyleSharingDepth() { --m_styleSharingDepth; } | 132 void decreaseStyleSharingDepth() { --m_styleSharingDepth; } |
| 173 | 133 |
| 174 PseudoElement* createPseudoElementIfNeeded(Element& parent, PseudoId); | 134 PseudoElement* createPseudoElementIfNeeded(Element& parent, PseudoId); |
| 175 | 135 |
| 176 DECLARE_TRACE(); | 136 DECLARE_TRACE(); |
| 177 | 137 |
| 178 void addTreeBoundaryCrossingScope(ContainerNode& scope); | |
| 179 void initWatchedSelectorRules(); | |
| 180 | |
| 181 private: | 138 private: |
| 182 explicit StyleResolver(Document&); | 139 explicit StyleResolver(Document&); |
| 183 | 140 |
| 184 PassRefPtr<ComputedStyle> initialStyleForElement(); | 141 PassRefPtr<ComputedStyle> initialStyleForElement(); |
| 185 | 142 |
| 186 // FIXME: This should probably go away, folded into FontBuilder. | 143 // FIXME: This should probably go away, folded into FontBuilder. |
| 187 void updateFont(StyleResolverState&); | 144 void updateFont(StyleResolverState&); |
| 188 | 145 |
| 189 void loadPendingResources(StyleResolverState&); | 146 void loadPendingResources(StyleResolverState&); |
| 190 void adjustComputedStyle(StyleResolverState&, Element*); | 147 void adjustComputedStyle(StyleResolverState&, Element*); |
| 191 | 148 |
| 192 void appendCSSStyleSheet(CSSStyleSheet&); | |
| 193 | |
| 194 void collectPseudoRulesForElement(const Element&, ElementRuleCollector&, Pse
udoId, unsigned rulesToInclude); | 149 void collectPseudoRulesForElement(const Element&, ElementRuleCollector&, Pse
udoId, unsigned rulesToInclude); |
| 195 void matchRuleSet(ElementRuleCollector&, RuleSet*); | 150 void matchRuleSet(ElementRuleCollector&, RuleSet*); |
| 196 void matchUARules(ElementRuleCollector&); | 151 void matchUARules(ElementRuleCollector&); |
| 197 void matchScopedRules(const Element&, ElementRuleCollector&); | 152 void matchScopedRules(const Element&, ElementRuleCollector&); |
| 198 void matchAuthorRules(const Element&, ElementRuleCollector&); | 153 void matchAuthorRules(const Element&, ElementRuleCollector&); |
| 199 void matchAuthorRulesV0(const Element&, ElementRuleCollector&); | 154 void matchAuthorRulesV0(const Element&, ElementRuleCollector&); |
| 200 void matchAllRules(StyleResolverState&, ElementRuleCollector&, bool includeS
MILProperties); | 155 void matchAllRules(StyleResolverState&, ElementRuleCollector&, bool includeS
MILProperties); |
| 201 void collectFeatures(); | |
| 202 void collectTreeBoundaryCrossingRules(const Element&, ElementRuleCollector&)
; | 156 void collectTreeBoundaryCrossingRules(const Element&, ElementRuleCollector&)
; |
| 203 | 157 |
| 204 void applyMatchedProperties(StyleResolverState&, const MatchResult&); | 158 void applyMatchedProperties(StyleResolverState&, const MatchResult&); |
| 205 bool applyAnimatedProperties(StyleResolverState&, const Element* animatingEl
ement); | 159 bool applyAnimatedProperties(StyleResolverState&, const Element* animatingEl
ement); |
| 206 void applyCallbackSelectors(StyleResolverState&); | 160 void applyCallbackSelectors(StyleResolverState&); |
| 207 | 161 |
| 208 template <CSSPropertyPriority priority> | 162 template <CSSPropertyPriority priority> |
| 209 void applyMatchedProperties(StyleResolverState&, const MatchedPropertiesRang
e&, bool important, bool inheritedOnly); | 163 void applyMatchedProperties(StyleResolverState&, const MatchedPropertiesRang
e&, bool important, bool inheritedOnly); |
| 210 template <CSSPropertyPriority priority> | 164 template <CSSPropertyPriority priority> |
| 211 void applyProperties(StyleResolverState&, const StylePropertySet* properties
, bool isImportant, bool inheritedOnly, PropertyWhitelistType = PropertyWhitelis
tNone); | 165 void applyProperties(StyleResolverState&, const StylePropertySet* properties
, bool isImportant, bool inheritedOnly, PropertyWhitelistType = PropertyWhitelis
tNone); |
| 212 template <CSSPropertyPriority priority> | 166 template <CSSPropertyPriority priority> |
| 213 void applyAnimatedProperties(StyleResolverState&, const ActiveInterpolations
Map&); | 167 void applyAnimatedProperties(StyleResolverState&, const ActiveInterpolations
Map&); |
| 214 template <CSSPropertyPriority priority> | 168 template <CSSPropertyPriority priority> |
| 215 void applyAllProperty(StyleResolverState&, CSSValue*, bool inheritedOnly, Pr
opertyWhitelistType); | 169 void applyAllProperty(StyleResolverState&, CSSValue*, bool inheritedOnly, Pr
opertyWhitelistType); |
| 216 template <CSSPropertyPriority priority> | 170 template <CSSPropertyPriority priority> |
| 217 void applyPropertiesForApplyAtRule(StyleResolverState&, const CSSValue*, boo
l isImportant, bool inheritedOnly, PropertyWhitelistType); | 171 void applyPropertiesForApplyAtRule(StyleResolverState&, const CSSValue*, boo
l isImportant, bool inheritedOnly, PropertyWhitelistType); |
| 218 | 172 |
| 219 bool pseudoStyleForElementInternal(Element&, const PseudoStyleRequest&, cons
t ComputedStyle* parentStyle, StyleResolverState&); | 173 bool pseudoStyleForElementInternal(Element&, const PseudoStyleRequest&, cons
t ComputedStyle* parentStyle, StyleResolverState&); |
| 220 bool hasAuthorBackground(const StyleResolverState&); | 174 bool hasAuthorBackground(const StyleResolverState&); |
| 221 bool hasAuthorBorder(const StyleResolverState&); | 175 bool hasAuthorBorder(const StyleResolverState&); |
| 222 | 176 |
| 223 PseudoElement* createPseudoElement(Element* parent, PseudoId); | 177 PseudoElement* createPseudoElement(Element* parent, PseudoId); |
| 224 | 178 |
| 225 Document& document() { return *m_document; } | 179 Document& document() { return *m_document; } |
| 226 | 180 |
| 227 static ComputedStyle* s_styleNotYetAvailable; | 181 static ComputedStyle* s_styleNotYetAvailable; |
| 228 | 182 |
| 229 MatchedPropertiesCache m_matchedPropertiesCache; | 183 MatchedPropertiesCache m_matchedPropertiesCache; |
| 230 | 184 |
| 231 Member<MediaQueryEvaluator> m_medium; | |
| 232 MediaQueryResultList m_viewportDependentMediaQueryResults; | |
| 233 MediaQueryResultList m_deviceDependentMediaQueryResults; | |
| 234 | |
| 235 Member<Document> m_document; | 185 Member<Document> m_document; |
| 236 SelectorFilter m_selectorFilter; | 186 SelectorFilter m_selectorFilter; |
| 237 | 187 |
| 238 Member<ViewportStyleResolver> m_viewportStyleResolver; | 188 bool m_printMediaType = false; |
| 239 | 189 |
| 240 HeapListHashSet<Member<CSSStyleSheet>, 16> m_pendingStyleSheets; | 190 unsigned m_styleSharingDepth = 0; |
| 241 | |
| 242 // FIXME: The entire logic of collecting features on StyleResolver, as well
as transferring them | |
| 243 // between various parts of machinery smells wrong. This needs to be better
somehow. | |
| 244 RuleFeatureSet m_features; | |
| 245 Member<RuleSet> m_siblingRuleSet; | |
| 246 Member<RuleSet> m_uncommonAttributeRuleSet; | |
| 247 Member<RuleSet> m_watchedSelectorsRules; | |
| 248 | |
| 249 DocumentOrderedList m_treeBoundaryCrossingScopes; | |
| 250 | |
| 251 bool m_needCollectFeatures; | |
| 252 bool m_printMediaType; | |
| 253 bool m_hasFullscreenUAStyle = false; | |
| 254 | |
| 255 unsigned m_styleSharingDepth; | |
| 256 HeapVector<Member<StyleSharingList>, styleSharingMaxDepth> m_styleSharingLis
ts; | 191 HeapVector<Member<StyleSharingList>, styleSharingMaxDepth> m_styleSharingLis
ts; |
| 257 }; | 192 }; |
| 258 | 193 |
| 259 } // namespace blink | 194 } // namespace blink |
| 260 | 195 |
| 261 #endif // StyleResolver_h | 196 #endif // StyleResolver_h |
| OLD | NEW |