2015-10-27 17:48:46 +00: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/. */
|
|
|
|
|
|
|
|
#include "mozilla/dom/ChromeNodeList.h"
|
2020-11-23 16:21:38 +00:00
|
|
|
|
|
|
|
#include <new>
|
|
|
|
#include <utility>
|
|
|
|
#include "mozilla/ErrorResult.h"
|
|
|
|
#include "mozilla/RefPtr.h"
|
|
|
|
#include "mozilla/dom/BindingDeclarations.h"
|
2015-10-27 17:48:46 +00:00
|
|
|
#include "mozilla/dom/ChromeNodeListBinding.h"
|
2020-11-23 16:21:38 +00:00
|
|
|
#include "mozilla/dom/Document.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsINode.h"
|
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsTArray.h"
|
2015-10-27 17:48:46 +00:00
|
|
|
|
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
|
|
|
already_AddRefed<ChromeNodeList> ChromeNodeList::Constructor(
|
2019-09-12 11:01:17 +00:00
|
|
|
const GlobalObject& aGlobal) {
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> win = do_QueryInterface(aGlobal.GetAsSupports());
|
2019-01-02 13:05:23 +00:00
|
|
|
Document* root = win ? win->GetExtantDoc() : nullptr;
|
2015-10-27 17:48:46 +00:00
|
|
|
RefPtr<ChromeNodeList> list = new ChromeNodeList(root);
|
|
|
|
return list.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
JSObject* ChromeNodeList::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-25 21:20:54 +00:00
|
|
|
return ChromeNodeList_Binding::Wrap(aCx, this, aGivenProto);
|
2015-10-27 17:48:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ChromeNodeList::Append(nsINode& aNode, ErrorResult& aError) {
|
|
|
|
if (!aNode.IsContent()) {
|
|
|
|
// nsINodeList deals with nsIContent objects only, so need to
|
|
|
|
// filter out other nodes for now.
|
2020-03-06 21:04:58 +00:00
|
|
|
aError.ThrowTypeError("The node passed in is not a ChildNode");
|
2015-10-27 17:48:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
AppendElement(aNode.AsContent());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ChromeNodeList::Remove(nsINode& aNode, ErrorResult& aError) {
|
|
|
|
if (!aNode.IsContent()) {
|
2020-03-06 21:04:58 +00:00
|
|
|
aError.ThrowTypeError("The node passed in is not a ChildNode");
|
2015-10-27 17:48:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RemoveElement(aNode.AsContent());
|
|
|
|
}
|