Bug 460926 A11y hierachy is broken on Ubuntu 8.10 (GNOME 2.24), r=Evan.Yan sr=roc
[wine-gecko.git] / layout / style / nsDOMCSSAttrDeclaration.cpp
blobeafdce511c59abe5f61230649b8f50474e3717b4
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 Communicator client 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):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 /* DOM object for element.style */
40 #include "nsDOMCSSAttrDeclaration.h"
41 #include "nsCSSDeclaration.h"
42 #include "nsIDocument.h"
43 #include "nsIDOMMutationEvent.h"
44 #include "nsICSSStyleRule.h"
45 #include "nsICSSLoader.h"
46 #include "nsICSSParser.h"
47 #include "nsIURI.h"
48 #include "nsINameSpaceManager.h"
49 #include "nsStyleConsts.h"
50 #include "nsContentUtils.h"
51 #include "nsIContent.h"
52 #include "nsIPrincipal.h"
54 nsDOMCSSAttributeDeclaration::nsDOMCSSAttributeDeclaration(nsIContent *aContent)
56 MOZ_COUNT_CTOR(nsDOMCSSAttributeDeclaration);
58 // This reference is not reference-counted. The content
59 // object tells us when its about to go away.
60 NS_ASSERTION(aContent && aContent->IsNodeOfType(nsINode::eELEMENT),
61 "Inline style for non-element content?");
62 mContent = aContent;
65 nsDOMCSSAttributeDeclaration::~nsDOMCSSAttributeDeclaration()
67 MOZ_COUNT_DTOR(nsDOMCSSAttributeDeclaration);
70 NS_IMPL_ADDREF(nsDOMCSSAttributeDeclaration)
71 NS_IMPL_RELEASE(nsDOMCSSAttributeDeclaration)
73 void
74 nsDOMCSSAttributeDeclaration::DropReference()
76 mContent = nsnull;
79 nsresult
80 nsDOMCSSAttributeDeclaration::DeclarationChanged()
82 NS_ASSERTION(mContent, "Must have content node to set the decl!");
83 nsICSSStyleRule* oldRule = mContent->GetInlineStyleRule();
84 NS_ASSERTION(oldRule, "content must have rule");
86 nsCOMPtr<nsICSSStyleRule> newRule = oldRule->DeclarationChanged(PR_FALSE);
87 if (!newRule) {
88 return NS_ERROR_OUT_OF_MEMORY;
91 return mContent->SetInlineStyleRule(newRule, PR_TRUE);
94 nsresult
95 nsDOMCSSAttributeDeclaration::GetCSSDeclaration(nsCSSDeclaration **aDecl,
96 PRBool aAllocate)
98 nsresult result = NS_OK;
100 *aDecl = nsnull;
101 if (mContent) {
102 nsICSSStyleRule* cssRule = mContent->GetInlineStyleRule();
103 if (cssRule) {
104 *aDecl = cssRule->GetDeclaration();
106 else if (aAllocate) {
107 nsCSSDeclaration *decl = new nsCSSDeclaration();
108 if (!decl)
109 return NS_ERROR_OUT_OF_MEMORY;
110 if (!decl->InitializeEmpty()) {
111 decl->RuleAbort();
112 return NS_ERROR_OUT_OF_MEMORY;
115 nsCOMPtr<nsICSSStyleRule> newRule;
116 result = NS_NewCSSStyleRule(getter_AddRefs(newRule), nsnull, decl);
117 if (NS_FAILED(result)) {
118 decl->RuleAbort();
119 return result;
122 result = mContent->SetInlineStyleRule(newRule, PR_FALSE);
123 if (NS_SUCCEEDED(result)) {
124 *aDecl = decl;
129 return result;
133 * This is a utility function. It will only fail if it can't get a
134 * parser. This means it can return NS_OK without aURI or aCSSLoader
135 * being initialized.
137 nsresult
138 nsDOMCSSAttributeDeclaration::GetCSSParsingEnvironment(nsIURI** aSheetURI,
139 nsIURI** aBaseURI,
140 nsIPrincipal** aSheetPrincipal,
141 nsICSSLoader** aCSSLoader,
142 nsICSSParser** aCSSParser)
144 NS_ASSERTION(mContent, "Something is severely broken -- there should be an nsIContent here!");
145 // null out the out params since some of them may not get initialized below
146 *aSheetURI = nsnull;
147 *aBaseURI = nsnull;
148 *aSheetPrincipal = nsnull;
149 *aCSSLoader = nsnull;
150 *aCSSParser = nsnull;
152 nsIDocument* doc = mContent->GetOwnerDoc();
153 if (!doc) {
154 // document has been destroyed
155 return NS_ERROR_NOT_AVAILABLE;
158 nsCOMPtr<nsIURI> baseURI = mContent->GetBaseURI();
159 nsCOMPtr<nsIURI> sheetURI = doc->GetDocumentURI();
161 NS_ADDREF(*aCSSLoader = doc->CSSLoader());
163 nsresult rv = NS_OK;
165 // Note: parsers coming from a CSSLoader for a document already have
166 // the right case-sensitivity, quirkiness, etc.
167 rv = (*aCSSLoader)->GetParserFor(nsnull, aCSSParser);
168 if (NS_FAILED(rv)) {
169 return rv;
172 baseURI.swap(*aBaseURI);
173 sheetURI.swap(*aSheetURI);
174 NS_ADDREF(*aSheetPrincipal = mContent->NodePrincipal());
176 return NS_OK;
179 NS_IMETHODIMP
180 nsDOMCSSAttributeDeclaration::GetParentRule(nsIDOMCSSRule **aParent)
182 NS_ENSURE_ARG_POINTER(aParent);
184 *aParent = nsnull;
185 return NS_OK;