LCOV - code coverage report
Current view: directory - objdir/dist/include - nsHTMLCanvasElement.h (source / functions) Found Hit Coverage
Test: app.info Lines: 8 1 12.5 %
Date: 2012-06-02 Functions: 100 1 1.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* vim:set ts=2 sw=2 sts=2 et cindent: */
       3                 : /* ***** BEGIN LICENSE BLOCK *****
       4                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       5                 :  *
       6                 :  * The contents of this file are subject to the Mozilla Public License Version
       7                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       8                 :  * the License. You may obtain a copy of the License at
       9                 :  * http://www.mozilla.org/MPL/
      10                 :  *
      11                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      12                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      13                 :  * for the specific language governing rights and limitations under the
      14                 :  * License.
      15                 :  *
      16                 :  * The Original Code is Mozilla code.
      17                 :  *
      18                 :  * The Initial Developer of the Original Code is the Mozilla Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2010
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *    Vladimir Vukicevic <vladimir@pobox.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                 : #if !defined(nsHTMLCanvasElement_h__)
      39                 : #define nsHTMLCanvasElement_h__
      40                 : 
      41                 : #include "nsIDOMHTMLCanvasElement.h"
      42                 : #include "nsGenericHTMLElement.h"
      43                 : #include "nsGkAtoms.h"
      44                 : #include "nsSize.h"
      45                 : #include "nsIFrame.h"
      46                 : #include "nsIDocument.h"
      47                 : #include "nsIDOMDocument.h"
      48                 : #include "nsDOMError.h"
      49                 : #include "nsNodeInfoManager.h"
      50                 : 
      51                 : #include "nsICanvasRenderingContextInternal.h"
      52                 : #include "nsICanvasElementExternal.h"
      53                 : #include "nsIDOMCanvasRenderingContext2D.h"
      54                 : #include "nsLayoutUtils.h"
      55                 : 
      56                 : #include "Layers.h"
      57                 : 
      58                 : class nsIDOMFile;
      59                 : 
      60                 : class nsHTMLCanvasElement : public nsGenericHTMLElement,
      61                 :                             public nsICanvasElementExternal,
      62                 :                             public nsIDOMHTMLCanvasElement
      63                 : {
      64                 :   typedef mozilla::layers::CanvasLayer CanvasLayer;
      65                 :   typedef mozilla::layers::LayerManager LayerManager;
      66                 : 
      67                 : public:
      68                 :   nsHTMLCanvasElement(already_AddRefed<nsINodeInfo> aNodeInfo);
      69                 :   virtual ~nsHTMLCanvasElement();
      70                 : 
      71               0 :   static nsHTMLCanvasElement* FromContent(nsIContent* aPossibleCanvas)
      72                 :   {
      73               0 :     if (!aPossibleCanvas || !aPossibleCanvas->IsHTML(nsGkAtoms::canvas)) {
      74               0 :       return nsnull;
      75                 :     }
      76               0 :     return static_cast<nsHTMLCanvasElement*>(aPossibleCanvas);
      77                 :   }
      78                 :   // nsISupports
      79                 :   NS_DECL_ISUPPORTS_INHERITED
      80                 : 
      81                 :   // nsIDOMNode
      82               0 :   NS_FORWARD_NSIDOMNODE(nsGenericHTMLElement::)
      83                 : 
      84                 :   // nsIDOMElement
      85               0 :   NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
      86                 : 
      87                 :   // nsIDOMHTMLElement
      88               0 :   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
      89                 : 
      90                 :   // nsIDOMHTMLCanvasElement
      91                 :   NS_DECL_NSIDOMHTMLCANVASELEMENT
      92                 : 
      93                 :   // CC
      94            1464 :   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(nsHTMLCanvasElement,
      95                 :                                            nsGenericHTMLElement)
      96                 : 
      97                 :   /**
      98                 :    * Ask the canvas Element to return the primary frame, if any
      99                 :    */
     100                 :   nsIFrame *GetPrimaryCanvasFrame();
     101                 : 
     102                 :   /**
     103                 :    * Get the size in pixels of this canvas element
     104                 :    */
     105                 :   nsIntSize GetSize();
     106                 : 
     107                 :   /**
     108                 :    * Determine whether the canvas is write-only.
     109                 :    */
     110                 :   bool IsWriteOnly();
     111                 : 
     112                 :   /**
     113                 :    * Force the canvas to be write-only.
     114                 :    */
     115                 :   void SetWriteOnly();
     116                 : 
     117                 :   /**
     118                 :    * Notify that some canvas content has changed and the window may
     119                 :    * need to be updated. aDamageRect is in canvas coordinates.
     120                 :    */
     121                 :   void InvalidateCanvasContent(const gfxRect* aDamageRect);
     122                 :   /*
     123                 :    * Notify that we need to repaint the entire canvas, including updating of
     124                 :    * the layer tree.
     125                 :    */
     126                 :   void InvalidateCanvas();
     127                 : 
     128                 :   /*
     129                 :    * Get the number of contexts in this canvas, and request a context at
     130                 :    * an index.
     131                 :    */
     132                 :   PRInt32 CountContexts ();
     133                 :   nsICanvasRenderingContextInternal *GetContextAtIndex (PRInt32 index);
     134                 : 
     135                 :   /*
     136                 :    * Returns true if the canvas context content is guaranteed to be opaque
     137                 :    * across its entire area.
     138                 :    */
     139                 :   bool GetIsOpaque();
     140                 : 
     141                 :   /*
     142                 :    * nsICanvasElementExternal -- for use outside of content/layout
     143                 :    */
     144                 :   NS_IMETHOD_(nsIntSize) GetSizeExternal();
     145                 :   NS_IMETHOD RenderContextsExternal(gfxContext *aContext, gfxPattern::GraphicsFilter aFilter);
     146                 : 
     147                 :   virtual bool ParseAttribute(PRInt32 aNamespaceID,
     148                 :                                 nsIAtom* aAttribute,
     149                 :                                 const nsAString& aValue,
     150                 :                                 nsAttrValue& aResult);
     151                 :   nsChangeHint GetAttributeChangeHint(const nsIAtom* aAttribute, PRInt32 aModType) const;
     152                 : 
     153                 :   // SetAttr override.  C++ is stupid, so have to override both
     154                 :   // overloaded methods.
     155                 :   nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
     156                 :                    const nsAString& aValue, bool aNotify)
     157                 :   {
     158                 :     return SetAttr(aNameSpaceID, aName, nsnull, aValue, aNotify);
     159                 :   }
     160                 :   virtual nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
     161                 :                            nsIAtom* aPrefix, const nsAString& aValue,
     162                 :                            bool aNotify);
     163                 :   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
     164                 :   nsresult CopyInnerTo(nsGenericElement* aDest) const;
     165                 : 
     166                 :   /*
     167                 :    * Helpers called by various users of Canvas
     168                 :    */
     169                 : 
     170                 :   already_AddRefed<CanvasLayer> GetCanvasLayer(nsDisplayListBuilder* aBuilder,
     171                 :                                                CanvasLayer *aOldLayer,
     172                 :                                                LayerManager *aManager);
     173                 :   // Should return true if the canvas layer should always be marked inactive.
     174                 :   // We should return true here if we can't do accelerated compositing with
     175                 :   // a non-BasicCanvasLayer.
     176                 :   bool ShouldForceInactiveLayer(LayerManager *aManager);
     177                 : 
     178                 :   // Call this whenever we need future changes to the canvas
     179                 :   // to trigger fresh invalidation requests. This needs to be called
     180                 :   // whenever we render the canvas contents to the screen, or whenever we
     181                 :   // take a snapshot of the canvas that needs to be "live" (e.g. -moz-element).
     182                 :   void MarkContextClean();
     183                 : 
     184                 :   virtual nsXPCClassInfo* GetClassInfo();
     185                 : protected:
     186                 :   nsIntSize GetWidthHeight();
     187                 : 
     188                 :   nsresult UpdateContext(nsIPropertyBag *aNewContextOptions = nsnull);
     189                 :   nsresult ExtractData(const nsAString& aType,
     190                 :                        const nsAString& aOptions,
     191                 :                        nsIInputStream** aStream,
     192                 :                        bool& aFellBackToPNG);
     193                 :   nsresult ToDataURLImpl(const nsAString& aMimeType,
     194                 :                          nsIVariant* aEncoderOptions,
     195                 :                          nsAString& aDataURL);
     196                 :   nsresult MozGetAsFileImpl(const nsAString& aName,
     197                 :                             const nsAString& aType,
     198                 :                             nsIDOMFile** aResult);
     199                 :   nsresult GetContextHelper(const nsAString& aContextId,
     200                 :                             bool aForceThebes,
     201                 :                             nsICanvasRenderingContextInternal **aContext);
     202                 : 
     203                 :   nsString mCurrentContextId;
     204                 :   nsCOMPtr<nsICanvasRenderingContextInternal> mCurrentContext;
     205                 :   
     206                 : public:
     207                 :   // Record whether this canvas should be write-only or not.
     208                 :   // We set this when script paints an image from a different origin.
     209                 :   // We also transitively set it when script paints a canvas which
     210                 :   // is itself write-only.
     211                 :   bool                     mWriteOnly;
     212                 : };
     213                 : 
     214                 : #endif /* nsHTMLCanvasElement_h__ */

Generated by: LCOV version 1.7