summaryrefslogtreecommitdiffstats
path: root/Source/WebCore/platform/Scrollbar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/WebCore/platform/Scrollbar.cpp')
-rw-r--r--Source/WebCore/platform/Scrollbar.cpp110
1 files changed, 37 insertions, 73 deletions
diff --git a/Source/WebCore/platform/Scrollbar.cpp b/Source/WebCore/platform/Scrollbar.cpp
index 7fd2651..4c625f4 100644
--- a/Source/WebCore/platform/Scrollbar.cpp
+++ b/Source/WebCore/platform/Scrollbar.cpp
@@ -26,14 +26,14 @@
#include "config.h"
#include "Scrollbar.h"
-#include "AccessibilityScrollbar.h"
#include "AXObjectCache.h"
+#include "AccessibilityScrollbar.h"
#include "EventHandler.h"
#include "Frame.h"
#include "FrameView.h"
#include "GraphicsContext.h"
#include "PlatformMouseEvent.h"
-#include "ScrollbarClient.h"
+#include "ScrollableArea.h"
#include "ScrollbarTheme.h"
#include <algorithm>
@@ -49,9 +49,9 @@ using namespace std;
namespace WebCore {
#if !PLATFORM(EFL)
-PassRefPtr<Scrollbar> Scrollbar::createNativeScrollbar(ScrollbarClient* client, ScrollbarOrientation orientation, ScrollbarControlSize size)
+PassRefPtr<Scrollbar> Scrollbar::createNativeScrollbar(ScrollableArea* scrollableArea, ScrollbarOrientation orientation, ScrollbarControlSize size)
{
- return adoptRef(new Scrollbar(client, orientation, size));
+ return adoptRef(new Scrollbar(scrollableArea, orientation, size));
}
#endif
@@ -61,9 +61,9 @@ int Scrollbar::maxOverlapBetweenPages()
return maxOverlapBetweenPages;
}
-Scrollbar::Scrollbar(ScrollbarClient* client, ScrollbarOrientation orientation, ScrollbarControlSize controlSize,
+Scrollbar::Scrollbar(ScrollableArea* scrollableArea, ScrollbarOrientation orientation, ScrollbarControlSize controlSize,
ScrollbarTheme* theme)
- : m_client(client)
+ : m_scrollableArea(scrollableArea)
, m_orientation(orientation)
, m_controlSize(controlSize)
, m_theme(theme)
@@ -104,13 +104,19 @@ Scrollbar::~Scrollbar()
m_theme->unregisterScrollbar(this);
}
-bool Scrollbar::setValue(int v, ScrollSource source)
+void Scrollbar::offsetDidChange()
{
- v = max(min(v, m_totalSize - m_visibleSize), 0);
- if (value() == v)
- return false; // Our value stayed the same.
- setCurrentPos(v, source);
- return true;
+ ASSERT(m_scrollableArea);
+
+ float position = static_cast<float>(m_scrollableArea->scrollPosition(this));
+ if (position == m_currentPos)
+ return;
+
+ int oldThumbPosition = theme()->thumbPosition(this);
+ m_currentPos = position;
+ updateThumbPosition();
+ if (m_pressedPart == ThumbPart)
+ setPressedPos(m_pressedPos + theme()->thumbPosition(this) - oldThumbPosition);
}
void Scrollbar::setProportion(int visibleSize, int totalSize)
@@ -131,31 +137,6 @@ void Scrollbar::setSteps(int lineStep, int pageStep, int pixelsPerStep)
m_pixelStep = 1.0f / pixelsPerStep;
}
-bool Scrollbar::scroll(ScrollDirection direction, ScrollGranularity granularity, float multiplier)
-{
-#if HAVE(ACCESSIBILITY)
- if (AXObjectCache::accessibilityEnabled() && axObjectCache())
- axObjectCache()->postNotification(axObjectCache()->getOrCreate(this), 0, AXObjectCache::AXValueChanged, true);
-#endif
-
- // Ignore perpendicular scrolls.
- if ((m_orientation == HorizontalScrollbar) ? (direction == ScrollUp || direction == ScrollDown) : (direction == ScrollLeft || direction == ScrollRight))
- return false;
- float step = 0;
- switch (granularity) {
- case ScrollByLine: step = m_lineStep; break;
- case ScrollByPage: step = m_pageStep; break;
- case ScrollByDocument: step = m_totalSize; break;
- case ScrollByPixel: step = m_pixelStep; break;
- }
- if (direction == ScrollUp || direction == ScrollLeft)
- multiplier = -multiplier;
- if (client())
- return client()->scroll(m_orientation, granularity, step, multiplier);
-
- return setCurrentPos(max(min(m_currentPos + (step * multiplier), static_cast<float>(m_totalSize - m_visibleSize)), 0.0f), NotFromScrollAnimator);
-}
-
void Scrollbar::updateThumb()
{
#ifdef THUMB_POSITION_AFFECTS_BUTTONS
@@ -215,7 +196,7 @@ void Scrollbar::autoscrollPressedPart(double delay)
}
// Handle the arrows and track.
- if (scroll(pressedPartScrollDirection(), pressedPartScrollGranularity()))
+ if (scrollableArea()->scroll(pressedPartScrollDirection(), pressedPartScrollGranularity()))
startTimerIfNeeded(delay);
}
@@ -284,28 +265,11 @@ void Scrollbar::moveThumb(int pos)
delta = min(maxPos - thumbPos, delta);
else if (delta < 0)
delta = max(-thumbPos, delta);
- if (delta)
- setCurrentPos(static_cast<float>(thumbPos + delta) * maximum() / (trackLen - thumbLen), NotFromScrollAnimator);
-}
-
-bool Scrollbar::setCurrentPos(float pos, ScrollSource source)
-{
- if ((source != FromScrollAnimator) && client())
- client()->setScrollPositionAndStopAnimation(m_orientation, pos);
-
- if (pos == m_currentPos)
- return false;
-
- int oldValue = value();
- int oldThumbPos = theme()->thumbPosition(this);
- m_currentPos = pos;
- updateThumbPosition();
- if (m_pressedPart == ThumbPart)
- setPressedPos(m_pressedPos + theme()->thumbPosition(this) - oldThumbPos);
-
- if (value() != oldValue && client())
- client()->valueChanged(this);
- return true;
+
+ if (delta) {
+ float newPosition = static_cast<float>(thumbPos + delta) * maximum() / (trackLen - thumbLen);
+ scrollableArea()->scrollToOffsetWithoutAnimation(m_orientation, newPosition);
+ }
}
void Scrollbar::setHoveredPart(ScrollbarPart part)
@@ -337,7 +301,7 @@ bool Scrollbar::mouseMoved(const PlatformMouseEvent& evt)
{
if (m_pressedPart == ThumbPart) {
if (theme()->shouldSnapBackToDragOrigin(this, evt))
- setCurrentPos(m_dragOrigin, NotFromScrollAnimator);
+ scrollableArea()->scrollToOffsetWithoutAnimation(m_orientation, m_dragOrigin);
else {
moveThumb(m_orientation == HorizontalScrollbar ?
convertFromContainingWindow(evt.pos()).x() :
@@ -469,7 +433,7 @@ void Scrollbar::setEnabled(bool e)
bool Scrollbar::isWindowActive() const
{
- return m_client && m_client->isActive();
+ return m_scrollableArea && m_scrollableArea->isActive();
}
AXObjectCache* Scrollbar::axObjectCache() const
@@ -485,40 +449,40 @@ void Scrollbar::invalidateRect(const IntRect& rect)
{
if (suppressInvalidation())
return;
- if (m_client)
- m_client->invalidateScrollbarRect(this, rect);
+ if (m_scrollableArea)
+ m_scrollableArea->invalidateScrollbarRect(this, rect);
}
IntRect Scrollbar::convertToContainingView(const IntRect& localRect) const
{
- if (m_client)
- return m_client->convertFromScrollbarToContainingView(this, localRect);
+ if (m_scrollableArea)
+ return m_scrollableArea->convertFromScrollbarToContainingView(this, localRect);
return Widget::convertToContainingView(localRect);
}
IntRect Scrollbar::convertFromContainingView(const IntRect& parentRect) const
{
- if (m_client)
- return m_client->convertFromContainingViewToScrollbar(this, parentRect);
+ if (m_scrollableArea)
+ return m_scrollableArea->convertFromContainingViewToScrollbar(this, parentRect);
return Widget::convertFromContainingView(parentRect);
}
IntPoint Scrollbar::convertToContainingView(const IntPoint& localPoint) const
{
- if (m_client)
- return m_client->convertFromScrollbarToContainingView(this, localPoint);
+ if (m_scrollableArea)
+ return m_scrollableArea->convertFromScrollbarToContainingView(this, localPoint);
return Widget::convertToContainingView(localPoint);
}
IntPoint Scrollbar::convertFromContainingView(const IntPoint& parentPoint) const
{
- if (m_client)
- return m_client->convertFromContainingViewToScrollbar(this, parentPoint);
+ if (m_scrollableArea)
+ return m_scrollableArea->convertFromContainingViewToScrollbar(this, parentPoint);
return Widget::convertFromContainingView(parentPoint);
}
-}
+} // namespace WebCore