diff options
author | Teng-Hui Zhu <ztenghui@google.com> | 2011-12-23 10:40:01 -0800 |
---|---|---|
committer | Teng-Hui Zhu <ztenghui@google.com> | 2012-01-27 15:52:14 -0800 |
commit | 31dba079cf3041945529750234190fc24ed92ab5 (patch) | |
tree | 5ec8112b32fcf1d2318a60669f4f02fb82e5d05e /Source | |
parent | ce7f402c69fcd625a91611f47cd61d1baa3681b9 (diff) | |
download | external_webkit-31dba079cf3041945529750234190fc24ed92ab5.zip external_webkit-31dba079cf3041945529750234190fc24ed92ab5.tar.gz external_webkit-31dba079cf3041945529750234190fc24ed92ab5.tar.bz2 |
Only allow user gesture to play video
Basically, once a guesture trigger a video to load, play or pause, then no need
for future gesture to interact with the video.
Change-Id: I0631ea0d5efc1f6fff89e1eaaebee0e601403b27
Diffstat (limited to 'Source')
-rw-r--r-- | Source/WebCore/html/HTMLMediaElement.cpp | 34 | ||||
-rw-r--r-- | Source/WebCore/html/HTMLMediaElement.h | 4 |
2 files changed, 33 insertions, 5 deletions
diff --git a/Source/WebCore/html/HTMLMediaElement.cpp b/Source/WebCore/html/HTMLMediaElement.cpp index e1f4227..ae0571c 100644 --- a/Source/WebCore/html/HTMLMediaElement.cpp +++ b/Source/WebCore/html/HTMLMediaElement.cpp @@ -178,6 +178,7 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document* docum , m_completelyLoaded(false) #if PLATFORM(ANDROID) , m_lastTouch(0) + , m_userGestureInitiated(false) #endif { LOG(Media, "HTMLMediaElement::HTMLMediaElement"); @@ -187,8 +188,8 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document* docum #if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) // Enable the Media Element to listen to all the touch events document->addListenerTypeIfNeeded(eventNames().touchstartEvent); + m_restrictions |= RequireUserGestureForRateChangeRestriction; #endif - } HTMLMediaElement::~HTMLMediaElement() @@ -515,6 +516,9 @@ void HTMLMediaElement::load(bool isUserGesture, ExceptionCode& ec) ec = INVALID_STATE_ERR; else { m_loadInitiatedByUserGesture = isUserGesture; +#if PLATFORM(ANDROID) + m_userGestureInitiated |= isUserGesture; +#endif prepareForLoad(); loadInternal(); } @@ -1417,9 +1421,19 @@ void HTMLMediaElement::play(bool isUserGesture) { LOG(Media, "HTMLMediaElement::play(isUserGesture : %s)", boolString(isUserGesture)); - if (m_restrictions & RequireUserGestureForRateChangeRestriction && !isUserGesture) + if (m_restrictions & RequireUserGestureForRateChangeRestriction && !isUserGesture +#if PLATFORM(ANDROID) + && !m_userGestureInitiated +#endif + ) return; +#if PLATFORM(ANDROID) + // B/c we set the restriction to require gesture for rate change for + // Android, when we don't early return, we can safely set this to true. + m_userGestureInitiated = true; +#endif + Document* doc = document(); Settings* settings = doc->settings(); if (settings && settings->needsSiteSpecificQuirks() && m_dispatchingCanPlayEvent && !m_loadInitiatedByUserGesture) { @@ -1466,9 +1480,17 @@ void HTMLMediaElement::pause(bool isUserGesture) { LOG(Media, "HTMLMediaElement::pause(isUserGesture : %s)", boolString(isUserGesture)); - if (m_restrictions & RequireUserGestureForRateChangeRestriction && !isUserGesture) + if (m_restrictions & RequireUserGestureForRateChangeRestriction && !isUserGesture +#if PLATFORM(ANDROID) + && !m_userGestureInitiated +#endif + ) return; - +#if PLATFORM(ANDROID) + // B/c we set the restriction to require gesture for rate change for + // Android, when we don't early return, we can safely set this to true. + m_userGestureInitiated = true; +#endif pauseInternal(); } @@ -2406,8 +2428,10 @@ void HTMLMediaElement::defaultEventHandler(Event* event) // It is really hard to hit the play/pause button on mobile devices. // This allows user to click the video area to toggle play/pause state. if (event->type() == eventNames().clickEvent - && !hasEventListeners(eventNames().clickEvent)) + && !hasEventListeners(eventNames().clickEvent)) { + m_userGestureInitiated = true; togglePlayState(); + } #endif HTMLElement::defaultEventHandler(event); #endif diff --git a/Source/WebCore/html/HTMLMediaElement.h b/Source/WebCore/html/HTMLMediaElement.h index 987cf87..2144ea1 100644 --- a/Source/WebCore/html/HTMLMediaElement.h +++ b/Source/WebCore/html/HTMLMediaElement.h @@ -420,6 +420,10 @@ private: #if PLATFORM(ANDROID) double m_lastTouch; + // When user gesture invoke load, play or pause, this turns to be true. + // After this becomes true, we ignore the user gesture requirement for play + // and pause. + bool m_userGestureInitiated; #endif }; |