2008-09-26 David Hyatt <hyatt@apple.com>
https://bugs.webkit.org/show_bug.cgi?id=21168
Make contentsToWindow/windowToContents cross-platform.
Reviewed by Oliver Hunt
* platform/ScrollView.cpp:
(WebCore::ScrollView::windowToContents):
(WebCore::ScrollView::contentsToWindow):
* platform/ScrollView.h:
* platform/gtk/ScrollViewGtk.cpp:
* platform/mac/ScrollViewMac.mm:
* platform/qt/ScrollViewQt.cpp:
* platform/win/ScrollViewWin.cpp:
* platform/wx/ScrollViewWx.cpp:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@36988 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/platform/ScrollView.cpp b/WebCore/platform/ScrollView.cpp
index 185fe32..a5c01de 100644
--- a/WebCore/platform/ScrollView.cpp
+++ b/WebCore/platform/ScrollView.cpp
@@ -155,6 +155,32 @@
}
}
+IntPoint ScrollView::windowToContents(const IntPoint& windowPoint) const
+{
+ IntPoint viewPoint = convertFromContainingWindow(windowPoint);
+ return viewPoint + scrollOffset();
+}
+
+IntPoint ScrollView::contentsToWindow(const IntPoint& contentsPoint) const
+{
+ IntPoint viewPoint = contentsPoint - scrollOffset();
+ return convertToContainingWindow(viewPoint);
+}
+
+IntRect ScrollView::windowToContents(const IntRect& windowRect) const
+{
+ IntRect viewRect = convertFromContainingWindow(windowRect);
+ viewRect.move(scrollOffset());
+ return viewRect;
+}
+
+IntRect ScrollView::contentsToWindow(const IntRect& contentsRect) const
+{
+ IntRect viewRect = contentsRect;
+ viewRect.move(-scrollOffset());
+ return convertToContainingWindow(viewRect);
+}
+
#if !PLATFORM(MAC)
void ScrollView::platformSetCanBlitOnScroll()
{
diff --git a/WebCore/platform/ScrollView.h b/WebCore/platform/ScrollView.h
index 840418e..4bc341a 100644
--- a/WebCore/platform/ScrollView.h
+++ b/WebCore/platform/ScrollView.h
@@ -203,11 +203,6 @@
NSScrollView<WebCoreFrameScrollView>* scrollView() const;
#endif
-#if !PLATFORM(MAC)
-private:
- IntSize maximumScroll() const;
-#endif
-
class ScrollViewPrivate;
ScrollViewPrivate* m_data;
@@ -280,23 +275,6 @@
}; // class ScrollView
-#if !PLATFORM(MAC)
-
-// On Mac only, because of flipped NSWindow y-coordinates, we have to have a special implementation.
-// Other platforms can just implement these helper methods using the corresponding point conversion methods.
-
-inline IntRect ScrollView::contentsToWindow(const IntRect& rect) const
-{
- return IntRect(contentsToWindow(rect.location()), rect.size());
-}
-
-inline IntRect ScrollView::windowToContents(const IntRect& rect) const
-{
- return IntRect(windowToContents(rect.location()), rect.size());
-}
-
-#endif
-
} // namespace WebCore
#endif // ScrollView_h
diff --git a/WebCore/platform/gtk/ScrollViewGtk.cpp b/WebCore/platform/gtk/ScrollViewGtk.cpp
index 2f2ac4e..a845eb4 100644
--- a/WebCore/platform/gtk/ScrollViewGtk.cpp
+++ b/WebCore/platform/gtk/ScrollViewGtk.cpp
@@ -531,18 +531,6 @@
m_data->inUpdateScrollbars = false;
}
-IntPoint ScrollView::windowToContents(const IntPoint& windowPoint) const
-{
- IntPoint viewPoint = convertFromContainingWindow(windowPoint);
- return viewPoint + scrollOffset();
-}
-
-IntPoint ScrollView::contentsToWindow(const IntPoint& contentsPoint) const
-{
- IntPoint viewPoint = contentsPoint - scrollOffset();
- return convertToContainingWindow(viewPoint);
-}
-
Scrollbar* ScrollView::scrollbarUnderMouse(const PlatformMouseEvent& mouseEvent)
{
IntPoint viewPoint = convertFromContainingWindow(mouseEvent.pos());
diff --git a/WebCore/platform/mac/ScrollViewMac.mm b/WebCore/platform/mac/ScrollViewMac.mm
index 8b42998..2833508 100644
--- a/WebCore/platform/mac/ScrollViewMac.mm
+++ b/WebCore/platform/mac/ScrollViewMac.mm
@@ -198,46 +198,6 @@
// "Containing Window" means the NSWindow's coord system, which is origin lower left
-IntPoint ScrollView::contentsToWindow(const IntPoint& contentsPoint) const
-{
- BEGIN_BLOCK_OBJC_EXCEPTIONS;
- if (NSView* documentView = this->documentView()) {
- NSPoint tempPoint = { contentsPoint.x(), contentsPoint.y() }; // Don't use NSMakePoint to work around 4213314.
- return IntPoint([documentView convertPoint:tempPoint toView:nil]);
- }
- END_BLOCK_OBJC_EXCEPTIONS;
- return IntPoint();
-}
-
-IntPoint ScrollView::windowToContents(const IntPoint& point) const
-{
- BEGIN_BLOCK_OBJC_EXCEPTIONS;
- if (NSView* documentView = this->documentView()) {
- NSPoint tempPoint = { point.x(), point.y() }; // Don't use NSMakePoint to work around 4213314.
- return IntPoint([documentView convertPoint:tempPoint fromView:nil]);
- }
- END_BLOCK_OBJC_EXCEPTIONS;
- return IntPoint();
-}
-
-IntRect ScrollView::contentsToWindow(const IntRect& contentsRect) const
-{
- BEGIN_BLOCK_OBJC_EXCEPTIONS;
- if (NSView* documentView = this->documentView())
- return IntRect([documentView convertRect:contentsRect toView:nil]);
- END_BLOCK_OBJC_EXCEPTIONS;
- return IntRect();
-}
-
-IntRect ScrollView::windowToContents(const IntRect& rect) const
-{
- BEGIN_BLOCK_OBJC_EXCEPTIONS;
- if (NSView* documentView = this->documentView())
- return IntRect([documentView convertRect:rect fromView:nil]);
- END_BLOCK_OBJC_EXCEPTIONS;
- return IntRect();
-}
-
IntRect ScrollView::contentsToScreen(const IntRect& rect) const
{
BEGIN_BLOCK_OBJC_EXCEPTIONS;
diff --git a/WebCore/platform/qt/ScrollViewQt.cpp b/WebCore/platform/qt/ScrollViewQt.cpp
index a68ca46..4d98602 100644
--- a/WebCore/platform/qt/ScrollViewQt.cpp
+++ b/WebCore/platform/qt/ScrollViewQt.cpp
@@ -246,18 +246,6 @@
const_cast<ScrollView *>(this)->invalidateScrollbars();
}
-IntPoint ScrollView::windowToContents(const IntPoint& windowPoint) const
-{
- IntPoint viewPoint = convertFromContainingWindow(windowPoint);
- return viewPoint + scrollOffset();
-}
-
-IntPoint ScrollView::contentsToWindow(const IntPoint& contentsPoint) const
-{
- IntPoint viewPoint = contentsPoint - scrollOffset();
- return convertToContainingWindow(viewPoint);
-}
-
void ScrollView::suppressScrollbars(bool suppressed, bool repaintOnSuppress)
{
m_data->m_scrollbarsSuppressed = suppressed;
diff --git a/WebCore/platform/win/ScrollViewWin.cpp b/WebCore/platform/win/ScrollViewWin.cpp
index 2820ef9..581d374 100644
--- a/WebCore/platform/win/ScrollViewWin.cpp
+++ b/WebCore/platform/win/ScrollViewWin.cpp
@@ -271,18 +271,6 @@
geometryChanged();
}
-IntPoint ScrollView::windowToContents(const IntPoint& windowPoint) const
-{
- IntPoint viewPoint = convertFromContainingWindow(windowPoint);
- return viewPoint + scrollOffset();
-}
-
-IntPoint ScrollView::contentsToWindow(const IntPoint& contentsPoint) const
-{
- IntPoint viewPoint = contentsPoint - scrollOffset();
- return convertToContainingWindow(viewPoint);
-}
-
void ScrollView::suppressScrollbars(bool suppressed, bool repaintOnSuppress)
{
m_data->m_scrollbarsSuppressed = suppressed;
diff --git a/WebCore/platform/wx/ScrollViewWx.cpp b/WebCore/platform/wx/ScrollViewWx.cpp
index da13eb8..32fe718 100644
--- a/WebCore/platform/wx/ScrollViewWx.cpp
+++ b/WebCore/platform/wx/ScrollViewWx.cpp
@@ -313,16 +313,6 @@
m_data->suppressScrollbars = suppressed;
}
-IntPoint ScrollView::contentsToWindow(const IntPoint& point) const
-{
- return point - scrollOffset();
-}
-
-IntPoint ScrollView::windowToContents(const IntPoint& point) const
-{
- return point + scrollOffset();
-}
-
bool ScrollView::isOffscreen() const
{
// NB: This is called from RenderObject::willRenderImage