Merge mozilla-central and tracemonkey. (a=blockers)
[mozilla-central.git] / layout / style / nsHTMLCSSStyleSheet.cpp
bloba6fcf86308b992ee4bc366096fbbb4ce891591f4
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
13 * License.
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.
22 * Contributor(s):
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"
44 #include "nsCRT.h"
45 #include "nsIAtom.h"
46 #include "nsIURL.h"
47 #include "nsCSSPseudoElements.h"
48 #include "nsIStyleRule.h"
49 #include "nsIFrame.h"
50 #include "nsICSSStyleRule.h"
51 #include "nsIStyleRuleProcessor.h"
52 #include "nsPresContext.h"
53 #include "nsIDocument.h"
54 #include "nsCOMPtr.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()
63 : mDocument(nsnull)
67 NS_IMPL_ISUPPORTS2(nsHTMLCSSStyleSheet,
68 nsIStyleSheet,
69 nsIStyleRuleProcessor)
71 /* virtual */ void
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();
78 if (rule) {
79 rule->RuleMatched();
80 aData->mRuleWalker->Forward(rule);
83 #ifdef MOZ_SMIL
84 rule = element->GetSMILOverrideStyleRule();
85 if (rule) {
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,
92 eRestyle_Self);
93 } else {
94 // Animation restyle (or non-restyle traversal of rules)
95 // Now we can walk SMIL overrride style, without triggering transitions.
96 rule->RuleMatched();
97 aData->mRuleWalker->Forward(rule);
100 #endif // MOZ_SMIL
103 /* virtual */ void
104 nsHTMLCSSStyleSheet::RulesMatching(PseudoElementRuleProcessorData* aData)
108 /* virtual */ void
109 nsHTMLCSSStyleSheet::RulesMatching(AnonBoxRuleProcessorData* aData)
113 #ifdef MOZ_XUL
114 /* virtual */ void
115 nsHTMLCSSStyleSheet::RulesMatching(XULTreeRuleProcessorData* aData)
118 #endif
120 nsresult
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!
131 mURL = aURL;
132 return NS_OK;
135 // Test if style is dependent on content state
136 /* virtual */ nsRestyleHint
137 nsHTMLCSSStyleSheet::HasStateDependentStyle(StateRuleProcessorData* aData)
139 return nsRestyleHint(0);
142 /* virtual */ PRBool
143 nsHTMLCSSStyleSheet::HasDocumentStateDependentStyle(StateRuleProcessorData* aData)
145 return PR_FALSE;
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);
161 /* virtual */ PRBool
162 nsHTMLCSSStyleSheet::MediumFeaturesChanged(nsPresContext* aPresContext)
164 return PR_FALSE;
168 void
169 nsHTMLCSSStyleSheet::Reset(nsIURI* aURL)
171 mURL = aURL;
174 /* virtual */ nsIURI*
175 nsHTMLCSSStyleSheet::GetSheetURI() const
177 return mURL;
180 /* virtual */ nsIURI*
181 nsHTMLCSSStyleSheet::GetBaseURI() const
183 return mURL;
186 /* virtual */ void
187 nsHTMLCSSStyleSheet::GetTitle(nsString& aTitle) const
189 aTitle.AssignLiteral("Internal HTML/CSS Style Sheet");
192 /* virtual */ void
193 nsHTMLCSSStyleSheet::GetType(nsString& aType) const
195 aType.AssignLiteral("text/html");
198 /* virtual */ PRBool
199 nsHTMLCSSStyleSheet::HasRules() const
201 // Say we always have rules, since we don't know.
202 return PR_TRUE;
205 /* virtual */ PRBool
206 nsHTMLCSSStyleSheet::IsApplicable() const
208 return PR_TRUE;
211 /* virtual */ void
212 nsHTMLCSSStyleSheet::SetEnabled(PRBool aEnabled)
213 { // these can't be disabled
216 /* virtual */ PRBool
217 nsHTMLCSSStyleSheet::IsComplete() const
219 return PR_TRUE;
222 /* virtual */ void
223 nsHTMLCSSStyleSheet::SetComplete()
227 // style sheet owner info
228 /* virtual */ nsIStyleSheet*
229 nsHTMLCSSStyleSheet::GetParentSheet() const
231 return nsnull;
234 /* virtual */ nsIDocument*
235 nsHTMLCSSStyleSheet::GetOwningDocument() const
237 return mDocument;
240 /* virtual */ void
241 nsHTMLCSSStyleSheet::SetOwningDocument(nsIDocument* aDocument)
243 mDocument = aDocument;
246 #ifdef DEBUG
247 /* virtual */ void
248 nsHTMLCSSStyleSheet::List(FILE* out, PRInt32 aIndent) const
250 // Indent
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);
259 fputs("\n", out);
261 #endif