layout/generic/nsCanvasFrame.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/generic/nsCanvasFrame.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,231 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/* rendering object that goes directly inside the document's scrollbars */
    1.10 +
    1.11 +#ifndef nsCanvasFrame_h___
    1.12 +#define nsCanvasFrame_h___
    1.13 +
    1.14 +#include "mozilla/Attributes.h"
    1.15 +#include "mozilla/EventForwards.h"
    1.16 +#include "nsContainerFrame.h"
    1.17 +#include "nsIScrollPositionListener.h"
    1.18 +#include "nsDisplayList.h"
    1.19 +
    1.20 +class nsPresContext;
    1.21 +class nsRenderingContext;
    1.22 +
    1.23 +/**
    1.24 + * Root frame class.
    1.25 + *
    1.26 + * The root frame is the parent frame for the document element's frame.
    1.27 + * It only supports having a single child frame which must be an area
    1.28 + * frame
    1.29 + */
    1.30 +class nsCanvasFrame : public nsContainerFrame,
    1.31 +                      public nsIScrollPositionListener
    1.32 +{
    1.33 +public:
    1.34 +  nsCanvasFrame(nsStyleContext* aContext)
    1.35 +  : nsContainerFrame(aContext),
    1.36 +    mDoPaintFocus(false),
    1.37 +    mAddedScrollPositionListener(false) {}
    1.38 +
    1.39 +  NS_DECL_QUERYFRAME_TARGET(nsCanvasFrame)
    1.40 +  NS_DECL_QUERYFRAME
    1.41 +  NS_DECL_FRAMEARENA_HELPERS
    1.42 +
    1.43 +
    1.44 +  virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
    1.45 +
    1.46 +  virtual nsresult SetInitialChildList(ChildListID     aListID,
    1.47 +                                       nsFrameList&    aChildList) MOZ_OVERRIDE;
    1.48 +  virtual nsresult AppendFrames(ChildListID     aListID,
    1.49 +                                nsFrameList&    aFrameList) MOZ_OVERRIDE;
    1.50 +  virtual nsresult InsertFrames(ChildListID     aListID,
    1.51 +                                nsIFrame*       aPrevFrame,
    1.52 +                                nsFrameList&    aFrameList) MOZ_OVERRIDE;
    1.53 +  virtual nsresult RemoveFrame(ChildListID     aListID,
    1.54 +                               nsIFrame*       aOldFrame) MOZ_OVERRIDE;
    1.55 +
    1.56 +  virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
    1.57 +  virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
    1.58 +  virtual nsresult Reflow(nsPresContext*           aPresContext,
    1.59 +                          nsHTMLReflowMetrics&     aDesiredSize,
    1.60 +                          const nsHTMLReflowState& aReflowState,
    1.61 +                          nsReflowStatus&          aStatus) MOZ_OVERRIDE;
    1.62 +  virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE
    1.63 +  {
    1.64 +    return nsContainerFrame::IsFrameOfType(aFlags &
    1.65 +             ~(nsIFrame::eCanContainOverflowContainers));
    1.66 +  }
    1.67 +
    1.68 +  /** SetHasFocus tells the CanvasFrame to draw with focus ring
    1.69 +   *  @param aHasFocus true to show focus ring, false to hide it
    1.70 +   */
    1.71 +  NS_IMETHOD SetHasFocus(bool aHasFocus);
    1.72 +
    1.73 +  virtual void BuildDisplayList(nsDisplayListBuilder*   aBuilder,
    1.74 +                                const nsRect&           aDirtyRect,
    1.75 +                                const nsDisplayListSet& aLists) MOZ_OVERRIDE;
    1.76 +
    1.77 +  void PaintFocus(nsRenderingContext& aRenderingContext, nsPoint aPt);
    1.78 +
    1.79 +  // nsIScrollPositionListener
    1.80 +  virtual void ScrollPositionWillChange(nscoord aX, nscoord aY) MOZ_OVERRIDE;
    1.81 +  virtual void ScrollPositionDidChange(nscoord aX, nscoord aY) MOZ_OVERRIDE {}
    1.82 +
    1.83 +  /**
    1.84 +   * Get the "type" of the frame
    1.85 +   *
    1.86 +   * @see nsGkAtoms::canvasFrame
    1.87 +   */
    1.88 +  virtual nsIAtom* GetType() const MOZ_OVERRIDE;
    1.89 +
    1.90 +  virtual nsresult StealFrame(nsIFrame* aChild, bool aForceNormal) MOZ_OVERRIDE
    1.91 +  {
    1.92 +    NS_ASSERTION(!aForceNormal, "No-one should be passing this in here");
    1.93 +
    1.94 +    // nsCanvasFrame keeps overflow container continuations of its child
    1.95 +    // frame in main child list
    1.96 +    nsresult rv = nsContainerFrame::StealFrame(aChild, true);
    1.97 +    if (NS_FAILED(rv)) {
    1.98 +      rv = nsContainerFrame::StealFrame(aChild);
    1.99 +    }
   1.100 +    return rv;
   1.101 +  }
   1.102 +
   1.103 +#ifdef DEBUG_FRAME_DUMP
   1.104 +  virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
   1.105 +#endif
   1.106 +  virtual nsresult GetContentForEvent(mozilla::WidgetEvent* aEvent,
   1.107 +                                      nsIContent** aContent) MOZ_OVERRIDE;
   1.108 +
   1.109 +  nsRect CanvasArea() const;
   1.110 +
   1.111 +protected:
   1.112 +  // Data members
   1.113 +  bool                      mDoPaintFocus;
   1.114 +  bool                      mAddedScrollPositionListener;
   1.115 +};
   1.116 +
   1.117 +/**
   1.118 + * Override nsDisplayBackground methods so that we pass aBGClipRect to
   1.119 + * PaintBackground, covering the whole overflow area.
   1.120 + * We can also paint an "extra background color" behind the normal
   1.121 + * background.
   1.122 + */
   1.123 +class nsDisplayCanvasBackgroundColor : public nsDisplayItem {
   1.124 +public:
   1.125 +  nsDisplayCanvasBackgroundColor(nsDisplayListBuilder* aBuilder, nsIFrame *aFrame)
   1.126 +    : nsDisplayItem(aBuilder, aFrame)
   1.127 +    , mColor(NS_RGBA(0,0,0,0))
   1.128 +  {
   1.129 +  }
   1.130 +
   1.131 +  virtual bool ComputeVisibility(nsDisplayListBuilder* aBuilder,
   1.132 +                                 nsRegion* aVisibleRegion,
   1.133 +                                 const nsRect& aAllowVisibleRegionExpansion) MOZ_OVERRIDE
   1.134 +  {
   1.135 +    return NS_GET_A(mColor) > 0;
   1.136 +  }
   1.137 +  virtual nsRegion GetOpaqueRegion(nsDisplayListBuilder* aBuilder,
   1.138 +                                   bool* aSnap) MOZ_OVERRIDE
   1.139 +  {
   1.140 +    if (NS_GET_A(mColor) == 255) {
   1.141 +      return nsRegion(GetBounds(aBuilder, aSnap));
   1.142 +    }
   1.143 +    return nsRegion();
   1.144 +  }
   1.145 +  virtual bool IsUniform(nsDisplayListBuilder* aBuilder, nscolor* aColor) MOZ_OVERRIDE
   1.146 +  {
   1.147 +    *aColor = mColor;
   1.148 +    return true;
   1.149 +  }
   1.150 +  virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) MOZ_OVERRIDE
   1.151 +  {
   1.152 +    nsCanvasFrame* frame = static_cast<nsCanvasFrame*>(mFrame);
   1.153 +    *aSnap = true;
   1.154 +    return frame->CanvasArea() + ToReferenceFrame();
   1.155 +  }
   1.156 +  virtual void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
   1.157 +                       HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames) MOZ_OVERRIDE
   1.158 +  {
   1.159 +    // We need to override so we don't consider border-radius.
   1.160 +    aOutFrames->AppendElement(mFrame);
   1.161 +  }
   1.162 +
   1.163 +  virtual nsDisplayItemGeometry* AllocateGeometry(nsDisplayListBuilder* aBuilder) MOZ_OVERRIDE
   1.164 +  {
   1.165 +    return new nsDisplayItemBoundsGeometry(this, aBuilder);
   1.166 +  }
   1.167 +
   1.168 +  virtual void ComputeInvalidationRegion(nsDisplayListBuilder* aBuilder,
   1.169 +                                         const nsDisplayItemGeometry* aGeometry,
   1.170 +                                         nsRegion* aInvalidRegion) MOZ_OVERRIDE
   1.171 +  {
   1.172 +    const nsDisplayItemBoundsGeometry* geometry = static_cast<const nsDisplayItemBoundsGeometry*>(aGeometry);
   1.173 +    ComputeInvalidationRegionDifference(aBuilder, geometry, aInvalidRegion);
   1.174 +  }
   1.175 +
   1.176 +  virtual void Paint(nsDisplayListBuilder* aBuilder,
   1.177 +                     nsRenderingContext* aCtx) MOZ_OVERRIDE;
   1.178 +
   1.179 +  void SetExtraBackgroundColor(nscolor aColor)
   1.180 +  {
   1.181 +    mColor = aColor;
   1.182 +  }
   1.183 +
   1.184 +  NS_DISPLAY_DECL_NAME("CanvasBackgroundColor", TYPE_CANVAS_BACKGROUND_COLOR)
   1.185 +
   1.186 +private:
   1.187 +  nscolor mColor;
   1.188 +};
   1.189 +
   1.190 +class nsDisplayCanvasBackgroundImage : public nsDisplayBackgroundImage {
   1.191 +public:
   1.192 +  nsDisplayCanvasBackgroundImage(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame,
   1.193 +                                 uint32_t aLayer, const nsStyleBackground* aBg)
   1.194 +    : nsDisplayBackgroundImage(aBuilder, aFrame, aLayer, aBg)
   1.195 +  {}
   1.196 +
   1.197 +  virtual void Paint(nsDisplayListBuilder* aBuilder, nsRenderingContext* aCtx) MOZ_OVERRIDE;
   1.198 +
   1.199 +  virtual void NotifyRenderingChanged() MOZ_OVERRIDE
   1.200 +  {
   1.201 +    mFrame->Properties().Delete(nsIFrame::CachedBackgroundImage());
   1.202 +    mFrame->Properties().Delete(nsIFrame::CachedBackgroundImageDT());
   1.203 +  }
   1.204 +
   1.205 +  virtual bool ShouldFixToViewport(nsDisplayListBuilder* aBuilder) MOZ_OVERRIDE
   1.206 +  {
   1.207 +    // Put background-attachment:fixed canvas background images in their own
   1.208 +    // compositing layer. Since we know their background painting area can't
   1.209 +    // change (unless the viewport size itself changes), async scrolling
   1.210 +    // will work well.
   1.211 +    return mBackgroundStyle->mLayers[mLayer].mAttachment == NS_STYLE_BG_ATTACHMENT_FIXED &&
   1.212 +           !mBackgroundStyle->mLayers[mLayer].mImage.IsEmpty();
   1.213 +  }
   1.214 + 
   1.215 +  // We still need to paint a background color as well as an image for this item, 
   1.216 +  // so we can't support this yet.
   1.217 +  virtual bool SupportsOptimizingToImage() MOZ_OVERRIDE { return false; }
   1.218 +  
   1.219 +  
   1.220 +  NS_DISPLAY_DECL_NAME("CanvasBackgroundImage", TYPE_CANVAS_BACKGROUND_IMAGE)
   1.221 +};
   1.222 +
   1.223 +class nsDisplayCanvasThemedBackground : public nsDisplayThemedBackground {
   1.224 +public:
   1.225 +  nsDisplayCanvasThemedBackground(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
   1.226 +    : nsDisplayThemedBackground(aBuilder, aFrame)
   1.227 +  {}
   1.228 +
   1.229 +  virtual void Paint(nsDisplayListBuilder* aBuilder, nsRenderingContext* aCtx) MOZ_OVERRIDE;
   1.230 +
   1.231 +  NS_DISPLAY_DECL_NAME("CanvasThemedBackground", TYPE_CANVAS_THEMED_BACKGROUND)
   1.232 +};
   1.233 +
   1.234 +#endif /* nsCanvasFrame_h___ */

mercurial