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

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLMediaElement.cpp

Issue 2700663002: Adds keyboard functionality for videos. (Closed)
Patch Set: Created 3 years, 10 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
1 /* 1 /*
2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights
3 * reserved. 3 * 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 #include "core/html/HTMLMediaElement.h" 27 #include "core/html/HTMLMediaElement.h"
28 28
29 #include <limits>
29 #include "bindings/core/v8/ExceptionState.h" 30 #include "bindings/core/v8/ExceptionState.h"
30 #include "bindings/core/v8/Microtask.h" 31 #include "bindings/core/v8/Microtask.h"
31 #include "bindings/core/v8/ScriptController.h" 32 #include "bindings/core/v8/ScriptController.h"
32 #include "bindings/core/v8/ScriptEventListener.h" 33 #include "bindings/core/v8/ScriptEventListener.h"
33 #include "bindings/core/v8/ScriptPromiseResolver.h" 34 #include "bindings/core/v8/ScriptPromiseResolver.h"
34 #include "core/HTMLNames.h" 35 #include "core/HTMLNames.h"
35 #include "core/css/MediaList.h" 36 #include "core/css/MediaList.h"
36 #include "core/dom/Attribute.h" 37 #include "core/dom/Attribute.h"
37 #include "core/dom/DOMException.h" 38 #include "core/dom/DOMException.h"
38 #include "core/dom/ElementTraversal.h" 39 #include "core/dom/ElementTraversal.h"
39 #include "core/dom/ElementVisibilityObserver.h" 40 #include "core/dom/ElementVisibilityObserver.h"
40 #include "core/dom/Fullscreen.h" 41 #include "core/dom/Fullscreen.h"
41 #include "core/dom/TaskRunnerHelper.h" 42 #include "core/dom/TaskRunnerHelper.h"
42 #include "core/dom/shadow/ShadowRoot.h" 43 #include "core/dom/shadow/ShadowRoot.h"
43 #include "core/events/Event.h" 44 #include "core/events/Event.h"
45 #include "core/events/KeyboardEvent.h"
44 #include "core/frame/FrameView.h" 46 #include "core/frame/FrameView.h"
45 #include "core/frame/LocalFrame.h" 47 #include "core/frame/LocalFrame.h"
46 #include "core/frame/Settings.h" 48 #include "core/frame/Settings.h"
47 #include "core/frame/UseCounter.h" 49 #include "core/frame/UseCounter.h"
48 #include "core/frame/csp/ContentSecurityPolicy.h" 50 #include "core/frame/csp/ContentSecurityPolicy.h"
49 #include "core/html/AutoplayUmaHelper.h" 51 #include "core/html/AutoplayUmaHelper.h"
50 #include "core/html/HTMLMediaSource.h" 52 #include "core/html/HTMLMediaSource.h"
51 #include "core/html/HTMLSourceElement.h" 53 #include "core/html/HTMLSourceElement.h"
52 #include "core/html/HTMLTrackElement.h" 54 #include "core/html/HTMLTrackElement.h"
53 #include "core/html/MediaError.h" 55 #include "core/html/MediaError.h"
(...skipping 23 matching lines...) Expand all
77 #include "platform/RuntimeEnabledFeatures.h" 79 #include "platform/RuntimeEnabledFeatures.h"
78 #include "platform/UserGestureIndicator.h" 80 #include "platform/UserGestureIndicator.h"
79 #include "platform/audio/AudioBus.h" 81 #include "platform/audio/AudioBus.h"
80 #include "platform/audio/AudioSourceProviderClient.h" 82 #include "platform/audio/AudioSourceProviderClient.h"
81 #include "platform/graphics/GraphicsLayer.h" 83 #include "platform/graphics/GraphicsLayer.h"
82 #include "platform/mediastream/MediaStreamDescriptor.h" 84 #include "platform/mediastream/MediaStreamDescriptor.h"
83 #include "platform/network/mime/ContentType.h" 85 #include "platform/network/mime/ContentType.h"
84 #include "platform/network/mime/MIMETypeFromURL.h" 86 #include "platform/network/mime/MIMETypeFromURL.h"
85 #include "platform/weborigin/SecurityOrigin.h" 87 #include "platform/weborigin/SecurityOrigin.h"
86 #include "public/platform/Platform.h" 88 #include "public/platform/Platform.h"
89 #include "public/platform/UserMetricsAction.h"
87 #include "public/platform/WebAudioSourceProvider.h" 90 #include "public/platform/WebAudioSourceProvider.h"
88 #include "public/platform/WebContentDecryptionModule.h" 91 #include "public/platform/WebContentDecryptionModule.h"
89 #include "public/platform/WebInbandTextTrack.h" 92 #include "public/platform/WebInbandTextTrack.h"
90 #include "public/platform/WebMediaPlayerSource.h" 93 #include "public/platform/WebMediaPlayerSource.h"
91 #include "public/platform/WebMediaStream.h" 94 #include "public/platform/WebMediaStream.h"
92 #include "public/platform/modules/remoteplayback/WebRemotePlaybackAvailability.h " 95 #include "public/platform/modules/remoteplayback/WebRemotePlaybackAvailability.h "
93 #include "public/platform/modules/remoteplayback/WebRemotePlaybackClient.h" 96 #include "public/platform/modules/remoteplayback/WebRemotePlaybackClient.h"
94 #include "public/platform/modules/remoteplayback/WebRemotePlaybackState.h" 97 #include "public/platform/modules/remoteplayback/WebRemotePlaybackState.h"
95 #include "wtf/AutoReset.h" 98 #include "wtf/AutoReset.h"
96 #include "wtf/CurrentTime.h" 99 #include "wtf/CurrentTime.h"
97 #include "wtf/MathExtras.h" 100 #include "wtf/MathExtras.h"
98 #include "wtf/PtrUtil.h" 101 #include "wtf/PtrUtil.h"
99 #include "wtf/text/CString.h" 102 #include "wtf/text/CString.h"
100 #include <limits>
101 103
102 #ifndef BLINK_MEDIA_LOG 104 #ifndef BLINK_MEDIA_LOG
103 #define BLINK_MEDIA_LOG DVLOG(3) 105 #define BLINK_MEDIA_LOG DVLOG(3)
104 #endif 106 #endif
105 107
106 #ifndef LOG_MEDIA_EVENTS 108 #ifndef LOG_MEDIA_EVENTS
107 // Default to not logging events because so many are generated they can 109 // Default to not logging events because so many are generated they can
108 // overwhelm the rest of the logging. 110 // overwhelm the rest of the logging.
109 #define LOG_MEDIA_EVENTS 0 111 #define LOG_MEDIA_EVENTS 0
110 #endif 112 #endif
(...skipping 3524 matching lines...) Expand 10 before | Expand all | Expand 10 after
3635 3637
3636 ShadowRoot& shadowRoot = ensureUserAgentShadowRoot(); 3638 ShadowRoot& shadowRoot = ensureUserAgentShadowRoot();
3637 m_mediaControls = MediaControls::create(*this, shadowRoot); 3639 m_mediaControls = MediaControls::create(*this, shadowRoot);
3638 3640
3639 // The media controls should be inserted after the text track container, 3641 // The media controls should be inserted after the text track container,
3640 // so that they are rendered in front of captions and subtitles. This check 3642 // so that they are rendered in front of captions and subtitles. This check
3641 // is verifying the contract. 3643 // is verifying the contract.
3642 assertShadowRootChildren(shadowRoot); 3644 assertShadowRootChildren(shadowRoot);
3643 } 3645 }
3644 3646
3647 void HTMLMediaElement::defaultEventHandler(Event* event) {
3648 if (isFocusedElementInDocument()) {
3649 if (event->isKeyboardEvent()) {
3650 int key = toKeyboardEvent(event)->keyCode();
3651 switch (key) {
3652 case ('\r'):
3653 case (' '):
3654 togglePlayState();
3655 return;
3656 case (37):
3657 case (39):
3658 m_mediaControls->timelineElement()->defaultEventHandler(event);
3659 m_mediaControls->startHideMediaControlsTimer();
3660 return;
3661 case (38):
3662 case (40):
3663 m_mediaControls->volumeSliderElement()->defaultEventHandler(event);
3664 m_mediaControls->startHideMediaControlsTimer();
3665 return;
3666 }
3667 }
3668 }
3669 HTMLElement::defaultEventHandler(event);
3670 }
3671
3645 void HTMLMediaElement::updateControlsVisibility() { 3672 void HTMLMediaElement::updateControlsVisibility() {
3646 if (!isConnected()) { 3673 if (!isConnected()) {
3647 if (mediaControls()) 3674 if (mediaControls())
3648 mediaControls()->hide(); 3675 mediaControls()->hide();
3649 return; 3676 return;
3650 } 3677 }
3651 3678
3652 ensureMediaControls(); 3679 ensureMediaControls();
3653 // TODO(mlamouri): this doesn't sound needed but the following tests, on 3680 // TODO(mlamouri): this doesn't sound needed but the following tests, on
3654 // Android fails when removed: 3681 // Android fails when removed:
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after
4126 kMostlyFillViewportBecomeStableSeconds, BLINK_FROM_HERE); 4153 kMostlyFillViewportBecomeStableSeconds, BLINK_FROM_HERE);
4127 } 4154 }
4128 4155
4129 void HTMLMediaElement::viewportFillDebouncerTimerFired(TimerBase*) { 4156 void HTMLMediaElement::viewportFillDebouncerTimerFired(TimerBase*) {
4130 m_mostlyFillingViewport = true; 4157 m_mostlyFillingViewport = true;
4131 if (m_webMediaPlayer) 4158 if (m_webMediaPlayer)
4132 m_webMediaPlayer->becameDominantVisibleContent(m_mostlyFillingViewport); 4159 m_webMediaPlayer->becameDominantVisibleContent(m_mostlyFillingViewport);
4133 } 4160 }
4134 4161
4135 } // namespace blink 4162 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698