2015-05-03 19:32:37 +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: */
|
2012-05-21 11:12:37 +00: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/. */
|
1998-11-25 08:14:47 +00:00
|
|
|
|
2006-03-30 08:03:04 +00:00
|
|
|
/*
|
2006-03-31 08:41:49 +00:00
|
|
|
* Implementation of DOM Core's nsIDOMDocumentFragment.
|
2006-03-30 08:03:04 +00:00
|
|
|
*/
|
|
|
|
|
2012-11-14 18:05:41 +00:00
|
|
|
#include "mozilla/dom/DocumentFragment.h"
|
2013-06-26 14:59:45 +00:00
|
|
|
#include "mozilla/dom/Element.h" // for NS_IMPL_ELEMENT_CLONE
|
2014-06-20 02:01:40 +00:00
|
|
|
#include "mozilla/dom/NodeInfo.h"
|
2000-05-10 13:13:39 +00:00
|
|
|
#include "nsNodeInfoManager.h"
|
2012-07-27 14:03:27 +00:00
|
|
|
#include "nsError.h"
|
2007-01-30 00:06:41 +00:00
|
|
|
#include "nsGkAtoms.h"
|
2004-04-01 19:44:17 +00:00
|
|
|
#include "nsDOMString.h"
|
2013-08-14 06:56:21 +00:00
|
|
|
#include "nsContentUtils.h" // for NS_INTERFACE_MAP_ENTRY_TEAROFF
|
2012-12-25 03:35:19 +00:00
|
|
|
#include "mozilla/dom/DocumentFragmentBinding.h"
|
2013-10-02 20:09:18 +00:00
|
|
|
#include "nsPIDOMWindow.h"
|
|
|
|
#include "nsIDocument.h"
|
2014-03-27 20:38:33 +00:00
|
|
|
#include "mozilla/IntegerPrintfMacros.h"
|
1999-01-19 03:54:26 +00:00
|
|
|
|
2012-11-14 18:05:41 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2012-12-25 03:35:19 +00: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 14:13:33 +00:00
|
|
|
DocumentFragment::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
|
2012-12-25 03:35:19 +00: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 14:13:33 +00:00
|
|
|
return DocumentFragmentBinding::Wrap(aCx, this, aGivenProto);
|
1998-11-25 08:14:47 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-11-14 18:05:41 +00:00
|
|
|
DocumentFragment::IsNodeOfType(uint32_t aFlags) const
|
2006-05-15 19:35:12 +00:00
|
|
|
{
|
|
|
|
return !(aFlags & ~(eCONTENT | eDOCUMENT_FRAGMENT));
|
|
|
|
}
|
1998-11-25 08:14:47 +00:00
|
|
|
|
2013-07-08 12:09:18 +00: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 13:31:49 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
2012-11-14 18:05:41 +00:00
|
|
|
DocumentFragment::List(FILE* out, int32_t aIndent) const
|
2012-07-02 13:31:49 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t indent;
|
2012-07-02 13:31:49 +00: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 20:38:33 +00:00
|
|
|
fprintf(out, " refcount=%" PRIuPTR "<", mRefCnt.get());
|
2012-07-02 13:31:49 +00: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 18:05:41 +00:00
|
|
|
DocumentFragment::DumpContent(FILE* out, int32_t aIndent,
|
|
|
|
bool aDumpAll) const
|
2012-07-02 13:31:49 +00:00
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t indent;
|
2012-07-02 13:31:49 +00: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 15:56:38 +00:00
|
|
|
int32_t indent = aIndent ? aIndent + 1 : 0;
|
2012-07-02 13:31:49 +00: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 10:59:00 +00:00
|
|
|
/* static */ already_AddRefed<DocumentFragment>
|
2013-08-23 05:17:08 +00:00
|
|
|
DocumentFragment::Constructor(const GlobalObject& aGlobal,
|
|
|
|
ErrorResult& aRv)
|
2013-05-23 10:59:00 +00:00
|
|
|
{
|
2016-01-30 17:05:36 +00:00
|
|
|
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aGlobal.GetAsSupports());
|
2013-05-23 10:59:00 +00:00
|
|
|
if (!window || !window->GetDoc()) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return window->GetDoc()->CreateDocumentFragment();
|
|
|
|
}
|
|
|
|
|
2012-11-14 18:05:41 +00:00
|
|
|
// QueryInterface implementation for DocumentFragment
|
|
|
|
NS_INTERFACE_MAP_BEGIN(DocumentFragment)
|
2012-05-18 08:29:38 +00:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2012-11-14 18:05:41 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(DocumentFragment)
|
2012-05-18 08:29:38 +00: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 13:44:01 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY(mozilla::dom::EventTarget)
|
2012-05-18 08:29:38 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY_TEAROFF(nsISupportsWeakReference,
|
|
|
|
new nsNodeSupportsWeakRefTearoff(this))
|
2013-06-26 14:59:45 +00:00
|
|
|
// DOM bindings depend on the identity pointer being the
|
|
|
|
// same as nsINode (which nsIContent inherits).
|
2012-05-18 08:29:38 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContent)
|
|
|
|
NS_INTERFACE_MAP_END
|
1998-11-25 08:14:47 +00:00
|
|
|
|
2012-11-14 18:05:41 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(DocumentFragment, FragmentOrElement)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(DocumentFragment, FragmentOrElement)
|
|
|
|
|
|
|
|
NS_IMPL_ELEMENT_CLONE(DocumentFragment)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
|
2012-11-14 18:05:41 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|