Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: third_party/WebKit/Source/platform/mac/ScrollAnimatorMac.mm

Issue 2387883002: Use float for scroll offset. (Closed)
Patch Set: rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 48 // FIXME: This is temporary until all platforms that support ScrollbarPainter support this part of the API.
49 // support this part of the API.
50 static bool globalSupportsUIStateTransitionProgress = 49 static bool globalSupportsUIStateTransitionProgress =
51 [NSClassFromString(@"NSScrollerImp") 50 [NSClassFromString(@"NSScrollerImp")
52 instancesRespondToSelector:@selector(mouseEnteredScroller)]; 51 instancesRespondToSelector:@selector(mouseEnteredScroller)];
53 return globalSupportsUIStateTransitionProgress; 52 return globalSupportsUIStateTransitionProgress;
54 } 53 }
55 54
56 static bool supportsExpansionTransitionProgress() { 55 static bool supportsExpansionTransitionProgress() {
57 static bool globalSupportsExpansionTransitionProgress = 56 static bool globalSupportsExpansionTransitionProgress =
58 [NSClassFromString(@"NSScrollerImp") 57 [NSClassFromString(@"NSScrollerImp")
59 instancesRespondToSelector:@selector(expansionTransitionProgress)]; 58 instancesRespondToSelector:@selector(expansionTransitionProgress)];
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 } 115 }
117 116
118 - (void)invalidate { 117 - (void)invalidate {
119 _animator = 0; 118 _animator = 0;
120 } 119 }
121 120
122 - (NSRect)bounds { 121 - (NSRect)bounds {
123 if (!_animator) 122 if (!_animator)
124 return NSZeroRect; 123 return NSZeroRect;
125 124
126 blink::FloatPoint currentPosition = _animator->currentPosition(); 125 blink::ScrollOffset currentOffset = _animator->currentOffset();
127 return NSMakeRect(currentPosition.x(), currentPosition.y(), 0, 0); 126 return NSMakeRect(currentOffset.width(), currentOffset.height(), 0, 0);
128 } 127 }
129 128
130 - (void)_immediateScrollToPoint:(NSPoint)newPosition { 129 - (void)_immediateScrollToPoint:(NSPoint)newPosition {
131 if (!_animator) 130 if (!_animator)
132 return; 131 return;
133 _animator->immediateScrollToPointForScrollAnimation(newPosition); 132 _animator->immediateScrollToOffsetForScrollAnimation(
133 toScrollOffset(newPosition));
134 } 134 }
135 135
136 - (NSPoint)_pixelAlignProposedScrollPosition:(NSPoint)newOrigin { 136 - (NSPoint)_pixelAlignProposedScrollPosition:(NSPoint)newOrigin {
137 return newOrigin; 137 return newOrigin;
138 } 138 }
139 139
140 - (NSSize)convertSizeToBase:(NSSize)size { 140 - (NSSize)convertSizeToBase:(NSSize)size {
141 return abs(size); 141 return abs(size);
142 } 142 }
143 143
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 toScrollerImp:(id)scrollerImp { 215 toScrollerImp:(id)scrollerImp {
216 if (!_scrollableArea || !scrollerImp) 216 if (!_scrollableArea || !scrollerImp)
217 return NSZeroPoint; 217 return NSZeroPoint;
218 218
219 blink::Scrollbar* scrollbar = nil; 219 blink::Scrollbar* scrollbar = nil;
220 if ([scrollerImp isHorizontal]) 220 if ([scrollerImp isHorizontal])
221 scrollbar = _scrollableArea->horizontalScrollbar(); 221 scrollbar = _scrollableArea->horizontalScrollbar();
222 else 222 else
223 scrollbar = _scrollableArea->verticalScrollbar(); 223 scrollbar = _scrollableArea->verticalScrollbar();
224 224
225 // It is possible to have a null scrollbar here since it is possible for this 225 // It is possible to have a null scrollbar here since it is possible for this delegate
226 // delegate method to be called between the moment when a scrollbar has been 226 // method to be called between the moment when a scrollbar has been set to 0 a nd the
227 // set to 0 and the moment when its destructor has been called. We should 227 // moment when its destructor has been called. We should probably de-couple so me
228 // probably de-couple some of the clean-up work in 228 // of the clean-up work in ScrollbarThemeMac::unregisterScrollbar() to avoid t his
229 // ScrollbarThemeMac::unregisterScrollbar() to avoid this issue. 229 // issue.
230 if (!scrollbar) 230 if (!scrollbar)
231 return NSZeroPoint; 231 return NSZeroPoint;
232 232
233 ASSERT(scrollerImp == scrollbarPainterForScrollbar(*scrollbar)); 233 ASSERT(scrollerImp == scrollbarPainterForScrollbar(*scrollbar));
234 234
235 return scrollbar->convertFromContainingWidget( 235 return scrollbar->convertFromContainingWidget(
236 blink::IntPoint(pointInContentArea)); 236 blink::IntPoint(pointInContentArea));
237 } 237 }
238 238
239 - (void)scrollerImpPair:(id)scrollerImpPair 239 - (void)scrollerImpPair:(id)scrollerImpPair
240 setContentAreaNeedsDisplayInRect:(NSRect)rect { 240 setContentAreaNeedsDisplayInRect:(NSRect)rect {
241 if (!_scrollableArea) 241 if (!_scrollableArea)
242 return; 242 return;
243 243
244 if (!_scrollableArea->scrollbarsCanBeActive()) 244 if (!_scrollableArea->scrollbarsCanBeActive())
245 return; 245 return;
246 246
247 _scrollableArea->scrollAnimator().contentAreaWillPaint(); 247 _scrollableArea->scrollAnimator().contentAreaWillPaint();
248 } 248 }
249 249
250 - (void)scrollerImpPair:(id)scrollerImpPair 250 - (void)scrollerImpPair:(id)scrollerImpPair
251 updateScrollerStyleForNewRecommendedScrollerStyle: 251 updateScrollerStyleForNewRecommendedScrollerStyle:
252 (NSScrollerStyle)newRecommendedScrollerStyle { 252 (NSScrollerStyle)newRecommendedScrollerStyle {
253 // Chrome has a single process mode which is used for testing on Mac. In that 253 // Chrome has a single process mode which is used for testing on Mac. In that mode, WebKit runs on a thread in the
254 // mode, WebKit runs on a thread in the browser process. This notification is 254 // browser process. This notification is called by the OS on the main thread i n the browser process, and not on the
255 // called by the OS on the main thread in the browser process, and not on the
256 // the WebKit thread. Better to not update the style than crash. 255 // the WebKit thread. Better to not update the style than crash.
257 // http://crbug.com/126514 256 // http://crbug.com/126514
258 if (!isMainThread()) 257 if (!isMainThread())
259 return; 258 return;
260 259
261 if (!_scrollableArea) 260 if (!_scrollableArea)
262 return; 261 return;
263 262
264 [scrollerImpPair setScrollerStyle:newRecommendedScrollerStyle]; 263 [scrollerImpPair setScrollerStyle:newRecommendedScrollerStyle];
265 264
266 static_cast<ScrollAnimatorMac&>(_scrollableArea->scrollAnimator()) 265 static_cast<ScrollAnimatorMac&>(_scrollableArea->scrollAnimator())
267 .updateScrollerStyle(); 266 .updateScrollerStyle();
268 } 267 }
269 268
270 @end 269 @end
271 270
272 enum FeatureToAnimate { 271 enum FeatureToAnimate {
273 ThumbAlpha, 272 ThumbAlpha,
274 TrackAlpha, 273 TrackAlpha,
275 UIStateTransition, 274 UIStateTransition,
276 ExpansionTransition 275 ExpansionTransition
277 }; 276 };
278 277
279 @class BlinkScrollbarPartAnimation; 278 @class BlinkScrollbarPartAnimation;
280 279
281 namespace blink { 280 namespace blink {
282 281
283 // This class is used to drive the animation timer for 282 // This class is used to drive the animation timer for BlinkScrollbarPartAnimati on
284 // BlinkScrollbarPartAnimation objects. This is used instead of NSAnimation 283 // objects. This is used instead of NSAnimation because CoreAnimation
285 // because CoreAnimation establishes connections to the WindowServer, which 284 // establishes connections to the WindowServer, which should not be done in a
286 // should not be done in a sandboxed renderer process. 285 // sandboxed renderer process.
287 class BlinkScrollbarPartAnimationTimer { 286 class BlinkScrollbarPartAnimationTimer {
288 public: 287 public:
289 BlinkScrollbarPartAnimationTimer(BlinkScrollbarPartAnimation* animation, 288 BlinkScrollbarPartAnimationTimer(BlinkScrollbarPartAnimation* animation,
290 CFTimeInterval duration) 289 CFTimeInterval duration)
291 : m_timer(this, &BlinkScrollbarPartAnimationTimer::timerFired), 290 : m_timer(this, &BlinkScrollbarPartAnimationTimer::timerFired),
292 m_startTime(0.0), 291 m_startTime(0.0),
293 m_duration(duration), 292 m_duration(duration),
294 m_animation(animation), 293 m_animation(animation),
295 m_timingFunction(CubicBezierTimingFunction::preset( 294 m_timingFunction(CubicBezierTimingFunction::preset(
296 CubicBezierTimingFunction::EaseType::EASE_IN_OUT)) {} 295 CubicBezierTimingFunction::EaseType::EASE_IN_OUT)) {}
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 return _scrollbar->convertFromContainingWidget( 490 return _scrollbar->convertFromContainingWidget(
492 _scrollbar->getScrollableArea()->lastKnownMousePosition()); 491 _scrollbar->getScrollableArea()->lastKnownMousePosition());
493 } 492 }
494 493
495 - (void)setUpAlphaAnimation: 494 - (void)setUpAlphaAnimation:
496 (RetainPtr<BlinkScrollbarPartAnimation>&)scrollbarPartAnimation 495 (RetainPtr<BlinkScrollbarPartAnimation>&)scrollbarPartAnimation
497 scrollerPainter:(ScrollbarPainter)scrollerPainter 496 scrollerPainter:(ScrollbarPainter)scrollerPainter
498 part:(blink::ScrollbarPart)part 497 part:(blink::ScrollbarPart)part
499 animateAlphaTo:(CGFloat)newAlpha 498 animateAlphaTo:(CGFloat)newAlpha
500 duration:(NSTimeInterval)duration { 499 duration:(NSTimeInterval)duration {
501 // If the user has scrolled the page, then the scrollbars must be animated 500 // If the user has scrolled the page, then the scrollbars must be animated her e.
502 // here. This overrides the early returns. 501 // This overrides the early returns.
503 bool mustAnimate = [self scrollAnimator].haveScrolledSincePageLoad(); 502 bool mustAnimate = [self scrollAnimator].haveScrolledSincePageLoad();
504 503
505 if ([self scrollAnimator].scrollbarPaintTimerIsActive() && !mustAnimate) 504 if ([self scrollAnimator].scrollbarPaintTimerIsActive() && !mustAnimate)
506 return; 505 return;
507 506
508 if (_scrollbar->getScrollableArea()->shouldSuspendScrollAnimations() && 507 if (_scrollbar->getScrollableArea()->shouldSuspendScrollAnimations() &&
509 !mustAnimate) { 508 !mustAnimate) {
510 [self scrollAnimator].startScrollbarPaintTimer(); 509 [self scrollAnimator].startScrollbarPaintTimer();
511 return; 510 return;
512 } 511 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 if (!_scrollbar) 575 if (!_scrollbar)
577 return; 576 return;
578 577
579 if (!supportsUIStateTransitionProgress()) 578 if (!supportsUIStateTransitionProgress())
580 return; 579 return;
581 580
582 ASSERT(scrollerImp == scrollbarPainterForScrollbar(*_scrollbar)); 581 ASSERT(scrollerImp == scrollbarPainterForScrollbar(*_scrollbar));
583 582
584 ScrollbarPainter scrollbarPainter = (ScrollbarPainter)scrollerImp; 583 ScrollbarPainter scrollbarPainter = (ScrollbarPainter)scrollerImp;
585 584
586 // UIStateTransition always animates to 1. In case an animation is in progress 585 // UIStateTransition always animates to 1. In case an animation is in progress this avoids a hard transition.
587 // this avoids a hard transition.
588 [scrollbarPainter 586 [scrollbarPainter
589 setUiStateTransitionProgress:1 - [scrollerImp uiStateTransitionProgress]]; 587 setUiStateTransitionProgress:1 - [scrollerImp uiStateTransitionProgress]];
590 588
591 if (!_uiStateTransitionAnimation) 589 if (!_uiStateTransitionAnimation)
592 _uiStateTransitionAnimation.adoptNS([[BlinkScrollbarPartAnimation alloc] 590 _uiStateTransitionAnimation.adoptNS([[BlinkScrollbarPartAnimation alloc]
593 initWithScrollbar:_scrollbar 591 initWithScrollbar:_scrollbar
594 featureToAnimate:UIStateTransition 592 featureToAnimate:UIStateTransition
595 animateFrom:[scrollbarPainter uiStateTransitionProgress] 593 animateFrom:[scrollbarPainter uiStateTransitionProgress]
596 animateTo:1.0 594 animateTo:1.0
597 duration:duration]); 595 duration:duration]);
598 else { 596 else {
599 // If we don't need to initialize the animation, just reset the values in 597 // If we don't need to initialize the animation, just reset the values in ca se they have changed.
600 // case they have changed.
601 [_uiStateTransitionAnimation.get() 598 [_uiStateTransitionAnimation.get()
602 setStartValue:[scrollbarPainter uiStateTransitionProgress]]; 599 setStartValue:[scrollbarPainter uiStateTransitionProgress]];
603 [_uiStateTransitionAnimation.get() setEndValue:1.0]; 600 [_uiStateTransitionAnimation.get() setEndValue:1.0];
604 [_uiStateTransitionAnimation.get() setDuration:duration]; 601 [_uiStateTransitionAnimation.get() setDuration:duration];
605 } 602 }
606 [_uiStateTransitionAnimation.get() startAnimation]; 603 [_uiStateTransitionAnimation.get() startAnimation];
607 } 604 }
608 605
609 - (void)scrollerImp:(id)scrollerImp 606 - (void)scrollerImp:(id)scrollerImp
610 animateExpansionTransitionWithDuration:(NSTimeInterval)duration { 607 animateExpansionTransitionWithDuration:(NSTimeInterval)duration {
611 if (!_scrollbar) 608 if (!_scrollbar)
612 return; 609 return;
613 610
614 if (!supportsExpansionTransitionProgress()) 611 if (!supportsExpansionTransitionProgress())
615 return; 612 return;
616 613
617 ASSERT(scrollerImp == scrollbarPainterForScrollbar(*_scrollbar)); 614 ASSERT(scrollerImp == scrollbarPainterForScrollbar(*_scrollbar));
618 615
619 ScrollbarPainter scrollbarPainter = (ScrollbarPainter)scrollerImp; 616 ScrollbarPainter scrollbarPainter = (ScrollbarPainter)scrollerImp;
620 617
621 // ExpansionTransition always animates to 1. In case an animation is in 618 // ExpansionTransition always animates to 1. In case an animation is in progre ss this avoids a hard transition.
622 // progress this avoids a hard transition.
623 [scrollbarPainter 619 [scrollbarPainter
624 setExpansionTransitionProgress:1 - 620 setExpansionTransitionProgress:1 -
625 [scrollerImp expansionTransitionProgress]]; 621 [scrollerImp expansionTransitionProgress]];
626 622
627 if (!_expansionTransitionAnimation) { 623 if (!_expansionTransitionAnimation) {
628 _expansionTransitionAnimation.adoptNS([[BlinkScrollbarPartAnimation alloc] 624 _expansionTransitionAnimation.adoptNS([[BlinkScrollbarPartAnimation alloc]
629 initWithScrollbar:_scrollbar 625 initWithScrollbar:_scrollbar
630 featureToAnimate:ExpansionTransition 626 featureToAnimate:ExpansionTransition
631 animateFrom:[scrollbarPainter expansionTransitionProgress] 627 animateFrom:[scrollbarPainter expansionTransitionProgress]
632 animateTo:1.0 628 animateTo:1.0
633 duration:duration]); 629 duration:duration]);
634 } else { 630 } else {
635 // If we don't need to initialize the animation, just reset the values in 631 // If we don't need to initialize the animation, just reset the values in ca se they have changed.
636 // case they have changed.
637 [_expansionTransitionAnimation.get() 632 [_expansionTransitionAnimation.get()
638 setStartValue:[scrollbarPainter uiStateTransitionProgress]]; 633 setStartValue:[scrollbarPainter uiStateTransitionProgress]];
639 [_expansionTransitionAnimation.get() setEndValue:1.0]; 634 [_expansionTransitionAnimation.get() setEndValue:1.0];
640 [_expansionTransitionAnimation.get() setDuration:duration]; 635 [_expansionTransitionAnimation.get() setDuration:duration];
641 } 636 }
642 [_expansionTransitionAnimation.get() startAnimation]; 637 [_expansionTransitionAnimation.get() startAnimation];
643 } 638 }
644 639
645 - (void)scrollerImp:(id)scrollerImp 640 - (void)scrollerImp:(id)scrollerImp
646 overlayScrollerStateChangedTo:(NSUInteger)newOverlayScrollerState { 641 overlayScrollerStateChangedTo:(NSUInteger)newOverlayScrollerState {
647 // The names of these states are based on their observed behavior, and are not 642 // The names of these states are based on their observed behavior, and are not based on documentation.
648 // based on documentation.
649 enum { 643 enum {
650 NSScrollerStateInvisible = 0, 644 NSScrollerStateInvisible = 0,
651 NSScrollerStateKnob = 1, 645 NSScrollerStateKnob = 1,
652 NSScrollerStateExpanded = 2 646 NSScrollerStateExpanded = 2
653 }; 647 };
654 // We do not receive notifications about the thumb un-expanding when the 648 // We do not receive notifications about the thumb un-expanding when the scrol lbar fades away. Ensure
655 // scrollbar fades away. Ensure that we re-paint the thumb the next time that 649 // that we re-paint the thumb the next time that we transition away from being invisible, so that
656 // we transition away from being invisible, so that the thumb doesn't stick 650 // the thumb doesn't stick in an expanded state.
657 // in an expanded state.
658 if (newOverlayScrollerState == NSScrollerStateExpanded) { 651 if (newOverlayScrollerState == NSScrollerStateExpanded) {
659 _hasExpandedSinceInvisible = YES; 652 _hasExpandedSinceInvisible = YES;
660 } else if (newOverlayScrollerState != NSScrollerStateInvisible && 653 } else if (newOverlayScrollerState != NSScrollerStateInvisible &&
661 _hasExpandedSinceInvisible) { 654 _hasExpandedSinceInvisible) {
662 _scrollbar->setNeedsPaintInvalidation(ThumbPart); 655 _scrollbar->setNeedsPaintInvalidation(ThumbPart);
663 _hasExpandedSinceInvisible = NO; 656 _hasExpandedSinceInvisible = NO;
664 } 657 }
665 } 658 }
666 659
667 - (void)invalidate { 660 - (void)invalidate {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 [m_horizontalScrollbarPainterDelegate.get() invalidate]; 719 [m_horizontalScrollbarPainterDelegate.get() invalidate];
727 [m_verticalScrollbarPainterDelegate.get() invalidate]; 720 [m_verticalScrollbarPainterDelegate.get() invalidate];
728 [m_scrollAnimationHelperDelegate.get() invalidate]; 721 [m_scrollAnimationHelperDelegate.get() invalidate];
729 END_BLOCK_OBJC_EXCEPTIONS; 722 END_BLOCK_OBJC_EXCEPTIONS;
730 723
731 m_initialScrollbarPaintTaskFactory->cancel(); 724 m_initialScrollbarPaintTaskFactory->cancel();
732 m_sendContentAreaScrolledTaskFactory->cancel(); 725 m_sendContentAreaScrolledTaskFactory->cancel();
733 } 726 }
734 727
735 ScrollResult ScrollAnimatorMac::userScroll(ScrollGranularity granularity, 728 ScrollResult ScrollAnimatorMac::userScroll(ScrollGranularity granularity,
736 const FloatSize& delta) { 729 const ScrollOffset& delta) {
737 m_haveScrolledSincePageLoad = true; 730 m_haveScrolledSincePageLoad = true;
738 731
739 if (!m_scrollableArea->scrollAnimatorEnabled()) 732 if (!m_scrollableArea->scrollAnimatorEnabled())
740 return ScrollAnimatorBase::userScroll(granularity, delta); 733 return ScrollAnimatorBase::userScroll(granularity, delta);
741 734
742 if (granularity == ScrollByPixel || granularity == ScrollByPrecisePixel) 735 if (granularity == ScrollByPixel || granularity == ScrollByPrecisePixel)
743 return ScrollAnimatorBase::userScroll(granularity, delta); 736 return ScrollAnimatorBase::userScroll(granularity, delta);
744 737
745 FloatSize consumedDelta = computeDeltaToConsume(delta); 738 ScrollOffset consumedDelta = computeDeltaToConsume(delta);
746 FloatPoint newPos = m_currentPos + consumedDelta; 739 ScrollOffset newOffset = m_currentOffset + consumedDelta;
747 if (m_currentPos == newPos) 740 if (m_currentOffset == newOffset)
748 return ScrollResult(); 741 return ScrollResult();
749 742
750 // Prevent clobbering an existing animation on an unscrolled axis. 743 // Prevent clobbering an existing animation on an unscrolled axis.
751 if ([m_scrollAnimationHelper.get() _isAnimating]) { 744 if ([m_scrollAnimationHelper.get() _isAnimating]) {
752 NSPoint targetOrigin = [m_scrollAnimationHelper.get() targetOrigin]; 745 NSPoint targetOrigin = [m_scrollAnimationHelper.get() targetOrigin];
753 if (!delta.width()) 746 if (!delta.width())
754 newPos.setX(targetOrigin.x); 747 newOffset.setWidth(targetOrigin.x);
755 if (!delta.height()) 748 if (!delta.height())
756 newPos.setY(targetOrigin.y); 749 newOffset.setHeight(targetOrigin.y);
757 } 750 }
758 751
759 NSPoint newPoint = NSMakePoint(newPos.x(), newPos.y()); 752 NSPoint newPoint = NSMakePoint(newOffset.width(), newOffset.height());
760 [m_scrollAnimationHelper.get() scrollToPoint:newPoint]; 753 [m_scrollAnimationHelper.get() scrollToPoint:newPoint];
761 754
762 // TODO(bokan): This has different semantics on ScrollResult than 755 // TODO(bokan): This has different semantics on ScrollResult than ScrollAnimat or,
763 // ScrollAnimator, which only returns unused delta if there's no animation 756 // which only returns unused delta if there's no animation and we don't start one.
764 // and we don't start one.
765 return ScrollResult(consumedDelta.width(), consumedDelta.height(), 757 return ScrollResult(consumedDelta.width(), consumedDelta.height(),
766 delta.width() - consumedDelta.width(), 758 delta.width() - consumedDelta.width(),
767 delta.height() - consumedDelta.height()); 759 delta.height() - consumedDelta.height());
768 } 760 }
769 761
770 void ScrollAnimatorMac::scrollToOffsetWithoutAnimation( 762 void ScrollAnimatorMac::scrollToOffsetWithoutAnimation(
771 const FloatPoint& offset) { 763 const ScrollOffset& offset) {
772 [m_scrollAnimationHelper.get() _stopRun]; 764 [m_scrollAnimationHelper.get() _stopRun];
773 immediateScrollTo(offset); 765 immediateScrollTo(offset);
774 } 766 }
775 767
776 FloatPoint ScrollAnimatorMac::adjustScrollPositionIfNecessary( 768 ScrollOffset ScrollAnimatorMac::adjustScrollOffsetIfNecessary(
777 const FloatPoint& position) const { 769 const ScrollOffset& offset) const {
778 IntPoint minPos = m_scrollableArea->minimumScrollPosition(); 770 ScrollOffset minOffset = m_scrollableArea->minimumScrollOffset();
779 IntPoint maxPos = m_scrollableArea->maximumScrollPosition(); 771 ScrollOffset maxOffset = m_scrollableArea->maximumScrollOffset();
780 772
781 float newX = clampTo<float, float>(position.x(), minPos.x(), maxPos.x()); 773 float newX = clampTo<float, float>(offset.width(), minOffset.width(),
782 float newY = clampTo<float, float>(position.y(), minPos.y(), maxPos.y()); 774 maxOffset.width());
775 float newY = clampTo<float, float>(offset.height(), minOffset.height(),
776 maxOffset.height());
783 777
784 return FloatPoint(newX, newY); 778 return ScrollOffset(newX, newY);
785 } 779 }
786 780
787 void ScrollAnimatorMac::immediateScrollTo(const FloatPoint& newPosition) { 781 void ScrollAnimatorMac::immediateScrollTo(const ScrollOffset& newOffset) {
788 FloatPoint adjustedPosition = adjustScrollPositionIfNecessary(newPosition); 782 ScrollOffset adjustedOffset = adjustScrollOffsetIfNecessary(newOffset);
789 783
790 bool positionChanged = adjustedPosition != m_currentPos; 784 bool offsetChanged = adjustedOffset != m_currentOffset;
791 if (!positionChanged && !getScrollableArea()->scrollOriginChanged()) 785 if (!offsetChanged && !getScrollableArea()->scrollOriginChanged())
792 return; 786 return;
793 787
794 FloatSize delta = adjustedPosition - m_currentPos; 788 ScrollOffset delta = adjustedOffset - m_currentOffset;
795 789
796 m_currentPos = adjustedPosition; 790 m_currentOffset = adjustedOffset;
797 notifyContentAreaScrolled(delta); 791 notifyContentAreaScrolled(delta);
798 notifyPositionChanged(); 792 notifyOffsetChanged();
799 } 793 }
800 794
801 void ScrollAnimatorMac::immediateScrollToPointForScrollAnimation( 795 void ScrollAnimatorMac::immediateScrollToOffsetForScrollAnimation(
802 const FloatPoint& newPosition) { 796 const ScrollOffset& newOffset) {
803 ASSERT(m_scrollAnimationHelper); 797 ASSERT(m_scrollAnimationHelper);
804 immediateScrollTo(newPosition); 798 immediateScrollTo(newOffset);
805 } 799 }
806 800
807 void ScrollAnimatorMac::contentAreaWillPaint() const { 801 void ScrollAnimatorMac::contentAreaWillPaint() const {
808 if (!getScrollableArea()->scrollbarsCanBeActive()) 802 if (!getScrollableArea()->scrollbarsCanBeActive())
809 return; 803 return;
810 [m_scrollbarPainterController.get() contentAreaWillDraw]; 804 [m_scrollbarPainterController.get() contentAreaWillDraw];
811 } 805 }
812 806
813 void ScrollAnimatorMac::mouseEnteredContentArea() const { 807 void ScrollAnimatorMac::mouseEnteredContentArea() const {
814 if (!getScrollableArea()->scrollbarsCanBeActive()) 808 if (!getScrollableArea()->scrollbarsCanBeActive())
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 [painter setDelegate:nil]; 934 [painter setDelegate:nil];
941 [m_scrollbarPainterController.get() setHorizontalScrollerImp:nil]; 935 [m_scrollbarPainterController.get() setHorizontalScrollerImp:nil];
942 } 936 }
943 937
944 bool ScrollAnimatorMac::shouldScrollbarParticipateInHitTesting( 938 bool ScrollAnimatorMac::shouldScrollbarParticipateInHitTesting(
945 Scrollbar& scrollbar) { 939 Scrollbar& scrollbar) {
946 // Non-overlay scrollbars should always participate in hit testing. 940 // Non-overlay scrollbars should always participate in hit testing.
947 if (ScrollbarThemeMac::recommendedScrollerStyle() != NSScrollerStyleOverlay) 941 if (ScrollbarThemeMac::recommendedScrollerStyle() != NSScrollerStyleOverlay)
948 return true; 942 return true;
949 943
950 // Overlay scrollbars should participate in hit testing whenever they are at 944 // Overlay scrollbars should participate in hit testing whenever they are at a ll visible.
951 // all visible.
952 ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar); 945 ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar);
953 if (!painter) 946 if (!painter)
954 return false; 947 return false;
955 return [painter knobAlpha] > 0; 948 return [painter knobAlpha] > 0;
956 } 949 }
957 950
958 void ScrollAnimatorMac::notifyContentAreaScrolled(const FloatSize& delta) { 951 void ScrollAnimatorMac::notifyContentAreaScrolled(const ScrollOffset& delta) {
959 // This function is called when a page is going into the page cache, but the 952 // This function is called when a page is going into the page cache, but the p age
960 // page isn't really scrolling in that case. We should only pass the message 953 // isn't really scrolling in that case. We should only pass the message on to the
961 // on to the ScrollbarPainterController when we're really scrolling on an 954 // ScrollbarPainterController when we're really scrolling on an active page.
962 // active page.
963 if (getScrollableArea()->scrollbarsCanBeActive()) 955 if (getScrollableArea()->scrollbarsCanBeActive())
964 sendContentAreaScrolledSoon(delta); 956 sendContentAreaScrolledSoon(delta);
965 } 957 }
966 958
967 bool ScrollAnimatorMac::setScrollbarsVisibleForTesting(bool show) { 959 bool ScrollAnimatorMac::setScrollbarsVisibleForTesting(bool show) {
968 if (show) 960 if (show)
969 [m_scrollbarPainterController.get() flashScrollers]; 961 [m_scrollbarPainterController.get() flashScrollers];
970 else 962 else
971 [m_scrollbarPainterController.get() hideOverlayScrollers]; 963 [m_scrollbarPainterController.get() hideOverlayScrollers];
972 964
973 [m_verticalScrollbarPainterDelegate.get() updateVisibilityImmediately:show]; 965 [m_verticalScrollbarPainterDelegate.get() updateVisibilityImmediately:show];
974 [m_verticalScrollbarPainterDelegate.get() updateVisibilityImmediately:show]; 966 [m_verticalScrollbarPainterDelegate.get() updateVisibilityImmediately:show];
975 return true; 967 return true;
976 } 968 }
977 969
978 void ScrollAnimatorMac::cancelAnimation() { 970 void ScrollAnimatorMac::cancelAnimation() {
979 [m_scrollAnimationHelper.get() _stopRun]; 971 [m_scrollAnimationHelper.get() _stopRun];
980 m_haveScrolledSincePageLoad = false; 972 m_haveScrolledSincePageLoad = false;
981 } 973 }
982 974
983 void ScrollAnimatorMac::handleWheelEventPhase(PlatformWheelEventPhase phase) { 975 void ScrollAnimatorMac::handleWheelEventPhase(PlatformWheelEventPhase phase) {
984 // This may not have been set to true yet if the wheel event was handled by 976 // This may not have been set to true yet if the wheel event was handled by th e ScrollingTree,
985 // the ScrollingTree, so set it to true here. 977 // So set it to true here.
986 m_haveScrolledSincePageLoad = true; 978 m_haveScrolledSincePageLoad = true;
987 979
988 if (phase == PlatformWheelEventPhaseBegan) 980 if (phase == PlatformWheelEventPhaseBegan)
989 didBeginScrollGesture(); 981 didBeginScrollGesture();
990 else if (phase == PlatformWheelEventPhaseEnded || 982 else if (phase == PlatformWheelEventPhaseEnded ||
991 phase == PlatformWheelEventPhaseCancelled) 983 phase == PlatformWheelEventPhaseCancelled)
992 didEndScrollGesture(); 984 didEndScrollGesture();
993 else if (phase == PlatformWheelEventPhaseMayBegin) 985 else if (phase == PlatformWheelEventPhaseMayBegin)
994 mayBeginScrollGesture(); 986 mayBeginScrollGesture();
995 } 987 }
(...skipping 19 matching lines...) Expand all
1015 [m_scrollbarPainterController.get() verticalScrollerImp]; 1007 [m_scrollbarPainterController.get() verticalScrollerImp];
1016 ScrollbarPainter newVerticalPainter = [NSClassFromString(@"NSScrollerImp") 1008 ScrollbarPainter newVerticalPainter = [NSClassFromString(@"NSScrollerImp")
1017 scrollerImpWithStyle:newStyle 1009 scrollerImpWithStyle:newStyle
1018 controlSize:(NSControlSize)verticalScrollbar->controlSize() 1010 controlSize:(NSControlSize)verticalScrollbar->controlSize()
1019 horizontal:NO 1011 horizontal:NO
1020 replacingScrollerImp:oldVerticalPainter]; 1012 replacingScrollerImp:oldVerticalPainter];
1021 [m_scrollbarPainterController.get() 1013 [m_scrollbarPainterController.get()
1022 setVerticalScrollerImp:newVerticalPainter]; 1014 setVerticalScrollerImp:newVerticalPainter];
1023 macTheme->setNewPainterForScrollbar(*verticalScrollbar, newVerticalPainter); 1015 macTheme->setNewPainterForScrollbar(*verticalScrollbar, newVerticalPainter);
1024 1016
1025 // The different scrollbar styles have different thicknesses, so we must 1017 // The different scrollbar styles have different thicknesses, so we must re- set the
1026 // re-set the frameRect to the new thickness, and the re-layout below will 1018 // frameRect to the new thickness, and the re-layout below will ensure the o ffset
1027 // ensure the position and length are properly updated. 1019 // and length are properly updated.
1028 int thickness = 1020 int thickness =
1029 macTheme->scrollbarThickness(verticalScrollbar->controlSize()); 1021 macTheme->scrollbarThickness(verticalScrollbar->controlSize());
1030 verticalScrollbar->setFrameRect(IntRect(0, 0, thickness, thickness)); 1022 verticalScrollbar->setFrameRect(IntRect(0, 0, thickness, thickness));
1031 } 1023 }
1032 1024
1033 if (Scrollbar* horizontalScrollbar = 1025 if (Scrollbar* horizontalScrollbar =
1034 getScrollableArea()->horizontalScrollbar()) { 1026 getScrollableArea()->horizontalScrollbar()) {
1035 horizontalScrollbar->setNeedsPaintInvalidation(AllParts); 1027 horizontalScrollbar->setNeedsPaintInvalidation(AllParts);
1036 1028
1037 ScrollbarPainter oldHorizontalPainter = 1029 ScrollbarPainter oldHorizontalPainter =
1038 [m_scrollbarPainterController.get() horizontalScrollerImp]; 1030 [m_scrollbarPainterController.get() horizontalScrollerImp];
1039 ScrollbarPainter newHorizontalPainter = [NSClassFromString(@"NSScrollerImp") 1031 ScrollbarPainter newHorizontalPainter = [NSClassFromString(@"NSScrollerImp")
1040 scrollerImpWithStyle:newStyle 1032 scrollerImpWithStyle:newStyle
1041 controlSize:(NSControlSize)horizontalScrollbar->controlSize() 1033 controlSize:(NSControlSize)horizontalScrollbar->controlSize()
1042 horizontal:YES 1034 horizontal:YES
1043 replacingScrollerImp:oldHorizontalPainter]; 1035 replacingScrollerImp:oldHorizontalPainter];
1044 [m_scrollbarPainterController.get() 1036 [m_scrollbarPainterController.get()
1045 setHorizontalScrollerImp:newHorizontalPainter]; 1037 setHorizontalScrollerImp:newHorizontalPainter];
1046 macTheme->setNewPainterForScrollbar(*horizontalScrollbar, 1038 macTheme->setNewPainterForScrollbar(*horizontalScrollbar,
1047 newHorizontalPainter); 1039 newHorizontalPainter);
1048 1040
1049 // The different scrollbar styles have different thicknesses, so we must 1041 // The different scrollbar styles have different thicknesses, so we must re- set the
1050 // re-set the frameRect to the new thickness, and the re-layout below will 1042 // frameRect to the new thickness, and the re-layout below will ensure the o ffset
1051 // ensure the position and length are properly updated. 1043 // and length are properly updated.
1052 int thickness = 1044 int thickness =
1053 macTheme->scrollbarThickness(horizontalScrollbar->controlSize()); 1045 macTheme->scrollbarThickness(horizontalScrollbar->controlSize());
1054 horizontalScrollbar->setFrameRect(IntRect(0, 0, thickness, thickness)); 1046 horizontalScrollbar->setFrameRect(IntRect(0, 0, thickness, thickness));
1055 } 1047 }
1056 1048
1057 // If m_needsScrollerStyleUpdate is true, then the page is restoring from the 1049 // If m_needsScrollerStyleUpdate is true, then the page is restoring from the page cache, and
1058 // page cache, and a relayout will happen on its own. Otherwise, we must 1050 // a relayout will happen on its own. Otherwise, we must initiate a re-layout ourselves.
1059 // initiate a re-layout ourselves.
1060 if (!m_needsScrollerStyleUpdate) 1051 if (!m_needsScrollerStyleUpdate)
1061 getScrollableArea()->scrollbarStyleChanged(); 1052 getScrollableArea()->scrollbarStyleChanged();
1062 1053
1063 m_needsScrollerStyleUpdate = false; 1054 m_needsScrollerStyleUpdate = false;
1064 } 1055 }
1065 1056
1066 void ScrollAnimatorMac::startScrollbarPaintTimer() { 1057 void ScrollAnimatorMac::startScrollbarPaintTimer() {
1067 m_taskRunner->postDelayedTask( 1058 m_taskRunner->postDelayedTask(
1068 BLINK_FROM_HERE, m_initialScrollbarPaintTaskFactory->cancelAndCreate(), 1059 BLINK_FROM_HERE, m_initialScrollbarPaintTaskFactory->cancelAndCreate(),
1069 0.1); 1060 0.1);
1070 } 1061 }
1071 1062
1072 bool ScrollAnimatorMac::scrollbarPaintTimerIsActive() const { 1063 bool ScrollAnimatorMac::scrollbarPaintTimerIsActive() const {
1073 return m_initialScrollbarPaintTaskFactory->isPending(); 1064 return m_initialScrollbarPaintTaskFactory->isPending();
1074 } 1065 }
1075 1066
1076 void ScrollAnimatorMac::stopScrollbarPaintTimer() { 1067 void ScrollAnimatorMac::stopScrollbarPaintTimer() {
1077 m_initialScrollbarPaintTaskFactory->cancel(); 1068 m_initialScrollbarPaintTaskFactory->cancel();
1078 } 1069 }
1079 1070
1080 void ScrollAnimatorMac::initialScrollbarPaintTask() { 1071 void ScrollAnimatorMac::initialScrollbarPaintTask() {
1081 // To force the scrollbars to flash, we have to call hide first. Otherwise, 1072 // To force the scrollbars to flash, we have to call hide first. Otherwise, th e ScrollbarPainterController
1082 // the ScrollbarPainterController might think that the scrollbars are already 1073 // might think that the scrollbars are already showing and bail early.
1083 // showing and bail early.
1084 [m_scrollbarPainterController.get() hideOverlayScrollers]; 1074 [m_scrollbarPainterController.get() hideOverlayScrollers];
1085 [m_scrollbarPainterController.get() flashScrollers]; 1075 [m_scrollbarPainterController.get() flashScrollers];
1086 } 1076 }
1087 1077
1088 void ScrollAnimatorMac::sendContentAreaScrolledSoon(const FloatSize& delta) { 1078 void ScrollAnimatorMac::sendContentAreaScrolledSoon(const ScrollOffset& delta) {
1089 m_contentAreaScrolledTimerScrollDelta = delta; 1079 m_contentAreaScrolledTimerScrollDelta = delta;
1090 1080
1091 if (!m_sendContentAreaScrolledTaskFactory->isPending()) 1081 if (!m_sendContentAreaScrolledTaskFactory->isPending())
1092 m_taskRunner->postTask( 1082 m_taskRunner->postTask(
1093 BLINK_FROM_HERE, 1083 BLINK_FROM_HERE,
1094 m_sendContentAreaScrolledTaskFactory->cancelAndCreate()); 1084 m_sendContentAreaScrolledTaskFactory->cancelAndCreate());
1095 } 1085 }
1096 1086
1097 void ScrollAnimatorMac::sendContentAreaScrolledTask() { 1087 void ScrollAnimatorMac::sendContentAreaScrolledTask() {
1098 if (supportsContentAreaScrolledInDirection()) { 1088 if (supportsContentAreaScrolledInDirection()) {
1099 [m_scrollbarPainterController.get() 1089 [m_scrollbarPainterController.get()
1100 contentAreaScrolledInDirection:NSMakePoint( 1090 contentAreaScrolledInDirection:NSMakePoint(
1101 m_contentAreaScrolledTimerScrollDelta 1091 m_contentAreaScrolledTimerScrollDelta
1102 .width(), 1092 .width(),
1103 m_contentAreaScrolledTimerScrollDelta 1093 m_contentAreaScrolledTimerScrollDelta
1104 .height())]; 1094 .height())];
1105 m_contentAreaScrolledTimerScrollDelta = FloatSize(); 1095 m_contentAreaScrolledTimerScrollDelta = ScrollOffset();
1106 } else 1096 } else
1107 [m_scrollbarPainterController.get() contentAreaScrolled]; 1097 [m_scrollbarPainterController.get() contentAreaScrolled];
1108 } 1098 }
1109 1099
1110 void ScrollAnimatorMac::setVisibleScrollerThumbRect( 1100 void ScrollAnimatorMac::setVisibleScrollerThumbRect(
1111 const IntRect& scrollerThumb) { 1101 const IntRect& scrollerThumb) {
1112 IntRect rectInViewCoordinates = scrollerThumb; 1102 IntRect rectInViewCoordinates = scrollerThumb;
1113 if (Scrollbar* verticalScrollbar = m_scrollableArea->verticalScrollbar()) 1103 if (Scrollbar* verticalScrollbar = m_scrollableArea->verticalScrollbar())
1114 rectInViewCoordinates = 1104 rectInViewCoordinates =
1115 verticalScrollbar->convertToContainingWidget(scrollerThumb); 1105 verticalScrollbar->convertToContainingWidget(scrollerThumb);
1116 1106
1117 if (rectInViewCoordinates == m_visibleScrollerThumbRect) 1107 if (rectInViewCoordinates == m_visibleScrollerThumbRect)
1118 return; 1108 return;
1119 1109
1120 m_visibleScrollerThumbRect = rectInViewCoordinates; 1110 m_visibleScrollerThumbRect = rectInViewCoordinates;
1121 } 1111 }
1122 1112
1123 } // namespace blink 1113 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698