MathMLElement.h (3979B)
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 #ifndef mozilla_dom_MathMLElement_h_ 8 #define mozilla_dom_MathMLElement_h_ 9 10 #include "Link.h" 11 #include "mozilla/Attributes.h" 12 #include "nsStyledElement.h" 13 14 class nsCSSValue; 15 16 namespace mozilla { 17 class EventChainPostVisitor; 18 class EventChainPreVisitor; 19 namespace dom { 20 21 using MathMLElementBase = nsStyledElement; 22 23 /* 24 * The base class for MathML elements. 25 */ 26 class MathMLElement final : public MathMLElementBase, public Link { 27 public: 28 explicit MathMLElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo); 29 explicit MathMLElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo); 30 31 // Implementation of nsISupports is inherited from MathMLElementBase 32 NS_DECL_ISUPPORTS_INHERITED 33 34 NS_IMPL_FROMNODE(MathMLElement, kNameSpaceID_MathML) 35 36 nsresult BindToTree(BindContext&, nsINode& aParent) override; 37 void UnbindFromTree(UnbindContext&) override; 38 39 bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute, 40 const nsAString& aValue, 41 nsIPrincipal* aMaybeScriptedPrincipal, 42 nsAttrValue& aResult) override; 43 44 NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override; 45 nsMapRuleToAttributesFunc GetAttributeMappingFunction() const override; 46 47 enum { 48 PARSE_ALLOW_NEGATIVE = 0x02, 49 PARSE_SUPPRESS_WARNINGS = 0x04, 50 }; 51 static bool ParseNamedSpaceValue(const nsString& aString, 52 nsCSSValue& aCSSValue, uint32_t aFlags, 53 const Document& aDocument); 54 55 static bool ParseNumericValue(const nsString& aString, nsCSSValue& aCSSValue, 56 uint32_t aFlags, Document* aDocument); 57 58 static void MapGlobalMathMLAttributesInto( 59 mozilla::MappedDeclarationsBuilder&); 60 static void MapMiAttributesInto(mozilla::MappedDeclarationsBuilder&); 61 static void MapMTableAttributesInto(mozilla::MappedDeclarationsBuilder&); 62 63 void GetEventTargetParent(mozilla::EventChainPreVisitor& aVisitor) override; 64 MOZ_CAN_RUN_SCRIPT 65 nsresult PostHandleEvent(mozilla::EventChainPostVisitor& aVisitor) override; 66 nsresult Clone(mozilla::dom::NodeInfo*, nsINode** aResult) const override; 67 68 // Set during reflow as necessary. Does a style change notification, 69 // aNotify must be true. 70 void SetIncrementScriptLevel(bool aIncrementScriptLevel, bool aNotify); 71 bool GetIncrementScriptLevel() const { 72 return Element::State().HasState(ElementState::INCREMENT_SCRIPT_LEVEL); 73 } 74 75 int32_t TabIndexDefault() final; 76 77 Focusable IsFocusableWithoutStyle(IsFocusableFlags) override; 78 already_AddRefed<nsIURI> GetHrefURI() const override; 79 80 void NodeInfoChanged(Document* aOldDoc) override { 81 ClearHasPendingLinkUpdate(); 82 MathMLElementBase::NodeInfoChanged(aOldDoc); 83 } 84 85 bool IsEventAttributeNameInternal(nsAtom* aName) final; 86 87 bool Autofocus() const { return GetBoolAttr(nsGkAtoms::autofocus); } 88 void SetAutofocus(bool aAutofocus, ErrorResult& aRv) { 89 if (aAutofocus) { 90 SetAttr(nsGkAtoms::autofocus, u""_ns, aRv); 91 } else { 92 UnsetAttr(nsGkAtoms::autofocus, aRv); 93 } 94 } 95 96 protected: 97 virtual ~MathMLElement() = default; 98 99 JSObject* WrapNode(JSContext*, JS::Handle<JSObject*> aGivenProto) override; 100 101 void BeforeSetAttr(int32_t aNamespaceID, nsAtom* aName, 102 const nsAttrValue* aValue, bool aNotify) final; 103 void AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName, 104 const nsAttrValue* aValue, const nsAttrValue* aOldValue, 105 nsIPrincipal* aSubjectPrincipal, bool aNotify) override; 106 }; 107 108 } // namespace dom 109 } // namespace mozilla 110 111 #endif // mozilla_dom_MathMLElement_h_