ChromeNodeList.cpp (1821B)
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 9 #include <new> 10 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" 16 #include "nsCOMPtr.h" 17 #include "nsINode.h" 18 #include "nsISupports.h" 19 #include "nsPIDOMWindow.h" 20 #include "nsString.h" 21 #include "nsTArray.h" 22 23 using namespace mozilla; 24 using namespace mozilla::dom; 25 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); 31 return list.forget(); 32 } 33 34 JSObject* ChromeNodeList::WrapObject(JSContext* aCx, 35 JS::Handle<JSObject*> aGivenProto) { 36 return ChromeNodeList_Binding::Wrap(aCx, this, aGivenProto); 37 } 38 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"); 44 return; 45 } 46 47 AppendElement(aNode.AsContent()); 48 } 49 50 void ChromeNodeList::Remove(nsINode& aNode, ErrorResult& aError) { 51 if (!aNode.IsContent()) { 52 aError.ThrowTypeError("The node passed in is not a ChildNode"); 53 return; 54 } 55 56 RemoveElement(aNode.AsContent()); 57 }