tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

HTMLTitleElement.cpp (2952B)


      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/ErrorResult.h"
     10 #include "mozilla/dom/Document.h"
     11 #include "mozilla/dom/HTMLTitleElementBinding.h"
     12 #include "nsContentUtils.h"
     13 #include "nsStyleConsts.h"
     14 
     15 NS_IMPL_NS_NEW_HTML_ELEMENT(Title)
     16 
     17 namespace mozilla::dom {
     18 
     19 HTMLTitleElement::HTMLTitleElement(
     20    already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
     21    : nsGenericHTMLElement(std::move(aNodeInfo)) {
     22  AddMutationObserver(this);
     23 }
     24 
     25 HTMLTitleElement::~HTMLTitleElement() = default;
     26 
     27 NS_IMPL_ISUPPORTS_INHERITED(HTMLTitleElement, nsGenericHTMLElement,
     28                            nsIMutationObserver)
     29 
     30 NS_IMPL_ELEMENT_CLONE(HTMLTitleElement)
     31 
     32 JSObject* HTMLTitleElement::WrapNode(JSContext* cx,
     33                                     JS::Handle<JSObject*> aGivenProto) {
     34  return HTMLTitleElement_Binding::Wrap(cx, this, aGivenProto);
     35 }
     36 
     37 void HTMLTitleElement::GetText(DOMString& aText, ErrorResult& aError) const {
     38  if (!nsContentUtils::GetNodeTextContent(this, false, aText, fallible)) {
     39    aError = NS_ERROR_OUT_OF_MEMORY;
     40  }
     41 }
     42 
     43 void HTMLTitleElement::SetText(const nsAString& aText, ErrorResult& aError) {
     44  aError = nsContentUtils::SetNodeTextContent(this, aText, true);
     45 }
     46 
     47 void HTMLTitleElement::CharacterDataChanged(nsIContent* aContent,
     48                                            const CharacterDataChangeInfo&) {
     49  SendTitleChangeEvent(false);
     50 }
     51 
     52 void HTMLTitleElement::ContentAppended(nsIContent* aFirstNewContent,
     53                                       const ContentAppendInfo&) {
     54  SendTitleChangeEvent(false);
     55 }
     56 
     57 void HTMLTitleElement::ContentInserted(nsIContent* aChild,
     58                                       const ContentInsertInfo&) {
     59  SendTitleChangeEvent(false);
     60 }
     61 
     62 void HTMLTitleElement::ContentWillBeRemoved(nsIContent* aChild,
     63                                            const ContentRemoveInfo&) {
     64  SendTitleChangeEvent(false);
     65 }
     66 
     67 nsresult HTMLTitleElement::BindToTree(BindContext& aContext, nsINode& aParent) {
     68  // Let this fall through.
     69  nsresult rv = nsGenericHTMLElement::BindToTree(aContext, aParent);
     70  NS_ENSURE_SUCCESS(rv, rv);
     71 
     72  SendTitleChangeEvent(true);
     73 
     74  return NS_OK;
     75 }
     76 
     77 void HTMLTitleElement::UnbindFromTree(UnbindContext& aContext) {
     78  SendTitleChangeEvent(false);
     79 
     80  // Let this fall through.
     81  nsGenericHTMLElement::UnbindFromTree(aContext);
     82 }
     83 
     84 void HTMLTitleElement::DoneAddingChildren(bool aHaveNotified) {
     85  if (!aHaveNotified) {
     86    SendTitleChangeEvent(false);
     87  }
     88 }
     89 
     90 void HTMLTitleElement::SendTitleChangeEvent(bool aBound) {
     91  if (Document* doc = GetUncomposedDoc()) {
     92    doc->NotifyPossibleTitleChange(aBound);
     93  }
     94 }
     95 
     96 }  // namespace mozilla::dom