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"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsCSSPseudoElements.h"
|
|
|
|
#include "nsIStyleRule.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"
|
|
|
|
#include "nsRuleData.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"
|
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
|
|
|
|
2009-12-31 07:56:32 -08:00
|
|
|
nsHTMLCSSStyleSheet::nsHTMLCSSStyleSheet()
|
2012-07-30 07:20:58 -07:00
|
|
|
: mDocument(nullptr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-12-31 07:56:33 -08:00
|
|
|
NS_IMPL_ISUPPORTS2(nsHTMLCSSStyleSheet,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIStyleSheet,
|
|
|
|
nsIStyleRuleProcessor)
|
|
|
|
|
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
|
|
|
|
2009-12-31 07:56:33 -08:00
|
|
|
nsresult
|
2009-12-31 07:56:32 -08:00
|
|
|
nsHTMLCSSStyleSheet::Init(nsIURI* aURL, nsIDocument* aDocument)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aURL && aDocument, "null ptr");
|
|
|
|
if (! aURL || ! aDocument)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
if (mURL || mDocument)
|
|
|
|
return NS_ERROR_ALREADY_INITIALIZED;
|
|
|
|
|
|
|
|
mDocument = aDocument; // not refcounted!
|
|
|
|
mURL = aURL;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
nsHTMLCSSStyleSheet::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ size_t
|
|
|
|
nsHTMLCSSStyleSheet::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
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
|
|
|
|
2010-05-17 21:00:39 -07:00
|
|
|
void
|
2009-12-31 07:56:32 -08:00
|
|
|
nsHTMLCSSStyleSheet::Reset(nsIURI* aURL)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mURL = aURL;
|
|
|
|
}
|
|
|
|
|
2010-05-17 21:00:39 -07:00
|
|
|
/* virtual */ nsIURI*
|
2010-05-12 13:18:47 -07:00
|
|
|
nsHTMLCSSStyleSheet::GetSheetURI() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-05-12 13:18:47 -07:00
|
|
|
return mURL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-05-17 21:00:39 -07:00
|
|
|
/* virtual */ nsIURI*
|
2010-05-12 13:18:47 -07:00
|
|
|
nsHTMLCSSStyleSheet::GetBaseURI() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-05-12 13:18:47 -07:00
|
|
|
return mURL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-05-14 12:05:14 -07:00
|
|
|
/* virtual */ void
|
2009-12-31 07:56:32 -08:00
|
|
|
nsHTMLCSSStyleSheet::GetTitle(nsString& aTitle) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
aTitle.AssignLiteral("Internal HTML/CSS Style Sheet");
|
|
|
|
}
|
|
|
|
|
2010-05-14 12:05:14 -07:00
|
|
|
/* virtual */ void
|
2009-12-31 07:56:32 -08:00
|
|
|
nsHTMLCSSStyleSheet::GetType(nsString& aType) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
aType.AssignLiteral("text/html");
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
/* virtual */ bool
|
2009-12-31 07:56:32 -08:00
|
|
|
nsHTMLCSSStyleSheet::HasRules() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-12-12 10:59:03 -08:00
|
|
|
// Say we always have rules, since we don't know.
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
/* virtual */ bool
|
2010-05-14 12:05:14 -07:00
|
|
|
nsHTMLCSSStyleSheet::IsApplicable() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-05-14 12:05:14 -07:00
|
|
|
/* virtual */ void
|
2011-09-28 23:19:26 -07:00
|
|
|
nsHTMLCSSStyleSheet::SetEnabled(bool aEnabled)
|
2007-03-22 10:30:00 -07:00
|
|
|
{ // these can't be disabled
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
/* virtual */ bool
|
2010-05-14 12:05:14 -07:00
|
|
|
nsHTMLCSSStyleSheet::IsComplete() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-05-14 12:05:14 -07:00
|
|
|
/* virtual */ void
|
2009-12-31 07:56:32 -08:00
|
|
|
nsHTMLCSSStyleSheet::SetComplete()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// style sheet owner info
|
2010-05-17 21:00:39 -07:00
|
|
|
/* virtual */ nsIStyleSheet*
|
2010-05-12 13:18:47 -07:00
|
|
|
nsHTMLCSSStyleSheet::GetParentSheet() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-05-17 21:00:39 -07:00
|
|
|
/* virtual */ nsIDocument*
|
2010-05-12 13:18:47 -07:00
|
|
|
nsHTMLCSSStyleSheet::GetOwningDocument() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-05-12 13:18:47 -07:00
|
|
|
return mDocument;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-05-14 12:05:14 -07:00
|
|
|
/* virtual */ void
|
2009-12-31 07:56:32 -08:00
|
|
|
nsHTMLCSSStyleSheet::SetOwningDocument(nsIDocument* aDocument)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mDocument = aDocument;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2010-05-14 12:05:14 -07:00
|
|
|
/* virtual */ void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsHTMLCSSStyleSheet::List(FILE* out, int32_t aIndent) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Indent
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t index = aIndent; --index >= 0; ) fputs(" ", out);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
fputs("HTML CSS Style Sheet: ", out);
|
|
|
|
nsCAutoString urlSpec;
|
|
|
|
mURL->GetSpec(urlSpec);
|
|
|
|
if (!urlSpec.IsEmpty()) {
|
|
|
|
fputs(urlSpec.get(), out);
|
|
|
|
}
|
|
|
|
fputs("\n", out);
|
|
|
|
}
|
|
|
|
#endif
|