| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010, 2011 Apple Inc. All rights reserved. | 2 * Copyright (C) 2010, 2011 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 116 } |
| 117 | 117 |
| 118 - (void)invalidate { | 118 - (void)invalidate { |
| 119 _animator = 0; | 119 _animator = 0; |
| 120 } | 120 } |
| 121 | 121 |
| 122 - (NSRect)bounds { | 122 - (NSRect)bounds { |
| 123 if (!_animator) | 123 if (!_animator) |
| 124 return NSZeroRect; | 124 return NSZeroRect; |
| 125 | 125 |
| 126 blink::FloatPoint currentPosition = _animator->currentPosition(); | 126 blink::ScrollOffset currentOffset = _animator->currentOffset(); |
| 127 return NSMakeRect(currentPosition.x(), currentPosition.y(), 0, 0); | 127 return NSMakeRect(currentOffset.width(), currentOffset.height(), 0, 0); |
| 128 } | 128 } |
| 129 | 129 |
| 130 - (void)_immediateScrollToPoint:(NSPoint)newPosition { | 130 - (void)_immediateScrollToPoint:(NSPoint)newPosition { |
| 131 if (!_animator) | 131 if (!_animator) |
| 132 return; | 132 return; |
| 133 _animator->immediateScrollToPointForScrollAnimation(newPosition); | 133 _animator->immediateScrollToOffsetForScrollAnimation( |
| 134 toScrollOffset(newPosition)); |
| 134 } | 135 } |
| 135 | 136 |
| 136 - (NSPoint)_pixelAlignProposedScrollPosition:(NSPoint)newOrigin { | 137 - (NSPoint)_pixelAlignProposedScrollPosition:(NSPoint)newOrigin { |
| 137 return newOrigin; | 138 return newOrigin; |
| 138 } | 139 } |
| 139 | 140 |
| 140 - (NSSize)convertSizeToBase:(NSSize)size { | 141 - (NSSize)convertSizeToBase:(NSSize)size { |
| 141 return abs(size); | 142 return abs(size); |
| 142 } | 143 } |
| 143 | 144 |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 if (!_scrollableArea || !scrollerImp) | 217 if (!_scrollableArea || !scrollerImp) |
| 217 return NSZeroPoint; | 218 return NSZeroPoint; |
| 218 | 219 |
| 219 blink::Scrollbar* scrollbar = nil; | 220 blink::Scrollbar* scrollbar = nil; |
| 220 if ([scrollerImp isHorizontal]) | 221 if ([scrollerImp isHorizontal]) |
| 221 scrollbar = _scrollableArea->horizontalScrollbar(); | 222 scrollbar = _scrollableArea->horizontalScrollbar(); |
| 222 else | 223 else |
| 223 scrollbar = _scrollableArea->verticalScrollbar(); | 224 scrollbar = _scrollableArea->verticalScrollbar(); |
| 224 | 225 |
| 225 // It is possible to have a null scrollbar here since it is possible for this | 226 // It is possible to have a null scrollbar here since it is possible for this |
| 226 // delegate method to be called between the moment when a scrollbar has been | 227 // delegate |
| 227 // set to 0 and the moment when its destructor has been called. We should | 228 // method to be called between the moment when a scrollbar has been set to 0 |
| 228 // probably de-couple some of the clean-up work in | 229 // and the |
| 229 // ScrollbarThemeMac::unregisterScrollbar() to avoid this issue. | 230 // moment when its destructor has been called. We should probably de-couple |
| 231 // some |
| 232 // of the clean-up work in ScrollbarThemeMac::unregisterScrollbar() to avoid |
| 233 // this |
| 234 // issue. |
| 230 if (!scrollbar) | 235 if (!scrollbar) |
| 231 return NSZeroPoint; | 236 return NSZeroPoint; |
| 232 | 237 |
| 233 ASSERT(scrollerImp == scrollbarPainterForScrollbar(*scrollbar)); | 238 ASSERT(scrollerImp == scrollbarPainterForScrollbar(*scrollbar)); |
| 234 | 239 |
| 235 return scrollbar->convertFromContainingWidget( | 240 return scrollbar->convertFromContainingWidget( |
| 236 blink::IntPoint(pointInContentArea)); | 241 blink::IntPoint(pointInContentArea)); |
| 237 } | 242 } |
| 238 | 243 |
| 239 - (void)scrollerImpPair:(id)scrollerImpPair | 244 - (void)scrollerImpPair:(id)scrollerImpPair |
| 240 setContentAreaNeedsDisplayInRect:(NSRect)rect { | 245 setContentAreaNeedsDisplayInRect:(NSRect)rect { |
| 241 if (!_scrollableArea) | 246 if (!_scrollableArea) |
| 242 return; | 247 return; |
| 243 | 248 |
| 244 if (!_scrollableArea->scrollbarsCanBeActive()) | 249 if (!_scrollableArea->scrollbarsCanBeActive()) |
| 245 return; | 250 return; |
| 246 | 251 |
| 247 _scrollableArea->scrollAnimator().contentAreaWillPaint(); | 252 _scrollableArea->scrollAnimator().contentAreaWillPaint(); |
| 248 } | 253 } |
| 249 | 254 |
| 250 - (void)scrollerImpPair:(id)scrollerImpPair | 255 - (void)scrollerImpPair:(id)scrollerImpPair |
| 251 updateScrollerStyleForNewRecommendedScrollerStyle: | 256 updateScrollerStyleForNewRecommendedScrollerStyle: |
| 252 (NSScrollerStyle)newRecommendedScrollerStyle { | 257 (NSScrollerStyle)newRecommendedScrollerStyle { |
| 253 // Chrome has a single process mode which is used for testing on Mac. In that | 258 // Chrome has a single process mode which is used for testing on Mac. In that |
| 254 // mode, WebKit runs on a thread in the browser process. This notification is | 259 // mode, WebKit runs on a thread in the |
| 255 // called by the OS on the main thread in the browser process, and not on the | 260 // browser process. This notification is called by the OS on the main thread |
| 261 // in the browser process, and not on the |
| 256 // the WebKit thread. Better to not update the style than crash. | 262 // the WebKit thread. Better to not update the style than crash. |
| 257 // http://crbug.com/126514 | 263 // http://crbug.com/126514 |
| 258 if (!isMainThread()) | 264 if (!isMainThread()) |
| 259 return; | 265 return; |
| 260 | 266 |
| 261 if (!_scrollableArea) | 267 if (!_scrollableArea) |
| 262 return; | 268 return; |
| 263 | 269 |
| 264 [scrollerImpPair setScrollerStyle:newRecommendedScrollerStyle]; | 270 [scrollerImpPair setScrollerStyle:newRecommendedScrollerStyle]; |
| 265 | 271 |
| 266 static_cast<ScrollAnimatorMac&>(_scrollableArea->scrollAnimator()) | 272 static_cast<ScrollAnimatorMac&>(_scrollableArea->scrollAnimator()) |
| 267 .updateScrollerStyle(); | 273 .updateScrollerStyle(); |
| 268 } | 274 } |
| 269 | 275 |
| 270 @end | 276 @end |
| 271 | 277 |
| 272 enum FeatureToAnimate { | 278 enum FeatureToAnimate { |
| 273 ThumbAlpha, | 279 ThumbAlpha, |
| 274 TrackAlpha, | 280 TrackAlpha, |
| 275 UIStateTransition, | 281 UIStateTransition, |
| 276 ExpansionTransition | 282 ExpansionTransition |
| 277 }; | 283 }; |
| 278 | 284 |
| 279 @class BlinkScrollbarPartAnimation; | 285 @class BlinkScrollbarPartAnimation; |
| 280 | 286 |
| 281 namespace blink { | 287 namespace blink { |
| 282 | 288 |
| 283 // This class is used to drive the animation timer for | 289 // This class is used to drive the animation timer for |
| 284 // BlinkScrollbarPartAnimation objects. This is used instead of NSAnimation | 290 // BlinkScrollbarPartAnimation |
| 285 // because CoreAnimation establishes connections to the WindowServer, which | 291 // objects. This is used instead of NSAnimation because CoreAnimation |
| 286 // should not be done in a sandboxed renderer process. | 292 // establishes connections to the WindowServer, which should not be done in a |
| 293 // sandboxed renderer process. |
| 287 class BlinkScrollbarPartAnimationTimer { | 294 class BlinkScrollbarPartAnimationTimer { |
| 288 public: | 295 public: |
| 289 BlinkScrollbarPartAnimationTimer(BlinkScrollbarPartAnimation* animation, | 296 BlinkScrollbarPartAnimationTimer(BlinkScrollbarPartAnimation* animation, |
| 290 CFTimeInterval duration) | 297 CFTimeInterval duration) |
| 291 : m_timer(this, &BlinkScrollbarPartAnimationTimer::timerFired), | 298 : m_timer(this, &BlinkScrollbarPartAnimationTimer::timerFired), |
| 292 m_startTime(0.0), | 299 m_startTime(0.0), |
| 293 m_duration(duration), | 300 m_duration(duration), |
| 294 m_animation(animation), | 301 m_animation(animation), |
| 295 m_timingFunction(CubicBezierTimingFunction::preset( | 302 m_timingFunction(CubicBezierTimingFunction::preset( |
| 296 CubicBezierTimingFunction::EaseType::EASE_IN_OUT)) {} | 303 CubicBezierTimingFunction::EaseType::EASE_IN_OUT)) {} |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 _scrollbar->getScrollableArea()->lastKnownMousePosition()); | 498 _scrollbar->getScrollableArea()->lastKnownMousePosition()); |
| 492 } | 499 } |
| 493 | 500 |
| 494 - (void)setUpAlphaAnimation: | 501 - (void)setUpAlphaAnimation: |
| 495 (RetainPtr<BlinkScrollbarPartAnimation>&)scrollbarPartAnimation | 502 (RetainPtr<BlinkScrollbarPartAnimation>&)scrollbarPartAnimation |
| 496 scrollerPainter:(ScrollbarPainter)scrollerPainter | 503 scrollerPainter:(ScrollbarPainter)scrollerPainter |
| 497 part:(blink::ScrollbarPart)part | 504 part:(blink::ScrollbarPart)part |
| 498 animateAlphaTo:(CGFloat)newAlpha | 505 animateAlphaTo:(CGFloat)newAlpha |
| 499 duration:(NSTimeInterval)duration { | 506 duration:(NSTimeInterval)duration { |
| 500 // If the user has scrolled the page, then the scrollbars must be animated | 507 // If the user has scrolled the page, then the scrollbars must be animated |
| 501 // here. This overrides the early returns. | 508 // here. |
| 509 // This overrides the early returns. |
| 502 bool mustAnimate = [self scrollAnimator].haveScrolledSincePageLoad(); | 510 bool mustAnimate = [self scrollAnimator].haveScrolledSincePageLoad(); |
| 503 | 511 |
| 504 if ([self scrollAnimator].scrollbarPaintTimerIsActive() && !mustAnimate) | 512 if ([self scrollAnimator].scrollbarPaintTimerIsActive() && !mustAnimate) |
| 505 return; | 513 return; |
| 506 | 514 |
| 507 if (_scrollbar->getScrollableArea()->shouldSuspendScrollAnimations() && | 515 if (_scrollbar->getScrollableArea()->shouldSuspendScrollAnimations() && |
| 508 !mustAnimate) { | 516 !mustAnimate) { |
| 509 [self scrollAnimator].startScrollbarPaintTimer(); | 517 [self scrollAnimator].startScrollbarPaintTimer(); |
| 510 return; | 518 return; |
| 511 } | 519 } |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 - (void)scrollerImp:(id)scrollerImp | 652 - (void)scrollerImp:(id)scrollerImp |
| 645 overlayScrollerStateChangedTo:(NSUInteger)newOverlayScrollerState { | 653 overlayScrollerStateChangedTo:(NSUInteger)newOverlayScrollerState { |
| 646 // The names of these states are based on their observed behavior, and are not | 654 // The names of these states are based on their observed behavior, and are not |
| 647 // based on documentation. | 655 // based on documentation. |
| 648 enum { | 656 enum { |
| 649 NSScrollerStateInvisible = 0, | 657 NSScrollerStateInvisible = 0, |
| 650 NSScrollerStateKnob = 1, | 658 NSScrollerStateKnob = 1, |
| 651 NSScrollerStateExpanded = 2 | 659 NSScrollerStateExpanded = 2 |
| 652 }; | 660 }; |
| 653 // We do not receive notifications about the thumb un-expanding when the | 661 // We do not receive notifications about the thumb un-expanding when the |
| 654 // scrollbar fades away. Ensure that we re-paint the thumb the next time that | 662 // scrollbar fades away. Ensure |
| 655 // we transition away from being invisible, so that the thumb doesn't stick | 663 // that we re-paint the thumb the next time that we transition away from being |
| 656 // in an expanded state. | 664 // invisible, so that |
| 665 // the thumb doesn't stick in an expanded state. |
| 657 if (newOverlayScrollerState == NSScrollerStateExpanded) { | 666 if (newOverlayScrollerState == NSScrollerStateExpanded) { |
| 658 _hasExpandedSinceInvisible = YES; | 667 _hasExpandedSinceInvisible = YES; |
| 659 } else if (newOverlayScrollerState != NSScrollerStateInvisible && | 668 } else if (newOverlayScrollerState != NSScrollerStateInvisible && |
| 660 _hasExpandedSinceInvisible) { | 669 _hasExpandedSinceInvisible) { |
| 661 _scrollbar->setNeedsPaintInvalidation(ThumbPart); | 670 _scrollbar->setNeedsPaintInvalidation(ThumbPart); |
| 662 _hasExpandedSinceInvisible = NO; | 671 _hasExpandedSinceInvisible = NO; |
| 663 } | 672 } |
| 664 } | 673 } |
| 665 | 674 |
| 666 - (void)invalidate { | 675 - (void)invalidate { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 725 [m_horizontalScrollbarPainterDelegate.get() invalidate]; | 734 [m_horizontalScrollbarPainterDelegate.get() invalidate]; |
| 726 [m_verticalScrollbarPainterDelegate.get() invalidate]; | 735 [m_verticalScrollbarPainterDelegate.get() invalidate]; |
| 727 [m_scrollAnimationHelperDelegate.get() invalidate]; | 736 [m_scrollAnimationHelperDelegate.get() invalidate]; |
| 728 END_BLOCK_OBJC_EXCEPTIONS; | 737 END_BLOCK_OBJC_EXCEPTIONS; |
| 729 | 738 |
| 730 m_initialScrollbarPaintTaskFactory->cancel(); | 739 m_initialScrollbarPaintTaskFactory->cancel(); |
| 731 m_sendContentAreaScrolledTaskFactory->cancel(); | 740 m_sendContentAreaScrolledTaskFactory->cancel(); |
| 732 } | 741 } |
| 733 | 742 |
| 734 ScrollResult ScrollAnimatorMac::userScroll(ScrollGranularity granularity, | 743 ScrollResult ScrollAnimatorMac::userScroll(ScrollGranularity granularity, |
| 735 const FloatSize& delta) { | 744 const ScrollOffset& delta) { |
| 736 m_haveScrolledSincePageLoad = true; | 745 m_haveScrolledSincePageLoad = true; |
| 737 | 746 |
| 738 if (!m_scrollableArea->scrollAnimatorEnabled()) | 747 if (!m_scrollableArea->scrollAnimatorEnabled()) |
| 739 return ScrollAnimatorBase::userScroll(granularity, delta); | 748 return ScrollAnimatorBase::userScroll(granularity, delta); |
| 740 | 749 |
| 741 if (granularity == ScrollByPixel || granularity == ScrollByPrecisePixel) | 750 if (granularity == ScrollByPixel || granularity == ScrollByPrecisePixel) |
| 742 return ScrollAnimatorBase::userScroll(granularity, delta); | 751 return ScrollAnimatorBase::userScroll(granularity, delta); |
| 743 | 752 |
| 744 FloatSize consumedDelta = computeDeltaToConsume(delta); | 753 ScrollOffset consumedDelta = computeDeltaToConsume(delta); |
| 745 FloatPoint newPos = m_currentPos + consumedDelta; | 754 ScrollOffset newOffset = m_currentOffset + consumedDelta; |
| 746 if (m_currentPos == newPos) | 755 if (m_currentOffset == newOffset) |
| 747 return ScrollResult(); | 756 return ScrollResult(); |
| 748 | 757 |
| 749 // Prevent clobbering an existing animation on an unscrolled axis. | 758 // Prevent clobbering an existing animation on an unscrolled axis. |
| 750 if ([m_scrollAnimationHelper.get() _isAnimating]) { | 759 if ([m_scrollAnimationHelper.get() _isAnimating]) { |
| 751 NSPoint targetOrigin = [m_scrollAnimationHelper.get() targetOrigin]; | 760 NSPoint targetOrigin = [m_scrollAnimationHelper.get() targetOrigin]; |
| 752 if (!delta.width()) | 761 if (!delta.width()) |
| 753 newPos.setX(targetOrigin.x); | 762 newOffset.setWidth(targetOrigin.x); |
| 754 if (!delta.height()) | 763 if (!delta.height()) |
| 755 newPos.setY(targetOrigin.y); | 764 newOffset.setHeight(targetOrigin.y); |
| 756 } | 765 } |
| 757 | 766 |
| 758 NSPoint newPoint = NSMakePoint(newPos.x(), newPos.y()); | 767 NSPoint newPoint = NSMakePoint(newOffset.width(), newOffset.height()); |
| 759 [m_scrollAnimationHelper.get() scrollToPoint:newPoint]; | 768 [m_scrollAnimationHelper.get() scrollToPoint:newPoint]; |
| 760 | 769 |
| 761 // TODO(bokan): This has different semantics on ScrollResult than | 770 // TODO(bokan): This has different semantics on ScrollResult than |
| 762 // ScrollAnimator, which only returns unused delta if there's no animation | 771 // ScrollAnimator, |
| 763 // and we don't start one. | 772 // which only returns unused delta if there's no animation and we don't start |
| 773 // one. |
| 764 return ScrollResult(consumedDelta.width(), consumedDelta.height(), | 774 return ScrollResult(consumedDelta.width(), consumedDelta.height(), |
| 765 delta.width() - consumedDelta.width(), | 775 delta.width() - consumedDelta.width(), |
| 766 delta.height() - consumedDelta.height()); | 776 delta.height() - consumedDelta.height()); |
| 767 } | 777 } |
| 768 | 778 |
| 769 void ScrollAnimatorMac::scrollToOffsetWithoutAnimation( | 779 void ScrollAnimatorMac::scrollToOffsetWithoutAnimation( |
| 770 const FloatPoint& offset) { | 780 const ScrollOffset& offset) { |
| 771 [m_scrollAnimationHelper.get() _stopRun]; | 781 [m_scrollAnimationHelper.get() _stopRun]; |
| 772 immediateScrollTo(offset); | 782 immediateScrollTo(offset); |
| 773 } | 783 } |
| 774 | 784 |
| 775 FloatPoint ScrollAnimatorMac::adjustScrollPositionIfNecessary( | 785 ScrollOffset ScrollAnimatorMac::adjustScrollOffsetIfNecessary( |
| 776 const FloatPoint& position) const { | 786 const ScrollOffset& offset) const { |
| 777 IntPoint minPos = m_scrollableArea->minimumScrollPosition(); | 787 ScrollOffset minOffset = m_scrollableArea->minimumScrollOffset(); |
| 778 IntPoint maxPos = m_scrollableArea->maximumScrollPosition(); | 788 ScrollOffset maxOffset = m_scrollableArea->maximumScrollOffset(); |
| 779 | 789 |
| 780 float newX = clampTo<float, float>(position.x(), minPos.x(), maxPos.x()); | 790 float newX = clampTo<float, float>(offset.width(), minOffset.width(), |
| 781 float newY = clampTo<float, float>(position.y(), minPos.y(), maxPos.y()); | 791 maxOffset.width()); |
| 792 float newY = clampTo<float, float>(offset.height(), minOffset.height(), |
| 793 maxOffset.height()); |
| 782 | 794 |
| 783 return FloatPoint(newX, newY); | 795 return ScrollOffset(newX, newY); |
| 784 } | 796 } |
| 785 | 797 |
| 786 void ScrollAnimatorMac::immediateScrollTo(const FloatPoint& newPosition) { | 798 void ScrollAnimatorMac::immediateScrollTo(const ScrollOffset& newOffset) { |
| 787 FloatPoint adjustedPosition = adjustScrollPositionIfNecessary(newPosition); | 799 ScrollOffset adjustedOffset = adjustScrollOffsetIfNecessary(newOffset); |
| 788 | 800 |
| 789 bool positionChanged = adjustedPosition != m_currentPos; | 801 bool offsetChanged = adjustedOffset != m_currentOffset; |
| 790 if (!positionChanged && !getScrollableArea()->scrollOriginChanged()) | 802 if (!offsetChanged && !getScrollableArea()->scrollOriginChanged()) |
| 791 return; | 803 return; |
| 792 | 804 |
| 793 FloatSize delta = adjustedPosition - m_currentPos; | 805 ScrollOffset delta = adjustedOffset - m_currentOffset; |
| 794 | 806 |
| 795 m_currentPos = adjustedPosition; | 807 m_currentOffset = adjustedOffset; |
| 796 notifyContentAreaScrolled(delta); | 808 notifyContentAreaScrolled(delta); |
| 797 notifyPositionChanged(); | 809 notifyOffsetChanged(); |
| 798 } | 810 } |
| 799 | 811 |
| 800 void ScrollAnimatorMac::immediateScrollToPointForScrollAnimation( | 812 void ScrollAnimatorMac::immediateScrollToOffsetForScrollAnimation( |
| 801 const FloatPoint& newPosition) { | 813 const ScrollOffset& newOffset) { |
| 802 ASSERT(m_scrollAnimationHelper); | 814 ASSERT(m_scrollAnimationHelper); |
| 803 immediateScrollTo(newPosition); | 815 immediateScrollTo(newOffset); |
| 804 } | 816 } |
| 805 | 817 |
| 806 void ScrollAnimatorMac::contentAreaWillPaint() const { | 818 void ScrollAnimatorMac::contentAreaWillPaint() const { |
| 807 if (!getScrollableArea()->scrollbarsCanBeActive()) | 819 if (!getScrollableArea()->scrollbarsCanBeActive()) |
| 808 return; | 820 return; |
| 809 [m_scrollbarPainterController.get() contentAreaWillDraw]; | 821 [m_scrollbarPainterController.get() contentAreaWillDraw]; |
| 810 } | 822 } |
| 811 | 823 |
| 812 void ScrollAnimatorMac::mouseEnteredContentArea() const { | 824 void ScrollAnimatorMac::mouseEnteredContentArea() const { |
| 813 if (!getScrollableArea()->scrollbarsCanBeActive()) | 825 if (!getScrollableArea()->scrollbarsCanBeActive()) |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 947 return true; | 959 return true; |
| 948 | 960 |
| 949 // Overlay scrollbars should participate in hit testing whenever they are at | 961 // Overlay scrollbars should participate in hit testing whenever they are at |
| 950 // all visible. | 962 // all visible. |
| 951 ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar); | 963 ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar); |
| 952 if (!painter) | 964 if (!painter) |
| 953 return false; | 965 return false; |
| 954 return [painter knobAlpha] > 0; | 966 return [painter knobAlpha] > 0; |
| 955 } | 967 } |
| 956 | 968 |
| 957 void ScrollAnimatorMac::notifyContentAreaScrolled(const FloatSize& delta) { | 969 void ScrollAnimatorMac::notifyContentAreaScrolled(const ScrollOffset& delta) { |
| 958 // This function is called when a page is going into the page cache, but the | 970 // This function is called when a page is going into the page cache, but the |
| 959 // page isn't really scrolling in that case. We should only pass the message | 971 // page |
| 960 // on to the ScrollbarPainterController when we're really scrolling on an | 972 // isn't really scrolling in that case. We should only pass the message on to |
| 961 // active page. | 973 // the |
| 974 // ScrollbarPainterController when we're really scrolling on an active page. |
| 962 if (getScrollableArea()->scrollbarsCanBeActive()) | 975 if (getScrollableArea()->scrollbarsCanBeActive()) |
| 963 sendContentAreaScrolledSoon(delta); | 976 sendContentAreaScrolledSoon(delta); |
| 964 } | 977 } |
| 965 | 978 |
| 966 bool ScrollAnimatorMac::setScrollbarsVisibleForTesting(bool show) { | 979 bool ScrollAnimatorMac::setScrollbarsVisibleForTesting(bool show) { |
| 967 if (show) | 980 if (show) |
| 968 [m_scrollbarPainterController.get() flashScrollers]; | 981 [m_scrollbarPainterController.get() flashScrollers]; |
| 969 else | 982 else |
| 970 [m_scrollbarPainterController.get() hideOverlayScrollers]; | 983 [m_scrollbarPainterController.get() hideOverlayScrollers]; |
| 971 | 984 |
| 972 [m_verticalScrollbarPainterDelegate.get() updateVisibilityImmediately:show]; | 985 [m_verticalScrollbarPainterDelegate.get() updateVisibilityImmediately:show]; |
| 973 [m_verticalScrollbarPainterDelegate.get() updateVisibilityImmediately:show]; | 986 [m_verticalScrollbarPainterDelegate.get() updateVisibilityImmediately:show]; |
| 974 return true; | 987 return true; |
| 975 } | 988 } |
| 976 | 989 |
| 977 void ScrollAnimatorMac::cancelAnimation() { | 990 void ScrollAnimatorMac::cancelAnimation() { |
| 978 [m_scrollAnimationHelper.get() _stopRun]; | 991 [m_scrollAnimationHelper.get() _stopRun]; |
| 979 m_haveScrolledSincePageLoad = false; | 992 m_haveScrolledSincePageLoad = false; |
| 980 } | 993 } |
| 981 | 994 |
| 982 void ScrollAnimatorMac::handleWheelEventPhase(PlatformWheelEventPhase phase) { | 995 void ScrollAnimatorMac::handleWheelEventPhase(PlatformWheelEventPhase phase) { |
| 983 // This may not have been set to true yet if the wheel event was handled by | 996 // This may not have been set to true yet if the wheel event was handled by |
| 984 // the ScrollingTree, so set it to true here. | 997 // the ScrollingTree, |
| 998 // So set it to true here. |
| 985 m_haveScrolledSincePageLoad = true; | 999 m_haveScrolledSincePageLoad = true; |
| 986 | 1000 |
| 987 if (phase == PlatformWheelEventPhaseBegan) | 1001 if (phase == PlatformWheelEventPhaseBegan) |
| 988 didBeginScrollGesture(); | 1002 didBeginScrollGesture(); |
| 989 else if (phase == PlatformWheelEventPhaseEnded || | 1003 else if (phase == PlatformWheelEventPhaseEnded || |
| 990 phase == PlatformWheelEventPhaseCancelled) | 1004 phase == PlatformWheelEventPhaseCancelled) |
| 991 didEndScrollGesture(); | 1005 didEndScrollGesture(); |
| 992 else if (phase == PlatformWheelEventPhaseMayBegin) | 1006 else if (phase == PlatformWheelEventPhaseMayBegin) |
| 993 mayBeginScrollGesture(); | 1007 mayBeginScrollGesture(); |
| 994 } | 1008 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1015 ScrollbarPainter newVerticalPainter = [NSClassFromString(@"NSScrollerImp") | 1029 ScrollbarPainter newVerticalPainter = [NSClassFromString(@"NSScrollerImp") |
| 1016 scrollerImpWithStyle:newStyle | 1030 scrollerImpWithStyle:newStyle |
| 1017 controlSize:(NSControlSize)verticalScrollbar->controlSize() | 1031 controlSize:(NSControlSize)verticalScrollbar->controlSize() |
| 1018 horizontal:NO | 1032 horizontal:NO |
| 1019 replacingScrollerImp:oldVerticalPainter]; | 1033 replacingScrollerImp:oldVerticalPainter]; |
| 1020 [m_scrollbarPainterController.get() | 1034 [m_scrollbarPainterController.get() |
| 1021 setVerticalScrollerImp:newVerticalPainter]; | 1035 setVerticalScrollerImp:newVerticalPainter]; |
| 1022 macTheme->setNewPainterForScrollbar(*verticalScrollbar, newVerticalPainter); | 1036 macTheme->setNewPainterForScrollbar(*verticalScrollbar, newVerticalPainter); |
| 1023 | 1037 |
| 1024 // The different scrollbar styles have different thicknesses, so we must | 1038 // The different scrollbar styles have different thicknesses, so we must |
| 1025 // re-set the frameRect to the new thickness, and the re-layout below will | 1039 // re-set the |
| 1026 // ensure the position and length are properly updated. | 1040 // frameRect to the new thickness, and the re-layout below will ensure the |
| 1041 // offset |
| 1042 // and length are properly updated. |
| 1027 int thickness = | 1043 int thickness = |
| 1028 macTheme->scrollbarThickness(verticalScrollbar->controlSize()); | 1044 macTheme->scrollbarThickness(verticalScrollbar->controlSize()); |
| 1029 verticalScrollbar->setFrameRect(IntRect(0, 0, thickness, thickness)); | 1045 verticalScrollbar->setFrameRect(IntRect(0, 0, thickness, thickness)); |
| 1030 } | 1046 } |
| 1031 | 1047 |
| 1032 if (Scrollbar* horizontalScrollbar = | 1048 if (Scrollbar* horizontalScrollbar = |
| 1033 getScrollableArea()->horizontalScrollbar()) { | 1049 getScrollableArea()->horizontalScrollbar()) { |
| 1034 horizontalScrollbar->setNeedsPaintInvalidation(AllParts); | 1050 horizontalScrollbar->setNeedsPaintInvalidation(AllParts); |
| 1035 | 1051 |
| 1036 ScrollbarPainter oldHorizontalPainter = | 1052 ScrollbarPainter oldHorizontalPainter = |
| 1037 [m_scrollbarPainterController.get() horizontalScrollerImp]; | 1053 [m_scrollbarPainterController.get() horizontalScrollerImp]; |
| 1038 ScrollbarPainter newHorizontalPainter = [NSClassFromString(@"NSScrollerImp") | 1054 ScrollbarPainter newHorizontalPainter = [NSClassFromString(@"NSScrollerImp") |
| 1039 scrollerImpWithStyle:newStyle | 1055 scrollerImpWithStyle:newStyle |
| 1040 controlSize:(NSControlSize)horizontalScrollbar->controlSize() | 1056 controlSize:(NSControlSize)horizontalScrollbar->controlSize() |
| 1041 horizontal:YES | 1057 horizontal:YES |
| 1042 replacingScrollerImp:oldHorizontalPainter]; | 1058 replacingScrollerImp:oldHorizontalPainter]; |
| 1043 [m_scrollbarPainterController.get() | 1059 [m_scrollbarPainterController.get() |
| 1044 setHorizontalScrollerImp:newHorizontalPainter]; | 1060 setHorizontalScrollerImp:newHorizontalPainter]; |
| 1045 macTheme->setNewPainterForScrollbar(*horizontalScrollbar, | 1061 macTheme->setNewPainterForScrollbar(*horizontalScrollbar, |
| 1046 newHorizontalPainter); | 1062 newHorizontalPainter); |
| 1047 | 1063 |
| 1048 // The different scrollbar styles have different thicknesses, so we must | 1064 // The different scrollbar styles have different thicknesses, so we must |
| 1049 // re-set the frameRect to the new thickness, and the re-layout below will | 1065 // re-set the |
| 1050 // ensure the position and length are properly updated. | 1066 // frameRect to the new thickness, and the re-layout below will ensure the |
| 1067 // offset |
| 1068 // and length are properly updated. |
| 1051 int thickness = | 1069 int thickness = |
| 1052 macTheme->scrollbarThickness(horizontalScrollbar->controlSize()); | 1070 macTheme->scrollbarThickness(horizontalScrollbar->controlSize()); |
| 1053 horizontalScrollbar->setFrameRect(IntRect(0, 0, thickness, thickness)); | 1071 horizontalScrollbar->setFrameRect(IntRect(0, 0, thickness, thickness)); |
| 1054 } | 1072 } |
| 1055 | 1073 |
| 1056 // If m_needsScrollerStyleUpdate is true, then the page is restoring from the | 1074 // If m_needsScrollerStyleUpdate is true, then the page is restoring from the |
| 1057 // page cache, and a relayout will happen on its own. Otherwise, we must | 1075 // page cache, and |
| 1058 // initiate a re-layout ourselves. | 1076 // a relayout will happen on its own. Otherwise, we must initiate a re-layout |
| 1077 // ourselves. |
| 1059 if (!m_needsScrollerStyleUpdate) | 1078 if (!m_needsScrollerStyleUpdate) |
| 1060 getScrollableArea()->scrollbarStyleChanged(); | 1079 getScrollableArea()->scrollbarStyleChanged(); |
| 1061 | 1080 |
| 1062 m_needsScrollerStyleUpdate = false; | 1081 m_needsScrollerStyleUpdate = false; |
| 1063 } | 1082 } |
| 1064 | 1083 |
| 1065 void ScrollAnimatorMac::startScrollbarPaintTimer() { | 1084 void ScrollAnimatorMac::startScrollbarPaintTimer() { |
| 1066 m_taskRunner->postDelayedTask( | 1085 m_taskRunner->postDelayedTask( |
| 1067 BLINK_FROM_HERE, m_initialScrollbarPaintTaskFactory->cancelAndCreate(), | 1086 BLINK_FROM_HERE, m_initialScrollbarPaintTaskFactory->cancelAndCreate(), |
| 1068 0.1); | 1087 0.1); |
| 1069 } | 1088 } |
| 1070 | 1089 |
| 1071 bool ScrollAnimatorMac::scrollbarPaintTimerIsActive() const { | 1090 bool ScrollAnimatorMac::scrollbarPaintTimerIsActive() const { |
| 1072 return m_initialScrollbarPaintTaskFactory->isPending(); | 1091 return m_initialScrollbarPaintTaskFactory->isPending(); |
| 1073 } | 1092 } |
| 1074 | 1093 |
| 1075 void ScrollAnimatorMac::stopScrollbarPaintTimer() { | 1094 void ScrollAnimatorMac::stopScrollbarPaintTimer() { |
| 1076 m_initialScrollbarPaintTaskFactory->cancel(); | 1095 m_initialScrollbarPaintTaskFactory->cancel(); |
| 1077 } | 1096 } |
| 1078 | 1097 |
| 1079 void ScrollAnimatorMac::initialScrollbarPaintTask() { | 1098 void ScrollAnimatorMac::initialScrollbarPaintTask() { |
| 1080 // To force the scrollbars to flash, we have to call hide first. Otherwise, | 1099 // To force the scrollbars to flash, we have to call hide first. Otherwise, |
| 1081 // the ScrollbarPainterController might think that the scrollbars are already | 1100 // the ScrollbarPainterController |
| 1082 // showing and bail early. | 1101 // might think that the scrollbars are already showing and bail early. |
| 1083 [m_scrollbarPainterController.get() hideOverlayScrollers]; | 1102 [m_scrollbarPainterController.get() hideOverlayScrollers]; |
| 1084 [m_scrollbarPainterController.get() flashScrollers]; | 1103 [m_scrollbarPainterController.get() flashScrollers]; |
| 1085 } | 1104 } |
| 1086 | 1105 |
| 1087 void ScrollAnimatorMac::sendContentAreaScrolledSoon(const FloatSize& delta) { | 1106 void ScrollAnimatorMac::sendContentAreaScrolledSoon(const ScrollOffset& delta) { |
| 1088 m_contentAreaScrolledTimerScrollDelta = delta; | 1107 m_contentAreaScrolledTimerScrollDelta = delta; |
| 1089 | 1108 |
| 1090 if (!m_sendContentAreaScrolledTaskFactory->isPending()) | 1109 if (!m_sendContentAreaScrolledTaskFactory->isPending()) |
| 1091 m_taskRunner->postTask( | 1110 m_taskRunner->postTask( |
| 1092 BLINK_FROM_HERE, | 1111 BLINK_FROM_HERE, |
| 1093 m_sendContentAreaScrolledTaskFactory->cancelAndCreate()); | 1112 m_sendContentAreaScrolledTaskFactory->cancelAndCreate()); |
| 1094 } | 1113 } |
| 1095 | 1114 |
| 1096 void ScrollAnimatorMac::sendContentAreaScrolledTask() { | 1115 void ScrollAnimatorMac::sendContentAreaScrolledTask() { |
| 1097 if (supportsContentAreaScrolledInDirection()) { | 1116 if (supportsContentAreaScrolledInDirection()) { |
| 1098 [m_scrollbarPainterController.get() | 1117 [m_scrollbarPainterController.get() |
| 1099 contentAreaScrolledInDirection:NSMakePoint( | 1118 contentAreaScrolledInDirection:NSMakePoint( |
| 1100 m_contentAreaScrolledTimerScrollDelta | 1119 m_contentAreaScrolledTimerScrollDelta |
| 1101 .width(), | 1120 .width(), |
| 1102 m_contentAreaScrolledTimerScrollDelta | 1121 m_contentAreaScrolledTimerScrollDelta |
| 1103 .height())]; | 1122 .height())]; |
| 1104 m_contentAreaScrolledTimerScrollDelta = FloatSize(); | 1123 m_contentAreaScrolledTimerScrollDelta = ScrollOffset(); |
| 1105 } else | 1124 } else |
| 1106 [m_scrollbarPainterController.get() contentAreaScrolled]; | 1125 [m_scrollbarPainterController.get() contentAreaScrolled]; |
| 1107 } | 1126 } |
| 1108 | 1127 |
| 1109 void ScrollAnimatorMac::setVisibleScrollerThumbRect( | 1128 void ScrollAnimatorMac::setVisibleScrollerThumbRect( |
| 1110 const IntRect& scrollerThumb) { | 1129 const IntRect& scrollerThumb) { |
| 1111 IntRect rectInViewCoordinates = scrollerThumb; | 1130 IntRect rectInViewCoordinates = scrollerThumb; |
| 1112 if (Scrollbar* verticalScrollbar = m_scrollableArea->verticalScrollbar()) | 1131 if (Scrollbar* verticalScrollbar = m_scrollableArea->verticalScrollbar()) |
| 1113 rectInViewCoordinates = | 1132 rectInViewCoordinates = |
| 1114 verticalScrollbar->convertToContainingWidget(scrollerThumb); | 1133 verticalScrollbar->convertToContainingWidget(scrollerThumb); |
| 1115 | 1134 |
| 1116 if (rectInViewCoordinates == m_visibleScrollerThumbRect) | 1135 if (rectInViewCoordinates == m_visibleScrollerThumbRect) |
| 1117 return; | 1136 return; |
| 1118 | 1137 |
| 1119 m_visibleScrollerThumbRect = rectInViewCoordinates; | 1138 m_visibleScrollerThumbRect = rectInViewCoordinates; |
| 1120 } | 1139 } |
| 1121 | 1140 |
| 1122 } // namespace blink | 1141 } // namespace blink |
| OLD | NEW |