LCOV - code coverage report
Current view: directory - layout/generic - nsCanvasFrame.h (source / functions) Found Hit Coverage
Test: app.info Lines: 44 0 0.0 %
Date: 2012-06-02 Functions: 17 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                 :  * Netscape Communications Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *
      24                 :  * Alternatively, the contents of this file may be used under the terms of
      25                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      26                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      28                 :  * of those above. If you wish to allow use of your version of this file only
      29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      30                 :  * use your version of this file under the terms of the MPL, indicate your
      31                 :  * decision by deleting the provisions above and replace them with the notice
      32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      33                 :  * the provisions above, a recipient may use your version of this file under
      34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      35                 :  *
      36                 :  * ***** END LICENSE BLOCK ***** */
      37                 : 
      38                 : /* rendering object that goes directly inside the document's scrollbars */
      39                 : 
      40                 : #ifndef nsCanvasFrame_h___
      41                 : #define nsCanvasFrame_h___
      42                 : 
      43                 : #include "nsContainerFrame.h"
      44                 : #include "nsIScrollPositionListener.h"
      45                 : #include "nsDisplayList.h"
      46                 : #include "nsGkAtoms.h"
      47                 : 
      48                 : class nsPresContext;
      49                 : class nsRenderingContext;
      50                 : class nsEvent;
      51                 : 
      52                 : /**
      53                 :  * Root frame class.
      54                 :  *
      55                 :  * The root frame is the parent frame for the document element's frame.
      56                 :  * It only supports having a single child frame which must be an area
      57                 :  * frame
      58                 :  */
      59                 : class nsCanvasFrame : public nsContainerFrame,
      60                 :                       public nsIScrollPositionListener
      61               0 : {
      62                 : public:
      63               0 :   nsCanvasFrame(nsStyleContext* aContext)
      64                 :   : nsContainerFrame(aContext),
      65                 :     mDoPaintFocus(false),
      66               0 :     mAddedScrollPositionListener(false) {}
      67                 : 
      68                 :   NS_DECL_QUERYFRAME_TARGET(nsCanvasFrame)
      69                 :   NS_DECL_QUERYFRAME
      70                 :   NS_DECL_FRAMEARENA_HELPERS
      71                 : 
      72                 : 
      73                 :   virtual void DestroyFrom(nsIFrame* aDestructRoot);
      74                 : 
      75                 :   NS_IMETHOD SetInitialChildList(ChildListID     aListID,
      76                 :                                  nsFrameList&    aChildList);
      77                 :   NS_IMETHOD AppendFrames(ChildListID     aListID,
      78                 :                           nsFrameList&    aFrameList);
      79                 :   NS_IMETHOD InsertFrames(ChildListID     aListID,
      80                 :                           nsIFrame*       aPrevFrame,
      81                 :                           nsFrameList&    aFrameList);
      82                 :   NS_IMETHOD RemoveFrame(ChildListID     aListID,
      83                 :                          nsIFrame*       aOldFrame);
      84                 : 
      85                 :   virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext);
      86                 :   virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext);
      87                 :   NS_IMETHOD Reflow(nsPresContext*          aPresContext,
      88                 :                     nsHTMLReflowMetrics&     aDesiredSize,
      89                 :                     const nsHTMLReflowState& aReflowState,
      90                 :                     nsReflowStatus&          aStatus);
      91               0 :   virtual bool IsFrameOfType(PRUint32 aFlags) const
      92                 :   {
      93                 :     return nsContainerFrame::IsFrameOfType(aFlags &
      94               0 :              ~(nsIFrame::eCanContainOverflowContainers));
      95                 :   }
      96                 : 
      97                 :   /** SetHasFocus tells the CanvasFrame to draw with focus ring
      98                 :    *  @param aHasFocus true to show focus ring, false to hide it
      99                 :    */
     100                 :   NS_IMETHOD SetHasFocus(bool aHasFocus);
     101                 : 
     102                 :   NS_IMETHOD BuildDisplayList(nsDisplayListBuilder*   aBuilder,
     103                 :                               const nsRect&           aDirtyRect,
     104                 :                               const nsDisplayListSet& aLists);
     105                 : 
     106                 :   void PaintFocus(nsRenderingContext& aRenderingContext, nsPoint aPt);
     107                 : 
     108                 :   // nsIScrollPositionListener
     109                 :   virtual void ScrollPositionWillChange(nscoord aX, nscoord aY);
     110               0 :   virtual void ScrollPositionDidChange(nscoord aX, nscoord aY) {}
     111                 : 
     112                 :   /**
     113                 :    * Get the "type" of the frame
     114                 :    *
     115                 :    * @see nsGkAtoms::canvasFrame
     116                 :    */
     117                 :   virtual nsIAtom* GetType() const;
     118                 : 
     119               0 :   virtual nsresult StealFrame(nsPresContext* aPresContext,
     120                 :                               nsIFrame*      aChild,
     121                 :                               bool           aForceNormal)
     122                 :   {
     123               0 :     NS_ASSERTION(!aForceNormal, "No-one should be passing this in here");
     124                 : 
     125                 :     // nsCanvasFrame keeps overflow container continuations of its child
     126                 :     // frame in main child list
     127               0 :     nsresult rv = nsContainerFrame::StealFrame(aPresContext, aChild, true);
     128               0 :     if (NS_FAILED(rv)) {
     129               0 :       rv = nsContainerFrame::StealFrame(aPresContext, aChild);
     130                 :     }
     131               0 :     return rv;
     132                 :   }
     133                 : 
     134                 : #ifdef DEBUG
     135                 :   NS_IMETHOD GetFrameName(nsAString& aResult) const;
     136                 : #endif
     137                 :   NS_IMETHOD GetContentForEvent(nsEvent* aEvent,
     138                 :                                 nsIContent** aContent);
     139                 : 
     140                 :   nsRect CanvasArea() const;
     141                 : 
     142                 : protected:
     143                 :   virtual PRIntn GetSkipSides() const;
     144                 : 
     145                 :   // Data members
     146                 :   bool                      mDoPaintFocus;
     147                 :   bool                      mAddedScrollPositionListener;
     148                 : };
     149                 : 
     150                 : /**
     151                 :  * Override nsDisplayBackground methods so that we pass aBGClipRect to
     152                 :  * PaintBackground, covering the whole overflow area.
     153                 :  * We can also paint an "extra background color" behind the normal
     154                 :  * background.
     155                 :  */
     156               0 : class nsDisplayCanvasBackground : public nsDisplayBackground {
     157                 : public:
     158               0 :   nsDisplayCanvasBackground(nsDisplayListBuilder* aBuilder, nsIFrame *aFrame)
     159               0 :     : nsDisplayBackground(aBuilder, aFrame)
     160                 :   {
     161               0 :     mExtraBackgroundColor = NS_RGBA(0,0,0,0);
     162               0 :   }
     163                 : 
     164               0 :   virtual bool ComputeVisibility(nsDisplayListBuilder* aBuilder,
     165                 :                                    nsRegion* aVisibleRegion,
     166                 :                                    const nsRect& aAllowVisibleRegionExpansion)
     167                 :   {
     168                 :     return NS_GET_A(mExtraBackgroundColor) > 0 ||
     169                 :       nsDisplayBackground::ComputeVisibility(aBuilder, aVisibleRegion,
     170               0 :                                              aAllowVisibleRegionExpansion);
     171                 :   }
     172               0 :   virtual nsRegion GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
     173                 :                                    bool* aForceTransparentSurface = nsnull)
     174                 :   {
     175               0 :     if (aForceTransparentSurface) {
     176               0 :       *aForceTransparentSurface = false;
     177                 :     }
     178               0 :     if (NS_GET_A(mExtraBackgroundColor) == 255)
     179               0 :       return nsRegion(GetBounds(aBuilder));
     180               0 :     return nsDisplayBackground::GetOpaqueRegion(aBuilder);
     181                 :   }
     182               0 :   virtual bool IsUniform(nsDisplayListBuilder* aBuilder, nscolor* aColor)
     183                 :   {
     184                 :     nscolor background;
     185               0 :     if (!nsDisplayBackground::IsUniform(aBuilder, &background))
     186               0 :       return false;
     187               0 :     NS_ASSERTION(background == NS_RGBA(0,0,0,0),
     188                 :                  "The nsDisplayBackground for a canvas frame doesn't paint "
     189                 :                  "its background color normally");
     190               0 :     *aColor = mExtraBackgroundColor;
     191               0 :     return true;
     192                 :   }
     193               0 :   virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder)
     194                 :   {
     195               0 :     nsCanvasFrame* frame = static_cast<nsCanvasFrame*>(mFrame);
     196               0 :     nsRect r = frame->CanvasArea() + ToReferenceFrame();
     197               0 :     if (mSnappingEnabled) {
     198               0 :       nscoord appUnitsPerDevPixel = frame->PresContext()->AppUnitsPerDevPixel();
     199               0 :       r = r.ToNearestPixels(appUnitsPerDevPixel).ToAppUnits(appUnitsPerDevPixel);
     200                 :     }
     201                 :     return r;
     202                 :   }
     203               0 :   virtual void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
     204                 :                        HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames)
     205                 :   {
     206                 :     // We need to override so we don't consider border-radius.
     207               0 :     aOutFrames->AppendElement(mFrame);
     208               0 :   }
     209                 : 
     210                 :   virtual void Paint(nsDisplayListBuilder* aBuilder,
     211                 :                      nsRenderingContext* aCtx);
     212                 : 
     213               0 :   void SetExtraBackgroundColor(nscolor aColor)
     214                 :   {
     215               0 :     mExtraBackgroundColor = aColor;
     216               0 :   }
     217                 : 
     218               0 :   NS_DISPLAY_DECL_NAME("CanvasBackground", TYPE_CANVAS_BACKGROUND)
     219                 : 
     220                 : private:
     221                 :   nscolor mExtraBackgroundColor;
     222                 : };
     223                 : 
     224                 : 
     225                 : #endif /* nsCanvasFrame_h___ */

Generated by: LCOV version 1.7