2001-09-25 05:32:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 01:52:36 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-05-14 03:42:18 +04:00
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* 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/
|
1998-05-14 03:42:18 +04:00
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* 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.
|
1998-05-14 03:42:18 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 05:32:19 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* Contributor(s):
|
2000-02-03 01:24:56 +03:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2001-09-25 05:32:19 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 01:52:36 +04:00
|
|
|
* 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"),
|
2001-09-25 05:32:19 +04:00
|
|
|
* 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
|
2004-04-18 01:52:36 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 05:32:19 +04:00
|
|
|
* 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
|
2004-04-18 01:52:36 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 05:32:19 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-02-27 04:35:25 +03:00
|
|
|
|
2006-03-25 08:47:31 +03:00
|
|
|
/*
|
|
|
|
* style sheet and style rule processor representing style attributes
|
|
|
|
*/
|
|
|
|
|
2009-12-31 18:56:32 +03:00
|
|
|
#include "nsHTMLCSSStyleSheet.h"
|
1998-05-14 03:42:18 +04:00
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsIURL.h"
|
2002-11-17 18:37:56 +03:00
|
|
|
#include "nsCSSPseudoElements.h"
|
1998-05-14 03:42:18 +04:00
|
|
|
#include "nsIStyleRule.h"
|
1998-05-19 01:11:08 +04:00
|
|
|
#include "nsIFrame.h"
|
2011-03-11 05:48:57 +03:00
|
|
|
#include "mozilla/css/StyleRule.h"
|
1999-10-08 07:09:31 +04:00
|
|
|
#include "nsIStyleRuleProcessor.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
1998-11-26 04:34:53 +03:00
|
|
|
#include "nsIDocument.h"
|
2000-03-31 11:08:36 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2001-10-24 04:01:09 +04:00
|
|
|
#include "nsRuleWalker.h"
|
2004-07-20 10:11:27 +04:00
|
|
|
#include "nsRuleData.h"
|
2009-08-01 19:53:40 +04:00
|
|
|
#include "nsRuleProcessorData.h"
|
2010-05-05 22:18:05 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2010-04-30 17:12:06 +04:00
|
|
|
|
|
|
|
using namespace mozilla::dom;
|
2011-03-11 05:48:57 +03:00
|
|
|
namespace css = mozilla::css;
|
2001-06-01 02:19:43 +04:00
|
|
|
|
2009-12-31 18:56:32 +03:00
|
|
|
nsHTMLCSSStyleSheet::nsHTMLCSSStyleSheet()
|
2010-05-18 08:00:39 +04:00
|
|
|
: mDocument(nsnull)
|
1998-05-14 03:42:18 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-12-31 18:56:33 +03:00
|
|
|
NS_IMPL_ISUPPORTS2(nsHTMLCSSStyleSheet,
|
2001-11-11 02:51:45 +03:00
|
|
|
nsIStyleSheet,
|
|
|
|
nsIStyleRuleProcessor)
|
1998-05-14 03:42:18 +04:00
|
|
|
|
2010-07-19 01:20:40 +04:00
|
|
|
/* virtual */ void
|
2009-12-31 18:56:32 +03:00
|
|
|
nsHTMLCSSStyleSheet::RulesMatching(ElementRuleProcessorData* aData)
|
1998-05-14 03:42:18 +04:00
|
|
|
{
|
2010-04-30 17:12:06 +04:00
|
|
|
Element* element = aData->mElement;
|
2009-12-11 10:37:40 +03:00
|
|
|
|
|
|
|
// just get the one and only style rule from the content's STYLE attribute
|
2011-03-11 05:48:57 +03:00
|
|
|
css::StyleRule* rule = element->GetInlineStyleRule();
|
2009-12-11 19:13:19 +03:00
|
|
|
if (rule) {
|
|
|
|
rule->RuleMatched();
|
2009-12-11 10:37:40 +03:00
|
|
|
aData->mRuleWalker->Forward(rule);
|
2009-12-11 19:13:19 +03:00
|
|
|
}
|
2009-09-03 04:28:37 +04:00
|
|
|
|
|
|
|
#ifdef MOZ_SMIL
|
2010-04-30 17:12:06 +04:00
|
|
|
rule = element->GetSMILOverrideStyleRule();
|
2009-12-11 19:13:19 +03:00
|
|
|
if (rule) {
|
2010-03-01 22:31:45 +03: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 05:54:29 +04:00
|
|
|
aData->mPresContext->PresShell()->RestyleForAnimation(element,
|
|
|
|
eRestyle_Self);
|
2010-03-01 22:31:45 +03: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 19:13:19 +03:00
|
|
|
}
|
2009-09-03 04:28:37 +04:00
|
|
|
#endif // MOZ_SMIL
|
1998-05-14 03:42:18 +04:00
|
|
|
}
|
|
|
|
|
2010-07-19 01:20:40 +04:00
|
|
|
/* virtual */ void
|
2009-12-31 18:56:32 +03:00
|
|
|
nsHTMLCSSStyleSheet::RulesMatching(PseudoElementRuleProcessorData* aData)
|
2009-12-11 10:37:40 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-07-19 01:20:40 +04:00
|
|
|
/* virtual */ void
|
2009-12-31 18:56:32 +03:00
|
|
|
nsHTMLCSSStyleSheet::RulesMatching(AnonBoxRuleProcessorData* aData)
|
2009-12-11 10:37:40 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-12-11 10:37:40 +03:00
|
|
|
#ifdef MOZ_XUL
|
2010-07-19 01:20:40 +04:00
|
|
|
/* virtual */ void
|
2009-12-31 18:56:32 +03:00
|
|
|
nsHTMLCSSStyleSheet::RulesMatching(XULTreeRuleProcessorData* aData)
|
1998-05-19 01:11:08 +04:00
|
|
|
{
|
|
|
|
}
|
2009-12-11 10:37:40 +03:00
|
|
|
#endif
|
1998-05-19 01:11:08 +04:00
|
|
|
|
2009-12-31 18:56:33 +03:00
|
|
|
nsresult
|
2009-12-31 18:56:32 +03:00
|
|
|
nsHTMLCSSStyleSheet::Init(nsIURI* aURL, nsIDocument* aDocument)
|
1998-12-03 23:20:35 +03: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;
|
|
|
|
}
|
|
|
|
|
1999-04-20 04:05:54 +04:00
|
|
|
// Test if style is dependent on content state
|
2010-05-14 23:05:14 +04:00
|
|
|
/* virtual */ nsRestyleHint
|
2009-12-31 18:56:32 +03:00
|
|
|
nsHTMLCSSStyleSheet::HasStateDependentStyle(StateRuleProcessorData* aData)
|
1999-04-20 04:05:54 +04:00
|
|
|
{
|
2010-04-01 04:43:32 +04:00
|
|
|
return nsRestyleHint(0);
|
1999-04-20 04:05:54 +04:00
|
|
|
}
|
|
|
|
|
2010-05-14 23:05:14 +04:00
|
|
|
/* virtual */ PRBool
|
2010-03-17 20:10:57 +03:00
|
|
|
nsHTMLCSSStyleSheet::HasDocumentStateDependentStyle(StateRuleProcessorData* aData)
|
|
|
|
{
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-02-22 19:10:53 +03:00
|
|
|
// Test if style is dependent on attribute
|
2010-05-14 23:05:14 +04:00
|
|
|
/* virtual */ nsRestyleHint
|
2009-12-31 18:56:32 +03:00
|
|
|
nsHTMLCSSStyleSheet::HasAttributeDependentStyle(AttributeRuleProcessorData* aData)
|
2003-02-22 19:10:53 +03:00
|
|
|
{
|
2010-05-14 21:04:51 +04: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 04:43:32 +04:00
|
|
|
return nsRestyleHint(0);
|
2003-02-22 19:10:53 +03:00
|
|
|
}
|
|
|
|
|
2010-07-19 01:20:40 +04:00
|
|
|
/* virtual */ PRBool
|
|
|
|
nsHTMLCSSStyleSheet::MediumFeaturesChanged(nsPresContext* aPresContext)
|
2008-07-26 20:14:48 +04:00
|
|
|
{
|
2010-07-19 01:20:40 +04:00
|
|
|
return PR_FALSE;
|
2008-07-26 20:14:48 +04:00
|
|
|
}
|
1999-04-20 04:05:54 +04:00
|
|
|
|
|
|
|
|
2010-05-18 08:00:39 +04:00
|
|
|
void
|
2009-12-31 18:56:32 +03:00
|
|
|
nsHTMLCSSStyleSheet::Reset(nsIURI* aURL)
|
1999-02-03 22:38:16 +03:00
|
|
|
{
|
|
|
|
mURL = aURL;
|
|
|
|
}
|
|
|
|
|
2010-05-18 08:00:39 +04:00
|
|
|
/* virtual */ nsIURI*
|
2010-05-13 00:18:47 +04:00
|
|
|
nsHTMLCSSStyleSheet::GetSheetURI() const
|
1998-05-14 03:42:18 +04:00
|
|
|
{
|
2010-05-13 00:18:47 +04:00
|
|
|
return mURL;
|
2004-09-10 10:45:59 +04:00
|
|
|
}
|
|
|
|
|
2010-05-18 08:00:39 +04:00
|
|
|
/* virtual */ nsIURI*
|
2010-05-13 00:18:47 +04:00
|
|
|
nsHTMLCSSStyleSheet::GetBaseURI() const
|
2004-09-10 10:45:59 +04:00
|
|
|
{
|
2010-05-13 00:18:47 +04:00
|
|
|
return mURL;
|
1998-11-26 04:34:53 +03:00
|
|
|
}
|
|
|
|
|
2010-05-14 23:05:14 +04:00
|
|
|
/* virtual */ void
|
2009-12-31 18:56:32 +03:00
|
|
|
nsHTMLCSSStyleSheet::GetTitle(nsString& aTitle) const
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
2004-06-17 04:13:25 +04:00
|
|
|
aTitle.AssignLiteral("Internal HTML/CSS Style Sheet");
|
1998-11-26 04:34:53 +03:00
|
|
|
}
|
|
|
|
|
2010-05-14 23:05:14 +04:00
|
|
|
/* virtual */ void
|
2009-12-31 18:56:32 +03:00
|
|
|
nsHTMLCSSStyleSheet::GetType(nsString& aType) const
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
2004-06-17 04:13:25 +04:00
|
|
|
aType.AssignLiteral("text/html");
|
1998-11-26 04:34:53 +03:00
|
|
|
}
|
|
|
|
|
2010-05-14 23:05:14 +04:00
|
|
|
/* virtual */ PRBool
|
2009-12-31 18:56:32 +03:00
|
|
|
nsHTMLCSSStyleSheet::HasRules() const
|
2003-07-04 05:44:24 +04:00
|
|
|
{
|
2008-12-12 21:59:03 +03:00
|
|
|
// Say we always have rules, since we don't know.
|
|
|
|
return PR_TRUE;
|
2003-07-04 05:44:24 +04:00
|
|
|
}
|
|
|
|
|
2010-05-14 23:05:14 +04:00
|
|
|
/* virtual */ PRBool
|
|
|
|
nsHTMLCSSStyleSheet::IsApplicable() const
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
2010-05-13 00:18:47 +04:00
|
|
|
return PR_TRUE;
|
1998-11-26 04:34:53 +03:00
|
|
|
}
|
|
|
|
|
2010-05-14 23:05:14 +04:00
|
|
|
/* virtual */ void
|
2009-12-31 18:56:32 +03:00
|
|
|
nsHTMLCSSStyleSheet::SetEnabled(PRBool aEnabled)
|
1998-11-26 04:34:53 +03:00
|
|
|
{ // these can't be disabled
|
|
|
|
}
|
|
|
|
|
2010-05-14 23:05:14 +04:00
|
|
|
/* virtual */ PRBool
|
|
|
|
nsHTMLCSSStyleSheet::IsComplete() const
|
2002-12-03 08:48:14 +03:00
|
|
|
{
|
2010-05-13 00:18:47 +04:00
|
|
|
return PR_TRUE;
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
|
|
|
|
2010-05-14 23:05:14 +04:00
|
|
|
/* virtual */ void
|
2009-12-31 18:56:32 +03:00
|
|
|
nsHTMLCSSStyleSheet::SetComplete()
|
2002-12-03 08:48:14 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
// style sheet owner info
|
2010-05-18 08:00:39 +04:00
|
|
|
/* virtual */ nsIStyleSheet*
|
2010-05-13 00:18:47 +04:00
|
|
|
nsHTMLCSSStyleSheet::GetParentSheet() const
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
2010-05-13 00:18:47 +04:00
|
|
|
return nsnull;
|
1998-11-26 04:34:53 +03:00
|
|
|
}
|
|
|
|
|
2010-05-18 08:00:39 +04:00
|
|
|
/* virtual */ nsIDocument*
|
2010-05-13 00:18:47 +04:00
|
|
|
nsHTMLCSSStyleSheet::GetOwningDocument() const
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
2010-05-13 00:18:47 +04:00
|
|
|
return mDocument;
|
1998-11-26 04:34:53 +03:00
|
|
|
}
|
|
|
|
|
2010-05-14 23:05:14 +04:00
|
|
|
/* virtual */ void
|
2009-12-31 18:56:32 +03:00
|
|
|
nsHTMLCSSStyleSheet::SetOwningDocument(nsIDocument* aDocument)
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
|
|
|
mDocument = aDocument;
|
1998-05-14 03:42:18 +04:00
|
|
|
}
|
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
2010-05-14 23:05:14 +04:00
|
|
|
/* virtual */ void
|
|
|
|
nsHTMLCSSStyleSheet::List(FILE* out, PRInt32 aIndent) const
|
1998-05-14 03:42:18 +04:00
|
|
|
{
|
|
|
|
// Indent
|
|
|
|
for (PRInt32 index = aIndent; --index >= 0; ) fputs(" ", out);
|
|
|
|
|
|
|
|
fputs("HTML CSS Style Sheet: ", out);
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCAutoString urlSpec;
|
|
|
|
mURL->GetSpec(urlSpec);
|
|
|
|
if (!urlSpec.IsEmpty()) {
|
|
|
|
fputs(urlSpec.get(), out);
|
1999-06-28 01:17:39 +04:00
|
|
|
}
|
1998-05-14 03:42:18 +04:00
|
|
|
fputs("\n", out);
|
|
|
|
}
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|