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