OSDN Git Service

Show/hide HTML5 video control properly according to the touch event
authorTeng-Hui Zhu <ztenghui@google.com>
Fri, 19 Aug 2011 00:03:04 +0000 (17:03 -0700)
committerTeng-Hui Zhu <ztenghui@google.com>
Fri, 19 Aug 2011 16:23:38 +0000 (09:23 -0700)
Due to the webkit merge, some code of handling touch and control is gone.
Now basically add this functionality back.
Refer to the original CL : c/101875

bug:5137664
Change-Id: I951c88cf8fa86061a13465f966fb291706104d8f

Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h

index a9f025f..93bd09e 100644 (file)
 #include "Widget.h"
 #endif
 
+#if PLATFORM(ANDROID)
+// For every touch, show the media control for 4 seconds.
+#define TOUCH_DELAY 4
+#endif
+
 using namespace std;
 
 namespace WebCore {
@@ -171,6 +176,9 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document* docum
     , m_dispatchingCanPlayEvent(false)
     , m_loadInitiatedByUserGesture(false)
     , m_completelyLoaded(false)
+#if PLATFORM(ANDROID)
+    , m_lastTouch(0)
+#endif
 {
     LOG(Media, "HTMLMediaElement::HTMLMediaElement");
     document->registerForDocumentActivationCallbacks(this);
@@ -1626,8 +1634,13 @@ void HTMLMediaElement::playbackProgressTimerFired(Timer<HTMLMediaElement>*)
 
     scheduleTimeupdateEvent(true);
     if (hasMediaControls()) {
-        if (!m_mouseOver && controls() && hasVideo())
+
+        if (!m_mouseOver && controls() && hasVideo()) {
+#if PLATFORM(ANDROID)
+            if (WTF::currentTime() - m_lastTouch > TOUCH_DELAY)
+#endif
             mediaControls()->makeTransparent();
+        }
         mediaControls()->playbackProgressed();
     }
     // FIXME: deal with cue ranges here
@@ -2373,8 +2386,13 @@ void HTMLMediaElement::defaultEventHandler(Event* event)
     }
 
 #if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS)
-    if (event->isTouchEvent())
+    if (event->isTouchEvent()) {
         m_mouseOver = !(event->type() == eventNames().touchendEvent || event->type() == eventNames().touchcancelEvent);
+        if (m_mouseOver && hasMediaControls() && controls() && !canPlay()) {
+            m_lastTouch = WTF::currentTime();
+            mediaControls()->makeOpaque();
+        }
+    }
 #endif
 
     HTMLElement::defaultEventHandler(event);
index 604cdf8..987cf87 100644 (file)
@@ -417,6 +417,10 @@ private:
     bool m_dispatchingCanPlayEvent : 1;
     bool m_loadInitiatedByUserGesture : 1;
     bool m_completelyLoaded : 1;
+
+#if PLATFORM(ANDROID)
+    double m_lastTouch;
+#endif
 };
 
 } //namespace