HTMLMarqueeElement.h (4283B)
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 #ifndef HTMLMarqueeElement_h___ 7 #define HTMLMarqueeElement_h___ 8 9 #include "nsContentUtils.h" 10 #include "nsGenericHTMLElement.h" 11 12 namespace mozilla::dom { 13 class HTMLMarqueeElement final : public nsGenericHTMLElement { 14 public: 15 explicit HTMLMarqueeElement(already_AddRefed<dom::NodeInfo>&& aNodeInfo) 16 : nsGenericHTMLElement(std::move(aNodeInfo)) {} 17 18 NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLMarqueeElement, marquee); 19 20 nsresult BindToTree(BindContext&, nsINode& aParent) override; 21 void UnbindFromTree(UnbindContext&) override; 22 23 static const int kDefaultLoop = -1; 24 static const int kDefaultScrollAmount = 6; 25 static const int kDefaultScrollDelayMS = 85; 26 27 void GetBehavior(nsAString& aValue); 28 void SetBehavior(const nsAString& aValue, ErrorResult& aError) { 29 SetHTMLAttr(nsGkAtoms::behavior, aValue, aError); 30 } 31 32 void GetDirection(nsAString& aValue); 33 void SetDirection(const nsAString& aValue, ErrorResult& aError) { 34 SetHTMLAttr(nsGkAtoms::direction, aValue, aError); 35 } 36 37 void GetBgColor(DOMString& aBgColor) { 38 GetHTMLAttr(nsGkAtoms::bgcolor, aBgColor); 39 } 40 void SetBgColor(const nsAString& aBgColor, ErrorResult& aError) { 41 SetHTMLAttr(nsGkAtoms::bgcolor, aBgColor, aError); 42 } 43 void GetHeight(DOMString& aHeight) { 44 GetHTMLAttr(nsGkAtoms::height, aHeight); 45 } 46 void SetHeight(const nsAString& aHeight, ErrorResult& aError) { 47 SetHTMLAttr(nsGkAtoms::height, aHeight, aError); 48 } 49 uint32_t Hspace() { 50 return GetDimensionAttrAsUnsignedInt(nsGkAtoms::hspace, 0); 51 } 52 void SetHspace(uint32_t aValue, ErrorResult& aError) { 53 SetUnsignedIntAttr(nsGkAtoms::hspace, aValue, 0, aError); 54 } 55 int32_t Loop() { 56 int loop = GetIntAttr(nsGkAtoms::loop, kDefaultLoop); 57 if (loop <= 0) { 58 loop = -1; 59 } 60 61 return loop; 62 } 63 void SetLoop(int32_t aValue, ErrorResult& aError) { 64 if (aValue == -1 || aValue > 0) { 65 SetHTMLIntAttr(nsGkAtoms::loop, aValue, aError); 66 } 67 } 68 uint32_t ScrollAmount() { 69 return GetUnsignedIntAttr(nsGkAtoms::scrollamount, kDefaultScrollAmount); 70 } 71 void SetScrollAmount(uint32_t aValue, ErrorResult& aError) { 72 SetUnsignedIntAttr(nsGkAtoms::scrollamount, aValue, kDefaultScrollAmount, 73 aError); 74 } 75 uint32_t ScrollDelay() { 76 return GetUnsignedIntAttr(nsGkAtoms::scrolldelay, kDefaultScrollDelayMS); 77 } 78 void SetScrollDelay(uint32_t aValue, ErrorResult& aError) { 79 SetUnsignedIntAttr(nsGkAtoms::scrolldelay, aValue, kDefaultScrollDelayMS, 80 aError); 81 } 82 bool TrueSpeed() const { return GetBoolAttr(nsGkAtoms::truespeed); } 83 void SetTrueSpeed(bool aValue, ErrorResult& aError) { 84 SetHTMLBoolAttr(nsGkAtoms::truespeed, aValue, aError); 85 } 86 void GetWidth(DOMString& aWidth) { GetHTMLAttr(nsGkAtoms::width, aWidth); } 87 void SetWidth(const nsAString& aWidth, ErrorResult& aError) { 88 SetHTMLAttr(nsGkAtoms::width, aWidth, aError); 89 } 90 uint32_t Vspace() { 91 return GetDimensionAttrAsUnsignedInt(nsGkAtoms::vspace, 0); 92 } 93 void SetVspace(uint32_t aValue, ErrorResult& aError) { 94 SetUnsignedIntAttr(nsGkAtoms::vspace, aValue, 0, aError); 95 } 96 97 void Start(); 98 void Stop(); 99 100 bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute, 101 const nsAString& aValue, 102 nsIPrincipal* aMaybeScriptedPrincipal, 103 nsAttrValue& aResult) override; 104 NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override; 105 nsMapRuleToAttributesFunc GetAttributeMappingFunction() const override; 106 107 nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override; 108 109 protected: 110 virtual ~HTMLMarqueeElement(); 111 112 JSObject* WrapNode(JSContext* aCx, 113 JS::Handle<JSObject*> aGivenProto) override; 114 115 private: 116 static void MapAttributesIntoRule(MappedDeclarationsBuilder&); 117 118 void DispatchEventToShadowRoot(const nsAString& aEventTypeArg); 119 }; 120 121 } // namespace mozilla::dom 122 123 #endif /* HTMLMarqueeElement_h___ */