Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / html / HTMLPictureElement.cpp
blob45b1e4e3e3f255b11b0ea0d9cdf7fcf574765b2b
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"
10 #include "mozilla/dom/HTMLSourceElement.h"
12 // Expand NS_IMPL_NS_NEW_HTML_ELEMENT(Picture) to add pref check.
13 nsGenericHTMLElement* NS_NewHTMLPictureElement(
14 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
15 mozilla::dom::FromParser aFromParser) {
16 RefPtr<mozilla::dom::NodeInfo> nodeInfo(aNodeInfo);
17 auto* nim = nodeInfo->NodeInfoManager();
18 return new (nim) mozilla::dom::HTMLPictureElement(nodeInfo.forget());
21 namespace mozilla::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 MOZ_ASSERT(aKid);
34 if (auto* img = HTMLImageElement::FromNode(aKid)) {
35 img->PictureSourceRemoved();
36 } else if (auto* source = HTMLSourceElement::FromNode(aKid)) {
37 // Find all img siblings after this <source> to notify them of its demise
38 nsCOMPtr<nsIContent> nextSibling = source->GetNextSibling();
39 if (nextSibling && nextSibling->GetParentNode() == this) {
40 do {
41 if (auto* img = HTMLImageElement::FromNode(nextSibling)) {
42 img->PictureSourceRemoved(source);
44 } while ((nextSibling = nextSibling->GetNextSibling()));
48 nsGenericHTMLElement::RemoveChildNode(aKid, aNotify);
51 void HTMLPictureElement::InsertChildBefore(nsIContent* aKid,
52 nsIContent* aBeforeThis,
53 bool aNotify, ErrorResult& aRv) {
54 nsGenericHTMLElement::InsertChildBefore(aKid, aBeforeThis, aNotify, aRv);
55 if (aRv.Failed() || !aKid) {
56 return;
59 if (auto* img = HTMLImageElement::FromNode(aKid)) {
60 img->PictureSourceAdded();
61 } else if (auto* source = HTMLSourceElement::FromNode(aKid)) {
62 // Find all img siblings after this <source> to notify them of its insertion
63 nsCOMPtr<nsIContent> nextSibling = source->GetNextSibling();
64 if (nextSibling && nextSibling->GetParentNode() == this) {
65 do {
66 if (auto* img = HTMLImageElement::FromNode(nextSibling)) {
67 img->PictureSourceAdded(source);
69 } while ((nextSibling = nextSibling->GetNextSibling()));
74 JSObject* HTMLPictureElement::WrapNode(JSContext* aCx,
75 JS::Handle<JSObject*> aGivenProto) {
76 return HTMLPictureElement_Binding::Wrap(aCx, this, aGivenProto);
79 } // namespace mozilla::dom