nsStyledElement.h (3482B)
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/dom/Element.h" 17 #include "nsString.h" 18 19 namespace mozilla { 20 class DeclarationBlock; 21 struct MutationClosureData; 22 23 namespace dom { 24 class StylePropertyMap; 25 } 26 } // namespace mozilla 27 28 // IID for nsStyledElement interface 29 #define NS_STYLED_ELEMENT_IID \ 30 {0xacbd9ea6, 0x15aa, 0x4f37, {0x8c, 0xe0, 0x35, 0x1e, 0xd7, 0x21, 0xca, 0xe9}} 31 32 using nsStyledElementBase = mozilla::dom::Element; 33 34 class nsStyledElement : public nsStyledElementBase { 35 protected: 36 inline explicit nsStyledElement( 37 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo) 38 : nsStyledElementBase(std::move(aNodeInfo)) {} 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 InlineStyleDeclarationWillChange( 48 mozilla::MutationClosureData& aData) override; 49 virtual nsresult SetInlineStyleDeclaration( 50 mozilla::DeclarationBlock& aDeclaration, 51 mozilla::MutationClosureData& aData) override; 52 virtual nsresult BindToTree(BindContext& aContext, nsINode& aParent) override; 53 54 nsDOMCSSDeclaration* Style(); 55 56 mozilla::dom::StylePropertyMap* AttributeStyleMap(); 57 58 NS_INLINE_DECL_STATIC_IID(NS_STYLED_ELEMENT_IID) 59 NS_IMPL_FROMNODE_HELPER(nsStyledElement, IsStyledElement()); 60 61 bool IsStyledElement() const final { return true; } 62 63 protected: 64 nsDOMCSSDeclaration* GetExistingStyle(); 65 66 /** 67 * Parse a style attr value into a CSS rulestruct (or, if there is no 68 * document, leave it as a string) and return as nsAttrValue. 69 * 70 * @param aValue the value to parse 71 * @param aMaybeScriptedPrincipal if available, the scripted principal 72 * responsible for this attribute value, as passed to 73 * Element::ParseAttribute. 74 * @param aResult the resulting HTMLValue [OUT] 75 */ 76 void ParseStyleAttribute(const nsAString& aValue, 77 nsIPrincipal* aMaybeScriptedPrincipal, 78 nsAttrValue& aResult, bool aForceInDataDoc); 79 80 bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute, 81 const nsAString& aValue, 82 nsIPrincipal* aMaybeScriptedPrincipal, 83 nsAttrValue& aResult) override; 84 85 friend class mozilla::dom::Element; 86 87 /** 88 * Create the style struct from the style attr. Used when an element is 89 * first put into a document. Only has an effect if the old value is a 90 * string. If aForceInDataDoc is true, will reparse even if we're in a data 91 * document. 92 */ 93 nsresult ReparseStyleAttribute(bool aForceInDataDoc); 94 95 void BeforeSetAttr(int32_t aNamespaceID, nsAtom* aName, 96 const nsAttrValue* aValue, bool aNotify) override; 97 }; 98 99 #endif // __NS_STYLEDELEMENT_H_