image/src/SVGDocumentWrapper.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/image/src/SVGDocumentWrapper.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,165 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/* This class wraps an SVG document, for use by VectorImage objects. */
    1.10 +
    1.11 +#ifndef mozilla_imagelib_SVGDocumentWrapper_h_
    1.12 +#define mozilla_imagelib_SVGDocumentWrapper_h_
    1.13 +
    1.14 +#include "mozilla/Attributes.h"
    1.15 +
    1.16 +#include "nsCOMPtr.h"
    1.17 +#include "nsIStreamListener.h"
    1.18 +#include "nsIObserver.h"
    1.19 +#include "nsIContentViewer.h"
    1.20 +#include "nsWeakReference.h"
    1.21 +
    1.22 +class nsIAtom;
    1.23 +class nsIPresShell;
    1.24 +class nsIRequest;
    1.25 +class nsILoadGroup;
    1.26 +class nsIFrame;
    1.27 +struct nsIntSize;
    1.28 +
    1.29 +#define OBSERVER_SVC_CID "@mozilla.org/observer-service;1"
    1.30 +
    1.31 +// undef the GetCurrentTime macro defined in WinBase.h from the MS Platform SDK
    1.32 +#undef GetCurrentTime
    1.33 +
    1.34 +namespace mozilla {
    1.35 +namespace dom {
    1.36 +class SVGSVGElement;
    1.37 +}
    1.38 +
    1.39 +namespace image {
    1.40 +
    1.41 +class SVGDocumentWrapper MOZ_FINAL : public nsIStreamListener,
    1.42 +                                     public nsIObserver,
    1.43 +                                     nsSupportsWeakReference
    1.44 +{
    1.45 +public:
    1.46 +  SVGDocumentWrapper();
    1.47 +  ~SVGDocumentWrapper();
    1.48 +
    1.49 +  NS_DECL_ISUPPORTS
    1.50 +  NS_DECL_NSISTREAMLISTENER
    1.51 +  NS_DECL_NSIREQUESTOBSERVER
    1.52 +  NS_DECL_NSIOBSERVER
    1.53 +
    1.54 +  enum Dimension {
    1.55 +    eWidth,
    1.56 +    eHeight
    1.57 +  };
    1.58 +
    1.59 +  /**
    1.60 +   * Looks up the value of the wrapped SVG document's |width| or |height|
    1.61 +   * attribute in CSS pixels, and returns it by reference.  If the document has
    1.62 +   * a percent value for the queried attribute, then this method fails
    1.63 +   * (returns false).
    1.64 +   *
    1.65 +   * @param aDimension    Indicates whether the width or height is desired.
    1.66 +   * @param[out] aResult  If this method succeeds, then this outparam will be
    1.67 +                          populated with the width or height in CSS pixels.
    1.68 +   * @return false to indicate failure, if the queried attribute has a
    1.69 +   *         percent value.  Otherwise, true.
    1.70 +   *
    1.71 +   */
    1.72 +  bool      GetWidthOrHeight(Dimension aDimension, int32_t& aResult);
    1.73 +
    1.74 +  /**
    1.75 +   * Returns the wrapped document, or nullptr on failure. (No AddRef.)
    1.76 +   */
    1.77 +  nsIDocument* GetDocument();
    1.78 +
    1.79 +  /**
    1.80 +   * Returns the root <svg> element for the wrapped document, or nullptr on
    1.81 +   * failure.
    1.82 +   */
    1.83 +  mozilla::dom::SVGSVGElement* GetRootSVGElem();
    1.84 +
    1.85 +  /**
    1.86 +   * Returns the root nsIFrame* for the wrapped document, or nullptr on failure.
    1.87 +   *
    1.88 +   * @return the root nsIFrame* for the wrapped document, or nullptr on failure.
    1.89 +   */
    1.90 +  nsIFrame* GetRootLayoutFrame();
    1.91 +
    1.92 +  /**
    1.93 +   * Returns (by reference) the nsIPresShell for the wrapped document.
    1.94 +   *
    1.95 +   * @param[out] aPresShell On success, this will be populated with a pointer
    1.96 +   *                        to the wrapped document's nsIPresShell.
    1.97 +   *
    1.98 +   * @return NS_OK on success, or an error code on failure.
    1.99 +   */
   1.100 +  inline nsresult  GetPresShell(nsIPresShell** aPresShell)
   1.101 +    { return mViewer->GetPresShell(aPresShell); }
   1.102 +
   1.103 +  /**
   1.104 +   * Modifier to update the viewport dimensions of the wrapped document. This
   1.105 +   * method performs a synchronous "Flush_Layout" on the wrapped document,
   1.106 +   * since a viewport-change affects layout.
   1.107 +   *
   1.108 +   * @param aViewportSize The new viewport dimensions.
   1.109 +   */
   1.110 +  void UpdateViewportBounds(const nsIntSize& aViewportSize);
   1.111 +
   1.112 +  /**
   1.113 +   * If an SVG image's helper document has a pending notification for an
   1.114 +   * override on the root node's "preserveAspectRatio" attribute, then this
   1.115 +   * method will flush that notification so that the image can paint correctly.
   1.116 +   * (First, though, it sets the mIgnoreInvalidation flag so that we won't
   1.117 +   * notify the image's observers and trigger unwanted repaint-requests.)
   1.118 +   */
   1.119 +  void FlushImageTransformInvalidation();
   1.120 +
   1.121 +  /**
   1.122 +   * Returns a bool indicating whether the document has any SMIL animations.
   1.123 +   *
   1.124 +   * @return true if the document has any SMIL animations. Else, false.
   1.125 +   */
   1.126 +  bool      IsAnimated();
   1.127 +
   1.128 +  /**
   1.129 +   * Indicates whether we should currently ignore rendering invalidations sent
   1.130 +   * from the wrapped SVG doc.
   1.131 +   *
   1.132 +   * @return true if we should ignore invalidations sent from this SVG doc.
   1.133 +   */
   1.134 +  bool ShouldIgnoreInvalidation() { return mIgnoreInvalidation; }
   1.135 +
   1.136 +  /**
   1.137 +   * Methods to control animation.
   1.138 +   */
   1.139 +  void StartAnimation();
   1.140 +  void StopAnimation();
   1.141 +  void ResetAnimation();
   1.142 +  float GetCurrentTime();
   1.143 +  void SetCurrentTime(float aTime);
   1.144 +
   1.145 +  /**
   1.146 +   * Force a layout flush of the underlying SVG document.
   1.147 +   */
   1.148 +  void FlushLayout();
   1.149 +
   1.150 +private:
   1.151 +  nsresult SetupViewer(nsIRequest *aRequest,
   1.152 +                       nsIContentViewer** aViewer,
   1.153 +                       nsILoadGroup** aLoadGroup);
   1.154 +  void     DestroyViewer();
   1.155 +  void     RegisterForXPCOMShutdown();
   1.156 +  void     UnregisterForXPCOMShutdown();
   1.157 +
   1.158 +  nsCOMPtr<nsIContentViewer>  mViewer;
   1.159 +  nsCOMPtr<nsILoadGroup>      mLoadGroup;
   1.160 +  nsCOMPtr<nsIStreamListener> mListener;
   1.161 +  bool                        mIgnoreInvalidation;
   1.162 +  bool                        mRegisteredForXPCOMShutdown;
   1.163 +};
   1.164 +
   1.165 +} // namespace image
   1.166 +} // namespace mozilla
   1.167 +
   1.168 +#endif // mozilla_imagelib_SVGDocumentWrapper_h_

mercurial