PageRenderTime 76ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/mozilla/mozilla/dist/include/content/nsIDocument.h

http://kmbrasil.codeplex.com
C++ Header | 972 lines | 409 code | 135 blank | 428 comment | 4 complexity | 1245d19c740daa995e53ef7e77312e93 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, GPL-2.0
  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 nsIDocument_h___
  38. #define nsIDocument_h___
  39. #include "nsISupports.h"
  40. #include "nsEvent.h"
  41. #include "nsString.h"
  42. #include "nsCOMArray.h"
  43. #include "nsIDocumentObserver.h"
  44. #include "nsCOMPtr.h"
  45. #include "nsIURI.h"
  46. #include "nsIBindingManager.h"
  47. #include "nsWeakPtr.h"
  48. #include "nsIWeakReferenceUtils.h"
  49. #include "nsILoadGroup.h"
  50. #include "nsReadableUtils.h"
  51. #include "nsCRT.h"
  52. #include "mozFlushType.h"
  53. #include "nsPropertyTable.h"
  54. #include "nsHashSets.h"
  55. #include "nsAutoPtr.h"
  56. class nsIAtom;
  57. class nsIContent;
  58. class nsPresContext;
  59. class nsIPresShell;
  60. class nsIStreamListener;
  61. class nsIStreamObserver;
  62. class nsStyleSet;
  63. class nsIStyleSheet;
  64. class nsIStyleRule;
  65. class nsIViewManager;
  66. class nsIScriptGlobalObject;
  67. class nsPIDOMWindow;
  68. class nsIDOMEvent;
  69. class nsIDeviceContext;
  70. class nsIParser;
  71. class nsIDOMNode;
  72. class nsIDOMDocumentFragment;
  73. class nsILineBreaker;
  74. class nsIWordBreaker;
  75. class nsISelection;
  76. class nsIChannel;
  77. class nsIPrincipal;
  78. class nsIDOMDocument;
  79. class nsIDOMDocumentType;
  80. class nsIObserver;
  81. class nsISupportsArray;
  82. class nsIScriptLoader;
  83. class nsIContentSink;
  84. class nsIScriptEventManager;
  85. class nsNodeInfoManager;
  86. class nsICSSLoader;
  87. class nsHTMLStyleSheet;
  88. class nsIHTMLCSSStyleSheet;
  89. class nsILayoutHistoryState;
  90. // IID for the nsIDocument interface
  91. #define NS_IDOCUMENT_IID \
  92. { 0xd7c47f55, 0x480b, 0x4a60, \
  93. { 0x9a, 0xdf, 0xca, 0x49, 0x87, 0x3c, 0x71, 0xe2 } }
  94. // The base value for the content ID counter.
  95. // This counter is used by the document to
  96. // assign a monotonically increasing ID to each content
  97. // object it creates
  98. #define NS_CONTENT_ID_COUNTER_BASE 10000
  99. // Flag for AddStyleSheet().
  100. #define NS_STYLESHEET_FROM_CATALOG (1 << 0)
  101. //----------------------------------------------------------------------
  102. // Document interface
  103. class nsIDocument : public nsISupports
  104. {
  105. public:
  106. NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_IID)
  107. NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
  108. nsIDocument()
  109. : mCharacterSet(NS_LITERAL_CSTRING("ISO-8859-1")),
  110. mNextContentID(NS_CONTENT_ID_COUNTER_BASE),
  111. mNodeInfoManager(nsnull),
  112. mPartID(0)
  113. {
  114. }
  115. virtual nsresult StartDocumentLoad(const char* aCommand,
  116. nsIChannel* aChannel,
  117. nsILoadGroup* aLoadGroup,
  118. nsISupports* aContainer,
  119. nsIStreamListener **aDocListener,
  120. PRBool aReset,
  121. nsIContentSink* aSink = nsnull) = 0;
  122. virtual void StopDocumentLoad() = 0;
  123. /**
  124. * Return the title of the document. May return null.
  125. */
  126. const nsAFlatString& GetDocumentTitle() const
  127. {
  128. return mDocumentTitle;
  129. }
  130. /**
  131. * Return the URI for the document. May return null.
  132. */
  133. nsIURI* GetDocumentURI() const
  134. {
  135. return mDocumentURI;
  136. }
  137. void SetDocumentURI(nsIURI* aURI)
  138. {
  139. mDocumentURI = aURI;
  140. }
  141. /**
  142. * Return the principal responsible for this document.
  143. */
  144. virtual nsIPrincipal* GetPrincipal() = 0;
  145. /**
  146. * Set the principal responsible for this document.
  147. */
  148. virtual void SetPrincipal(nsIPrincipal *aPrincipal) = 0;
  149. /**
  150. * Return the LoadGroup for the document. May return null.
  151. */
  152. already_AddRefed<nsILoadGroup> GetDocumentLoadGroup() const
  153. {
  154. nsILoadGroup *group = nsnull;
  155. if (mDocumentLoadGroup)
  156. CallQueryReferent(mDocumentLoadGroup.get(), &group);
  157. return group;
  158. }
  159. /**
  160. * Return the base URI for relative URIs in the document (the document uri
  161. * unless it's overridden by SetBaseURI, HTML <base> tags, etc.). The
  162. * returned URI could be null if there is no document URI.
  163. */
  164. nsIURI* GetBaseURI() const
  165. {
  166. return mDocumentBaseURI ? mDocumentBaseURI : mDocumentURI;
  167. }
  168. virtual nsresult SetBaseURI(nsIURI* aURI) = 0;
  169. /**
  170. * Get/Set the base target of a link in a document.
  171. */
  172. virtual void GetBaseTarget(nsAString &aBaseTarget) const = 0;
  173. virtual void SetBaseTarget(const nsAString &aBaseTarget) = 0;
  174. /**
  175. * Return a standard name for the document's character set. This
  176. * will trigger a startDocumentLoad if necessary to answer the
  177. * question.
  178. */
  179. const nsAFlatCString& GetDocumentCharacterSet() const
  180. {
  181. return mCharacterSet;
  182. }
  183. /**
  184. * Set the document's character encoding. |aCharSetID| should be canonical.
  185. * That is, callers are responsible for the charset alias resolution.
  186. */
  187. virtual void SetDocumentCharacterSet(const nsACString& aCharSetID) = 0;
  188. PRInt32 GetDocumentCharacterSetSource() const
  189. {
  190. return mCharacterSetSource;
  191. }
  192. void SetDocumentCharacterSetSource(PRInt32 aCharsetSource)
  193. {
  194. mCharacterSetSource = aCharsetSource;
  195. }
  196. /**
  197. * Add an observer that gets notified whenever the charset changes.
  198. */
  199. virtual nsresult AddCharSetObserver(nsIObserver* aObserver) = 0;
  200. /**
  201. * Remove a charset observer.
  202. */
  203. virtual void RemoveCharSetObserver(nsIObserver* aObserver) = 0;
  204. /**
  205. * Get the Content-Type of this document.
  206. * (This will always return NS_OK, but has this signature to be compatible
  207. * with nsIDOMNSDocument::GetContentType())
  208. */
  209. NS_IMETHOD GetContentType(nsAString& aContentType) = 0;
  210. /**
  211. * Set the Content-Type of this document.
  212. */
  213. virtual void SetContentType(const nsAString& aContentType) = 0;
  214. /**
  215. * Return the language of this document.
  216. */
  217. void GetContentLanguage(nsAString& aContentLanguage) const
  218. {
  219. CopyASCIItoUCS2(mContentLanguage, aContentLanguage);
  220. }
  221. // The state BidiEnabled should persist across multiple views
  222. // (screen, print) of the same document.
  223. /**
  224. * Check if the document contains bidi data.
  225. * If so, we have to apply the Unicode Bidi Algorithm.
  226. */
  227. PRBool GetBidiEnabled() const
  228. {
  229. return mBidiEnabled;
  230. }
  231. /**
  232. * Indicate the document contains bidi data.
  233. * Currently, we cannot disable bidi, because once bidi is enabled,
  234. * it affects a frame model irreversibly, and plays even though
  235. * the document no longer contains bidi data.
  236. */
  237. void SetBidiEnabled(PRBool aBidiEnabled)
  238. {
  239. mBidiEnabled = aBidiEnabled;
  240. }
  241. /**
  242. * Return the Line Breaker for the document
  243. */
  244. virtual nsILineBreaker* GetLineBreaker() = 0;
  245. virtual void SetLineBreaker(nsILineBreaker* aLineBreaker) = 0;
  246. virtual nsIWordBreaker* GetWordBreaker() = 0;
  247. virtual void SetWordBreaker(nsIWordBreaker* aWordBreaker) = 0;
  248. /**
  249. * Access HTTP header data (this may also get set from other
  250. * sources, like HTML META tags).
  251. */
  252. virtual void GetHeaderData(nsIAtom* aHeaderField, nsAString& aData) const = 0;
  253. virtual void SetHeaderData(nsIAtom* aheaderField, const nsAString& aData) = 0;
  254. /**
  255. * Create a new presentation shell that will use aContext for its
  256. * presentation context (presentation contexts <b>must not</b> be
  257. * shared among multiple presentation shells).
  258. */
  259. virtual nsresult CreateShell(nsPresContext* aContext,
  260. nsIViewManager* aViewManager,
  261. nsStyleSet* aStyleSet,
  262. nsIPresShell** aInstancePtrResult) = 0;
  263. virtual PRBool DeleteShell(nsIPresShell* aShell) = 0;
  264. virtual PRUint32 GetNumberOfShells() const = 0;
  265. virtual nsIPresShell *GetShellAt(PRUint32 aIndex) const = 0;
  266. /**
  267. * Return the parent document of this document. Will return null
  268. * unless this document is within a compound document and has a
  269. * parent. Note that this parent chain may cross chrome boundaries.
  270. */
  271. nsIDocument *GetParentDocument() const
  272. {
  273. return mParentDocument;
  274. }
  275. /**
  276. * Set the parent document of this document.
  277. */
  278. void SetParentDocument(nsIDocument* aParent)
  279. {
  280. mParentDocument = aParent;
  281. }
  282. /**
  283. * Set the sub document for aContent to aSubDoc.
  284. */
  285. virtual nsresult SetSubDocumentFor(nsIContent *aContent,
  286. nsIDocument* aSubDoc) = 0;
  287. /**
  288. * Get the sub document for aContent
  289. */
  290. virtual nsIDocument *GetSubDocumentFor(nsIContent *aContent) const = 0;
  291. /**
  292. * Find the content node for which aDocument is a sub document.
  293. */
  294. virtual nsIContent *FindContentForSubDocument(nsIDocument *aDocument) const = 0;
  295. /**
  296. * Return the root content object for this document.
  297. */
  298. nsIContent *GetRootContent() const
  299. {
  300. return mRootContent;
  301. }
  302. /**
  303. * Set aRoot as the root content object for this document. If aRoot is
  304. * non-null, this should not be called on documents that currently have a
  305. * root content without first clearing out the document's children. Passing
  306. * in null to unbind the existing root content is allowed. This method will
  307. * bind aRoot to the document; the caller need not call BindToTree on aRoot.
  308. *
  309. * Note that this method never sends out nsIDocumentObserver notifications;
  310. * doing that is the caller's responsibility.
  311. */
  312. virtual nsresult SetRootContent(nsIContent* aRoot) = 0;
  313. /**
  314. * Get the direct children of the document - content in
  315. * the prolog, the root content and content in the epilog.
  316. */
  317. virtual nsIContent *GetChildAt(PRUint32 aIndex) const = 0;
  318. virtual PRInt32 IndexOf(nsIContent* aPossibleChild) const = 0;
  319. virtual PRUint32 GetChildCount() const = 0;
  320. /**
  321. * Accessors to the collection of stylesheets owned by this document.
  322. * Style sheets are ordered, most significant last.
  323. */
  324. /**
  325. * Get the number of stylesheets
  326. *
  327. * @return the number of stylesheets
  328. * @throws no exceptions
  329. */
  330. virtual PRInt32 GetNumberOfStyleSheets() const = 0;
  331. /**
  332. * Get a particular stylesheet
  333. * @param aIndex the index the stylesheet lives at. This is zero-based
  334. * @return the stylesheet at aIndex. Null if aIndex is out of range.
  335. * @throws no exceptions
  336. */
  337. virtual nsIStyleSheet* GetStyleSheetAt(PRInt32 aIndex) const = 0;
  338. /**
  339. * Insert a sheet at a particular spot in the stylesheet list (zero-based)
  340. * @param aSheet the sheet to insert
  341. * @param aIndex the index to insert at. This index will be
  342. * adjusted for the "special" sheets.
  343. * @throws no exceptions
  344. */
  345. virtual void InsertStyleSheetAt(nsIStyleSheet* aSheet, PRInt32 aIndex) = 0;
  346. /**
  347. * Get the index of a particular stylesheet. This will _always_
  348. * consider the "special" sheets as part of the sheet list.
  349. * @param aSheet the sheet to get the index of
  350. * @return aIndex the index of the sheet in the full list
  351. */
  352. virtual PRInt32 GetIndexOfStyleSheet(nsIStyleSheet* aSheet) const = 0;
  353. /**
  354. * Replace the stylesheets in aOldSheets with the stylesheets in
  355. * aNewSheets. The two lists must have equal length, and the sheet
  356. * at positon J in the first list will be replaced by the sheet at
  357. * position J in the second list. Some sheets in the second list
  358. * may be null; if so the corresponding sheets in the first list
  359. * will simply be removed.
  360. */
  361. virtual void UpdateStyleSheets(nsCOMArray<nsIStyleSheet>& aOldSheets,
  362. nsCOMArray<nsIStyleSheet>& aNewSheets) = 0;
  363. /**
  364. * Add a stylesheet to the document
  365. */
  366. virtual void AddStyleSheet(nsIStyleSheet* aSheet) = 0;
  367. /**
  368. * Remove a stylesheet from the document
  369. */
  370. virtual void RemoveStyleSheet(nsIStyleSheet* aSheet) = 0;
  371. /**
  372. * Notify the document that the applicable state of the sheet changed
  373. * and that observers should be notified and style sets updated
  374. */
  375. virtual void SetStyleSheetApplicableState(nsIStyleSheet* aSheet,
  376. PRBool aApplicable) = 0;
  377. /**
  378. * Just like the style sheet API, but for "catalog" sheets,
  379. * extra sheets inserted at the UA level.
  380. */
  381. virtual PRInt32 GetNumberOfCatalogStyleSheets() const = 0;
  382. virtual nsIStyleSheet* GetCatalogStyleSheetAt(PRInt32 aIndex) const = 0;
  383. virtual void AddCatalogStyleSheet(nsIStyleSheet* aSheet) = 0;
  384. virtual void EnsureCatalogStyleSheet(const char *aStyleSheetURI) = 0;
  385. /**
  386. * Get this document's CSSLoader. This is guaranteed to not return null.
  387. */
  388. nsICSSLoader* CSSLoader() const {
  389. return mCSSLoader;
  390. }
  391. /**
  392. * Get the channel that was passed to StartDocumentLoad or Reset for this
  393. * document. Note that this may be null in some cases (eg if
  394. * StartDocumentLoad or Reset were never called)
  395. */
  396. virtual nsIChannel* GetChannel() const = 0;
  397. /**
  398. * Get this document's attribute stylesheet. May return null if
  399. * there isn't one.
  400. */
  401. virtual nsHTMLStyleSheet* GetAttributeStyleSheet() const = 0;
  402. /**
  403. * Get this document's inline style sheet. May return null if there
  404. * isn't one
  405. */
  406. virtual nsIHTMLCSSStyleSheet* GetInlineStyleSheet() const = 0;
  407. /**
  408. * Get/set the object from which a document can get a script context
  409. * and scope. This is the context within which all scripts (during
  410. * document creation and during event handling) will run. Note that
  411. * this is the *inner* window object.
  412. */
  413. virtual nsIScriptGlobalObject* GetScriptGlobalObject() const = 0;
  414. virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject) = 0;
  415. /**
  416. * Return the window containing the document (the outer window).
  417. */
  418. virtual nsPIDOMWindow *GetWindow() = 0;
  419. /**
  420. * Get the script loader for this document
  421. */
  422. virtual nsIScriptLoader* GetScriptLoader() = 0;
  423. //----------------------------------------------------------------------
  424. // Document notification API's
  425. /**
  426. * Add a new observer of document change notifications. Whenever
  427. * content is changed, appended, inserted or removed the observers are
  428. * informed.
  429. */
  430. virtual void AddObserver(nsIDocumentObserver* aObserver) = 0;
  431. /**
  432. * Remove an observer of document change notifications. This will
  433. * return false if the observer cannot be found.
  434. */
  435. virtual PRBool RemoveObserver(nsIDocumentObserver* aObserver) = 0;
  436. // Observation hooks used to propagate notifications to document observers.
  437. // BeginUpdate must be called before any batch of modifications of the
  438. // content model or of style data, EndUpdate must be called afterward.
  439. // To make this easy and painless, use the mozAutoDocUpdate helper class.
  440. virtual void BeginUpdate(nsUpdateType aUpdateType) = 0;
  441. virtual void EndUpdate(nsUpdateType aUpdateType) = 0;
  442. virtual void BeginLoad() = 0;
  443. virtual void EndLoad() = 0;
  444. virtual void CharacterDataChanged(nsIContent* aContent, PRBool aAppend) = 0;
  445. // notify that one or two content nodes changed state
  446. // either may be nsnull, but not both
  447. virtual void ContentStatesChanged(nsIContent* aContent1,
  448. nsIContent* aContent2,
  449. PRInt32 aStateMask) = 0;
  450. virtual void AttributeWillChange(nsIContent* aChild,
  451. PRInt32 aNameSpaceID,
  452. nsIAtom* aAttribute) = 0;
  453. virtual void AttributeChanged(nsIContent* aChild,
  454. PRInt32 aNameSpaceID,
  455. nsIAtom* aAttribute,
  456. PRInt32 aModType) = 0;
  457. virtual void ContentAppended(nsIContent* aContainer,
  458. PRInt32 aNewIndexInContainer) = 0;
  459. virtual void ContentInserted(nsIContent* aContainer,
  460. nsIContent* aChild,
  461. PRInt32 aIndexInContainer) = 0;
  462. virtual void ContentRemoved(nsIContent* aContainer,
  463. nsIContent* aChild,
  464. PRInt32 aIndexInContainer) = 0;
  465. // Observation hooks for style data to propagate notifications
  466. // to document observers
  467. virtual void StyleRuleChanged(nsIStyleSheet* aStyleSheet,
  468. nsIStyleRule* aOldStyleRule,
  469. nsIStyleRule* aNewStyleRule) = 0;
  470. virtual void StyleRuleAdded(nsIStyleSheet* aStyleSheet,
  471. nsIStyleRule* aStyleRule) = 0;
  472. virtual void StyleRuleRemoved(nsIStyleSheet* aStyleSheet,
  473. nsIStyleRule* aStyleRule) = 0;
  474. virtual nsresult HandleDOMEvent(nsPresContext* aPresContext,
  475. nsEvent* aEvent, nsIDOMEvent** aDOMEvent,
  476. PRUint32 aFlags,
  477. nsEventStatus* aEventStatus) = 0;
  478. /**
  479. * Flush notifications for this document and its parent documents
  480. * (since those may affect the layout of this one).
  481. */
  482. virtual void FlushPendingNotifications(mozFlushType aType) = 0;
  483. PRInt32 GetAndIncrementContentID()
  484. {
  485. return mNextContentID++;
  486. }
  487. nsIBindingManager* BindingManager() const
  488. {
  489. return mBindingManager;
  490. }
  491. /**
  492. * Only to be used inside Gecko, you can't really do anything with the
  493. * pointer outside Gecko anyway.
  494. */
  495. nsNodeInfoManager* NodeInfoManager() const
  496. {
  497. return mNodeInfoManager;
  498. }
  499. /**
  500. * Reset the document using the given channel and loadgroup. This works
  501. * like ResetToURI, but also sets the document's channel to aChannel.
  502. */
  503. virtual void Reset(nsIChannel* aChannel, nsILoadGroup* aLoadGroup) = 0;
  504. /**
  505. * Reset this document to aURI and aLoadGroup. aURI must not be null.
  506. */
  507. virtual void ResetToURI(nsIURI *aURI, nsILoadGroup* aLoadGroup) = 0;
  508. /**
  509. * Set the container (docshell) for this document.
  510. */
  511. void SetContainer(nsISupports *aContainer)
  512. {
  513. mDocumentContainer = do_GetWeakReference(aContainer);
  514. }
  515. /**
  516. * Get the container (docshell) for this document.
  517. */
  518. already_AddRefed<nsISupports> GetContainer() const
  519. {
  520. nsISupports* container = nsnull;
  521. if (mDocumentContainer)
  522. CallQueryReferent(mDocumentContainer.get(), &container);
  523. return container;
  524. }
  525. virtual nsIScriptEventManager* GetScriptEventManager() = 0;
  526. /**
  527. * Set and get XML declaration. If aVersion is null there is no declaration.
  528. * aStandalone takes values -1, 0 and 1 indicating respectively that there
  529. * was no standalone parameter in the declaration, that it was given as no,
  530. * or that it was given as yes.
  531. */
  532. virtual void SetXMLDeclaration(const PRUnichar *aVersion,
  533. const PRUnichar *aEncoding,
  534. const PRInt32 aStandalone) = 0;
  535. virtual void GetXMLDeclaration(nsAString& aVersion,
  536. nsAString& aEncoding,
  537. nsAString& Standalone) = 0;
  538. virtual PRBool IsCaseSensitive()
  539. {
  540. return PR_TRUE;
  541. }
  542. virtual PRBool IsScriptEnabled() = 0;
  543. virtual nsresult AddXMLEventsContent(nsIContent * aXMLEventsElement) = 0;
  544. virtual PRBool IsLoadedAsData()
  545. {
  546. return PR_FALSE;
  547. }
  548. /**
  549. * Create an element with the specified name, prefix and namespace ID.
  550. * If aDocumentDefaultType is true we create an element of the default type
  551. * for that document (currently XHTML in HTML documents and XUL in XUL
  552. * documents), otherwise we use the type specified by the namespace ID.
  553. */
  554. virtual nsresult CreateElem(nsIAtom *aName, nsIAtom *aPrefix,
  555. PRInt32 aNamespaceID,
  556. PRBool aDocumentDefaultType,
  557. nsIContent** aResult) = 0;
  558. /**
  559. * Get the security info (i.e. SSL state etc) that the document got
  560. * from the channel/document that created the content of the
  561. * document.
  562. *
  563. * @see nsIChannel
  564. */
  565. nsISupports *GetSecurityInfo()
  566. {
  567. return mSecurityInfo;
  568. }
  569. /**
  570. * Returns the default namespace ID used for elements created in this
  571. * document.
  572. */
  573. virtual PRInt32 GetDefaultNamespaceID() const = 0;
  574. virtual void* GetProperty(nsIAtom *aPropertyName,
  575. nsresult *aStatus = nsnull) const = 0;
  576. virtual nsresult SetProperty(nsIAtom *aPropertyName,
  577. void *aValue,
  578. NSPropertyDtorFunc aDtor = nsnull) = 0;
  579. virtual nsresult DeleteProperty(nsIAtom *aPropertyName) = 0;
  580. virtual void* UnsetProperty(nsIAtom *aPropertyName,
  581. nsresult *aStatus = nsnull) = 0;
  582. nsPropertyTable* PropertyTable() { return &mPropertyTable; }
  583. /**
  584. * Sets the ID used to identify this part of the multipart document
  585. */
  586. void SetPartID(PRUint32 aID) {
  587. mPartID = aID;
  588. }
  589. /**
  590. * Return the ID used to identify this part of the multipart document
  591. */
  592. PRUint32 GetPartID() const {
  593. return mPartID;
  594. }
  595. /**
  596. * Sanitize the document by resetting all input elements and forms that have
  597. * autocomplete=off to their default values.
  598. */
  599. virtual nsresult Sanitize() = 0;
  600. /**
  601. * Enumerate all subdocuments.
  602. * The enumerator callback should return PR_TRUE to continue enumerating, or
  603. * PR_FALSE to stop.
  604. */
  605. typedef PRBool (*nsSubDocEnumFunc)(nsIDocument *aDocument, void *aData);
  606. virtual void EnumerateSubDocuments(nsSubDocEnumFunc aCallback,
  607. void *aData) = 0;
  608. /**
  609. * Check whether it is safe to cache the presentation of this document
  610. * and all of its subdocuments. This method checks the following conditions
  611. * recursively:
  612. * - Some document types, such as plugin documents, cannot be safely cached.
  613. * - If there are any pending requests, we don't allow the presentation
  614. * to be cached. Ideally these requests would be suspended and resumed,
  615. * but that is difficult in some cases, such as XMLHttpRequest.
  616. * - If there are any beforeunload or unload listeners, we must fire them
  617. * for correctness, but this likely puts the document into a state where
  618. * it would not function correctly if restored.
  619. *
  620. * |aNewRequest| should be the request for a new document which will
  621. * replace this document in the docshell. The new document's request
  622. * will be ignored when checking for active requests. If there is no
  623. * request associated with the new document, this parameter may be null.
  624. */
  625. virtual PRBool CanSavePresentation(nsIRequest *aNewRequest) = 0;
  626. /**
  627. * Notify the document that its associated ContentViewer is being destroyed.
  628. * This releases circular references so that the document can go away.
  629. * Destroy() is only called on documents that have a content viewer.
  630. */
  631. virtual void Destroy() = 0;
  632. /**
  633. * Get the layout history state that should be used to save and restore state
  634. * for nodes in this document. This may return null; if that happens state
  635. * saving and restoration is not possible.
  636. */
  637. virtual already_AddRefed<nsILayoutHistoryState> GetLayoutHistoryState() const = 0;
  638. /**
  639. * Methods that can be used to prevent onload firing while an event that
  640. * should block onload is posted. onload is guaranteed to not fire until
  641. * either all calls to BlockOnload() have been matched by calls to
  642. * UnblockOnload() or the load has been stopped altogether (by the user
  643. * pressing the Stop button, say). onload may fire synchronously from inside
  644. * the UnblockOnload() call.
  645. */
  646. virtual void BlockOnload() = 0;
  647. virtual void UnblockOnload() = 0;
  648. /**
  649. * Notification that the page has been shown, for documents which are loaded
  650. * into a DOM window. This corresponds to the completion of document load,
  651. * or to the page's presentation being restored into an existing DOM window.
  652. * This notification fires applicable DOM events to the content window. See
  653. * nsIDOMPageTransitionEvent.idl for a description of the |aPersisted|
  654. * parameter.
  655. */
  656. virtual void OnPageShow(PRBool aPersisted) = 0;
  657. /**
  658. * Notification that the page has been hidden, for documents which are loaded
  659. * into a DOM window. This corresponds to the unloading of the document, or
  660. * to the document's presentation being saved but removed from an existing
  661. * DOM window. This notification fires applicable DOM events to the content
  662. * window. See nsIDOMPageTransitionEvent.idl for a description of the
  663. * |aPersisted| parameter.
  664. */
  665. virtual void OnPageHide(PRBool aPersisted) = 0;
  666. /*
  667. * We record the set of links in the document that are relevant to
  668. * style.
  669. */
  670. /**
  671. * Notification that an element is a link with a given URI that is
  672. * relevant to style.
  673. */
  674. virtual void AddStyleRelevantLink(nsIContent* aContent, nsIURI* aURI) = 0;
  675. /**
  676. * Notification that an element is a link and its URI might have been
  677. * changed or the element removed. If the element is still a link relevant
  678. * to style, then someone must ensure that AddStyleRelevantLink is
  679. * (eventually) called on it again.
  680. */
  681. virtual void ForgetLink(nsIContent* aContent) = 0;
  682. /**
  683. * Notification that the visitedness state of a URI has been changed
  684. * and style related to elements linking to that URI should be updated.
  685. */
  686. virtual void NotifyURIVisitednessChanged(nsIURI* aURI) = 0;
  687. protected:
  688. ~nsIDocument()
  689. {
  690. // XXX The cleanup of mNodeInfoManager (calling DropDocumentReference and
  691. // releasing it) happens in the nsDocument destructor. We'd prefer to
  692. // do it here but nsNodeInfoManager is a concrete class that we don't
  693. // want to expose to users of the nsIDocument API outside of Gecko.
  694. }
  695. nsString mDocumentTitle;
  696. nsCOMPtr<nsIURI> mDocumentURI;
  697. nsCOMPtr<nsIURI> mDocumentBaseURI;
  698. nsWeakPtr mDocumentLoadGroup;
  699. nsWeakPtr mDocumentContainer;
  700. nsCString mCharacterSet;
  701. PRInt32 mCharacterSetSource;
  702. // This is just a weak pointer; the parent document owns its children.
  703. nsIDocument* mParentDocument;
  704. // A weak reference to the only child element, or null if no
  705. // such element exists.
  706. nsIContent* mRootContent;
  707. // A content ID counter used to give a monotonically increasing ID
  708. // to the content objects in the document's content model
  709. PRInt32 mNextContentID;
  710. nsCOMPtr<nsIBindingManager> mBindingManager;
  711. nsNodeInfoManager* mNodeInfoManager; // [STRONG]
  712. nsICSSLoader* mCSSLoader; // [STRONG; not a COMPtr to avoid
  713. // including nsICSSLoader.h; the ownership
  714. // is managed by nsDocument]
  715. // Table of element properties for this document.
  716. nsPropertyTable mPropertyTable;
  717. // True if BIDI is enabled.
  718. PRBool mBidiEnabled;
  719. nsXPIDLCString mContentLanguage;
  720. nsCString mContentType;
  721. // The document's security info
  722. nsCOMPtr<nsISupports> mSecurityInfo;
  723. // if this document is part of a multipart document,
  724. // the ID can be used to distinguish it from the other parts.
  725. PRUint32 mPartID;
  726. };
  727. // IID for the nsIDocument_MOZILLA_1_8_0_BRANCH interface
  728. #define NS_IDOCUMENT_MOZILLA_1_8_0_BRANCH_IID \
  729. { 0x7d001ad2, 0x01ac, 0x4bf2, \
  730. { 0xb8, 0x3a, 0x50, 0xaa, 0xed, 0xc6, 0x1d, 0xfa } }
  731. class nsIDocument_MOZILLA_1_8_0_BRANCH : public nsISupports
  732. {
  733. public:
  734. NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_MOZILLA_1_8_0_BRANCH_IID)
  735. /**
  736. * Get the object that is used as the scope for all of the content
  737. * wrappers whose owner document is this document. Unlike the script global
  738. * object, this will only return null when the global object for this
  739. * document is truly gone. Use this object when you're trying to find a
  740. * content wrapper in XPConnect.
  741. */
  742. virtual nsIScriptGlobalObject* GetScopeObject() = 0;
  743. /**
  744. * Remove a child from this document.
  745. *
  746. * @param aIndex the index of the child to remove
  747. * @param aNotify whether to notify the document that the remove has
  748. * occurred
  749. */
  750. virtual nsresult RemoveChildAt(PRUint32 aIndex, PRBool aNotify) = 0;
  751. };
  752. // IID for the nsIDocument_MOZILLA_1_8_BRANCH2 interface
  753. #define NS_IDOCUMENT_MOZILLA_1_8_BRANCH2_IID \
  754. { 0x095024b5, 0x57d1, 0x4117, \
  755. { 0xb6, 0x02, 0x5c, 0x6d, 0xf2, 0x81, 0xe0, 0xba } }
  756. class nsIDocument_MOZILLA_1_8_BRANCH2 : public nsISupports
  757. {
  758. public:
  759. NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDOCUMENT_MOZILLA_1_8_BRANCH2_IID)
  760. nsIDocument_MOZILLA_1_8_BRANCH2() :
  761. mIsInitialDocumentInWindow(PR_FALSE)
  762. {
  763. }
  764. /**
  765. * Ask this document whether it's the initial document in its window.
  766. */
  767. PRBool IsInitialDocument() const
  768. {
  769. return mIsInitialDocumentInWindow;
  770. }
  771. /**
  772. * Tell this document that it's the initial document in its window. See
  773. * comments on mIsInitialDocumentInWindow for when this should be called.
  774. */
  775. void SetIsInitialDocument(PRBool aIsInitialDocument)
  776. {
  777. mIsInitialDocumentInWindow = aIsInitialDocument;
  778. }
  779. protected:
  780. // True if this document is the initial document for a window. This should
  781. // basically be true only for documents that exist in newly-opened windows or
  782. // documents created to satisfy a GetDocument() on a window when there's no
  783. // document in it.
  784. PRBool mIsInitialDocumentInWindow;
  785. };
  786. /**
  787. * Helper class to automatically handle batching of document updates. This
  788. * class will call BeginUpdate on construction and EndUpdate on destruction on
  789. * the given document with the given update type. The document could be null,
  790. * in which case no updates will be called. The constructor also takes a
  791. * boolean that can be set to false to prevent notifications.
  792. */
  793. class mozAutoDocUpdate
  794. {
  795. public:
  796. mozAutoDocUpdate(nsIDocument* aDocument, nsUpdateType aUpdateType,
  797. PRBool aNotify) :
  798. mDocument(aNotify ? aDocument : nsnull),
  799. mUpdateType(aUpdateType)
  800. {
  801. if (mDocument) {
  802. mDocument->BeginUpdate(mUpdateType);
  803. }
  804. }
  805. ~mozAutoDocUpdate()
  806. {
  807. if (mDocument) {
  808. mDocument->EndUpdate(mUpdateType);
  809. }
  810. }
  811. private:
  812. nsCOMPtr<nsIDocument> mDocument;
  813. nsUpdateType mUpdateType;
  814. };
  815. // XXX These belong somewhere else
  816. nsresult
  817. NS_NewHTMLDocument(nsIDocument** aInstancePtrResult);
  818. nsresult
  819. NS_NewXMLDocument(nsIDocument** aInstancePtrResult);
  820. #ifdef MOZ_SVG
  821. nsresult
  822. NS_NewSVGDocument(nsIDocument** aInstancePtrResult);
  823. #endif
  824. nsresult
  825. NS_NewImageDocument(nsIDocument** aInstancePtrResult);
  826. nsresult
  827. NS_NewDocumentFragment(nsIDOMDocumentFragment** aInstancePtrResult,
  828. nsNodeInfoManager *aNodeInfoManager);
  829. nsresult
  830. NS_NewDOMDocument(nsIDOMDocument** aInstancePtrResult,
  831. const nsAString& aNamespaceURI,
  832. const nsAString& aQualifiedName,
  833. nsIDOMDocumentType* aDoctype,
  834. nsIURI* aBaseURI);
  835. nsresult
  836. NS_NewPluginDocument(nsIDocument** aInstancePtrResult);
  837. #endif /* nsIDocument_h___ */