LCOV - code coverage report
Current view: directory - image/src - SVGDocumentWrapper.h (source / functions) Found Hit Coverage
Test: app.info Lines: 4 0 0.0 %
Date: 2012-06-02 Functions: 3 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is mozilla.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * the Mozilla Foundation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2010
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Daniel Holbert <dholbert@mozilla.com>
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      27                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : /* This class wraps an SVG document, for use by VectorImage objects. */
      40                 : 
      41                 : #ifndef mozilla_imagelib_SVGDocumentWrapper_h_
      42                 : #define mozilla_imagelib_SVGDocumentWrapper_h_
      43                 : 
      44                 : #include "mozilla/Attributes.h"
      45                 : 
      46                 : #include "nsCOMPtr.h"
      47                 : #include "nsIStreamListener.h"
      48                 : #include "nsIObserver.h"
      49                 : #include "nsIContentViewer.h"
      50                 : #include "nsWeakReference.h"
      51                 : 
      52                 : class nsIAtom;
      53                 : class nsIPresShell;
      54                 : class nsIRequest;
      55                 : class nsILoadGroup;
      56                 : class nsIFrame;
      57                 : struct nsIntSize;
      58                 : class nsSVGSVGElement;
      59                 : 
      60                 : #define SVG_MIMETYPE     "image/svg+xml"
      61                 : #define OBSERVER_SVC_CID "@mozilla.org/observer-service;1"
      62                 : 
      63                 : 
      64                 : namespace mozilla {
      65                 : namespace image {
      66                 : 
      67                 : class SVGDocumentWrapper MOZ_FINAL : public nsIStreamListener,
      68                 :                                      public nsIObserver,
      69                 :                                      nsSupportsWeakReference
      70                 : {
      71                 : public:
      72                 :   SVGDocumentWrapper();
      73                 :   ~SVGDocumentWrapper();
      74                 : 
      75                 :   NS_DECL_ISUPPORTS
      76                 :   NS_DECL_NSISTREAMLISTENER
      77                 :   NS_DECL_NSIREQUESTOBSERVER
      78                 :   NS_DECL_NSIOBSERVER
      79                 : 
      80                 :   enum Dimension {
      81                 :     eWidth,
      82                 :     eHeight
      83                 :   };
      84                 : 
      85                 :   /**
      86                 :    * Looks up the value of the wrapped SVG document's |width| or |height|
      87                 :    * attribute in CSS pixels, and returns it by reference.  If the document has
      88                 :    * a percent value for the queried attribute, then this method fails
      89                 :    * (returns false).
      90                 :    *
      91                 :    * @param aDimension    Indicates whether the width or height is desired.
      92                 :    * @param[out] aResult  If this method succeeds, then this outparam will be
      93                 :                           populated with the width or height in CSS pixels.
      94                 :    * @return false to indicate failure, if the queried attribute has a
      95                 :    *         percent value.  Otherwise, true.
      96                 :    *
      97                 :    */
      98                 :   bool      GetWidthOrHeight(Dimension aDimension, PRInt32& aResult);
      99                 : 
     100                 :   /**
     101                 :    * Returns the root <svg> element for the wrapped document, or nsnull on
     102                 :    * failure.
     103                 :    */
     104                 :   nsSVGSVGElement* GetRootSVGElem();
     105                 : 
     106                 :   /**
     107                 :    * Returns the root nsIFrame* for the wrapped document, or nsnull on failure.
     108                 :    *
     109                 :    * @return the root nsIFrame* for the wrapped document, or nsnull on failure.
     110                 :    */
     111                 :   nsIFrame* GetRootLayoutFrame();
     112                 : 
     113                 :   /**
     114                 :    * Returns (by reference) the nsIPresShell for the wrapped document.
     115                 :    *
     116                 :    * @param[out] aPresShell On success, this will be populated with a pointer
     117                 :    *                        to the wrapped document's nsIPresShell.
     118                 :    *
     119                 :    * @return NS_OK on success, or an error code on failure.
     120                 :    */
     121               0 :   inline nsresult  GetPresShell(nsIPresShell** aPresShell)
     122               0 :     { return mViewer->GetPresShell(aPresShell); }
     123                 : 
     124                 :   /**
     125                 :    * Returns a bool indicating whether the wrapped document has been parsed
     126                 :    * successfully.
     127                 :    *
     128                 :    * @return true if the document has been parsed successfully,
     129                 :    *         false otherwise (e.g. if there's a syntax error in the SVG).
     130                 :    */
     131               0 :   inline bool      ParsedSuccessfully()  { return !!GetRootSVGElem(); }
     132                 : 
     133                 :   /**
     134                 :    * Modifier to update the viewport dimensions of the wrapped document. This
     135                 :    * method performs a synchronous "Flush_Layout" on the wrapped document,
     136                 :    * since a viewport-change affects layout.
     137                 :    *
     138                 :    * @param aViewportSize The new viewport dimensions.
     139                 :    */
     140                 :   void UpdateViewportBounds(const nsIntSize& aViewportSize);
     141                 : 
     142                 :   /**
     143                 :    * If an SVG image's helper document has a pending notification for an
     144                 :    * override on the root node's "preserveAspectRatio" attribute, then this
     145                 :    * method will flush that notification so that the image can paint correctly.
     146                 :    * (First, though, it sets the mIgnoreInvalidation flag so that we won't
     147                 :    * notify the image's observers and trigger unwanted repaint-requests.)
     148                 :    */
     149                 :   void FlushImageTransformInvalidation();
     150                 : 
     151                 :   /**
     152                 :    * Returns a bool indicating whether the document has any SMIL animations.
     153                 :    *
     154                 :    * @return true if the document has any SMIL animations. Else, false.
     155                 :    */
     156                 :   bool      IsAnimated();
     157                 : 
     158                 :   /**
     159                 :    * Indicates whether we should currently ignore rendering invalidations sent
     160                 :    * from the wrapped SVG doc.
     161                 :    *
     162                 :    * @return true if we should ignore invalidations sent from this SVG doc.
     163                 :    */
     164               0 :   bool ShouldIgnoreInvalidation() { return mIgnoreInvalidation; }
     165                 : 
     166                 :   /**
     167                 :    * Methods to control animation.
     168                 :    */
     169                 :   void StartAnimation();
     170                 :   void StopAnimation();
     171                 :   void ResetAnimation();
     172                 : 
     173                 : private:
     174                 :   nsresult SetupViewer(nsIRequest *aRequest,
     175                 :                        nsIContentViewer** aViewer,
     176                 :                        nsILoadGroup** aLoadGroup);
     177                 :   void     DestroyViewer();
     178                 :   void     RegisterForXPCOMShutdown();
     179                 :   void     UnregisterForXPCOMShutdown();
     180                 : 
     181                 :   void     FlushLayout();
     182                 : 
     183                 :   nsCOMPtr<nsIContentViewer>  mViewer;
     184                 :   nsCOMPtr<nsILoadGroup>      mLoadGroup;
     185                 :   nsCOMPtr<nsIStreamListener> mListener;
     186                 :   bool                        mIgnoreInvalidation;
     187                 :   bool                        mRegisteredForXPCOMShutdown;
     188                 : };
     189                 : 
     190                 : } // namespace image
     191                 : } // namespace mozilla
     192                 : 
     193                 : #endif // mozilla_imagelib_SVGDocumentWrapper_h_

Generated by: LCOV version 1.7