1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
23 * Pierre Phaneuf <pp@ludusdesign.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either of the GNU General Public License Version 2 or later (the "GPL"),
27 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
40 * style sheet and style rule processor representing style attributes
43 #include "nsHTMLCSSStyleSheet.h"
47 #include "nsCSSPseudoElements.h"
48 #include "nsIStyleRule.h"
50 #include "nsICSSStyleRule.h"
51 #include "nsIStyleRuleProcessor.h"
52 #include "nsPresContext.h"
53 #include "nsIDocument.h"
55 #include "nsRuleWalker.h"
56 #include "nsRuleData.h"
57 #include "nsRuleProcessorData.h"
58 #include "mozilla/dom/Element.h"
60 using namespace mozilla::dom
;
62 nsHTMLCSSStyleSheet::nsHTMLCSSStyleSheet()
67 NS_IMPL_ISUPPORTS2(nsHTMLCSSStyleSheet
,
69 nsIStyleRuleProcessor
)
72 nsHTMLCSSStyleSheet::RulesMatching(ElementRuleProcessorData
* aData
)
74 Element
* element
= aData
->mElement
;
76 // just get the one and only style rule from the content's STYLE attribute
77 nsICSSStyleRule
* rule
= element
->GetInlineStyleRule();
80 aData
->mRuleWalker
->Forward(rule
);
84 rule
= element
->GetSMILOverrideStyleRule();
86 if (aData
->mPresContext
->IsProcessingRestyles() &&
87 !aData
->mPresContext
->IsProcessingAnimationStyleChange()) {
88 // Non-animation restyle -- don't process SMIL override style, because we
89 // don't want SMIL animation to trigger new CSS transitions. Instead,
90 // request an Animation restyle, so we still get noticed.
91 aData
->mPresContext
->PresShell()->RestyleForAnimation(element
,
94 // Animation restyle (or non-restyle traversal of rules)
95 // Now we can walk SMIL overrride style, without triggering transitions.
97 aData
->mRuleWalker
->Forward(rule
);
104 nsHTMLCSSStyleSheet::RulesMatching(PseudoElementRuleProcessorData
* aData
)
109 nsHTMLCSSStyleSheet::RulesMatching(AnonBoxRuleProcessorData
* aData
)
115 nsHTMLCSSStyleSheet::RulesMatching(XULTreeRuleProcessorData
* aData
)
121 nsHTMLCSSStyleSheet::Init(nsIURI
* aURL
, nsIDocument
* aDocument
)
123 NS_PRECONDITION(aURL
&& aDocument
, "null ptr");
124 if (! aURL
|| ! aDocument
)
125 return NS_ERROR_NULL_POINTER
;
127 if (mURL
|| mDocument
)
128 return NS_ERROR_ALREADY_INITIALIZED
;
130 mDocument
= aDocument
; // not refcounted!
135 // Test if style is dependent on content state
136 /* virtual */ nsRestyleHint
137 nsHTMLCSSStyleSheet::HasStateDependentStyle(StateRuleProcessorData
* aData
)
139 return nsRestyleHint(0);
143 nsHTMLCSSStyleSheet::HasDocumentStateDependentStyle(StateRuleProcessorData
* aData
)
148 // Test if style is dependent on attribute
149 /* virtual */ nsRestyleHint
150 nsHTMLCSSStyleSheet::HasAttributeDependentStyle(AttributeRuleProcessorData
* aData
)
152 // Perhaps should check that it's XUL, SVG, (or HTML) namespace, but
153 // it doesn't really matter.
154 if (aData
->mAttrHasChanged
&& aData
->mAttribute
== nsGkAtoms::style
) {
155 return eRestyle_Self
;
158 return nsRestyleHint(0);
162 nsHTMLCSSStyleSheet::MediumFeaturesChanged(nsPresContext
* aPresContext
)
169 nsHTMLCSSStyleSheet::Reset(nsIURI
* aURL
)
174 /* virtual */ nsIURI
*
175 nsHTMLCSSStyleSheet::GetSheetURI() const
180 /* virtual */ nsIURI
*
181 nsHTMLCSSStyleSheet::GetBaseURI() const
187 nsHTMLCSSStyleSheet::GetTitle(nsString
& aTitle
) const
189 aTitle
.AssignLiteral("Internal HTML/CSS Style Sheet");
193 nsHTMLCSSStyleSheet::GetType(nsString
& aType
) const
195 aType
.AssignLiteral("text/html");
199 nsHTMLCSSStyleSheet::HasRules() const
201 // Say we always have rules, since we don't know.
206 nsHTMLCSSStyleSheet::IsApplicable() const
212 nsHTMLCSSStyleSheet::SetEnabled(PRBool aEnabled
)
213 { // these can't be disabled
217 nsHTMLCSSStyleSheet::IsComplete() const
223 nsHTMLCSSStyleSheet::SetComplete()
227 // style sheet owner info
228 /* virtual */ nsIStyleSheet
*
229 nsHTMLCSSStyleSheet::GetParentSheet() const
234 /* virtual */ nsIDocument
*
235 nsHTMLCSSStyleSheet::GetOwningDocument() const
241 nsHTMLCSSStyleSheet::SetOwningDocument(nsIDocument
* aDocument
)
243 mDocument
= aDocument
;
248 nsHTMLCSSStyleSheet::List(FILE* out
, PRInt32 aIndent
) const
251 for (PRInt32 index
= aIndent
; --index
>= 0; ) fputs(" ", out
);
253 fputs("HTML CSS Style Sheet: ", out
);
254 nsCAutoString urlSpec
;
255 mURL
->GetSpec(urlSpec
);
256 if (!urlSpec
.IsEmpty()) {
257 fputs(urlSpec
.get(), out
);