Title: [88546] trunk/Source/WebCore
Revision
88546
Author
[email protected]
Date
2011-06-10 10:05:31 -0700 (Fri, 10 Jun 2011)

Log Message

2011-06-10  Darin Adler  <[email protected]>

        Reviewed by Eric Carlson.

        REGRESSION: Fullscreen video controller can't be dragged
        https://bugs.webkit.org/show_bug.cgi?id=62462

        No regression test because we don't have machinery for testing the fullscreen
        mode. We may find a way to add this in the future.

        * html/shadow/MediaControlElements.cpp:
        (WebCore::MediaControlPanelElement::MediaControlPanelElement): Initialize new
        booleans related to dragging.
        (WebCore::MediaControlPanelElement::startDrag): Added. Starts drag if dragging
        is allowed and a drag isn't already in progress.
        (WebCore::MediaControlPanelElement::continueDrag): Added. Moves the window if
        dragging is already in progress.
        (WebCore::MediaControlPanelElement::endDrag): Added. Ends the capture that is
        done during the dragging process.
        (WebCore::MediaControlPanelElement::setPosition): Added. Positions the panel
        using explicit top/left.
        (WebCore::MediaControlPanelElement::resetPosition): Added. Removes the positioning
        done by setPosition.
        (WebCore::MediaControlPanelElement::defaultEventHandler): Added. Calls startDrag,
        continueDrag, and endDrag in response to mouse events.
        (WebCore::MediaControlPanelElement::setCanBeDragged): Added.
        * html/shadow/MediaControlElements.h: Added new function and data members
        as mentioned above.

        * html/shadow/MediaControlRootElement.cpp:
        (WebCore::MediaControlRootElement::enteredFullscreen): Call setCanBeDragged(true)
        so you can drag the panel while in fullscreen.
        (WebCore::MediaControlRootElement::exitedFullscreen): Call setCanBeDragged(false)
        so you can't drag the panel while not in fullscreen. Also call resetPosition so
        position changes from dragging don't affect the panel in other contexts.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (88545 => 88546)


--- trunk/Source/WebCore/ChangeLog	2011-06-10 17:00:17 UTC (rev 88545)
+++ trunk/Source/WebCore/ChangeLog	2011-06-10 17:05:31 UTC (rev 88546)
@@ -2,6 +2,42 @@
 
         Reviewed by Eric Carlson.
 
+        REGRESSION: Fullscreen video controller can't be dragged
+        https://bugs.webkit.org/show_bug.cgi?id=62462
+
+        No regression test because we don't have machinery for testing the fullscreen
+        mode. We may find a way to add this in the future.
+
+        * html/shadow/MediaControlElements.cpp:
+        (WebCore::MediaControlPanelElement::MediaControlPanelElement): Initialize new
+        booleans related to dragging.
+        (WebCore::MediaControlPanelElement::startDrag): Added. Starts drag if dragging
+        is allowed and a drag isn't already in progress.
+        (WebCore::MediaControlPanelElement::continueDrag): Added. Moves the window if
+        dragging is already in progress.
+        (WebCore::MediaControlPanelElement::endDrag): Added. Ends the capture that is
+        done during the dragging process.
+        (WebCore::MediaControlPanelElement::setPosition): Added. Positions the panel
+        using explicit top/left.
+        (WebCore::MediaControlPanelElement::resetPosition): Added. Removes the positioning
+        done by setPosition.
+        (WebCore::MediaControlPanelElement::defaultEventHandler): Added. Calls startDrag,
+        continueDrag, and endDrag in response to mouse events.
+        (WebCore::MediaControlPanelElement::setCanBeDragged): Added.
+        * html/shadow/MediaControlElements.h: Added new function and data members
+        as mentioned above.
+
+        * html/shadow/MediaControlRootElement.cpp:
+        (WebCore::MediaControlRootElement::enteredFullscreen): Call setCanBeDragged(true)
+        so you can drag the panel while in fullscreen.
+        (WebCore::MediaControlRootElement::exitedFullscreen): Call setCanBeDragged(false)
+        so you can't drag the panel while not in fullscreen. Also call resetPosition so
+        position changes from dragging don't affect the panel in other contexts.
+
+2011-06-10  Darin Adler  <[email protected]>
+
+        Reviewed by Eric Carlson.
+
         REGRESSION: Full screen video HUD is positioned too low for standalone video documents
         https://bugs.webkit.org/show_bug.cgi?id=62463
 

Modified: trunk/Source/WebCore/html/shadow/MediaControlElements.cpp (88545 => 88546)


--- trunk/Source/WebCore/html/shadow/MediaControlElements.cpp	2011-06-10 17:00:17 UTC (rev 88545)
+++ trunk/Source/WebCore/html/shadow/MediaControlElements.cpp	2011-06-10 17:05:31 UTC (rev 88546)
@@ -33,6 +33,7 @@
 #include "MediaControlElements.h"
 
 #include "CSSStyleSelector.h"
+#include "CSSValueKeywords.h"
 #include "EventNames.h"
 #include "FloatConversion.h"
 #include "Frame.h"
@@ -99,6 +100,8 @@
 
 inline MediaControlPanelElement::MediaControlPanelElement(HTMLMediaElement* mediaElement)
     : MediaControlElement(mediaElement)
+    , m_canBeDragged(false)
+    , m_isBeingDragged(false)
 {
 }
 
@@ -118,6 +121,108 @@
     return id;
 }
 
+void MediaControlPanelElement::startDrag(const IntPoint& eventLocation)
+{
+    if (!m_canBeDragged)
+        return;
+
+    if (m_isBeingDragged)
+        return;
+
+    RenderObject* renderer = this->renderer();
+    if (!renderer || !renderer->isBox())
+        return;
+
+    Frame* frame = document()->frame();
+    if (!frame)
+        return;
+
+    m_dragStartPosition = toRenderBox(renderer)->location();
+    m_dragStartEventLocation = eventLocation;
+
+    frame->eventHandler()->setCapturingMouseEventsNode(this);
+
+    m_isBeingDragged = true;
+}
+
+void MediaControlPanelElement::continueDrag(const IntPoint& eventLocation)
+{
+    if (!m_isBeingDragged)
+        return;
+
+    IntSize distanceDragged = eventLocation - m_dragStartEventLocation;
+    setPosition(m_dragStartPosition + distanceDragged);
+}
+
+void MediaControlPanelElement::endDrag()
+{
+    if (!m_isBeingDragged)
+        return;
+
+    m_isBeingDragged = false;
+
+    Frame* frame = document()->frame();
+    if (!frame)
+        return;
+
+    frame->eventHandler()->setCapturingMouseEventsNode(0);
+}
+
+void MediaControlPanelElement::setPosition(const IntPoint& position)
+{
+    CSSMutableStyleDeclaration* style = getInlineStyleDecl();
+
+    double left = position.x();
+    double top = position.y();
+
+    // Set the left and top to control the panel's position; this depends on it being absolute positioned.
+    // Set the margin to zero since the position passed in will already include the effect of the margin.
+    style->setProperty(CSSPropertyLeft, left, CSSPrimitiveValue::CSS_PX);
+    style->setProperty(CSSPropertyTop, top, CSSPrimitiveValue::CSS_PX);
+    style->setProperty(CSSPropertyMarginLeft, 0.0, CSSPrimitiveValue::CSS_PX);
+    style->setProperty(CSSPropertyMarginTop, 0.0, CSSPrimitiveValue::CSS_PX);
+}
+
+void MediaControlPanelElement::resetPosition()
+{
+    CSSMutableStyleDeclaration* style = getInlineStyleDecl();
+
+    style->removeProperty(CSSPropertyLeft);
+    style->removeProperty(CSSPropertyTop);
+    style->removeProperty(CSSPropertyMarginLeft);
+    style->removeProperty(CSSPropertyMarginTop);
+}
+
+void MediaControlPanelElement::defaultEventHandler(Event* event)
+{
+    MediaControlElement::defaultEventHandler(event);
+
+    if (event->isMouseEvent()) {
+        IntPoint location = static_cast<MouseEvent*>(event)->absoluteLocation();
+        if (event->type() == eventNames().mousedownEvent) {
+            startDrag(location);
+            event->setDefaultHandled();
+        } else if (event->type() == eventNames().mousemoveEvent)
+            continueDrag(location);
+        else if (event->type() == eventNames().mouseupEvent) {
+            continueDrag(location);
+            endDrag();
+            event->setDefaultHandled();
+        }
+    }
+}
+
+void MediaControlPanelElement::setCanBeDragged(bool canBeDragged)
+{
+    if (m_canBeDragged == canBeDragged)
+        return;
+
+    m_canBeDragged = canBeDragged;
+
+    if (!canBeDragged)
+        endDrag();
+}
+
 // ----------------------------
 
 inline MediaControlTimelineContainerElement::MediaControlTimelineContainerElement(HTMLMediaElement* mediaElement)

Modified: trunk/Source/WebCore/html/shadow/MediaControlElements.h (88545 => 88546)


--- trunk/Source/WebCore/html/shadow/MediaControlElements.h	2011-06-10 17:00:17 UTC (rev 88545)
+++ trunk/Source/WebCore/html/shadow/MediaControlElements.h	2011-06-10 17:05:31 UTC (rev 88546)
@@ -99,10 +99,25 @@
 public:
     static PassRefPtr<MediaControlPanelElement> create(HTMLMediaElement*);
 
+    void setCanBeDragged(bool);
+    void resetPosition();
+
 private:
     MediaControlPanelElement(HTMLMediaElement*);
     virtual MediaControlElementType displayType() const;
     virtual const AtomicString& shadowPseudoId() const;
+    virtual void defaultEventHandler(Event*);
+
+    void startDrag(const IntPoint& eventLocation);
+    void continueDrag(const IntPoint& eventLocation);
+    void endDrag();
+
+    void setPosition(const IntPoint&);
+
+    bool m_canBeDragged;
+    bool m_isBeingDragged;
+    IntPoint m_dragStartPosition;
+    IntPoint m_dragStartEventLocation;
 };
 
 // ----------------------------

Modified: trunk/Source/WebCore/html/shadow/MediaControlRootElement.cpp (88545 => 88546)


--- trunk/Source/WebCore/html/shadow/MediaControlRootElement.cpp	2011-06-10 17:00:17 UTC (rev 88545)
+++ trunk/Source/WebCore/html/shadow/MediaControlRootElement.cpp	2011-06-10 17:05:31 UTC (rev 88546)
@@ -451,6 +451,8 @@
         m_returnToRealTimeButton->hide();
     }
 
+    m_panel->setCanBeDragged(true);
+
     startHideFullscreenControlsTimer();
 }
 
@@ -464,6 +466,13 @@
     m_seekForwardButton->show();
     m_returnToRealTimeButton->show();
 
+    m_panel->setCanBeDragged(false);
+
+    // We will keep using the panel, but we want it to go back to the standard position.
+    // This will matter right away because we use the panel even when not fullscreen.
+    // And if we reenter fullscreen we also want the panel in the standard position.
+    m_panel->resetPosition();
+
     stopHideFullscreenControlsTimer();    
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to