Reviewed by Adam Roben.
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Nov 2007 17:38:54 +0000 (17:38 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Nov 2007 17:38:54 +0000 (17:38 +0000)
        - fix <rdar://problem/5090708> Textareas render broken-looking scrollbars when too short to show full scrollbar

        * platform/win/PlatformScrollBar.h:
        * platform/win/PlatformScrollBarSafari.cpp:
        Added the "hit inset" constants (representing how far the track eats
        into the button).
        (WebCore::PlatformScrollbar::paint): Changed to paint the buttons and
        the thumb only if they should be showing.
        (WebCore::PlatformScrollbar::hasButtons): Added. Returns whether the
        arrows should be drawn.
        (WebCore::PlatformScrollbar::hasThumb): Added. Returns whether the thumb
        should be drawn.
        (WebCore::PlatformScrollbar::forwardButtonRect):
        (WebCore::PlatformScrollbar::trackRect): Changed to return the entire
        bounds of the scrollbar if the scrollbar has no buttons.
        (WebCore::PlatformScrollbar::paintTrack): Changed to paint a disabled
        track along the entire scrollbar if it has not buttons.
        (WebCore::PlatformScrollbar::hitTest): Changed to hit test only the
        parts that the scrollbar has in its current dimensions.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@27929 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/platform/win/PlatformScrollBar.h
WebCore/platform/win/PlatformScrollBarSafari.cpp

index 0c1aeba6b09fc764549e50b33307618fa77d8bae..aabad874a73f9938887d684e2a0584906f99a53d 100644 (file)
@@ -1,3 +1,27 @@
+2007-11-20  Dan Bernstein  <mitz@apple.com>
+
+        Reviewed by Adam Roben.
+
+        - fix <rdar://problem/5090708> Textareas render broken-looking scrollbars when too short to show full scrollbar
+
+        * platform/win/PlatformScrollBar.h:
+        * platform/win/PlatformScrollBarSafari.cpp:
+        Added the "hit inset" constants (representing how far the track eats
+        into the button).
+        (WebCore::PlatformScrollbar::paint): Changed to paint the buttons and
+        the thumb only if they should be showing.
+        (WebCore::PlatformScrollbar::hasButtons): Added. Returns whether the
+        arrows should be drawn.
+        (WebCore::PlatformScrollbar::hasThumb): Added. Returns whether the thumb
+        should be drawn.
+        (WebCore::PlatformScrollbar::forwardButtonRect):
+        (WebCore::PlatformScrollbar::trackRect): Changed to return the entire
+        bounds of the scrollbar if the scrollbar has no buttons.
+        (WebCore::PlatformScrollbar::paintTrack): Changed to paint a disabled
+        track along the entire scrollbar if it has not buttons.
+        (WebCore::PlatformScrollbar::hitTest): Changed to hit test only the
+        parts that the scrollbar has in its current dimensions.
+
 2007-11-20  Mark Rowe  <mrowe@apple.com>
 
         Reviewed by Alp Toker.
index b15c2bea4a3a8ed94526a28b87a8797789bc23b6..43f2f950eaa945f0d7869fd9f4fde1a7f580e2aa 100644 (file)
@@ -70,6 +70,8 @@ protected:
     virtual void updateThumbProportion();
 
 private:
+    bool hasButtons() const;
+    bool hasThumb() const;
     IntRect backButtonRect() const;
     IntRect forwardButtonRect() const;
     IntRect trackRect() const;
index c39a7d8bd34e0c42e9f4e5cea3b22272fd585196..7e1528b10b1d294e1abf9ce064a0f33e6b0e71ca 100644 (file)
@@ -54,6 +54,7 @@ static int cVerticalWidth[] = { 15, 11 };
 static int cVerticalHeight[] = { 15, 11 };
 static int cRealButtonLength[] = { 28, 21 };
 static int cButtonInset[] = { 14, 11 };
+static int cButtonHitInset[] = { 3, 2 };
 // cRealButtonLength - cButtonInset
 static int cButtonLength[] = { 14, 10 };
 static int cThumbWidth[] = { 15, 11 };
@@ -238,18 +239,28 @@ void PlatformScrollbar::paint(GraphicsContext* graphicsContext, const IntRect& d
     IntRect track = trackRect();
     paintTrack(graphicsContext, track, true, damageRect);
 
-    if (isEnabled()) {
+    if (hasButtons()) {
         paintButton(graphicsContext, backButtonRect(), true, damageRect);
         paintButton(graphicsContext, forwardButtonRect(), false, damageRect);
     }
 
-    if (damageRect.intersects(track) && isEnabled()) {
+    if (hasThumb() && damageRect.intersects(track)) {
         IntRect startTrackRect, thumbRect, endTrackRect;
         splitTrack(track, startTrackRect, thumbRect, endTrackRect);
         paintThumb(graphicsContext, thumbRect, damageRect);
     }
 }
 
+bool PlatformScrollbar::hasButtons() const
+{
+    return isEnabled() && (m_orientation == HorizontalScrollbar ? width() : height()) >= 2 * (cRealButtonLength[controlSize()] - cButtonHitInset[controlSize()]);
+}
+
+bool PlatformScrollbar::hasThumb() const
+{
+    return isEnabled() && (m_orientation == HorizontalScrollbar ? width() : height()) >= 2 * cButtonInset[controlSize()] + cThumbMinLength[controlSize()] + 1;
+}
+
 IntRect PlatformScrollbar::backButtonRect() const
 {
     // Our desired rect is essentially 17x17.
@@ -272,20 +283,19 @@ IntRect PlatformScrollbar::forwardButtonRect() const
 
     if (m_orientation == HorizontalScrollbar)
         return IntRect(x() + width() - cButtonLength[controlSize()], y(), cButtonLength[controlSize()], cHorizontalHeight[controlSize()]);
-    
     return IntRect(x(), y() + height() - cButtonLength[controlSize()], cVerticalWidth[controlSize()], cButtonLength[controlSize()]);
 }
 
 IntRect PlatformScrollbar::trackRect() const
 {
     if (m_orientation == HorizontalScrollbar) {
-        if (width() < 2 * cHorizontalWidth[controlSize()])
-            return IntRect();
+        if (!hasButtons())
+            return IntRect(x(), y(), width(), cHorizontalHeight[controlSize()]);
         return IntRect(x() + cButtonLength[controlSize()], y(), width() - 2 * cButtonLength[controlSize()], cHorizontalHeight[controlSize()]);
     }
 
-    if (height() < 2 * cVerticalHeight[controlSize()])
-        return IntRect();
+    if (!hasButtons())
+        return IntRect(x(), y(), cVerticalWidth[controlSize()], height());
     return IntRect(x(), y() + cButtonLength[controlSize()], cVerticalWidth[controlSize()], height() - 2 * cButtonLength[controlSize()]);
 }
 
@@ -370,14 +380,14 @@ void PlatformScrollbar::paintTrack(GraphicsContext* context, const IntRect& rect
     if (!paintThemePart)
         return;
 
-    IntRect paintRect = trackRepaintRect(rect, m_orientation, controlSize());
+    IntRect paintRect = hasButtons() ? trackRepaintRect(rect, m_orientation, controlSize()) : rect;
     
     if (!damageRect.intersects(paintRect))
         return;
 
     ThemePart part = m_orientation == HorizontalScrollbar ? HScrollTrackPart : VScrollTrackPart;
     ThemeControlState state = 0;
-    if (isEnabled())
+    if (hasButtons())
         state |= EnabledState;
 
     paintThemePart(part, context->platformContext(), paintRect, controlSize() == SmallScrollbar ? NSSmallControlSize : NSRegularControlSize, state);
@@ -401,30 +411,34 @@ void PlatformScrollbar::paintThumb(GraphicsContext* context, const IntRect& rect
 
 ScrollbarPart PlatformScrollbar::hitTest(const PlatformMouseEvent& evt)
 {
-    ScrollbarPart result = NoPart;
     if (!isEnabled())
-        return result;
+        return NoPart;
 
     IntPoint mousePosition = convertFromContainingWindow(evt.pos());
     mousePosition.move(x(), y());
-    if (backButtonRect().contains(mousePosition))
-        result = BackButtonPart;
-    else if (forwardButtonRect().contains(mousePosition))
-        result = ForwardButtonPart;
-    else {
-        IntRect track = trackRect();
-        if (track.contains(mousePosition)) {
-            IntRect beforeThumbRect, thumbRect, afterThumbRect;
-            splitTrack(track, beforeThumbRect, thumbRect, afterThumbRect);
-            if (beforeThumbRect.contains(mousePosition))
-                result = BackTrackPart;
-            else if (thumbRect.contains(mousePosition))
-                result = ThumbPart;
-            else
-                result = ForwardTrackPart;
-        }
+
+    if (hasButtons()) {
+        if (backButtonRect().contains(mousePosition))
+            return BackButtonPart;
+
+        if (forwardButtonRect().contains(mousePosition))
+            return ForwardButtonPart;
+    }
+
+    if (!hasThumb())
+        return NoPart;
+
+    IntRect track = trackRect();
+    if (track.contains(mousePosition)) {
+        IntRect beforeThumbRect, thumbRect, afterThumbRect;
+        splitTrack(track, beforeThumbRect, thumbRect, afterThumbRect);
+        if (beforeThumbRect.contains(mousePosition))
+            return BackTrackPart;
+        if (thumbRect.contains(mousePosition))
+            return ThumbPart;
+        return ForwardTrackPart;
     }
-    return result;
+    return NoPart;
 }
 
 bool PlatformScrollbar::handleMouseMoveEvent(const PlatformMouseEvent& evt)