Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / html / HTMLTitleElement.cpp
blobd8d65491cc3c32331e3fc0baeed0fadc75d65673
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 "mozilla/dom/Document.h"
13 #include "nsContentUtils.h"
15 NS_IMPL_NS_NEW_HTML_ELEMENT(Title)
17 namespace mozilla::dom {
19 HTMLTitleElement::HTMLTitleElement(
20 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
21 : nsGenericHTMLElement(std::move(aNodeInfo)) {
22 AddMutationObserver(this);
25 HTMLTitleElement::~HTMLTitleElement() = default;
27 NS_IMPL_ISUPPORTS_INHERITED(HTMLTitleElement, nsGenericHTMLElement,
28 nsIMutationObserver)
30 NS_IMPL_ELEMENT_CLONE(HTMLTitleElement)
32 JSObject* HTMLTitleElement::WrapNode(JSContext* cx,
33 JS::Handle<JSObject*> aGivenProto) {
34 return HTMLTitleElement_Binding::Wrap(cx, this, aGivenProto);
37 void HTMLTitleElement::GetText(DOMString& aText, ErrorResult& aError) const {
38 if (!nsContentUtils::GetNodeTextContent(this, false, aText, fallible)) {
39 aError = NS_ERROR_OUT_OF_MEMORY;
43 void HTMLTitleElement::SetText(const nsAString& aText, ErrorResult& aError) {
44 aError = nsContentUtils::SetNodeTextContent(this, aText, true);
47 void HTMLTitleElement::CharacterDataChanged(nsIContent* aContent,
48 const CharacterDataChangeInfo&) {
49 SendTitleChangeEvent(false);
52 void HTMLTitleElement::ContentAppended(nsIContent* aFirstNewContent) {
53 SendTitleChangeEvent(false);
56 void HTMLTitleElement::ContentInserted(nsIContent* aChild) {
57 SendTitleChangeEvent(false);
60 void HTMLTitleElement::ContentRemoved(nsIContent* aChild,
61 nsIContent* aPreviousSibling) {
62 SendTitleChangeEvent(false);
65 nsresult HTMLTitleElement::BindToTree(BindContext& aContext, nsINode& aParent) {
66 // Let this fall through.
67 nsresult rv = nsGenericHTMLElement::BindToTree(aContext, aParent);
68 NS_ENSURE_SUCCESS(rv, rv);
70 SendTitleChangeEvent(true);
72 return NS_OK;
75 void HTMLTitleElement::UnbindFromTree(UnbindContext& aContext) {
76 SendTitleChangeEvent(false);
78 // Let this fall through.
79 nsGenericHTMLElement::UnbindFromTree(aContext);
82 void HTMLTitleElement::DoneAddingChildren(bool aHaveNotified) {
83 if (!aHaveNotified) {
84 SendTitleChangeEvent(false);
88 void HTMLTitleElement::SendTitleChangeEvent(bool aBound) {
89 Document* doc = GetUncomposedDoc();
90 if (doc) {
91 doc->NotifyPossibleTitleChange(aBound);
95 } // namespace mozilla::dom