2015-05-03 12:32:37 -07: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 04:12:37 -07: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 01:55:14 -07:00
|
|
|
|
|
|
|
/*
|
2013-01-15 00:35:59 -08:00
|
|
|
* Implementation of DOMTokenList specified by HTML5.
|
2009-08-12 01:55:14 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef nsDOMTokenList_h___
|
|
|
|
#define nsDOMTokenList_h___
|
|
|
|
|
2012-10-16 04:51:00 -07:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsDOMString.h"
|
|
|
|
#include "nsWrapperCache.h"
|
2013-05-29 20:15:31 -07:00
|
|
|
#include "mozilla/dom/Element.h"
|
2013-06-14 14:22:17 -07:00
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
2009-08-12 01:55:14 -07:00
|
|
|
|
2012-09-05 13:49:53 -07:00
|
|
|
namespace mozilla {
|
|
|
|
class ErrorResult;
|
2012-11-14 14:10:07 -08:00
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2009-08-12 01:55:14 -07:00
|
|
|
class nsAttrValue;
|
2012-10-16 04:51:00 -07:00
|
|
|
class nsIAtom;
|
2009-08-12 01:55:14 -07:00
|
|
|
|
2013-01-15 00:35:59 -08:00
|
|
|
// nsISupports must be on the primary inheritance chain
|
2016-02-11 14:50:42 -08:00
|
|
|
|
2013-01-15 00:35:59 -08:00
|
|
|
class nsDOMTokenList : public nsISupports,
|
2011-08-22 02:14:13 -07:00
|
|
|
public nsWrapperCache
|
2009-08-12 01:55:14 -07:00
|
|
|
{
|
2012-11-14 14:10:08 -08:00
|
|
|
protected:
|
2012-11-14 14:10:07 -08:00
|
|
|
typedef mozilla::dom::Element Element;
|
|
|
|
|
2009-08-12 01:55:14 -07:00
|
|
|
public:
|
2011-08-22 02:14:13 -07:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(nsDOMTokenList)
|
2009-08-12 01:55:14 -07:00
|
|
|
|
2012-11-14 14:10:07 -08:00
|
|
|
nsDOMTokenList(Element* aElement, nsIAtom* aAttrAtom);
|
2009-08-12 01:55:14 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual JSObject* WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override;
|
2011-08-22 02:14:13 -07:00
|
|
|
|
2012-11-14 14:10:07 -08:00
|
|
|
Element* GetParentObject()
|
2011-08-22 02:14:13 -07:00
|
|
|
{
|
|
|
|
return mElement;
|
|
|
|
}
|
|
|
|
|
2012-09-05 13:49:53 -07: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 00:31:13 -07:00
|
|
|
void Add(const nsTArray<nsString>& aTokens,
|
|
|
|
mozilla::ErrorResult& aError);
|
2012-09-05 13:49:53 -07:00
|
|
|
void Remove(const nsAString& aToken, mozilla::ErrorResult& aError);
|
2013-08-28 00:31:13 -07:00
|
|
|
void Remove(const nsTArray<nsString>& aTokens,
|
|
|
|
mozilla::ErrorResult& aError);
|
2013-06-14 14:22:17 -07:00
|
|
|
bool Toggle(const nsAString& aToken,
|
|
|
|
const mozilla::dom::Optional<bool>& force,
|
|
|
|
mozilla::ErrorResult& aError);
|
2016-02-11 14:50:42 -08:00
|
|
|
|
|
|
|
void GetValue(nsAString& aResult) { Stringify(aResult); }
|
|
|
|
void SetValue(const nsAString& aValue, mozilla::ErrorResult& rv);
|
2012-09-05 13:49:53 -07:00
|
|
|
void Stringify(nsAString& aResult);
|
|
|
|
|
2012-06-04 16:49:57 -07:00
|
|
|
protected:
|
2012-06-18 19:30:09 -07:00
|
|
|
virtual ~nsDOMTokenList();
|
2012-06-04 16:49:57 -07:00
|
|
|
|
2009-08-12 01:55:14 -07:00
|
|
|
nsresult CheckToken(const nsAString& aStr);
|
2013-08-28 00:31:13 -07: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 04:51:00 -07:00
|
|
|
inline const nsAttrValue* GetParsedAttr();
|
2009-08-12 01:55:14 -07:00
|
|
|
|
2014-03-28 07:36:47 -07:00
|
|
|
nsCOMPtr<Element> mElement;
|
2009-08-12 01:55:14 -07:00
|
|
|
nsCOMPtr<nsIAtom> mAttrAtom;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsDOMTokenList_h___
|