tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

nsDOMTokenList.h (3399B)


      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 /*
      8 * Implementation of DOMTokenList specified by HTML5.
      9 */
     10 
     11 #ifndef nsDOMTokenList_h___
     12 #define nsDOMTokenList_h___
     13 
     14 #include "mozilla/dom/BindingDeclarations.h"
     15 #include "mozilla/dom/DOMTokenListSupportedTokens.h"
     16 #include "nsCOMPtr.h"
     17 #include "nsContentUtils.h"
     18 #include "nsDOMString.h"
     19 #include "nsWhitespaceTokenizer.h"
     20 #include "nsWrapperCache.h"
     21 
     22 namespace mozilla {
     23 class ErrorResult;
     24 namespace dom {
     25 class DocGroup;
     26 class Element;
     27 }  // namespace dom
     28 }  // namespace mozilla
     29 
     30 class nsAttrValue;
     31 class nsAtom;
     32 
     33 // nsISupports must be on the primary inheritance chain
     34 
     35 class nsDOMTokenList : public nsISupports, public nsWrapperCache {
     36 protected:
     37  using Element = mozilla::dom::Element;
     38  using DocGroup = mozilla::dom::DocGroup;
     39  using WhitespaceTokenizer =
     40      nsWhitespaceTokenizerTemplate<nsContentUtils::IsHTMLWhitespace>;
     41 
     42 public:
     43  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     44  NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(nsDOMTokenList)
     45 
     46  nsDOMTokenList(Element* aElement, nsAtom* aAttrAtom,
     47                 const mozilla::dom::DOMTokenListSupportedTokenArray = nullptr);
     48 
     49  virtual JSObject* WrapObject(JSContext* cx,
     50                               JS::Handle<JSObject*> aGivenProto) override;
     51 
     52  Element* GetParentObject() { return mElement; }
     53 
     54  DocGroup* GetDocGroup() const;
     55 
     56  uint32_t Length();
     57  void Item(uint32_t aIndex, nsAString& aResult) {
     58    bool found;
     59    IndexedGetter(aIndex, found, aResult);
     60    if (!found) {
     61      SetDOMStringToNull(aResult);
     62    }
     63  }
     64  void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aResult);
     65  bool Contains(const nsAString& aToken);
     66  void Add(const nsAString& aToken, mozilla::ErrorResult& aError);
     67  void Add(const nsTArray<nsString>& aTokens, mozilla::ErrorResult& aError);
     68  void Remove(const nsAString& aToken, mozilla::ErrorResult& aError);
     69  void Remove(const nsTArray<nsString>& aTokens, mozilla::ErrorResult& aError);
     70  bool Replace(const nsAString& aToken, const nsAString& aNewToken,
     71               mozilla::ErrorResult& aError);
     72  bool Toggle(const nsAString& aToken,
     73              const mozilla::dom::Optional<bool>& force,
     74              mozilla::ErrorResult& aError);
     75  bool Supports(const nsAString& aToken, mozilla::ErrorResult& aError);
     76 
     77  void GetValue(nsAString& aResult);
     78  void SetValue(const nsAString& aValue, mozilla::ErrorResult& rv);
     79 
     80 protected:
     81  virtual ~nsDOMTokenList();
     82 
     83  void CheckToken(const nsAString& aToken, mozilla::ErrorResult& aRv);
     84  void CheckTokens(const nsTArray<nsString>& aTokens,
     85                   mozilla::ErrorResult& aRv);
     86  void AddInternal(const nsAttrValue* aAttr, const nsTArray<nsString>& aTokens);
     87  void RemoveInternal(const nsAttrValue* aAttr,
     88                      const nsTArray<nsString>& aTokens);
     89  bool ReplaceInternal(const nsAttrValue* aAttr, const nsAString& aToken,
     90                       const nsAString& aNewToken);
     91  inline const nsAttrValue* GetParsedAttr();
     92 
     93  nsCOMPtr<Element> mElement;
     94  RefPtr<nsAtom> mAttrAtom;
     95  const mozilla::dom::DOMTokenListSupportedTokenArray mSupportedTokens;
     96 };
     97 
     98 #endif  // nsDOMTokenList_h___