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 "mozilla/Attributes.h" 11 #include "mozilla/dom/Element.h" 12 #include "nsMappedAttributeElement.h" 13 #include "Link.h" 14 #include "mozilla/dom/DOMRect.h" 15 16 class nsCSSValue; 17 18 namespace mozilla { 19 class EventChainPostVisitor; 20 class EventChainPreVisitor; 21 namespace dom { 22 23 typedef nsMappedAttributeElement MathMLElementBase; 24 25 /* 26 * The base class for MathML elements. 27 */ 28 class MathMLElement final : public MathMLElementBase, 29 public mozilla::dom::Link { 30 public: 31 explicit MathMLElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo); 32 explicit MathMLElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo); 33 34 // Implementation of nsISupports is inherited from MathMLElementBase 35 NS_DECL_ISUPPORTS_INHERITED 36 37 NS_IMPL_FROMNODE(MathMLElement, kNameSpaceID_MathML) 38 39 nsresult BindToTree(BindContext&, nsINode& aParent) override; 40 virtual void UnbindFromTree(bool aNullParent = true) override; 41 42 virtual bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute, 43 const nsAString& aValue, 44 nsIPrincipal* aMaybeScriptedPrincipal, 45 nsAttrValue& aResult) override; 46 47 NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override; 48 virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() 49 const override; 50 51 enum { 52 PARSE_ALLOW_UNITLESS = 0x01, // unitless 0 will be turned into 0px 53 PARSE_ALLOW_NEGATIVE = 0x02, 54 PARSE_SUPPRESS_WARNINGS = 0x04, 55 CONVERT_UNITLESS_TO_PERCENT = 0x08 56 }; 57 static bool ParseNamedSpaceValue(const nsString& aString, 58 nsCSSValue& aCSSValue, uint32_t aFlags, 59 const Document& aDocument); 60 61 static bool ParseNumericValue(const nsString& aString, nsCSSValue& aCSSValue, 62 uint32_t aFlags, Document* aDocument); 63 64 static void MapMathMLAttributesInto(const nsMappedAttributes* aAttributes, 65 mozilla::MappedDeclarations&); 66 67 void GetEventTargetParent(mozilla::EventChainPreVisitor& aVisitor) override; 68 MOZ_CAN_RUN_SCRIPT 69 nsresult PostHandleEvent(mozilla::EventChainPostVisitor& aVisitor) override; 70 nsresult Clone(mozilla::dom::NodeInfo*, nsINode** aResult) const override; 71 virtual mozilla::EventStates IntrinsicState() const override; 72 virtual bool IsNodeOfType(uint32_t aFlags) const override; 73 74 // Set during reflow as necessary. Does a style change notification, 75 // aNotify must be true. 76 void SetIncrementScriptLevel(bool aIncrementScriptLevel, bool aNotify); GetIncrementScriptLevel()77 bool GetIncrementScriptLevel() const { return mIncrementScriptLevel; } 78 79 int32_t TabIndexDefault() final; 80 virtual bool IsFocusableInternal(int32_t* aTabIndex, 81 bool aWithMouse) override; 82 virtual bool IsLink(nsIURI** aURI) const override; 83 virtual void GetLinkTarget(nsAString& aTarget) override; 84 virtual already_AddRefed<nsIURI> GetHrefURI() const override; 85 NodeInfoChanged(Document * aOldDoc)86 virtual void NodeInfoChanged(Document* aOldDoc) override { 87 ClearHasPendingLinkUpdate(); 88 MathMLElementBase::NodeInfoChanged(aOldDoc); 89 } 90 91 void RecompileScriptEventListeners() final; 92 bool IsEventAttributeNameInternal(nsAtom* aName) final; 93 94 protected: 95 virtual ~MathMLElement() = default; 96 97 virtual JSObject* WrapNode(JSContext* aCx, 98 JS::Handle<JSObject*> aGivenProto) override; 99 100 nsresult BeforeSetAttr(int32_t aNamespaceID, nsAtom* aName, 101 const nsAttrValueOrString* aValue, bool aNotify) final; 102 virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName, 103 const nsAttrValue* aValue, 104 const nsAttrValue* aOldValue, 105 nsIPrincipal* aSubjectPrincipal, 106 bool aNotify) override; 107 108 private: 109 bool mIncrementScriptLevel; 110 }; 111 112 } // namespace dom 113 } // namespace mozilla 114 115 #endif // mozilla_dom_MathMLElement_h_ 116