1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/style/nsHTMLCSSStyleSheet.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,187 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* 1.10 + * style sheet and style rule processor representing style attributes 1.11 + */ 1.12 + 1.13 +#include "nsHTMLCSSStyleSheet.h" 1.14 +#include "mozilla/MemoryReporting.h" 1.15 +#include "mozilla/css/StyleRule.h" 1.16 +#include "nsIStyleRuleProcessor.h" 1.17 +#include "nsPresContext.h" 1.18 +#include "nsRuleWalker.h" 1.19 +#include "nsRuleProcessorData.h" 1.20 +#include "mozilla/dom/Element.h" 1.21 +#include "nsAttrValue.h" 1.22 +#include "nsAttrValueInlines.h" 1.23 + 1.24 +using namespace mozilla; 1.25 +using namespace mozilla::dom; 1.26 + 1.27 +namespace { 1.28 + 1.29 +PLDHashOperator 1.30 +ClearAttrCache(const nsAString& aKey, MiscContainer*& aValue, void*) 1.31 +{ 1.32 + // Ideally we'd just call MiscContainer::Evict, but we can't do that since 1.33 + // we're iterating the hashtable. 1.34 + MOZ_ASSERT(aValue->mType == nsAttrValue::eCSSStyleRule); 1.35 + 1.36 + aValue->mValue.mCSSStyleRule->SetHTMLCSSStyleSheet(nullptr); 1.37 + aValue->mValue.mCached = 0; 1.38 + 1.39 + return PL_DHASH_REMOVE; 1.40 +} 1.41 + 1.42 +} // anonymous namespace 1.43 + 1.44 +nsHTMLCSSStyleSheet::nsHTMLCSSStyleSheet() 1.45 +{ 1.46 +} 1.47 + 1.48 +nsHTMLCSSStyleSheet::~nsHTMLCSSStyleSheet() 1.49 +{ 1.50 + // We may go away before all of our cached style attributes do, 1.51 + // so clean up any that are left. 1.52 + mCachedStyleAttrs.Enumerate(ClearAttrCache, nullptr); 1.53 +} 1.54 + 1.55 +NS_IMPL_ISUPPORTS(nsHTMLCSSStyleSheet, nsIStyleRuleProcessor) 1.56 + 1.57 +/* virtual */ void 1.58 +nsHTMLCSSStyleSheet::RulesMatching(ElementRuleProcessorData* aData) 1.59 +{ 1.60 + Element* element = aData->mElement; 1.61 + 1.62 + // just get the one and only style rule from the content's STYLE attribute 1.63 + css::StyleRule* rule = element->GetInlineStyleRule(); 1.64 + if (rule) { 1.65 + rule->RuleMatched(); 1.66 + aData->mRuleWalker->Forward(rule); 1.67 + } 1.68 + 1.69 + rule = element->GetSMILOverrideStyleRule(); 1.70 + if (rule) { 1.71 + if (aData->mPresContext->IsProcessingRestyles() && 1.72 + !aData->mPresContext->IsProcessingAnimationStyleChange()) { 1.73 + // Non-animation restyle -- don't process SMIL override style, because we 1.74 + // don't want SMIL animation to trigger new CSS transitions. Instead, 1.75 + // request an Animation restyle, so we still get noticed. 1.76 + aData->mPresContext->PresShell()->RestyleForAnimation(element, 1.77 + eRestyle_Self); 1.78 + } else { 1.79 + // Animation restyle (or non-restyle traversal of rules) 1.80 + // Now we can walk SMIL overrride style, without triggering transitions. 1.81 + rule->RuleMatched(); 1.82 + aData->mRuleWalker->Forward(rule); 1.83 + } 1.84 + } 1.85 +} 1.86 + 1.87 +/* virtual */ void 1.88 +nsHTMLCSSStyleSheet::RulesMatching(PseudoElementRuleProcessorData* aData) 1.89 +{ 1.90 + if (nsCSSPseudoElements::PseudoElementSupportsStyleAttribute(aData->mPseudoType)) { 1.91 + MOZ_ASSERT(aData->mPseudoElement, 1.92 + "If pseudo element is supposed to support style attribute, it must " 1.93 + "have a pseudo element set"); 1.94 + 1.95 + // just get the one and only style rule from the content's STYLE attribute 1.96 + css::StyleRule* rule = aData->mPseudoElement->GetInlineStyleRule(); 1.97 + if (rule) { 1.98 + rule->RuleMatched(); 1.99 + aData->mRuleWalker->Forward(rule); 1.100 + } 1.101 + } 1.102 +} 1.103 + 1.104 +/* virtual */ void 1.105 +nsHTMLCSSStyleSheet::RulesMatching(AnonBoxRuleProcessorData* aData) 1.106 +{ 1.107 +} 1.108 + 1.109 +#ifdef MOZ_XUL 1.110 +/* virtual */ void 1.111 +nsHTMLCSSStyleSheet::RulesMatching(XULTreeRuleProcessorData* aData) 1.112 +{ 1.113 +} 1.114 +#endif 1.115 + 1.116 +// Test if style is dependent on content state 1.117 +/* virtual */ nsRestyleHint 1.118 +nsHTMLCSSStyleSheet::HasStateDependentStyle(StateRuleProcessorData* aData) 1.119 +{ 1.120 + return nsRestyleHint(0); 1.121 +} 1.122 + 1.123 +/* virtual */ nsRestyleHint 1.124 +nsHTMLCSSStyleSheet::HasStateDependentStyle(PseudoElementStateRuleProcessorData* aData) 1.125 +{ 1.126 + return nsRestyleHint(0); 1.127 +} 1.128 + 1.129 +/* virtual */ bool 1.130 +nsHTMLCSSStyleSheet::HasDocumentStateDependentStyle(StateRuleProcessorData* aData) 1.131 +{ 1.132 + return false; 1.133 +} 1.134 + 1.135 +// Test if style is dependent on attribute 1.136 +/* virtual */ nsRestyleHint 1.137 +nsHTMLCSSStyleSheet::HasAttributeDependentStyle(AttributeRuleProcessorData* aData) 1.138 +{ 1.139 + // Perhaps should check that it's XUL, SVG, (or HTML) namespace, but 1.140 + // it doesn't really matter. 1.141 + if (aData->mAttrHasChanged && aData->mAttribute == nsGkAtoms::style) { 1.142 + return eRestyle_Self; 1.143 + } 1.144 + 1.145 + return nsRestyleHint(0); 1.146 +} 1.147 + 1.148 +/* virtual */ bool 1.149 +nsHTMLCSSStyleSheet::MediumFeaturesChanged(nsPresContext* aPresContext) 1.150 +{ 1.151 + return false; 1.152 +} 1.153 + 1.154 +/* virtual */ size_t 1.155 +nsHTMLCSSStyleSheet::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const 1.156 +{ 1.157 + return 0; 1.158 +} 1.159 + 1.160 +/* virtual */ size_t 1.161 +nsHTMLCSSStyleSheet::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const 1.162 +{ 1.163 + return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf); 1.164 +} 1.165 + 1.166 +void 1.167 +nsHTMLCSSStyleSheet::CacheStyleAttr(const nsAString& aSerialized, 1.168 + MiscContainer* aValue) 1.169 +{ 1.170 + mCachedStyleAttrs.Put(aSerialized, aValue); 1.171 +} 1.172 + 1.173 +void 1.174 +nsHTMLCSSStyleSheet::EvictStyleAttr(const nsAString& aSerialized, 1.175 + MiscContainer* aValue) 1.176 +{ 1.177 +#ifdef DEBUG 1.178 + { 1.179 + NS_ASSERTION(aValue = mCachedStyleAttrs.Get(aSerialized), 1.180 + "Cached value does not match?!"); 1.181 + } 1.182 +#endif 1.183 + mCachedStyleAttrs.Remove(aSerialized); 1.184 +} 1.185 + 1.186 +MiscContainer* 1.187 +nsHTMLCSSStyleSheet::LookupStyleAttr(const nsAString& aSerialized) 1.188 +{ 1.189 + return mCachedStyleAttrs.Get(aSerialized); 1.190 +}