michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #ifndef nsIDocumentObserver_h___ michael@0: #define nsIDocumentObserver_h___ michael@0: michael@0: #include "mozilla/EventStates.h" michael@0: #include "nsISupports.h" michael@0: #include "nsIMutationObserver.h" michael@0: michael@0: class nsIAtom; michael@0: class nsIContent; michael@0: class nsIStyleSheet; michael@0: class nsIStyleRule; michael@0: class nsString; michael@0: class nsIDocument; michael@0: michael@0: #define NS_IDOCUMENT_OBSERVER_IID \ michael@0: { 0x900bc4bc, 0x8b6c, 0x4cba, \ michael@0: { 0x82, 0xfa, 0x56, 0x8a, 0x80, 0xff, 0xfd, 0x3e } } michael@0: michael@0: typedef uint32_t nsUpdateType; michael@0: michael@0: #define UPDATE_CONTENT_MODEL 0x00000001 michael@0: #define UPDATE_STYLE 0x00000002 michael@0: #define UPDATE_ALL (UPDATE_CONTENT_MODEL | UPDATE_STYLE) michael@0: michael@0: // Document observer interface michael@0: class nsIDocumentObserver : public nsIMutationObserver michael@0: { michael@0: public: michael@0: NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_OBSERVER_IID) michael@0: michael@0: /** michael@0: * Notify that a content model update is beginning. This call can be michael@0: * nested. michael@0: */ michael@0: virtual void BeginUpdate(nsIDocument *aDocument, michael@0: nsUpdateType aUpdateType) = 0; michael@0: michael@0: /** michael@0: * Notify that a content model update is finished. This call can be michael@0: * nested. michael@0: */ michael@0: virtual void EndUpdate(nsIDocument *aDocument, nsUpdateType aUpdateType) = 0; michael@0: michael@0: /** michael@0: * Notify the observer that a document load is beginning. michael@0: */ michael@0: virtual void BeginLoad(nsIDocument *aDocument) = 0; michael@0: michael@0: /** michael@0: * Notify the observer that a document load has finished. Note that michael@0: * the associated reflow of the document will be done before michael@0: * EndLoad is invoked, not after. michael@0: */ michael@0: virtual void EndLoad(nsIDocument *aDocument) = 0; michael@0: michael@0: /** michael@0: * Notification that the state of a content node has changed. michael@0: * (ie: gained or lost focus, became active or hovered over) michael@0: * This method is called automatically by content objects michael@0: * when their state is changed (therefore there is normally michael@0: * no need to invoke this method directly). The notification michael@0: * is passed to any IDocumentObservers. The notification is michael@0: * passed on to all of the document observers.
michael@0: * michael@0: * This notification is not sent when a piece of content is michael@0: * added/removed from the document or the content itself changed michael@0: * (the other notifications are used for that). michael@0: * michael@0: * @param aDocument The document being observed michael@0: * @param aContent the piece of content that changed michael@0: */ michael@0: virtual void ContentStateChanged(nsIDocument* aDocument, michael@0: nsIContent* aContent, michael@0: mozilla::EventStates aStateMask) = 0; michael@0: michael@0: /** michael@0: * Notification that the state of the document has changed. michael@0: * michael@0: * @param aDocument The document being observed michael@0: * @param aStateMask the state that changed michael@0: */ michael@0: virtual void DocumentStatesChanged(nsIDocument* aDocument, michael@0: mozilla::EventStates aStateMask) = 0; michael@0: michael@0: /** michael@0: * A StyleSheet has just been added to the document. This method is michael@0: * called automatically when a StyleSheet gets added to the michael@0: * document, even if the stylesheet is not applicable. The michael@0: * notification is passed on to all of the document observers. michael@0: * michael@0: * @param aDocument The document being observed michael@0: * @param aStyleSheet the StyleSheet that has been added michael@0: * @param aDocumentSheet True if sheet is in document's style sheet list, michael@0: * false if sheet is not (i.e., UA or user sheet) michael@0: */ michael@0: virtual void StyleSheetAdded(nsIDocument *aDocument, michael@0: nsIStyleSheet* aStyleSheet, michael@0: bool aDocumentSheet) = 0; michael@0: michael@0: /** michael@0: * A StyleSheet has just been removed from the document. This michael@0: * method is called automatically when a StyleSheet gets removed michael@0: * from the document, even if the stylesheet is not applicable. The michael@0: * notification is passed on to all of the document observers. michael@0: * michael@0: * @param aDocument The document being observed michael@0: * @param aStyleSheet the StyleSheet that has been removed michael@0: * @param aDocumentSheet True if sheet is in document's style sheet list, michael@0: * false if sheet is not (i.e., UA or user sheet) michael@0: */ michael@0: virtual void StyleSheetRemoved(nsIDocument *aDocument, michael@0: nsIStyleSheet* aStyleSheet, michael@0: bool aDocumentSheet) = 0; michael@0: michael@0: /** michael@0: * A StyleSheet has just changed its applicable state. michael@0: * This method is called automatically when the applicable state michael@0: * of a StyleSheet gets changed. The style sheet passes this michael@0: * notification to the document. The notification is passed on michael@0: * to all of the document observers. michael@0: * michael@0: * @param aDocument The document being observed michael@0: * @param aStyleSheet the StyleSheet that has changed state michael@0: * @param aApplicable true if the sheet is applicable, false if michael@0: * it is not applicable michael@0: */ michael@0: virtual void StyleSheetApplicableStateChanged(nsIDocument *aDocument, michael@0: nsIStyleSheet* aStyleSheet, michael@0: bool aApplicable) = 0; michael@0: michael@0: /** michael@0: * A StyleRule has just been modified within a style sheet. michael@0: * This method is called automatically when the rule gets michael@0: * modified. The style sheet passes this notification to michael@0: * the document. The notification is passed on to all of michael@0: * the document observers. michael@0: * michael@0: * Since nsIStyleRule objects are immutable, there is a new object michael@0: * replacing the old one. However, the use of this method (rather michael@0: * than StyleRuleAdded and StyleRuleRemoved) implies that the new rule michael@0: * matches the same elements and has the same priority (weight, michael@0: * origin, specificity) as the old one. (However, if it is a CSS michael@0: * style rule, there may be a change in whether it has an important michael@0: * rule.) michael@0: * michael@0: * @param aDocument The document being observed michael@0: * @param aStyleSheet the StyleSheet that contians the rule michael@0: * @param aOldStyleRule The rule being removed. This rule may not be michael@0: * fully valid anymore -- however, it can still michael@0: * be used for pointer comparison and michael@0: * |QueryInterface|. michael@0: * @param aNewStyleRule The rule being added. michael@0: */ michael@0: virtual void StyleRuleChanged(nsIDocument *aDocument, michael@0: nsIStyleSheet* aStyleSheet, michael@0: nsIStyleRule* aOldStyleRule, michael@0: nsIStyleRule* aNewStyleRule) = 0; michael@0: michael@0: /** michael@0: * A StyleRule has just been added to a style sheet. michael@0: * This method is called automatically when the rule gets michael@0: * added to the sheet. The style sheet passes this michael@0: * notification to the document. The notification is passed on michael@0: * to all of the document observers. michael@0: * michael@0: * @param aDocument The document being observed michael@0: * @param aStyleSheet the StyleSheet that has been modified michael@0: * @param aStyleRule the rule that was added michael@0: */ michael@0: virtual void StyleRuleAdded(nsIDocument *aDocument, michael@0: nsIStyleSheet* aStyleSheet, michael@0: nsIStyleRule* aStyleRule) = 0; michael@0: michael@0: /** michael@0: * A StyleRule has just been removed from a style sheet. michael@0: * This method is called automatically when the rule gets michael@0: * removed from the sheet. The style sheet passes this michael@0: * notification to the document. The notification is passed on michael@0: * to all of the document observers. michael@0: * michael@0: * @param aDocument The document being observed michael@0: * @param aStyleSheet the StyleSheet that has been modified michael@0: * @param aStyleRule the rule that was removed michael@0: */ michael@0: virtual void StyleRuleRemoved(nsIDocument *aDocument, michael@0: nsIStyleSheet* aStyleSheet, michael@0: nsIStyleRule* aStyleRule) = 0; michael@0: }; michael@0: michael@0: NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocumentObserver, NS_IDOCUMENT_OBSERVER_IID) michael@0: michael@0: #define NS_DECL_NSIDOCUMENTOBSERVER_BEGINUPDATE \ michael@0: virtual void BeginUpdate(nsIDocument* aDocument, \ michael@0: nsUpdateType aUpdateType); michael@0: michael@0: #define NS_DECL_NSIDOCUMENTOBSERVER_ENDUPDATE \ michael@0: virtual void EndUpdate(nsIDocument* aDocument, nsUpdateType aUpdateType); michael@0: michael@0: #define NS_DECL_NSIDOCUMENTOBSERVER_BEGINLOAD \ michael@0: virtual void BeginLoad(nsIDocument* aDocument); michael@0: michael@0: #define NS_DECL_NSIDOCUMENTOBSERVER_ENDLOAD \ michael@0: virtual void EndLoad(nsIDocument* aDocument); michael@0: michael@0: #define NS_DECL_NSIDOCUMENTOBSERVER_CONTENTSTATECHANGED \ michael@0: virtual void ContentStateChanged(nsIDocument* aDocument, \ michael@0: nsIContent* aContent, \ michael@0: mozilla::EventStates aStateMask); michael@0: michael@0: #define NS_DECL_NSIDOCUMENTOBSERVER_DOCUMENTSTATESCHANGED \ michael@0: virtual void DocumentStatesChanged(nsIDocument* aDocument, \ michael@0: mozilla::EventStates aStateMask); michael@0: michael@0: #define NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETADDED \ michael@0: virtual void StyleSheetAdded(nsIDocument* aDocument, \ michael@0: nsIStyleSheet* aStyleSheet, \ michael@0: bool aDocumentSheet); michael@0: michael@0: #define NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETREMOVED \ michael@0: virtual void StyleSheetRemoved(nsIDocument* aDocument, \ michael@0: nsIStyleSheet* aStyleSheet, \ michael@0: bool aDocumentSheet); michael@0: michael@0: #define NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETAPPLICABLESTATECHANGED \ michael@0: virtual void StyleSheetApplicableStateChanged(nsIDocument* aDocument, \ michael@0: nsIStyleSheet* aStyleSheet,\ michael@0: bool aApplicable); michael@0: michael@0: #define NS_DECL_NSIDOCUMENTOBSERVER_STYLERULECHANGED \ michael@0: virtual void StyleRuleChanged(nsIDocument* aDocument, \ michael@0: nsIStyleSheet* aStyleSheet, \ michael@0: nsIStyleRule* aOldStyleRule, \ michael@0: nsIStyleRule* aNewStyleRule); michael@0: michael@0: #define NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEADDED \ michael@0: virtual void StyleRuleAdded(nsIDocument* aDocument, \ michael@0: nsIStyleSheet* aStyleSheet, \ michael@0: nsIStyleRule* aStyleRule); michael@0: michael@0: #define NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEREMOVED \ michael@0: virtual void StyleRuleRemoved(nsIDocument* aDocument, \ michael@0: nsIStyleSheet* aStyleSheet, \ michael@0: nsIStyleRule* aStyleRule); michael@0: michael@0: #define NS_DECL_NSIDOCUMENTOBSERVER \ michael@0: NS_DECL_NSIDOCUMENTOBSERVER_BEGINUPDATE \ michael@0: NS_DECL_NSIDOCUMENTOBSERVER_ENDUPDATE \ michael@0: NS_DECL_NSIDOCUMENTOBSERVER_BEGINLOAD \ michael@0: NS_DECL_NSIDOCUMENTOBSERVER_ENDLOAD \ michael@0: NS_DECL_NSIDOCUMENTOBSERVER_CONTENTSTATECHANGED \ michael@0: NS_DECL_NSIDOCUMENTOBSERVER_DOCUMENTSTATESCHANGED \ michael@0: NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETADDED \ michael@0: NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETREMOVED \ michael@0: NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETAPPLICABLESTATECHANGED \ michael@0: NS_DECL_NSIDOCUMENTOBSERVER_STYLERULECHANGED \ michael@0: NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEADDED \ michael@0: NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEREMOVED \ michael@0: NS_DECL_NSIMUTATIONOBSERVER michael@0: michael@0: michael@0: #define NS_IMPL_NSIDOCUMENTOBSERVER_CORE_STUB(_class) \ michael@0: void \ michael@0: _class::BeginUpdate(nsIDocument* aDocument, nsUpdateType aUpdateType) \ michael@0: { \ michael@0: } \ michael@0: void \ michael@0: _class::EndUpdate(nsIDocument* aDocument, nsUpdateType aUpdateType) \ michael@0: { \ michael@0: } \ michael@0: NS_IMPL_NSIMUTATIONOBSERVER_CORE_STUB(_class) michael@0: michael@0: #define NS_IMPL_NSIDOCUMENTOBSERVER_LOAD_STUB(_class) \ michael@0: void \ michael@0: _class::BeginLoad(nsIDocument* aDocument) \ michael@0: { \ michael@0: } \ michael@0: void \ michael@0: _class::EndLoad(nsIDocument* aDocument) \ michael@0: { \ michael@0: } michael@0: michael@0: #define NS_IMPL_NSIDOCUMENTOBSERVER_STATE_STUB(_class) \ michael@0: void \ michael@0: _class::ContentStateChanged(nsIDocument* aDocument, \ michael@0: nsIContent* aContent, \ michael@0: mozilla::EventStates aStateMask) \ michael@0: { \ michael@0: } \ michael@0: \ michael@0: void \ michael@0: _class::DocumentStatesChanged(nsIDocument* aDocument, \ michael@0: mozilla::EventStates aStateMask) \ michael@0: { \ michael@0: } michael@0: michael@0: #define NS_IMPL_NSIDOCUMENTOBSERVER_CONTENT(_class) \ michael@0: NS_IMPL_NSIMUTATIONOBSERVER_CONTENT(_class) michael@0: michael@0: #define NS_IMPL_NSIDOCUMENTOBSERVER_STYLE_STUB(_class) \ michael@0: void \ michael@0: _class::StyleSheetAdded(nsIDocument* aDocument, \ michael@0: nsIStyleSheet* aStyleSheet, \ michael@0: bool aDocumentSheet) \ michael@0: { \ michael@0: } \ michael@0: void \ michael@0: _class::StyleSheetRemoved(nsIDocument* aDocument, \ michael@0: nsIStyleSheet* aStyleSheet, \ michael@0: bool aDocumentSheet) \ michael@0: { \ michael@0: } \ michael@0: void \ michael@0: _class::StyleSheetApplicableStateChanged(nsIDocument* aDocument, \ michael@0: nsIStyleSheet* aStyleSheet, \ michael@0: bool aApplicable) \ michael@0: { \ michael@0: } \ michael@0: void \ michael@0: _class::StyleRuleChanged(nsIDocument* aDocument, \ michael@0: nsIStyleSheet* aStyleSheet, \ michael@0: nsIStyleRule* aOldStyleRule, \ michael@0: nsIStyleRule* aNewStyleRule) \ michael@0: { \ michael@0: } \ michael@0: void \ michael@0: _class::StyleRuleAdded(nsIDocument* aDocument, \ michael@0: nsIStyleSheet* aStyleSheet, \ michael@0: nsIStyleRule* aStyleRule) \ michael@0: { \ michael@0: } \ michael@0: void \ michael@0: _class::StyleRuleRemoved(nsIDocument* aDocument, \ michael@0: nsIStyleSheet* aStyleSheet, \ michael@0: nsIStyleRule* aStyleRule) \ michael@0: { \ michael@0: } michael@0: michael@0: #endif /* nsIDocumentObserver_h___ */