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

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

Issue 1511003003: Use refs for non-null GraphicsContext, Scrollbar, etc. in scrollbar related code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ScrollbarRemove
Patch Set: yet another mac fix Created 5 years 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 59
60 static bool supportsContentAreaScrolledInDirection() 60 static bool supportsContentAreaScrolledInDirection()
61 { 61 {
62 static bool globalSupportsContentAreaScrolledInDirection = [NSClassFromStrin g(@"NSScrollerImpPair") instancesRespondToSelector:@selector(contentAreaScrolled InDirection:)]; 62 static bool globalSupportsContentAreaScrolledInDirection = [NSClassFromStrin g(@"NSScrollerImpPair") instancesRespondToSelector:@selector(contentAreaScrolled InDirection:)];
63 return globalSupportsContentAreaScrolledInDirection; 63 return globalSupportsContentAreaScrolledInDirection;
64 } 64 }
65 65
66 static ScrollbarThemeMacOverlayAPI* macOverlayScrollbarTheme() 66 static ScrollbarThemeMacOverlayAPI* macOverlayScrollbarTheme()
67 { 67 {
68 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(ScrollbarThemeMacCommon::isOverlayA PIAvailable()); 68 RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(ScrollbarThemeMacCommon::isOverlayA PIAvailable());
69 ScrollbarTheme* scrollbarTheme = ScrollbarTheme::theme(); 69 ScrollbarTheme& scrollbarTheme = ScrollbarTheme::theme();
70 return !scrollbarTheme->isMockTheme() ? static_cast<ScrollbarThemeMacOverlay API*>(scrollbarTheme) : 0; 70 return !scrollbarTheme.isMockTheme() ? static_cast<ScrollbarThemeMacOverlayA PI*>(&scrollbarTheme) : nil;
71 } 71 }
72 72
73 static ScrollbarPainter scrollbarPainterForScrollbar(Scrollbar* scrollbar) 73 static ScrollbarPainter scrollbarPainterForScrollbar(Scrollbar& scrollbar)
74 { 74 {
75 if (ScrollbarThemeMacOverlayAPI* scrollbarTheme = macOverlayScrollbarTheme() ) 75 if (ScrollbarThemeMacOverlayAPI* scrollbarTheme = macOverlayScrollbarTheme() )
76 return scrollbarTheme->painterForScrollbar(scrollbar); 76 return scrollbarTheme->painterForScrollbar(scrollbar);
77 77
78 return nil; 78 return nil;
79 } 79 }
80 80
81 @interface NSObject (ScrollAnimationHelperDetails) 81 @interface NSObject (ScrollAnimationHelperDetails)
82 - (id)initWithDelegate:(id)delegate; 82 - (id)initWithDelegate:(id)delegate;
83 - (void)_stopRun; 83 - (void)_stopRun;
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 230
231 return _scrollableArea->lastKnownMousePosition(); 231 return _scrollableArea->lastKnownMousePosition();
232 } 232 }
233 233
234 - (NSPoint)scrollerImpPair:(id)scrollerImpPair convertContentPoint:(NSPoint)poin tInContentArea toScrollerImp:(id)scrollerImp 234 - (NSPoint)scrollerImpPair:(id)scrollerImpPair convertContentPoint:(NSPoint)poin tInContentArea toScrollerImp:(id)scrollerImp
235 { 235 {
236 236
237 if (!_scrollableArea || !scrollerImp) 237 if (!_scrollableArea || !scrollerImp)
238 return NSZeroPoint; 238 return NSZeroPoint;
239 239
240 blink::Scrollbar* scrollbar = 0; 240 blink::Scrollbar* scrollbar = nil;
241 if ([scrollerImp isHorizontal]) 241 if ([scrollerImp isHorizontal])
242 scrollbar = _scrollableArea->horizontalScrollbar(); 242 scrollbar = _scrollableArea->horizontalScrollbar();
243 else 243 else
244 scrollbar = _scrollableArea->verticalScrollbar(); 244 scrollbar = _scrollableArea->verticalScrollbar();
245 245
246 // It is possible to have a null scrollbar here since it is possible for thi s delegate 246 // It is possible to have a null scrollbar here since it is possible for thi s delegate
247 // method to be called between the moment when a scrollbar has been set to 0 and the 247 // method to be called between the moment when a scrollbar has been set to 0 and the
248 // moment when its destructor has been called. We should probably de-couple some 248 // moment when its destructor has been called. We should probably de-couple some
249 // of the clean-up work in ScrollbarThemeMac::unregisterScrollbar() to avoid this 249 // of the clean-up work in ScrollbarThemeMac::unregisterScrollbar() to avoid this
250 // issue. 250 // issue.
251 if (!scrollbar) 251 if (!scrollbar)
252 return NSZeroPoint; 252 return NSZeroPoint;
253 253
254 ASSERT(scrollerImp == scrollbarPainterForScrollbar(scrollbar)); 254 ASSERT(scrollerImp == scrollbarPainterForScrollbar(*scrollbar));
255 255
256 return scrollbar->convertFromContainingWidget(blink::IntPoint(pointInContent Area)); 256 return scrollbar->convertFromContainingWidget(blink::IntPoint(pointInContent Area));
257 } 257 }
258 258
259 - (void)scrollerImpPair:(id)scrollerImpPair setContentAreaNeedsDisplayInRect:(NS Rect)rect 259 - (void)scrollerImpPair:(id)scrollerImpPair setContentAreaNeedsDisplayInRect:(NS Rect)rect
260 { 260 {
261 if (!_scrollableArea) 261 if (!_scrollableArea)
262 return; 262 return;
263 263
264 if (!_scrollableArea->scrollbarsCanBeActive()) 264 if (!_scrollableArea->scrollbarsCanBeActive())
265 return; 265 return;
266 266
267 _scrollableArea->scrollAnimator()->contentAreaWillPaint(); 267 _scrollableArea->scrollAnimator().contentAreaWillPaint();
268 } 268 }
269 269
270 - (void)scrollerImpPair:(id)scrollerImpPair updateScrollerStyleForNewRecommended ScrollerStyle:(NSScrollerStyle)newRecommendedScrollerStyle 270 - (void)scrollerImpPair:(id)scrollerImpPair updateScrollerStyleForNewRecommended ScrollerStyle:(NSScrollerStyle)newRecommendedScrollerStyle
271 { 271 {
272 // Chrome has a single process mode which is used for testing on Mac. In tha t mode, WebKit runs on a thread in the 272 // Chrome has a single process mode which is used for testing on Mac. In tha t mode, WebKit runs on a thread in the
273 // browser process. This notification is called by the OS on the main thread in the browser process, and not on the 273 // browser process. This notification is called by the OS on the main thread in the browser process, and not on the
274 // the WebKit thread. Better to not update the style than crash. 274 // the WebKit thread. Better to not update the style than crash.
275 // http://crbug.com/126514 275 // http://crbug.com/126514
276 if (!isMainThread()) 276 if (!isMainThread())
277 return; 277 return;
278 278
279 if (!_scrollableArea) 279 if (!_scrollableArea)
280 return; 280 return;
281 281
282 [scrollerImpPair setScrollerStyle:newRecommendedScrollerStyle]; 282 [scrollerImpPair setScrollerStyle:newRecommendedScrollerStyle];
283 283
284 static_cast<ScrollAnimatorMac*>(_scrollableArea->scrollAnimator())->updateSc rollerStyle(); 284 static_cast<ScrollAnimatorMac&>(_scrollableArea->scrollAnimator()).updateScr ollerStyle();
285 } 285 }
286 286
287 @end 287 @end
288 288
289 enum FeatureToAnimate { 289 enum FeatureToAnimate {
290 ThumbAlpha, 290 ThumbAlpha,
291 TrackAlpha, 291 TrackAlpha,
292 UIStateTransition, 292 UIStateTransition,
293 ExpansionTransition 293 ExpansionTransition
294 }; 294 };
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 _startValue = startValue; 383 _startValue = startValue;
384 _endValue = endValue; 384 _endValue = endValue;
385 385
386 return self; 386 return self;
387 } 387 }
388 388
389 - (void)startAnimation 389 - (void)startAnimation
390 { 390 {
391 ASSERT(_scrollbar); 391 ASSERT(_scrollbar);
392 392
393 _scrollbarPainter = scrollbarPainterForScrollbar(_scrollbar); 393 _scrollbarPainter = scrollbarPainterForScrollbar(*_scrollbar);
394 _timer->start(); 394 _timer->start();
395 } 395 }
396 396
397 - (void)stopAnimation 397 - (void)stopAnimation
398 { 398 {
399 _timer->stop(); 399 _timer->stop();
400 } 400 }
401 401
402 - (void)setDuration:(CFTimeInterval)duration 402 - (void)setDuration:(CFTimeInterval)duration
403 { 403 {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 if (!self) 479 if (!self)
480 return nil; 480 return nil;
481 481
482 _scrollbar = scrollbar; 482 _scrollbar = scrollbar;
483 return self; 483 return self;
484 } 484 }
485 485
486 - (void)updateVisibilityImmediately:(bool)show 486 - (void)updateVisibilityImmediately:(bool)show
487 { 487 {
488 [self cancelAnimations]; 488 [self cancelAnimations];
489 [scrollbarPainterForScrollbar(_scrollbar) setKnobAlpha:(show ? 1.0 : 0.0)]; 489 [scrollbarPainterForScrollbar(*_scrollbar) setKnobAlpha:(show ? 1.0 : 0.0)];
490 } 490 }
491 491
492 - (void)cancelAnimations 492 - (void)cancelAnimations
493 { 493 {
494 BEGIN_BLOCK_OBJC_EXCEPTIONS; 494 BEGIN_BLOCK_OBJC_EXCEPTIONS;
495 [_knobAlphaAnimation.get() stopAnimation]; 495 [_knobAlphaAnimation.get() stopAnimation];
496 [_trackAlphaAnimation.get() stopAnimation]; 496 [_trackAlphaAnimation.get() stopAnimation];
497 [_uiStateTransitionAnimation.get() stopAnimation]; 497 [_uiStateTransitionAnimation.get() stopAnimation];
498 [_expansionTransitionAnimation.get() stopAnimation]; 498 [_expansionTransitionAnimation.get() stopAnimation];
499 END_BLOCK_OBJC_EXCEPTIONS; 499 END_BLOCK_OBJC_EXCEPTIONS;
500 } 500 }
501 501
502 - (ScrollAnimatorMac*)scrollAnimator 502 - (ScrollAnimatorMac&)scrollAnimator
503 { 503 {
504 return static_cast<ScrollAnimatorMac*>(_scrollbar->scrollableArea()->scrollA nimator()); 504 return static_cast<ScrollAnimatorMac&>(_scrollbar->scrollableArea()->scrollA nimator());
505 } 505 }
506 506
507 - (NSRect)convertRectToBacking:(NSRect)aRect 507 - (NSRect)convertRectToBacking:(NSRect)aRect
508 { 508 {
509 return aRect; 509 return aRect;
510 } 510 }
511 511
512 - (NSRect)convertRectFromBacking:(NSRect)aRect 512 - (NSRect)convertRectFromBacking:(NSRect)aRect
513 { 513 {
514 return aRect; 514 return aRect;
515 } 515 }
516 516
517 - (NSPoint)mouseLocationInScrollerForScrollerImp:(id)scrollerImp 517 - (NSPoint)mouseLocationInScrollerForScrollerImp:(id)scrollerImp
518 { 518 {
519 if (!_scrollbar) 519 if (!_scrollbar)
520 return NSZeroPoint; 520 return NSZeroPoint;
521 521
522 ASSERT_UNUSED(scrollerImp, scrollerImp == scrollbarPainterForScrollbar(_scro llbar)); 522 ASSERT_UNUSED(scrollerImp, scrollerImp == scrollbarPainterForScrollbar(*_scr ollbar));
523 523
524 return _scrollbar->convertFromContainingWidget(_scrollbar->scrollableArea()- >lastKnownMousePosition()); 524 return _scrollbar->convertFromContainingWidget(_scrollbar->scrollableArea()- >lastKnownMousePosition());
525 } 525 }
526 526
527 - (void)setUpAlphaAnimation:(RetainPtr<WebScrollbarPartAnimation>&)scrollbarPart Animation scrollerPainter:(ScrollbarPainter)scrollerPainter part:(blink::Scrollb arPart)part animateAlphaTo:(CGFloat)newAlpha duration:(NSTimeInterval)duration 527 - (void)setUpAlphaAnimation:(RetainPtr<WebScrollbarPartAnimation>&)scrollbarPart Animation scrollerPainter:(ScrollbarPainter)scrollerPainter part:(blink::Scrollb arPart)part animateAlphaTo:(CGFloat)newAlpha duration:(NSTimeInterval)duration
528 { 528 {
529 // If the user has scrolled the page, then the scrollbars must be animated h ere. 529 // If the user has scrolled the page, then the scrollbars must be animated h ere.
530 // This overrides the early returns. 530 // This overrides the early returns.
531 bool mustAnimate = [self scrollAnimator]->haveScrolledSincePageLoad(); 531 bool mustAnimate = [self scrollAnimator].haveScrolledSincePageLoad();
532 532
533 if ([self scrollAnimator]->scrollbarPaintTimerIsActive() && !mustAnimate) 533 if ([self scrollAnimator].scrollbarPaintTimerIsActive() && !mustAnimate)
534 return; 534 return;
535 535
536 if (_scrollbar->scrollableArea()->shouldSuspendScrollAnimations() && !mustAn imate) { 536 if (_scrollbar->scrollableArea()->shouldSuspendScrollAnimations() && !mustAn imate) {
537 [self scrollAnimator]->startScrollbarPaintTimer(); 537 [self scrollAnimator].startScrollbarPaintTimer();
538 return; 538 return;
539 } 539 }
540 540
541 // At this point, we are definitely going to animate now, so stop the timer. 541 // At this point, we are definitely going to animate now, so stop the timer.
542 [self scrollAnimator]->stopScrollbarPaintTimer(); 542 [self scrollAnimator].stopScrollbarPaintTimer();
543 543
544 // If we are currently animating, stop 544 // If we are currently animating, stop
545 if (scrollbarPartAnimation) { 545 if (scrollbarPartAnimation) {
546 [scrollbarPartAnimation.get() stopAnimation]; 546 [scrollbarPartAnimation.get() stopAnimation];
547 scrollbarPartAnimation = nullptr; 547 scrollbarPartAnimation = nullptr;
548 } 548 }
549 549
550 if (part == blink::ThumbPart && _scrollbar->orientation() == VerticalScrollb ar) { 550 if (part == blink::ThumbPart && _scrollbar->orientation() == VerticalScrollb ar) {
551 if (newAlpha == 1) { 551 if (newAlpha == 1) {
552 IntRect thumbRect = IntRect([scrollerPainter rectForPart:NSScrollerK nob]); 552 IntRect thumbRect = IntRect([scrollerPainter rectForPart:NSScrollerK nob]);
553 [self scrollAnimator]->setVisibleScrollerThumbRect(thumbRect); 553 [self scrollAnimator].setVisibleScrollerThumbRect(thumbRect);
554 } else 554 } else
555 [self scrollAnimator]->setVisibleScrollerThumbRect(IntRect()); 555 [self scrollAnimator].setVisibleScrollerThumbRect(IntRect());
556 } 556 }
557 557
558 scrollbarPartAnimation.adoptNS([[WebScrollbarPartAnimation alloc] initWithSc rollbar:_scrollbar 558 scrollbarPartAnimation.adoptNS([[WebScrollbarPartAnimation alloc] initWithSc rollbar:_scrollbar
559 featureTo Animate:part == ThumbPart ? ThumbAlpha : TrackAlpha 559 featureTo Animate:part == ThumbPart ? ThumbAlpha : TrackAlpha
560 anim ateFrom:part == ThumbPart ? [scrollerPainter knobAlpha] : [scrollerPainter track Alpha] 560 anim ateFrom:part == ThumbPart ? [scrollerPainter knobAlpha] : [scrollerPainter track Alpha]
561 an imateTo:newAlpha 561 an imateTo:newAlpha
562 d uration:duration]); 562 d uration:duration]);
563 [scrollbarPartAnimation.get() startAnimation]; 563 [scrollbarPartAnimation.get() startAnimation];
564 } 564 }
565 565
566 - (void)scrollerImp:(id)scrollerImp animateKnobAlphaTo:(CGFloat)newKnobAlpha dur ation:(NSTimeInterval)duration 566 - (void)scrollerImp:(id)scrollerImp animateKnobAlphaTo:(CGFloat)newKnobAlpha dur ation:(NSTimeInterval)duration
567 { 567 {
568 if (!_scrollbar) 568 if (!_scrollbar)
569 return; 569 return;
570 570
571 ASSERT(scrollerImp == scrollbarPainterForScrollbar(_scrollbar)); 571 ASSERT(scrollerImp == scrollbarPainterForScrollbar(*_scrollbar));
572 572
573 ScrollbarPainter scrollerPainter = (ScrollbarPainter)scrollerImp; 573 ScrollbarPainter scrollerPainter = (ScrollbarPainter)scrollerImp;
574 [self setUpAlphaAnimation:_knobAlphaAnimation scrollerPainter:scrollerPainte r part:blink::ThumbPart animateAlphaTo:newKnobAlpha duration:duration]; 574 [self setUpAlphaAnimation:_knobAlphaAnimation scrollerPainter:scrollerPainte r part:blink::ThumbPart animateAlphaTo:newKnobAlpha duration:duration];
575 } 575 }
576 576
577 - (void)scrollerImp:(id)scrollerImp animateTrackAlphaTo:(CGFloat)newTrackAlpha d uration:(NSTimeInterval)duration 577 - (void)scrollerImp:(id)scrollerImp animateTrackAlphaTo:(CGFloat)newTrackAlpha d uration:(NSTimeInterval)duration
578 { 578 {
579 if (!_scrollbar) 579 if (!_scrollbar)
580 return; 580 return;
581 581
582 ASSERT(scrollerImp == scrollbarPainterForScrollbar(_scrollbar)); 582 ASSERT(scrollerImp == scrollbarPainterForScrollbar(*_scrollbar));
583 583
584 ScrollbarPainter scrollerPainter = (ScrollbarPainter)scrollerImp; 584 ScrollbarPainter scrollerPainter = (ScrollbarPainter)scrollerImp;
585 [self setUpAlphaAnimation:_trackAlphaAnimation scrollerPainter:scrollerPaint er part:blink::BackTrackPart animateAlphaTo:newTrackAlpha duration:duration]; 585 [self setUpAlphaAnimation:_trackAlphaAnimation scrollerPainter:scrollerPaint er part:blink::BackTrackPart animateAlphaTo:newTrackAlpha duration:duration];
586 } 586 }
587 587
588 - (void)scrollerImp:(id)scrollerImp animateUIStateTransitionWithDuration:(NSTime Interval)duration 588 - (void)scrollerImp:(id)scrollerImp animateUIStateTransitionWithDuration:(NSTime Interval)duration
589 { 589 {
590 if (!_scrollbar) 590 if (!_scrollbar)
591 return; 591 return;
592 592
593 if (!supportsUIStateTransitionProgress()) 593 if (!supportsUIStateTransitionProgress())
594 return; 594 return;
595 595
596 ASSERT(scrollerImp == scrollbarPainterForScrollbar(_scrollbar)); 596 ASSERT(scrollerImp == scrollbarPainterForScrollbar(*_scrollbar));
597 597
598 ScrollbarPainter scrollbarPainter = (ScrollbarPainter)scrollerImp; 598 ScrollbarPainter scrollbarPainter = (ScrollbarPainter)scrollerImp;
599 599
600 // UIStateTransition always animates to 1. In case an animation is in progre ss this avoids a hard transition. 600 // UIStateTransition always animates to 1. In case an animation is in progre ss this avoids a hard transition.
601 [scrollbarPainter setUiStateTransitionProgress:1 - [scrollerImp uiStateTrans itionProgress]]; 601 [scrollbarPainter setUiStateTransitionProgress:1 - [scrollerImp uiStateTrans itionProgress]];
602 602
603 if (!_uiStateTransitionAnimation) 603 if (!_uiStateTransitionAnimation)
604 _uiStateTransitionAnimation.adoptNS([[WebScrollbarPartAnimation alloc] i nitWithScrollbar:_scrollbar 604 _uiStateTransitionAnimation.adoptNS([[WebScrollbarPartAnimation alloc] i nitWithScrollbar:_scrollbar
605 featureToAnimate:UIStateTransition 605 featureToAnimate:UIStateTransition
606 animateFrom:[scrollbarPainter uiStateTransitionProgress] 606 animateFrom:[scrollbarPainter uiStateTransitionProgress]
607 animateTo:1.0 607 animateTo:1.0
608 duration:duration]); 608 duration:duration]);
609 else { 609 else {
610 // If we don't need to initialize the animation, just reset the values i n case they have changed. 610 // If we don't need to initialize the animation, just reset the values i n case they have changed.
611 [_uiStateTransitionAnimation.get() setStartValue:[scrollbarPainter uiSta teTransitionProgress]]; 611 [_uiStateTransitionAnimation.get() setStartValue:[scrollbarPainter uiSta teTransitionProgress]];
612 [_uiStateTransitionAnimation.get() setEndValue:1.0]; 612 [_uiStateTransitionAnimation.get() setEndValue:1.0];
613 [_uiStateTransitionAnimation.get() setDuration:duration]; 613 [_uiStateTransitionAnimation.get() setDuration:duration];
614 } 614 }
615 [_uiStateTransitionAnimation.get() startAnimation]; 615 [_uiStateTransitionAnimation.get() startAnimation];
616 } 616 }
617 617
618 - (void)scrollerImp:(id)scrollerImp animateExpansionTransitionWithDuration:(NSTi meInterval)duration 618 - (void)scrollerImp:(id)scrollerImp animateExpansionTransitionWithDuration:(NSTi meInterval)duration
619 { 619 {
620 if (!_scrollbar) 620 if (!_scrollbar)
621 return; 621 return;
622 622
623 if (!supportsExpansionTransitionProgress()) 623 if (!supportsExpansionTransitionProgress())
624 return; 624 return;
625 625
626 ASSERT(scrollerImp == scrollbarPainterForScrollbar(_scrollbar)); 626 ASSERT(scrollerImp == scrollbarPainterForScrollbar(*_scrollbar));
627 627
628 ScrollbarPainter scrollbarPainter = (ScrollbarPainter)scrollerImp; 628 ScrollbarPainter scrollbarPainter = (ScrollbarPainter)scrollerImp;
629 629
630 // ExpansionTransition always animates to 1. In case an animation is in prog ress this avoids a hard transition. 630 // ExpansionTransition always animates to 1. In case an animation is in prog ress this avoids a hard transition.
631 [scrollbarPainter setExpansionTransitionProgress:1 - [scrollerImp expansionT ransitionProgress]]; 631 [scrollbarPainter setExpansionTransitionProgress:1 - [scrollerImp expansionT ransitionProgress]];
632 632
633 if (!_expansionTransitionAnimation) { 633 if (!_expansionTransitionAnimation) {
634 _expansionTransitionAnimation.adoptNS([[WebScrollbarPartAnimation alloc] initWithScrollbar:_scrollbar 634 _expansionTransitionAnimation.adoptNS([[WebScrollbarPartAnimation alloc] initWithScrollbar:_scrollbar
635 featureToAnimate:ExpansionTransition 635 featureToAnimate:ExpansionTransition
636 animateFrom:[scrollbarPainter expansionTransitionProgress] 636 animateFrom:[scrollbarPainter expansionTransitionProgress]
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 [m_verticalScrollbarPainterDelegate.get() invalidate]; 723 [m_verticalScrollbarPainterDelegate.get() invalidate];
724 [m_scrollAnimationHelperDelegate.get() invalidate]; 724 [m_scrollAnimationHelperDelegate.get() invalidate];
725 END_BLOCK_OBJC_EXCEPTIONS; 725 END_BLOCK_OBJC_EXCEPTIONS;
726 } 726 }
727 m_initialScrollbarPaintTimer.stop(); 727 m_initialScrollbarPaintTimer.stop();
728 m_sendContentAreaScrolledTimer.stop(); 728 m_sendContentAreaScrolledTimer.stop();
729 } 729 }
730 730
731 ScrollResultOneDimensional ScrollAnimatorMac::userScroll(ScrollbarOrientation or ientation, ScrollGranularity granularity, float step, float delta) 731 ScrollResultOneDimensional ScrollAnimatorMac::userScroll(ScrollbarOrientation or ientation, ScrollGranularity granularity, float step, float delta)
732 { 732 {
733 bool scrollAnimationEnabledForSystem = static_cast<ScrollbarThemeMacCommon*> ( 733 bool scrollAnimationEnabledForSystem = static_cast<ScrollbarThemeMacCommon&> (
734 ScrollbarTheme::theme()) 734 ScrollbarTheme::theme())
735 ->scrollAnimationEnabledForSystem (); 735 .scrollAnimationEnabledForSystem( );
736 m_haveScrolledSincePageLoad = true; 736 m_haveScrolledSincePageLoad = true;
737 737
738 if (!scrollAnimationEnabledForSystem || !m_scrollableArea->scrollAnimatorEna bled()) 738 if (!scrollAnimationEnabledForSystem || !m_scrollableArea->scrollAnimatorEna bled())
739 return ScrollAnimatorBase::userScroll(orientation, granularity, step, de lta); 739 return ScrollAnimatorBase::userScroll(orientation, granularity, step, de lta);
740 740
741 if (granularity == ScrollByPixel || granularity == ScrollByPrecisePixel) 741 if (granularity == ScrollByPixel || granularity == ScrollByPrecisePixel)
742 return ScrollAnimatorBase::userScroll(orientation, granularity, step, de lta); 742 return ScrollAnimatorBase::userScroll(orientation, granularity, step, de lta);
743 743
744 float currentPos = orientation == HorizontalScrollbar ? m_currentPosX : m_cu rrentPosY; 744 float currentPos = orientation == HorizontalScrollbar ? m_currentPosX : m_cu rrentPosY;
745 float newPos = std::max<float>(std::min<float>(currentPos + (step * delta), m_scrollableArea->maximumScrollPosition(orientation)), m_scrollableArea->minimum ScrollPosition(orientation)); 745 float newPos = std::max<float>(std::min<float>(currentPos + (step * delta), m_scrollableArea->maximumScrollPosition(orientation)), m_scrollableArea->minimum ScrollPosition(orientation));
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 } 823 }
824 824
825 void ScrollAnimatorMac::mouseMovedInContentArea() const 825 void ScrollAnimatorMac::mouseMovedInContentArea() const
826 { 826 {
827 if (!scrollableArea()->scrollbarsCanBeActive()) 827 if (!scrollableArea()->scrollbarsCanBeActive())
828 return; 828 return;
829 if (ScrollbarThemeMacCommon::isOverlayAPIAvailable()) 829 if (ScrollbarThemeMacCommon::isOverlayAPIAvailable())
830 [m_scrollbarPainterController.get() mouseMovedInContentArea]; 830 [m_scrollbarPainterController.get() mouseMovedInContentArea];
831 } 831 }
832 832
833 void ScrollAnimatorMac::mouseEnteredScrollbar(Scrollbar* scrollbar) const 833 void ScrollAnimatorMac::mouseEnteredScrollbar(Scrollbar& scrollbar) const
834 { 834 {
835 if (!scrollableArea()->scrollbarsCanBeActive()) 835 if (!scrollableArea()->scrollbarsCanBeActive())
836 return; 836 return;
837 837
838 if (ScrollbarThemeMacCommon::isOverlayAPIAvailable()) { 838 if (ScrollbarThemeMacCommon::isOverlayAPIAvailable()) {
839 if (!supportsUIStateTransitionProgress()) 839 if (!supportsUIStateTransitionProgress())
840 return; 840 return;
841 if (ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar)) 841 if (ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar))
842 [painter mouseEnteredScroller]; 842 [painter mouseEnteredScroller];
843 } 843 }
844 } 844 }
845 845
846 void ScrollAnimatorMac::mouseExitedScrollbar(Scrollbar* scrollbar) const 846 void ScrollAnimatorMac::mouseExitedScrollbar(Scrollbar& scrollbar) const
847 { 847 {
848 if (!scrollableArea()->scrollbarsCanBeActive()) 848 if (!scrollableArea()->scrollbarsCanBeActive())
849 return; 849 return;
850 850
851 if (ScrollbarThemeMacCommon::isOverlayAPIAvailable()) { 851 if (ScrollbarThemeMacCommon::isOverlayAPIAvailable()) {
852 if (!supportsUIStateTransitionProgress()) 852 if (!supportsUIStateTransitionProgress())
853 return; 853 return;
854 if (ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar)) 854 if (ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar))
855 [painter mouseExitedScroller]; 855 [painter mouseExitedScroller];
856 } 856 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 [m_scrollbarPainterController.get() contentAreaScrolled]; 923 [m_scrollbarPainterController.get() contentAreaScrolled];
924 } 924 }
925 925
926 void ScrollAnimatorMac::finishCurrentScrollAnimations() 926 void ScrollAnimatorMac::finishCurrentScrollAnimations()
927 { 927 {
928 if (ScrollbarThemeMacCommon::isOverlayAPIAvailable()) { 928 if (ScrollbarThemeMacCommon::isOverlayAPIAvailable()) {
929 [m_scrollbarPainterController.get() hideOverlayScrollers]; 929 [m_scrollbarPainterController.get() hideOverlayScrollers];
930 } 930 }
931 } 931 }
932 932
933 void ScrollAnimatorMac::didAddVerticalScrollbar(Scrollbar* scrollbar) 933 void ScrollAnimatorMac::didAddVerticalScrollbar(Scrollbar& scrollbar)
934 { 934 {
935 if (!ScrollbarThemeMacCommon::isOverlayAPIAvailable()) 935 if (!ScrollbarThemeMacCommon::isOverlayAPIAvailable())
936 return; 936 return;
937 937
938 ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar); 938 ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar);
939 if (!painter) 939 if (!painter)
940 return; 940 return;
941 941
942 ASSERT(!m_verticalScrollbarPainterDelegate); 942 ASSERT(!m_verticalScrollbarPainterDelegate);
943 m_verticalScrollbarPainterDelegate.adoptNS([[WebScrollbarPainterDelegate all oc] initWithScrollbar:scrollbar]); 943 m_verticalScrollbarPainterDelegate.adoptNS([[WebScrollbarPainterDelegate all oc] initWithScrollbar:&scrollbar]);
944 944
945 [painter setDelegate:m_verticalScrollbarPainterDelegate.get()]; 945 [painter setDelegate:m_verticalScrollbarPainterDelegate.get()];
946 [m_scrollbarPainterController.get() setVerticalScrollerImp:painter]; 946 [m_scrollbarPainterController.get() setVerticalScrollerImp:painter];
947 if (scrollableArea()->inLiveResize()) 947 if (scrollableArea()->inLiveResize())
948 [painter setKnobAlpha:1]; 948 [painter setKnobAlpha:1];
949 } 949 }
950 950
951 void ScrollAnimatorMac::willRemoveVerticalScrollbar(Scrollbar* scrollbar) 951 void ScrollAnimatorMac::willRemoveVerticalScrollbar(Scrollbar& scrollbar)
952 { 952 {
953 if (!ScrollbarThemeMacCommon::isOverlayAPIAvailable()) 953 if (!ScrollbarThemeMacCommon::isOverlayAPIAvailable())
954 return; 954 return;
955 955
956 ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar); 956 ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar);
957 if (!painter) 957 if (!painter)
958 return; 958 return;
959 959
960 ASSERT(m_verticalScrollbarPainterDelegate); 960 ASSERT(m_verticalScrollbarPainterDelegate);
961 [m_verticalScrollbarPainterDelegate.get() invalidate]; 961 [m_verticalScrollbarPainterDelegate.get() invalidate];
962 m_verticalScrollbarPainterDelegate = nullptr; 962 m_verticalScrollbarPainterDelegate = nullptr;
963 963
964 [painter setDelegate:nil]; 964 [painter setDelegate:nil];
965 [m_scrollbarPainterController.get() setVerticalScrollerImp:nil]; 965 [m_scrollbarPainterController.get() setVerticalScrollerImp:nil];
966 } 966 }
967 967
968 void ScrollAnimatorMac::didAddHorizontalScrollbar(Scrollbar* scrollbar) 968 void ScrollAnimatorMac::didAddHorizontalScrollbar(Scrollbar& scrollbar)
969 { 969 {
970 if (!ScrollbarThemeMacCommon::isOverlayAPIAvailable()) 970 if (!ScrollbarThemeMacCommon::isOverlayAPIAvailable())
971 return; 971 return;
972 972
973 ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar); 973 ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar);
974 if (!painter) 974 if (!painter)
975 return; 975 return;
976 976
977 ASSERT(!m_horizontalScrollbarPainterDelegate); 977 ASSERT(!m_horizontalScrollbarPainterDelegate);
978 m_horizontalScrollbarPainterDelegate.adoptNS([[WebScrollbarPainterDelegate a lloc] initWithScrollbar:scrollbar]); 978 m_horizontalScrollbarPainterDelegate.adoptNS([[WebScrollbarPainterDelegate a lloc] initWithScrollbar:&scrollbar]);
979 979
980 [painter setDelegate:m_horizontalScrollbarPainterDelegate.get()]; 980 [painter setDelegate:m_horizontalScrollbarPainterDelegate.get()];
981 [m_scrollbarPainterController.get() setHorizontalScrollerImp:painter]; 981 [m_scrollbarPainterController.get() setHorizontalScrollerImp:painter];
982 if (scrollableArea()->inLiveResize()) 982 if (scrollableArea()->inLiveResize())
983 [painter setKnobAlpha:1]; 983 [painter setKnobAlpha:1];
984 } 984 }
985 985
986 void ScrollAnimatorMac::willRemoveHorizontalScrollbar(Scrollbar* scrollbar) 986 void ScrollAnimatorMac::willRemoveHorizontalScrollbar(Scrollbar& scrollbar)
987 { 987 {
988 if (!ScrollbarThemeMacCommon::isOverlayAPIAvailable()) 988 if (!ScrollbarThemeMacCommon::isOverlayAPIAvailable())
989 return; 989 return;
990 990
991 ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar); 991 ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar);
992 if (!painter) 992 if (!painter)
993 return; 993 return;
994 994
995 ASSERT(m_horizontalScrollbarPainterDelegate); 995 ASSERT(m_horizontalScrollbarPainterDelegate);
996 [m_horizontalScrollbarPainterDelegate.get() invalidate]; 996 [m_horizontalScrollbarPainterDelegate.get() invalidate];
997 m_horizontalScrollbarPainterDelegate = nullptr; 997 m_horizontalScrollbarPainterDelegate = nullptr;
998 998
999 [painter setDelegate:nil]; 999 [painter setDelegate:nil];
1000 [m_scrollbarPainterController.get() setHorizontalScrollerImp:nil]; 1000 [m_scrollbarPainterController.get() setHorizontalScrollerImp:nil];
1001 } 1001 }
1002 1002
1003 bool ScrollAnimatorMac::shouldScrollbarParticipateInHitTesting(Scrollbar* scroll bar) 1003 bool ScrollAnimatorMac::shouldScrollbarParticipateInHitTesting(Scrollbar& scroll bar)
1004 { 1004 {
1005 // Non-overlay scrollbars should always participate in hit testing. 1005 // Non-overlay scrollbars should always participate in hit testing.
1006 if (ScrollbarThemeMacCommon::recommendedScrollerStyle() != NSScrollerStyleOv erlay) 1006 if (ScrollbarThemeMacCommon::recommendedScrollerStyle() != NSScrollerStyleOv erlay)
1007 return true; 1007 return true;
1008 1008
1009 if (!ScrollbarThemeMacCommon::isOverlayAPIAvailable()) 1009 if (!ScrollbarThemeMacCommon::isOverlayAPIAvailable())
1010 return true; 1010 return true;
1011 1011
1012 if (scrollbar->isAlphaLocked()) 1012 if (scrollbar.isAlphaLocked())
1013 return true; 1013 return true;
1014 1014
1015 // Overlay scrollbars should participate in hit testing whenever they are at all visible. 1015 // Overlay scrollbars should participate in hit testing whenever they are at all visible.
1016 ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar); 1016 ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar);
1017 if (!painter) 1017 if (!painter)
1018 return false; 1018 return false;
1019 return [painter knobAlpha] > 0; 1019 return [painter knobAlpha] > 0;
1020 } 1020 }
1021 1021
1022 void ScrollAnimatorMac::notifyContentAreaScrolled(const FloatSize& delta) 1022 void ScrollAnimatorMac::notifyContentAreaScrolled(const FloatSize& delta)
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 verticalScrollbar->setTrackNeedsRepaint(true); 1105 verticalScrollbar->setTrackNeedsRepaint(true);
1106 verticalScrollbar->setThumbNeedsRepaint(true); 1106 verticalScrollbar->setThumbNeedsRepaint(true);
1107 verticalScrollbar->setNeedsPaintInvalidation(); 1107 verticalScrollbar->setNeedsPaintInvalidation();
1108 1108
1109 ScrollbarPainter oldVerticalPainter = [m_scrollbarPainterController.get( ) verticalScrollerImp]; 1109 ScrollbarPainter oldVerticalPainter = [m_scrollbarPainterController.get( ) verticalScrollerImp];
1110 ScrollbarPainter newVerticalPainter = [NSClassFromString(@"NSScrollerImp ") scrollerImpWithStyle:newStyle 1110 ScrollbarPainter newVerticalPainter = [NSClassFromString(@"NSScrollerImp ") scrollerImpWithStyle:newStyle
1111 controlSize:(NSControlSize)verticalScrollbar->controlSize() 1111 controlSize:(NSControlSize)verticalScrollbar->controlSize()
1112 horizontal:NO 1112 horizontal:NO
1113 replacingScrollerImp:oldVerticalPainter]; 1113 replacingScrollerImp:oldVerticalPainter];
1114 [m_scrollbarPainterController.get() setVerticalScrollerImp:newVerticalPa inter]; 1114 [m_scrollbarPainterController.get() setVerticalScrollerImp:newVerticalPa inter];
1115 macTheme->setNewPainterForScrollbar(verticalScrollbar, newVerticalPainte r); 1115 macTheme->setNewPainterForScrollbar(*verticalScrollbar, newVerticalPaint er);
1116 1116
1117 // The different scrollbar styles have different thicknesses, so we must re-set the 1117 // The different scrollbar styles have different thicknesses, so we must re-set the
1118 // frameRect to the new thickness, and the re-layout below will ensure t he position 1118 // frameRect to the new thickness, and the re-layout below will ensure t he position
1119 // and length are properly updated. 1119 // and length are properly updated.
1120 int thickness = macTheme->scrollbarThickness(verticalScrollbar->controlS ize()); 1120 int thickness = macTheme->scrollbarThickness(verticalScrollbar->controlS ize());
1121 verticalScrollbar->setFrameRect(IntRect(0, 0, thickness, thickness)); 1121 verticalScrollbar->setFrameRect(IntRect(0, 0, thickness, thickness));
1122 } 1122 }
1123 1123
1124 if (Scrollbar* horizontalScrollbar = scrollableArea()->horizontalScrollbar() ) { 1124 if (Scrollbar* horizontalScrollbar = scrollableArea()->horizontalScrollbar() ) {
1125 horizontalScrollbar->setTrackNeedsRepaint(true); 1125 horizontalScrollbar->setTrackNeedsRepaint(true);
1126 horizontalScrollbar->setThumbNeedsRepaint(true); 1126 horizontalScrollbar->setThumbNeedsRepaint(true);
1127 horizontalScrollbar->setNeedsPaintInvalidation(); 1127 horizontalScrollbar->setNeedsPaintInvalidation();
1128 1128
1129 ScrollbarPainter oldHorizontalPainter = [m_scrollbarPainterController.ge t() horizontalScrollerImp]; 1129 ScrollbarPainter oldHorizontalPainter = [m_scrollbarPainterController.ge t() horizontalScrollerImp];
1130 ScrollbarPainter newHorizontalPainter = [NSClassFromString(@"NSScrollerI mp") scrollerImpWithStyle:newStyle 1130 ScrollbarPainter newHorizontalPainter = [NSClassFromString(@"NSScrollerI mp") scrollerImpWithStyle:newStyle
1131 controlSize:(NSControlSize)horizontalScrollbar->controlSize() 1131 controlSize:(NSControlSize)horizontalScrollbar->controlSize()
1132 horizontal:YES 1132 horizontal:YES
1133 replacingScrollerImp:oldHorizontalPainter]; 1133 replacingScrollerImp:oldHorizontalPainter];
1134 [m_scrollbarPainterController.get() setHorizontalScrollerImp:newHorizont alPainter]; 1134 [m_scrollbarPainterController.get() setHorizontalScrollerImp:newHorizont alPainter];
1135 macTheme->setNewPainterForScrollbar(horizontalScrollbar, newHorizontalPa inter); 1135 macTheme->setNewPainterForScrollbar(*horizontalScrollbar, newHorizontalP ainter);
1136 1136
1137 // The different scrollbar styles have different thicknesses, so we must re-set the 1137 // The different scrollbar styles have different thicknesses, so we must re-set the
1138 // frameRect to the new thickness, and the re-layout below will ensure t he position 1138 // frameRect to the new thickness, and the re-layout below will ensure t he position
1139 // and length are properly updated. 1139 // and length are properly updated.
1140 int thickness = macTheme->scrollbarThickness(horizontalScrollbar->contro lSize()); 1140 int thickness = macTheme->scrollbarThickness(horizontalScrollbar->contro lSize());
1141 horizontalScrollbar->setFrameRect(IntRect(0, 0, thickness, thickness)); 1141 horizontalScrollbar->setFrameRect(IntRect(0, 0, thickness, thickness));
1142 } 1142 }
1143 1143
1144 // If m_needsScrollerStyleUpdate is true, then the page is restoring from th e page cache, and 1144 // If m_needsScrollerStyleUpdate is true, then the page is restoring from th e page cache, and
1145 // a relayout will happen on its own. Otherwise, we must initiate a re-layou t ourselves. 1145 // a relayout will happen on its own. Otherwise, we must initiate a re-layou t ourselves.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 return; 1201 return;
1202 1202
1203 m_visibleScrollerThumbRect = rectInViewCoordinates; 1203 m_visibleScrollerThumbRect = rectInViewCoordinates;
1204 } 1204 }
1205 1205
1206 bool ScrollAnimatorMac::canUseCoordinatedScrollbar() { 1206 bool ScrollAnimatorMac::canUseCoordinatedScrollbar() {
1207 return ScrollbarThemeMacCommon::isOverlayAPIAvailable(); 1207 return ScrollbarThemeMacCommon::isOverlayAPIAvailable();
1208 } 1208 }
1209 1209
1210 } // namespace blink 1210 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698