SVGDocumentWrapper.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. /* This class wraps an SVG document, for use by VectorImage objects. */
  6. #ifndef mozilla_image_SVGDocumentWrapper_h
  7. #define mozilla_image_SVGDocumentWrapper_h
  8. #include "mozilla/Attributes.h"
  9. #include "nsCOMPtr.h"
  10. #include "nsIStreamListener.h"
  11. #include "nsIObserver.h"
  12. #include "nsIContentViewer.h"
  13. #include "nsWeakReference.h"
  14. #include "nsSize.h"
  15. class nsIPresShell;
  16. class nsIRequest;
  17. class nsILoadGroup;
  18. class nsIFrame;
  19. #define OBSERVER_SVC_CID "@mozilla.org/observer-service;1"
  20. // undef the GetCurrentTime macro defined in WinBase.h from the MS Platform SDK
  21. #undef GetCurrentTime
  22. namespace mozilla {
  23. namespace dom {
  24. class SVGSVGElement;
  25. } // namespace dom
  26. namespace image {
  27. class SVGDocumentWrapper final : public nsIStreamListener,
  28. public nsIObserver,
  29. nsSupportsWeakReference
  30. {
  31. public:
  32. SVGDocumentWrapper();
  33. NS_DECL_ISUPPORTS
  34. NS_DECL_NSISTREAMLISTENER
  35. NS_DECL_NSIREQUESTOBSERVER
  36. NS_DECL_NSIOBSERVER
  37. enum Dimension {
  38. eWidth,
  39. eHeight
  40. };
  41. /**
  42. * Returns the wrapped document, or nullptr on failure. (No AddRef.)
  43. */
  44. nsIDocument* GetDocument();
  45. /**
  46. * Returns the root <svg> element for the wrapped document, or nullptr on
  47. * failure.
  48. */
  49. mozilla::dom::SVGSVGElement* GetRootSVGElem();
  50. /**
  51. * Returns the root nsIFrame* for the wrapped document, or nullptr on failure.
  52. *
  53. * @return the root nsIFrame* for the wrapped document, or nullptr on failure.
  54. */
  55. nsIFrame* GetRootLayoutFrame();
  56. /**
  57. * Returns (by reference) the nsIPresShell for the wrapped document.
  58. *
  59. * @param[out] aPresShell On success, this will be populated with a pointer
  60. * to the wrapped document's nsIPresShell.
  61. *
  62. * @return NS_OK on success, or an error code on failure.
  63. */
  64. inline nsresult GetPresShell(nsIPresShell** aPresShell)
  65. { return mViewer->GetPresShell(aPresShell); }
  66. /**
  67. * Modifier to update the viewport dimensions of the wrapped document. This
  68. * method performs a synchronous "Flush_Layout" on the wrapped document,
  69. * since a viewport-change affects layout.
  70. *
  71. * @param aViewportSize The new viewport dimensions.
  72. */
  73. void UpdateViewportBounds(const nsIntSize& aViewportSize);
  74. /**
  75. * If an SVG image's helper document has a pending notification for an
  76. * override on the root node's "preserveAspectRatio" attribute, then this
  77. * method will flush that notification so that the image can paint correctly.
  78. * (First, though, it sets the mIgnoreInvalidation flag so that we won't
  79. * notify the image's observers and trigger unwanted repaint-requests.)
  80. */
  81. void FlushImageTransformInvalidation();
  82. /**
  83. * Returns a bool indicating whether the document has any SMIL animations.
  84. *
  85. * @return true if the document has any SMIL animations. Else, false.
  86. */
  87. bool IsAnimated();
  88. /**
  89. * Indicates whether we should currently ignore rendering invalidations sent
  90. * from the wrapped SVG doc.
  91. *
  92. * @return true if we should ignore invalidations sent from this SVG doc.
  93. */
  94. bool ShouldIgnoreInvalidation() { return mIgnoreInvalidation; }
  95. /**
  96. * Methods to control animation.
  97. */
  98. void StartAnimation();
  99. void StopAnimation();
  100. void ResetAnimation();
  101. float GetCurrentTime();
  102. void SetCurrentTime(float aTime);
  103. void TickRefreshDriver();
  104. /**
  105. * Force a layout flush of the underlying SVG document.
  106. */
  107. void FlushLayout();
  108. private:
  109. ~SVGDocumentWrapper();
  110. nsresult SetupViewer(nsIRequest* aRequest,
  111. nsIContentViewer** aViewer,
  112. nsILoadGroup** aLoadGroup);
  113. void DestroyViewer();
  114. void RegisterForXPCOMShutdown();
  115. void UnregisterForXPCOMShutdown();
  116. nsCOMPtr<nsIContentViewer> mViewer;
  117. nsCOMPtr<nsILoadGroup> mLoadGroup;
  118. nsCOMPtr<nsIStreamListener> mListener;
  119. bool mIgnoreInvalidation;
  120. bool mRegisteredForXPCOMShutdown;
  121. };
  122. } // namespace image
  123. } // namespace mozilla
  124. #endif // mozilla_image_SVGDocumentWrapper_h