2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 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 StyleResolver_h
23 #define StyleResolver_h
25 #include "CSSToStyleMap.h"
26 #include "CSSValueList.h"
27 #include "DocumentRuleSets.h"
28 #include "InspectorCSSOMWrappers.h"
30 #include "MediaQueryExp.h"
31 #include "RenderStyle.h"
32 #include "RuleFeature.h"
34 #include "RuntimeEnabledFeatures.h"
35 #include "ScrollTypes.h"
36 #include "SelectorChecker.h"
37 #include "SelectorFilter.h"
38 #include "StyleInheritedData.h"
39 #include "StyleScopeResolver.h"
40 #include "ViewportStyleResolver.h"
41 #if ENABLE(CSS_FILTERS) && ENABLE(SVG)
42 #include "WebKitCSSSVGDocumentValue.h"
44 #if ENABLE(CSS_SHADERS)
45 #include "CustomFilterConstants.h"
47 #include <wtf/HashMap.h>
48 #include <wtf/HashSet.h>
49 #include <wtf/RefPtr.h>
50 #include <wtf/Vector.h>
51 #include <wtf/text/AtomicStringHash.h>
52 #include <wtf/text/StringHash.h>
56 class CSSCursorImageValue;
57 class CSSFontSelector;
59 class CSSFontFaceRule;
60 class CSSImageGeneratorValue;
61 class CSSImageSetValue;
64 class CSSPrimitiveValue;
70 class CustomFilterOperation;
71 class CustomFilterParameter;
72 class CustomFilterParameterList;
73 class CustomFilterProgram;
74 struct CustomFilterProgramMixSettings;
76 class DeprecatedStyleBuilder;
83 class MediaQueryEvaluator;
86 class RenderScrollbar;
90 class StyleCustomFilterProgramCache;
91 class StyleScopeResolver;
94 class StylePendingImage;
95 class StyleProperties;
97 #if ENABLE(SHADOW_DOM)
100 class StyleRuleKeyframes;
102 class StyleRuleRegion;
105 class StyleSheetList;
107 class ViewportStyleResolver;
108 class WebKitCSSFilterValue;
109 class WebKitCSSShaderValue;
110 class WebKitCSSSVGDocumentValue;
112 class MediaQueryResult {
113 WTF_MAKE_NONCOPYABLE(MediaQueryResult); WTF_MAKE_FAST_ALLOCATED;
115 MediaQueryResult(const MediaQueryExp& expr, bool result)
121 MediaQueryExp m_expression;
125 enum StyleSharingBehavior {
127 DisallowStyleSharing,
130 // MatchOnlyUserAgentRules is used in media queries, where relative units
131 // are interpreted according to the document root element style, and styled only
132 // from the User Agent Stylesheet rules.
134 enum RuleMatchingBehavior {
136 MatchAllRulesExcludingSMIL,
137 MatchOnlyUserAgentRules,
140 class PseudoStyleRequest {
142 PseudoStyleRequest(PseudoId pseudoId, RenderScrollbar* scrollbar = 0, ScrollbarPart scrollbarPart = NoPart)
144 , scrollbarPart(scrollbarPart)
145 , scrollbar(scrollbar)
150 ScrollbarPart scrollbarPart;
151 RenderScrollbar* scrollbar;
154 // This class selects a RenderStyle for a given element based on a collection of stylesheets.
155 class StyleResolver {
156 WTF_MAKE_NONCOPYABLE(StyleResolver); WTF_MAKE_FAST_ALLOCATED;
158 StyleResolver(Document&, bool matchAuthorAndUserStyles);
161 // Using these during tree walk will allow style selector to optimize child and descendant selector lookups.
162 void pushParentElement(Element*);
163 void popParentElement(Element*);
164 void pushParentShadowRoot(const ShadowRoot*);
165 void popParentShadowRoot(const ShadowRoot*);
166 #if ENABLE(SHADOW_DOM)
167 void addHostRule(StyleRuleHost* rule, bool hasDocumentSecurityOrigin, const ContainerNode* scope) { ensureScopeResolver()->addHostRule(rule, hasDocumentSecurityOrigin, scope); }
170 PassRef<RenderStyle> styleForElement(Element*, RenderStyle* parentStyle = 0, StyleSharingBehavior = AllowStyleSharing,
171 RuleMatchingBehavior = MatchAllRules, RenderRegion* regionForStyling = 0);
173 void keyframeStylesForAnimation(Element*, const RenderStyle*, KeyframeList&);
175 PassRefPtr<RenderStyle> pseudoStyleForElement(Element*, const PseudoStyleRequest&, RenderStyle* parentStyle);
177 PassRef<RenderStyle> styleForPage(int pageIndex);
178 PassRef<RenderStyle> defaultStyleForElement();
180 RenderStyle* style() const { return m_state.style(); }
181 RenderStyle* parentStyle() const { return m_state.parentStyle(); }
182 RenderStyle* rootElementStyle() const { return m_state.rootElementStyle(); }
183 Element* element() { return m_state.element(); }
184 Document& document() { return m_document; }
185 StyleScopeResolver* scopeResolver() const { return m_scopeResolver.get(); }
186 bool hasParentNode() const { return m_state.parentNode(); }
188 // FIXME: It could be better to call m_ruleSets.appendAuthorStyleSheets() directly after we factor StyleRsolver further.
189 // https://bugs.webkit.org/show_bug.cgi?id=108890
190 void appendAuthorStyleSheets(unsigned firstNew, const Vector<RefPtr<CSSStyleSheet>>&);
192 DocumentRuleSets& ruleSets() { return m_ruleSets; }
193 const DocumentRuleSets& ruleSets() const { return m_ruleSets; }
194 SelectorFilter& selectorFilter() { return m_selectorFilter; }
196 #if ENABLE(SHADOW_DOM)
197 StyleScopeResolver* ensureScopeResolver()
199 ASSERT(RuntimeEnabledFeatures::sharedFeatures().shadowDOMEnabled());
200 if (!m_scopeResolver)
201 m_scopeResolver = adoptPtr(new StyleScopeResolver());
202 return m_scopeResolver.get();
207 void initElement(Element*);
208 RenderStyle* locateSharedStyle();
209 bool styleSharingCandidateMatchesRuleSet(RuleSet*);
210 bool styleSharingCandidateMatchesHostRules();
211 Node* locateCousinList(Element* parent, unsigned& visitedNodeCount) const;
212 StyledElement* findSiblingForStyleSharing(Node*, unsigned& count) const;
213 bool canShareStyleWithElement(StyledElement*) const;
215 PassRef<RenderStyle> styleForKeyframe(const RenderStyle*, const StyleKeyframe*, KeyframeValue&);
218 // These methods will give back the set of rules that matched for a given element (or a pseudo-element).
220 UAAndUserCSSRules = 1 << 1,
221 AuthorCSSRules = 1 << 2,
222 EmptyCSSRules = 1 << 3,
223 CrossOriginCSSRules = 1 << 4,
224 AllButEmptyCSSRules = UAAndUserCSSRules | AuthorCSSRules | CrossOriginCSSRules,
225 AllCSSRules = AllButEmptyCSSRules | EmptyCSSRules,
227 Vector<RefPtr<StyleRuleBase>> styleRulesForElement(Element*, unsigned rulesToInclude = AllButEmptyCSSRules);
228 Vector<RefPtr<StyleRuleBase>> pseudoStyleRulesForElement(Element*, PseudoId, unsigned rulesToInclude = AllButEmptyCSSRules);
231 void applyPropertyToStyle(CSSPropertyID, CSSValue*, RenderStyle*);
233 void applyPropertyToCurrentStyle(CSSPropertyID, CSSValue*);
236 void initializeFontStyle(Settings*);
238 void setFontSize(FontDescription&, float size);
241 bool useSVGZoomRules();
243 static bool colorFromPrimitiveValueIsDerivedFromElement(CSSPrimitiveValue*);
244 Color colorFromPrimitiveValue(CSSPrimitiveValue*, bool forVisitedLink = false) const;
246 bool hasSelectorForId(const AtomicString&) const;
247 bool hasSelectorForClass(const AtomicString&) const;
248 bool hasSelectorForAttribute(const AtomicString&) const;
250 CSSFontSelector* fontSelector() const { return m_fontSelector.get(); }
251 #if ENABLE(CSS_DEVICE_ADAPTATION)
252 ViewportStyleResolver* viewportStyleResolver() { return m_viewportStyleResolver.get(); }
255 void addViewportDependentMediaQueryResult(const MediaQueryExp*, bool result);
256 bool hasViewportDependentMediaQueries() const { return !m_viewportDependentMediaQueryResults.isEmpty(); }
257 bool affectedByViewportChange() const;
259 void addKeyframeStyle(PassRefPtr<StyleRuleKeyframes>);
261 bool checkRegionStyle(Element* regionElement);
263 bool usesSiblingRules() const { return !m_ruleSets.features().siblingRules.isEmpty(); }
264 bool usesFirstLineRules() const { return m_ruleSets.features().usesFirstLineRules; }
265 bool usesBeforeAfterRules() const { return m_ruleSets.features().usesBeforeAfterRules; }
267 void invalidateMatchedPropertiesCache();
269 #if ENABLE(CSS_FILTERS)
270 bool createFilterOperations(CSSValue* inValue, FilterOperations& outOperations);
271 #if ENABLE(CSS_SHADERS)
272 StyleShader* styleShader(CSSValue*);
273 StyleShader* cachedOrPendingStyleShaderFromValue(WebKitCSSShaderValue*);
274 bool parseCustomFilterParameterList(CSSValue*, CustomFilterParameterList&);
275 PassRefPtr<CustomFilterParameter> parseCustomFilterParameter(const String& name, CSSValue*);
276 PassRefPtr<CustomFilterParameter> parseCustomFilterColorParameter(const String& name, CSSValueList*);
277 PassRefPtr<CustomFilterParameter> parseCustomFilterArrayParameter(const String& name, CSSValueList*, bool);
278 PassRefPtr<CustomFilterParameter> parseCustomFilterNumberParameter(const String& name, CSSValueList*);
279 PassRefPtr<CustomFilterParameter> parseCustomFilterTransformParameter(const String& name, CSSValueList*);
280 PassRefPtr<CustomFilterOperation> createCustomFilterOperationWithAtRuleReferenceSyntax(WebKitCSSFilterValue*);
281 PassRefPtr<CustomFilterOperation> createCustomFilterOperationWithInlineSyntax(WebKitCSSFilterValue*);
282 PassRefPtr<CustomFilterOperation> createCustomFilterOperation(WebKitCSSFilterValue*);
283 void loadPendingShaders();
284 PassRefPtr<CustomFilterProgram> lookupCustomFilterProgram(WebKitCSSShaderValue* vertexShader, WebKitCSSShaderValue* fragmentShader,
285 CustomFilterProgramType, const CustomFilterProgramMixSettings&, CustomFilterMeshType);
288 void loadPendingSVGDocuments();
290 #endif // ENABLE(CSS_FILTERS)
292 void loadPendingResources();
294 int viewportPercentageValue(CSSPrimitiveValue& unit, int percentage);
297 RuleRange(int& firstRuleIndex, int& lastRuleIndex): firstRuleIndex(firstRuleIndex), lastRuleIndex(lastRuleIndex) { }
303 MatchRanges() : firstUARule(-1), lastUARule(-1), firstAuthorRule(-1), lastAuthorRule(-1), firstUserRule(-1), lastUserRule(-1) { }
310 RuleRange UARuleRange() { return RuleRange(firstUARule, lastUARule); }
311 RuleRange authorRuleRange() { return RuleRange(firstAuthorRule, lastAuthorRule); }
312 RuleRange userRuleRange() { return RuleRange(firstUserRule, lastUserRule); }
315 struct MatchedProperties {
317 ~MatchedProperties();
319 RefPtr<StyleProperties> properties;
322 unsigned linkMatchType : 2;
323 unsigned whitelistType : 2;
325 // Used to make sure all memory is zero-initialized since we compute the hash over the bytes of this object.
326 void* possiblyPaddedMember;
331 MatchResult() : isCacheable(true) { }
332 Vector<MatchedProperties, 64> matchedProperties;
333 Vector<StyleRule*, 64> matchedRules;
337 void addMatchedProperties(const StyleProperties&, StyleRule* = 0, unsigned linkMatchType = SelectorChecker::MatchAll, PropertyWhitelistType = PropertyWhitelistNone);
341 // This function fixes up the default font size if it detects that the current generic font family has changed. -dwh
342 void checkForGenericFamilyChange(RenderStyle*, RenderStyle* parentStyle);
343 void checkForZoomChange(RenderStyle*, RenderStyle* parentStyle);
344 #if ENABLE(IOS_TEXT_AUTOSIZING)
345 void checkForTextSizeAdjust(RenderStyle*);
348 void adjustRenderStyle(RenderStyle& styleToAdjust, const RenderStyle& parentStyle, Element*);
349 void adjustGridItemPosition(RenderStyle& styleToAdjust, const RenderStyle& parentStyle) const;
351 bool fastRejectSelector(const RuleData&) const;
353 void applyMatchedProperties(const MatchResult&, const Element*);
355 enum StyleApplicationPass {
356 HighPriorityProperties,
357 LowPriorityProperties
359 template <StyleApplicationPass pass>
360 void applyMatchedProperties(const MatchResult&, bool important, int startIndex, int endIndex, bool inheritedOnly);
361 template <StyleApplicationPass pass>
362 void applyProperties(const StyleProperties*, StyleRule*, bool isImportant, bool inheritedOnly, PropertyWhitelistType = PropertyWhitelistNone);
363 static bool isValidRegionStyleProperty(CSSPropertyID);
364 #if ENABLE(VIDEO_TRACK)
365 static bool isValidCueStyleProperty(CSSPropertyID);
367 void matchPageRules(MatchResult&, RuleSet*, bool isLeftPage, bool isFirstPage, const String& pageName);
368 void matchPageRulesForList(Vector<StyleRulePage*>& matchedRules, const Vector<StyleRulePage*>&, bool isLeftPage, bool isFirstPage, const String& pageName);
369 Settings* documentSettings() { return m_document.settings(); }
371 bool isLeftPage(int pageIndex) const;
372 bool isRightPage(int pageIndex) const { return !isLeftPage(pageIndex); }
373 bool isFirstPage(int pageIndex) const;
374 String pageName(int pageIndex) const;
376 DocumentRuleSets m_ruleSets;
378 typedef HashMap<AtomicStringImpl*, RefPtr<StyleRuleKeyframes>> KeyframesRuleMap;
379 KeyframesRuleMap m_keyframesRuleMap;
382 typedef HashMap<CSSPropertyID, RefPtr<CSSValue>> PendingImagePropertyMap;
383 #if ENABLE(CSS_FILTERS) && ENABLE(SVG)
384 typedef HashMap<FilterOperation*, RefPtr<WebKitCSSSVGDocumentValue>> PendingSVGDocumentMap;
388 WTF_MAKE_NONCOPYABLE(State);
395 , m_rootElementStyle(0)
396 , m_regionForStyling(0)
397 , m_elementLinkState(NotInsideLink)
398 , m_elementAffectedByClassRules(false)
399 , m_applyPropertyToRegularStyle(true)
400 , m_applyPropertyToVisitedLinkStyle(false)
401 #if ENABLE(CSS_SHADERS)
402 , m_hasPendingShaders(false)
404 , m_lineHeightValue(0)
406 , m_hasUAAppearance(false)
407 , m_backgroundData(BackgroundFillLayer) { }
410 void initElement(Element*);
411 void initForStyleResolve(Document&, Element*, RenderStyle* parentStyle = 0, RenderRegion* regionForStyling = 0);
414 Document& document() const { return m_element->document(); }
415 Element* element() const { return m_element; }
416 StyledElement* styledElement() const { return m_styledElement; }
417 void setStyle(PassRef<RenderStyle> style) { m_style = std::move(style); }
418 RenderStyle* style() const { return m_style.get(); }
419 PassRef<RenderStyle> takeStyle() { return m_style.releaseNonNull(); }
421 const ContainerNode* parentNode() const { return m_parentNode; }
422 void setParentStyle(PassRef<RenderStyle> parentStyle) { m_parentStyle = std::move(parentStyle); }
423 RenderStyle* parentStyle() const { return m_parentStyle.get(); }
424 RenderStyle* rootElementStyle() const { return m_rootElementStyle; }
426 const RenderRegion* regionForStyling() const { return m_regionForStyling; }
427 EInsideLink elementLinkState() const { return m_elementLinkState; }
428 void setElementAffectedByClassRules(bool isAffected) { m_elementAffectedByClassRules = isAffected; }
429 bool elementAffectedByClassRules() const { return m_elementAffectedByClassRules; }
431 void setApplyPropertyToRegularStyle(bool isApply) { m_applyPropertyToRegularStyle = isApply; }
432 void setApplyPropertyToVisitedLinkStyle(bool isApply) { m_applyPropertyToVisitedLinkStyle = isApply; }
433 bool applyPropertyToRegularStyle() const { return m_applyPropertyToRegularStyle; }
434 bool applyPropertyToVisitedLinkStyle() const { return m_applyPropertyToVisitedLinkStyle; }
435 PendingImagePropertyMap& pendingImageProperties() { return m_pendingImageProperties; }
436 #if ENABLE(CSS_FILTERS) && ENABLE(SVG)
437 PendingSVGDocumentMap& pendingSVGDocuments() { return m_pendingSVGDocuments; }
439 #if ENABLE(CSS_SHADERS)
440 void setHasPendingShaders(bool hasPendingShaders) { m_hasPendingShaders = hasPendingShaders; }
441 bool hasPendingShaders() const { return m_hasPendingShaders; }
444 void setLineHeightValue(CSSValue* value) { m_lineHeightValue = value; }
445 CSSValue* lineHeightValue() { return m_lineHeightValue; }
446 void setFontDirty(bool isDirty) { m_fontDirty = isDirty; }
447 bool fontDirty() const { return m_fontDirty; }
449 void cacheBorderAndBackground();
450 bool hasUAAppearance() const { return m_hasUAAppearance; }
451 BorderData borderData() const { return m_borderData; }
452 FillLayer backgroundData() const { return m_backgroundData; }
453 Color backgroundColor() const { return m_backgroundColor; }
455 const FontDescription& fontDescription() { return m_style->fontDescription(); }
456 const FontDescription& parentFontDescription() { return m_parentStyle->fontDescription(); }
457 void setFontDescription(const FontDescription& fontDescription) { m_fontDirty |= m_style->setFontDescription(fontDescription); }
458 void setZoom(float f) { m_fontDirty |= m_style->setZoom(f); }
459 void setEffectiveZoom(float f) { m_fontDirty |= m_style->setEffectiveZoom(f); }
460 void setWritingMode(WritingMode writingMode) { m_fontDirty |= m_style->setWritingMode(writingMode); }
461 void setTextOrientation(TextOrientation textOrientation) { m_fontDirty |= m_style->setTextOrientation(textOrientation); }
463 bool useSVGZoomRules() const { return m_element && m_element->isSVGElement(); }
466 // FIXME(bug 108563): to make it easier to review, these member
467 // variables are public. However we should add methods to access
470 RefPtr<RenderStyle> m_style;
471 StyledElement* m_styledElement;
472 ContainerNode* m_parentNode;
473 RefPtr<RenderStyle> m_parentStyle;
474 RenderStyle* m_rootElementStyle;
476 // Required to ASSERT in applyProperties.
477 RenderRegion* m_regionForStyling;
479 EInsideLink m_elementLinkState;
481 bool m_elementAffectedByClassRules;
483 bool m_applyPropertyToRegularStyle;
484 bool m_applyPropertyToVisitedLinkStyle;
486 PendingImagePropertyMap m_pendingImageProperties;
487 #if ENABLE(CSS_SHADERS)
488 bool m_hasPendingShaders;
490 #if ENABLE(CSS_FILTERS) && ENABLE(SVG)
491 PendingSVGDocumentMap m_pendingSVGDocuments;
493 CSSValue* m_lineHeightValue;
496 bool m_hasUAAppearance;
497 BorderData m_borderData;
498 FillLayer m_backgroundData;
499 Color m_backgroundColor;
502 static RenderStyle* styleNotYetAvailable() { return s_styleNotYetAvailable; }
504 PassRefPtr<StyleImage> styleImage(CSSPropertyID, CSSValue*);
505 PassRefPtr<StyleImage> cachedOrPendingFromValue(CSSPropertyID, CSSImageValue*);
506 PassRefPtr<StyleImage> generatedOrPendingFromValue(CSSPropertyID, CSSImageGeneratorValue&);
507 #if ENABLE(CSS_IMAGE_SET)
508 PassRefPtr<StyleImage> setOrPendingFromValue(CSSPropertyID, CSSImageSetValue*);
510 PassRefPtr<StyleImage> cursorOrPendingFromValue(CSSPropertyID, CSSCursorImageValue*);
512 bool applyPropertyToRegularStyle() const { return m_state.applyPropertyToRegularStyle(); }
513 bool applyPropertyToVisitedLinkStyle() const { return m_state.applyPropertyToVisitedLinkStyle(); }
515 static Length convertToIntLength(const CSSPrimitiveValue*, const RenderStyle*, const RenderStyle* rootStyle, double multiplier = 1);
516 static Length convertToFloatLength(const CSSPrimitiveValue*, const RenderStyle*, const RenderStyle* rootStyle, double multiplier = 1);
518 CSSToStyleMap* styleMap() { return &m_styleMap; }
519 InspectorCSSOMWrappers& inspectorCSSOMWrappers() { return m_inspectorCSSOMWrappers; }
520 const FontDescription& fontDescription() { return m_state.fontDescription(); }
521 const FontDescription& parentFontDescription() { return m_state.parentFontDescription(); }
522 void setFontDescription(const FontDescription& fontDescription) { m_state.setFontDescription(fontDescription); }
523 void setZoom(float f) { m_state.setZoom(f); }
524 void setEffectiveZoom(float f) { m_state.setEffectiveZoom(f); }
525 void setWritingMode(WritingMode writingMode) { m_state.setWritingMode(writingMode); }
526 void setTextOrientation(TextOrientation textOrientation) { m_state.setTextOrientation(textOrientation); }
529 static RenderStyle* s_styleNotYetAvailable;
531 void cacheBorderAndBackground();
534 bool canShareStyleWithControl(StyledElement*) const;
536 void applyProperty(CSSPropertyID, CSSValue*);
539 void applySVGProperty(CSSPropertyID, CSSValue*);
542 PassRefPtr<StyleImage> loadPendingImage(StylePendingImage*);
543 void loadPendingImages();
544 #if ENABLE(CSS_SHAPES)
545 void loadPendingShapeImage(ShapeValue*);
548 static unsigned computeMatchedPropertiesHash(const MatchedProperties*, unsigned size);
549 struct MatchedPropertiesCacheItem {
550 Vector<MatchedProperties> matchedProperties;
552 RefPtr<RenderStyle> renderStyle;
553 RefPtr<RenderStyle> parentRenderStyle;
555 const MatchedPropertiesCacheItem* findFromMatchedPropertiesCache(unsigned hash, const MatchResult&);
556 void addToMatchedPropertiesCache(const RenderStyle*, const RenderStyle* parentStyle, unsigned hash, const MatchResult&);
558 // Every N additions to the matched declaration cache trigger a sweep where entries holding
559 // the last reference to a style declaration are garbage collected.
560 void sweepMatchedPropertiesCache(Timer<StyleResolver>*);
562 bool classNamesAffectedByRules(const SpaceSplitString&) const;
563 bool sharingCandidateHasIdenticalStyleAffectingAttributes(StyledElement*) const;
566 unsigned m_matchedPropertiesCacheAdditionsSinceLastSweep;
568 typedef HashMap<unsigned, MatchedPropertiesCacheItem> MatchedPropertiesCache;
569 MatchedPropertiesCache m_matchedPropertiesCache;
571 Timer<StyleResolver> m_matchedPropertiesCacheSweepTimer;
573 OwnPtr<MediaQueryEvaluator> m_medium;
574 RefPtr<RenderStyle> m_rootDefaultStyle;
576 Document& m_document;
577 SelectorFilter m_selectorFilter;
579 bool m_matchAuthorAndUserStyles;
581 RefPtr<CSSFontSelector> m_fontSelector;
582 Vector<OwnPtr<MediaQueryResult>> m_viewportDependentMediaQueryResults;
584 #if ENABLE(CSS_DEVICE_ADAPTATION)
585 RefPtr<ViewportStyleResolver> m_viewportStyleResolver;
588 const DeprecatedStyleBuilder& m_deprecatedStyleBuilder;
590 OwnPtr<StyleScopeResolver> m_scopeResolver;
591 CSSToStyleMap m_styleMap;
592 InspectorCSSOMWrappers m_inspectorCSSOMWrappers;
596 #if ENABLE(CSS_SHADERS)
597 OwnPtr<StyleCustomFilterProgramCache> m_customFilterProgramCache;
600 friend class DeprecatedStyleBuilder;
601 friend bool operator==(const MatchedProperties&, const MatchedProperties&);
602 friend bool operator!=(const MatchedProperties&, const MatchedProperties&);
603 friend bool operator==(const MatchRanges&, const MatchRanges&);
604 friend bool operator!=(const MatchRanges&, const MatchRanges&);
607 inline bool StyleResolver::hasSelectorForAttribute(const AtomicString &attributeName) const
609 ASSERT(!attributeName.isEmpty());
610 return m_ruleSets.features().attrsInRules.contains(attributeName.impl());
613 inline bool StyleResolver::hasSelectorForClass(const AtomicString& classValue) const
615 ASSERT(!classValue.isEmpty());
616 return m_ruleSets.features().classesInRules.contains(classValue.impl());
619 inline bool StyleResolver::hasSelectorForId(const AtomicString& idValue) const
621 ASSERT(!idValue.isEmpty());
622 return m_ruleSets.features().idsInRules.contains(idValue.impl());
625 inline bool checkRegionSelector(const CSSSelector* regionSelector, Element* regionElement)
627 if (!regionSelector || !regionElement)
630 SelectorChecker selectorChecker(regionElement->document(), SelectorChecker::QueryingRules);
631 for (const CSSSelector* s = regionSelector; s; s = CSSSelectorList::next(s)) {
632 SelectorChecker::SelectorCheckingContext selectorCheckingContext(s, regionElement, SelectorChecker::VisitedMatchDisabled);
633 PseudoId ignoreDynamicPseudo = NOPSEUDO;
634 if (selectorChecker.match(selectorCheckingContext, ignoreDynamicPseudo))
640 class StyleResolverParentPusher {
642 StyleResolverParentPusher(Element* parent)
644 , m_pushedStyleResolver(0)
648 if (m_pushedStyleResolver)
650 m_pushedStyleResolver = &m_parent->document().ensureStyleResolver();
651 m_pushedStyleResolver->pushParentElement(m_parent);
653 ~StyleResolverParentPusher()
655 if (!m_pushedStyleResolver)
657 // This tells us that our pushed style selector is in a bad state,
658 // so we should just bail out in that scenario.
659 ASSERT(m_pushedStyleResolver == &m_parent->document().ensureStyleResolver());
660 if (m_pushedStyleResolver != &m_parent->document().ensureStyleResolver())
662 m_pushedStyleResolver->popParentElement(m_parent);
667 StyleResolver* m_pushedStyleResolver;
670 } // namespace WebCore
672 #endif // StyleResolver_h