Line data Source code
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/. */
6 :
7 : #include "mozilla/dom/ChromeNodeList.h"
8 : #include "mozilla/dom/ChromeNodeListBinding.h"
9 :
10 : using namespace mozilla;
11 : using namespace mozilla::dom;
12 :
13 : already_AddRefed<ChromeNodeList>
14 0 : ChromeNodeList::Constructor(const GlobalObject& aGlobal, ErrorResult& aRv)
15 : {
16 0 : nsCOMPtr<nsPIDOMWindowInner> win = do_QueryInterface(aGlobal.GetAsSupports());
17 0 : nsIDocument* root = win ? win->GetExtantDoc() : nullptr;
18 0 : RefPtr<ChromeNodeList> list = new ChromeNodeList(root);
19 0 : return list.forget();
20 : }
21 :
22 : JSObject*
23 0 : ChromeNodeList::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
24 : {
25 0 : return ChromeNodeListBinding::Wrap(aCx, this, aGivenProto);
26 : }
27 :
28 : void
29 0 : ChromeNodeList::Append(nsINode& aNode, ErrorResult& aError)
30 : {
31 0 : if (!aNode.IsContent()) {
32 : // nsINodeList deals with nsIContent objects only, so need to
33 : // filter out other nodes for now.
34 0 : aError.Throw(NS_ERROR_DOM_TYPE_ERR);
35 0 : return;
36 : }
37 :
38 0 : AppendElement(aNode.AsContent());
39 : }
40 :
41 : void
42 0 : ChromeNodeList::Remove(nsINode& aNode, ErrorResult& aError)
43 : {
44 0 : if (!aNode.IsContent()) {
45 0 : aError.Throw(NS_ERROR_DOM_TYPE_ERR);
46 0 : return;
47 : }
48 :
49 0 : RemoveElement(aNode.AsContent());
50 : }
|