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/. */
7 #include "mozilla/dom/ChromeNodeList.h"
11 #include "mozilla/ErrorResult.h"
12 #include "mozilla/RefPtr.h"
13 #include "mozilla/dom/BindingDeclarations.h"
14 #include "mozilla/dom/ChromeNodeListBinding.h"
15 #include "mozilla/dom/Document.h"
18 #include "nsISupports.h"
19 #include "nsPIDOMWindow.h"
23 using namespace mozilla
;
24 using namespace mozilla::dom
;
26 already_AddRefed
<ChromeNodeList
> ChromeNodeList::Constructor(
27 const GlobalObject
& aGlobal
) {
28 nsCOMPtr
<nsPIDOMWindowInner
> win
= do_QueryInterface(aGlobal
.GetAsSupports());
29 Document
* root
= win
? win
->GetExtantDoc() : nullptr;
30 RefPtr
<ChromeNodeList
> list
= new ChromeNodeList(root
);
34 JSObject
* ChromeNodeList::WrapObject(JSContext
* aCx
,
35 JS::Handle
<JSObject
*> aGivenProto
) {
36 return ChromeNodeList_Binding::Wrap(aCx
, this, aGivenProto
);
39 void ChromeNodeList::Append(nsINode
& aNode
, ErrorResult
& aError
) {
40 if (!aNode
.IsContent()) {
41 // nsINodeList deals with nsIContent objects only, so need to
42 // filter out other nodes for now.
43 aError
.ThrowTypeError("The node passed in is not a ChildNode");
47 AppendElement(aNode
.AsContent());
50 void ChromeNodeList::Remove(nsINode
& aNode
, ErrorResult
& aError
) {
51 if (!aNode
.IsContent()) {
52 aError
.ThrowTypeError("The node passed in is not a ChildNode");
56 RemoveElement(aNode
.AsContent());