Reviewed by Mitz.
authorantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Nov 2007 23:30:30 +0000 (23:30 +0000)
committerantti@apple.com <antti@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 27 Nov 2007 23:30:30 +0000 (23:30 +0000)
        Small changes to make RenderSlider a bit more generic so it can be used in video controls.

        * html/HTMLInputElement.cpp:
        (WebCore::HTMLInputElement::defaultEventHandler): Fix coordinates with forwarded events.
        * rendering/RenderSlider.cpp:
        (WebCore::HTMLSliderThumbElement::defaultEventHandler): Fix coordinates with forwarded events.
        (WebCore::RenderSlider::setStyle):
        (WebCore::RenderSlider::createThumbStyle): Copy thumb left and top from the orginal style so position does not reset.
        (WebCore::RenderSlider::mouseEventIsInThumb): Make this work with forwarded events.
        * rendering/RenderSlider.h:

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

WebCore/ChangeLog
WebCore/html/HTMLInputElement.cpp
WebCore/rendering/RenderSlider.cpp
WebCore/rendering/RenderSlider.h

index 49a548a6d950aea1a1636fa30d554469cba2ef24..0d3a14c31a1a92a11d4ff7d47b2a3f13cb761a79 100644 (file)
@@ -1,3 +1,18 @@
+2007-11-27  Antti Koivisto  <antti@apple.com>
+
+        Reviewed by Mitz.
+
+        Small changes to make RenderSlider a bit more generic so it can be used in video controls.
+
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::defaultEventHandler): Fix coordinates with forwarded events.
+        * rendering/RenderSlider.cpp:
+        (WebCore::HTMLSliderThumbElement::defaultEventHandler): Fix coordinates with forwarded events.
+        (WebCore::RenderSlider::setStyle):
+        (WebCore::RenderSlider::createThumbStyle): Copy thumb left and top from the orginal style so position does not reset.
+        (WebCore::RenderSlider::mouseEventIsInThumb): Make this work with forwarded events.
+        * rendering/RenderSlider.h:
+
 2007-11-27  Antti Koivisto  <antti@apple.com>
 
         Reviewed by Darin.
index 454248ed9d990f3c79f246031bdf1598efc83c9c..bd111551762f259d35285c391505afc1fe2fc841 100644 (file)
@@ -1310,7 +1310,13 @@ void HTMLInputElement::defaultEventHandler(Event* evt)
         if (evt->isMouseEvent() && evt->type() == mousedownEvent && static_cast<MouseEvent*>(evt)->button() == LeftButton) {
             MouseEvent* mEvt = static_cast<MouseEvent*>(evt);
             if (!slider->mouseEventIsInThumb(mEvt)) {
-                slider->setValueForPosition(slider->positionForOffset(IntPoint(mEvt->offsetX(), mEvt->offsetY())));
+                IntPoint eventOffset(mEvt->offsetX(), mEvt->offsetY());
+                if (mEvt->target() != this) {
+                    IntRect rect = renderer()->absoluteBoundingBoxRect();
+                    eventOffset.setX(mEvt->pageX() - rect.x());
+                    eventOffset.setY(mEvt->pageY() - rect.y());
+                }
+                slider->setValueForPosition(slider->positionForOffset(eventOffset));
             }
         }
         if (evt->isMouseEvent() || evt->isDragEvent() || evt->isWheelEvent())
index f5b5c0cd75acb45830350e0711c2b2762f3e3a02..bf26edac5ed3e039981804468477a796f8838af0 100644 (file)
@@ -77,7 +77,7 @@ void HTMLSliderThumbElement::defaultEventHandler(Event* event)
         if (document()->frame() && renderer() && renderer()->parent()
                 && static_cast<RenderSlider*>(renderer()->parent())->mouseEventIsInThumb(mouseEvent)) {
             // Cache the initial point where the mouse down occurred.
-            m_initialClickPoint = IntPoint(mouseEvent->x(), mouseEvent->y());
+            m_initialClickPoint = IntPoint(mouseEvent->pageX(), mouseEvent->pageY());
             // Cache the initial position of the thumb.
             m_initialPosition = static_cast<RenderSlider*>(renderer()->parent())->currentPosition();
             m_inDragMode = true;
@@ -101,9 +101,9 @@ void HTMLSliderThumbElement::defaultEventHandler(Event* event)
             MouseEvent* mouseEvent = static_cast<MouseEvent*>(event);
             RenderSlider* slider = static_cast<RenderSlider*>(renderer()->parent());
             int newPosition = slider->positionForOffset(
-                IntPoint(m_initialPosition + mouseEvent->x() - m_initialClickPoint.x()
+                IntPoint(m_initialPosition + mouseEvent->pageX() - m_initialClickPoint.x()
                         + (renderer()->absoluteBoundingBoxRect().width() / 2), 
-                    m_initialPosition + mouseEvent->y() - m_initialClickPoint.y()
+                    m_initialPosition + mouseEvent->pageY() - m_initialClickPoint.y()
                         + (renderer()->absoluteBoundingBoxRect().height() / 2)));
             if (slider->currentPosition() != newPosition) {
                 slider->setCurrentPosition(newPosition);
@@ -167,14 +167,14 @@ void RenderSlider::setStyle(RenderStyle* newStyle)
     RenderBlock::setStyle(newStyle);
     
     if (m_thumb) {
-        RenderStyle* thumbStyle = createThumbStyle(newStyle);
+        RenderStyle* thumbStyle = createThumbStyle(newStyle, m_thumb->renderer()->style());
         m_thumb->renderer()->setStyle(thumbStyle);
     }
         
     setReplaced(isInline());
 }
 
-RenderStyle* RenderSlider::createThumbStyle(RenderStyle* parentStyle)
+RenderStyle* RenderSlider::createThumbStyle(RenderStyle* parentStyle, RenderStyle* oldStyle)
 {
     RenderStyle* style;
 
@@ -190,6 +190,10 @@ RenderStyle* RenderSlider::createThumbStyle(RenderStyle* parentStyle)
 
     style->setDisplay(BLOCK);
     style->setPosition(RelativePosition);
+    if (oldStyle) {
+        style->setLeft(oldStyle->left());
+        style->setTop(oldStyle->top());
+    }
 
     if (parentStyle->appearance() == SliderVerticalAppearance)
        style->setAppearance(SliderThumbVerticalAppearance);
@@ -252,13 +256,8 @@ bool RenderSlider::mouseEventIsInThumb(MouseEvent* evt)
     if (!m_thumb || !m_thumb->renderer())
         return false;
  
-    ASSERT(evt->target()->toNode() == node());
-    
     IntRect thumbBounds = m_thumb->renderer()->absoluteBoundingBoxRect();
-    thumbBounds.setX(m_thumb->renderer()->style()->left().value());
-    thumbBounds.setY(m_thumb->renderer()->style()->top().value());
-    
-    return thumbBounds.contains(evt->offsetX(), evt->offsetY());
+    return thumbBounds.contains(evt->pageX(), evt->pageY());
 }
 
 void RenderSlider::setValueForPosition(int position)
index 4c5bd16b695dac26e17b61c317ec9017c2a8406d..2da80e9b6afe4f1e9ad6e67173c92277bc12b8ae 100644 (file)
@@ -60,7 +60,7 @@ namespace WebCore {
         bool inDragMode() const;
 
     private:
-        RenderStyle* createThumbStyle(RenderStyle* parentStyle);
+        RenderStyle* createThumbStyle(RenderStyle* parentStyle, RenderStyle* oldStyle = 0);
         int trackSize();
 
         RefPtr<HTMLSliderThumbElement> m_thumb;