dom/html/HTMLMarqueeElement.h
author Emilio Cobos Álvarez <emilio@crisal.io>
Wed, 02 Jan 2019 14:05:23 +0100
changeset 452446 f0a91d36587266d7454a450c6044d573664fbed5
parent 448947 6f3709b3878117466168c40affa7bca0b60cf75b
child 455689 951448bcc1fcebcad89deb2a7d03770a261eb79b
permissions -rw-r--r--
Bug 1517241 - Rename nsIDocument to mozilla::dom::Document. r=smaug Summary: Really sorry for the size of the patch. It's mostly automatic s/nsIDocument/Document/ but I had to fix up in a bunch of places manually to add the right namespacing and such. Overall it's not a very interesting patch I think. nsDocument.cpp turns into Document.cpp, nsIDocument.h into Document.h and nsIDocumentInlines.h into DocumentInlines.h. I also changed a bunch of nsCOMPtr usage to RefPtr, but not all of it. While fixing up some of the bits I also removed some unneeded OwnerDoc() null checks and such, but I didn't do anything riskier than that.

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef HTMLMarqueeElement_h___
#define HTMLMarqueeElement_h___

#include "mozilla/Attributes.h"
#include "nsGenericHTMLElement.h"
#include "nsContentUtils.h"

namespace mozilla {
namespace dom {
class FunctionStringCallback;

class HTMLMarqueeElement final : public nsGenericHTMLElement {
 public:
  explicit HTMLMarqueeElement(already_AddRefed<dom::NodeInfo>&& aNodeInfo)
      : nsGenericHTMLElement(std::move(aNodeInfo)) {}

  // nsISupports
  NS_DECL_ISUPPORTS_INHERITED
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLMarqueeElement,
                                           nsGenericHTMLElement)

  nsresult BindToTree(Document* aDocument, nsIContent* aParent,
                      nsIContent* aBindingParent) override;
  void UnbindFromTree(bool aDeep = true, bool aNullParent = true) override;

  static const int kDefaultLoop = -1;
  static const int kDefaultScrollAmount = 6;
  static const int kDefaultScrollDelayMS = 85;

  bool IsEventAttributeNameInternal(nsAtom* aName) override;

  void SetStartStopCallback(FunctionStringCallback* aCallback);

  void GetBehavior(nsAString& aValue);
  void SetBehavior(const nsAString& aValue, ErrorResult& aError) {
    SetHTMLAttr(nsGkAtoms::behavior, aValue, aError);
  }

  void GetDirection(nsAString& aValue);
  void SetDirection(const nsAString& aValue, ErrorResult& aError) {
    SetHTMLAttr(nsGkAtoms::direction, aValue, aError);
  }

  void GetBgColor(DOMString& aBgColor) {
    GetHTMLAttr(nsGkAtoms::bgcolor, aBgColor);
  }
  void SetBgColor(const nsAString& aBgColor, ErrorResult& aError) {
    SetHTMLAttr(nsGkAtoms::bgcolor, aBgColor, aError);
  }
  void GetHeight(DOMString& aHeight) {
    GetHTMLAttr(nsGkAtoms::height, aHeight);
  }
  void SetHeight(const nsAString& aHeight, ErrorResult& aError) {
    SetHTMLAttr(nsGkAtoms::height, aHeight, aError);
  }
  uint32_t Hspace() { return GetIntAttr(nsGkAtoms::hspace, 0); }
  void SetHspace(uint32_t aValue, ErrorResult& aError) {
    SetUnsignedIntAttr(nsGkAtoms::hspace, aValue, 0, aError);
  }
  int32_t Loop() {
    int loop = GetIntAttr(nsGkAtoms::loop, kDefaultLoop);
    if (loop <= 0) {
      loop = -1;
    }

    return loop;
  }
  void SetLoop(int32_t aValue, ErrorResult& aError) {
    if (aValue == -1 || aValue > 0) {
      SetHTMLIntAttr(nsGkAtoms::loop, aValue, aError);
    }
  }
  uint32_t ScrollAmount() {
    return GetUnsignedIntAttr(nsGkAtoms::scrollamount, kDefaultScrollAmount);
  }
  void SetScrollAmount(uint32_t aValue, ErrorResult& aError) {
    SetUnsignedIntAttr(nsGkAtoms::scrollamount, aValue, kDefaultScrollAmount,
                       aError);
  }
  uint32_t ScrollDelay() {
    return GetUnsignedIntAttr(nsGkAtoms::scrolldelay, kDefaultScrollDelayMS);
  }
  void SetScrollDelay(uint32_t aValue, ErrorResult& aError) {
    SetUnsignedIntAttr(nsGkAtoms::scrolldelay, aValue, kDefaultScrollDelayMS,
                       aError);
  }
  bool TrueSpeed() const { return GetBoolAttr(nsGkAtoms::truespeed); }
  void SetTrueSpeed(bool aValue, ErrorResult& aError) {
    SetHTMLBoolAttr(nsGkAtoms::truespeed, aValue, aError);
  }
  void GetWidth(DOMString& aWidth) { GetHTMLAttr(nsGkAtoms::width, aWidth); }
  void SetWidth(const nsAString& aWidth, ErrorResult& aError) {
    SetHTMLAttr(nsGkAtoms::width, aWidth, aError);
  }
  uint32_t Vspace() { return GetIntAttr(nsGkAtoms::vspace, 0); }
  void SetVspace(uint32_t aValue, ErrorResult& aError) {
    SetUnsignedIntAttr(nsGkAtoms::vspace, aValue, 0, aError);
  }

  void Start();
  void Stop();

  bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
                      const nsAString& aValue,
                      nsIPrincipal* aMaybeScriptedPrincipal,
                      nsAttrValue& aResult) override;
  virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
                                const nsAttrValue* aValue,
                                const nsAttrValue* aOldValue,
                                nsIPrincipal* aMaybeScriptedPrincipal,
                                bool aNotify) override;
  NS_IMETHOD_(bool) IsAttributeMapped(const nsAtom* aAttribute) const override;
  nsMapRuleToAttributesFunc GetAttributeMappingFunction() const override;

  nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;

 protected:
  virtual ~HTMLMarqueeElement();

  JSObject* WrapNode(JSContext* aCx,
                     JS::Handle<JSObject*> aGivenProto) override;

 private:
  RefPtr<FunctionStringCallback> mStartStopCallback;
  static void MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
                                    MappedDeclarations&);

  void DispatchEventToShadowRoot(const nsAString& aEventTypeArg);
};

}  // namespace dom
}  // namespace mozilla

#endif /* HTMLMarqueeElement_h___ */