2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* style sheet and style rule processor representing style attributes
|
|
|
|
*/
|
|
|
|
|
2009-12-31 07:56:32 -08:00
|
|
|
#include "nsHTMLCSSStyleSheet.h"
|
2013-06-23 05:03:39 -07:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2011-03-10 18:48:57 -08:00
|
|
|
#include "mozilla/css/StyleRule.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIStyleRuleProcessor.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsRuleWalker.h"
|
2009-08-01 08:53:40 -07:00
|
|
|
#include "nsRuleProcessorData.h"
|
2010-05-05 11:18:05 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2012-09-30 09:40:24 -07:00
|
|
|
#include "nsAttrValue.h"
|
|
|
|
#include "nsAttrValueInlines.h"
|
2010-04-30 06:12:06 -07:00
|
|
|
|
|
|
|
using namespace mozilla::dom;
|
2011-03-10 18:48:57 -08:00
|
|
|
namespace css = mozilla::css;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-09-30 09:40:24 -07: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-13 22:34:37 -07:00
|
|
|
nsHTMLCSSStyleSheet::nsHTMLCSSStyleSheet()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-09-30 09:40:24 -07: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);
|
|
|
|
}
|
|
|
|
|
2013-06-13 22:34:37 -07:00
|
|
|
NS_IMPL_ISUPPORTS1(nsHTMLCSSStyleSheet, nsIStyleRuleProcessor)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-18 14:20:40 -07:00
|
|
|
/* virtual */ void
|
2009-12-31 07:56:32 -08:00
|
|
|
nsHTMLCSSStyleSheet::RulesMatching(ElementRuleProcessorData* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-04-30 06:12:06 -07:00
|
|
|
Element* element = aData->mElement;
|
2009-12-10 23:37:40 -08:00
|
|
|
|
|
|
|
// just get the one and only style rule from the content's STYLE attribute
|
2011-03-10 18:48:57 -08:00
|
|
|
css::StyleRule* rule = element->GetInlineStyleRule();
|
2009-12-11 08:13:19 -08:00
|
|
|
if (rule) {
|
|
|
|
rule->RuleMatched();
|
2009-12-10 23:37:40 -08:00
|
|
|
aData->mRuleWalker->Forward(rule);
|
2009-12-11 08:13:19 -08:00
|
|
|
}
|
2009-09-02 17:28:37 -07:00
|
|
|
|
2010-04-30 06:12:06 -07:00
|
|
|
rule = element->GetSMILOverrideStyleRule();
|
2009-12-11 08:13:19 -08:00
|
|
|
if (rule) {
|
2010-03-01 11:31:45 -08: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-06-30 18:54:29 -07:00
|
|
|
aData->mPresContext->PresShell()->RestyleForAnimation(element,
|
|
|
|
eRestyle_Self);
|
2010-03-01 11:31:45 -08: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 08:13:19 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-07-18 14:20:40 -07:00
|
|
|
/* virtual */ void
|
2009-12-31 07:56:32 -08:00
|
|
|
nsHTMLCSSStyleSheet::RulesMatching(PseudoElementRuleProcessorData* aData)
|
2009-12-10 23:37:40 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-07-18 14:20:40 -07:00
|
|
|
/* virtual */ void
|
2009-12-31 07:56:32 -08:00
|
|
|
nsHTMLCSSStyleSheet::RulesMatching(AnonBoxRuleProcessorData* aData)
|
2009-12-10 23:37:40 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-12-10 23:37:40 -08:00
|
|
|
#ifdef MOZ_XUL
|
2010-07-18 14:20:40 -07:00
|
|
|
/* virtual */ void
|
2009-12-31 07:56:32 -08:00
|
|
|
nsHTMLCSSStyleSheet::RulesMatching(XULTreeRuleProcessorData* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
2009-12-10 23:37:40 -08:00
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Test if style is dependent on content state
|
2010-05-14 12:05:14 -07:00
|
|
|
/* virtual */ nsRestyleHint
|
2009-12-31 07:56:32 -08:00
|
|
|
nsHTMLCSSStyleSheet::HasStateDependentStyle(StateRuleProcessorData* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-03-31 17:43:32 -07:00
|
|
|
return nsRestyleHint(0);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
/* virtual */ bool
|
2010-03-17 10:10:57 -07:00
|
|
|
nsHTMLCSSStyleSheet::HasDocumentStateDependentStyle(StateRuleProcessorData* aData)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-03-17 10:10:57 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Test if style is dependent on attribute
|
2010-05-14 12:05:14 -07:00
|
|
|
/* virtual */ nsRestyleHint
|
2009-12-31 07:56:32 -08:00
|
|
|
nsHTMLCSSStyleSheet::HasAttributeDependentStyle(AttributeRuleProcessorData* aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-05-14 10:04:51 -07: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-03-31 17:43:32 -07:00
|
|
|
return nsRestyleHint(0);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
/* virtual */ bool
|
2010-07-18 14:20:40 -07:00
|
|
|
nsHTMLCSSStyleSheet::MediumFeaturesChanged(nsPresContext* aPresContext)
|
2008-07-26 09:14:48 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2008-07-26 09:14:48 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-12-08 21:01:52 -08:00
|
|
|
/* virtual */ size_t
|
2013-06-23 05:03:39 -07:00
|
|
|
nsHTMLCSSStyleSheet::SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2011-12-08 21:01:52 -08:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ size_t
|
2013-06-23 05:03:39 -07:00
|
|
|
nsHTMLCSSStyleSheet::SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
2011-12-08 21:01:52 -08:00
|
|
|
{
|
2012-01-25 00:52:51 -08:00
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
2011-12-08 21:01:52 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-09-30 09:40:24 -07: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);
|
|
|
|
}
|