/src/mozilla-central/dom/base/nsStyledElement.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | /** |
8 | | * nsStyledElement is the base for elements supporting styling via the |
9 | | * id/class/style attributes; it is a common base for their support in HTML, |
10 | | * SVG and MathML. |
11 | | */ |
12 | | |
13 | | #ifndef __NS_STYLEDELEMENT_H_ |
14 | | #define __NS_STYLEDELEMENT_H_ |
15 | | |
16 | | #include "mozilla/Attributes.h" |
17 | | #include "nsString.h" |
18 | | #include "mozilla/dom/Element.h" |
19 | | |
20 | | namespace mozilla { |
21 | | class DeclarationBlock; |
22 | | } // namespace mozilla |
23 | | |
24 | | // IID for nsStyledElement interface |
25 | | #define NS_STYLED_ELEMENT_IID \ |
26 | | { 0xacbd9ea6, 0x15aa, 0x4f37, \ |
27 | | { 0x8c, 0xe0, 0x35, 0x1e, 0xd7, 0x21, 0xca, 0xe9 } } |
28 | | |
29 | | typedef mozilla::dom::Element nsStyledElementBase; |
30 | | |
31 | | class nsStyledElement : public nsStyledElementBase |
32 | | { |
33 | | |
34 | | protected: |
35 | | |
36 | | inline explicit nsStyledElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo) |
37 | | : nsStyledElementBase(std::move(aNodeInfo)) |
38 | 0 | {} |
39 | | |
40 | | public: |
41 | | // We don't want to implement AddRef/Release because that would add an extra |
42 | | // function call for those on pretty much all elements. But we do need QI, so |
43 | | // we can QI to nsStyledElement. |
44 | | NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override; |
45 | | |
46 | | // Element interface methods |
47 | | virtual void |
48 | | InlineStyleDeclarationWillChange(mozilla::MutationClosureData& aData) override; |
49 | | virtual nsresult |
50 | | SetInlineStyleDeclaration(mozilla::DeclarationBlock& aDeclaration, |
51 | | mozilla::MutationClosureData& aData) override; |
52 | | |
53 | | nsICSSDeclaration* Style(); |
54 | | |
55 | | NS_DECLARE_STATIC_IID_ACCESSOR(NS_STYLED_ELEMENT_IID) |
56 | | |
57 | | protected: |
58 | | |
59 | | nsICSSDeclaration* GetExistingStyle(); |
60 | | |
61 | | /** |
62 | | * Parse a style attr value into a CSS rulestruct (or, if there is no |
63 | | * document, leave it as a string) and return as nsAttrValue. |
64 | | * |
65 | | * @param aValue the value to parse |
66 | | * @param aMaybeScriptedPrincipal if available, the scripted principal |
67 | | * responsible for this attribute value, as passed to |
68 | | * Element::ParseAttribute. |
69 | | * @param aResult the resulting HTMLValue [OUT] |
70 | | */ |
71 | | void ParseStyleAttribute(const nsAString& aValue, |
72 | | nsIPrincipal* aMaybeScriptedPrincipal, |
73 | | nsAttrValue& aResult, |
74 | | bool aForceInDataDoc); |
75 | | |
76 | | virtual bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute, |
77 | | const nsAString& aValue, |
78 | | nsIPrincipal* aMaybeScriptedPrincipal, |
79 | | nsAttrValue& aResult) override; |
80 | | |
81 | | friend class mozilla::dom::Element; |
82 | | |
83 | | /** |
84 | | * Create the style struct from the style attr. Used when an element is |
85 | | * first put into a document. Only has an effect if the old value is a |
86 | | * string. If aForceInDataDoc is true, will reparse even if we're in a data |
87 | | * document. If aForceIfAlreadyParsed is set, this will always reparse even |
88 | | * if the value has already been parsed. |
89 | | */ |
90 | | nsresult ReparseStyleAttribute(bool aForceInDataDoc, bool aForceIfAlreadyParsed); |
91 | | |
92 | | virtual void NodeInfoChanged(nsIDocument* aOldDoc) override; |
93 | | |
94 | | virtual nsresult BeforeSetAttr(int32_t aNamespaceID, nsAtom* aName, |
95 | | const nsAttrValueOrString* aValue, |
96 | | bool aNotify) override; |
97 | | }; |
98 | | |
99 | | NS_DEFINE_STATIC_IID_ACCESSOR(nsStyledElement, NS_STYLED_ELEMENT_IID) |
100 | | #endif // __NS_STYLEDELEMENT_H_ |