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 27 matching lines...) Expand all Loading... |
38 #include "platform/scroll/ScrollbarThemeMac.h" | 38 #include "platform/scroll/ScrollbarThemeMac.h" |
39 #include "public/platform/Platform.h" | 39 #include "public/platform/Platform.h" |
40 #include "public/platform/WebScheduler.h" | 40 #include "public/platform/WebScheduler.h" |
41 #include "wtf/MathExtras.h" | 41 #include "wtf/MathExtras.h" |
42 #include "wtf/PtrUtil.h" | 42 #include "wtf/PtrUtil.h" |
43 #include <memory> | 43 #include <memory> |
44 | 44 |
45 using namespace blink; | 45 using namespace blink; |
46 | 46 |
47 static bool supportsUIStateTransitionProgress() { | 47 static bool supportsUIStateTransitionProgress() { |
48 // FIXME: This is temporary until all platforms that support ScrollbarPainter
support this part of the API. | 48 // FIXME: This is temporary until all platforms that support ScrollbarPainter |
| 49 // support this part of the API. |
49 static bool globalSupportsUIStateTransitionProgress = | 50 static bool globalSupportsUIStateTransitionProgress = |
50 [NSClassFromString(@"NSScrollerImp") | 51 [NSClassFromString(@"NSScrollerImp") |
51 instancesRespondToSelector:@selector(mouseEnteredScroller)]; | 52 instancesRespondToSelector:@selector(mouseEnteredScroller)]; |
52 return globalSupportsUIStateTransitionProgress; | 53 return globalSupportsUIStateTransitionProgress; |
53 } | 54 } |
54 | 55 |
55 static bool supportsExpansionTransitionProgress() { | 56 static bool supportsExpansionTransitionProgress() { |
56 static bool globalSupportsExpansionTransitionProgress = | 57 static bool globalSupportsExpansionTransitionProgress = |
57 [NSClassFromString(@"NSScrollerImp") | 58 [NSClassFromString(@"NSScrollerImp") |
58 instancesRespondToSelector:@selector(expansionTransitionProgress)]; | 59 instancesRespondToSelector:@selector(expansionTransitionProgress)]; |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 toScrollerImp:(id)scrollerImp { | 215 toScrollerImp:(id)scrollerImp { |
215 if (!_scrollableArea || !scrollerImp) | 216 if (!_scrollableArea || !scrollerImp) |
216 return NSZeroPoint; | 217 return NSZeroPoint; |
217 | 218 |
218 blink::Scrollbar* scrollbar = nil; | 219 blink::Scrollbar* scrollbar = nil; |
219 if ([scrollerImp isHorizontal]) | 220 if ([scrollerImp isHorizontal]) |
220 scrollbar = _scrollableArea->horizontalScrollbar(); | 221 scrollbar = _scrollableArea->horizontalScrollbar(); |
221 else | 222 else |
222 scrollbar = _scrollableArea->verticalScrollbar(); | 223 scrollbar = _scrollableArea->verticalScrollbar(); |
223 | 224 |
224 // It is possible to have a null scrollbar here since it is possible for this
delegate | 225 // It is possible to have a null scrollbar here since it is possible for this |
225 // method to be called between the moment when a scrollbar has been set to 0 a
nd the | 226 // delegate method to be called between the moment when a scrollbar has been |
226 // moment when its destructor has been called. We should probably de-couple so
me | 227 // set to 0 and the moment when its destructor has been called. We should |
227 // of the clean-up work in ScrollbarThemeMac::unregisterScrollbar() to avoid t
his | 228 // probably de-couple some of the clean-up work in |
228 // issue. | 229 // ScrollbarThemeMac::unregisterScrollbar() to avoid this issue. |
229 if (!scrollbar) | 230 if (!scrollbar) |
230 return NSZeroPoint; | 231 return NSZeroPoint; |
231 | 232 |
232 ASSERT(scrollerImp == scrollbarPainterForScrollbar(*scrollbar)); | 233 ASSERT(scrollerImp == scrollbarPainterForScrollbar(*scrollbar)); |
233 | 234 |
234 return scrollbar->convertFromContainingWidget( | 235 return scrollbar->convertFromContainingWidget( |
235 blink::IntPoint(pointInContentArea)); | 236 blink::IntPoint(pointInContentArea)); |
236 } | 237 } |
237 | 238 |
238 - (void)scrollerImpPair:(id)scrollerImpPair | 239 - (void)scrollerImpPair:(id)scrollerImpPair |
239 setContentAreaNeedsDisplayInRect:(NSRect)rect { | 240 setContentAreaNeedsDisplayInRect:(NSRect)rect { |
240 if (!_scrollableArea) | 241 if (!_scrollableArea) |
241 return; | 242 return; |
242 | 243 |
243 if (!_scrollableArea->scrollbarsCanBeActive()) | 244 if (!_scrollableArea->scrollbarsCanBeActive()) |
244 return; | 245 return; |
245 | 246 |
246 _scrollableArea->scrollAnimator().contentAreaWillPaint(); | 247 _scrollableArea->scrollAnimator().contentAreaWillPaint(); |
247 } | 248 } |
248 | 249 |
249 - (void)scrollerImpPair:(id)scrollerImpPair | 250 - (void)scrollerImpPair:(id)scrollerImpPair |
250 updateScrollerStyleForNewRecommendedScrollerStyle: | 251 updateScrollerStyleForNewRecommendedScrollerStyle: |
251 (NSScrollerStyle)newRecommendedScrollerStyle { | 252 (NSScrollerStyle)newRecommendedScrollerStyle { |
252 // Chrome has a single process mode which is used for testing on Mac. In that
mode, WebKit runs on a thread in the | 253 // Chrome has a single process mode which is used for testing on Mac. In that |
253 // browser process. This notification is called by the OS on the main thread i
n the browser process, and not on the | 254 // mode, WebKit runs on a thread in the browser process. This notification is |
| 255 // called by the OS on the main thread in the browser process, and not on the |
254 // the WebKit thread. Better to not update the style than crash. | 256 // the WebKit thread. Better to not update the style than crash. |
255 // http://crbug.com/126514 | 257 // http://crbug.com/126514 |
256 if (!isMainThread()) | 258 if (!isMainThread()) |
257 return; | 259 return; |
258 | 260 |
259 if (!_scrollableArea) | 261 if (!_scrollableArea) |
260 return; | 262 return; |
261 | 263 |
262 [scrollerImpPair setScrollerStyle:newRecommendedScrollerStyle]; | 264 [scrollerImpPair setScrollerStyle:newRecommendedScrollerStyle]; |
263 | 265 |
264 static_cast<ScrollAnimatorMac&>(_scrollableArea->scrollAnimator()) | 266 static_cast<ScrollAnimatorMac&>(_scrollableArea->scrollAnimator()) |
265 .updateScrollerStyle(); | 267 .updateScrollerStyle(); |
266 } | 268 } |
267 | 269 |
268 @end | 270 @end |
269 | 271 |
270 enum FeatureToAnimate { | 272 enum FeatureToAnimate { |
271 ThumbAlpha, | 273 ThumbAlpha, |
272 TrackAlpha, | 274 TrackAlpha, |
273 UIStateTransition, | 275 UIStateTransition, |
274 ExpansionTransition | 276 ExpansionTransition |
275 }; | 277 }; |
276 | 278 |
277 @class BlinkScrollbarPartAnimation; | 279 @class BlinkScrollbarPartAnimation; |
278 | 280 |
279 namespace blink { | 281 namespace blink { |
280 | 282 |
281 // This class is used to drive the animation timer for BlinkScrollbarPartAnimati
on | 283 // This class is used to drive the animation timer for |
282 // objects. This is used instead of NSAnimation because CoreAnimation | 284 // BlinkScrollbarPartAnimation objects. This is used instead of NSAnimation |
283 // establishes connections to the WindowServer, which should not be done in a | 285 // because CoreAnimation establishes connections to the WindowServer, which |
284 // sandboxed renderer process. | 286 // should not be done in a sandboxed renderer process. |
285 class BlinkScrollbarPartAnimationTimer { | 287 class BlinkScrollbarPartAnimationTimer { |
286 public: | 288 public: |
287 BlinkScrollbarPartAnimationTimer(BlinkScrollbarPartAnimation* animation, | 289 BlinkScrollbarPartAnimationTimer(BlinkScrollbarPartAnimation* animation, |
288 CFTimeInterval duration) | 290 CFTimeInterval duration) |
289 : m_timer(this, &BlinkScrollbarPartAnimationTimer::timerFired), | 291 : m_timer(this, &BlinkScrollbarPartAnimationTimer::timerFired), |
290 m_startTime(0.0), | 292 m_startTime(0.0), |
291 m_duration(duration), | 293 m_duration(duration), |
292 m_animation(animation), | 294 m_animation(animation), |
293 m_timingFunction(CubicBezierTimingFunction::preset( | 295 m_timingFunction(CubicBezierTimingFunction::preset( |
294 CubicBezierTimingFunction::EaseType::EASE_IN_OUT)) {} | 296 CubicBezierTimingFunction::EaseType::EASE_IN_OUT)) {} |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 return _scrollbar->convertFromContainingWidget( | 491 return _scrollbar->convertFromContainingWidget( |
490 _scrollbar->getScrollableArea()->lastKnownMousePosition()); | 492 _scrollbar->getScrollableArea()->lastKnownMousePosition()); |
491 } | 493 } |
492 | 494 |
493 - (void)setUpAlphaAnimation: | 495 - (void)setUpAlphaAnimation: |
494 (RetainPtr<BlinkScrollbarPartAnimation>&)scrollbarPartAnimation | 496 (RetainPtr<BlinkScrollbarPartAnimation>&)scrollbarPartAnimation |
495 scrollerPainter:(ScrollbarPainter)scrollerPainter | 497 scrollerPainter:(ScrollbarPainter)scrollerPainter |
496 part:(blink::ScrollbarPart)part | 498 part:(blink::ScrollbarPart)part |
497 animateAlphaTo:(CGFloat)newAlpha | 499 animateAlphaTo:(CGFloat)newAlpha |
498 duration:(NSTimeInterval)duration { | 500 duration:(NSTimeInterval)duration { |
499 // If the user has scrolled the page, then the scrollbars must be animated her
e. | 501 // If the user has scrolled the page, then the scrollbars must be animated |
500 // This overrides the early returns. | 502 // here. This overrides the early returns. |
501 bool mustAnimate = [self scrollAnimator].haveScrolledSincePageLoad(); | 503 bool mustAnimate = [self scrollAnimator].haveScrolledSincePageLoad(); |
502 | 504 |
503 if ([self scrollAnimator].scrollbarPaintTimerIsActive() && !mustAnimate) | 505 if ([self scrollAnimator].scrollbarPaintTimerIsActive() && !mustAnimate) |
504 return; | 506 return; |
505 | 507 |
506 if (_scrollbar->getScrollableArea()->shouldSuspendScrollAnimations() && | 508 if (_scrollbar->getScrollableArea()->shouldSuspendScrollAnimations() && |
507 !mustAnimate) { | 509 !mustAnimate) { |
508 [self scrollAnimator].startScrollbarPaintTimer(); | 510 [self scrollAnimator].startScrollbarPaintTimer(); |
509 return; | 511 return; |
510 } | 512 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 if (!_scrollbar) | 576 if (!_scrollbar) |
575 return; | 577 return; |
576 | 578 |
577 if (!supportsUIStateTransitionProgress()) | 579 if (!supportsUIStateTransitionProgress()) |
578 return; | 580 return; |
579 | 581 |
580 ASSERT(scrollerImp == scrollbarPainterForScrollbar(*_scrollbar)); | 582 ASSERT(scrollerImp == scrollbarPainterForScrollbar(*_scrollbar)); |
581 | 583 |
582 ScrollbarPainter scrollbarPainter = (ScrollbarPainter)scrollerImp; | 584 ScrollbarPainter scrollbarPainter = (ScrollbarPainter)scrollerImp; |
583 | 585 |
584 // UIStateTransition always animates to 1. In case an animation is in progress
this avoids a hard transition. | 586 // UIStateTransition always animates to 1. In case an animation is in progress |
| 587 // this avoids a hard transition. |
585 [scrollbarPainter | 588 [scrollbarPainter |
586 setUiStateTransitionProgress:1 - [scrollerImp uiStateTransitionProgress]]; | 589 setUiStateTransitionProgress:1 - [scrollerImp uiStateTransitionProgress]]; |
587 | 590 |
588 if (!_uiStateTransitionAnimation) | 591 if (!_uiStateTransitionAnimation) |
589 _uiStateTransitionAnimation.adoptNS([[BlinkScrollbarPartAnimation alloc] | 592 _uiStateTransitionAnimation.adoptNS([[BlinkScrollbarPartAnimation alloc] |
590 initWithScrollbar:_scrollbar | 593 initWithScrollbar:_scrollbar |
591 featureToAnimate:UIStateTransition | 594 featureToAnimate:UIStateTransition |
592 animateFrom:[scrollbarPainter uiStateTransitionProgress] | 595 animateFrom:[scrollbarPainter uiStateTransitionProgress] |
593 animateTo:1.0 | 596 animateTo:1.0 |
594 duration:duration]); | 597 duration:duration]); |
595 else { | 598 else { |
596 // If we don't need to initialize the animation, just reset the values in ca
se they have changed. | 599 // If we don't need to initialize the animation, just reset the values in |
| 600 // case they have changed. |
597 [_uiStateTransitionAnimation.get() | 601 [_uiStateTransitionAnimation.get() |
598 setStartValue:[scrollbarPainter uiStateTransitionProgress]]; | 602 setStartValue:[scrollbarPainter uiStateTransitionProgress]]; |
599 [_uiStateTransitionAnimation.get() setEndValue:1.0]; | 603 [_uiStateTransitionAnimation.get() setEndValue:1.0]; |
600 [_uiStateTransitionAnimation.get() setDuration:duration]; | 604 [_uiStateTransitionAnimation.get() setDuration:duration]; |
601 } | 605 } |
602 [_uiStateTransitionAnimation.get() startAnimation]; | 606 [_uiStateTransitionAnimation.get() startAnimation]; |
603 } | 607 } |
604 | 608 |
605 - (void)scrollerImp:(id)scrollerImp | 609 - (void)scrollerImp:(id)scrollerImp |
606 animateExpansionTransitionWithDuration:(NSTimeInterval)duration { | 610 animateExpansionTransitionWithDuration:(NSTimeInterval)duration { |
607 if (!_scrollbar) | 611 if (!_scrollbar) |
608 return; | 612 return; |
609 | 613 |
610 if (!supportsExpansionTransitionProgress()) | 614 if (!supportsExpansionTransitionProgress()) |
611 return; | 615 return; |
612 | 616 |
613 ASSERT(scrollerImp == scrollbarPainterForScrollbar(*_scrollbar)); | 617 ASSERT(scrollerImp == scrollbarPainterForScrollbar(*_scrollbar)); |
614 | 618 |
615 ScrollbarPainter scrollbarPainter = (ScrollbarPainter)scrollerImp; | 619 ScrollbarPainter scrollbarPainter = (ScrollbarPainter)scrollerImp; |
616 | 620 |
617 // ExpansionTransition always animates to 1. In case an animation is in progre
ss this avoids a hard transition. | 621 // ExpansionTransition always animates to 1. In case an animation is in |
| 622 // progress this avoids a hard transition. |
618 [scrollbarPainter | 623 [scrollbarPainter |
619 setExpansionTransitionProgress:1 - | 624 setExpansionTransitionProgress:1 - |
620 [scrollerImp expansionTransitionProgress]]; | 625 [scrollerImp expansionTransitionProgress]]; |
621 | 626 |
622 if (!_expansionTransitionAnimation) { | 627 if (!_expansionTransitionAnimation) { |
623 _expansionTransitionAnimation.adoptNS([[BlinkScrollbarPartAnimation alloc] | 628 _expansionTransitionAnimation.adoptNS([[BlinkScrollbarPartAnimation alloc] |
624 initWithScrollbar:_scrollbar | 629 initWithScrollbar:_scrollbar |
625 featureToAnimate:ExpansionTransition | 630 featureToAnimate:ExpansionTransition |
626 animateFrom:[scrollbarPainter expansionTransitionProgress] | 631 animateFrom:[scrollbarPainter expansionTransitionProgress] |
627 animateTo:1.0 | 632 animateTo:1.0 |
628 duration:duration]); | 633 duration:duration]); |
629 } else { | 634 } else { |
630 // If we don't need to initialize the animation, just reset the values in ca
se they have changed. | 635 // If we don't need to initialize the animation, just reset the values in |
| 636 // case they have changed. |
631 [_expansionTransitionAnimation.get() | 637 [_expansionTransitionAnimation.get() |
632 setStartValue:[scrollbarPainter uiStateTransitionProgress]]; | 638 setStartValue:[scrollbarPainter uiStateTransitionProgress]]; |
633 [_expansionTransitionAnimation.get() setEndValue:1.0]; | 639 [_expansionTransitionAnimation.get() setEndValue:1.0]; |
634 [_expansionTransitionAnimation.get() setDuration:duration]; | 640 [_expansionTransitionAnimation.get() setDuration:duration]; |
635 } | 641 } |
636 [_expansionTransitionAnimation.get() startAnimation]; | 642 [_expansionTransitionAnimation.get() startAnimation]; |
637 } | 643 } |
638 | 644 |
639 - (void)scrollerImp:(id)scrollerImp | 645 - (void)scrollerImp:(id)scrollerImp |
640 overlayScrollerStateChangedTo:(NSUInteger)newOverlayScrollerState { | 646 overlayScrollerStateChangedTo:(NSUInteger)newOverlayScrollerState { |
641 // The names of these states are based on their observed behavior, and are not
based on documentation. | 647 // The names of these states are based on their observed behavior, and are not |
| 648 // based on documentation. |
642 enum { | 649 enum { |
643 NSScrollerStateInvisible = 0, | 650 NSScrollerStateInvisible = 0, |
644 NSScrollerStateKnob = 1, | 651 NSScrollerStateKnob = 1, |
645 NSScrollerStateExpanded = 2 | 652 NSScrollerStateExpanded = 2 |
646 }; | 653 }; |
647 // We do not receive notifications about the thumb un-expanding when the scrol
lbar fades away. Ensure | 654 // We do not receive notifications about the thumb un-expanding when the |
648 // that we re-paint the thumb the next time that we transition away from being
invisible, so that | 655 // scrollbar fades away. Ensure that we re-paint the thumb the next time that |
649 // the thumb doesn't stick in an expanded state. | 656 // we transition away from being invisible, so that the thumb doesn't stick |
| 657 // in an expanded state. |
650 if (newOverlayScrollerState == NSScrollerStateExpanded) { | 658 if (newOverlayScrollerState == NSScrollerStateExpanded) { |
651 _hasExpandedSinceInvisible = YES; | 659 _hasExpandedSinceInvisible = YES; |
652 } else if (newOverlayScrollerState != NSScrollerStateInvisible && | 660 } else if (newOverlayScrollerState != NSScrollerStateInvisible && |
653 _hasExpandedSinceInvisible) { | 661 _hasExpandedSinceInvisible) { |
654 _scrollbar->setNeedsPaintInvalidation(ThumbPart); | 662 _scrollbar->setNeedsPaintInvalidation(ThumbPart); |
655 _hasExpandedSinceInvisible = NO; | 663 _hasExpandedSinceInvisible = NO; |
656 } | 664 } |
657 } | 665 } |
658 | 666 |
659 - (void)invalidate { | 667 - (void)invalidate { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 NSPoint targetOrigin = [m_scrollAnimationHelper.get() targetOrigin]; | 752 NSPoint targetOrigin = [m_scrollAnimationHelper.get() targetOrigin]; |
745 if (!delta.width()) | 753 if (!delta.width()) |
746 newPos.setX(targetOrigin.x); | 754 newPos.setX(targetOrigin.x); |
747 if (!delta.height()) | 755 if (!delta.height()) |
748 newPos.setY(targetOrigin.y); | 756 newPos.setY(targetOrigin.y); |
749 } | 757 } |
750 | 758 |
751 NSPoint newPoint = NSMakePoint(newPos.x(), newPos.y()); | 759 NSPoint newPoint = NSMakePoint(newPos.x(), newPos.y()); |
752 [m_scrollAnimationHelper.get() scrollToPoint:newPoint]; | 760 [m_scrollAnimationHelper.get() scrollToPoint:newPoint]; |
753 | 761 |
754 // TODO(bokan): This has different semantics on ScrollResult than ScrollAnimat
or, | 762 // TODO(bokan): This has different semantics on ScrollResult than |
755 // which only returns unused delta if there's no animation and we don't start
one. | 763 // ScrollAnimator, which only returns unused delta if there's no animation |
| 764 // and we don't start one. |
756 return ScrollResult(consumedDelta.width(), consumedDelta.height(), | 765 return ScrollResult(consumedDelta.width(), consumedDelta.height(), |
757 delta.width() - consumedDelta.width(), | 766 delta.width() - consumedDelta.width(), |
758 delta.height() - consumedDelta.height()); | 767 delta.height() - consumedDelta.height()); |
759 } | 768 } |
760 | 769 |
761 void ScrollAnimatorMac::scrollToOffsetWithoutAnimation( | 770 void ScrollAnimatorMac::scrollToOffsetWithoutAnimation( |
762 const FloatPoint& offset) { | 771 const FloatPoint& offset) { |
763 [m_scrollAnimationHelper.get() _stopRun]; | 772 [m_scrollAnimationHelper.get() _stopRun]; |
764 immediateScrollTo(offset); | 773 immediateScrollTo(offset); |
765 } | 774 } |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 [painter setDelegate:nil]; | 940 [painter setDelegate:nil]; |
932 [m_scrollbarPainterController.get() setHorizontalScrollerImp:nil]; | 941 [m_scrollbarPainterController.get() setHorizontalScrollerImp:nil]; |
933 } | 942 } |
934 | 943 |
935 bool ScrollAnimatorMac::shouldScrollbarParticipateInHitTesting( | 944 bool ScrollAnimatorMac::shouldScrollbarParticipateInHitTesting( |
936 Scrollbar& scrollbar) { | 945 Scrollbar& scrollbar) { |
937 // Non-overlay scrollbars should always participate in hit testing. | 946 // Non-overlay scrollbars should always participate in hit testing. |
938 if (ScrollbarThemeMac::recommendedScrollerStyle() != NSScrollerStyleOverlay) | 947 if (ScrollbarThemeMac::recommendedScrollerStyle() != NSScrollerStyleOverlay) |
939 return true; | 948 return true; |
940 | 949 |
941 // Overlay scrollbars should participate in hit testing whenever they are at a
ll visible. | 950 // Overlay scrollbars should participate in hit testing whenever they are at |
| 951 // all visible. |
942 ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar); | 952 ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar); |
943 if (!painter) | 953 if (!painter) |
944 return false; | 954 return false; |
945 return [painter knobAlpha] > 0; | 955 return [painter knobAlpha] > 0; |
946 } | 956 } |
947 | 957 |
948 void ScrollAnimatorMac::notifyContentAreaScrolled(const FloatSize& delta) { | 958 void ScrollAnimatorMac::notifyContentAreaScrolled(const FloatSize& delta) { |
949 // This function is called when a page is going into the page cache, but the p
age | 959 // This function is called when a page is going into the page cache, but the |
950 // isn't really scrolling in that case. We should only pass the message on to
the | 960 // page isn't really scrolling in that case. We should only pass the message |
951 // ScrollbarPainterController when we're really scrolling on an active page. | 961 // on to the ScrollbarPainterController when we're really scrolling on an |
| 962 // active page. |
952 if (getScrollableArea()->scrollbarsCanBeActive()) | 963 if (getScrollableArea()->scrollbarsCanBeActive()) |
953 sendContentAreaScrolledSoon(delta); | 964 sendContentAreaScrolledSoon(delta); |
954 } | 965 } |
955 | 966 |
956 bool ScrollAnimatorMac::setScrollbarsVisibleForTesting(bool show) { | 967 bool ScrollAnimatorMac::setScrollbarsVisibleForTesting(bool show) { |
957 if (show) | 968 if (show) |
958 [m_scrollbarPainterController.get() flashScrollers]; | 969 [m_scrollbarPainterController.get() flashScrollers]; |
959 else | 970 else |
960 [m_scrollbarPainterController.get() hideOverlayScrollers]; | 971 [m_scrollbarPainterController.get() hideOverlayScrollers]; |
961 | 972 |
962 [m_verticalScrollbarPainterDelegate.get() updateVisibilityImmediately:show]; | 973 [m_verticalScrollbarPainterDelegate.get() updateVisibilityImmediately:show]; |
963 [m_verticalScrollbarPainterDelegate.get() updateVisibilityImmediately:show]; | 974 [m_verticalScrollbarPainterDelegate.get() updateVisibilityImmediately:show]; |
964 return true; | 975 return true; |
965 } | 976 } |
966 | 977 |
967 void ScrollAnimatorMac::cancelAnimation() { | 978 void ScrollAnimatorMac::cancelAnimation() { |
968 [m_scrollAnimationHelper.get() _stopRun]; | 979 [m_scrollAnimationHelper.get() _stopRun]; |
969 m_haveScrolledSincePageLoad = false; | 980 m_haveScrolledSincePageLoad = false; |
970 } | 981 } |
971 | 982 |
972 void ScrollAnimatorMac::handleWheelEventPhase(PlatformWheelEventPhase phase) { | 983 void ScrollAnimatorMac::handleWheelEventPhase(PlatformWheelEventPhase phase) { |
973 // This may not have been set to true yet if the wheel event was handled by th
e ScrollingTree, | 984 // This may not have been set to true yet if the wheel event was handled by |
974 // So set it to true here. | 985 // the ScrollingTree, so set it to true here. |
975 m_haveScrolledSincePageLoad = true; | 986 m_haveScrolledSincePageLoad = true; |
976 | 987 |
977 if (phase == PlatformWheelEventPhaseBegan) | 988 if (phase == PlatformWheelEventPhaseBegan) |
978 didBeginScrollGesture(); | 989 didBeginScrollGesture(); |
979 else if (phase == PlatformWheelEventPhaseEnded || | 990 else if (phase == PlatformWheelEventPhaseEnded || |
980 phase == PlatformWheelEventPhaseCancelled) | 991 phase == PlatformWheelEventPhaseCancelled) |
981 didEndScrollGesture(); | 992 didEndScrollGesture(); |
982 else if (phase == PlatformWheelEventPhaseMayBegin) | 993 else if (phase == PlatformWheelEventPhaseMayBegin) |
983 mayBeginScrollGesture(); | 994 mayBeginScrollGesture(); |
984 } | 995 } |
(...skipping 19 matching lines...) Expand all Loading... |
1004 [m_scrollbarPainterController.get() verticalScrollerImp]; | 1015 [m_scrollbarPainterController.get() verticalScrollerImp]; |
1005 ScrollbarPainter newVerticalPainter = [NSClassFromString(@"NSScrollerImp") | 1016 ScrollbarPainter newVerticalPainter = [NSClassFromString(@"NSScrollerImp") |
1006 scrollerImpWithStyle:newStyle | 1017 scrollerImpWithStyle:newStyle |
1007 controlSize:(NSControlSize)verticalScrollbar->controlSize() | 1018 controlSize:(NSControlSize)verticalScrollbar->controlSize() |
1008 horizontal:NO | 1019 horizontal:NO |
1009 replacingScrollerImp:oldVerticalPainter]; | 1020 replacingScrollerImp:oldVerticalPainter]; |
1010 [m_scrollbarPainterController.get() | 1021 [m_scrollbarPainterController.get() |
1011 setVerticalScrollerImp:newVerticalPainter]; | 1022 setVerticalScrollerImp:newVerticalPainter]; |
1012 macTheme->setNewPainterForScrollbar(*verticalScrollbar, newVerticalPainter); | 1023 macTheme->setNewPainterForScrollbar(*verticalScrollbar, newVerticalPainter); |
1013 | 1024 |
1014 // The different scrollbar styles have different thicknesses, so we must re-
set the | 1025 // The different scrollbar styles have different thicknesses, so we must |
1015 // frameRect to the new thickness, and the re-layout below will ensure the p
osition | 1026 // re-set the frameRect to the new thickness, and the re-layout below will |
1016 // and length are properly updated. | 1027 // ensure the position and length are properly updated. |
1017 int thickness = | 1028 int thickness = |
1018 macTheme->scrollbarThickness(verticalScrollbar->controlSize()); | 1029 macTheme->scrollbarThickness(verticalScrollbar->controlSize()); |
1019 verticalScrollbar->setFrameRect(IntRect(0, 0, thickness, thickness)); | 1030 verticalScrollbar->setFrameRect(IntRect(0, 0, thickness, thickness)); |
1020 } | 1031 } |
1021 | 1032 |
1022 if (Scrollbar* horizontalScrollbar = | 1033 if (Scrollbar* horizontalScrollbar = |
1023 getScrollableArea()->horizontalScrollbar()) { | 1034 getScrollableArea()->horizontalScrollbar()) { |
1024 horizontalScrollbar->setNeedsPaintInvalidation(AllParts); | 1035 horizontalScrollbar->setNeedsPaintInvalidation(AllParts); |
1025 | 1036 |
1026 ScrollbarPainter oldHorizontalPainter = | 1037 ScrollbarPainter oldHorizontalPainter = |
1027 [m_scrollbarPainterController.get() horizontalScrollerImp]; | 1038 [m_scrollbarPainterController.get() horizontalScrollerImp]; |
1028 ScrollbarPainter newHorizontalPainter = [NSClassFromString(@"NSScrollerImp") | 1039 ScrollbarPainter newHorizontalPainter = [NSClassFromString(@"NSScrollerImp") |
1029 scrollerImpWithStyle:newStyle | 1040 scrollerImpWithStyle:newStyle |
1030 controlSize:(NSControlSize)horizontalScrollbar->controlSize() | 1041 controlSize:(NSControlSize)horizontalScrollbar->controlSize() |
1031 horizontal:YES | 1042 horizontal:YES |
1032 replacingScrollerImp:oldHorizontalPainter]; | 1043 replacingScrollerImp:oldHorizontalPainter]; |
1033 [m_scrollbarPainterController.get() | 1044 [m_scrollbarPainterController.get() |
1034 setHorizontalScrollerImp:newHorizontalPainter]; | 1045 setHorizontalScrollerImp:newHorizontalPainter]; |
1035 macTheme->setNewPainterForScrollbar(*horizontalScrollbar, | 1046 macTheme->setNewPainterForScrollbar(*horizontalScrollbar, |
1036 newHorizontalPainter); | 1047 newHorizontalPainter); |
1037 | 1048 |
1038 // The different scrollbar styles have different thicknesses, so we must re-
set the | 1049 // The different scrollbar styles have different thicknesses, so we must |
1039 // frameRect to the new thickness, and the re-layout below will ensure the p
osition | 1050 // re-set the frameRect to the new thickness, and the re-layout below will |
1040 // and length are properly updated. | 1051 // ensure the position and length are properly updated. |
1041 int thickness = | 1052 int thickness = |
1042 macTheme->scrollbarThickness(horizontalScrollbar->controlSize()); | 1053 macTheme->scrollbarThickness(horizontalScrollbar->controlSize()); |
1043 horizontalScrollbar->setFrameRect(IntRect(0, 0, thickness, thickness)); | 1054 horizontalScrollbar->setFrameRect(IntRect(0, 0, thickness, thickness)); |
1044 } | 1055 } |
1045 | 1056 |
1046 // If m_needsScrollerStyleUpdate is true, then the page is restoring from the
page cache, and | 1057 // If m_needsScrollerStyleUpdate is true, then the page is restoring from the |
1047 // a relayout will happen on its own. Otherwise, we must initiate a re-layout
ourselves. | 1058 // page cache, and a relayout will happen on its own. Otherwise, we must |
| 1059 // initiate a re-layout ourselves. |
1048 if (!m_needsScrollerStyleUpdate) | 1060 if (!m_needsScrollerStyleUpdate) |
1049 getScrollableArea()->scrollbarStyleChanged(); | 1061 getScrollableArea()->scrollbarStyleChanged(); |
1050 | 1062 |
1051 m_needsScrollerStyleUpdate = false; | 1063 m_needsScrollerStyleUpdate = false; |
1052 } | 1064 } |
1053 | 1065 |
1054 void ScrollAnimatorMac::startScrollbarPaintTimer() { | 1066 void ScrollAnimatorMac::startScrollbarPaintTimer() { |
1055 m_taskRunner->postDelayedTask( | 1067 m_taskRunner->postDelayedTask( |
1056 BLINK_FROM_HERE, m_initialScrollbarPaintTaskFactory->cancelAndCreate(), | 1068 BLINK_FROM_HERE, m_initialScrollbarPaintTaskFactory->cancelAndCreate(), |
1057 0.1); | 1069 0.1); |
1058 } | 1070 } |
1059 | 1071 |
1060 bool ScrollAnimatorMac::scrollbarPaintTimerIsActive() const { | 1072 bool ScrollAnimatorMac::scrollbarPaintTimerIsActive() const { |
1061 return m_initialScrollbarPaintTaskFactory->isPending(); | 1073 return m_initialScrollbarPaintTaskFactory->isPending(); |
1062 } | 1074 } |
1063 | 1075 |
1064 void ScrollAnimatorMac::stopScrollbarPaintTimer() { | 1076 void ScrollAnimatorMac::stopScrollbarPaintTimer() { |
1065 m_initialScrollbarPaintTaskFactory->cancel(); | 1077 m_initialScrollbarPaintTaskFactory->cancel(); |
1066 } | 1078 } |
1067 | 1079 |
1068 void ScrollAnimatorMac::initialScrollbarPaintTask() { | 1080 void ScrollAnimatorMac::initialScrollbarPaintTask() { |
1069 // To force the scrollbars to flash, we have to call hide first. Otherwise, th
e ScrollbarPainterController | 1081 // To force the scrollbars to flash, we have to call hide first. Otherwise, |
1070 // might think that the scrollbars are already showing and bail early. | 1082 // the ScrollbarPainterController might think that the scrollbars are already |
| 1083 // showing and bail early. |
1071 [m_scrollbarPainterController.get() hideOverlayScrollers]; | 1084 [m_scrollbarPainterController.get() hideOverlayScrollers]; |
1072 [m_scrollbarPainterController.get() flashScrollers]; | 1085 [m_scrollbarPainterController.get() flashScrollers]; |
1073 } | 1086 } |
1074 | 1087 |
1075 void ScrollAnimatorMac::sendContentAreaScrolledSoon(const FloatSize& delta) { | 1088 void ScrollAnimatorMac::sendContentAreaScrolledSoon(const FloatSize& delta) { |
1076 m_contentAreaScrolledTimerScrollDelta = delta; | 1089 m_contentAreaScrolledTimerScrollDelta = delta; |
1077 | 1090 |
1078 if (!m_sendContentAreaScrolledTaskFactory->isPending()) | 1091 if (!m_sendContentAreaScrolledTaskFactory->isPending()) |
1079 m_taskRunner->postTask( | 1092 m_taskRunner->postTask( |
1080 BLINK_FROM_HERE, | 1093 BLINK_FROM_HERE, |
(...skipping 20 matching lines...) Expand all Loading... |
1101 rectInViewCoordinates = | 1114 rectInViewCoordinates = |
1102 verticalScrollbar->convertToContainingWidget(scrollerThumb); | 1115 verticalScrollbar->convertToContainingWidget(scrollerThumb); |
1103 | 1116 |
1104 if (rectInViewCoordinates == m_visibleScrollerThumbRect) | 1117 if (rectInViewCoordinates == m_visibleScrollerThumbRect) |
1105 return; | 1118 return; |
1106 | 1119 |
1107 m_visibleScrollerThumbRect = rectInViewCoordinates; | 1120 m_visibleScrollerThumbRect = rectInViewCoordinates; |
1108 } | 1121 } |
1109 | 1122 |
1110 } // namespace blink | 1123 } // namespace blink |
OLD | NEW |