image/src/SVGDocumentWrapper.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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/. */
     6 /* This class wraps an SVG document, for use by VectorImage objects. */
     8 #ifndef mozilla_imagelib_SVGDocumentWrapper_h_
     9 #define mozilla_imagelib_SVGDocumentWrapper_h_
    11 #include "mozilla/Attributes.h"
    13 #include "nsCOMPtr.h"
    14 #include "nsIStreamListener.h"
    15 #include "nsIObserver.h"
    16 #include "nsIContentViewer.h"
    17 #include "nsWeakReference.h"
    19 class nsIAtom;
    20 class nsIPresShell;
    21 class nsIRequest;
    22 class nsILoadGroup;
    23 class nsIFrame;
    24 struct nsIntSize;
    26 #define OBSERVER_SVC_CID "@mozilla.org/observer-service;1"
    28 // undef the GetCurrentTime macro defined in WinBase.h from the MS Platform SDK
    29 #undef GetCurrentTime
    31 namespace mozilla {
    32 namespace dom {
    33 class SVGSVGElement;
    34 }
    36 namespace image {
    38 class SVGDocumentWrapper MOZ_FINAL : public nsIStreamListener,
    39                                      public nsIObserver,
    40                                      nsSupportsWeakReference
    41 {
    42 public:
    43   SVGDocumentWrapper();
    44   ~SVGDocumentWrapper();
    46   NS_DECL_ISUPPORTS
    47   NS_DECL_NSISTREAMLISTENER
    48   NS_DECL_NSIREQUESTOBSERVER
    49   NS_DECL_NSIOBSERVER
    51   enum Dimension {
    52     eWidth,
    53     eHeight
    54   };
    56   /**
    57    * Looks up the value of the wrapped SVG document's |width| or |height|
    58    * attribute in CSS pixels, and returns it by reference.  If the document has
    59    * a percent value for the queried attribute, then this method fails
    60    * (returns false).
    61    *
    62    * @param aDimension    Indicates whether the width or height is desired.
    63    * @param[out] aResult  If this method succeeds, then this outparam will be
    64                           populated with the width or height in CSS pixels.
    65    * @return false to indicate failure, if the queried attribute has a
    66    *         percent value.  Otherwise, true.
    67    *
    68    */
    69   bool      GetWidthOrHeight(Dimension aDimension, int32_t& aResult);
    71   /**
    72    * Returns the wrapped document, or nullptr on failure. (No AddRef.)
    73    */
    74   nsIDocument* GetDocument();
    76   /**
    77    * Returns the root <svg> element for the wrapped document, or nullptr on
    78    * failure.
    79    */
    80   mozilla::dom::SVGSVGElement* GetRootSVGElem();
    82   /**
    83    * Returns the root nsIFrame* for the wrapped document, or nullptr on failure.
    84    *
    85    * @return the root nsIFrame* for the wrapped document, or nullptr on failure.
    86    */
    87   nsIFrame* GetRootLayoutFrame();
    89   /**
    90    * Returns (by reference) the nsIPresShell for the wrapped document.
    91    *
    92    * @param[out] aPresShell On success, this will be populated with a pointer
    93    *                        to the wrapped document's nsIPresShell.
    94    *
    95    * @return NS_OK on success, or an error code on failure.
    96    */
    97   inline nsresult  GetPresShell(nsIPresShell** aPresShell)
    98     { return mViewer->GetPresShell(aPresShell); }
   100   /**
   101    * Modifier to update the viewport dimensions of the wrapped document. This
   102    * method performs a synchronous "Flush_Layout" on the wrapped document,
   103    * since a viewport-change affects layout.
   104    *
   105    * @param aViewportSize The new viewport dimensions.
   106    */
   107   void UpdateViewportBounds(const nsIntSize& aViewportSize);
   109   /**
   110    * If an SVG image's helper document has a pending notification for an
   111    * override on the root node's "preserveAspectRatio" attribute, then this
   112    * method will flush that notification so that the image can paint correctly.
   113    * (First, though, it sets the mIgnoreInvalidation flag so that we won't
   114    * notify the image's observers and trigger unwanted repaint-requests.)
   115    */
   116   void FlushImageTransformInvalidation();
   118   /**
   119    * Returns a bool indicating whether the document has any SMIL animations.
   120    *
   121    * @return true if the document has any SMIL animations. Else, false.
   122    */
   123   bool      IsAnimated();
   125   /**
   126    * Indicates whether we should currently ignore rendering invalidations sent
   127    * from the wrapped SVG doc.
   128    *
   129    * @return true if we should ignore invalidations sent from this SVG doc.
   130    */
   131   bool ShouldIgnoreInvalidation() { return mIgnoreInvalidation; }
   133   /**
   134    * Methods to control animation.
   135    */
   136   void StartAnimation();
   137   void StopAnimation();
   138   void ResetAnimation();
   139   float GetCurrentTime();
   140   void SetCurrentTime(float aTime);
   142   /**
   143    * Force a layout flush of the underlying SVG document.
   144    */
   145   void FlushLayout();
   147 private:
   148   nsresult SetupViewer(nsIRequest *aRequest,
   149                        nsIContentViewer** aViewer,
   150                        nsILoadGroup** aLoadGroup);
   151   void     DestroyViewer();
   152   void     RegisterForXPCOMShutdown();
   153   void     UnregisterForXPCOMShutdown();
   155   nsCOMPtr<nsIContentViewer>  mViewer;
   156   nsCOMPtr<nsILoadGroup>      mLoadGroup;
   157   nsCOMPtr<nsIStreamListener> mListener;
   158   bool                        mIgnoreInvalidation;
   159   bool                        mRegisteredForXPCOMShutdown;
   160 };
   162 } // namespace image
   163 } // namespace mozilla
   165 #endif // mozilla_imagelib_SVGDocumentWrapper_h_

mercurial