diff options
author | Ben Murdoch <benm@google.com> | 2011-05-16 16:25:10 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2011-05-23 18:54:14 +0100 |
commit | ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddb (patch) | |
tree | db769fadd053248f85db67434a5b275224defef7 /Source/WebCore/platform/ScrollView.cpp | |
parent | 52e2557aeb8477967e97fd24f20f8f407a10fa15 (diff) | |
download | external_webkit-ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddb.zip external_webkit-ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddb.tar.gz external_webkit-ab9e7a118cf1ea2e3a93dce683b2ded3e7291ddb.tar.bz2 |
Merge WebKit at r76408: Initial merge by git.
Change-Id: I5b91decbd693ccbf5c1b8354b37cd68cc9a1ea53
Diffstat (limited to 'Source/WebCore/platform/ScrollView.cpp')
-rw-r--r-- | Source/WebCore/platform/ScrollView.cpp | 80 |
1 files changed, 34 insertions, 46 deletions
diff --git a/Source/WebCore/platform/ScrollView.cpp b/Source/WebCore/platform/ScrollView.cpp index 6ea60df..b07c743 100644 --- a/Source/WebCore/platform/ScrollView.cpp +++ b/Source/WebCore/platform/ScrollView.cpp @@ -229,9 +229,15 @@ IntRect ScrollView::visibleContentRect(bool includeScrollbars) const if (paintsEntireContents()) return IntRect(IntPoint(0, 0), contentsSize()); + bool hasOverlayScrollbars = ScrollbarTheme::nativeTheme()->usesOverlayScrollbars(); + int verticalScrollbarWidth = verticalScrollbar() && !hasOverlayScrollbars && !includeScrollbars + ? verticalScrollbar()->width() : 0; + int horizontalScrollbarHeight = horizontalScrollbar() && !hasOverlayScrollbars && !includeScrollbars + ? horizontalScrollbar()->height() : 0; + return IntRect(IntPoint(m_scrollOffset.width(), m_scrollOffset.height()), - IntSize(max(0, width() - (verticalScrollbar() && !includeScrollbars ? verticalScrollbar()->width() : 0)), - max(0, height() - (horizontalScrollbar() && !includeScrollbars ? horizontalScrollbar()->height() : 0)))); + IntSize(max(0, width() - verticalScrollbarWidth), + max(0, height() - horizontalScrollbarHeight))); } #endif @@ -344,25 +350,20 @@ int ScrollView::scrollSize(ScrollbarOrientation orientation) const return scrollbar ? (scrollbar->totalSize() - scrollbar->visibleSize()) : 0; } -void ScrollView::setScrollOffsetFromAnimation(const IntPoint& offset) +void ScrollView::setScrollOffset(const IntPoint& offset) { - if (m_horizontalScrollbar) - m_horizontalScrollbar->setValue(offset.x(), Scrollbar::FromScrollAnimator); - if (m_verticalScrollbar) - m_verticalScrollbar->setValue(offset.y(), Scrollbar::FromScrollAnimator); -} + int horizontalOffset = std::max(std::min(offset.x(), contentsWidth() - visibleWidth()), 0); + int verticalOffset = std::max(std::min(offset.y(), contentsHeight() - visibleHeight()), 0); -void ScrollView::valueChanged(Scrollbar* scrollbar) -{ - // Figure out if we really moved. IntSize newOffset = m_scrollOffset; - if (scrollbar) { - if (scrollbar->orientation() == HorizontalScrollbar) - newOffset.setWidth(scrollbar->value() - m_scrollOrigin.x()); - else if (scrollbar->orientation() == VerticalScrollbar) - newOffset.setHeight(scrollbar->value() - m_scrollOrigin.y()); - } + newOffset.setWidth(horizontalOffset - m_scrollOrigin.x()); + newOffset.setHeight(verticalOffset - m_scrollOrigin.y()); + + scrollTo(newOffset); +} +void ScrollView::scrollTo(const IntSize& newOffset) +{ IntSize scrollDelta = newOffset - m_scrollOffset; if (scrollDelta == IntSize()) return; @@ -375,13 +376,13 @@ void ScrollView::valueChanged(Scrollbar* scrollbar) scrollContents(scrollDelta); } -void ScrollView::valueChanged(const IntSize& scrollDelta) +int ScrollView::scrollPosition(Scrollbar* scrollbar) const { - if (scrollbarsSuppressed()) - return; - - repaintFixedElementsAfterScrolling(); - scrollContents(scrollDelta); + if (scrollbar->orientation() == HorizontalScrollbar) + return scrollPosition().x() + m_scrollOrigin.x(); + if (scrollbar->orientation() == VerticalScrollbar) + return scrollPosition().y() + m_scrollOrigin.y(); + return 0; } void ScrollView::setScrollPosition(const IntPoint& scrollPoint) @@ -415,15 +416,8 @@ 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; + + return ScrollableArea::scroll(direction, granularity); } bool ScrollView::logicalScroll(ScrollLogicalDirection direction, ScrollGranularity granularity) @@ -554,7 +548,6 @@ void ScrollView::updateScrollbars(const IntSize& desiredOffset) m_horizontalScrollbar->setSuppressInvalidation(true); m_horizontalScrollbar->setSteps(Scrollbar::pixelsPerLineStep(), pageStep); m_horizontalScrollbar->setProportion(clientWidth, contentsWidth()); - m_horizontalScrollbar->setValue(scroll.width() + m_scrollOrigin.x(), Scrollbar::NotFromScrollAnimator); if (m_scrollbarsSuppressed) m_horizontalScrollbar->setSuppressInvalidation(false); } @@ -576,7 +569,6 @@ void ScrollView::updateScrollbars(const IntSize& desiredOffset) m_verticalScrollbar->setSuppressInvalidation(true); m_verticalScrollbar->setSteps(Scrollbar::pixelsPerLineStep(), pageStep); m_verticalScrollbar->setProportion(clientHeight, contentsHeight()); - m_verticalScrollbar->setValue(scroll.height() + m_scrollOrigin.y(), Scrollbar::NotFromScrollAnimator); if (m_scrollbarsSuppressed) m_verticalScrollbar->setSuppressInvalidation(false); } @@ -586,15 +578,7 @@ void ScrollView::updateScrollbars(const IntSize& desiredOffset) updateScrollCorner(); } - // See if our offset has changed in a situation where we might not have scrollbars. - // This can happen when editing a body with overflow:hidden and scrolling to reveal selection. - // It can also happen when maximizing a window that has scrollbars (but the new maximized result - // does not). - IntSize scrollDelta = scroll - m_scrollOffset; - if (scrollDelta != IntSize()) { - m_scrollOffset = scroll; - valueChanged(scrollDelta); - } + ScrollableArea::scrollToOffsetWithoutAnimation(FloatPoint(scroll.width() + m_scrollOrigin.x(), scroll.height() + m_scrollOrigin.y())); m_inUpdateScrollbars = false; } @@ -781,6 +765,7 @@ void ScrollView::wheelEvent(PlatformWheelEvent& e) // 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) @@ -797,9 +782,9 @@ void ScrollView::wheelEvent(PlatformWheelEvent& e) } if (deltaY) - m_verticalScrollbar->scroll(ScrollUp, ScrollByPixel, deltaY); + ScrollableArea::scroll(ScrollUp, ScrollByPixel, deltaY); if (deltaX) - m_horizontalScrollbar->scroll(ScrollLeft, ScrollByPixel, deltaX); + ScrollableArea::scroll(ScrollLeft, ScrollByPixel, deltaX); } } @@ -857,7 +842,10 @@ void ScrollView::repaintContentRectangle(const IntRect& rect, bool now) IntRect ScrollView::scrollCornerRect() const { IntRect cornerRect; - + + if (ScrollbarTheme::nativeTheme()->usesOverlayScrollbars()) + return cornerRect; + if (m_horizontalScrollbar && width() - m_horizontalScrollbar->width() > 0) { cornerRect.unite(IntRect(m_horizontalScrollbar->width(), height() - m_horizontalScrollbar->height(), |