WebCore:
authoradele@apple.com <adele@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Jul 2008 20:28:19 +0000 (20:28 +0000)
committeradele@apple.com <adele@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 Jul 2008 20:28:19 +0000 (20:28 +0000)
2008-07-29  Adele Peterson  <adele@apple.com>

        Reviewed by Sammy Weinig.

        Fix for <rdar://problem/6103024>
        When a QT movie is loaded directly in the browser, I can't pause it by single-clicking on the video

        Test: media/video-click-dlbclick-standalone.html

        * loader/MediaDocument.cpp: (WebCore::MediaDocument::defaultEventHandler): For standalone media documents,
        match the default Quicktime plugin behavior to allow clicking and double-clicking to pause and play the media.
        * loader/MediaDocument.h: Added defaultEventHandler.

        * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::defaultEventHandler): Return early if the event has been handled.
        * rendering/MediaControlElements.cpp:
        (WebCore::MediaControlMuteButtonElement::defaultEventHandler): Correct what was probably a typo.  Instead of "event->defaultHandled()",
         it is supposed to be "event->setDefaultHandled()".
        (WebCore::MediaControlPlayButtonElement::defaultEventHandler): ditto.
        (WebCore::MediaControlSeekButtonElement::defaultEventHandler): ditto.
        (WebCore::MediaControlFullscreenButtonElement::defaultEventHandler): ditto.

LayoutTests:

2008-07-29  Adele Peterson  <adele@apple.com>

        Reviewed by Sammy Weinig.

        Test for <rdar://problem/6103024>
        When a QT movie is loaded directly in the browser, I can't pause it by single-clicking on the video

        * media/video-click-dlbclick-standalone-expected.txt: Added.
        * media/video-click-dlbclick-standalone.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@35429 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/media/video-click-dlbclick-standalone-expected.txt [new file with mode: 0644]
LayoutTests/media/video-click-dlbclick-standalone.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/html/HTMLMediaElement.cpp
WebCore/loader/MediaDocument.cpp
WebCore/loader/MediaDocument.h
WebCore/rendering/MediaControlElements.cpp

index cc63844..3c5c57d 100644 (file)
@@ -1,3 +1,13 @@
+2008-07-29  Adele Peterson  <adele@apple.com>
+
+        Reviewed by Sammy Weinig.
+
+        Test for <rdar://problem/6103024>
+        When a QT movie is loaded directly in the browser, I can't pause it by single-clicking on the video
+
+        * media/video-click-dlbclick-standalone-expected.txt: Added.
+        * media/video-click-dlbclick-standalone.html: Added.
+
 2008-07-29  Dan Bernstein  <mitz@apple.com>
 
         Reviewed by Dave Hyatt.
diff --git a/LayoutTests/media/video-click-dlbclick-standalone-expected.txt b/LayoutTests/media/video-click-dlbclick-standalone-expected.txt
new file mode 100644 (file)
index 0000000..8953445
--- /dev/null
@@ -0,0 +1,6 @@
+
+This tests that clicking on a standalone video will pause and double-clicking will play.
+
+PASS: video is playing
+PASS: video is paused
+
diff --git a/LayoutTests/media/video-click-dlbclick-standalone.html b/LayoutTests/media/video-click-dlbclick-standalone.html
new file mode 100644 (file)
index 0000000..c5076f2
--- /dev/null
@@ -0,0 +1,46 @@
+<html>
+    <head>
+        <script>
+        var video;
+        function log(msg)
+        {
+            document.getElementById('console').appendChild(document.createTextNode(msg + "\n"));
+        }
+        
+        function test()
+        {
+            if (window.layoutTestController) {
+                layoutTestController.dumpAsText();
+                layoutTestController.waitUntilDone();
+            }
+            video = document.getElementById('fr').contentDocument.getElementsByTagName('video')[0];
+            video.addEventListener('canplaythrough', test2);
+        }
+        function test2()
+        {
+            var doubleClick = document.createEvent("MouseEvents");
+            doubleClick.initMouseEvent("dblclick", true, true, window, 2, 0, 0, 0, 0, false, false, false, false, 0, document);
+            var click = document.createEvent("MouseEvents");
+            click.initMouseEvent("click", true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, document);
+            video.dispatchEvent(doubleClick);
+            if (!video.paused)
+                log("PASS: video is playing");
+            else
+                log("FAIL: video should be playing");
+            video.dispatchEvent(click);
+            if (video.paused)
+                log("PASS: video is paused");
+            else
+                log("FAIL: video should be paused");
+
+            if (window.layoutTestController)
+                layoutTestController.notifyDone();
+        }
+        </script>
+    </head>
+    <body onload="test()">
+    <iframe src="content/test.mp4" id="fr"></iframe>
+    <p>This tests that clicking on a standalone video will pause and double-clicking will play.</p>
+    <pre id="console"></pre>
+    </body>
+</html>
index 978cedc..6fcf1a3 100644 (file)
@@ -1,3 +1,24 @@
+2008-07-29  Adele Peterson  <adele@apple.com>
+
+        Reviewed by Sammy Weinig.
+
+        Fix for <rdar://problem/6103024>
+        When a QT movie is loaded directly in the browser, I can't pause it by single-clicking on the video
+
+        Test: media/video-click-dlbclick-standalone.html
+
+        * loader/MediaDocument.cpp: (WebCore::MediaDocument::defaultEventHandler): For standalone media documents,
+        match the default Quicktime plugin behavior to allow clicking and double-clicking to pause and play the media.
+        * loader/MediaDocument.h: Added defaultEventHandler.
+
+        * html/HTMLMediaElement.cpp: (WebCore::HTMLMediaElement::defaultEventHandler): Return early if the event has been handled.
+        * rendering/MediaControlElements.cpp:
+        (WebCore::MediaControlMuteButtonElement::defaultEventHandler): Correct what was probably a typo.  Instead of "event->defaultHandled()",
+         it is supposed to be "event->setDefaultHandled()".
+        (WebCore::MediaControlPlayButtonElement::defaultEventHandler): ditto.
+        (WebCore::MediaControlSeekButtonElement::defaultEventHandler): ditto.
+        (WebCore::MediaControlFullscreenButtonElement::defaultEventHandler): ditto.
+
 2008-07-29  Dan Bernstein  <mitz@apple.com>
 
         Reviewed by Dave Hyatt.
index 4844554..2c4e3ab 100644 (file)
@@ -1040,6 +1040,8 @@ void HTMLMediaElement::defaultEventHandler(Event* event)
 {
     if (renderer() && renderer()->isMedia())
         static_cast<RenderMedia*>(renderer())->forwardEvent(event);
+    if (event->defaultHandled())
+        return;
     HTMLElement::defaultEventHandler(event);
 }
 
index fab5664..cd4be2f 100644 (file)
 #include "MediaDocument.h"
 
 #include "Element.h"
+#include "Event.h"
+#include "EventNames.h"
 #include "Frame.h"
 #include "FrameLoader.h"
 #include "FrameLoaderClient.h"
 #include "HTMLEmbedElement.h"
 #include "HTMLNames.h"
-#include "HTMLMediaElement.h"
 #include "HTMLVideoElement.h"
 #include "Page.h"
 #include "SegmentedString.h"
 #include "XMLTokenizer.h"
 
 namespace WebCore {
-    
+
+using namespace EventNames;
 using namespace HTMLNames;
-    
+
 class MediaTokenizer : public Tokenizer {
 public:
     MediaTokenizer(Document* doc) : m_doc(doc), m_mediaElement(0) {}
@@ -63,7 +65,7 @@ private:
     Document* m_doc;
     HTMLMediaElement* m_mediaElement;
 };
-    
+
 bool MediaTokenizer::write(const SegmentedString& s, bool appendData)
 {
     ASSERT_NOT_REACHED();
@@ -91,7 +93,7 @@ void MediaTokenizer::createDocumentStructure()
     m_mediaElement->setAttribute(nameAttr, "media");
     m_mediaElement->setSrc(m_doc->url());
     
-    body->appendChild(mediaElement, ec);    
+    body->appendChild(mediaElement, ec);
 }
     
 bool MediaTokenizer::writeRawData(const char* data, int len)
@@ -128,6 +130,28 @@ Tokenizer* MediaDocument::createTokenizer()
 {
     return new MediaTokenizer(this);
 }
-    
+
+void MediaDocument::defaultEventHandler(Event* event)
+{
+    // Match the default Quicktime plugin behavior to allow 
+    // clicking and double-clicking to pause and play the media.
+    EventTargetNode* targetNode = event->target()->toNode();
+    if (targetNode && targetNode->hasTagName(videoTag)) {
+        HTMLVideoElement* video = static_cast<HTMLVideoElement*>(targetNode);
+        ExceptionCode ec;
+        if (event->type() == clickEvent) {
+            if (!video->canPlay()) {
+                video->pause(ec);
+                event->setDefaultHandled();
+            }
+        } else if (event->type() == dblclickEvent) {
+            if (video->canPlay()) {
+                video->play(ec);
+                event->setDefaultHandled();
+            }
+        }
+    }
+}
+
 }
 #endif
index c3a3f34..e5167e4 100644 (file)
@@ -39,6 +39,8 @@ public:
         return new MediaDocument(frame);
     }
 
+    virtual void defaultEventHandler(Event*);
+
 private:
     MediaDocument(Frame*);
 
index cfaff94..efaf668 100644 (file)
@@ -106,7 +106,7 @@ void MediaControlMuteButtonElement::defaultEventHandler(Event* event)
 {
     if (event->type() == clickEvent) {
         m_mediaElement->setMuted(!m_mediaElement->muted());
-        event->defaultHandled();
+        event->setDefaultHandled();
     }
     HTMLInputElement::defaultEventHandler(event);
 }
@@ -126,7 +126,7 @@ void MediaControlPlayButtonElement::defaultEventHandler(Event* event)
             m_mediaElement->play(ec);
         else 
             m_mediaElement->pause(ec);
-        event->defaultHandled();
+        event->setDefaultHandled();
     }
     HTMLInputElement::defaultEventHandler(event);
 }
@@ -152,7 +152,7 @@ void MediaControlSeekButtonElement::defaultEventHandler(Event* event)
         ExceptionCode ec;
         m_mediaElement->pause(ec);
         m_seekTimer.startRepeating(cSeekRepeatDelay);
-        event->defaultHandled();
+        event->setDefaultHandled();
     } else if (event->type() == mouseupEvent) {
         if (m_capturing)
             if (Frame* frame = document()->frame()) {
@@ -167,7 +167,7 @@ void MediaControlSeekButtonElement::defaultEventHandler(Event* event)
             }
             m_seekTimer.stop();
             m_seeking = false;
-            event->defaultHandled();
+            event->setDefaultHandled();
         }
     }
     HTMLInputElement::defaultEventHandler(event);
@@ -235,7 +235,7 @@ MediaControlFullscreenButtonElement::MediaControlFullscreenButtonElement(Documen
 void MediaControlFullscreenButtonElement::defaultEventHandler(Event* event)
 {
     if (event->type() == clickEvent) {
-        event->defaultHandled();
+        event->setDefaultHandled();
     }
     HTMLInputElement::defaultEventHandler(event);
 }