2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
3 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
27 #ifndef MediaControls_h
28 #define MediaControls_h
30 #include "core/html/HTMLDivElement.h"
31 #include "core/html/shadow/MediaControlElements.h"
36 class MediaControlsMediaEventListener;
37 class MediaControlsWindowEventListener;
39 class CORE_EXPORT MediaControls final : public HTMLDivElement {
41 static MediaControls* create(HTMLMediaElement&);
43 HTMLMediaElement& mediaElement() const { return *m_mediaElement; }
49 bool isVisible() const;
51 void playbackStarted();
52 void playbackProgressed();
53 void playbackStopped();
55 void beginScrubbing();
58 void updateCurrentTimeDisplay();
60 void changedClosedCaptionsVisibility();
61 void refreshClosedCaptionsButtonVisibility();
62 void toggleTextTrackList();
63 void showTextTrackAtIndex(unsigned indexToEnable);
64 void disableShowingTextTracks();
66 void enteredFullscreen();
67 void exitedFullscreen();
69 void startedCasting();
70 void stoppedCasting();
71 void refreshCastButtonVisibility();
72 void showOverlayCastButtonIfNeeded();
73 // Update cast button visibility, but don't try to update our panel
74 // button visibility for space.
75 void refreshCastButtonVisibilityWithoutUpdate();
77 void setAllowHiddenVolumeControls(bool);
79 // Returns the layout object for the part of the controls that should be
80 // used for overlap checking during text track layout. May be null.
81 LayoutObject* layoutObjectForTextTrackLayout();
83 // Return the internal elements, which is used by registering clicking
84 // EventHandlers from MediaControlsWindowEventListener.
85 MediaControlPanelElement* panelElement() { return m_panel; }
86 MediaControlTimelineElement* timelineElement() { return m_timeline; }
87 MediaControlCastButtonElement* castButtonElement() { return m_castButton; }
88 MediaControlVolumeSliderElement* volumeSliderElement() {
89 return m_volumeSlider;
92 // Notify us that our controls enclosure has changed width.
93 void notifyPanelWidthChanged(const LayoutUnit& newWidth);
95 // Notify us that the media element's network state has changed.
96 void networkStateChanged();
98 void toggleOverflowMenu();
100 bool overflowMenuVisible();
102 #if defined(TIZEN_VIDEO_MANUAL_ROTATION_SUPPORT)
103 void enableManualRotateButton(bool);
106 DECLARE_VIRTUAL_TRACE();
108 #if defined(TIZEN_MULTIMEDIA_SUPPORT)
111 int getSpinnerProgressCount() const;
112 void setSpinnerProgressCount(int);
114 void systemVolumeChanged();
118 friend class MediaControlsMediaEventListener;
119 friend class MediaControlsTest;
121 void invalidate(Element*);
123 class BatchedControlUpdate;
125 explicit MediaControls(HTMLMediaElement&);
127 void initializeControls();
130 void makeTransparent();
132 #if defined(TIZEN_MULTIMEDIA_SUPPORT)
133 void onSpinnerTimerFired(TimerBase*);
136 void updatePlayState();
138 enum HideBehaviorFlags {
140 IgnoreVideoHover = 1 << 0,
141 IgnoreFocus = 1 << 1,
142 IgnoreControlsHover = 1 << 2,
143 IgnoreWaitForTimer = 1 << 3,
146 bool shouldHideMediaControls(unsigned behaviorFlags = 0) const;
147 void hideMediaControlsTimerFired(TimerBase*);
148 void startHideMediaControlsTimer();
149 void stopHideMediaControlsTimer();
150 void resetHideMediaControlsTimer();
152 void panelWidthChangedTimerFired(TimerBase*);
156 // Hide elements that don't fit, and show those things that we want which
157 // do fit. This requires that m_panelWidth is current.
158 void computeWhichControlsFit();
161 bool isMediaControls() const override { return true; }
162 bool willRespondToMouseMoveEvents() override { return true; }
163 void defaultEventHandler(Event*) override;
164 bool containsRelatedTarget(Event*);
166 // Methods called by MediaControlsMediaEventListener.
167 void onVolumeChange();
170 Member<HTMLMediaElement> m_mediaElement;
172 // Media control elements.
173 Member<MediaControlOverlayEnclosureElement> m_overlayEnclosure;
174 Member<MediaControlOverlayPlayButtonElement> m_overlayPlayButton;
176 #if defined(TIZEN_VIDEO_MANUAL_ROTATION_SUPPORT)
177 Member<MediaControlRotateButtonElement> m_rotateButton;
180 Member<MediaControlCastButtonElement> m_overlayCastButton;
181 Member<MediaControlPanelEnclosureElement> m_enclosure;
182 Member<MediaControlPanelElement> m_panel;
183 Member<MediaControlPlayButtonElement> m_playButton;
185 #if defined(OS_TIZEN)
186 Member<MediaControlSeekBackButtonElement> m_seekBackButton;
187 Member<MediaControlSeekForwardButtonElement> m_seekForwardButton;
190 Member<MediaControlTimelineElement> m_timeline;
191 Member<MediaControlCurrentTimeDisplayElement> m_currentTimeDisplay;
192 Member<MediaControlTimeRemainingDisplayElement> m_durationDisplay;
193 Member<MediaControlMuteButtonElement> m_muteButton;
194 Member<MediaControlVolumeSliderElement> m_volumeSlider;
195 Member<MediaControlToggleClosedCaptionsButtonElement>
196 m_toggleClosedCaptionsButton;
197 Member<MediaControlTextTrackListElement> m_textTrackList;
198 Member<MediaControlOverflowMenuButtonElement> m_overflowMenu;
199 Member<MediaControlOverflowMenuListElement> m_overflowList;
201 Member<MediaControlCastButtonElement> m_castButton;
202 Member<MediaControlFullscreenButtonElement> m_fullscreenButton;
203 Member<MediaControlDownloadButtonElement> m_downloadButton;
205 Member<MediaControlsMediaEventListener> m_mediaEventListener;
206 Member<MediaControlsWindowEventListener> m_windowEventListener;
208 Timer<MediaControls> m_hideMediaControlsTimer;
209 unsigned m_hideTimerBehaviorFlags;
210 bool m_isMouseOverControls : 1;
211 bool m_isPausedForScrubbing : 1;
213 #if defined(TIZEN_MULTIMEDIA_SUPPORT)
214 Member<MediaControlOverlaySpinnerElement> m_overlaySpinner;
215 Timer<MediaControls> m_spinnerTimer;
217 int m_spinnerProgressCount;
220 Timer<MediaControls> m_panelWidthChangedTimer;
223 bool m_keepShowingUntilTimerFires : 1;
226 DEFINE_ELEMENT_TYPE_CASTS(MediaControls, isMediaControls());