2010-09-08 13:40:39 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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 http://mozilla.org/MPL/2.0/. */
|
2010-09-08 13:40:39 -07:00
|
|
|
|
|
|
|
/* This class wraps an SVG document, for use by VectorImage objects. */
|
|
|
|
|
|
|
|
#ifndef mozilla_imagelib_SVGDocumentWrapper_h_
|
|
|
|
#define mozilla_imagelib_SVGDocumentWrapper_h_
|
|
|
|
|
2012-01-02 12:23:41 -08:00
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
|
2010-09-08 13:40:39 -07:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
#include "nsIObserver.h"
|
2011-10-15 00:33:26 -07:00
|
|
|
#include "nsIContentViewer.h"
|
2010-11-08 09:45:18 -08:00
|
|
|
#include "nsWeakReference.h"
|
2013-01-08 13:40:47 -08:00
|
|
|
#include "nsMimeTypes.h"
|
2010-09-08 13:40:39 -07:00
|
|
|
|
|
|
|
class nsIAtom;
|
|
|
|
class nsIPresShell;
|
|
|
|
class nsIRequest;
|
|
|
|
class nsILoadGroup;
|
|
|
|
class nsIFrame;
|
2011-01-20 19:49:09 -08:00
|
|
|
struct nsIntSize;
|
2010-09-08 13:40:39 -07:00
|
|
|
|
|
|
|
#define OBSERVER_SVC_CID "@mozilla.org/observer-service;1"
|
|
|
|
|
|
|
|
|
|
|
|
namespace mozilla {
|
2013-01-09 15:02:45 -08:00
|
|
|
namespace dom {
|
|
|
|
class SVGSVGElement;
|
|
|
|
}
|
|
|
|
|
2012-01-06 08:02:27 -08:00
|
|
|
namespace image {
|
2010-09-08 13:40:39 -07:00
|
|
|
|
2012-01-02 12:23:41 -08:00
|
|
|
class SVGDocumentWrapper MOZ_FINAL : public nsIStreamListener,
|
|
|
|
public nsIObserver,
|
|
|
|
nsSupportsWeakReference
|
2010-09-08 13:40:39 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
SVGDocumentWrapper();
|
|
|
|
~SVGDocumentWrapper();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
|
|
|
enum Dimension {
|
|
|
|
eWidth,
|
|
|
|
eHeight
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2011-10-17 07:59:28 -07:00
|
|
|
* (returns false).
|
2010-09-08 13:40:39 -07:00
|
|
|
*
|
|
|
|
* @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.
|
2011-10-17 07:59:28 -07:00
|
|
|
* @return false to indicate failure, if the queried attribute has a
|
|
|
|
* percent value. Otherwise, true.
|
2010-09-08 13:40:39 -07:00
|
|
|
*
|
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
bool GetWidthOrHeight(Dimension aDimension, int32_t& aResult);
|
2010-09-08 13:40:39 -07:00
|
|
|
|
2013-02-13 18:04:08 -08:00
|
|
|
/**
|
|
|
|
* Returns the wrapped document, or nullptr on failure. (No AddRef.)
|
|
|
|
*/
|
|
|
|
nsIDocument* GetDocument();
|
|
|
|
|
2010-09-08 13:40:39 -07:00
|
|
|
/**
|
2012-07-30 07:20:58 -07:00
|
|
|
* Returns the root <svg> element for the wrapped document, or nullptr on
|
2010-09-08 13:40:39 -07:00
|
|
|
* failure.
|
|
|
|
*/
|
2013-01-09 15:02:45 -08:00
|
|
|
mozilla::dom::SVGSVGElement* GetRootSVGElem();
|
2010-09-08 13:40:39 -07:00
|
|
|
|
|
|
|
/**
|
2012-07-30 07:20:58 -07:00
|
|
|
* Returns the root nsIFrame* for the wrapped document, or nullptr on failure.
|
2010-09-08 13:40:39 -07:00
|
|
|
*
|
2012-07-30 07:20:58 -07:00
|
|
|
* @return the root nsIFrame* for the wrapped document, or nullptr on failure.
|
2010-09-08 13:40:39 -07:00
|
|
|
*/
|
|
|
|
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); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2010-12-19 16:45:29 -08:00
|
|
|
/**
|
|
|
|
* 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.)
|
|
|
|
*/
|
2011-02-09 12:13:18 -08:00
|
|
|
void FlushImageTransformInvalidation();
|
2010-09-08 13:40:39 -07:00
|
|
|
|
|
|
|
/**
|
2011-09-28 23:19:26 -07:00
|
|
|
* Returns a bool indicating whether the document has any SMIL animations.
|
2010-09-08 13:40:39 -07:00
|
|
|
*
|
2011-10-17 07:59:28 -07:00
|
|
|
* @return true if the document has any SMIL animations. Else, false.
|
2010-09-08 13:40:39 -07:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool IsAnimated();
|
2010-09-08 13:40:39 -07:00
|
|
|
|
2010-09-08 13:40:40 -07:00
|
|
|
/**
|
|
|
|
* Indicates whether we should currently ignore rendering invalidations sent
|
|
|
|
* from the wrapped SVG doc.
|
|
|
|
*
|
2011-10-17 07:59:28 -07:00
|
|
|
* @return true if we should ignore invalidations sent from this SVG doc.
|
2010-09-08 13:40:40 -07:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool ShouldIgnoreInvalidation() { return mIgnoreInvalidation; }
|
2010-09-08 13:40:40 -07:00
|
|
|
|
2010-09-08 13:40:39 -07:00
|
|
|
/**
|
|
|
|
* Methods to control animation.
|
|
|
|
*/
|
|
|
|
void StartAnimation();
|
|
|
|
void StopAnimation();
|
|
|
|
void ResetAnimation();
|
|
|
|
|
2013-02-13 18:04:08 -08:00
|
|
|
/**
|
|
|
|
* Force a layout flush of the underlying SVG document.
|
|
|
|
*/
|
|
|
|
void FlushLayout();
|
|
|
|
|
2010-09-08 13:40:39 -07:00
|
|
|
private:
|
|
|
|
nsresult SetupViewer(nsIRequest *aRequest,
|
2011-10-15 00:33:26 -07:00
|
|
|
nsIContentViewer** aViewer,
|
2010-09-08 13:40:39 -07:00
|
|
|
nsILoadGroup** aLoadGroup);
|
|
|
|
void DestroyViewer();
|
|
|
|
void RegisterForXPCOMShutdown();
|
2010-11-08 09:45:18 -08:00
|
|
|
void UnregisterForXPCOMShutdown();
|
2010-09-08 13:40:39 -07:00
|
|
|
|
2011-10-15 00:33:26 -07:00
|
|
|
nsCOMPtr<nsIContentViewer> mViewer;
|
2010-09-08 13:40:39 -07:00
|
|
|
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
|
|
|
nsCOMPtr<nsIStreamListener> mListener;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mIgnoreInvalidation;
|
|
|
|
bool mRegisteredForXPCOMShutdown;
|
2010-09-08 13:40:39 -07:00
|
|
|
};
|
|
|
|
|
2012-01-06 08:02:27 -08:00
|
|
|
} // namespace image
|
2010-09-08 13:40:39 -07:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_imagelib_SVGDocumentWrapper_h_
|