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/. */
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,
13 #ifndef __NS_STYLEDELEMENT_H_
14 #define __NS_STYLEDELEMENT_H_
16 #include "mozilla/Attributes.h"
17 #include "mozilla/dom/Element.h"
21 class DeclarationBlock
;
22 struct MutationClosureData
;
23 } // namespace mozilla
25 // IID for nsStyledElement interface
26 #define NS_STYLED_ELEMENT_IID \
28 0xacbd9ea6, 0x15aa, 0x4f37, { \
29 0x8c, 0xe0, 0x35, 0x1e, 0xd7, 0x21, 0xca, 0xe9 \
33 using nsStyledElementBase
= mozilla::dom::Element
;
35 class nsStyledElement
: public nsStyledElementBase
{
37 inline explicit nsStyledElement(
38 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
)
39 : nsStyledElementBase(std::move(aNodeInfo
)) {}
42 // We don't want to implement AddRef/Release because that would add an extra
43 // function call for those on pretty much all elements. But we do need QI, so
44 // we can QI to nsStyledElement.
45 NS_IMETHOD
QueryInterface(REFNSIID aIID
, void** aInstancePtr
) override
;
47 // Element interface methods
48 virtual void InlineStyleDeclarationWillChange(
49 mozilla::MutationClosureData
& aData
) override
;
50 virtual nsresult
SetInlineStyleDeclaration(
51 mozilla::DeclarationBlock
& aDeclaration
,
52 mozilla::MutationClosureData
& aData
) override
;
54 nsICSSDeclaration
* Style();
56 NS_DECLARE_STATIC_IID_ACCESSOR(NS_STYLED_ELEMENT_IID
)
57 NS_IMPL_FROMNODE_HELPER(nsStyledElement
, IsStyledElement());
59 bool IsStyledElement() const final
{ return true; }
62 nsICSSDeclaration
* GetExistingStyle();
65 * Parse a style attr value into a CSS rulestruct (or, if there is no
66 * document, leave it as a string) and return as nsAttrValue.
68 * @param aValue the value to parse
69 * @param aMaybeScriptedPrincipal if available, the scripted principal
70 * responsible for this attribute value, as passed to
71 * Element::ParseAttribute.
72 * @param aResult the resulting HTMLValue [OUT]
74 void ParseStyleAttribute(const nsAString
& aValue
,
75 nsIPrincipal
* aMaybeScriptedPrincipal
,
76 nsAttrValue
& aResult
, bool aForceInDataDoc
);
78 virtual bool ParseAttribute(int32_t aNamespaceID
, nsAtom
* aAttribute
,
79 const nsAString
& aValue
,
80 nsIPrincipal
* aMaybeScriptedPrincipal
,
81 nsAttrValue
& aResult
) override
;
83 friend class mozilla::dom::Element
;
86 * Create the style struct from the style attr. Used when an element is
87 * first put into a document. Only has an effect if the old value is a
88 * string. If aForceInDataDoc is true, will reparse even if we're in a data
91 nsresult
ReparseStyleAttribute(bool aForceInDataDoc
);
93 virtual nsresult
BeforeSetAttr(int32_t aNamespaceID
, nsAtom
* aName
,
94 const nsAttrValueOrString
* aValue
,
95 bool aNotify
) override
;
98 NS_DEFINE_STATIC_IID_ACCESSOR(nsStyledElement
, NS_STYLED_ELEMENT_IID
)
99 #endif // __NS_STYLEDELEMENT_H_