1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/public/nsIDocumentObserver.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,342 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 +#ifndef nsIDocumentObserver_h___ 1.9 +#define nsIDocumentObserver_h___ 1.10 + 1.11 +#include "mozilla/EventStates.h" 1.12 +#include "nsISupports.h" 1.13 +#include "nsIMutationObserver.h" 1.14 + 1.15 +class nsIAtom; 1.16 +class nsIContent; 1.17 +class nsIStyleSheet; 1.18 +class nsIStyleRule; 1.19 +class nsString; 1.20 +class nsIDocument; 1.21 + 1.22 +#define NS_IDOCUMENT_OBSERVER_IID \ 1.23 +{ 0x900bc4bc, 0x8b6c, 0x4cba, \ 1.24 + { 0x82, 0xfa, 0x56, 0x8a, 0x80, 0xff, 0xfd, 0x3e } } 1.25 + 1.26 +typedef uint32_t nsUpdateType; 1.27 + 1.28 +#define UPDATE_CONTENT_MODEL 0x00000001 1.29 +#define UPDATE_STYLE 0x00000002 1.30 +#define UPDATE_ALL (UPDATE_CONTENT_MODEL | UPDATE_STYLE) 1.31 + 1.32 +// Document observer interface 1.33 +class nsIDocumentObserver : public nsIMutationObserver 1.34 +{ 1.35 +public: 1.36 + NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_OBSERVER_IID) 1.37 + 1.38 + /** 1.39 + * Notify that a content model update is beginning. This call can be 1.40 + * nested. 1.41 + */ 1.42 + virtual void BeginUpdate(nsIDocument *aDocument, 1.43 + nsUpdateType aUpdateType) = 0; 1.44 + 1.45 + /** 1.46 + * Notify that a content model update is finished. This call can be 1.47 + * nested. 1.48 + */ 1.49 + virtual void EndUpdate(nsIDocument *aDocument, nsUpdateType aUpdateType) = 0; 1.50 + 1.51 + /** 1.52 + * Notify the observer that a document load is beginning. 1.53 + */ 1.54 + virtual void BeginLoad(nsIDocument *aDocument) = 0; 1.55 + 1.56 + /** 1.57 + * Notify the observer that a document load has finished. Note that 1.58 + * the associated reflow of the document will be done <b>before</b> 1.59 + * EndLoad is invoked, not after. 1.60 + */ 1.61 + virtual void EndLoad(nsIDocument *aDocument) = 0; 1.62 + 1.63 + /** 1.64 + * Notification that the state of a content node has changed. 1.65 + * (ie: gained or lost focus, became active or hovered over) 1.66 + * This method is called automatically by content objects 1.67 + * when their state is changed (therefore there is normally 1.68 + * no need to invoke this method directly). The notification 1.69 + * is passed to any IDocumentObservers. The notification is 1.70 + * passed on to all of the document observers. <p> 1.71 + * 1.72 + * This notification is not sent when a piece of content is 1.73 + * added/removed from the document or the content itself changed 1.74 + * (the other notifications are used for that). 1.75 + * 1.76 + * @param aDocument The document being observed 1.77 + * @param aContent the piece of content that changed 1.78 + */ 1.79 + virtual void ContentStateChanged(nsIDocument* aDocument, 1.80 + nsIContent* aContent, 1.81 + mozilla::EventStates aStateMask) = 0; 1.82 + 1.83 + /** 1.84 + * Notification that the state of the document has changed. 1.85 + * 1.86 + * @param aDocument The document being observed 1.87 + * @param aStateMask the state that changed 1.88 + */ 1.89 + virtual void DocumentStatesChanged(nsIDocument* aDocument, 1.90 + mozilla::EventStates aStateMask) = 0; 1.91 + 1.92 + /** 1.93 + * A StyleSheet has just been added to the document. This method is 1.94 + * called automatically when a StyleSheet gets added to the 1.95 + * document, even if the stylesheet is not applicable. The 1.96 + * notification is passed on to all of the document observers. 1.97 + * 1.98 + * @param aDocument The document being observed 1.99 + * @param aStyleSheet the StyleSheet that has been added 1.100 + * @param aDocumentSheet True if sheet is in document's style sheet list, 1.101 + * false if sheet is not (i.e., UA or user sheet) 1.102 + */ 1.103 + virtual void StyleSheetAdded(nsIDocument *aDocument, 1.104 + nsIStyleSheet* aStyleSheet, 1.105 + bool aDocumentSheet) = 0; 1.106 + 1.107 + /** 1.108 + * A StyleSheet has just been removed from the document. This 1.109 + * method is called automatically when a StyleSheet gets removed 1.110 + * from the document, even if the stylesheet is not applicable. The 1.111 + * notification is passed on to all of the document observers. 1.112 + * 1.113 + * @param aDocument The document being observed 1.114 + * @param aStyleSheet the StyleSheet that has been removed 1.115 + * @param aDocumentSheet True if sheet is in document's style sheet list, 1.116 + * false if sheet is not (i.e., UA or user sheet) 1.117 + */ 1.118 + virtual void StyleSheetRemoved(nsIDocument *aDocument, 1.119 + nsIStyleSheet* aStyleSheet, 1.120 + bool aDocumentSheet) = 0; 1.121 + 1.122 + /** 1.123 + * A StyleSheet has just changed its applicable state. 1.124 + * This method is called automatically when the applicable state 1.125 + * of a StyleSheet gets changed. The style sheet passes this 1.126 + * notification to the document. The notification is passed on 1.127 + * to all of the document observers. 1.128 + * 1.129 + * @param aDocument The document being observed 1.130 + * @param aStyleSheet the StyleSheet that has changed state 1.131 + * @param aApplicable true if the sheet is applicable, false if 1.132 + * it is not applicable 1.133 + */ 1.134 + virtual void StyleSheetApplicableStateChanged(nsIDocument *aDocument, 1.135 + nsIStyleSheet* aStyleSheet, 1.136 + bool aApplicable) = 0; 1.137 + 1.138 + /** 1.139 + * A StyleRule has just been modified within a style sheet. 1.140 + * This method is called automatically when the rule gets 1.141 + * modified. The style sheet passes this notification to 1.142 + * the document. The notification is passed on to all of 1.143 + * the document observers. 1.144 + * 1.145 + * Since nsIStyleRule objects are immutable, there is a new object 1.146 + * replacing the old one. However, the use of this method (rather 1.147 + * than StyleRuleAdded and StyleRuleRemoved) implies that the new rule 1.148 + * matches the same elements and has the same priority (weight, 1.149 + * origin, specificity) as the old one. (However, if it is a CSS 1.150 + * style rule, there may be a change in whether it has an important 1.151 + * rule.) 1.152 + * 1.153 + * @param aDocument The document being observed 1.154 + * @param aStyleSheet the StyleSheet that contians the rule 1.155 + * @param aOldStyleRule The rule being removed. This rule may not be 1.156 + * fully valid anymore -- however, it can still 1.157 + * be used for pointer comparison and 1.158 + * |QueryInterface|. 1.159 + * @param aNewStyleRule The rule being added. 1.160 + */ 1.161 + virtual void StyleRuleChanged(nsIDocument *aDocument, 1.162 + nsIStyleSheet* aStyleSheet, 1.163 + nsIStyleRule* aOldStyleRule, 1.164 + nsIStyleRule* aNewStyleRule) = 0; 1.165 + 1.166 + /** 1.167 + * A StyleRule has just been added to a style sheet. 1.168 + * This method is called automatically when the rule gets 1.169 + * added to the sheet. The style sheet passes this 1.170 + * notification to the document. The notification is passed on 1.171 + * to all of the document observers. 1.172 + * 1.173 + * @param aDocument The document being observed 1.174 + * @param aStyleSheet the StyleSheet that has been modified 1.175 + * @param aStyleRule the rule that was added 1.176 + */ 1.177 + virtual void StyleRuleAdded(nsIDocument *aDocument, 1.178 + nsIStyleSheet* aStyleSheet, 1.179 + nsIStyleRule* aStyleRule) = 0; 1.180 + 1.181 + /** 1.182 + * A StyleRule has just been removed from a style sheet. 1.183 + * This method is called automatically when the rule gets 1.184 + * removed from the sheet. The style sheet passes this 1.185 + * notification to the document. The notification is passed on 1.186 + * to all of the document observers. 1.187 + * 1.188 + * @param aDocument The document being observed 1.189 + * @param aStyleSheet the StyleSheet that has been modified 1.190 + * @param aStyleRule the rule that was removed 1.191 + */ 1.192 + virtual void StyleRuleRemoved(nsIDocument *aDocument, 1.193 + nsIStyleSheet* aStyleSheet, 1.194 + nsIStyleRule* aStyleRule) = 0; 1.195 +}; 1.196 + 1.197 +NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocumentObserver, NS_IDOCUMENT_OBSERVER_IID) 1.198 + 1.199 +#define NS_DECL_NSIDOCUMENTOBSERVER_BEGINUPDATE \ 1.200 + virtual void BeginUpdate(nsIDocument* aDocument, \ 1.201 + nsUpdateType aUpdateType); 1.202 + 1.203 +#define NS_DECL_NSIDOCUMENTOBSERVER_ENDUPDATE \ 1.204 + virtual void EndUpdate(nsIDocument* aDocument, nsUpdateType aUpdateType); 1.205 + 1.206 +#define NS_DECL_NSIDOCUMENTOBSERVER_BEGINLOAD \ 1.207 + virtual void BeginLoad(nsIDocument* aDocument); 1.208 + 1.209 +#define NS_DECL_NSIDOCUMENTOBSERVER_ENDLOAD \ 1.210 + virtual void EndLoad(nsIDocument* aDocument); 1.211 + 1.212 +#define NS_DECL_NSIDOCUMENTOBSERVER_CONTENTSTATECHANGED \ 1.213 + virtual void ContentStateChanged(nsIDocument* aDocument, \ 1.214 + nsIContent* aContent, \ 1.215 + mozilla::EventStates aStateMask); 1.216 + 1.217 +#define NS_DECL_NSIDOCUMENTOBSERVER_DOCUMENTSTATESCHANGED \ 1.218 + virtual void DocumentStatesChanged(nsIDocument* aDocument, \ 1.219 + mozilla::EventStates aStateMask); 1.220 + 1.221 +#define NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETADDED \ 1.222 + virtual void StyleSheetAdded(nsIDocument* aDocument, \ 1.223 + nsIStyleSheet* aStyleSheet, \ 1.224 + bool aDocumentSheet); 1.225 + 1.226 +#define NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETREMOVED \ 1.227 + virtual void StyleSheetRemoved(nsIDocument* aDocument, \ 1.228 + nsIStyleSheet* aStyleSheet, \ 1.229 + bool aDocumentSheet); 1.230 + 1.231 +#define NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETAPPLICABLESTATECHANGED \ 1.232 + virtual void StyleSheetApplicableStateChanged(nsIDocument* aDocument, \ 1.233 + nsIStyleSheet* aStyleSheet,\ 1.234 + bool aApplicable); 1.235 + 1.236 +#define NS_DECL_NSIDOCUMENTOBSERVER_STYLERULECHANGED \ 1.237 + virtual void StyleRuleChanged(nsIDocument* aDocument, \ 1.238 + nsIStyleSheet* aStyleSheet, \ 1.239 + nsIStyleRule* aOldStyleRule, \ 1.240 + nsIStyleRule* aNewStyleRule); 1.241 + 1.242 +#define NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEADDED \ 1.243 + virtual void StyleRuleAdded(nsIDocument* aDocument, \ 1.244 + nsIStyleSheet* aStyleSheet, \ 1.245 + nsIStyleRule* aStyleRule); 1.246 + 1.247 +#define NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEREMOVED \ 1.248 + virtual void StyleRuleRemoved(nsIDocument* aDocument, \ 1.249 + nsIStyleSheet* aStyleSheet, \ 1.250 + nsIStyleRule* aStyleRule); 1.251 + 1.252 +#define NS_DECL_NSIDOCUMENTOBSERVER \ 1.253 + NS_DECL_NSIDOCUMENTOBSERVER_BEGINUPDATE \ 1.254 + NS_DECL_NSIDOCUMENTOBSERVER_ENDUPDATE \ 1.255 + NS_DECL_NSIDOCUMENTOBSERVER_BEGINLOAD \ 1.256 + NS_DECL_NSIDOCUMENTOBSERVER_ENDLOAD \ 1.257 + NS_DECL_NSIDOCUMENTOBSERVER_CONTENTSTATECHANGED \ 1.258 + NS_DECL_NSIDOCUMENTOBSERVER_DOCUMENTSTATESCHANGED \ 1.259 + NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETADDED \ 1.260 + NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETREMOVED \ 1.261 + NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETAPPLICABLESTATECHANGED \ 1.262 + NS_DECL_NSIDOCUMENTOBSERVER_STYLERULECHANGED \ 1.263 + NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEADDED \ 1.264 + NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEREMOVED \ 1.265 + NS_DECL_NSIMUTATIONOBSERVER 1.266 + 1.267 + 1.268 +#define NS_IMPL_NSIDOCUMENTOBSERVER_CORE_STUB(_class) \ 1.269 +void \ 1.270 +_class::BeginUpdate(nsIDocument* aDocument, nsUpdateType aUpdateType) \ 1.271 +{ \ 1.272 +} \ 1.273 +void \ 1.274 +_class::EndUpdate(nsIDocument* aDocument, nsUpdateType aUpdateType) \ 1.275 +{ \ 1.276 +} \ 1.277 +NS_IMPL_NSIMUTATIONOBSERVER_CORE_STUB(_class) 1.278 + 1.279 +#define NS_IMPL_NSIDOCUMENTOBSERVER_LOAD_STUB(_class) \ 1.280 +void \ 1.281 +_class::BeginLoad(nsIDocument* aDocument) \ 1.282 +{ \ 1.283 +} \ 1.284 +void \ 1.285 +_class::EndLoad(nsIDocument* aDocument) \ 1.286 +{ \ 1.287 +} 1.288 + 1.289 +#define NS_IMPL_NSIDOCUMENTOBSERVER_STATE_STUB(_class) \ 1.290 +void \ 1.291 +_class::ContentStateChanged(nsIDocument* aDocument, \ 1.292 + nsIContent* aContent, \ 1.293 + mozilla::EventStates aStateMask) \ 1.294 +{ \ 1.295 +} \ 1.296 + \ 1.297 +void \ 1.298 +_class::DocumentStatesChanged(nsIDocument* aDocument, \ 1.299 + mozilla::EventStates aStateMask) \ 1.300 +{ \ 1.301 +} 1.302 + 1.303 +#define NS_IMPL_NSIDOCUMENTOBSERVER_CONTENT(_class) \ 1.304 +NS_IMPL_NSIMUTATIONOBSERVER_CONTENT(_class) 1.305 + 1.306 +#define NS_IMPL_NSIDOCUMENTOBSERVER_STYLE_STUB(_class) \ 1.307 +void \ 1.308 +_class::StyleSheetAdded(nsIDocument* aDocument, \ 1.309 + nsIStyleSheet* aStyleSheet, \ 1.310 + bool aDocumentSheet) \ 1.311 +{ \ 1.312 +} \ 1.313 +void \ 1.314 +_class::StyleSheetRemoved(nsIDocument* aDocument, \ 1.315 + nsIStyleSheet* aStyleSheet, \ 1.316 + bool aDocumentSheet) \ 1.317 +{ \ 1.318 +} \ 1.319 +void \ 1.320 +_class::StyleSheetApplicableStateChanged(nsIDocument* aDocument, \ 1.321 + nsIStyleSheet* aStyleSheet, \ 1.322 + bool aApplicable) \ 1.323 +{ \ 1.324 +} \ 1.325 +void \ 1.326 +_class::StyleRuleChanged(nsIDocument* aDocument, \ 1.327 + nsIStyleSheet* aStyleSheet, \ 1.328 + nsIStyleRule* aOldStyleRule, \ 1.329 + nsIStyleRule* aNewStyleRule) \ 1.330 +{ \ 1.331 +} \ 1.332 +void \ 1.333 +_class::StyleRuleAdded(nsIDocument* aDocument, \ 1.334 + nsIStyleSheet* aStyleSheet, \ 1.335 + nsIStyleRule* aStyleRule) \ 1.336 +{ \ 1.337 +} \ 1.338 +void \ 1.339 +_class::StyleRuleRemoved(nsIDocument* aDocument, \ 1.340 + nsIStyleSheet* aStyleSheet, \ 1.341 + nsIStyleRule* aStyleRule) \ 1.342 +{ \ 1.343 +} 1.344 + 1.345 +#endif /* nsIDocumentObserver_h___ */