[SCM] WebKit Debian packaging branch, webkit-1.3, updated. upstream/1.3.7-4207-g178b198
weinig at apple.com
weinig at apple.com
Mon Feb 21 00:03:54 UTC 2011
The following commit has been merged in the webkit-1.3 branch:
commit fe3ba1a8eb806f178290699976cf3030f80fca0e
Author: weinig at apple.com <weinig at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Thu Jan 27 21:23:06 2011 +0000
Add ability to do an unconstrained scroll on a ScrollView
https://bugs.webkit.org/show_bug.cgi?id=53249
Reviewed by Dave Hyatt.
* platform/ScrollView.cpp:
(WebCore::ScrollView::ScrollView):
Initialize m_constrainsScrollingToContentEdge to true.
(WebCore::ScrollView::setScrollOffset):
Only constrain the offset if the m_constrainsScrollingToContentEdge is set.
(WebCore::ScrollView::updateScrollbars):
Simplify expression converting an IntSize to an IntPoint.
(WebCore::ScrollView::paint):
Paint the overhang if there is any.
(WebCore::ScrollView::calculateOverhangAreasForPainting):
Calculate the overhang in viewport coordinates for painting.
* platform/ScrollView.h:
(WebCore::ScrollView::constrainsScrollingToContentEdge):
(WebCore::ScrollView::setConstrainsScrollingToContentEdge):
Add bit to control whether the scroll position should be constrained
to the content edge when set.
* platform/ScrollbarThemeComposite.cpp:
(WebCore::usedTotalSize):
(WebCore::ScrollbarThemeComposite::thumbPosition):
(WebCore::ScrollbarThemeComposite::thumbLength):
* platform/mac/ScrollbarThemeMac.mm:
(WebCore::ScrollbarThemeMac::paint):
Improve calculations of thumb size and position to take overhang into account.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@76831 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 660783b..370049d 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,40 @@
+2011-01-27 Sam Weinig <sam at webkit.org>
+
+ Reviewed by Dave Hyatt.
+
+ Add ability to do an unconstrained scroll on a ScrollView
+ https://bugs.webkit.org/show_bug.cgi?id=53249
+
+ * platform/ScrollView.cpp:
+ (WebCore::ScrollView::ScrollView):
+ Initialize m_constrainsScrollingToContentEdge to true.
+
+ (WebCore::ScrollView::setScrollOffset):
+ Only constrain the offset if the m_constrainsScrollingToContentEdge is set.
+
+ (WebCore::ScrollView::updateScrollbars):
+ Simplify expression converting an IntSize to an IntPoint.
+
+ (WebCore::ScrollView::paint):
+ Paint the overhang if there is any.
+
+ (WebCore::ScrollView::calculateOverhangAreasForPainting):
+ Calculate the overhang in viewport coordinates for painting.
+
+ * platform/ScrollView.h:
+ (WebCore::ScrollView::constrainsScrollingToContentEdge):
+ (WebCore::ScrollView::setConstrainsScrollingToContentEdge):
+ Add bit to control whether the scroll position should be constrained
+ to the content edge when set.
+
+ * platform/ScrollbarThemeComposite.cpp:
+ (WebCore::usedTotalSize):
+ (WebCore::ScrollbarThemeComposite::thumbPosition):
+ (WebCore::ScrollbarThemeComposite::thumbLength):
+ * platform/mac/ScrollbarThemeMac.mm:
+ (WebCore::ScrollbarThemeMac::paint):
+ Improve calculations of thumb size and position to take overhang into account.
+
2011-01-27 Dirk Schulze <krit at webkit.org>
Reviewed by Nikolas Zimmermann.
diff --git a/Source/WebCore/platform/ScrollView.cpp b/Source/WebCore/platform/ScrollView.cpp
index 814e65b..bd4ac76 100644
--- a/Source/WebCore/platform/ScrollView.cpp
+++ b/Source/WebCore/platform/ScrollView.cpp
@@ -35,8 +35,7 @@
#include "ScrollbarTheme.h"
#include <wtf/StdLibExtras.h>
-
-using std::max;
+using namespace std;
namespace WebCore {
@@ -56,6 +55,7 @@ ScrollView::ScrollView()
, m_paintsEntireContents(false)
, m_clipsRepaints(true)
, m_delegatesScrolling(false)
+ , m_constrainsScrollingToContentEdge(true)
{
platformInit();
}
@@ -322,8 +322,12 @@ int ScrollView::scrollSize(ScrollbarOrientation orientation) const
void ScrollView::setScrollOffset(const IntPoint& offset)
{
- int horizontalOffset = std::max(std::min(offset.x(), contentsWidth() - visibleWidth()), 0);
- int verticalOffset = std::max(std::min(offset.y(), contentsHeight() - visibleHeight()), 0);
+ int horizontalOffset = offset.x();
+ int verticalOffset = offset.y();
+ if (constrainsScrollingToContentEdge()) {
+ horizontalOffset = max(min(horizontalOffset, contentsWidth() - visibleWidth()), 0);
+ verticalOffset = max(min(verticalOffset, contentsHeight() - visibleHeight()), 0);
+ }
IntSize newOffset = m_scrollOffset;
newOffset.setWidth(horizontalOffset - m_scrollOrigin.x());
@@ -498,7 +502,7 @@ void ScrollView::updateScrollbars(const IntSize& desiredOffset)
m_inUpdateScrollbars = true;
- IntPoint scrollPoint = adjustScrollPositionWithinRange(IntPoint(desiredOffset.width(), desiredOffset.height()));
+ IntPoint scrollPoint = adjustScrollPositionWithinRange(IntPoint(desiredOffset));
IntSize scroll(scrollPoint.x(), scrollPoint.y());
if (m_horizontalScrollbar) {
@@ -860,6 +864,13 @@ void ScrollView::paint(GraphicsContext* context, const IntRect& rect)
context->restore();
+ IntRect horizontalOverhangRect;
+ IntRect verticalOverhangRect;
+ calculateOverhangAreasForPainting(horizontalOverhangRect, verticalOverhangRect);
+
+ if (!horizontalOverhangRect.isEmpty() || !verticalOverhangRect.isEmpty())
+ paintOverhangAreas(context, horizontalOverhangRect, verticalOverhangRect);
+
// Now paint the scrollbars.
if (!m_scrollbarsSuppressed && (m_horizontalScrollbar || m_verticalScrollbar)) {
context->save();
@@ -878,6 +889,51 @@ void ScrollView::paint(GraphicsContext* context, const IntRect& rect)
paintPanScrollIcon(context);
}
+void ScrollView::calculateOverhangAreasForPainting(IntRect& horizontalOverhangRect, IntRect& verticalOverhangRect)
+{
+ if (scrollY() < 0) {
+ horizontalOverhangRect = frameRect();
+ horizontalOverhangRect.setHeight(-scrollY());
+ } else if (scrollY() > contentsHeight() - visibleContentRect(true).height()) {
+ int height = scrollY() - (contentsHeight() - visibleContentRect(true).height());
+ horizontalOverhangRect = frameRect();
+ horizontalOverhangRect.setY(frameRect().bottom() - height);
+ horizontalOverhangRect.setHeight(height);
+ }
+
+ if (scrollX() < 0) {
+ verticalOverhangRect.setWidth(-scrollX());
+ verticalOverhangRect.setHeight(frameRect().height() - horizontalOverhangRect.height());
+ verticalOverhangRect.setX(frameRect().x());
+ if (horizontalOverhangRect.y() == frameRect().y())
+ verticalOverhangRect.setY(frameRect().y() + horizontalOverhangRect.height());
+ else
+ verticalOverhangRect.setY(frameRect().y());
+ } else if (scrollX() > contentsWidth() - visibleContentRect(true).width()) {
+ int width = scrollX() - (contentsWidth() - visibleContentRect(true).width());
+ verticalOverhangRect.setWidth(width);
+ verticalOverhangRect.setHeight(frameRect().height() - horizontalOverhangRect.height());
+ verticalOverhangRect.setX(frameRect().right() - width);
+ if (horizontalOverhangRect.y() == frameRect().y())
+ verticalOverhangRect.setY(frameRect().y() + horizontalOverhangRect.height());
+ else
+ verticalOverhangRect.setY(frameRect().y());
+ }
+}
+
+void ScrollView::paintOverhangAreas(GraphicsContext*, const IntRect&, const IntRect&)
+{
+ // FIXME: This should be checking the dirty rect.
+
+ context->setFillColor(Color::white, ColorSpaceDeviceRGB);
+ if (!horizontalOverhangRect.isEmpty())
+ context->fillRect(horizontalOverhangRect);
+
+ context->setFillColor(Color::white, ColorSpaceDeviceRGB);
+ if (!verticalOverhangRect.isEmpty())
+ context->fillRect(verticalOverhangRect);
+}
+
bool ScrollView::isPointInScrollbarCorner(const IntPoint& windowPoint)
{
if (!scrollbarCornerPresent())
diff --git a/Source/WebCore/platform/ScrollView.h b/Source/WebCore/platform/ScrollView.h
index a70624d..22872bd 100644
--- a/Source/WebCore/platform/ScrollView.h
+++ b/Source/WebCore/platform/ScrollView.h
@@ -162,7 +162,11 @@ public:
int contentsWidth() const { return contentsSize().width(); }
int contentsHeight() const { return contentsSize().height(); }
virtual void setContentsSize(const IntSize&);
-
+
+ // Functions for controlling if you can scroll past the end of the document.
+ bool constrainsScrollingToContentEdge() const { return m_constrainsScrollingToContentEdge; }
+ void setConstrainsScrollingToContentEdge(bool constrainsScrollingToContentEdge) { m_constrainsScrollingToContentEdge = constrainsScrollingToContentEdge; }
+
// Functions for querying the current scrolled position (both as a point, a size, or as individual X and Y values).
IntPoint scrollPosition() const { return visibleContentRect().location(); }
IntSize scrollOffset() const { return visibleContentRect().location() - IntPoint(); } // Gets the scrolled position as an IntSize. Convenient for adding to other sizes.
@@ -275,7 +279,7 @@ protected:
virtual void repaintContentRectangle(const IntRect&, bool now = false);
virtual void paintContents(GraphicsContext*, const IntRect& damageRect) = 0;
-
+
virtual void contentsResized() = 0;
virtual void visibleContentsResized() = 0;
@@ -335,6 +339,8 @@ private:
bool m_clipsRepaints;
bool m_delegatesScrolling;
+ bool m_constrainsScrollingToContentEdge;
+
// There are 8 possible combinations of writing mode and direction. Scroll origin will be non-zero in the x or y axis
// if there is any reversed direction or writing-mode. The combinations are:
// writing-mode / direction scrollOrigin.x() set scrollOrigin.y() set
@@ -357,6 +363,9 @@ private:
// Called when the scroll position within this view changes. FrameView overrides this to generate repaint invalidations.
virtual void repaintFixedElementsAfterScrolling() {}
+ void calculateOverhangAreasForPainting(IntRect& horizontalOverhangRect, IntRect& verticalOverhangRect);
+ void paintOverhangAreas(GraphicsContext*, const IntRect& horizontalOverhangArea, const IntRect& verticalOverhangArea);
+
void platformInit();
void platformDestroy();
void platformAddChild(Widget*);
diff --git a/Source/WebCore/platform/ScrollbarThemeComposite.cpp b/Source/WebCore/platform/ScrollbarThemeComposite.cpp
index 7bc266f..7fd08a9 100644
--- a/Source/WebCore/platform/ScrollbarThemeComposite.cpp
+++ b/Source/WebCore/platform/ScrollbarThemeComposite.cpp
@@ -37,6 +37,8 @@
#include "ScrollableArea.h"
#include "Settings.h"
+using namespace std;
+
namespace WebCore {
#if PLATFORM(WIN)
@@ -254,10 +256,20 @@ void ScrollbarThemeComposite::splitTrack(Scrollbar* scrollbar, const IntRect& un
}
}
+// Returns the size represented by track taking into account scrolling past
+// the end of the document.
+static float usedTotalSize(Scrollbar* scrollbar)
+{
+ float overhangAtStart = -scrollbar->currentPos();
+ float overhangAtEnd = scrollbar->currentPos() + scrollbar->visibleSize() - scrollbar->totalSize();
+ float overhang = max(0.0f, max(overhangAtStart, overhangAtEnd));
+ return scrollbar->totalSize() + overhang;
+}
+
int ScrollbarThemeComposite::thumbPosition(Scrollbar* scrollbar)
{
if (scrollbar->enabled())
- return scrollbar->currentPos() * (trackLength(scrollbar) - thumbLength(scrollbar)) / scrollbar->maximum();
+ return max(0.0f, scrollbar->currentPos()) * (trackLength(scrollbar) - thumbLength(scrollbar)) / (usedTotalSize(scrollbar) - scrollbar->visibleSize());
return 0;
}
@@ -266,7 +278,7 @@ int ScrollbarThemeComposite::thumbLength(Scrollbar* scrollbar)
if (!scrollbar->enabled())
return 0;
- float proportion = (float)scrollbar->visibleSize() / scrollbar->totalSize();
+ float proportion = scrollbar->visibleSize() / usedTotalSize(scrollbar);
int trackLen = trackLength(scrollbar);
int length = proportion * trackLen;
length = max(length, minimumThumbLength(scrollbar));
diff --git a/Source/WebCore/platform/mac/ScrollbarThemeMac.mm b/Source/WebCore/platform/mac/ScrollbarThemeMac.mm
index 48ef52b..e646a73 100644
--- a/Source/WebCore/platform/mac/ScrollbarThemeMac.mm
+++ b/Source/WebCore/platform/mac/ScrollbarThemeMac.mm
@@ -417,14 +417,31 @@ static int scrollbarPartToHIPressedState(ScrollbarPart part)
bool ScrollbarThemeMac::paint(Scrollbar* scrollbar, GraphicsContext* context, const IntRect& damageRect)
{
#if defined(USE_WK_SCROLLBAR_PAINTER)
+ float value = 0.0f;
+ float totalSize = 0.0f;
+
+ if (scrollbar->currentPos() < 0) {
+ // Scrolled past the top.
+ value = 0.0f;
+ totalSize = scrollbar->totalSize() - scrollbar->currentPos();
+ } else if (scrollbar->visibleSize() + scrollbar->currentPos() > scrollbar->totalSize()) {
+ // Scrolled past the bottom.
+ value = 1.0f;
+ totalSize = scrollbar->visibleSize() + scrollbar->currentPos();
+ } else {
+ // Within the bounds of the scrollable area.
+ value = scrollbar->currentPos() / scrollbar->maximum();
+ totalSize = scrollbar->totalSize();
+ }
+
context->save();
context->clip(damageRect);
context->translate(scrollbar->frameRect().x(), scrollbar->frameRect().y());
LocalCurrentGraphicsContext localContext(context);
wkScrollbarPainterPaint(scrollbarMap()->get(scrollbar).get(),
scrollbar->enabled(),
- scrollbar->currentPos() / scrollbar->maximum(),
- static_cast<CGFloat>(scrollbar->visibleSize()) / scrollbar->totalSize(),
+ value,
+ static_cast<CGFloat>(scrollbar->visibleSize()) / totalSize,
scrollbar->frameRect());
context->restore();
return true;
@@ -434,9 +451,27 @@ bool ScrollbarThemeMac::paint(Scrollbar* scrollbar, GraphicsContext* context, co
trackInfo.version = 0;
trackInfo.kind = scrollbar->controlSize() == RegularScrollbar ? kThemeMediumScrollBar : kThemeSmallScrollBar;
trackInfo.bounds = scrollbar->frameRect();
+
+ float maximum = 0.0f;
+ float position = 0.0f;
+ if (scrollbar->currentPos() < 0) {
+ // Scrolled past the top.
+ maximum = (scrollbar->totalSize() - scrollbar->currentPos()) - scrollbar->visibleSize();
+ position = 0;
+ } else if (scrollbar->visibleSize() + scrollbar->currentPos() > scrollbar->totalSize()) {
+ // Scrolled past the bottom.
+ maximum = scrollbar->currentPos();
+ position = maximum;
+ } else {
+ // Within the bounds of the scrollable area.
+ maximum = scrollbar->maximum();
+ position = scrollbar->currentPos();
+ }
+
trackInfo.min = 0;
- trackInfo.max = scrollbar->maximum();
- trackInfo.value = scrollbar->currentPos();
+ trackInfo.max = static_cast<int>(maximum);
+ trackInfo.value = static_cast<int>(position);
+
trackInfo.trackInfo.scrollbar.viewsize = scrollbar->visibleSize();
trackInfo.attributes = 0;
if (scrollbar->orientation() == HorizontalScrollbar)
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list