author Mats Palmgren <>
Fri, 26 May 2017 12:11:11 +0200
changeset 360757 78e989ad55af7cf13cfafcb4ba891cc5ea78d740
parent 360755 47ed59045f9bff59434723249b995515116d4ed0
child 360973 b37e4d256cd6c88b48b0223113375f889a748982
permissions -rw-r--r--
Bug 1364805 part 4 - Remove the now unused LayoutFrameType values from the ctors. r=jfkthame MozReview-Commit-ID: 1RSDoc3pQXf

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at */

/* rendering object that goes directly inside the document's scrollbars */

#ifndef nsCanvasFrame_h___
#define nsCanvasFrame_h___

#include "mozilla/Attributes.h"
#include "mozilla/EventForwards.h"
#include "nsContainerFrame.h"
#include "nsIScrollPositionListener.h"
#include "nsDisplayList.h"
#include "nsIAnonymousContentCreator.h"
#include "gfxPrefs.h"

class nsPresContext;
class nsRenderingContext;

 * Root frame class.
 * The root frame is the parent frame for the document element's frame.
 * It only supports having a single child frame which must be an area
 * frame.
 * @note nsCanvasFrame keeps overflow container continuations of its child
 * frame in the main child list.
class nsCanvasFrame final : public nsContainerFrame,
                            public nsIScrollPositionListener,
                            public nsIAnonymousContentCreator
  explicit nsCanvasFrame(nsStyleContext* aContext)
    : nsContainerFrame(aContext, kClassID)
    , mDoPaintFocus(false)
    , mAddedScrollPositionListener(false)


  virtual void DestroyFrom(nsIFrame* aDestructRoot) override;

  virtual void SetInitialChildList(ChildListID     aListID,
                                   nsFrameList&    aChildList) override;
  virtual void AppendFrames(ChildListID     aListID,
                            nsFrameList&    aFrameList) override;
  virtual void InsertFrames(ChildListID     aListID,
                            nsIFrame*       aPrevFrame,
                            nsFrameList&    aFrameList) override;
#ifdef DEBUG
  virtual void RemoveFrame(ChildListID     aListID,
                           nsIFrame*       aOldFrame) override;

  virtual nscoord GetMinISize(nsRenderingContext *aRenderingContext) override;
  virtual nscoord GetPrefISize(nsRenderingContext *aRenderingContext) override;
  virtual void Reflow(nsPresContext*           aPresContext,
                      ReflowOutput&     aDesiredSize,
                      const ReflowInput& aReflowInput,
                      nsReflowStatus&          aStatus) override;
  virtual bool IsFrameOfType(uint32_t aFlags) const override
    return nsContainerFrame::IsFrameOfType(aFlags &

  // nsIAnonymousContentCreator
  virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) override;
  virtual void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements, uint32_t aFilter) override;

  mozilla::dom::Element* GetCustomContentContainer() const
    return mCustomContentContainer;

   * Unhide the CustomContentContainer. This call only has an effect if
   * mCustomContentContainer is non-null.
  void ShowCustomContentContainer();

   * Hide the CustomContentContainer. This call only has an effect if
   * mCustomContentContainer is non-null.
  void HideCustomContentContainer();

  /** SetHasFocus tells the CanvasFrame to draw with focus ring
   *  @param aHasFocus true to show focus ring, false to hide it
  NS_IMETHOD SetHasFocus(bool aHasFocus);

  virtual void BuildDisplayList(nsDisplayListBuilder*   aBuilder,
                                const nsRect&           aDirtyRect,
                                const nsDisplayListSet& aLists) override;

  void PaintFocus(mozilla::gfx::DrawTarget* aRenderingContext, nsPoint aPt);

  // nsIScrollPositionListener
  virtual void ScrollPositionWillChange(nscoord aX, nscoord aY) override;
  virtual void ScrollPositionDidChange(nscoord aX, nscoord aY) override {}

  virtual nsresult GetFrameName(nsAString& aResult) const override;
  virtual nsresult GetContentForEvent(mozilla::WidgetEvent* aEvent,
                                      nsIContent** aContent) override;

  nsRect CanvasArea() const;

  // Utility function to propagate the WritingMode from our first child to
  // 'this' and all its ancestors.
  void MaybePropagateRootElementWritingMode();

  // Data members
  bool                      mDoPaintFocus;
  bool                      mAddedScrollPositionListener;

  nsCOMPtr<mozilla::dom::Element> mCustomContentContainer;

 * Override nsDisplayBackground methods so that we pass aBGClipRect to
 * PaintBackground, covering the whole overflow area.
 * We can also paint an "extra background color" behind the normal
 * background.
class nsDisplayCanvasBackgroundColor : public nsDisplaySolidColorBase {
  nsDisplayCanvasBackgroundColor(nsDisplayListBuilder* aBuilder, nsIFrame *aFrame)
    : nsDisplaySolidColorBase(aBuilder, aFrame, NS_RGBA(0,0,0,0))

  virtual bool ComputeVisibility(nsDisplayListBuilder* aBuilder,
                                 nsRegion* aVisibleRegion) override
    return NS_GET_A(mColor) > 0;
  virtual nsRect GetBounds(nsDisplayListBuilder* aBuilder, bool* aSnap) override
    nsCanvasFrame* frame = static_cast<nsCanvasFrame*>(mFrame);
    *aSnap = true;
    return frame->CanvasArea() + ToReferenceFrame();
  virtual void HitTest(nsDisplayListBuilder* aBuilder, const nsRect& aRect,
                       HitTestState* aState, nsTArray<nsIFrame*> *aOutFrames) override
    // We need to override so we don't consider border-radius.
  virtual already_AddRefed<Layer> BuildLayer(nsDisplayListBuilder* aBuilder,
                                             LayerManager* aManager,
                                             const ContainerLayerParameters& aContainerParameters) override;
  virtual void CreateWebRenderCommands(mozilla::wr::DisplayListBuilder& aBuilder,
                                       const StackingContextHelper& aSc,
                                       nsTArray<WebRenderParentCommand>& aParentCommands,
                                       mozilla::layers::WebRenderDisplayItemLayer* aLayer) override;

  virtual LayerState GetLayerState(nsDisplayListBuilder* aBuilder,
                                   LayerManager* aManager,
                                   const ContainerLayerParameters& aParameters) override
    if (ShouldUseAdvancedLayer(aManager, gfxPrefs::LayersAllowCanvasBackgroundColorLayers) ||
        ForceActiveLayers()) {
      return mozilla::LAYER_ACTIVE;
    return mozilla::LAYER_NONE;
  virtual void Paint(nsDisplayListBuilder* aBuilder,
                     nsRenderingContext* aCtx) override;

  void SetExtraBackgroundColor(nscolor aColor)
    mColor = aColor;

  virtual void WriteDebugInfo(std::stringstream& aStream) override;

class nsDisplayCanvasBackgroundImage : public nsDisplayBackgroundImage {
  explicit nsDisplayCanvasBackgroundImage(const InitData& aInitData)
    : nsDisplayBackgroundImage(aInitData)

  virtual void Paint(nsDisplayListBuilder* aBuilder, nsRenderingContext* aCtx) override;

  virtual void NotifyRenderingChanged() override
  // We still need to paint a background color as well as an image for this item, 
  // so we can't support this yet.
  virtual bool SupportsOptimizingToImage() override { return false; }

  bool IsSingleFixedPositionImage(nsDisplayListBuilder* aBuilder,
                                  const nsRect& aClipRect,
                                  gfxRect* aDestRect);

class nsDisplayCanvasThemedBackground : public nsDisplayThemedBackground {
  nsDisplayCanvasThemedBackground(nsDisplayListBuilder* aBuilder, nsIFrame* aFrame)
    : nsDisplayThemedBackground(aBuilder, aFrame,
                                aFrame->GetRectRelativeToSelf() + aBuilder->ToReferenceFrame(aFrame))

  virtual void Paint(nsDisplayListBuilder* aBuilder, nsRenderingContext* aCtx) override;


#endif /* nsCanvasFrame_h___ */