Bug 1265584 [wpt PR 11167] - [Gecko Bug 1265584] Move wptrunner marionette usage...
[gecko.git] / dom / html / HTMLTitleElement.cpp
blob0c8d9717a97562ffe7916e1a323fe0fc583d517a
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)
18 namespace mozilla {
19 namespace dom {
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,
32 nsIMutationObserver)
34 NS_IMPL_ELEMENT_CLONE(HTMLTitleElement)
36 JSObject*
37 HTMLTitleElement::WrapNode(JSContext* cx, JS::Handle<JSObject*> aGivenProto)
39 return HTMLTitleElement_Binding::Wrap(cx, this, aGivenProto);
42 void
43 HTMLTitleElement::GetText(DOMString& aText, ErrorResult& aError)
45 if (!nsContentUtils::GetNodeTextContent(this, false, aText, fallible)) {
46 aError = NS_ERROR_OUT_OF_MEMORY;
50 void
51 HTMLTitleElement::SetText(const nsAString& aText, ErrorResult& aError)
53 aError = nsContentUtils::SetNodeTextContent(this, aText, true);
56 void
57 HTMLTitleElement::CharacterDataChanged(nsIContent* aContent,
58 const CharacterDataChangeInfo&)
60 SendTitleChangeEvent(false);
63 void
64 HTMLTitleElement::ContentAppended(nsIContent* aFirstNewContent)
66 SendTitleChangeEvent(false);
69 void
70 HTMLTitleElement::ContentInserted(nsIContent* aChild)
72 SendTitleChangeEvent(false);
75 void
76 HTMLTitleElement::ContentRemoved(nsIContent* aChild,
77 nsIContent* aPreviousSibling)
79 SendTitleChangeEvent(false);
82 nsresult
83 HTMLTitleElement::BindToTree(nsIDocument *aDocument,
84 nsIContent *aParent,
85 nsIContent *aBindingParent,
86 bool aCompileEventHandlers)
88 // Let this fall through.
89 nsresult rv = nsGenericHTMLElement::BindToTree(aDocument, aParent,
90 aBindingParent,
91 aCompileEventHandlers);
92 NS_ENSURE_SUCCESS(rv, rv);
94 SendTitleChangeEvent(true);
96 return NS_OK;
99 void
100 HTMLTitleElement::UnbindFromTree(bool aDeep, bool aNullParent)
102 SendTitleChangeEvent(false);
104 // Let this fall through.
105 nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
108 void
109 HTMLTitleElement::DoneAddingChildren(bool aHaveNotified)
111 if (!aHaveNotified) {
112 SendTitleChangeEvent(false);
116 void
117 HTMLTitleElement::SendTitleChangeEvent(bool aBound)
119 nsIDocument* doc = GetUncomposedDoc();
120 if (doc) {
121 doc->NotifyPossibleTitleChange(aBound);
125 } // namespace dom
126 } // namespace mozilla