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
4 : *
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/
9 : *
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.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
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.
21 : *
22 : * Contributor(s):
23 : * Pierre Phaneuf <pp@ludusdesign.com>
24 : *
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.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : /*
40 : * style sheet and style rule processor representing style attributes
41 : */
42 :
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 "mozilla/css/StyleRule.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"
59 :
60 : using namespace mozilla::dom;
61 : namespace css = mozilla::css;
62 :
63 469 : nsHTMLCSSStyleSheet::nsHTMLCSSStyleSheet()
64 469 : : mDocument(nsnull)
65 : {
66 469 : }
67 :
68 2035 : NS_IMPL_ISUPPORTS2(nsHTMLCSSStyleSheet,
69 : nsIStyleSheet,
70 : nsIStyleRuleProcessor)
71 :
72 : /* virtual */ void
73 0 : nsHTMLCSSStyleSheet::RulesMatching(ElementRuleProcessorData* aData)
74 : {
75 0 : Element* element = aData->mElement;
76 :
77 : // just get the one and only style rule from the content's STYLE attribute
78 0 : css::StyleRule* rule = element->GetInlineStyleRule();
79 0 : if (rule) {
80 0 : rule->RuleMatched();
81 0 : aData->mRuleWalker->Forward(rule);
82 : }
83 :
84 0 : rule = element->GetSMILOverrideStyleRule();
85 0 : if (rule) {
86 0 : if (aData->mPresContext->IsProcessingRestyles() &&
87 0 : !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 0 : 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 0 : rule->RuleMatched();
97 0 : aData->mRuleWalker->Forward(rule);
98 : }
99 : }
100 0 : }
101 :
102 : /* virtual */ void
103 0 : nsHTMLCSSStyleSheet::RulesMatching(PseudoElementRuleProcessorData* aData)
104 : {
105 0 : }
106 :
107 : /* virtual */ void
108 0 : nsHTMLCSSStyleSheet::RulesMatching(AnonBoxRuleProcessorData* aData)
109 : {
110 0 : }
111 :
112 : #ifdef MOZ_XUL
113 : /* virtual */ void
114 0 : nsHTMLCSSStyleSheet::RulesMatching(XULTreeRuleProcessorData* aData)
115 : {
116 0 : }
117 : #endif
118 :
119 : nsresult
120 469 : nsHTMLCSSStyleSheet::Init(nsIURI* aURL, nsIDocument* aDocument)
121 : {
122 469 : NS_PRECONDITION(aURL && aDocument, "null ptr");
123 469 : if (! aURL || ! aDocument)
124 0 : return NS_ERROR_NULL_POINTER;
125 :
126 469 : if (mURL || mDocument)
127 0 : return NS_ERROR_ALREADY_INITIALIZED;
128 :
129 469 : mDocument = aDocument; // not refcounted!
130 469 : mURL = aURL;
131 469 : return NS_OK;
132 : }
133 :
134 : // Test if style is dependent on content state
135 : /* virtual */ nsRestyleHint
136 0 : nsHTMLCSSStyleSheet::HasStateDependentStyle(StateRuleProcessorData* aData)
137 : {
138 0 : return nsRestyleHint(0);
139 : }
140 :
141 : /* virtual */ bool
142 0 : nsHTMLCSSStyleSheet::HasDocumentStateDependentStyle(StateRuleProcessorData* aData)
143 : {
144 0 : return false;
145 : }
146 :
147 : // Test if style is dependent on attribute
148 : /* virtual */ nsRestyleHint
149 0 : nsHTMLCSSStyleSheet::HasAttributeDependentStyle(AttributeRuleProcessorData* aData)
150 : {
151 : // Perhaps should check that it's XUL, SVG, (or HTML) namespace, but
152 : // it doesn't really matter.
153 0 : if (aData->mAttrHasChanged && aData->mAttribute == nsGkAtoms::style) {
154 0 : return eRestyle_Self;
155 : }
156 :
157 0 : return nsRestyleHint(0);
158 : }
159 :
160 : /* virtual */ bool
161 0 : nsHTMLCSSStyleSheet::MediumFeaturesChanged(nsPresContext* aPresContext)
162 : {
163 0 : return false;
164 : }
165 :
166 : /* virtual */ size_t
167 0 : nsHTMLCSSStyleSheet::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const
168 : {
169 0 : return 0;
170 : }
171 :
172 : /* virtual */ size_t
173 0 : nsHTMLCSSStyleSheet::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
174 : {
175 0 : return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
176 : }
177 :
178 : void
179 0 : nsHTMLCSSStyleSheet::Reset(nsIURI* aURL)
180 : {
181 0 : mURL = aURL;
182 0 : }
183 :
184 : /* virtual */ nsIURI*
185 0 : nsHTMLCSSStyleSheet::GetSheetURI() const
186 : {
187 0 : return mURL;
188 : }
189 :
190 : /* virtual */ nsIURI*
191 0 : nsHTMLCSSStyleSheet::GetBaseURI() const
192 : {
193 0 : return mURL;
194 : }
195 :
196 : /* virtual */ void
197 0 : nsHTMLCSSStyleSheet::GetTitle(nsString& aTitle) const
198 : {
199 0 : aTitle.AssignLiteral("Internal HTML/CSS Style Sheet");
200 0 : }
201 :
202 : /* virtual */ void
203 0 : nsHTMLCSSStyleSheet::GetType(nsString& aType) const
204 : {
205 0 : aType.AssignLiteral("text/html");
206 0 : }
207 :
208 : /* virtual */ bool
209 0 : nsHTMLCSSStyleSheet::HasRules() const
210 : {
211 : // Say we always have rules, since we don't know.
212 0 : return true;
213 : }
214 :
215 : /* virtual */ bool
216 0 : nsHTMLCSSStyleSheet::IsApplicable() const
217 : {
218 0 : return true;
219 : }
220 :
221 : /* virtual */ void
222 0 : nsHTMLCSSStyleSheet::SetEnabled(bool aEnabled)
223 : { // these can't be disabled
224 0 : }
225 :
226 : /* virtual */ bool
227 0 : nsHTMLCSSStyleSheet::IsComplete() const
228 : {
229 0 : return true;
230 : }
231 :
232 : /* virtual */ void
233 0 : nsHTMLCSSStyleSheet::SetComplete()
234 : {
235 0 : }
236 :
237 : // style sheet owner info
238 : /* virtual */ nsIStyleSheet*
239 0 : nsHTMLCSSStyleSheet::GetParentSheet() const
240 : {
241 0 : return nsnull;
242 : }
243 :
244 : /* virtual */ nsIDocument*
245 0 : nsHTMLCSSStyleSheet::GetOwningDocument() const
246 : {
247 0 : return mDocument;
248 : }
249 :
250 : /* virtual */ void
251 1407 : nsHTMLCSSStyleSheet::SetOwningDocument(nsIDocument* aDocument)
252 : {
253 1407 : mDocument = aDocument;
254 1407 : }
255 :
256 : #ifdef DEBUG
257 : /* virtual */ void
258 0 : nsHTMLCSSStyleSheet::List(FILE* out, PRInt32 aIndent) const
259 : {
260 : // Indent
261 0 : for (PRInt32 index = aIndent; --index >= 0; ) fputs(" ", out);
262 :
263 0 : fputs("HTML CSS Style Sheet: ", out);
264 0 : nsCAutoString urlSpec;
265 0 : mURL->GetSpec(urlSpec);
266 0 : if (!urlSpec.IsEmpty()) {
267 0 : fputs(urlSpec.get(), out);
268 : }
269 0 : fputs("\n", out);
270 0 : }
271 : #endif
|