Mypal/dom/base/StyleSheetList.h

76 lines
2.0 KiB
C
Raw Normal View History

2019-03-11 03:26: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: */
/* 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/. */
#ifndef mozilla_dom_StyleSheetList_h
#define mozilla_dom_StyleSheetList_h
#include "mozilla/dom/DocumentOrShadowRoot.h"
2019-03-11 03:26:37 -07:00
#include "nsIDOMStyleSheetList.h"
#include "nsWrapperCache.h"
2020-05-24 22:50:05 -07:00
#include "nsStubDocumentObserver.h"
2019-03-11 03:26:37 -07:00
class nsINode;
namespace mozilla {
class StyleSheet;
namespace dom {
2020-05-24 22:50:05 -07:00
class StyleSheetList final : public nsIDOMStyleSheetList
, public nsWrapperCache
, public nsStubDocumentObserver
2019-03-11 03:26:37 -07:00
{
public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
2020-05-24 22:50:05 -07:00
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(StyleSheetList, nsIDOMStyleSheetList)
2019-03-11 03:26:37 -07:00
NS_DECL_NSIDOMSTYLESHEETLIST
2020-05-24 22:50:05 -07:00
NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
explicit StyleSheetList(DocumentOrShadowRoot& aScope);
2020-05-24 22:50:05 -07:00
2019-03-11 03:26:37 -07:00
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override final;
2020-05-24 22:50:05 -07:00
nsINode* GetParentObject() const
{
return mDocumentOrShadowRoot ? &mDocumentOrShadowRoot->AsNode() : nullptr;
2020-05-24 22:50:05 -07:00
}
2019-03-11 03:26:37 -07:00
2020-05-24 22:50:05 -07:00
uint32_t Length() const
{
return mDocumentOrShadowRoot ? mDocumentOrShadowRoot->SheetCount() : 0;
2020-05-24 22:50:05 -07:00
}
StyleSheet* IndexedGetter(uint32_t aIndex, bool& aFound) const
{
if (!mDocumentOrShadowRoot) {
2020-05-24 22:50:05 -07:00
aFound = false;
return nullptr;
}
StyleSheet* sheet = mDocumentOrShadowRoot->SheetAt(aIndex);
2020-05-24 22:50:05 -07:00
aFound = !!sheet;
return sheet;
}
StyleSheet* Item(uint32_t aIndex) const
2019-03-11 03:26:37 -07:00
{
bool dummy = false;
return IndexedGetter(aIndex, dummy);
}
protected:
2020-05-24 22:50:05 -07:00
virtual ~StyleSheetList();
DocumentOrShadowRoot* mDocumentOrShadowRoot; // Weak, cleared on "NodeWillBeDestroyed".
2019-03-11 03:26:37 -07:00
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_StyleSheetList_h