2008-09-29 David Hyatt <hyatt@apple.com>
https://bugs.webkit.org/show_bug.cgi?id=21216
Make setScrollPosition and scroll() cross-platform.
Reviewed by Anders
* platform/ScrollView.cpp:
(WebCore::ScrollView::setScrollPosition):
(WebCore::ScrollView::scroll):
* platform/ScrollView.h:
* platform/gtk/ScrollViewGtk.cpp:
* platform/mac/ScrollViewMac.mm:
(WebCore::ScrollView::platformSetScrollPosition):
(WebCore::ScrollView::platformScroll):
* platform/qt/ScrollViewQt.cpp:
* platform/win/ScrollViewWin.cpp:
* platform/wx/ScrollViewWx.cpp:
(WebCore::ScrollView::platformSetScrollPosition):
(WebCore::ScrollView::platformScroll):
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@37067 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/platform/ScrollView.cpp b/WebCore/platform/ScrollView.cpp
index 7469147..6482ec3 100644
--- a/WebCore/platform/ScrollView.cpp
+++ b/WebCore/platform/ScrollView.cpp
@@ -159,6 +159,37 @@
}
}
+void ScrollView::setScrollPosition(const IntPoint& scrollPoint)
+{
+ if (platformWidget()) {
+ platformSetScrollPosition(scrollPoint);
+ return;
+ }
+
+ IntPoint newScrollPosition = scrollPoint.shrunkTo(maximumScrollPosition());
+ newScrollPosition.clampNegativeToZero();
+
+ if (newScrollPosition == scrollPosition())
+ return;
+
+ updateScrollbars(IntSize(newScrollPosition.x(), newScrollPosition.y()));
+}
+
+bool ScrollView::scroll(ScrollDirection direction, ScrollGranularity granularity)
+{
+ if (platformWidget())
+ return platformScroll(direction, granularity);
+
+ if (direction == ScrollUp || direction == ScrollDown) {
+ if (m_verticalScrollbar)
+ return m_verticalScrollbar->scroll(direction, granularity);
+ } else {
+ if (m_horizontalScrollbar)
+ return m_horizontalScrollbar->scroll(direction, granularity);
+ }
+ return false;
+}
+
IntPoint ScrollView::windowToContents(const IntPoint& windowPoint) const
{
IntPoint viewPoint = convertFromContainingWindow(windowPoint);
diff --git a/WebCore/platform/ScrollView.h b/WebCore/platform/ScrollView.h
index 19166e4..088a001 100644
--- a/WebCore/platform/ScrollView.h
+++ b/WebCore/platform/ScrollView.h
@@ -118,7 +118,10 @@
void setScrollPosition(const IntPoint&);
void scrollBy(const IntSize& s) { return setScrollPosition(scrollPosition() + s); }
void scrollRectIntoViewRecursively(const IntRect&);
-
+
+ // This method scrolls by lines, pages or pixels.
+ bool scroll(ScrollDirection, ScrollGranularity);
+
// This gives us a means of blocking painting on our scrollbars until the first layout has occurred.
void setScrollbarsSuppressed(bool suppressed, bool repaintOnUnsuppress = false);
bool scrollbarsSuppressed() const { return m_scrollbarsSuppressed; }
@@ -153,8 +156,6 @@
// (like Windows), we need this method in order to do the scroll ourselves.
void wheelEvent(PlatformWheelEvent&);
- bool scroll(ScrollDirection, ScrollGranularity);
-
IntPoint convertChildToSelf(const Widget* child, const IntPoint& point) const
{
IntPoint newPoint = point;
@@ -208,6 +209,8 @@
IntRect platformVisibleContentRect(bool includeScrollbars) const;
IntSize platformContentsSize() const;
void platformSetContentsSize();
+ void platformSetScrollPosition(const IntPoint&);
+ bool platformScroll(ScrollDirection, ScrollGranularity);
void platformSetScrollbarsSuppressed(bool repaintOnUnsuppress);
#if PLATFORM(MAC) && defined __OBJC__
diff --git a/WebCore/platform/gtk/ScrollViewGtk.cpp b/WebCore/platform/gtk/ScrollViewGtk.cpp
index 8a4104b..8f18302 100644
--- a/WebCore/platform/gtk/ScrollViewGtk.cpp
+++ b/WebCore/platform/gtk/ScrollViewGtk.cpp
@@ -572,18 +572,6 @@
}
}
-bool ScrollView::scroll(ScrollDirection direction, ScrollGranularity granularity)
-{
- if (direction == ScrollUp || direction == ScrollDown) {
- if (m_verticalScrollbar)
- return m_verticalScrollbar->scroll(direction, granularity);
- } else {
- if (m_horizontalScrollbar)
- return m_horizontalScrollbar->scroll(direction, granularity);
- }
- return false;
-}
-
void ScrollView::addToDirtyRegion(const IntRect& containingWindowRect)
{
ASSERT(isFrameView());
diff --git a/WebCore/platform/mac/ScrollViewMac.mm b/WebCore/platform/mac/ScrollViewMac.mm
index f28429b..de4f487 100644
--- a/WebCore/platform/mac/ScrollViewMac.mm
+++ b/WebCore/platform/mac/ScrollViewMac.mm
@@ -30,6 +30,7 @@
#import "FloatRect.h"
#import "IntRect.h"
#import "Logging.h"
+#import "NotImplemented.h"
#import "WebCoreFrameView.h"
using namespace std;
@@ -140,7 +141,7 @@
END_BLOCK_OBJC_EXCEPTIONS;
}
-void ScrollView::setScrollPosition(const IntPoint& scrollPoint)
+void ScrollView::platformSetScrollPosition(const IntPoint& scrollPoint)
{
BEGIN_BLOCK_OBJC_EXCEPTIONS;
NSPoint tempPoint = { max(0, scrollPoint.x()), max(0, scrollPoint.y()) }; // Don't use NSMakePoint to work around 4213314.
@@ -148,6 +149,13 @@
END_BLOCK_OBJC_EXCEPTIONS;
}
+bool ScrollView::platformScroll(ScrollDirection, ScrollGranularity)
+{
+ // FIXME: It would be nice to implement this so that all of the code in WebFrameView could go away.
+ notImplemented();
+ return true;
+}
+
void ScrollView::updateContents(const IntRect& rect, bool now)
{
BEGIN_BLOCK_OBJC_EXCEPTIONS;
diff --git a/WebCore/platform/qt/ScrollViewQt.cpp b/WebCore/platform/qt/ScrollViewQt.cpp
index 8652961..61352f3 100644
--- a/WebCore/platform/qt/ScrollViewQt.cpp
+++ b/WebCore/platform/qt/ScrollViewQt.cpp
@@ -471,18 +471,6 @@
}
}
-bool ScrollView::scroll(ScrollDirection direction, ScrollGranularity granularity)
-{
- if (direction == ScrollUp || direction == ScrollDown) {
- if (m_verticalScrollbar)
- return m_verticalScrollbar->scroll(direction, granularity);
- } else {
- if (m_horizontalScrollbar)
- return m_horizontalScrollbar->scroll(direction, granularity);
- }
- return false;
-}
-
void ScrollView::addToDirtyRegion(const IntRect& containingWindowRect)
{
ASSERT(isFrameView());
diff --git a/WebCore/platform/win/ScrollViewWin.cpp b/WebCore/platform/win/ScrollViewWin.cpp
index 3479858..33af8a1 100644
--- a/WebCore/platform/win/ScrollViewWin.cpp
+++ b/WebCore/platform/win/ScrollViewWin.cpp
@@ -232,17 +232,6 @@
::UpdateWindow(containingWindow());
}
-void ScrollView::setScrollPosition(const IntPoint& scrollPoint)
-{
- IntPoint newScrollPosition = scrollPoint.shrunkTo(maximumScrollPosition());
- newScrollPosition.clampNegativeToZero();
-
- if (newScrollPosition == scrollPosition())
- return;
-
- updateScrollbars(IntSize(newScrollPosition.x(), newScrollPosition.y()));
-}
-
void ScrollView::setFrameRect(const IntRect& newGeometry)
{
IntRect oldGeometry = frameRect();
@@ -485,18 +474,6 @@
invalidate();
}
-bool ScrollView::scroll(ScrollDirection direction, ScrollGranularity granularity)
-{
- if (direction == ScrollUp || direction == ScrollDown) {
- if (m_verticalScrollbar)
- return m_verticalScrollbar->scroll(direction, granularity);
- } else {
- if (m_horizontalScrollbar)
- return m_horizontalScrollbar->scroll(direction, granularity);
- }
- return false;
-}
-
void ScrollView::setParentVisible(bool visible)
{
if (isParentVisible() == visible)
diff --git a/WebCore/platform/wx/ScrollViewWx.cpp b/WebCore/platform/wx/ScrollViewWx.cpp
index dca7965..d789a11 100644
--- a/WebCore/platform/wx/ScrollViewWx.cpp
+++ b/WebCore/platform/wx/ScrollViewWx.cpp
@@ -179,11 +179,9 @@
return IntSize(width, height);
}
-void ScrollView::setScrollPosition(const IntPoint& scrollPoint)
+void ScrollView::platformSetScrollPosition(const IntPoint& scrollPoint)
{
wxWindow* win = platformWidget();
- if (!win)
- return;
wxPoint scrollOffset = m_data->viewStart;
wxPoint orig(scrollOffset);
@@ -218,6 +216,12 @@
adjustScrollbars();
}
+bool ScrollView::platformScroll(ScrollDirection, ScrollGranularity)
+{
+ notImplemented();
+ return true;
+}
+
void ScrollView::platformSetContentsSize()
{
wxWindow* win = platformWidget();