author Alexis Beingessner <>
Thu, 10 Oct 2019 23:10:28 +0000
changeset 552383 b6d82b1a6b027461055a92f052d6d0511086a5bb
parent 505383 6f3709b3878117466168c40affa7bca0b60cf75b
child 560502 f7c323d26c22ec61e3ea74700aceb87df280e1b2
permissions -rw-r--r--
Bug 1587155 - Block all hardware acceleration for AMD driver r=jrmuizel a=lizzard Driver's Haunted. Differential Revision:

/* -*- 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 */

 * Implementation of DOMTokenList specified by HTML5.

#ifndef nsDOMTokenList_h___
#define nsDOMTokenList_h___

#include "nsCOMPtr.h"
#include "nsContentUtils.h"
#include "nsDOMString.h"
#include "nsWhitespaceTokenizer.h"
#include "nsWrapperCache.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/DOMTokenListSupportedTokens.h"

namespace mozilla {
class ErrorResult;
namespace dom {
class DocGroup;
}  // namespace dom
}  // namespace mozilla

class nsAttrValue;
class nsAtom;

// nsISupports must be on the primary inheritance chain

class nsDOMTokenList : public nsISupports, public nsWrapperCache {
  typedef mozilla::dom::Element Element;
  typedef mozilla::dom::DocGroup DocGroup;
  typedef nsWhitespaceTokenizerTemplate<nsContentUtils::IsHTMLWhitespace>


  nsDOMTokenList(Element* aElement, nsAtom* aAttrAtom,
                 const mozilla::dom::DOMTokenListSupportedTokenArray = nullptr);

  virtual JSObject* WrapObject(JSContext* cx,
                               JS::Handle<JSObject*> aGivenProto) override;

  Element* GetParentObject() { return mElement; }

  DocGroup* GetDocGroup() const;

  void RemoveDuplicates(const nsAttrValue* aAttr);
  uint32_t Length();
  void Item(uint32_t aIndex, nsAString& aResult) {
    bool found;
    IndexedGetter(aIndex, found, aResult);
    if (!found) {
  void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aResult);
  bool Contains(const nsAString& aToken);
  void Add(const nsAString& aToken, mozilla::ErrorResult& aError);
  void Add(const nsTArray<nsString>& aTokens, mozilla::ErrorResult& aError);
  void Remove(const nsAString& aToken, mozilla::ErrorResult& aError);
  void Remove(const nsTArray<nsString>& aTokens, mozilla::ErrorResult& aError);
  bool Replace(const nsAString& aToken, const nsAString& aNewToken,
               mozilla::ErrorResult& aError);
  bool Toggle(const nsAString& aToken,
              const mozilla::dom::Optional<bool>& force,
              mozilla::ErrorResult& aError);
  bool Supports(const nsAString& aToken, mozilla::ErrorResult& aError);

  void GetValue(nsAString& aResult) { Stringify(aResult); }
  void SetValue(const nsAString& aValue, mozilla::ErrorResult& rv);
  void Stringify(nsAString& aResult);

  virtual ~nsDOMTokenList();

  nsresult CheckToken(const nsAString& aStr);
  nsresult CheckTokens(const nsTArray<nsString>& aStr);
  void RemoveDuplicatesInternal(nsTArray<RefPtr<nsAtom>>* aArray,
                                uint32_t aStart);
  void AddInternal(const nsAttrValue* aAttr, const nsTArray<nsString>& aTokens);
  void RemoveInternal(const nsAttrValue* aAttr,
                      const nsTArray<nsString>& aTokens);
  bool ReplaceInternal(const nsAttrValue* aAttr, const nsAString& aToken,
                       const nsAString& aNewToken);
  inline const nsAttrValue* GetParsedAttr();

  nsCOMPtr<Element> mElement;
  RefPtr<nsAtom> mAttrAtom;
  const mozilla::dom::DOMTokenListSupportedTokenArray mSupportedTokens;

#endif  // nsDOMTokenList_h___