/content/base/public/nsIDocumentObserver.h

https://github.com/diogogmt/mozilla-central · C Header · 374 lines · 181 code · 39 blank · 154 comment · 0 complexity · 9cefaa449ed2af74d44764964273d3ac MD5 · raw file

  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * The Original Code is mozilla.org code.
  16. *
  17. * The Initial Developer of the Original Code is
  18. * Netscape Communications Corporation.
  19. * Portions created by the Initial Developer are Copyright (C) 1998
  20. * the Initial Developer. All Rights Reserved.
  21. *
  22. * Contributor(s):
  23. *
  24. * Alternatively, the contents of this file may be used under the terms of
  25. * either of the GNU General Public License Version 2 or later (the "GPL"),
  26. * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. * in which case the provisions of the GPL or the LGPL are applicable instead
  28. * of those above. If you wish to allow use of your version of this file only
  29. * under the terms of either the GPL or the LGPL, and not to allow others to
  30. * use your version of this file under the terms of the MPL, indicate your
  31. * decision by deleting the provisions above and replace them with the notice
  32. * and other provisions required by the GPL or the LGPL. If you do not delete
  33. * the provisions above, a recipient may use your version of this file under
  34. * the terms of any one of the MPL, the GPL or the LGPL.
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. #ifndef nsIDocumentObserver_h___
  38. #define nsIDocumentObserver_h___
  39. #include "nsISupports.h"
  40. #include "nsIMutationObserver.h"
  41. #include "nsEventStates.h"
  42. class nsIAtom;
  43. class nsIContent;
  44. class nsIStyleSheet;
  45. class nsIStyleRule;
  46. class nsString;
  47. class nsIDocument;
  48. #define NS_IDOCUMENT_OBSERVER_IID \
  49. { 0x900bc4bc, 0x8b6c, 0x4cba, \
  50. { 0x82, 0xfa, 0x56, 0x8a, 0x80, 0xff, 0xfd, 0x3e } }
  51. typedef PRUint32 nsUpdateType;
  52. #define UPDATE_CONTENT_MODEL 0x00000001
  53. #define UPDATE_STYLE 0x00000002
  54. #define UPDATE_ALL (UPDATE_CONTENT_MODEL | UPDATE_STYLE)
  55. // Document observer interface
  56. class nsIDocumentObserver : public nsIMutationObserver
  57. {
  58. public:
  59. NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_OBSERVER_IID)
  60. /**
  61. * Notify that a content model update is beginning. This call can be
  62. * nested.
  63. */
  64. virtual void BeginUpdate(nsIDocument *aDocument,
  65. nsUpdateType aUpdateType) = 0;
  66. /**
  67. * Notify that a content model update is finished. This call can be
  68. * nested.
  69. */
  70. virtual void EndUpdate(nsIDocument *aDocument, nsUpdateType aUpdateType) = 0;
  71. /**
  72. * Notify the observer that a document load is beginning.
  73. */
  74. virtual void BeginLoad(nsIDocument *aDocument) = 0;
  75. /**
  76. * Notify the observer that a document load has finished. Note that
  77. * the associated reflow of the document will be done <b>before</b>
  78. * EndLoad is invoked, not after.
  79. */
  80. virtual void EndLoad(nsIDocument *aDocument) = 0;
  81. /**
  82. * Notification that the state of a content node has changed.
  83. * (ie: gained or lost focus, became active or hovered over)
  84. * This method is called automatically by content objects
  85. * when their state is changed (therefore there is normally
  86. * no need to invoke this method directly). The notification
  87. * is passed to any IDocumentObservers. The notification is
  88. * passed on to all of the document observers. <p>
  89. *
  90. * This notification is not sent when a piece of content is
  91. * added/removed from the document or the content itself changed
  92. * (the other notifications are used for that).
  93. *
  94. * @param aDocument The document being observed
  95. * @param aContent the piece of content that changed
  96. */
  97. virtual void ContentStateChanged(nsIDocument* aDocument,
  98. nsIContent* aContent,
  99. nsEventStates aStateMask) = 0;
  100. /**
  101. * Notification that the state of the document has changed.
  102. *
  103. * @param aDocument The document being observed
  104. * @param aStateMask the state that changed
  105. */
  106. virtual void DocumentStatesChanged(nsIDocument* aDocument,
  107. nsEventStates aStateMask) = 0;
  108. /**
  109. * A StyleSheet has just been added to the document. This method is
  110. * called automatically when a StyleSheet gets added to the
  111. * document, even if the stylesheet is not applicable. The
  112. * notification is passed on to all of the document observers.
  113. *
  114. * @param aDocument The document being observed
  115. * @param aStyleSheet the StyleSheet that has been added
  116. * @param aDocumentSheet True if sheet is in document's style sheet list,
  117. * false if sheet is not (i.e., UA or user sheet)
  118. */
  119. virtual void StyleSheetAdded(nsIDocument *aDocument,
  120. nsIStyleSheet* aStyleSheet,
  121. bool aDocumentSheet) = 0;
  122. /**
  123. * A StyleSheet has just been removed from the document. This
  124. * method is called automatically when a StyleSheet gets removed
  125. * from the document, even if the stylesheet is not applicable. The
  126. * notification is passed on to all of the document observers.
  127. *
  128. * @param aDocument The document being observed
  129. * @param aStyleSheet the StyleSheet that has been removed
  130. * @param aDocumentSheet True if sheet is in document's style sheet list,
  131. * false if sheet is not (i.e., UA or user sheet)
  132. */
  133. virtual void StyleSheetRemoved(nsIDocument *aDocument,
  134. nsIStyleSheet* aStyleSheet,
  135. bool aDocumentSheet) = 0;
  136. /**
  137. * A StyleSheet has just changed its applicable state.
  138. * This method is called automatically when the applicable state
  139. * of a StyleSheet gets changed. The style sheet passes this
  140. * notification to the document. The notification is passed on
  141. * to all of the document observers.
  142. *
  143. * @param aDocument The document being observed
  144. * @param aStyleSheet the StyleSheet that has changed state
  145. * @param aApplicable true if the sheet is applicable, false if
  146. * it is not applicable
  147. */
  148. virtual void StyleSheetApplicableStateChanged(nsIDocument *aDocument,
  149. nsIStyleSheet* aStyleSheet,
  150. bool aApplicable) = 0;
  151. /**
  152. * A StyleRule has just been modified within a style sheet.
  153. * This method is called automatically when the rule gets
  154. * modified. The style sheet passes this notification to
  155. * the document. The notification is passed on to all of
  156. * the document observers.
  157. *
  158. * Since nsIStyleRule objects are immutable, there is a new object
  159. * replacing the old one. However, the use of this method (rather
  160. * than StyleRuleAdded and StyleRuleRemoved) implies that the new rule
  161. * matches the same elements and has the same priority (weight,
  162. * origin, specificity) as the old one. (However, if it is a CSS
  163. * style rule, there may be a change in whether it has an important
  164. * rule.)
  165. *
  166. * @param aDocument The document being observed
  167. * @param aStyleSheet the StyleSheet that contians the rule
  168. * @param aOldStyleRule The rule being removed. This rule may not be
  169. * fully valid anymore -- however, it can still
  170. * be used for pointer comparison and
  171. * |QueryInterface|.
  172. * @param aNewStyleRule The rule being added.
  173. */
  174. virtual void StyleRuleChanged(nsIDocument *aDocument,
  175. nsIStyleSheet* aStyleSheet,
  176. nsIStyleRule* aOldStyleRule,
  177. nsIStyleRule* aNewStyleRule) = 0;
  178. /**
  179. * A StyleRule has just been added to a style sheet.
  180. * This method is called automatically when the rule gets
  181. * added to the sheet. The style sheet passes this
  182. * notification to the document. The notification is passed on
  183. * to all of the document observers.
  184. *
  185. * @param aDocument The document being observed
  186. * @param aStyleSheet the StyleSheet that has been modified
  187. * @param aStyleRule the rule that was added
  188. */
  189. virtual void StyleRuleAdded(nsIDocument *aDocument,
  190. nsIStyleSheet* aStyleSheet,
  191. nsIStyleRule* aStyleRule) = 0;
  192. /**
  193. * A StyleRule has just been removed from a style sheet.
  194. * This method is called automatically when the rule gets
  195. * removed from the sheet. The style sheet passes this
  196. * notification to the document. The notification is passed on
  197. * to all of the document observers.
  198. *
  199. * @param aDocument The document being observed
  200. * @param aStyleSheet the StyleSheet that has been modified
  201. * @param aStyleRule the rule that was removed
  202. */
  203. virtual void StyleRuleRemoved(nsIDocument *aDocument,
  204. nsIStyleSheet* aStyleSheet,
  205. nsIStyleRule* aStyleRule) = 0;
  206. };
  207. NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocumentObserver, NS_IDOCUMENT_OBSERVER_IID)
  208. #define NS_DECL_NSIDOCUMENTOBSERVER_BEGINUPDATE \
  209. virtual void BeginUpdate(nsIDocument* aDocument, \
  210. nsUpdateType aUpdateType);
  211. #define NS_DECL_NSIDOCUMENTOBSERVER_ENDUPDATE \
  212. virtual void EndUpdate(nsIDocument* aDocument, nsUpdateType aUpdateType);
  213. #define NS_DECL_NSIDOCUMENTOBSERVER_BEGINLOAD \
  214. virtual void BeginLoad(nsIDocument* aDocument);
  215. #define NS_DECL_NSIDOCUMENTOBSERVER_ENDLOAD \
  216. virtual void EndLoad(nsIDocument* aDocument);
  217. #define NS_DECL_NSIDOCUMENTOBSERVER_CONTENTSTATECHANGED \
  218. virtual void ContentStateChanged(nsIDocument* aDocument, \
  219. nsIContent* aContent, \
  220. nsEventStates aStateMask);
  221. #define NS_DECL_NSIDOCUMENTOBSERVER_DOCUMENTSTATESCHANGED \
  222. virtual void DocumentStatesChanged(nsIDocument* aDocument, \
  223. nsEventStates aStateMask);
  224. #define NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETADDED \
  225. virtual void StyleSheetAdded(nsIDocument* aDocument, \
  226. nsIStyleSheet* aStyleSheet, \
  227. bool aDocumentSheet);
  228. #define NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETREMOVED \
  229. virtual void StyleSheetRemoved(nsIDocument* aDocument, \
  230. nsIStyleSheet* aStyleSheet, \
  231. bool aDocumentSheet);
  232. #define NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETAPPLICABLESTATECHANGED \
  233. virtual void StyleSheetApplicableStateChanged(nsIDocument* aDocument, \
  234. nsIStyleSheet* aStyleSheet,\
  235. bool aApplicable);
  236. #define NS_DECL_NSIDOCUMENTOBSERVER_STYLERULECHANGED \
  237. virtual void StyleRuleChanged(nsIDocument* aDocument, \
  238. nsIStyleSheet* aStyleSheet, \
  239. nsIStyleRule* aOldStyleRule, \
  240. nsIStyleRule* aNewStyleRule);
  241. #define NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEADDED \
  242. virtual void StyleRuleAdded(nsIDocument* aDocument, \
  243. nsIStyleSheet* aStyleSheet, \
  244. nsIStyleRule* aStyleRule);
  245. #define NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEREMOVED \
  246. virtual void StyleRuleRemoved(nsIDocument* aDocument, \
  247. nsIStyleSheet* aStyleSheet, \
  248. nsIStyleRule* aStyleRule);
  249. #define NS_DECL_NSIDOCUMENTOBSERVER \
  250. NS_DECL_NSIDOCUMENTOBSERVER_BEGINUPDATE \
  251. NS_DECL_NSIDOCUMENTOBSERVER_ENDUPDATE \
  252. NS_DECL_NSIDOCUMENTOBSERVER_BEGINLOAD \
  253. NS_DECL_NSIDOCUMENTOBSERVER_ENDLOAD \
  254. NS_DECL_NSIDOCUMENTOBSERVER_CONTENTSTATECHANGED \
  255. NS_DECL_NSIDOCUMENTOBSERVER_DOCUMENTSTATESCHANGED \
  256. NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETADDED \
  257. NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETREMOVED \
  258. NS_DECL_NSIDOCUMENTOBSERVER_STYLESHEETAPPLICABLESTATECHANGED \
  259. NS_DECL_NSIDOCUMENTOBSERVER_STYLERULECHANGED \
  260. NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEADDED \
  261. NS_DECL_NSIDOCUMENTOBSERVER_STYLERULEREMOVED \
  262. NS_DECL_NSIMUTATIONOBSERVER
  263. #define NS_IMPL_NSIDOCUMENTOBSERVER_CORE_STUB(_class) \
  264. void \
  265. _class::BeginUpdate(nsIDocument* aDocument, nsUpdateType aUpdateType) \
  266. { \
  267. } \
  268. void \
  269. _class::EndUpdate(nsIDocument* aDocument, nsUpdateType aUpdateType) \
  270. { \
  271. } \
  272. NS_IMPL_NSIMUTATIONOBSERVER_CORE_STUB(_class)
  273. #define NS_IMPL_NSIDOCUMENTOBSERVER_LOAD_STUB(_class) \
  274. void \
  275. _class::BeginLoad(nsIDocument* aDocument) \
  276. { \
  277. } \
  278. void \
  279. _class::EndLoad(nsIDocument* aDocument) \
  280. { \
  281. }
  282. #define NS_IMPL_NSIDOCUMENTOBSERVER_STATE_STUB(_class) \
  283. void \
  284. _class::ContentStateChanged(nsIDocument* aDocument, \
  285. nsIContent* aContent, \
  286. nsEventStates aStateMask) \
  287. { \
  288. } \
  289. \
  290. void \
  291. _class::DocumentStatesChanged(nsIDocument* aDocument, \
  292. nsEventStates aStateMask) \
  293. { \
  294. }
  295. #define NS_IMPL_NSIDOCUMENTOBSERVER_CONTENT(_class) \
  296. NS_IMPL_NSIMUTATIONOBSERVER_CONTENT(_class)
  297. #define NS_IMPL_NSIDOCUMENTOBSERVER_STYLE_STUB(_class) \
  298. void \
  299. _class::StyleSheetAdded(nsIDocument* aDocument, \
  300. nsIStyleSheet* aStyleSheet, \
  301. bool aDocumentSheet) \
  302. { \
  303. } \
  304. void \
  305. _class::StyleSheetRemoved(nsIDocument* aDocument, \
  306. nsIStyleSheet* aStyleSheet, \
  307. bool aDocumentSheet) \
  308. { \
  309. } \
  310. void \
  311. _class::StyleSheetApplicableStateChanged(nsIDocument* aDocument, \
  312. nsIStyleSheet* aStyleSheet, \
  313. bool aApplicable) \
  314. { \
  315. } \
  316. void \
  317. _class::StyleRuleChanged(nsIDocument* aDocument, \
  318. nsIStyleSheet* aStyleSheet, \
  319. nsIStyleRule* aOldStyleRule, \
  320. nsIStyleRule* aNewStyleRule) \
  321. { \
  322. } \
  323. void \
  324. _class::StyleRuleAdded(nsIDocument* aDocument, \
  325. nsIStyleSheet* aStyleSheet, \
  326. nsIStyleRule* aStyleRule) \
  327. { \
  328. } \
  329. void \
  330. _class::StyleRuleRemoved(nsIDocument* aDocument, \
  331. nsIStyleSheet* aStyleSheet, \
  332. nsIStyleRule* aStyleRule) \
  333. { \
  334. }
  335. #endif /* nsIDocumentObserver_h___ */