Commit 10187a97 authored by weinig@apple.com's avatar weinig@apple.com
Browse files

Move ScrollView scroll wheel code to ScrollAnimator.

Reviewed by Adam Roben.

* platform/ScrollAnimator.cpp:
(WebCore::ScrollAnimator::handleWheelEvent):
* platform/ScrollAnimator.h:
Moved implementation of handleWheelEvent from ScrollView::wheelEvent.

* platform/ScrollView.cpp:
(WebCore::ScrollView::wheelEvent):
Call down to the ScrollableArea.

* platform/ScrollableArea.cpp:
(WebCore::ScrollableArea::handleWheelEvent):
Call down to the ScrollAnimator.

* platform/ScrollableArea.h:
(WebCore::ScrollableArea::scrollPosition):
(WebCore::ScrollableArea::minimumScrollPosition):
(WebCore::ScrollableArea::maximumScrollPosition):
(WebCore::ScrollableArea::visibleContentRect):
(WebCore::ScrollableArea::visibleHeight):
(WebCore::ScrollableArea::visibleWidth):
Add functions needed to implement wheel event in the animator.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@76757 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent e2501bd4
2011-01-26 Sam Weinig <sam@webkit.org>
Reviewed by Adam Roben.
Move ScrollView scroll wheel code to ScrollAnimator.
* platform/ScrollAnimator.cpp:
(WebCore::ScrollAnimator::handleWheelEvent):
* platform/ScrollAnimator.h:
Moved implementation of handleWheelEvent from ScrollView::wheelEvent.
* platform/ScrollView.cpp:
(WebCore::ScrollView::wheelEvent):
Call down to the ScrollableArea.
* platform/ScrollableArea.cpp:
(WebCore::ScrollableArea::handleWheelEvent):
Call down to the ScrollAnimator.
* platform/ScrollableArea.h:
(WebCore::ScrollableArea::scrollPosition):
(WebCore::ScrollableArea::minimumScrollPosition):
(WebCore::ScrollableArea::maximumScrollPosition):
(WebCore::ScrollableArea::visibleContentRect):
(WebCore::ScrollableArea::visibleHeight):
(WebCore::ScrollableArea::visibleWidth):
Add functions needed to implement wheel event in the animator.
2011-01-26 David Kilzer <ddkilzer@apple.com>
 
<http://webkit.org/b/53192> Add experimental support for HTTP pipelining in CFNetwork
......@@ -32,10 +32,13 @@
#include "ScrollAnimator.h"
#include "FloatPoint.h"
#include "PlatformWheelEvent.h"
#include "ScrollableArea.h"
#include <algorithm>
#include <wtf/PassOwnPtr.h>
using namespace std;
namespace WebCore {
#if !ENABLE(SMOOTH_SCROLLING)
......@@ -78,6 +81,38 @@ void ScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint& offset)
}
}
void ScrollAnimator::handleWheelEvent(PlatformWheelEvent& e)
{
Scrollbar* horizontalScrollbar = m_scrollableArea->horizontalScrollbar();
Scrollbar* verticalScrollbar = m_scrollableArea->verticalScrollbar();
// Accept the event if we have a scrollbar in that direction and can still
// scroll any further.
float deltaX = horizontalScrollbar ? e.deltaX() : 0;
float deltaY = verticalScrollbar ? e.deltaY() : 0;
IntSize maxForwardScrollDelta = m_scrollableArea->maximumScrollPosition() - m_scrollableArea->scrollPosition();
IntSize maxBackwardScrollDelta = m_scrollableArea->scrollPosition() - m_scrollableArea->minimumScrollPosition();
if ((deltaX < 0 && maxForwardScrollDelta.width() > 0)
|| (deltaX > 0 && maxBackwardScrollDelta.width() > 0)
|| (deltaY < 0 && maxForwardScrollDelta.height() > 0)
|| (deltaY > 0 && maxBackwardScrollDelta.height() > 0)) {
e.accept();
if (e.granularity() == ScrollByPageWheelEvent) {
ASSERT(!e.deltaX());
bool negative = deltaY < 0;
deltaY = max(max(static_cast<float>(m_scrollableArea->visibleHeight()) * Scrollbar::minFractionToStepWhenPaging(), static_cast<float>(m_scrollableArea->visibleHeight() - Scrollbar::maxOverlapBetweenPages())), 1.0f);
if (negative)
deltaY = -deltaY;
}
if (deltaY)
scroll(VerticalScrollbar, ScrollByPixel, verticalScrollbar->pixelStep(), -deltaY);
if (deltaX)
scroll(HorizontalScrollbar, ScrollByPixel, horizontalScrollbar->pixelStep(), -deltaX);
}
}
FloatPoint ScrollAnimator::currentPosition() const
{
return FloatPoint(m_currentPosX, m_currentPosY);
......
......@@ -37,6 +37,7 @@
namespace WebCore {
class FloatPoint;
class PlatformWheelEvent;
class ScrollableArea;
class ScrollAnimator {
......@@ -53,6 +54,8 @@ public:
virtual void scrollToOffsetWithoutAnimation(const FloatPoint&);
virtual void handleWheelEvent(PlatformWheelEvent&);
FloatPoint currentPosition() const;
protected:
......
......@@ -731,31 +731,7 @@ void ScrollView::wheelEvent(PlatformWheelEvent& e)
return;
}
// Accept the event if we have a scrollbar in that direction and can still
// scroll any further.
float deltaX = m_horizontalScrollbar ? e.deltaX() : 0;
float deltaY = m_verticalScrollbar ? e.deltaY() : 0;
IntSize maxForwardScrollDelta = maximumScrollPosition() - scrollPosition();
IntSize maxBackwardScrollDelta = scrollPosition() - minimumScrollPosition();
if ((deltaX < 0 && maxForwardScrollDelta.width() > 0)
|| (deltaX > 0 && maxBackwardScrollDelta.width() >0)
|| (deltaY < 0 && maxForwardScrollDelta.height() > 0)
|| (deltaY > 0 && maxBackwardScrollDelta.height() > 0)) {
e.accept();
if (e.granularity() == ScrollByPageWheelEvent) {
ASSERT(!e.deltaX());
bool negative = deltaY < 0;
deltaY = max(max(static_cast<float>(visibleHeight()) * Scrollbar::minFractionToStepWhenPaging(), static_cast<float>(visibleHeight() - Scrollbar::maxOverlapBetweenPages())), 1.0f);
if (negative)
deltaY = -deltaY;
}
if (deltaY)
ScrollableArea::scroll(ScrollUp, ScrollByPixel, deltaY);
if (deltaX)
ScrollableArea::scroll(ScrollLeft, ScrollByPixel, deltaX);
}
ScrollableArea::handleWheelEvent(e);
}
void ScrollView::setFrameRect(const IntRect& newRect)
......
......@@ -108,6 +108,11 @@ void ScrollableArea::scrollToYOffsetWithoutAnimation(float y)
scrollToOffsetWithoutAnimation(FloatPoint(m_scrollAnimator->currentPosition().x(), y));
}
void ScrollableArea::handleWheelEvent(PlatformWheelEvent& wheelEvent)
{
m_scrollAnimator->handleWheelEvent(wheelEvent);
}
void ScrollableArea::setScrollOffsetFromAnimation(const IntPoint& offset)
{
// Tell the derived class to scroll its contents.
......
......@@ -47,6 +47,8 @@ public:
void scrollToXOffsetWithoutAnimation(float x);
void scrollToYOffsetWithoutAnimation(float x);
void handleWheelEvent(PlatformWheelEvent&);
virtual int scrollSize(ScrollbarOrientation) const = 0;
virtual int scrollPosition(Scrollbar*) const = 0;
virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&) = 0;
......@@ -82,6 +84,14 @@ public:
virtual Scrollbar* horizontalScrollbar() const { return 0; }
virtual Scrollbar* verticalScrollbar() const { return 0; }
virtual IntPoint scrollPosition() const { ASSERT_NOT_REACHED(); return IntPoint(); }
virtual IntPoint minimumScrollPosition() const { ASSERT_NOT_REACHED(); return IntPoint(); }
virtual IntPoint maximumScrollPosition() const { ASSERT_NOT_REACHED(); return IntPoint(); }
virtual IntRect visibleContentRect(bool = false) const { ASSERT_NOT_REACHED(); return IntRect(); }
virtual int visibleHeight() const { ASSERT_NOT_REACHED(); return 0; }
virtual int visibleWidth() const { ASSERT_NOT_REACHED(); return 0; }
private:
// NOTE: Only called from the ScrollAnimator.
friend class ScrollAnimator;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment