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