1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 /* rendering object for the HTML <canvas> element */
8 
9 #ifndef nsHTMLCanvasFrame_h___
10 #define nsHTMLCanvasFrame_h___
11 
12 #include "mozilla/Attributes.h"
13 #include "nsContainerFrame.h"
14 #include "nsStringFwd.h"
15 
16 namespace mozilla {
17 class PresShell;
18 namespace layers {
19 class CanvasRenderer;
20 class Layer;
21 class LayerManager;
22 class WebRenderCanvasData;
23 }  // namespace layers
24 }  // namespace mozilla
25 
26 class nsPresContext;
27 
28 nsIFrame* NS_NewHTMLCanvasFrame(mozilla::PresShell* aPresShell,
29                                 mozilla::ComputedStyle* aStyle);
30 
31 class nsHTMLCanvasFrame final : public nsContainerFrame {
32  public:
33   typedef mozilla::layers::CanvasRenderer CanvasRenderer;
34   typedef mozilla::layers::Layer Layer;
35   typedef mozilla::layers::LayerManager LayerManager;
36   typedef mozilla::layers::WebRenderCanvasData WebRenderCanvasData;
37 
38   NS_DECL_QUERYFRAME
NS_DECL_FRAMEARENA_HELPERS(nsHTMLCanvasFrame)39   NS_DECL_FRAMEARENA_HELPERS(nsHTMLCanvasFrame)
40 
41   nsHTMLCanvasFrame(ComputedStyle* aStyle, nsPresContext* aPresContext)
42       : nsContainerFrame(aStyle, aPresContext, kClassID) {}
43 
44   virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
45                                 const nsDisplayListSet& aLists) override;
46 
47   void DestroyFrom(nsIFrame*, PostDestroyData&) override;
48 
49   bool UpdateWebRenderCanvasData(nsDisplayListBuilder* aBuilder,
50                                  WebRenderCanvasData* aCanvasData);
51 
52   /* get the size of the canvas's image */
53   nsIntSize GetCanvasSize() const;
54 
55   virtual nscoord GetMinISize(gfxContext* aRenderingContext) override;
56   virtual nscoord GetPrefISize(gfxContext* aRenderingContext) override;
57   virtual mozilla::IntrinsicSize GetIntrinsicSize() override;
58   mozilla::AspectRatio GetIntrinsicRatio() const override;
59 
60   SizeComputationResult ComputeSize(
61       gfxContext* aRenderingContext, mozilla::WritingMode aWM,
62       const mozilla::LogicalSize& aCBSize, nscoord aAvailableISize,
63       const mozilla::LogicalSize& aMargin,
64       const mozilla::LogicalSize& aBorderPadding,
65       const mozilla::StyleSizeOverrides& aSizeOverrides,
66       mozilla::ComputeSizeFlags aFlags) override;
67 
68   virtual void Reflow(nsPresContext* aPresContext, ReflowOutput& aDesiredSize,
69                       const ReflowInput& aReflowInput,
70                       nsReflowStatus& aStatus) override;
71 
72 #ifdef ACCESSIBILITY
73   virtual mozilla::a11y::AccType AccessibleType() override;
74 #endif
75 
IsFrameOfType(uint32_t aFlags)76   virtual bool IsFrameOfType(uint32_t aFlags) const override {
77     return nsSplittableFrame::IsFrameOfType(
78         aFlags & ~(nsIFrame::eReplaced | nsIFrame::eReplacedSizing));
79   }
80 
81 #ifdef DEBUG_FRAME_DUMP
82   virtual nsresult GetFrameName(nsAString& aResult) const override;
83 #endif
84 
85   // Inserted child content gets its frames parented by our child block
GetContentInsertionFrame()86   virtual nsContainerFrame* GetContentInsertionFrame() override {
87     return PrincipalChildList().FirstChild()->GetContentInsertionFrame();
88   }
89 
90   // Return the ::-moz-html-canvas-content anonymous box.
91   void AppendDirectlyOwnedAnonBoxes(nsTArray<OwnedAnonBox>& aResult) override;
92 
93  protected:
94   virtual ~nsHTMLCanvasFrame();
95 };
96 
97 #endif /* nsHTMLCanvasFrame_h___ */
98