author Neil Rashbrook <>
Mon, 25 Jun 2012 09:24:49 +0100
changeset 100281 ec9451e9e830e4a66186c488e33020775b4456a1
parent 96742 f4157e8c410708d76703f19e4dfb61859bfe32d8
child 103959 b5c4b792f3f2a047e3517472d72842a76afb77cd
child 109823 80e4ab0d24bc64ceaa7693ab5def36faffde7a40
permissions -rw-r--r--
Bug 758354 Stop unnecessarily preprocessing chrome r=dolske

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at */

/* This class wraps an SVG document, for use by VectorImage objects. */

#ifndef mozilla_imagelib_SVGDocumentWrapper_h_
#define mozilla_imagelib_SVGDocumentWrapper_h_

#include "mozilla/Attributes.h"

#include "nsCOMPtr.h"
#include "nsIStreamListener.h"
#include "nsIObserver.h"
#include "nsIContentViewer.h"
#include "nsWeakReference.h"

class nsIAtom;
class nsIPresShell;
class nsIRequest;
class nsILoadGroup;
class nsIFrame;
struct nsIntSize;
class nsSVGSVGElement;

#define SVG_MIMETYPE     "image/svg+xml"
#define OBSERVER_SVC_CID ";1"

namespace mozilla {
namespace image {

class SVGDocumentWrapper MOZ_FINAL : public nsIStreamListener,
                                     public nsIObserver,


  enum Dimension {

   * Looks up the value of the wrapped SVG document's |width| or |height|
   * attribute in CSS pixels, and returns it by reference.  If the document has
   * a percent value for the queried attribute, then this method fails
   * (returns false).
   * @param aDimension    Indicates whether the width or height is desired.
   * @param[out] aResult  If this method succeeds, then this outparam will be
                          populated with the width or height in CSS pixels.
   * @return false to indicate failure, if the queried attribute has a
   *         percent value.  Otherwise, true.
  bool      GetWidthOrHeight(Dimension aDimension, PRInt32& aResult);

   * Returns the root <svg> element for the wrapped document, or nsnull on
   * failure.
  nsSVGSVGElement* GetRootSVGElem();

   * Returns the root nsIFrame* for the wrapped document, or nsnull on failure.
   * @return the root nsIFrame* for the wrapped document, or nsnull on failure.
  nsIFrame* GetRootLayoutFrame();

   * Returns (by reference) the nsIPresShell for the wrapped document.
   * @param[out] aPresShell On success, this will be populated with a pointer
   *                        to the wrapped document's nsIPresShell.
   * @return NS_OK on success, or an error code on failure.
  inline nsresult  GetPresShell(nsIPresShell** aPresShell)
    { return mViewer->GetPresShell(aPresShell); }

   * Returns a bool indicating whether the wrapped document has been parsed
   * successfully.
   * @return true if the document has been parsed successfully,
   *         false otherwise (e.g. if there's a syntax error in the SVG).
  inline bool      ParsedSuccessfully()  { return !!GetRootSVGElem(); }

   * Modifier to update the viewport dimensions of the wrapped document. This
   * method performs a synchronous "Flush_Layout" on the wrapped document,
   * since a viewport-change affects layout.
   * @param aViewportSize The new viewport dimensions.
  void UpdateViewportBounds(const nsIntSize& aViewportSize);

   * If an SVG image's helper document has a pending notification for an
   * override on the root node's "preserveAspectRatio" attribute, then this
   * method will flush that notification so that the image can paint correctly.
   * (First, though, it sets the mIgnoreInvalidation flag so that we won't
   * notify the image's observers and trigger unwanted repaint-requests.)
  void FlushImageTransformInvalidation();

   * Returns a bool indicating whether the document has any SMIL animations.
   * @return true if the document has any SMIL animations. Else, false.
  bool      IsAnimated();

   * Indicates whether we should currently ignore rendering invalidations sent
   * from the wrapped SVG doc.
   * @return true if we should ignore invalidations sent from this SVG doc.
  bool ShouldIgnoreInvalidation() { return mIgnoreInvalidation; }

   * Methods to control animation.
  void StartAnimation();
  void StopAnimation();
  void ResetAnimation();

  nsresult SetupViewer(nsIRequest *aRequest,
                       nsIContentViewer** aViewer,
                       nsILoadGroup** aLoadGroup);
  void     DestroyViewer();
  void     RegisterForXPCOMShutdown();
  void     UnregisterForXPCOMShutdown();

  void     FlushLayout();

  nsCOMPtr<nsIContentViewer>  mViewer;
  nsCOMPtr<nsILoadGroup>      mLoadGroup;
  nsCOMPtr<nsIStreamListener> mListener;
  bool                        mIgnoreInvalidation;
  bool                        mRegisteredForXPCOMShutdown;

} // namespace image
} // namespace mozilla

#endif // mozilla_imagelib_SVGDocumentWrapper_h_