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: michael@0: /* This class wraps an SVG document, for use by VectorImage objects. */ michael@0: michael@0: #ifndef mozilla_imagelib_SVGDocumentWrapper_h_ michael@0: #define mozilla_imagelib_SVGDocumentWrapper_h_ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIStreamListener.h" michael@0: #include "nsIObserver.h" michael@0: #include "nsIContentViewer.h" michael@0: #include "nsWeakReference.h" michael@0: michael@0: class nsIAtom; michael@0: class nsIPresShell; michael@0: class nsIRequest; michael@0: class nsILoadGroup; michael@0: class nsIFrame; michael@0: struct nsIntSize; michael@0: michael@0: #define OBSERVER_SVC_CID "@mozilla.org/observer-service;1" michael@0: michael@0: // undef the GetCurrentTime macro defined in WinBase.h from the MS Platform SDK michael@0: #undef GetCurrentTime michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: class SVGSVGElement; michael@0: } michael@0: michael@0: namespace image { michael@0: michael@0: class SVGDocumentWrapper MOZ_FINAL : public nsIStreamListener, michael@0: public nsIObserver, michael@0: nsSupportsWeakReference michael@0: { michael@0: public: michael@0: SVGDocumentWrapper(); michael@0: ~SVGDocumentWrapper(); michael@0: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSISTREAMLISTENER michael@0: NS_DECL_NSIREQUESTOBSERVER michael@0: NS_DECL_NSIOBSERVER michael@0: michael@0: enum Dimension { michael@0: eWidth, michael@0: eHeight michael@0: }; michael@0: michael@0: /** michael@0: * Looks up the value of the wrapped SVG document's |width| or |height| michael@0: * attribute in CSS pixels, and returns it by reference. If the document has michael@0: * a percent value for the queried attribute, then this method fails michael@0: * (returns false). michael@0: * michael@0: * @param aDimension Indicates whether the width or height is desired. michael@0: * @param[out] aResult If this method succeeds, then this outparam will be michael@0: populated with the width or height in CSS pixels. michael@0: * @return false to indicate failure, if the queried attribute has a michael@0: * percent value. Otherwise, true. michael@0: * michael@0: */ michael@0: bool GetWidthOrHeight(Dimension aDimension, int32_t& aResult); michael@0: michael@0: /** michael@0: * Returns the wrapped document, or nullptr on failure. (No AddRef.) michael@0: */ michael@0: nsIDocument* GetDocument(); michael@0: michael@0: /** michael@0: * Returns the root element for the wrapped document, or nullptr on michael@0: * failure. michael@0: */ michael@0: mozilla::dom::SVGSVGElement* GetRootSVGElem(); michael@0: michael@0: /** michael@0: * Returns the root nsIFrame* for the wrapped document, or nullptr on failure. michael@0: * michael@0: * @return the root nsIFrame* for the wrapped document, or nullptr on failure. michael@0: */ michael@0: nsIFrame* GetRootLayoutFrame(); michael@0: michael@0: /** michael@0: * Returns (by reference) the nsIPresShell for the wrapped document. michael@0: * michael@0: * @param[out] aPresShell On success, this will be populated with a pointer michael@0: * to the wrapped document's nsIPresShell. michael@0: * michael@0: * @return NS_OK on success, or an error code on failure. michael@0: */ michael@0: inline nsresult GetPresShell(nsIPresShell** aPresShell) michael@0: { return mViewer->GetPresShell(aPresShell); } michael@0: michael@0: /** michael@0: * Modifier to update the viewport dimensions of the wrapped document. This michael@0: * method performs a synchronous "Flush_Layout" on the wrapped document, michael@0: * since a viewport-change affects layout. michael@0: * michael@0: * @param aViewportSize The new viewport dimensions. michael@0: */ michael@0: void UpdateViewportBounds(const nsIntSize& aViewportSize); michael@0: michael@0: /** michael@0: * If an SVG image's helper document has a pending notification for an michael@0: * override on the root node's "preserveAspectRatio" attribute, then this michael@0: * method will flush that notification so that the image can paint correctly. michael@0: * (First, though, it sets the mIgnoreInvalidation flag so that we won't michael@0: * notify the image's observers and trigger unwanted repaint-requests.) michael@0: */ michael@0: void FlushImageTransformInvalidation(); michael@0: michael@0: /** michael@0: * Returns a bool indicating whether the document has any SMIL animations. michael@0: * michael@0: * @return true if the document has any SMIL animations. Else, false. michael@0: */ michael@0: bool IsAnimated(); michael@0: michael@0: /** michael@0: * Indicates whether we should currently ignore rendering invalidations sent michael@0: * from the wrapped SVG doc. michael@0: * michael@0: * @return true if we should ignore invalidations sent from this SVG doc. michael@0: */ michael@0: bool ShouldIgnoreInvalidation() { return mIgnoreInvalidation; } michael@0: michael@0: /** michael@0: * Methods to control animation. michael@0: */ michael@0: void StartAnimation(); michael@0: void StopAnimation(); michael@0: void ResetAnimation(); michael@0: float GetCurrentTime(); michael@0: void SetCurrentTime(float aTime); michael@0: michael@0: /** michael@0: * Force a layout flush of the underlying SVG document. michael@0: */ michael@0: void FlushLayout(); michael@0: michael@0: private: michael@0: nsresult SetupViewer(nsIRequest *aRequest, michael@0: nsIContentViewer** aViewer, michael@0: nsILoadGroup** aLoadGroup); michael@0: void DestroyViewer(); michael@0: void RegisterForXPCOMShutdown(); michael@0: void UnregisterForXPCOMShutdown(); michael@0: michael@0: nsCOMPtr mViewer; michael@0: nsCOMPtr mLoadGroup; michael@0: nsCOMPtr mListener; michael@0: bool mIgnoreInvalidation; michael@0: bool mRegisteredForXPCOMShutdown; michael@0: }; michael@0: michael@0: } // namespace image michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_imagelib_SVGDocumentWrapper_h_