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 Communicator client 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 : *
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.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : /* base class for DOM objects for element.style and cssStyleRule.style */
39 :
40 : #ifndef nsDOMCSSDeclaration_h___
41 : #define nsDOMCSSDeclaration_h___
42 :
43 : #include "nsICSSDeclaration.h"
44 : #include "nsIDOMCSS2Properties.h"
45 : #include "nsCOMPtr.h"
46 :
47 : class nsCSSParser;
48 : class nsIURI;
49 : class nsIPrincipal;
50 : class nsIDocument;
51 :
52 : namespace mozilla {
53 : namespace css {
54 : class Declaration;
55 : class Loader;
56 : class Rule;
57 : }
58 : }
59 :
60 : class nsDOMCSSDeclaration : public nsICSSDeclaration,
61 : public nsIDOMCSS2Properties
62 0 : {
63 : public:
64 : // Only implement QueryInterface; subclasses have the responsibility
65 : // of implementing AddRef/Release.
66 : NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
67 :
68 : NS_DECL_NSICSSDECLARATION
69 :
70 : // Require subclasses to implement |GetParentRule|.
71 : //NS_DECL_NSIDOMCSSSTYLEDECLARATION
72 : NS_IMETHOD GetCssText(nsAString & aCssText);
73 : NS_IMETHOD SetCssText(const nsAString & aCssText);
74 : NS_IMETHOD GetPropertyValue(const nsAString & propertyName,
75 : nsAString & _retval);
76 : NS_IMETHOD GetPropertyCSSValue(const nsAString & propertyName,
77 : nsIDOMCSSValue **_retval);
78 : NS_IMETHOD RemoveProperty(const nsAString & propertyName,
79 : nsAString & _retval);
80 : NS_IMETHOD GetPropertyPriority(const nsAString & propertyName,
81 : nsAString & _retval);
82 : NS_IMETHOD SetProperty(const nsAString & propertyName,
83 : const nsAString & value, const nsAString & priority);
84 : NS_IMETHOD GetLength(PRUint32 *aLength);
85 : NS_IMETHOD Item(PRUint32 index, nsAString & _retval);
86 : NS_IMETHOD GetParentRule(nsIDOMCSSRule * *aParentRule) = 0;
87 :
88 : // We implement this as a shim which forwards to GetPropertyValue
89 : // and SetPropertyValue; subclasses need not.
90 : NS_DECL_NSIDOMCSS2PROPERTIES
91 :
92 : protected:
93 : // This method can return null regardless of the value of aAllocate;
94 : // however, a null return should only be considered a failure
95 : // if aAllocate is true.
96 : virtual mozilla::css::Declaration* GetCSSDeclaration(bool aAllocate) = 0;
97 : virtual nsresult SetCSSDeclaration(mozilla::css::Declaration* aDecl) = 0;
98 : // Document that we must call BeginUpdate/EndUpdate on around the
99 : // calls to SetCSSDeclaration and the style rule mutation that leads
100 : // to it.
101 : virtual nsIDocument* DocToUpdate() = 0;
102 :
103 : // Information neded to parse a declaration. We need the mSheetURI
104 : // for error reporting, mBaseURI to resolve relative URIs,
105 : // mPrincipal for subresource loads, and mCSSLoader for determining
106 : // whether we're in quirks mode. mBaseURI needs to be a strong
107 : // pointer because of xml:base possibly creating base URIs on the
108 : // fly. This is why we don't use CSSParsingEnvironment as a return
109 : // value, to avoid multiple-refcounting of mBaseURI.
110 0 : struct CSSParsingEnvironment {
111 : nsIURI* mSheetURI;
112 : nsCOMPtr<nsIURI> mBaseURI;
113 : nsIPrincipal* mPrincipal;
114 : mozilla::css::Loader* mCSSLoader;
115 : };
116 :
117 : // On failure, mPrincipal should be set to null in aCSSParseEnv.
118 : // If mPrincipal is null, the other members may not be set to
119 : // anything meaningful.
120 : virtual void GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv) = 0;
121 :
122 : // An implementation for GetCSSParsingEnvironment for callers wrapping
123 : // an css::Rule.
124 : static void GetCSSParsingEnvironmentForRule(mozilla::css::Rule* aRule,
125 : CSSParsingEnvironment& aCSSParseEnv);
126 :
127 : nsresult ParsePropertyValue(const nsCSSProperty aPropID,
128 : const nsAString& aPropValue,
129 : bool aIsImportant);
130 :
131 : // Prop-id based version of RemoveProperty. Note that this does not
132 : // return the old value; it just does a straight removal.
133 : nsresult RemoveProperty(const nsCSSProperty aPropID);
134 :
135 : protected:
136 : virtual ~nsDOMCSSDeclaration();
137 : };
138 :
139 : #endif // nsDOMCSSDeclaration_h___
|