Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Side by Side Diff: third_party/WebKit/Source/core/html/shadow/MediaControls.h

Issue 2795783004: Move core MediaControls implementation to modules/media_controls/. (Closed)
Patch Set: rebase Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
3 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 #ifndef MediaControls_h
28 #define MediaControls_h
29
30 #include "core/html/HTMLDivElement.h"
31 #include "core/html/shadow/MediaControlElements.h"
32
33 namespace blink {
34
35 class Event;
36 class MediaControlsMediaEventListener;
37 class MediaControlsOrientationLockDelegate;
38 class MediaControlsWindowEventListener;
39 class ShadowRoot;
40
41 class CORE_EXPORT MediaControls final : public HTMLDivElement {
42 public:
43 static MediaControls* create(HTMLMediaElement&, ShadowRoot&);
44
45 HTMLMediaElement& mediaElement() const { return *m_mediaElement; }
46
47 // Node override.
48 Node::InsertionNotificationRequest insertedInto(ContainerNode*) override;
49 void removedFrom(ContainerNode*) override;
50
51 void reset();
52 void onControlsListUpdated();
53
54 void show();
55 void hide();
56 bool isVisible() const;
57
58 void beginScrubbing();
59 void endScrubbing();
60
61 void updateCurrentTimeDisplay();
62
63 void toggleTextTrackList();
64 void showTextTrackAtIndex(unsigned indexToEnable);
65 void disableShowingTextTracks();
66
67 // Called by the fullscreen buttons to toggle fulllscreen on/off.
68 void enterFullscreen();
69 void exitFullscreen();
70
71 void showOverlayCastButtonIfNeeded();
72 // Update cast button visibility, but don't try to update our panel
73 // button visibility for space.
74 void refreshCastButtonVisibilityWithoutUpdate();
75
76 void setAllowHiddenVolumeControls(bool);
77
78 // Returns the layout object for the part of the controls that should be
79 // used for overlap checking during text track layout. May be null.
80 LayoutObject* layoutObjectForTextTrackLayout();
81
82 // Return the internal elements, which is used by registering clicking
83 // EventHandlers from MediaControlsWindowEventListener.
84 MediaControlPanelElement* panelElement() { return m_panel; }
85 MediaControlTimelineElement* timelineElement() { return m_timeline; }
86 MediaControlCastButtonElement* castButtonElement() { return m_castButton; }
87 MediaControlVolumeSliderElement* volumeSliderElement() {
88 return m_volumeSlider;
89 }
90
91 // Notify us that the media element's network state has changed.
92 void networkStateChanged();
93
94 void toggleOverflowMenu();
95
96 bool overflowMenuVisible();
97
98 // TODO(mlamouri): this is temporary to notify the controls that an
99 // HTMLTrackElement failed to load because there is no web exposed way to
100 // be notified on the TextTrack object. See https://crbug.com/669977
101 void onTrackElementFailedToLoad() { onTextTracksAddedOrRemoved(); }
102
103 // TODO(mlamouri): the following methods will be able to become private when
104 // the controls have moved to modules/ and have access to RemotePlayback.
105 void onRemotePlaybackAvailabilityChanged() { refreshCastButtonVisibility(); }
106 void onRemotePlaybackConnecting() { startedCasting(); }
107 void onRemotePlaybackDisconnected() { stoppedCasting(); }
108
109 // TODO(mlamouri): this method is needed in order to notify the controls that
110 // the attribute have changed.
111 void onDisableRemotePlaybackAttributeChanged() {
112 refreshCastButtonVisibility();
113 }
114
115 // TODO(mlamouri): this method is needed in order to notify the controls that
116 // the `mediaControlsEnabled` setting has changed.
117 void onMediaControlsEnabledChange() {
118 // There is no update because only the overlay is expected to change.
119 refreshCastButtonVisibilityWithoutUpdate();
120 }
121
122 DECLARE_VIRTUAL_TRACE();
123
124 private:
125 friend class MediaControlsMediaEventListener;
126 friend class MediaControlsOrientationLockDelegateTest;
127 friend class MediaControlsTest;
128
129 void invalidate(Element*);
130
131 // Need to be members of MediaControls for private member access.
132 class BatchedControlUpdate;
133 class MediaControlsResizeObserverCallback;
134
135 // Notify us that our controls enclosure has changed size.
136 void notifyElementSizeChanged(ClientRect* newSize);
137
138 explicit MediaControls(HTMLMediaElement&);
139
140 void initializeControls();
141
142 void makeOpaque();
143 void makeTransparent();
144
145 void updatePlayState();
146
147 enum HideBehaviorFlags {
148 IgnoreNone = 0,
149 IgnoreVideoHover = 1 << 0,
150 IgnoreFocus = 1 << 1,
151 IgnoreControlsHover = 1 << 2,
152 IgnoreWaitForTimer = 1 << 3,
153 };
154
155 bool shouldHideMediaControls(unsigned behaviorFlags = 0) const;
156 void hideMediaControlsTimerFired(TimerBase*);
157 void startHideMediaControlsTimer();
158 void stopHideMediaControlsTimer();
159 void resetHideMediaControlsTimer();
160
161 void elementSizeChangedTimerFired(TimerBase*);
162
163 void hideAllMenus();
164
165 // Hide elements that don't fit, and show those things that we want which
166 // do fit. This requires that m_effectiveWidth and m_effectiveHeight are
167 // current.
168 void computeWhichControlsFit();
169
170 // Node
171 bool isMediaControls() const override { return true; }
172 bool willRespondToMouseMoveEvents() override { return true; }
173 void defaultEventHandler(Event*) override;
174 bool containsRelatedTarget(Event*);
175
176 // Methods called by MediaControlsMediaEventListener.
177 void onVolumeChange();
178 void onFocusIn();
179 void onTimeUpdate();
180 void onDurationChange();
181 void onPlay();
182 void onPause();
183 void onTextTracksAddedOrRemoved();
184 void onTextTracksChanged();
185 void onError();
186 void onLoadedMetadata();
187 void onEnteredFullscreen();
188 void onExitedFullscreen();
189
190 // Internal cast related methods.
191 void startedCasting();
192 void stoppedCasting();
193 void refreshCastButtonVisibility();
194
195 Member<HTMLMediaElement> m_mediaElement;
196
197 // Media control elements.
198 Member<MediaControlOverlayEnclosureElement> m_overlayEnclosure;
199 Member<MediaControlOverlayPlayButtonElement> m_overlayPlayButton;
200 Member<MediaControlCastButtonElement> m_overlayCastButton;
201 Member<MediaControlPanelEnclosureElement> m_enclosure;
202 Member<MediaControlPanelElement> m_panel;
203 Member<MediaControlPlayButtonElement> m_playButton;
204 Member<MediaControlTimelineElement> m_timeline;
205 Member<MediaControlCurrentTimeDisplayElement> m_currentTimeDisplay;
206 Member<MediaControlTimeRemainingDisplayElement> m_durationDisplay;
207 Member<MediaControlMuteButtonElement> m_muteButton;
208 Member<MediaControlVolumeSliderElement> m_volumeSlider;
209 Member<MediaControlToggleClosedCaptionsButtonElement>
210 m_toggleClosedCaptionsButton;
211 Member<MediaControlTextTrackListElement> m_textTrackList;
212 Member<MediaControlOverflowMenuButtonElement> m_overflowMenu;
213 Member<MediaControlOverflowMenuListElement> m_overflowList;
214
215 Member<MediaControlCastButtonElement> m_castButton;
216 Member<MediaControlFullscreenButtonElement> m_fullscreenButton;
217 Member<MediaControlDownloadButtonElement> m_downloadButton;
218
219 Member<MediaControlsMediaEventListener> m_mediaEventListener;
220 Member<MediaControlsWindowEventListener> m_windowEventListener;
221 Member<MediaControlsOrientationLockDelegate> m_orientationLockDelegate;
222
223 TaskRunnerTimer<MediaControls> m_hideMediaControlsTimer;
224 unsigned m_hideTimerBehaviorFlags;
225 bool m_isMouseOverControls : 1;
226 bool m_isPausedForScrubbing : 1;
227
228 // Watches the video element for resize and updates media controls as
229 // necessary.
230 Member<ResizeObserver> m_resizeObserver;
231
232 TaskRunnerTimer<MediaControls> m_elementSizeChangedTimer;
233 IntSize m_size;
234
235 bool m_keepShowingUntilTimerFires : 1;
236 };
237
238 DEFINE_ELEMENT_TYPE_CASTS(MediaControls, isMediaControls());
239
240 } // namespace blink
241
242 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698