SVGTitleElement.cpp (2868B)
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/SVGTitleElement.h" 8 9 #include "mozilla/dom/Document.h" 10 #include "mozilla/dom/SVGTitleElementBinding.h" 11 12 NS_IMPL_NS_NEW_SVG_ELEMENT(Title) 13 14 namespace mozilla::dom { 15 16 JSObject* SVGTitleElement::WrapNode(JSContext* aCx, 17 JS::Handle<JSObject*> aGivenProto) { 18 return SVGTitleElement_Binding::Wrap(aCx, this, aGivenProto); 19 } 20 21 //---------------------------------------------------------------------- 22 // nsISupports methods 23 24 NS_IMPL_ISUPPORTS_INHERITED(SVGTitleElement, SVGTitleElementBase, 25 nsIMutationObserver) 26 27 //---------------------------------------------------------------------- 28 // Implementation 29 30 SVGTitleElement::SVGTitleElement( 31 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo) 32 : SVGTitleElementBase(std::move(aNodeInfo)) { 33 AddMutationObserver(this); 34 SetEnabledCallbacks(kCharacterDataChanged | kContentAppended | 35 kContentInserted | kContentWillBeRemoved); 36 } 37 38 void SVGTitleElement::CharacterDataChanged(nsIContent* aContent, 39 const CharacterDataChangeInfo&) { 40 SendTitleChangeEvent(false); 41 } 42 43 void SVGTitleElement::ContentAppended(nsIContent* aFirstNewContent, 44 const ContentAppendInfo&) { 45 SendTitleChangeEvent(false); 46 } 47 48 void SVGTitleElement::ContentInserted(nsIContent* aChild, 49 const ContentInsertInfo&) { 50 SendTitleChangeEvent(false); 51 } 52 53 void SVGTitleElement::ContentWillBeRemoved(nsIContent* aChild, 54 const ContentRemoveInfo&) { 55 SendTitleChangeEvent(false); 56 } 57 58 nsresult SVGTitleElement::BindToTree(BindContext& aContext, nsINode& aParent) { 59 // Let this fall through. 60 nsresult rv = SVGTitleElementBase::BindToTree(aContext, aParent); 61 NS_ENSURE_SUCCESS(rv, rv); 62 63 SendTitleChangeEvent(true); 64 65 return NS_OK; 66 } 67 68 void SVGTitleElement::UnbindFromTree(UnbindContext& aContext) { 69 SendTitleChangeEvent(false); 70 71 // Let this fall through. 72 SVGTitleElementBase::UnbindFromTree(aContext); 73 } 74 75 void SVGTitleElement::DoneAddingChildren(bool aHaveNotified) { 76 if (!aHaveNotified) { 77 SendTitleChangeEvent(false); 78 } 79 } 80 81 void SVGTitleElement::SendTitleChangeEvent(bool aBound) { 82 if (Document* doc = GetUncomposedDoc()) { 83 doc->NotifyPossibleTitleChange(aBound); 84 } 85 } 86 87 //---------------------------------------------------------------------- 88 // nsINode methods 89 90 NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGTitleElement) 91 92 } // namespace mozilla::dom