1 /* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 * 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 #ifndef nsChangeObserver_h_ 8 #define nsChangeObserver_h_ 9 10 class nsIContent; 11 class nsAtom; 12 namespace mozilla { 13 namespace dom { 14 class Document; 15 } 16 } // namespace mozilla 17 18 #define NS_DECL_CHANGEOBSERVER \ 19 void ObserveAttributeChanged(mozilla::dom::Document* aDocument, \ 20 nsIContent* aContent, nsAtom* aAttribute) \ 21 override; \ 22 void ObserveContentRemoved(mozilla::dom::Document* aDocument, \ 23 nsIContent* aContainer, nsIContent* aChild, \ 24 nsIContent* aPreviousChild) override; \ 25 void ObserveContentInserted(mozilla::dom::Document* aDocument, \ 26 nsIContent* aContainer, nsIContent* aChild) \ 27 override; 28 29 // Something that wants to be alerted to changes in attributes or changes in 30 // its corresponding content object. 31 // 32 // This interface is used by our menu code so we only have to have one 33 // nsIMutationObserver per menu subtree root (e.g. per menubar). 34 // 35 // Any class that implements this interface must take care to unregister itself 36 // on deletion. 37 // 38 // XXXmstange The methods below use nsIContent*. Eventually, the should be 39 // converted to use mozilla::dom::Element* instead. 40 class nsChangeObserver { 41 public: 42 // Called when the attribute aAttribute on the element aContent has changed. 43 // Only if aContent is being observed by this nsChangeObserver. 44 virtual void ObserveAttributeChanged(mozilla::dom::Document* aDocument, 45 nsIContent* aContent, 46 nsAtom* aAttribute) = 0; 47 48 // Called when aChild has been removed from its parent aContainer. 49 // aPreviousSibling is the old previous sibling of aChild. 50 // aContainer is always the old parent node of aChild and of aPreviousSibling. 51 // Only called if aContainer or aContainer's parent node are being observed 52 // by this nsChangeObserver. 53 // In other words: If you observe an element, ObserveContentRemoved is called 54 // if that element's children and grandchildren are removed. NOT if the 55 // observed element itself is removed. 56 virtual void ObserveContentRemoved(mozilla::dom::Document* aDocument, 57 nsIContent* aContainer, nsIContent* aChild, 58 nsIContent* aPreviousSibling) = 0; 59 60 // Called when aChild has been inserted into its new parent aContainer. 61 // Only called if aContainer or aContainer's parent node are being observed 62 // by this nsChangeObserver. 63 // In other words: If you observe an element, ObserveContentInserted is called 64 // if that element receives a new child or grandchild. NOT if the observed 65 // element itself is inserted anywhere. 66 virtual void ObserveContentInserted(mozilla::dom::Document* aDocument, 67 nsIContent* aContainer, 68 nsIContent* aChild) = 0; 69 }; 70 71 #endif // nsChangeObserver_h_ 72