Bug 1655413 [wpt PR 24763] - Make CSP default-src without 'unsafe-eval' block eval...
[gecko.git] / dom / html / HTMLPictureElement.cpp
blob05d4d1a95af47f52108e807a6cf63cd1d022b614
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 "mozilla/dom/HTMLPictureElement.h"
8 #include "mozilla/dom/HTMLPictureElementBinding.h"
9 #include "mozilla/dom/HTMLImageElement.h"
11 // Expand NS_IMPL_NS_NEW_HTML_ELEMENT(Picture) to add pref check.
12 nsGenericHTMLElement* NS_NewHTMLPictureElement(
13 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
14 mozilla::dom::FromParser aFromParser) {
15 RefPtr<mozilla::dom::NodeInfo> nodeInfo(aNodeInfo);
16 auto* nim = nodeInfo->NodeInfoManager();
17 return new (nim) mozilla::dom::HTMLPictureElement(nodeInfo.forget());
20 namespace mozilla {
21 namespace dom {
23 HTMLPictureElement::HTMLPictureElement(
24 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
25 : nsGenericHTMLElement(std::move(aNodeInfo)) {}
27 HTMLPictureElement::~HTMLPictureElement() = default;
29 NS_IMPL_ELEMENT_CLONE(HTMLPictureElement)
31 void HTMLPictureElement::RemoveChildNode(nsIContent* aKid, bool aNotify) {
32 if (aKid && aKid->IsHTMLElement(nsGkAtoms::img)) {
33 HTMLImageElement* img = HTMLImageElement::FromNode(aKid);
34 if (img) {
35 img->PictureSourceRemoved(aKid->AsContent());
37 } else if (aKid && aKid->IsHTMLElement(nsGkAtoms::source)) {
38 // Find all img siblings after this <source> to notify them of its demise
39 nsCOMPtr<nsIContent> nextSibling = aKid->GetNextSibling();
40 if (nextSibling && nextSibling->GetParentNode() == this) {
41 do {
42 HTMLImageElement* img = HTMLImageElement::FromNode(nextSibling);
43 if (img) {
44 img->PictureSourceRemoved(aKid->AsContent());
46 } while ((nextSibling = nextSibling->GetNextSibling()));
50 nsGenericHTMLElement::RemoveChildNode(aKid, aNotify);
53 nsresult HTMLPictureElement::InsertChildBefore(nsIContent* aKid,
54 nsIContent* aBeforeThis,
55 bool aNotify) {
56 nsresult rv =
57 nsGenericHTMLElement::InsertChildBefore(aKid, aBeforeThis, aNotify);
59 NS_ENSURE_SUCCESS(rv, rv);
60 NS_ENSURE_TRUE(aKid, rv);
62 if (aKid->IsHTMLElement(nsGkAtoms::img)) {
63 HTMLImageElement* img = HTMLImageElement::FromNode(aKid);
64 if (img) {
65 img->PictureSourceAdded(aKid->AsContent());
67 } else if (aKid->IsHTMLElement(nsGkAtoms::source)) {
68 // Find all img siblings after this <source> to notify them of its insertion
69 nsCOMPtr<nsIContent> nextSibling = aKid->GetNextSibling();
70 if (nextSibling && nextSibling->GetParentNode() == this) {
71 do {
72 HTMLImageElement* img = HTMLImageElement::FromNode(nextSibling);
73 if (img) {
74 img->PictureSourceAdded(aKid->AsContent());
76 } while ((nextSibling = nextSibling->GetNextSibling()));
80 return rv;
83 JSObject* HTMLPictureElement::WrapNode(JSContext* aCx,
84 JS::Handle<JSObject*> aGivenProto) {
85 return HTMLPictureElement_Binding::Wrap(aCx, this, aGivenProto);
88 } // namespace dom
89 } // namespace mozilla