2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2009-08-12 12:55:14 +04:00
|
|
|
|
|
|
|
/*
|
2013-01-15 12:35:59 +04:00
|
|
|
* Implementation of DOMTokenList specified by HTML5.
|
2009-08-12 12:55:14 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef nsDOMTokenList_h___
|
|
|
|
#define nsDOMTokenList_h___
|
|
|
|
|
2012-10-16 15:51:00 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2016-08-27 08:27:14 +03:00
|
|
|
#include "nsContentUtils.h"
|
2012-10-16 15:51:00 +04:00
|
|
|
#include "nsDOMString.h"
|
2016-08-27 08:27:14 +03:00
|
|
|
#include "nsWhitespaceTokenizer.h"
|
2012-10-16 15:51:00 +04:00
|
|
|
#include "nsWrapperCache.h"
|
2013-05-30 07:15:31 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2013-06-15 01:22:17 +04:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
2016-05-05 06:41:24 +03:00
|
|
|
#include "mozilla/dom/DOMTokenListSupportedTokens.h"
|
2009-08-12 12:55:14 +04:00
|
|
|
|
2012-09-06 00:49:53 +04:00
|
|
|
namespace mozilla {
|
|
|
|
class ErrorResult;
|
2017-11-27 11:10:27 +03:00
|
|
|
namespace dom {
|
|
|
|
class DocGroup;
|
|
|
|
} // namespace dom
|
2012-11-15 02:10:07 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2009-08-12 12:55:14 +04:00
|
|
|
class nsAttrValue;
|
2017-10-03 01:05:19 +03:00
|
|
|
class nsAtom;
|
2009-08-12 12:55:14 +04:00
|
|
|
|
2013-01-15 12:35:59 +04:00
|
|
|
// nsISupports must be on the primary inheritance chain
|
2016-02-12 01:50:42 +03:00
|
|
|
|
2013-01-15 12:35:59 +04:00
|
|
|
class nsDOMTokenList : public nsISupports, public nsWrapperCache {
|
2012-11-15 02:10:08 +04:00
|
|
|
protected:
|
2012-11-15 02:10:07 +04:00
|
|
|
typedef mozilla::dom::Element Element;
|
2017-11-27 11:10:27 +03:00
|
|
|
typedef mozilla::dom::DocGroup DocGroup;
|
2016-08-27 08:27:14 +03:00
|
|
|
typedef nsWhitespaceTokenizerTemplate<nsContentUtils::IsHTMLWhitespace>
|
|
|
|
WhitespaceTokenizer;
|
2012-11-15 02:10:07 +04:00
|
|
|
|
2009-08-12 12:55:14 +04:00
|
|
|
public:
|
2011-08-22 13:14:13 +04:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsDOMTokenList)
|
2009-08-12 12:55:14 +04:00
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
nsDOMTokenList(Element* aElement, nsAtom* aAttrAtom,
|
2016-05-05 06:41:24 +03:00
|
|
|
const mozilla::dom::DOMTokenListSupportedTokenArray = nullptr);
|
2009-08-12 12:55:14 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* cx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2011-08-22 13:14:13 +04:00
|
|
|
|
2012-11-15 02:10:07 +04:00
|
|
|
Element* GetParentObject() { return mElement; }
|
2011-08-22 13:14:13 +04:00
|
|
|
|
2017-11-27 11:10:27 +03:00
|
|
|
DocGroup* GetDocGroup() const;
|
|
|
|
|
2016-04-11 18:01:14 +03:00
|
|
|
void RemoveDuplicates(const nsAttrValue* aAttr);
|
2012-09-06 00:49:53 +04:00
|
|
|
uint32_t Length();
|
|
|
|
void Item(uint32_t aIndex, nsAString& aResult) {
|
|
|
|
bool found;
|
|
|
|
IndexedGetter(aIndex, found, aResult);
|
|
|
|
if (!found) {
|
|
|
|
SetDOMStringToNull(aResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aResult);
|
2016-05-05 13:07:22 +03:00
|
|
|
bool Contains(const nsAString& aToken);
|
2012-09-06 00:49:53 +04:00
|
|
|
void Add(const nsAString& aToken, mozilla::ErrorResult& aError);
|
2013-08-28 11:31:13 +04:00
|
|
|
void Add(const nsTArray<nsString>& aTokens, mozilla::ErrorResult& aError);
|
2012-09-06 00:49:53 +04:00
|
|
|
void Remove(const nsAString& aToken, mozilla::ErrorResult& aError);
|
2013-08-28 11:31:13 +04:00
|
|
|
void Remove(const nsTArray<nsString>& aTokens, mozilla::ErrorResult& aError);
|
2018-03-14 23:08:58 +03:00
|
|
|
bool Replace(const nsAString& aToken, const nsAString& aNewToken,
|
2016-04-28 12:20:25 +03:00
|
|
|
mozilla::ErrorResult& aError);
|
2013-06-15 01:22:17 +04:00
|
|
|
bool Toggle(const nsAString& aToken,
|
|
|
|
const mozilla::dom::Optional<bool>& force,
|
|
|
|
mozilla::ErrorResult& aError);
|
2016-05-05 06:41:25 +03:00
|
|
|
bool Supports(const nsAString& aToken, mozilla::ErrorResult& aError);
|
2016-04-28 12:20:25 +03:00
|
|
|
|
2016-02-12 01:50:42 +03:00
|
|
|
void GetValue(nsAString& aResult) { Stringify(aResult); }
|
|
|
|
void SetValue(const nsAString& aValue, mozilla::ErrorResult& rv);
|
2012-09-06 00:49:53 +04:00
|
|
|
void Stringify(nsAString& aResult);
|
|
|
|
|
2012-06-05 03:49:57 +04:00
|
|
|
protected:
|
2012-06-19 06:30:09 +04:00
|
|
|
virtual ~nsDOMTokenList();
|
2012-06-05 03:49:57 +04:00
|
|
|
|
2009-08-12 12:55:14 +04:00
|
|
|
nsresult CheckToken(const nsAString& aStr);
|
2013-08-28 11:31:13 +04:00
|
|
|
nsresult CheckTokens(const nsTArray<nsString>& aStr);
|
2017-10-03 01:05:19 +03:00
|
|
|
void RemoveDuplicatesInternal(nsTArray<RefPtr<nsAtom>>* aArray,
|
2016-04-11 18:01:14 +03:00
|
|
|
uint32_t aStart);
|
2013-08-28 11:31:13 +04:00
|
|
|
void AddInternal(const nsAttrValue* aAttr, const nsTArray<nsString>& aTokens);
|
|
|
|
void RemoveInternal(const nsAttrValue* aAttr,
|
|
|
|
const nsTArray<nsString>& aTokens);
|
2018-03-14 23:08:58 +03:00
|
|
|
bool ReplaceInternal(const nsAttrValue* aAttr, const nsAString& aToken,
|
2016-08-09 08:48:30 +03:00
|
|
|
const nsAString& aNewToken);
|
2012-10-16 15:51:00 +04:00
|
|
|
inline const nsAttrValue* GetParsedAttr();
|
2009-08-12 12:55:14 +04:00
|
|
|
|
2014-03-28 18:36:47 +04:00
|
|
|
nsCOMPtr<Element> mElement;
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> mAttrAtom;
|
2016-05-05 06:41:24 +03:00
|
|
|
const mozilla::dom::DOMTokenListSupportedTokenArray mSupportedTokens;
|
2009-08-12 12:55:14 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsDOMTokenList_h___
|