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"
|
|
|
|
#include "nsDOMString.h"
|
|
|
|
#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"
|
2009-08-12 12:55:14 +04:00
|
|
|
|
2012-09-06 00:49:53 +04:00
|
|
|
namespace mozilla {
|
|
|
|
class ErrorResult;
|
2012-11-15 02:10:07 +04:00
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2009-08-12 12:55:14 +04:00
|
|
|
class nsAttrValue;
|
2012-10-16 15:51:00 +04:00
|
|
|
class nsIAtom;
|
2009-08-12 12:55:14 +04:00
|
|
|
|
2013-01-15 12:35:59 +04:00
|
|
|
// nsISupports must be on the primary inheritance chain
|
2012-11-15 02:10:07 +04:00
|
|
|
// because nsDOMSettableTokenList is traversed by Element.
|
2013-01-15 12:35:59 +04:00
|
|
|
class nsDOMTokenList : public nsISupports,
|
2011-08-22 13:14:13 +04:00
|
|
|
public nsWrapperCache
|
2009-08-12 12:55:14 +04:00
|
|
|
{
|
2012-11-15 02:10:08 +04:00
|
|
|
protected:
|
2012-11-15 02:10:07 +04:00
|
|
|
typedef mozilla::dom::Element Element;
|
|
|
|
|
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
|
|
|
|
2012-11-15 02:10:07 +04:00
|
|
|
nsDOMTokenList(Element* aElement, nsIAtom* aAttrAtom);
|
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()
|
2011-08-22 13:14:13 +04:00
|
|
|
{
|
|
|
|
return mElement;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
bool Contains(const nsAString& aToken, mozilla::ErrorResult& aError);
|
|
|
|
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);
|
2013-06-15 01:22:17 +04:00
|
|
|
bool Toggle(const nsAString& aToken,
|
|
|
|
const mozilla::dom::Optional<bool>& force,
|
|
|
|
mozilla::ErrorResult& aError);
|
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);
|
|
|
|
void AddInternal(const nsAttrValue* aAttr,
|
|
|
|
const nsTArray<nsString>& aTokens);
|
|
|
|
void RemoveInternal(const nsAttrValue* aAttr,
|
|
|
|
const nsTArray<nsString>& aTokens);
|
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;
|
2009-08-12 12:55:14 +04:00
|
|
|
nsCOMPtr<nsIAtom> mAttrAtom;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsDOMTokenList_h___
|