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
;
53 virtual nsresult
BindToTree(BindContext
& aContext
, nsINode
& aParent
) override
;
55 nsICSSDeclaration
* Style();
57 NS_DECLARE_STATIC_IID_ACCESSOR(NS_STYLED_ELEMENT_IID
)
58 NS_IMPL_FROMNODE_HELPER(nsStyledElement
, IsStyledElement());
60 bool IsStyledElement() const final
{ return true; }
63 nsICSSDeclaration
* GetExistingStyle();
66 * Parse a style attr value into a CSS rulestruct (or, if there is no
67 * document, leave it as a string) and return as nsAttrValue.
69 * @param aValue the value to parse
70 * @param aMaybeScriptedPrincipal if available, the scripted principal
71 * responsible for this attribute value, as passed to
72 * Element::ParseAttribute.
73 * @param aResult the resulting HTMLValue [OUT]
75 void ParseStyleAttribute(const nsAString
& aValue
,
76 nsIPrincipal
* aMaybeScriptedPrincipal
,
77 nsAttrValue
& aResult
, bool aForceInDataDoc
);
79 bool ParseAttribute(int32_t aNamespaceID
, nsAtom
* aAttribute
,
80 const nsAString
& aValue
,
81 nsIPrincipal
* aMaybeScriptedPrincipal
,
82 nsAttrValue
& aResult
) override
;
84 friend class mozilla::dom::Element
;
87 * Create the style struct from the style attr. Used when an element is
88 * first put into a document. Only has an effect if the old value is a
89 * string. If aForceInDataDoc is true, will reparse even if we're in a data
92 nsresult
ReparseStyleAttribute(bool aForceInDataDoc
);
94 void BeforeSetAttr(int32_t aNamespaceID
, nsAtom
* aName
,
95 const nsAttrValue
* aValue
, bool aNotify
) override
;
98 NS_DEFINE_STATIC_IID_ACCESSOR(nsStyledElement
, NS_STYLED_ELEMENT_IID
)
99 #endif // __NS_STYLEDELEMENT_H_