15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/* 25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. 45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * This library is free software; you can redistribute it and/or 65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modify it under the terms of the GNU Library General Public 75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * License as published by the Free Software Foundation; either 85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * version 2 of the License, or (at your option) any later version. 95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * This library is distributed in the hope that it will be useful, 115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * but WITHOUT ANY WARRANTY; without even the implied warranty of 125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Library General Public License for more details. 145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * You should have received a copy of the GNU Library General Public License 165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * along with this library; see the file COPYING.LIB. If not, write to 175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Boston, MA 02110-1301, USA. 195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */ 215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef StyleResolver_h 235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define StyleResolver_h 245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 25f5e4ad553afbc08dd2e729bb77e937a9a94d5827Torne (Richard Coles)#include "core/animation/KeyframeAnimationEffect.h" 2653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/css/InspectorCSSOMWrappers.h" 275267f701546148b83dfbe1d151cb184385bb5c22Torne (Richard Coles)#include "core/css/PseudoStyleRequest.h" 2853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/css/RuleFeature.h" 2953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/css/RuleSet.h" 3053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/css/SelectorChecker.h" 3153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/css/SelectorFilter.h" 3253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/css/SiblingTraversalStrategies.h" 3351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "core/css/TreeBoundaryCrossingRules.h" 34e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "core/css/resolver/MatchedPropertiesCache.h" 3581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)#include "core/css/resolver/ScopedStyleResolver.h" 3651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "core/css/resolver/ScopedStyleTree.h" 37e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch#include "core/css/resolver/StyleBuilder.h" 38f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)#include "core/css/resolver/StyleResolverIncludes.h" 3981a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)#include "core/css/resolver/StyleResolverState.h" 40591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch#include "core/css/resolver/StyleResourceLoader.h" 418abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)#include "wtf/Deque.h" 4281a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)#include "wtf/HashMap.h" 4381a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)#include "wtf/HashSet.h" 4451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)#include "wtf/ListHashSet.h" 4581a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)#include "wtf/RefPtr.h" 4681a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles)#include "wtf/Vector.h" 475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)namespace WebCore { 495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 50f5e4ad553afbc08dd2e729bb77e937a9a94d5827Torne (Richard Coles)class CSSAnimationUpdate; 515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class CSSFontSelector; 52926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)class CSSRuleList; 535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class CSSSelector; 545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class CSSStyleSheet; 555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class CSSValue; 565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class ContainerNode; 575c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class Document; 5883750176c3ee2cea66c8a9751271026a5901be3aBen Murdochclass DocumentTimeline; 595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class Element; 6053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)class ElementRuleCollector; 615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class KeyframeList; 625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class KeyframeValue; 635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class MediaQueryEvaluator; 64e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdochclass MediaQueryResult; 655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class RenderRegion; 665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class RuleData; 675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class Settings; 685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class StyleKeyframe; 695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class StylePropertySet; 7051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)class StyleResolverStats; 715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class StyleRule; 725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class StyleRuleKeyframes; 735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class StyleRulePage; 747757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdochclass ViewportStyleResolver; 755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 76e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdochstruct MatchResult; 775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)enum StyleSharingBehavior { 795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) AllowStyleSharing, 805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) DisallowStyleSharing, 815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}; 825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// MatchOnlyUserAgentRules is used in media queries, where relative units 845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// are interpreted according to the document root element style, and styled only 855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// from the User Agent Stylesheet rules. 865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)enum RuleMatchingBehavior { 875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) MatchAllRules, 885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) MatchAllRulesExcludingSMIL, 895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) MatchOnlyUserAgentRules, 905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}; 915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 928abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)const unsigned styleSharingListSize = 40; 9351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles)typedef WTF::Deque<Element*, styleSharingListSize> StyleSharingList; 947757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch 95e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdochstruct CSSPropertyValue { 96e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch CSSPropertyValue(CSSPropertyID property, CSSValue* value) 97e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch : property(property), value(value) { } 98e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch // Stores value=propertySet.getPropertyCSSValue(id).get(). 99e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch CSSPropertyValue(CSSPropertyID, const StylePropertySet&); 100e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch CSSPropertyID property; 101e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch CSSValue* value; 102e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch}; 103591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch 1045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// This class selects a RenderStyle for a given element based on a collection of stylesheets. 1051e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)class StyleResolver : public FontSelectorClient { 1065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) WTF_MAKE_NONCOPYABLE(StyleResolver); WTF_MAKE_FAST_ALLOCATED; 1075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)public: 10851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) explicit StyleResolver(Document&); 1095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) ~StyleResolver(); 1105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1117757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch // FIXME: StyleResolver should not be keeping tree-walk state. 1127757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch // These should move to some global tree-walk state, or should be contained in a 1137757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch // TreeWalkContext or similar which is passed in to StyleResolver methods when available. 1145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // Using these during tree walk will allow style selector to optimize child and descendant selector lookups. 11551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) void pushParentElement(Element&); 11651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) void popParentElement(Element&); 1178abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) void pushParentShadowRoot(const ShadowRoot&); 1188abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) void popParentShadowRoot(const ShadowRoot&); 1195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) PassRefPtr<RenderStyle> styleForElement(Element*, RenderStyle* parentStyle = 0, StyleSharingBehavior = AllowStyleSharing, 121521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles) RuleMatchingBehavior = MatchAllRules, RenderRegion* regionForStyling = 0); 1225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 12351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) // FIXME: keyframeStylesForAnimation is only used in the legacy animations implementation 12451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) // and should be removed when that is replaced by Web Animations. 12551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) void keyframeStylesForAnimation(Element*, const RenderStyle&, KeyframeList&); 1265aec9d262fb41a60afe1effb4cfcddf611b725e0Torne (Richard Coles) PassRefPtr<RenderStyle> styleForKeyframe(Element*, const RenderStyle&, RenderStyle* parentStyle, const StyleKeyframe*, const AtomicString& animationName); 127e08f70592b3fc0d5e68b9b914c9196e813720070Torne (Richard Coles) static PassRefPtr<KeyframeAnimationEffect> createKeyframeAnimationEffect(Element&, const Vector<RefPtr<MutableStylePropertySet> >&, KeyframeAnimationEffect::KeyframeVector&); 1285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 129926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) PassRefPtr<RenderStyle> pseudoStyleForElement(Element*, const PseudoStyleRequest&, RenderStyle* parentStyle); 1305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) PassRefPtr<RenderStyle> styleForPage(int pageIndex); 132926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) PassRefPtr<RenderStyle> defaultStyleForElement(); 133926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) PassRefPtr<RenderStyle> styleForText(Text*); 1345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1358abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) static PassRefPtr<RenderStyle> styleForDocument(Document&, CSSFontSelector* = 0); 1365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1377757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch // FIXME: This only has 5 callers and should be removed. Callers should be explicit about 1387757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch // their dependency on Document* instead of grabbing one through StyleResolver. 1398abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) Document& document() { return m_document; } 140926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 14151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) // FIXME: It could be better to call appendAuthorStyleSheets() directly after we factor StyleResolver further. 142926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) // https://bugs.webkit.org/show_bug.cgi?id=108890 1435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void appendAuthorStyleSheets(unsigned firstNew, const Vector<RefPtr<CSSStyleSheet> >&); 144591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch void resetAuthorStyle(const ContainerNode*); 145e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles) void finishAppendAuthorStyleSheets(); 14651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 14751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) TreeBoundaryCrossingRules& treeBoundaryCrossingRules() { return m_treeBoundaryCrossingRules; } 14851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) void processScopedRules(const RuleSet& authorRules, const KURL&, ContainerNode* scope = 0); 14951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 15051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) void lazyAppendAuthorStyleSheets(unsigned firstNew, const Vector<RefPtr<CSSStyleSheet> >&); 15151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) void removePendingAuthorStyleSheets(const Vector<RefPtr<CSSStyleSheet> >&); 15251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) void appendPendingAuthorStyleSheets(); 15351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) bool hasPendingAuthorStyleSheets() const { return m_pendingStyleSheets.size() > 0 || m_needCollectFeatures; } 1545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 155926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) SelectorFilter& selectorFilter() { return m_selectorFilter; } 156926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 157591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch void setBuildScopedStyleTreeInDocumentOrder(bool enabled) { m_styleTree.setBuildInDocumentOrder(enabled); } 158591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch bool buildScopedStyleTreeInDocumentOrder() const { return m_styleTree.buildInDocumentOrder(); } 15951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) bool styleTreeHasOnlyScopedResolverForDocument() const { return m_styleTree.hasOnlyScopedResolverForDocument(); } 16051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) ScopedStyleResolver* styleTreeScopedStyleResolverForDocument() const { return m_styleTree.scopedStyleResolverForDocument(); } 161591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch 16251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) ScopedStyleResolver* ensureScopedStyleResolver(ContainerNode* scope) 1635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) { 16451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) ASSERT(scope); 16551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return m_styleTree.ensureScopedStyleResolver(*scope); 16651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 16751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 16851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) void styleTreeResolveScopedKeyframesRules(const Element* element, Vector<ScopedStyleResolver*, 8>& resolvers) 16951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) { 17051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) m_styleTree.resolveScopedKeyframesRules(element, resolvers); 1715c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) } 1725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // These methods will give back the set of rules that matched for a given element (or a pseudo-element). 1745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) enum CSSRuleFilter { 1755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) UAAndUserCSSRules = 1 << 1, 1765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) AuthorCSSRules = 1 << 2, 1775c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) EmptyCSSRules = 1 << 3, 1785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) CrossOriginCSSRules = 1 << 4, 1795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) AllButEmptyCSSRules = UAAndUserCSSRules | AuthorCSSRules | CrossOriginCSSRules, 1805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) AllCSSRules = AllButEmptyCSSRules | EmptyCSSRules, 1815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) }; 18219cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) PassRefPtr<CSSRuleList> cssRulesForElement(Element*, unsigned rulesToInclude = AllButEmptyCSSRules, ShouldIncludeStyleSheetInCSSOMWrapper = IncludeStyleSheetInCSSOMWrapper); 18319cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) PassRefPtr<CSSRuleList> pseudoCSSRulesForElement(Element*, PseudoId, unsigned rulesToInclude = AllButEmptyCSSRules, ShouldIncludeStyleSheetInCSSOMWrapper = IncludeStyleSheetInCSSOMWrapper); 18419cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) PassRefPtr<StyleRuleList> styleRulesForElement(Element*, unsigned rulesToInclude); 1855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 186e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch // |properties| is an array with |count| elements. 187e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch void applyPropertiesToStyle(const CSSPropertyValue* properties, size_t count, RenderStyle*); 1885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 189926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) ViewportStyleResolver* viewportStyleResolver() { return m_viewportStyleResolver.get(); } 1905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 19151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) void addMediaQueryResults(const MediaQueryResultList&); 1921e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) MediaQueryResultList* viewportDependentMediaQueryResults() { return &m_viewportDependentMediaQueryResults; } 1935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) bool hasViewportDependentMediaQueries() const { return !m_viewportDependentMediaQueryResults.isEmpty(); } 1945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) bool affectedByViewportChange() const; 1955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 1967757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch // FIXME: Regions should not require special logic in StyleResolver. 1975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) bool checkRegionStyle(Element* regionElement); 1985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 199e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch // FIXME: Rename to reflect the purpose, like didChangeFontSize or something. 2005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void invalidateMatchedPropertiesCache(); 2015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 2027757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch // Exposed for RenderStyle::isStyleAvilable(). 2030019e4eead4d990e4304c54a9028aca9122fb256Ben Murdoch static RenderStyle* styleNotYetAvailable() { return s_styleNotYetAvailable; } 2040019e4eead4d990e4304c54a9028aca9122fb256Ben Murdoch 2057757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch // FIXME: StyleResolver should not have this member or method. 2060019e4eead4d990e4304c54a9028aca9122fb256Ben Murdoch InspectorCSSOMWrappers& inspectorCSSOMWrappers() { return m_inspectorCSSOMWrappers; } 2070019e4eead4d990e4304c54a9028aca9122fb256Ben Murdoch 20851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) const RuleFeatureSet& ensureRuleFeatureSet() 20951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) { 21051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) if (hasPendingAuthorStyleSheets()) 21151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) appendPendingAuthorStyleSheets(); 21251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) return m_features; 21351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) } 2147757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch 2158abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) StyleSharingList& styleSharingList() { return m_styleSharingList; } 2168abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 217bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) bool hasRulesForId(const AtomicString&) const; 2188abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 21951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) void addToStyleSharingList(Element&); 2208abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) void clearStyleSharingList(); 2218abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 22251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) StyleResolverStats* stats() { return m_styleResolverStats.get(); } 22351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) StyleResolverStats* statsTotals() { return m_styleResolverStatsTotals.get(); } 22451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) enum StatsReportType { ReportDefaultStats, ReportSlowStats }; 22551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) void enableStats(StatsReportType = ReportDefaultStats); 22651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) void disableStats(); 22751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) void printStats(); 22851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 22951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) unsigned accessCount() const { return m_accessCount; } 23051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) void didAccess() { ++m_accessCount; } 2311e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) 232e3f67c8c3ffbd6d58541f1801bb8b0c26449b3a2Ben Murdoch PassRefPtr<PseudoElement> createPseudoElementIfNeeded(Element&, PseudoId); 233e3f67c8c3ffbd6d58541f1801bb8b0c26449b3a2Ben Murdoch 2341e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)private: 2351e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) // FontSelectorClient implementation. 2361e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) virtual void fontsNeedUpdate(FontSelector*); 2371e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) 238926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)private: 23951b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) void initWatchedSelectorRules(const Vector<RefPtr<StyleRule> >& watchedSelectors); 24051b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 24151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) void addTreeBoundaryCrossingRules(const Vector<MinimalRuleData>&, ContainerNode* scope); 24251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 2437757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch // FIXME: This should probably go away, folded into FontBuilder. 24483750176c3ee2cea66c8a9751271026a5901be3aBen Murdoch void updateFont(StyleResolverState&); 2457757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch 24651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) void appendCSSStyleSheet(CSSStyleSheet*); 24751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 24819cde67944066db31e633d9e386f2aa9bf9fadb3Torne (Richard Coles) void collectPseudoRulesForElement(Element*, ElementRuleCollector&, PseudoId, unsigned rulesToInclude); 24953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) void matchUARules(ElementRuleCollector&, RuleSet*); 25083750176c3ee2cea66c8a9751271026a5901be3aBen Murdoch void matchAuthorRules(Element*, ElementRuleCollector&, bool includeEmptyRules); 2511e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) void matchAuthorRulesForShadowHost(Element*, ElementRuleCollector&, bool includeEmptyRules, Vector<ScopedStyleResolver*, 8>& resolvers, Vector<ScopedStyleResolver*, 8>& resolversInShadowTree); 25251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) void matchAllRules(StyleResolverState&, ElementRuleCollector&, bool includeSMILProperties); 25353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) void matchUARules(ElementRuleCollector&); 25451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) // FIXME: watched selectors should be implemented using injected author stylesheets: http://crbug.com/316960 25551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) void matchWatchSelectorRules(ElementRuleCollector&); 25693ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) void collectFeatures(); 25751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) void collectTreeBoundaryCrossingRules(Element*, ElementRuleCollector&, bool includeEmptyRules); 25851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) void resetRuleFeatures(); 25953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles) 2605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) bool fastRejectSelector(const RuleData&) const; 2615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 262a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) void applyMatchedProperties(StyleResolverState&, const MatchResult&); 26351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) void applyAnimatedProperties(StyleResolverState&, Element* animatingElement); 264926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 2655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) enum StyleApplicationPass { 2665c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) VariableDefinitions, 267e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch AnimationProperties, 2685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) HighPriorityProperties, 2695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) LowPriorityProperties 2705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) }; 271e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch template <StyleResolver::StyleApplicationPass pass> 272e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdoch static inline bool isPropertyForPass(CSSPropertyID); 2735c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) template <StyleApplicationPass pass> 27483750176c3ee2cea66c8a9751271026a5901be3aBen Murdoch void applyMatchedProperties(StyleResolverState&, const MatchResult&, bool important, int startIndex, int endIndex, bool inheritedOnly); 2755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) template <StyleApplicationPass pass> 27683750176c3ee2cea66c8a9751271026a5901be3aBen Murdoch void applyProperties(StyleResolverState&, const StylePropertySet* properties, StyleRule*, bool isImportant, bool inheritedOnly, PropertyWhitelistType = PropertyWhitelistNone); 27781a5157921f1d2a7ff6aae115bfe3c139b38a5c8Torne (Richard Coles) template <StyleApplicationPass pass> 27851b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) void applyAnimatedProperties(StyleResolverState&, const AnimationEffect::CompositableValueMap&); 2795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void matchPageRules(MatchResult&, RuleSet*, bool isLeftPage, bool isFirstPage, const String& pageName); 2805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void matchPageRulesForList(Vector<StyleRulePage*>& matchedRules, const Vector<StyleRulePage*>&, bool isLeftPage, bool isFirstPage, const String& pageName); 2810019e4eead4d990e4304c54a9028aca9122fb256Ben Murdoch void collectViewportRules(); 2828abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) Settings* documentSettings() { return m_document.settings(); } 2835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 2845c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) bool isLeftPage(int pageIndex) const; 2855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) bool isRightPage(int pageIndex) const { return !isLeftPage(pageIndex); } 2865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) bool isFirstPage(int pageIndex) const; 2875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) String pageName(int pageIndex) const; 2885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 289e3f67c8c3ffbd6d58541f1801bb8b0c26449b3a2Ben Murdoch bool pseudoStyleForElementInternal(Element&, const PseudoStyleRequest&, RenderStyle* parentStyle, StyleResolverState&); 290e3f67c8c3ffbd6d58541f1801bb8b0c26449b3a2Ben Murdoch 2917757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch // FIXME: This likely belongs on RuleSet. 29283750176c3ee2cea66c8a9751271026a5901be3aBen Murdoch typedef HashMap<StringImpl*, RefPtr<StyleRuleKeyframes> > KeyframesRuleMap; 2935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) KeyframesRuleMap m_keyframesRuleMap; 2945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 2955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) static RenderStyle* s_styleNotYetAvailable; 2965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 2975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void cacheBorderAndBackground(); 2985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 2995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) MatchedPropertiesCache m_matchedPropertiesCache; 3005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) OwnPtr<MediaQueryEvaluator> m_medium; 3021e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) MediaQueryResultList m_viewportDependentMediaQueryResults; 3031e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) 3045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) RefPtr<RenderStyle> m_rootDefaultStyle; 3055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3068abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) Document& m_document; 307926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) SelectorFilter m_selectorFilter; 308926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 309926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) RefPtr<ViewportStyleResolver> m_viewportStyleResolver; 3105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 31151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) ListHashSet<CSSStyleSheet*, 16> m_pendingStyleSheets; 31251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 31393ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) ScopedStyleTree m_styleTree; 31493ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) 315f5e4ad553afbc08dd2e729bb77e937a9a94d5827Torne (Richard Coles) // FIXME: The entire logic of collecting features on StyleResolver, as well astransferring them 316f5e4ad553afbc08dd2e729bb77e937a9a94d5827Torne (Richard Coles) // between various parts of machinery smells wrong. This needs to be better somehow. 31793ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) RuleFeatureSet m_features; 31893ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) OwnPtr<RuleSet> m_siblingRuleSet; 31993ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles) OwnPtr<RuleSet> m_uncommonAttributeRuleSet; 3205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 32151b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) // FIXME: watched selectors should be implemented using injected author stylesheets: http://crbug.com/316960 32251b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) OwnPtr<RuleSet> m_watchedSelectorsRules; 32351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) TreeBoundaryCrossingRules m_treeBoundaryCrossingRules; 32451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 32551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) bool m_needCollectFeatures; 32651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 327926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) InspectorCSSOMWrappers m_inspectorCSSOMWrappers; 328926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 329591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch StyleResourceLoader m_styleResourceLoader; 3305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3318abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) StyleSharingList m_styleSharingList; 3328abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles) 33351b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) OwnPtr<StyleResolverStats> m_styleResolverStats; 33451b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) OwnPtr<StyleResolverStats> m_styleResolverStatsTotals; 33551b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) unsigned m_styleResolverStatsSequence; 33651b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) 33751b2906e11752df6c18351cf520e30522d3b53a1Torne (Richard Coles) unsigned m_accessCount; 3385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}; 3395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 340926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)inline bool checkRegionSelector(const CSSSelector* regionSelector, Element* regionElement) 341926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){ 342926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) if (!regionSelector || !regionElement) 343926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) return false; 344926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 345926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) SelectorChecker selectorChecker(regionElement->document(), SelectorChecker::QueryingRules); 346926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) for (const CSSSelector* s = regionSelector; s; s = CSSSelectorList::next(s)) { 347926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) SelectorChecker::SelectorCheckingContext selectorCheckingContext(s, regionElement, SelectorChecker::VisitedMatchDisabled); 348a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles) if (selectorChecker.match(selectorCheckingContext, DOMSiblingTraversalStrategy()) == SelectorChecker::SelectorMatches) 349926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) return true; 350926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) } 351926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) return false; 3525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} 3535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)} // namespace WebCore 3555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 3565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#endif // StyleResolver_h 357