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/. */
7 #include "AnonymousContent.h"
8 #include "mozilla/dom/Document.h"
9 #include "mozilla/dom/Element.h"
10 #include "mozilla/dom/ShadowRoot.h"
11 #include "mozilla/dom/AnonymousContentBinding.h"
12 #include "nsCycleCollectionParticipant.h"
14 namespace mozilla::dom
{
16 // Ref counting and cycle collection
17 NS_IMPL_CYCLE_COLLECTION(AnonymousContent
, mHost
, mRoot
)
19 already_AddRefed
<AnonymousContent
> AnonymousContent::Create(Document
& aDoc
) {
20 RefPtr
<Element
> host
= aDoc
.CreateHTMLElement(nsGkAtoms::div
);
24 host
->SetAttr(kNameSpaceID_None
, nsGkAtoms::role
, u
"presentation"_ns
, false);
25 host
->SetAttr(kNameSpaceID_None
, nsGkAtoms::_class
,
26 u
"anonymous-content-host"_ns
, false);
27 RefPtr
<ShadowRoot
> root
= host
->AttachShadowWithoutNameChecks(
28 ShadowRootMode::Closed
, Element::DelegatesFocus::No
);
29 root
->SetIsUAWidget();
30 return do_AddRef(new AnonymousContent(host
.forget(), root
.forget()));
33 AnonymousContent::AnonymousContent(already_AddRefed
<Element
> aHost
,
34 already_AddRefed
<ShadowRoot
> aRoot
)
35 : mHost(aHost
), mRoot(aRoot
) {
40 AnonymousContent::~AnonymousContent() = default;
42 bool AnonymousContent::WrapObject(JSContext
* aCx
,
43 JS::Handle
<JSObject
*> aGivenProto
,
44 JS::MutableHandle
<JSObject
*> aReflector
) {
45 return AnonymousContent_Binding::Wrap(aCx
, this, aGivenProto
, aReflector
);
47 } // namespace mozilla::dom