1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim:set tw=80 expandtab softtabstop=2 ts=2 sw=2: */
3 : /* ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is Mozilla Communicator client code.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * Netscape Communications Corporation.
20 : * Portions created by the Initial Developer are Copyright (C) 1998
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : * Daniel Kraft <d@domob.eu>
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either of the GNU General Public License Version 2 or later (the "GPL"),
28 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : /**
41 : * nsStyledElement is the base for elements supporting styling via the
42 : * id/class/style attributes; it is a common base for their support in HTML,
43 : * SVG and MathML.
44 : */
45 :
46 : #ifndef __NS_STYLEDELEMENT_H_
47 : #define __NS_STYLEDELEMENT_H_
48 :
49 : #include "nsString.h"
50 : #include "nsGenericElement.h"
51 :
52 : namespace mozilla {
53 : namespace css {
54 : class StyleRule;
55 : }
56 : }
57 :
58 : typedef nsGenericElement nsStyledElementBase;
59 :
60 : class nsStyledElementNotElementCSSInlineStyle : public nsStyledElementBase
61 1870 : {
62 :
63 : protected:
64 :
65 935 : inline nsStyledElementNotElementCSSInlineStyle(already_AddRefed<nsINodeInfo> aNodeInfo)
66 935 : : nsStyledElementBase(aNodeInfo)
67 935 : {}
68 :
69 : public:
70 : // nsIContent interface methods
71 : virtual nsIAtom* GetClassAttributeName() const;
72 : virtual nsIAtom* GetIDAttributeName() const;
73 : virtual nsIAtom* DoGetID() const;
74 : virtual const nsAttrValue* DoGetClasses() const;
75 :
76 : virtual mozilla::css::StyleRule* GetInlineStyleRule();
77 : NS_IMETHOD SetInlineStyleRule(mozilla::css::StyleRule* aStyleRule, bool aNotify);
78 :
79 : virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
80 : nsIContent* aBindingParent,
81 : bool aCompileEventHandlers);
82 : virtual void UnbindFromTree(bool aDeep, bool aNullParent);
83 :
84 : virtual nsresult UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute,
85 : bool aNotify);
86 : virtual nsresult AfterSetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute,
87 : const nsAttrValue* aValue, bool aNotify);
88 :
89 : nsIDOMCSSStyleDeclaration* GetStyle(nsresult* retval);
90 :
91 : protected:
92 :
93 : /**
94 : * Parse a style attr value into a CSS rulestruct (or, if there is no
95 : * document, leave it as a string) and return as nsAttrValue.
96 : *
97 : * @param aValue the value to parse
98 : * @param aResult the resulting HTMLValue [OUT]
99 : */
100 : void ParseStyleAttribute(const nsAString& aValue,
101 : nsAttrValue& aResult,
102 : bool aForceInDataDoc);
103 :
104 : virtual bool ParseAttribute(PRInt32 aNamespaceID, nsIAtom* aAttribute,
105 : const nsAString& aValue, nsAttrValue& aResult);
106 :
107 : /**
108 : * Create the style struct from the style attr. Used when an element is
109 : * first put into a document. Only has an effect if the old value is a
110 : * string. If aForceInDataDoc is true, will reparse even if we're in a data
111 : * document.
112 : */
113 : nsresult ReparseStyleAttribute(bool aForceInDataDoc);
114 : };
115 :
116 1870 : class nsStyledElement : public nsStyledElementNotElementCSSInlineStyle {
117 : protected:
118 935 : inline nsStyledElement(already_AddRefed<nsINodeInfo> aNodeInfo)
119 935 : : nsStyledElementNotElementCSSInlineStyle(aNodeInfo)
120 935 : {}
121 : };
122 :
123 : #endif // __NS_STYLEDELEMENT_H_
|