2015-05-03 12:32: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: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Implementation of DOM Core's nsIDOMDocumentFragment.
|
|
|
|
*/
|
|
|
|
|
2012-11-14 10:05:41 -08:00
|
|
|
#include "mozilla/dom/DocumentFragment.h"
|
2013-06-26 07:59:45 -07:00
|
|
|
#include "mozilla/dom/Element.h" // for NS_IMPL_ELEMENT_CLONE
|
2014-06-19 19:01:40 -07:00
|
|
|
#include "mozilla/dom/NodeInfo.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsNodeInfoManager.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsDOMString.h"
|
2013-08-13 23:56:21 -07:00
|
|
|
#include "nsContentUtils.h" // for NS_INTERFACE_MAP_ENTRY_TEAROFF
|
2012-12-24 19:35:19 -08:00
|
|
|
#include "mozilla/dom/DocumentFragmentBinding.h"
|
2013-10-02 13:09:18 -07:00
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsIDocument.h"
|
2014-03-27 13:38:33 -07:00
|
|
|
#include "mozilla/IntegerPrintfMacros.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-11-14 10:05:41 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2012-12-24 19:35:19 -08:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
DocumentFragment::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
|
2012-12-24 19:35:19 -08:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 07:13:33 -07:00
|
|
|
return DocumentFragmentBinding::Wrap(aCx, this, aGivenProto);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-11-14 10:05:41 -08:00
|
|
|
DocumentFragment::IsNodeOfType(uint32_t aFlags) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return !(aFlags & ~(eCONTENT | eDOCUMENT_FRAGMENT));
|
|
|
|
}
|
|
|
|
|
2013-07-08 05:09:18 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentFragment::QuerySelector(const nsAString& aSelector,
|
|
|
|
nsIDOMElement **aReturn)
|
|
|
|
{
|
|
|
|
return nsINode::QuerySelector(aSelector, aReturn);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentFragment::QuerySelectorAll(const nsAString& aSelector,
|
|
|
|
nsIDOMNodeList **aReturn)
|
|
|
|
{
|
|
|
|
return nsINode::QuerySelectorAll(aSelector, aReturn);
|
|
|
|
}
|
|
|
|
|
2012-07-02 06:31:49 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
2012-11-14 10:05:41 -08:00
|
|
|
DocumentFragment::List(FILE* out, int32_t aIndent) const
|
2012-07-02 06:31:49 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t indent;
|
2012-07-02 06:31:49 -07:00
|
|
|
for (indent = aIndent; --indent >= 0; ) {
|
|
|
|
fputs(" ", out);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(out, "DocumentFragment@%p", (void *)this);
|
|
|
|
|
|
|
|
fprintf(out, " flags=[%08x]", static_cast<unsigned int>(GetFlags()));
|
2014-03-27 13:38:33 -07:00
|
|
|
fprintf(out, " refcount=%" PRIuPTR "<", mRefCnt.get());
|
2012-07-02 06:31:49 -07:00
|
|
|
|
|
|
|
nsIContent* child = GetFirstChild();
|
|
|
|
if (child) {
|
|
|
|
fputs("\n", out);
|
|
|
|
|
|
|
|
for (; child; child = child->GetNextSibling()) {
|
|
|
|
child->List(out, aIndent + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (indent = aIndent; --indent >= 0; ) {
|
|
|
|
fputs(" ", out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fputs(">\n", out);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-11-14 10:05:41 -08:00
|
|
|
DocumentFragment::DumpContent(FILE* out, int32_t aIndent,
|
|
|
|
bool aDumpAll) const
|
2012-07-02 06:31:49 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t indent;
|
2012-07-02 06:31:49 -07:00
|
|
|
for (indent = aIndent; --indent >= 0; ) {
|
|
|
|
fputs(" ", out);
|
|
|
|
}
|
|
|
|
|
|
|
|
fputs("<DocumentFragment>", out);
|
|
|
|
|
|
|
|
if(aIndent) {
|
|
|
|
fputs("\n", out);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (nsIContent* child = GetFirstChild();
|
|
|
|
child;
|
|
|
|
child = child->GetNextSibling()) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t indent = aIndent ? aIndent + 1 : 0;
|
2012-07-02 06:31:49 -07:00
|
|
|
child->DumpContent(out, indent, aDumpAll);
|
|
|
|
}
|
|
|
|
for (indent = aIndent; --indent >= 0; ) {
|
|
|
|
fputs(" ", out);
|
|
|
|
}
|
|
|
|
fputs("</DocumentFragment>", out);
|
|
|
|
|
|
|
|
if(aIndent) {
|
|
|
|
fputs("\n", out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-05-23 03:59:00 -07:00
|
|
|
/* static */ already_AddRefed<DocumentFragment>
|
2013-08-22 22:17:08 -07:00
|
|
|
DocumentFragment::Constructor(const GlobalObject& aGlobal,
|
|
|
|
ErrorResult& aRv)
|
2013-05-23 03:59:00 -07:00
|
|
|
{
|
2013-08-22 22:17:08 -07:00
|
|
|
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aGlobal.GetAsSupports());
|
2013-05-23 03:59:00 -07:00
|
|
|
if (!window || !window->GetDoc()) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return window->GetDoc()->CreateDocumentFragment();
|
|
|
|
}
|
|
|
|
|
2012-11-14 10:05:41 -08:00
|
|
|
// QueryInterface implementation for DocumentFragment
|
|
|
|
NS_INTERFACE_MAP_BEGIN(DocumentFragment)
|
2012-05-18 01:29:38 -07:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2012-11-14 10:05:41 -08:00
|
|
|
NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(DocumentFragment)
|
2012-05-18 01:29:38 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIContent)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsINode)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentFragment)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMNode)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMEventTarget)
|
2013-01-29 05:44:01 -08:00
|
|
|
NS_INTERFACE_MAP_ENTRY(mozilla::dom::EventTarget)
|
2012-05-18 01:29:38 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY_TEAROFF(nsISupportsWeakReference,
|
|
|
|
new nsNodeSupportsWeakRefTearoff(this))
|
2013-06-26 07:59:45 -07:00
|
|
|
// DOM bindings depend on the identity pointer being the
|
|
|
|
// same as nsINode (which nsIContent inherits).
|
2012-05-18 01:29:38 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContent)
|
|
|
|
NS_INTERFACE_MAP_END
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-11-14 10:05:41 -08:00
|
|
|
NS_IMPL_ADDREF_INHERITED(DocumentFragment, FragmentOrElement)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(DocumentFragment, FragmentOrElement)
|
|
|
|
|
|
|
|
NS_IMPL_ELEMENT_CLONE(DocumentFragment)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-11-14 10:05:41 -08:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|