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