2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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"
|
|
|
|
#include "nsIFrame.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()
|
2010-05-17 21:00:39 -07:00
|
|
|
: mDocument(nsnull)
|
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
|
|
|
{
|
2010-05-12 13:18:47 -07:00
|
|
|
return nsnull;
|
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
|
|
|
|
nsHTMLCSSStyleSheet::List(FILE* out, PRInt32 aIndent) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Indent
|
|
|
|
for (PRInt32 index = aIndent; --index >= 0; ) fputs(" ", out);
|
|
|
|
|
|
|
|
fputs("HTML CSS Style Sheet: ", out);
|
|
|
|
nsCAutoString urlSpec;
|
|
|
|
mURL->GetSpec(urlSpec);
|
|
|
|
if (!urlSpec.IsEmpty()) {
|
|
|
|
fputs(urlSpec.get(), out);
|
|
|
|
}
|
|
|
|
fputs("\n", out);
|
|
|
|
}
|
|
|
|
#endif
|