image/src/VectorImage.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 #ifndef mozilla_imagelib_VectorImage_h_
     7 #define mozilla_imagelib_VectorImage_h_
     9 #include "Image.h"
    10 #include "nsIStreamListener.h"
    11 #include "mozilla/MemoryReporting.h"
    13 class nsIRequest;
    14 class gfxDrawable;
    16 namespace mozilla {
    17 namespace layers {
    18 class LayerManager;
    19 class ImageContainer;
    20 }
    21 namespace image {
    23 struct SVGDrawingParameters;
    24 class  SVGDocumentWrapper;
    25 class  SVGRootRenderingObserver;
    26 class  SVGLoadEventListener;
    27 class  SVGParseCompleteListener;
    29 class VectorImage : public ImageResource,
    30                     public nsIStreamListener
    31 {
    32 public:
    33   NS_DECL_ISUPPORTS
    34   NS_DECL_NSIREQUESTOBSERVER
    35   NS_DECL_NSISTREAMLISTENER
    36   NS_DECL_IMGICONTAINER
    38   // (no public constructor - use ImageFactory)
    39   virtual ~VectorImage();
    41   // Methods inherited from Image
    42   nsresult Init(const char* aMimeType,
    43                 uint32_t aFlags);
    44   virtual nsIntRect FrameRect(uint32_t aWhichFrame) MOZ_OVERRIDE;
    46   virtual size_t HeapSizeOfSourceWithComputedFallback(mozilla::MallocSizeOf aMallocSizeOf) const;
    47   virtual size_t HeapSizeOfDecodedWithComputedFallback(mozilla::MallocSizeOf aMallocSizeOf) const;
    48   virtual size_t NonHeapSizeOfDecoded() const;
    49   virtual size_t OutOfProcessSizeOfDecoded() const;
    51   virtual nsresult OnImageDataAvailable(nsIRequest* aRequest,
    52                                         nsISupports* aContext,
    53                                         nsIInputStream* aInStr,
    54                                         uint64_t aSourceOffset,
    55                                         uint32_t aCount) MOZ_OVERRIDE;
    56   virtual nsresult OnImageDataComplete(nsIRequest* aRequest,
    57                                        nsISupports* aContext,
    58                                        nsresult aResult,
    59                                        bool aLastPart) MOZ_OVERRIDE;
    60   virtual nsresult OnNewSourceData() MOZ_OVERRIDE;
    62   /**
    63    * Callback for SVGRootRenderingObserver.
    64    *
    65    * This just sets a dirty flag that we check in VectorImage::RequestRefresh,
    66    * which is called under the ticks of the refresh driver of any observing
    67    * documents that we may have. Only then (after all animations in this image
    68    * have been updated) do we send out "frame changed" notifications,
    69    */
    70   void InvalidateObserversOnNextRefreshDriverTick();
    72   // Callback for SVGParseCompleteListener.
    73   void OnSVGDocumentParsed();
    75   // Callbacks for SVGLoadEventListener.
    76   void OnSVGDocumentLoaded();
    77   void OnSVGDocumentError();
    79 protected:
    80   VectorImage(imgStatusTracker* aStatusTracker = nullptr,
    81               ImageURL* aURI = nullptr);
    83   virtual nsresult StartAnimation();
    84   virtual nsresult StopAnimation();
    85   virtual bool     ShouldAnimate();
    87   void CreateDrawableAndShow(const SVGDrawingParameters& aParams);
    88   void Show(gfxDrawable* aDrawable, const SVGDrawingParameters& aParams);
    90 private:
    91   void CancelAllListeners();
    92   void SendInvalidationNotifications();
    94   nsRefPtr<SVGDocumentWrapper>       mSVGDocumentWrapper;
    95   nsRefPtr<SVGRootRenderingObserver> mRenderingObserver;
    96   nsRefPtr<SVGLoadEventListener>     mLoadEventListener;
    97   nsRefPtr<SVGParseCompleteListener> mParseCompleteListener;
    99   bool           mIsInitialized;          // Have we been initalized?
   100   bool           mIsFullyLoaded;          // Has the SVG document finished loading?
   101   bool           mIsDrawing;              // Are we currently drawing?
   102   bool           mHaveAnimations;         // Is our SVG content SMIL-animated?
   103                                           // (Only set after mIsFullyLoaded.)
   104   bool           mHasPendingInvalidation; // Invalidate observers next refresh
   105                                           // driver tick.
   107   // Initializes imgStatusTracker and resets it on RasterImage destruction.
   108   nsAutoPtr<imgStatusTrackerInit> mStatusTrackerInit;
   110   friend class ImageFactory;
   111 };
   113 inline NS_IMETHODIMP VectorImage::GetAnimationMode(uint16_t *aAnimationMode) {
   114   return GetAnimationModeInternal(aAnimationMode);
   115 }
   117 inline NS_IMETHODIMP VectorImage::SetAnimationMode(uint16_t aAnimationMode) {
   118   return SetAnimationModeInternal(aAnimationMode);
   119 }
   121 } // namespace image
   122 } // namespace mozilla
   124 #endif // mozilla_imagelib_VectorImage_h_

mercurial