Line data Source code
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 : /* 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 <video> element */
8 :
9 : #ifndef nsVideoFrame_h___
10 : #define nsVideoFrame_h___
11 :
12 : #include "mozilla/Attributes.h"
13 : #include "nsContainerFrame.h"
14 : #include "nsIAnonymousContentCreator.h"
15 : #include "nsTArrayForwardDeclare.h"
16 : #include "FrameLayerBuilder.h"
17 :
18 : namespace mozilla {
19 : namespace layers {
20 : class Layer;
21 : class LayerManager;
22 : } // namespace layers
23 : } // namespace mozilla
24 :
25 : class nsAString;
26 : class nsPresContext;
27 : class nsDisplayItem;
28 :
29 : class nsVideoFrame : public nsContainerFrame
30 : , public nsIAnonymousContentCreator
31 : {
32 : public:
33 : template <typename T> using Maybe = mozilla::Maybe<T>;
34 : using Nothing = mozilla::Nothing;
35 : using Visibility = mozilla::Visibility;
36 :
37 : typedef mozilla::layers::Layer Layer;
38 : typedef mozilla::layers::LayerManager LayerManager;
39 : typedef mozilla::ContainerLayerParameters ContainerLayerParameters;
40 :
41 : explicit nsVideoFrame(nsStyleContext* aContext);
42 :
43 : NS_DECL_QUERYFRAME
44 0 : NS_DECL_FRAMEARENA_HELPERS(nsVideoFrame)
45 :
46 : void BuildDisplayList(nsDisplayListBuilder* aBuilder,
47 : const nsRect& aDirtyRect,
48 : const nsDisplayListSet& aLists) override;
49 :
50 : nsresult AttributeChanged(int32_t aNameSpaceID,
51 : nsIAtom* aAttribute,
52 : int32_t aModType) override;
53 :
54 : void OnVisibilityChange(Visibility aNewVisibility,
55 : const Maybe<OnNonvisible>& aNonvisibleAction = Nothing()) override;
56 :
57 : /* get the size of the video's display */
58 : nsSize GetVideoIntrinsicSize(gfxContext *aRenderingContext);
59 : nsSize GetIntrinsicRatio() override;
60 : mozilla::LogicalSize
61 : ComputeSize(gfxContext *aRenderingContext,
62 : mozilla::WritingMode aWritingMode,
63 : const mozilla::LogicalSize& aCBSize,
64 : nscoord aAvailableISize,
65 : const mozilla::LogicalSize& aMargin,
66 : const mozilla::LogicalSize& aBorder,
67 : const mozilla::LogicalSize& aPadding,
68 : ComputeSizeFlags aFlags) override;
69 : nscoord GetMinISize(gfxContext *aRenderingContext) override;
70 : nscoord GetPrefISize(gfxContext *aRenderingContext) override;
71 : void DestroyFrom(nsIFrame* aDestructRoot) override;
72 :
73 : void Reflow(nsPresContext* aPresContext,
74 : ReflowOutput& aDesiredSize,
75 : const ReflowInput& aReflowInput,
76 : nsReflowStatus& aStatus) override;
77 :
78 : #ifdef ACCESSIBILITY
79 : mozilla::a11y::AccType AccessibleType() override;
80 : #endif
81 :
82 0 : bool IsFrameOfType(uint32_t aFlags) const override
83 : {
84 0 : return nsSplittableFrame::IsFrameOfType(aFlags &
85 0 : ~(nsIFrame::eReplaced | nsIFrame::eReplacedSizing));
86 : }
87 :
88 : nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) override;
89 : void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
90 : uint32_t aFilters) override;
91 :
92 : nsIContent* GetPosterImage() { return mPosterImage; }
93 :
94 : // Returns true if we should display the poster. Note that once we show
95 : // a video frame, the poster will never be displayed again.
96 : bool ShouldDisplayPoster();
97 :
98 0 : nsIContent *GetCaptionOverlay() { return mCaptionDiv; }
99 :
100 0 : nsIContent *GetVideoControls() { return mVideoControls; }
101 :
102 : #ifdef DEBUG_FRAME_DUMP
103 : nsresult GetFrameName(nsAString& aResult) const override;
104 : #endif
105 :
106 : already_AddRefed<Layer> BuildLayer(nsDisplayListBuilder* aBuilder,
107 : LayerManager* aManager,
108 : nsDisplayItem* aItem,
109 : const ContainerLayerParameters& aContainerParameters);
110 :
111 : protected:
112 :
113 : // Returns true if we're rendering for a video element. We still create
114 : // nsVideoFrame to render controls for an audio element.
115 : bool HasVideoElement();
116 :
117 : // Returns true if there is video data to render. Can return false
118 : // when we're the frame for an audio element, or we've created a video
119 : // element for a media which is audio-only.
120 : bool HasVideoData();
121 :
122 : // Sets the mPosterImage's src attribute to be the video's poster attribute,
123 : // if we're the frame for a video element. Only call on frames for video
124 : // elements, not for frames for audio elements.
125 : void UpdatePosterSource(bool aNotify);
126 :
127 : // Notify the mediaElement that the mCaptionDiv was created.
128 : void UpdateTextTrack();
129 :
130 : virtual ~nsVideoFrame();
131 :
132 : // Anonymous child which is bound via XBL to the video controls.
133 : nsCOMPtr<nsIContent> mVideoControls;
134 :
135 : // Anonymous child which is the image element of the poster frame.
136 : nsCOMPtr<nsIContent> mPosterImage;
137 :
138 : // Anonymous child which is the text track caption display div.
139 : nsCOMPtr<nsIContent> mCaptionDiv;
140 :
141 : };
142 :
143 : #endif /* nsVideoFrame_h___ */
|