2001-09-25 01:32:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-02-27 01:35:25 +00:00
|
|
|
|
2006-03-25 05:47:31 +00:00
|
|
|
/*
|
|
|
|
* style sheet and style rule processor representing style attributes
|
|
|
|
*/
|
|
|
|
|
2009-12-31 15:56:32 +00:00
|
|
|
#include "nsHTMLCSSStyleSheet.h"
|
2013-06-23 12:03:39 +00:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2011-03-11 02:48:57 +00:00
|
|
|
#include "mozilla/css/StyleRule.h"
|
1999-10-08 03:09:31 +00:00
|
|
|
#include "nsIStyleRuleProcessor.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
2001-10-24 00:01:09 +00:00
|
|
|
#include "nsRuleWalker.h"
|
2009-08-01 15:53:40 +00:00
|
|
|
#include "nsRuleProcessorData.h"
|
2010-05-05 18:18:05 +00:00
|
|
|
#include "mozilla/dom/Element.h"
|
2012-09-30 16:40:24 +00:00
|
|
|
#include "nsAttrValue.h"
|
|
|
|
#include "nsAttrValueInlines.h"
|
2010-04-30 13:12:06 +00:00
|
|
|
|
2013-11-15 02:42:57 +00:00
|
|
|
using namespace mozilla;
|
2010-04-30 13:12:06 +00:00
|
|
|
using namespace mozilla::dom;
|
2001-05-31 22:19:43 +00:00
|
|
|
|
2012-09-30 16:40:24 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
PLDHashOperator
|
|
|
|
ClearAttrCache(const nsAString& aKey, MiscContainer*& aValue, void*)
|
|
|
|
{
|
|
|
|
// Ideally we'd just call MiscContainer::Evict, but we can't do that since
|
|
|
|
// we're iterating the hashtable.
|
|
|
|
MOZ_ASSERT(aValue->mType == nsAttrValue::eCSSStyleRule);
|
|
|
|
|
|
|
|
aValue->mValue.mCSSStyleRule->SetHTMLCSSStyleSheet(nullptr);
|
|
|
|
aValue->mValue.mCached = 0;
|
|
|
|
|
|
|
|
return PL_DHASH_REMOVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
2013-06-14 05:34:37 +00:00
|
|
|
nsHTMLCSSStyleSheet::nsHTMLCSSStyleSheet()
|
1998-05-13 23:42:18 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-09-30 16:40:24 +00:00
|
|
|
nsHTMLCSSStyleSheet::~nsHTMLCSSStyleSheet()
|
|
|
|
{
|
|
|
|
// We may go away before all of our cached style attributes do,
|
|
|
|
// so clean up any that are left.
|
|
|
|
mCachedStyleAttrs.Enumerate(ClearAttrCache, nullptr);
|
|
|
|
}
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(nsHTMLCSSStyleSheet, nsIStyleRuleProcessor)
|
1998-05-13 23:42:18 +00:00
|
|
|
|
2010-07-18 21:20:40 +00:00
|
|
|
/* virtual */ void
|
2009-12-31 15:56:32 +00:00
|
|
|
nsHTMLCSSStyleSheet::RulesMatching(ElementRuleProcessorData* aData)
|
1998-05-13 23:42:18 +00:00
|
|
|
{
|
2010-04-30 13:12:06 +00:00
|
|
|
Element* element = aData->mElement;
|
2009-12-11 07:37:40 +00:00
|
|
|
|
|
|
|
// just get the one and only style rule from the content's STYLE attribute
|
2011-03-11 02:48:57 +00:00
|
|
|
css::StyleRule* rule = element->GetInlineStyleRule();
|
2009-12-11 16:13:19 +00:00
|
|
|
if (rule) {
|
|
|
|
rule->RuleMatched();
|
2009-12-11 07:37:40 +00:00
|
|
|
aData->mRuleWalker->Forward(rule);
|
2009-12-11 16:13:19 +00:00
|
|
|
}
|
2009-09-03 00:28:37 +00:00
|
|
|
|
2010-04-30 13:12:06 +00:00
|
|
|
rule = element->GetSMILOverrideStyleRule();
|
2009-12-11 16:13:19 +00:00
|
|
|
if (rule) {
|
2010-03-01 19:31:45 +00:00
|
|
|
if (aData->mPresContext->IsProcessingRestyles() &&
|
|
|
|
!aData->mPresContext->IsProcessingAnimationStyleChange()) {
|
|
|
|
// Non-animation restyle -- don't process SMIL override style, because we
|
|
|
|
// don't want SMIL animation to trigger new CSS transitions. Instead,
|
|
|
|
// request an Animation restyle, so we still get noticed.
|
2010-07-01 01:54:29 +00:00
|
|
|
aData->mPresContext->PresShell()->RestyleForAnimation(element,
|
|
|
|
eRestyle_Self);
|
2010-03-01 19:31:45 +00:00
|
|
|
} else {
|
|
|
|
// Animation restyle (or non-restyle traversal of rules)
|
|
|
|
// Now we can walk SMIL overrride style, without triggering transitions.
|
|
|
|
rule->RuleMatched();
|
|
|
|
aData->mRuleWalker->Forward(rule);
|
|
|
|
}
|
2009-12-11 16:13:19 +00:00
|
|
|
}
|
1998-05-13 23:42:18 +00:00
|
|
|
}
|
|
|
|
|
2010-07-18 21:20:40 +00:00
|
|
|
/* virtual */ void
|
2009-12-31 15:56:32 +00:00
|
|
|
nsHTMLCSSStyleSheet::RulesMatching(PseudoElementRuleProcessorData* aData)
|
2009-12-11 07:37:40 +00:00
|
|
|
{
|
2013-07-09 22:25:27 +00:00
|
|
|
if (nsCSSPseudoElements::PseudoElementSupportsStyleAttribute(aData->mPseudoType)) {
|
|
|
|
MOZ_ASSERT(aData->mPseudoElement,
|
|
|
|
"If pseudo element is supposed to support style attribute, it must "
|
|
|
|
"have a pseudo element set");
|
|
|
|
|
|
|
|
// just get the one and only style rule from the content's STYLE attribute
|
|
|
|
css::StyleRule* rule = aData->mPseudoElement->GetInlineStyleRule();
|
|
|
|
if (rule) {
|
|
|
|
rule->RuleMatched();
|
|
|
|
aData->mRuleWalker->Forward(rule);
|
|
|
|
}
|
|
|
|
}
|
2009-12-11 07:37:40 +00:00
|
|
|
}
|
|
|
|
|
2010-07-18 21:20:40 +00:00
|
|
|
/* virtual */ void
|
2009-12-31 15:56:32 +00:00
|
|
|
nsHTMLCSSStyleSheet::RulesMatching(AnonBoxRuleProcessorData* aData)
|
2009-12-11 07:37:40 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-12-11 07:37:40 +00:00
|
|
|
#ifdef MOZ_XUL
|
2010-07-18 21:20:40 +00:00
|
|
|
/* virtual */ void
|
2009-12-31 15:56:32 +00:00
|
|
|
nsHTMLCSSStyleSheet::RulesMatching(XULTreeRuleProcessorData* aData)
|
1998-05-18 21:11:08 +00:00
|
|
|
{
|
|
|
|
}
|
2009-12-11 07:37:40 +00:00
|
|
|
#endif
|
1998-05-18 21:11:08 +00:00
|
|
|
|
1999-04-20 00:05:54 +00:00
|
|
|
// Test if style is dependent on content state
|
2010-05-14 19:05:14 +00:00
|
|
|
/* virtual */ nsRestyleHint
|
2009-12-31 15:56:32 +00:00
|
|
|
nsHTMLCSSStyleSheet::HasStateDependentStyle(StateRuleProcessorData* aData)
|
1999-04-20 00:05:54 +00:00
|
|
|
{
|
2010-04-01 00:43:32 +00:00
|
|
|
return nsRestyleHint(0);
|
1999-04-20 00:05:54 +00:00
|
|
|
}
|
|
|
|
|
2013-11-28 06:46:39 +00:00
|
|
|
/* virtual */ nsRestyleHint
|
|
|
|
nsHTMLCSSStyleSheet::HasStateDependentStyle(PseudoElementStateRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
return nsRestyleHint(0);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
/* virtual */ bool
|
2010-03-17 17:10:57 +00:00
|
|
|
nsHTMLCSSStyleSheet::HasDocumentStateDependentStyle(StateRuleProcessorData* aData)
|
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-03-17 17:10:57 +00:00
|
|
|
}
|
|
|
|
|
2003-02-22 16:10:53 +00:00
|
|
|
// Test if style is dependent on attribute
|
2010-05-14 19:05:14 +00:00
|
|
|
/* virtual */ nsRestyleHint
|
2009-12-31 15:56:32 +00:00
|
|
|
nsHTMLCSSStyleSheet::HasAttributeDependentStyle(AttributeRuleProcessorData* aData)
|
2003-02-22 16:10:53 +00:00
|
|
|
{
|
2010-05-14 17:04:51 +00:00
|
|
|
// Perhaps should check that it's XUL, SVG, (or HTML) namespace, but
|
|
|
|
// it doesn't really matter.
|
|
|
|
if (aData->mAttrHasChanged && aData->mAttribute == nsGkAtoms::style) {
|
|
|
|
return eRestyle_Self;
|
|
|
|
}
|
|
|
|
|
2010-04-01 00:43:32 +00:00
|
|
|
return nsRestyleHint(0);
|
2003-02-22 16:10:53 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
/* virtual */ bool
|
2010-07-18 21:20:40 +00:00
|
|
|
nsHTMLCSSStyleSheet::MediumFeaturesChanged(nsPresContext* aPresContext)
|
2008-07-26 16:14:48 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2008-07-26 16:14:48 +00:00
|
|
|
}
|
1999-04-20 00:05:54 +00:00
|
|
|
|
2014-06-22 22:02:05 +00:00
|
|
|
size_t
|
|
|
|
SizeOfCachedStyleAttrsEntryExcludingThis(nsStringHashKey::KeyType& aKey,
|
|
|
|
MiscContainer* const& aData,
|
|
|
|
mozilla::MallocSizeOf aMallocSizeOf,
|
|
|
|
void* userArg)
|
|
|
|
{
|
|
|
|
// We don't own the MiscContainers so we don't count them. We do care about
|
|
|
|
// the size of the nsString members in the keys though.
|
|
|
|
return aKey.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
2011-12-09 05:01:52 +00:00
|
|
|
/* virtual */ size_t
|
2013-06-23 12:03:39 +00:00
|
|
|
nsHTMLCSSStyleSheet::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2011-12-09 05:01:52 +00:00
|
|
|
{
|
2014-06-22 22:02:05 +00:00
|
|
|
// The size of mCachedStyleAttrs's mTable member (a PLDHashTable) is
|
|
|
|
// significant in itself, but more significant is the size of the nsString
|
|
|
|
// members of the nsStringHashKeys.
|
|
|
|
return mCachedStyleAttrs.SizeOfExcludingThis(SizeOfCachedStyleAttrsEntryExcludingThis,
|
|
|
|
aMallocSizeOf,
|
|
|
|
nullptr);
|
2011-12-09 05:01:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ size_t
|
2013-06-23 12:03:39 +00:00
|
|
|
nsHTMLCSSStyleSheet::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2011-12-09 05:01:52 +00:00
|
|
|
{
|
2012-01-25 08:52:51 +00:00
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
2011-12-09 05:01:52 +00:00
|
|
|
}
|
1999-04-20 00:05:54 +00:00
|
|
|
|
2012-09-30 16:40:24 +00:00
|
|
|
void
|
|
|
|
nsHTMLCSSStyleSheet::CacheStyleAttr(const nsAString& aSerialized,
|
|
|
|
MiscContainer* aValue)
|
|
|
|
{
|
|
|
|
mCachedStyleAttrs.Put(aSerialized, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHTMLCSSStyleSheet::EvictStyleAttr(const nsAString& aSerialized,
|
|
|
|
MiscContainer* aValue)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aValue = mCachedStyleAttrs.Get(aSerialized),
|
|
|
|
"Cached value does not match?!");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
mCachedStyleAttrs.Remove(aSerialized);
|
|
|
|
}
|
|
|
|
|
|
|
|
MiscContainer*
|
|
|
|
nsHTMLCSSStyleSheet::LookupStyleAttr(const nsAString& aSerialized)
|
|
|
|
{
|
|
|
|
return mCachedStyleAttrs.Get(aSerialized);
|
|
|
|
}
|