Fix for <rdar://problem/8944544> Ability to animate track
authorbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Feb 2011 00:17:53 +0000 (00:17 +0000)
committerbdakin@apple.com <bdakin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Feb 2011 00:17:53 +0000 (00:17 +0000)
for WKPainter scrollers

Reviewed by Sam Weinig.

Source/WebCore:

Two new WebKitSystemInterface functions.
* WebCore.exp.in:
* platform/mac/WebCoreSystemInterface.h:
* platform/mac/WebCoreSystemInterface.mm:

Use Scrollbar::convertFromContainingView() to return the right point.
* platform/mac/ScrollAnimatorMac.mm:
(-[ScrollbarPainterControllerDelegate scrollerImpPair:convertContentPoint:toScrollerImp:]):

ScrollKnobAnimation is now ScrollbarPartAnimation. It can
now be used to animate the knob or the track.
(-[ScrollbarPartAnimation initWithScrollbarPainter:part:WebCore::scrollAnimator:WebCore::animateAlphaTo:duration:]):
(-[ScrollbarPartAnimation setCurrentProgress:]):
(-[ScrollbarPainterDelegate setUpAnimation:scrollerPainter:part:WebCore::animateAlphaTo:duration:]):
(-[ScrollbarPainterDelegate scrollerImp:animateKnobAlphaTo:duration:]):
(-[ScrollbarPainterDelegate scrollerImp:animateTrackAlphaTo:duration:]):

Scrollbars need invalodating after the overlay state changes.
(-[ScrollbarPainterDelegate scrollerImp:overlayScrollerStateChangedTo:]):

Source/WebKit/mac:

* WebCoreSupport/WebSystemInterface.mm:
(InitWebCoreSystemInterface):

Source/WebKit2:

* WebCoreSupport/WebSystemInterface.mm:
(InitWebCoreSystemInterface):

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

Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/platform/mac/ScrollAnimatorMac.mm
Source/WebCore/platform/mac/WebCoreSystemInterface.h
Source/WebCore/platform/mac/WebCoreSystemInterface.mm
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebCoreSupport/WebSystemInterface.mm
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/WebCoreSupport/mac/WebSystemInterface.mm

index c4b3e5ce9550629222b59d7c126d715563421603..d7fda9a5d68ae7b3d7c9658f8ade13cf2e3bc23e 100644 (file)
@@ -1,3 +1,30 @@
+2011-02-03  Beth Dakin  <bdakin@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        Fix for <rdar://problem/8944544> Ability to animate track
+        for WKPainter scrollers
+
+        Two new WebKitSystemInterface functions.
+        * WebCore.exp.in:
+        * platform/mac/WebCoreSystemInterface.h:
+        * platform/mac/WebCoreSystemInterface.mm:
+
+        Use Scrollbar::convertFromContainingView() to return the right point.
+        * platform/mac/ScrollAnimatorMac.mm:
+        (-[ScrollbarPainterControllerDelegate scrollerImpPair:convertContentPoint:toScrollerImp:]):
+        
+        ScrollKnobAnimation is now ScrollbarPartAnimation. It can
+        now be used to animate the knob or the track.
+        (-[ScrollbarPartAnimation initWithScrollbarPainter:part:WebCore::scrollAnimator:WebCore::animateAlphaTo:duration:]):
+        (-[ScrollbarPartAnimation setCurrentProgress:]):
+        (-[ScrollbarPainterDelegate setUpAnimation:scrollerPainter:part:WebCore::animateAlphaTo:duration:]):
+        (-[ScrollbarPainterDelegate scrollerImp:animateKnobAlphaTo:duration:]):
+        (-[ScrollbarPainterDelegate scrollerImp:animateTrackAlphaTo:duration:]):
+
+        Scrollbars need invalodating after the overlay state changes. 
+        (-[ScrollbarPainterDelegate scrollerImp:overlayScrollerStateChangedTo:]):
+
 2011-02-03  Sam Weinig  <sam@webkit.org>
 
         Reviewed by Beth Dakin.
index 0c3e31e795f40416e7cf3ee9bf2c4163b3dadb70..38e767f26bcd296b4c1a2b0e03802f99218a03c6 100644 (file)
@@ -1322,11 +1322,13 @@ _wkScrollbarPainterKnobAlpha
 _wkScrollbarPainterPaint
 _wkScrollbarPainterSetDelegate
 _wkScrollbarPainterSetOverlayState
+_wkScrollbarPainterTrackAlpha
 _wkScrollbarPainterUsesOverlayScrollers
 _wkScrollbarThickness
 _wkSetPainterForPainterController
 _wkSetScrollbarPainterControllerStyle
 _wkSetScrollbarPainterKnobAlpha
+_wkSetScrollbarPainterTrackAlpha
 _wkVerticalScrollbarPainterForController
 _wkWillEndLiveResize
 _wkWillStartLiveResize
index 0bfaea20148097a1e1fc7c951de1bdcf0aa74a95..fa42ac38fa55bf5d8466d607751d6349b2251fcf 100644 (file)
@@ -190,8 +190,22 @@ static NSSize abs(NSSize size)
 - (NSPoint)scrollerImpPair:(id)scrollerImpPair convertContentPoint:(NSPoint)pointInContentArea toScrollerImp:(id)scrollerImp
 {
     UNUSED_PARAM(scrollerImpPair);
-    UNUSED_PARAM(scrollerImp);
-    return pointInContentArea;
+
+    WebCore::Scrollbar* scrollbar = 0;
+    if (wkScrollbarPainterIsHorizontal((WKScrollbarPainterRef)scrollerImp))
+        scrollbar = _animator->scrollableArea()->horizontalScrollbar();
+    else 
+        scrollbar = _animator->scrollableArea()->verticalScrollbar();
+
+    // It is possible to have a null scrollbar here since it is possible for this delegate
+    // method to be called between the moment when a scrollbar has been set to 0 and the
+    // moment when its destructor has been called. We should probably de-couple some
+    // of the clean-up work in ScrollbarThemeMac::unregisterScrollbar() to avoid this
+    // issue.
+    if (!scrollbar)
+        return WebCore::IntPoint();
+    
+    return scrollbar->convertFromContainingView(WebCore::IntPoint(pointInContentArea));
 }
 
 - (void)scrollerImpPair:(id)scrollerImpPair setContentAreaNeedsDisplayInRect:(NSRect)rect
@@ -230,30 +244,32 @@ static NSSize abs(NSSize size)
 
 @end
 
-@interface ScrollKnobAnimation : NSAnimation
+@interface ScrollbarPartAnimation : NSAnimation
 {
     RetainPtr<WKScrollbarPainterRef> _scrollerPainter;
+    WebCore::ScrollbarPart _part;
     WebCore::ScrollAnimatorMac* _animator;
-    CGFloat _initialKnobAlpha;
-    CGFloat _newKnobAlpha;
+    CGFloat _initialAlpha;
+    CGFloat _newAlpha;
 }
 
-- (id)initWithScrollbarPainter:(WKScrollbarPainterRef)scrollerPainter forScrollAnimator:(WebCore::ScrollAnimatorMac*)scrollAnimator animateKnobAlphaTo:(CGFloat)newKnobAlpha duration:(NSTimeInterval)duration;
+- (id)initWithScrollbarPainter:(WKScrollbarPainterRef)scrollerPainter part:(WebCore::ScrollbarPart)part scrollAnimator:(WebCore::ScrollAnimatorMac*)scrollAnimator animateAlphaTo:(CGFloat)newAlpha duration:(NSTimeInterval)duration;
 
 @end
 
-@implementation ScrollKnobAnimation
+@implementation ScrollbarPartAnimation
 
-- (id)initWithScrollbarPainter:(WKScrollbarPainterRef)scrollerPainter forScrollAnimator:(WebCore::ScrollAnimatorMac*)scrollAnimator animateKnobAlphaTo:(CGFloat)newKnobAlpha duration:(NSTimeInterval)duration
+- (id)initWithScrollbarPainter:(WKScrollbarPainterRef)scrollerPainter part:(WebCore::ScrollbarPart)part scrollAnimator:(WebCore::ScrollAnimatorMac*)scrollAnimator animateAlphaTo:(CGFloat)newAlpha duration:(NSTimeInterval)duration
 {
     self = [super initWithDuration:duration animationCurve:NSAnimationEaseInOut];
     if (!self)
         return nil;
     
     _scrollerPainter = scrollerPainter;
+    _part = part;
     _animator = scrollAnimator;
-    _initialKnobAlpha = wkScrollbarPainterKnobAlpha(_scrollerPainter.get());
-    _newKnobAlpha = newKnobAlpha;
+    _initialAlpha = _part == WebCore::ThumbPart ? wkScrollbarPainterKnobAlpha(_scrollerPainter.get()) : wkScrollbarPainterTrackAlpha(_scrollerPainter.get());
+    _newAlpha = newAlpha;
     
     return self;    
 }
@@ -263,11 +279,15 @@ static NSSize abs(NSSize size)
     [super setCurrentProgress:progress];
 
     CGFloat currentAlpha;
-    if (_initialKnobAlpha > _newKnobAlpha)
+    if (_initialAlpha > _newAlpha)
         currentAlpha = 1 - progress;
     else
         currentAlpha = progress;
-    wkSetScrollbarPainterKnobAlpha(_scrollerPainter.get(), currentAlpha);
+    
+    if (_part == WebCore::ThumbPart)
+        wkSetScrollbarPainterKnobAlpha(_scrollerPainter.get(), currentAlpha);
+    else
+        wkSetScrollbarPainterTrackAlpha(_scrollerPainter.get(), currentAlpha);
 
     // Invalidate the scrollbars so that they paint the animation
     if (WebCore::Scrollbar* verticalScrollbar = _animator->scrollableArea()->verticalScrollbar())
@@ -281,8 +301,12 @@ static NSSize abs(NSSize size)
 @interface ScrollbarPainterDelegate : NSObject<NSAnimationDelegate>
 {
     WebCore::ScrollAnimatorMac* _animator;
-    RetainPtr<ScrollKnobAnimation> _verticalKnobAnimation;
-    RetainPtr<ScrollKnobAnimation> _horizontalKnobAnimation;
+
+    RetainPtr<ScrollbarPartAnimation> _verticalKnobAnimation;
+    RetainPtr<ScrollbarPartAnimation> _horizontalKnobAnimation;
+
+    RetainPtr<ScrollbarPartAnimation> _verticalTrackAnimation;
+    RetainPtr<ScrollbarPartAnimation> _horizontalTrackAnimation;
 }
 
 - (id)initWithScrollAnimator:(WebCore::ScrollAnimatorMac*)scrollAnimator;
@@ -324,20 +348,21 @@ static NSSize abs(NSSize size)
     return nil;
 }
 
-- (void)setUpAnimation:(RetainPtr<ScrollKnobAnimation>)scrollKnobAnimation scrollerPainter:(WKScrollbarPainterRef)scrollerPainter animateKnobAlphaTo:(CGFloat)newKnobAlpha duration:(NSTimeInterval)duration
+- (void)setUpAnimation:(RetainPtr<ScrollbarPartAnimation>)scrollbarPartAnimation scrollerPainter:(WKScrollbarPainterRef)scrollerPainter part:(WebCore::ScrollbarPart)part animateAlphaTo:(CGFloat)newAlpha duration:(NSTimeInterval)duration
 {
     // If we are currently animating, stop
-    if (scrollKnobAnimation) {
-        [scrollKnobAnimation.get() stopAnimation];
-        scrollKnobAnimation = nil;
+    if (scrollbarPartAnimation) {
+        [scrollbarPartAnimation.get() stopAnimation];
+        scrollbarPartAnimation = nil;
     }
     
-    scrollKnobAnimation.adoptNS([[ScrollKnobAnimation alloc] initWithScrollbarPainter:scrollerPainter 
-                                                                    forScrollAnimator:_animator 
-                                                                    animateKnobAlphaTo:newKnobAlpha 
+    scrollbarPartAnimation.adoptNS([[ScrollbarPartAnimation alloc] initWithScrollbarPainter:scrollerPainter 
+                                                                    part:part
+                                                                    scrollAnimator:_animator 
+                                                                    animateAlphaTo:newAlpha 
                                                                     duration:duration]);
-    [scrollKnobAnimation.get() setAnimationBlockingMode:NSAnimationNonblocking];
-    [scrollKnobAnimation.get() startAnimation];
+    [scrollbarPartAnimation.get() setAnimationBlockingMode:NSAnimationNonblocking];
+    [scrollbarPartAnimation.get() startAnimation];
 }
 
 - (void)scrollerImp:(id)scrollerImp animateKnobAlphaTo:(CGFloat)newKnobAlpha duration:(NSTimeInterval)duration
@@ -345,22 +370,34 @@ static NSSize abs(NSSize size)
     WKScrollbarPainterRef scrollerPainter = (WKScrollbarPainterRef)scrollerImp;
 
     if (wkScrollbarPainterIsHorizontal(scrollerPainter))
-        [self setUpAnimation:_horizontalKnobAnimation scrollerPainter:scrollerPainter animateKnobAlphaTo:newKnobAlpha duration:duration];
+        [self setUpAnimation:_horizontalKnobAnimation scrollerPainter:scrollerPainter part:WebCore::ThumbPart animateAlphaTo:newKnobAlpha duration:duration];
     else
-        [self setUpAnimation:_verticalKnobAnimation scrollerPainter:scrollerPainter animateKnobAlphaTo:newKnobAlpha duration:duration];
+        [self setUpAnimation:_verticalKnobAnimation scrollerPainter:scrollerPainter part:WebCore::ThumbPart animateAlphaTo:newKnobAlpha duration:duration];
 }
 
 - (void)scrollerImp:(id)scrollerImp animateTrackAlphaTo:(CGFloat)newTrackAlpha duration:(NSTimeInterval)duration
 {
-    // FIXME: Implement.
-    UNUSED_PARAM(scrollerImp);
-    UNUSED_PARAM(newTrackAlpha);
-    UNUSED_PARAM(duration);
+    WKScrollbarPainterRef scrollerPainter = (WKScrollbarPainterRef)scrollerImp;
+
+    if (wkScrollbarPainterIsHorizontal(scrollerPainter))
+        [self setUpAnimation:_horizontalTrackAnimation scrollerPainter:scrollerPainter part:WebCore::BackTrackPart animateAlphaTo:newTrackAlpha duration:duration];
+    else
+        [self setUpAnimation:_verticalTrackAnimation scrollerPainter:scrollerPainter part:WebCore::BackTrackPart animateAlphaTo:newTrackAlpha duration:duration];
 }
 
 - (void)scrollerImp:(id)scrollerImp overlayScrollerStateChangedTo:(NSUInteger)newOverlayScrollerState
 {
-    wkScrollbarPainterSetOverlayState((WKScrollbarPainterRef)scrollerImp, newOverlayScrollerState);
+    WKScrollbarPainterRef scrollbarPainter = (WKScrollbarPainterRef)scrollerImp;
+    wkScrollbarPainterSetOverlayState(scrollbarPainter, newOverlayScrollerState);
+
+    if (wkScrollbarPainterIsHorizontal(scrollbarPainter)) {
+        WebCore::Scrollbar* horizontalScrollbar = _animator->scrollableArea()->horizontalScrollbar();
+        _animator->scrollableArea()->invalidateScrollbarRect(horizontalScrollbar, WebCore::IntRect(0, 0, horizontalScrollbar->width(), horizontalScrollbar->height()));
+    } else {
+        WebCore::Scrollbar* verticalScrollbar = _animator->scrollableArea()->verticalScrollbar();
+        _animator->scrollableArea()->invalidateScrollbarRect(verticalScrollbar, WebCore::IntRect(0, 0, verticalScrollbar->width(), verticalScrollbar->height()));
+
+    }
 }
 
 @end
index a4bd0135cb006d137b60ddda151a933fccc5f4c1..401ca1b8f77e9d6aac95bf6ddc52dac24683cd74 100644 (file)
@@ -199,6 +199,8 @@ extern int (*wkScrollbarMinimumThumbLength)(WKScrollbarPainterRef);
 extern int (*wkScrollbarMinimumTotalLengthNeededForThumb)(WKScrollbarPainterRef);
 extern CGFloat (*wkScrollbarPainterKnobAlpha)(WKScrollbarPainterRef);
 extern void (*wkSetScrollbarPainterKnobAlpha)(WKScrollbarPainterRef, CGFloat);
+extern CGFloat (*wkScrollbarPainterTrackAlpha)(WKScrollbarPainterRef);
+extern void (*wkSetScrollbarPainterTrackAlpha)(WKScrollbarPainterRef, CGFloat);
 extern bool (*wkScrollbarPainterIsHorizontal)(WKScrollbarPainterRef);
 extern void (*wkScrollbarPainterSetOverlayState)(WKScrollbarPainterRef, int overlayScrollerState);
 
index 2c71db9f62253e2ee6c999c93625032f00bd2332..ad13f71374756482b5ceaaaddb72906e2ef029ce 100644 (file)
@@ -137,6 +137,8 @@ int (*wkScrollbarMinimumThumbLength)(WKScrollbarPainterRef);
 int (*wkScrollbarMinimumTotalLengthNeededForThumb)(WKScrollbarPainterRef);
 CGFloat (*wkScrollbarPainterKnobAlpha)(WKScrollbarPainterRef);
 void (*wkSetScrollbarPainterKnobAlpha)(WKScrollbarPainterRef, CGFloat);
+CGFloat (*wkScrollbarPainterTrackAlpha)(WKScrollbarPainterRef);
+void (*wkSetScrollbarPainterTrackAlpha)(WKScrollbarPainterRef, CGFloat);
 bool (*wkScrollbarPainterIsHorizontal)(WKScrollbarPainterRef);
 void (*wkScrollbarPainterSetOverlayState)(WKScrollbarPainterRef, int overlayScrollerState);
 
index 3065d4dea125e41fcda7b1085597de615443be6a..b8b7573c407b97599bc078189ccc9d81dc6817f4 100644 (file)
@@ -1,3 +1,13 @@
+2011-02-03  Beth Dakin  <bdakin@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        Fix for <rdar://problem/8944544> Ability to animate track
+        for WKPainter scrollers
+
+        * WebCoreSupport/WebSystemInterface.mm:
+        (InitWebCoreSystemInterface):
+
 2011-02-02  Mark Rowe  <mrowe@apple.com>
 
         Reviewed by Beth Dakin.
index 6297a608459759b39f789d473b6ed535ec386fa5..1143c7b9544157a1af14824fda0243321aae391e 100644 (file)
@@ -133,6 +133,8 @@ void InitWebCoreSystemInterface(void)
     INIT(ScrollbarMinimumTotalLengthNeededForThumb);
     INIT(ScrollbarPainterKnobAlpha);
     INIT(SetScrollbarPainterKnobAlpha);
+    INIT(ScrollbarPainterTrackAlpha);
+    INIT(SetScrollbarPainterTrackAlpha);
     INIT(ScrollbarPainterIsHorizontal);
     INIT(ScrollbarPainterSetOverlayState);
     INIT(MakeScrollbarPainterController);
index 966734745a351fe3f3e839d2614fc30f367cec3a..d0da260d3c8a546d57e154663d67a155c2101af8 100644 (file)
@@ -1,3 +1,13 @@
+2011-02-03  Beth Dakin  <bdakin@apple.com>
+
+        Reviewed by Sam Weinig.
+
+        Fix for <rdar://problem/8944544> Ability to animate track
+        for WKPainter scrollers
+
+        * WebCoreSupport/WebSystemInterface.mm:
+        (InitWebCoreSystemInterface):
+
 2011-02-03  Anders Carlsson  <andersca@apple.com>
 
         Reviewed by Dan Bernstein.
index ced83fc0be1daeaee98b57800360c7b07e9f2efb..cd5575757d353de1bb86e597f06ef97d892b5c6a 100644 (file)
@@ -106,6 +106,8 @@ void InitWebCoreSystemInterface(void)
         INIT(ScrollbarMinimumTotalLengthNeededForThumb);
         INIT(ScrollbarPainterKnobAlpha);
         INIT(SetScrollbarPainterKnobAlpha);
+        INIT(ScrollbarPainterTrackAlpha);
+        INIT(SetScrollbarPainterTrackAlpha);
         INIT(ScrollbarPainterIsHorizontal);
         INIT(ScrollbarPainterSetOverlayState);
         INIT(MakeScrollbarPainterController);