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/HTMLTitleElement.h"
9 #include "mozilla/dom/HTMLTitleElementBinding.h"
10 #include "mozilla/ErrorResult.h"
11 #include "nsStyleConsts.h"
12 #include "nsIDocument.h"
13 #include "nsContentUtils.h"
16 NS_IMPL_NS_NEW_HTML_ELEMENT(Title
)
21 HTMLTitleElement::HTMLTitleElement(already_AddRefed
<mozilla::dom::NodeInfo
>& aNodeInfo
)
22 : nsGenericHTMLElement(aNodeInfo
)
24 AddMutationObserver(this);
27 HTMLTitleElement::~HTMLTitleElement()
31 NS_IMPL_ISUPPORTS_INHERITED(HTMLTitleElement
, nsGenericHTMLElement
,
34 NS_IMPL_ELEMENT_CLONE(HTMLTitleElement
)
37 HTMLTitleElement::WrapNode(JSContext
* cx
, JS::Handle
<JSObject
*> aGivenProto
)
39 return HTMLTitleElement_Binding::Wrap(cx
, this, aGivenProto
);
43 HTMLTitleElement::GetText(DOMString
& aText
, ErrorResult
& aError
)
45 if (!nsContentUtils::GetNodeTextContent(this, false, aText
, fallible
)) {
46 aError
= NS_ERROR_OUT_OF_MEMORY
;
51 HTMLTitleElement::SetText(const nsAString
& aText
, ErrorResult
& aError
)
53 aError
= nsContentUtils::SetNodeTextContent(this, aText
, true);
57 HTMLTitleElement::CharacterDataChanged(nsIContent
* aContent
,
58 const CharacterDataChangeInfo
&)
60 SendTitleChangeEvent(false);
64 HTMLTitleElement::ContentAppended(nsIContent
* aFirstNewContent
)
66 SendTitleChangeEvent(false);
70 HTMLTitleElement::ContentInserted(nsIContent
* aChild
)
72 SendTitleChangeEvent(false);
76 HTMLTitleElement::ContentRemoved(nsIContent
* aChild
,
77 nsIContent
* aPreviousSibling
)
79 SendTitleChangeEvent(false);
83 HTMLTitleElement::BindToTree(nsIDocument
*aDocument
,
85 nsIContent
*aBindingParent
,
86 bool aCompileEventHandlers
)
88 // Let this fall through.
89 nsresult rv
= nsGenericHTMLElement::BindToTree(aDocument
, aParent
,
91 aCompileEventHandlers
);
92 NS_ENSURE_SUCCESS(rv
, rv
);
94 SendTitleChangeEvent(true);
100 HTMLTitleElement::UnbindFromTree(bool aDeep
, bool aNullParent
)
102 SendTitleChangeEvent(false);
104 // Let this fall through.
105 nsGenericHTMLElement::UnbindFromTree(aDeep
, aNullParent
);
109 HTMLTitleElement::DoneAddingChildren(bool aHaveNotified
)
111 if (!aHaveNotified
) {
112 SendTitleChangeEvent(false);
117 HTMLTitleElement::SendTitleChangeEvent(bool aBound
)
119 nsIDocument
* doc
= GetUncomposedDoc();
121 doc
->NotifyPossibleTitleChange(aBound
);
126 } // namespace mozilla