Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/html/HTMLPictureElement.cpp
Line
Count
Source (jump to first uncovered line)
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
NS_NewHTMLPictureElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
14
                         mozilla::dom::FromParser aFromParser)
15
0
{
16
0
  return new mozilla::dom::HTMLPictureElement(std::move(aNodeInfo));
17
0
}
18
19
namespace mozilla {
20
namespace dom {
21
22
HTMLPictureElement::HTMLPictureElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
23
  : nsGenericHTMLElement(std::move(aNodeInfo))
24
0
{
25
0
}
26
27
HTMLPictureElement::~HTMLPictureElement()
28
0
{
29
0
}
30
31
NS_IMPL_ELEMENT_CLONE(HTMLPictureElement)
32
33
void
34
HTMLPictureElement::RemoveChildNode(nsIContent* aKid, bool aNotify)
35
0
{
36
0
  if (aKid && aKid->IsHTMLElement(nsGkAtoms::img)) {
37
0
    HTMLImageElement* img = HTMLImageElement::FromNode(aKid);
38
0
    if (img) {
39
0
      img->PictureSourceRemoved(aKid->AsContent());
40
0
    }
41
0
  } else if (aKid && aKid->IsHTMLElement(nsGkAtoms::source)) {
42
0
    // Find all img siblings after this <source> to notify them of its demise
43
0
    nsCOMPtr<nsIContent> nextSibling = aKid->GetNextSibling();
44
0
    if (nextSibling && nextSibling->GetParentNode() == this) {
45
0
      do {
46
0
        HTMLImageElement* img = HTMLImageElement::FromNode(nextSibling);
47
0
        if (img) {
48
0
          img->PictureSourceRemoved(aKid->AsContent());
49
0
        }
50
0
      } while ( (nextSibling = nextSibling->GetNextSibling()) );
51
0
    }
52
0
  }
53
0
54
0
  nsGenericHTMLElement::RemoveChildNode(aKid, aNotify);
55
0
}
56
57
nsresult
58
HTMLPictureElement::InsertChildBefore(nsIContent* aKid, nsIContent* aBeforeThis,
59
                                      bool aNotify)
60
0
{
61
0
  nsresult rv =
62
0
    nsGenericHTMLElement::InsertChildBefore(aKid, aBeforeThis, aNotify);
63
0
64
0
  NS_ENSURE_SUCCESS(rv, rv);
65
0
  NS_ENSURE_TRUE(aKid, rv);
66
0
67
0
  if (aKid->IsHTMLElement(nsGkAtoms::img)) {
68
0
    HTMLImageElement* img = HTMLImageElement::FromNode(aKid);
69
0
    if (img) {
70
0
      img->PictureSourceAdded(aKid->AsContent());
71
0
    }
72
0
  } else if (aKid->IsHTMLElement(nsGkAtoms::source)) {
73
0
    // Find all img siblings after this <source> to notify them of its insertion
74
0
    nsCOMPtr<nsIContent> nextSibling = aKid->GetNextSibling();
75
0
    if (nextSibling && nextSibling->GetParentNode() == this) {
76
0
      do {
77
0
        HTMLImageElement* img = HTMLImageElement::FromNode(nextSibling);
78
0
        if (img) {
79
0
          img->PictureSourceAdded(aKid->AsContent());
80
0
        }
81
0
      } while ( (nextSibling = nextSibling->GetNextSibling()) );
82
0
    }
83
0
  }
84
0
85
0
  return rv;
86
0
}
87
88
JSObject*
89
HTMLPictureElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
90
0
{
91
0
  return HTMLPictureElement_Binding::Wrap(aCx, this, aGivenProto);
92
0
}
93
94
} // namespace dom
95
} // namespace mozilla