Line data Source code
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/. */
6 :
7 : #include "mozilla/dom/HTMLPictureElement.h"
8 : #include "mozilla/dom/HTMLPictureElementBinding.h"
9 : #include "mozilla/dom/HTMLImageElement.h"
10 :
11 : // Expand NS_IMPL_NS_NEW_HTML_ELEMENT(Picture) to add pref check.
12 : nsGenericHTMLElement*
13 0 : NS_NewHTMLPictureElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
14 : mozilla::dom::FromParser aFromParser)
15 : {
16 0 : return new mozilla::dom::HTMLPictureElement(aNodeInfo);
17 : }
18 :
19 : namespace mozilla {
20 : namespace dom {
21 :
22 0 : HTMLPictureElement::HTMLPictureElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
23 0 : : nsGenericHTMLElement(aNodeInfo)
24 : {
25 0 : }
26 :
27 0 : HTMLPictureElement::~HTMLPictureElement()
28 : {
29 0 : }
30 :
31 0 : NS_IMPL_ISUPPORTS_INHERITED(HTMLPictureElement, nsGenericHTMLElement,
32 : nsIDOMHTMLPictureElement)
33 :
34 0 : NS_IMPL_ELEMENT_CLONE(HTMLPictureElement)
35 :
36 : void
37 0 : HTMLPictureElement::RemoveChildAt(uint32_t aIndex, bool aNotify)
38 : {
39 0 : nsCOMPtr<nsIContent> child = GetChildAt(aIndex);
40 :
41 0 : if (child && child->IsHTMLElement(nsGkAtoms::img)) {
42 0 : HTMLImageElement* img = HTMLImageElement::FromContent(child);
43 0 : if (img) {
44 0 : img->PictureSourceRemoved(child->AsContent());
45 : }
46 0 : } else if (child && child->IsHTMLElement(nsGkAtoms::source)) {
47 : // Find all img siblings after this <source> to notify them of its demise
48 0 : nsCOMPtr<nsIContent> nextSibling = child->GetNextSibling();
49 0 : if (nextSibling && nextSibling->GetParentNode() == this) {
50 0 : do {
51 0 : HTMLImageElement* img = HTMLImageElement::FromContent(nextSibling);
52 0 : if (img) {
53 0 : img->PictureSourceRemoved(child->AsContent());
54 : }
55 0 : } while ( (nextSibling = nextSibling->GetNextSibling()) );
56 : }
57 : }
58 :
59 0 : nsGenericHTMLElement::RemoveChildAt(aIndex, aNotify);
60 0 : }
61 :
62 : nsresult
63 0 : HTMLPictureElement::InsertChildAt(nsIContent* aKid, uint32_t aIndex, bool aNotify)
64 : {
65 0 : nsresult rv = nsGenericHTMLElement::InsertChildAt(aKid, aIndex, aNotify);
66 :
67 0 : NS_ENSURE_SUCCESS(rv, rv);
68 0 : NS_ENSURE_TRUE(aKid, rv);
69 :
70 0 : if (aKid->IsHTMLElement(nsGkAtoms::img)) {
71 0 : HTMLImageElement* img = HTMLImageElement::FromContent(aKid);
72 0 : if (img) {
73 0 : img->PictureSourceAdded(aKid->AsContent());
74 : }
75 0 : } else if (aKid->IsHTMLElement(nsGkAtoms::source)) {
76 : // Find all img siblings after this <source> to notify them of its insertion
77 0 : nsCOMPtr<nsIContent> nextSibling = aKid->GetNextSibling();
78 0 : if (nextSibling && nextSibling->GetParentNode() == this) {
79 0 : do {
80 0 : HTMLImageElement* img = HTMLImageElement::FromContent(nextSibling);
81 0 : if (img) {
82 0 : img->PictureSourceAdded(aKid->AsContent());
83 : }
84 0 : } while ( (nextSibling = nextSibling->GetNextSibling()) );
85 : }
86 : }
87 :
88 0 : return rv;
89 : }
90 :
91 : JSObject*
92 0 : HTMLPictureElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
93 : {
94 0 : return HTMLPictureElementBinding::Wrap(aCx, this, aGivenProto);
95 : }
96 :
97 : } // namespace dom
98 : } // namespace mozilla
|