Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/dom/html/HTMLTitleElement.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/HTMLTitleElement.h"
8
9
#include "mozilla/dom/HTMLTitleElementBinding.h"
10
#include "mozilla/ErrorResult.h"
11
#include "nsStyleConsts.h"
12
#include "nsIDocument.h"
13
#include "nsContentUtils.h"
14
15
16
NS_IMPL_NS_NEW_HTML_ELEMENT(Title)
17
18
namespace mozilla {
19
namespace dom {
20
21
HTMLTitleElement::HTMLTitleElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
22
  : nsGenericHTMLElement(std::move(aNodeInfo))
23
0
{
24
0
  AddMutationObserver(this);
25
0
}
26
27
HTMLTitleElement::~HTMLTitleElement()
28
0
{
29
0
}
30
31
NS_IMPL_ISUPPORTS_INHERITED(HTMLTitleElement, nsGenericHTMLElement,
32
                            nsIMutationObserver)
33
34
NS_IMPL_ELEMENT_CLONE(HTMLTitleElement)
35
36
JSObject*
37
HTMLTitleElement::WrapNode(JSContext* cx, JS::Handle<JSObject*> aGivenProto)
38
0
{
39
0
  return HTMLTitleElement_Binding::Wrap(cx, this, aGivenProto);
40
0
}
41
42
void
43
HTMLTitleElement::GetText(DOMString& aText, ErrorResult& aError)
44
0
{
45
0
  if (!nsContentUtils::GetNodeTextContent(this, false, aText, fallible)) {
46
0
    aError = NS_ERROR_OUT_OF_MEMORY;
47
0
  }
48
0
}
49
50
void
51
HTMLTitleElement::SetText(const nsAString& aText, ErrorResult& aError)
52
0
{
53
0
  aError = nsContentUtils::SetNodeTextContent(this, aText, true);
54
0
}
55
56
void
57
HTMLTitleElement::CharacterDataChanged(nsIContent* aContent,
58
                                       const CharacterDataChangeInfo&)
59
0
{
60
0
  SendTitleChangeEvent(false);
61
0
}
62
63
void
64
HTMLTitleElement::ContentAppended(nsIContent* aFirstNewContent)
65
0
{
66
0
  SendTitleChangeEvent(false);
67
0
}
68
69
void
70
HTMLTitleElement::ContentInserted(nsIContent* aChild)
71
0
{
72
0
  SendTitleChangeEvent(false);
73
0
}
74
75
void
76
HTMLTitleElement::ContentRemoved(nsIContent* aChild,
77
                                 nsIContent* aPreviousSibling)
78
0
{
79
0
  SendTitleChangeEvent(false);
80
0
}
81
82
nsresult
83
HTMLTitleElement::BindToTree(nsIDocument *aDocument,
84
                             nsIContent *aParent,
85
                             nsIContent *aBindingParent)
86
0
{
87
0
  // Let this fall through.
88
0
  nsresult rv = nsGenericHTMLElement::BindToTree(aDocument, aParent,
89
0
                                                 aBindingParent);
90
0
  NS_ENSURE_SUCCESS(rv, rv);
91
0
92
0
  SendTitleChangeEvent(true);
93
0
94
0
  return NS_OK;
95
0
}
96
97
void
98
HTMLTitleElement::UnbindFromTree(bool aDeep, bool aNullParent)
99
0
{
100
0
  SendTitleChangeEvent(false);
101
0
102
0
  // Let this fall through.
103
0
  nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
104
0
}
105
106
void
107
HTMLTitleElement::DoneAddingChildren(bool aHaveNotified)
108
0
{
109
0
  if (!aHaveNotified) {
110
0
    SendTitleChangeEvent(false);
111
0
  }
112
0
}
113
114
void
115
HTMLTitleElement::SendTitleChangeEvent(bool aBound)
116
0
{
117
0
  nsIDocument* doc = GetUncomposedDoc();
118
0
  if (doc) {
119
0
    doc->NotifyPossibleTitleChange(aBound);
120
0
  }
121
0
}
122
123
} // namespace dom
124
} // namespace mozilla