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

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

Issue 1458703010: Mac: Don't repaint scrollbars every frame (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master2
Patch Set: Fix typo for real 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 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 426
427 switch (_featureToAnimate) { 427 switch (_featureToAnimate) {
428 case ThumbAlpha: 428 case ThumbAlpha:
429 [_scrollbarPainter.get() setKnobAlpha:currentValue]; 429 [_scrollbarPainter.get() setKnobAlpha:currentValue];
430 break; 430 break;
431 case TrackAlpha: 431 case TrackAlpha:
432 [_scrollbarPainter.get() setTrackAlpha:currentValue]; 432 [_scrollbarPainter.get() setTrackAlpha:currentValue];
433 break; 433 break;
434 case UIStateTransition: 434 case UIStateTransition:
435 [_scrollbarPainter.get() setUiStateTransitionProgress:currentValue]; 435 [_scrollbarPainter.get() setUiStateTransitionProgress:currentValue];
436 _scrollbar->setThumbNeedsRepaint(true);
436 break; 437 break;
437 case ExpansionTransition: 438 case ExpansionTransition:
438 [_scrollbarPainter.get() setExpansionTransitionProgress:currentValue]; 439 [_scrollbarPainter.get() setExpansionTransitionProgress:currentValue];
440 _scrollbar->setThumbNeedsRepaint(true);
439 break; 441 break;
440 } 442 }
441 443
442 _scrollbar->setNeedsPaintInvalidation(); 444 _scrollbar->setNeedsPaintInvalidation();
443 } 445 }
444 446
445 - (void)invalidate 447 - (void)invalidate
446 { 448 {
447 BEGIN_BLOCK_OBJC_EXCEPTIONS; 449 BEGIN_BLOCK_OBJC_EXCEPTIONS;
448 [self stopAnimation]; 450 [self stopAnimation];
449 END_BLOCK_OBJC_EXCEPTIONS; 451 END_BLOCK_OBJC_EXCEPTIONS;
450 _scrollbar = 0; 452 _scrollbar = 0;
451 } 453 }
452 454
453 @end 455 @end
454 456
455 @interface WebScrollbarPainterDelegate : NSObject<NSAnimationDelegate> 457 @interface WebScrollbarPainterDelegate : NSObject<NSAnimationDelegate>
456 { 458 {
457 blink::Scrollbar* _scrollbar; 459 blink::Scrollbar* _scrollbar;
458 460
459 RetainPtr<WebScrollbarPartAnimation> _knobAlphaAnimation; 461 RetainPtr<WebScrollbarPartAnimation> _knobAlphaAnimation;
460 RetainPtr<WebScrollbarPartAnimation> _trackAlphaAnimation; 462 RetainPtr<WebScrollbarPartAnimation> _trackAlphaAnimation;
461 RetainPtr<WebScrollbarPartAnimation> _uiStateTransitionAnimation; 463 RetainPtr<WebScrollbarPartAnimation> _uiStateTransitionAnimation;
462 RetainPtr<WebScrollbarPartAnimation> _expansionTransitionAnimation; 464 RetainPtr<WebScrollbarPartAnimation> _expansionTransitionAnimation;
465 BOOL _hasExpandedSinceInvisible;
463 } 466 }
464 - (id)initWithScrollbar:(blink::Scrollbar*)scrollbar; 467 - (id)initWithScrollbar:(blink::Scrollbar*)scrollbar;
465 - (void)updateVisibilityImmediately:(bool)show; 468 - (void)updateVisibilityImmediately:(bool)show;
466 - (void)cancelAnimations; 469 - (void)cancelAnimations;
467 @end 470 @end
468 471
469 @implementation WebScrollbarPainterDelegate 472 @implementation WebScrollbarPainterDelegate
470 473
471 - (id)initWithScrollbar:(blink::Scrollbar*)scrollbar 474 - (id)initWithScrollbar:(blink::Scrollbar*)scrollbar
472 { 475 {
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 // If we don't need to initialize the animation, just reset the values i n case they have changed. 638 // If we don't need to initialize the animation, just reset the values i n case they have changed.
636 [_expansionTransitionAnimation.get() setStartValue:[scrollbarPainter uiS tateTransitionProgress]]; 639 [_expansionTransitionAnimation.get() setStartValue:[scrollbarPainter uiS tateTransitionProgress]];
637 [_expansionTransitionAnimation.get() setEndValue:1.0]; 640 [_expansionTransitionAnimation.get() setEndValue:1.0];
638 [_expansionTransitionAnimation.get() setDuration:duration]; 641 [_expansionTransitionAnimation.get() setDuration:duration];
639 } 642 }
640 [_expansionTransitionAnimation.get() startAnimation]; 643 [_expansionTransitionAnimation.get() startAnimation];
641 } 644 }
642 645
643 - (void)scrollerImp:(id)scrollerImp overlayScrollerStateChangedTo:(NSUInteger)ne wOverlayScrollerState 646 - (void)scrollerImp:(id)scrollerImp overlayScrollerStateChangedTo:(NSUInteger)ne wOverlayScrollerState
644 { 647 {
648 enum {
649 NSScrollerStateInvisible = 0,
chrishtr 2015/11/24 21:15:12 Forgive my ignorance of Objective C. When is NSScr
ccameron 2015/11/25 00:23:01 That is a value of the newOverlayScrollerState par
650 NSScrollerStateKnob = 1,
651 NSScrollerStateExpanded = 2
652 };
653 // We do not receive notifications about the thumb un-expanding when the scr ollbar fades away. Ensure
654 // that we re-paint the thumb the next time that we transition away from bei ng invisible, so that
655 // the thumb doesn't stick in an expanded state.
656 if (newOverlayScrollerState == NSScrollerStateExpanded) {
657 _hasExpandedSinceInvisible = YES;
658 } else if (newOverlayScrollerState != NSScrollerStateInvisible && _hasExpand edSinceInvisible) {
659 _scrollbar->setThumbNeedsRepaint(true);
660 _hasExpandedSinceInvisible = NO;
661 }
645 } 662 }
646 663
647 - (void)invalidate 664 - (void)invalidate
648 { 665 {
649 _scrollbar = 0; 666 _scrollbar = 0;
650 BEGIN_BLOCK_OBJC_EXCEPTIONS; 667 BEGIN_BLOCK_OBJC_EXCEPTIONS;
651 [_knobAlphaAnimation.get() invalidate]; 668 [_knobAlphaAnimation.get() invalidate];
652 [_trackAlphaAnimation.get() invalidate]; 669 [_trackAlphaAnimation.get() invalidate];
653 [_uiStateTransitionAnimation.get() invalidate]; 670 [_uiStateTransitionAnimation.get() invalidate];
654 [_expansionTransitionAnimation.get() invalidate]; 671 [_expansionTransitionAnimation.get() invalidate];
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 void ScrollAnimatorMac::mouseMovedInContentArea() const 809 void ScrollAnimatorMac::mouseMovedInContentArea() const
793 { 810 {
794 if (!scrollableArea()->scrollbarsCanBeActive()) 811 if (!scrollableArea()->scrollbarsCanBeActive())
795 return; 812 return;
796 if (ScrollbarThemeMacCommon::isOverlayAPIAvailable()) 813 if (ScrollbarThemeMacCommon::isOverlayAPIAvailable())
797 [m_scrollbarPainterController.get() mouseMovedInContentArea]; 814 [m_scrollbarPainterController.get() mouseMovedInContentArea];
798 } 815 }
799 816
800 void ScrollAnimatorMac::mouseEnteredScrollbar(Scrollbar* scrollbar) const 817 void ScrollAnimatorMac::mouseEnteredScrollbar(Scrollbar* scrollbar) const
801 { 818 {
802 // At this time, only legacy scrollbars needs to send notifications here.
803 if (ScrollbarThemeMacCommon::recommendedScrollerStyle() != NSScrollerStyleLe gacy)
chrishtr 2015/11/24 21:15:12 What do the changes here and on line 819 do?
ccameron 2015/11/25 00:23:02 I set the wrong upstream branch -- this is part of
804 return;
805
806 if (!scrollableArea()->scrollbarsCanBeActive()) 819 if (!scrollableArea()->scrollbarsCanBeActive())
807 return; 820 return;
808 821
809 if (ScrollbarThemeMacCommon::isOverlayAPIAvailable()) { 822 if (ScrollbarThemeMacCommon::isOverlayAPIAvailable()) {
810 if (!supportsUIStateTransitionProgress()) 823 if (!supportsUIStateTransitionProgress())
811 return; 824 return;
812 if (ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar)) 825 if (ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar))
813 [painter mouseEnteredScroller]; 826 [painter mouseEnteredScroller];
814 } 827 }
815 } 828 }
816 829
817 void ScrollAnimatorMac::mouseExitedScrollbar(Scrollbar* scrollbar) const 830 void ScrollAnimatorMac::mouseExitedScrollbar(Scrollbar* scrollbar) const
818 { 831 {
819 // At this time, only legacy scrollbars needs to send notifications here.
820 if (ScrollbarThemeMacCommon::recommendedScrollerStyle() != NSScrollerStyleLe gacy)
821 return;
822
823 if (!scrollableArea()->scrollbarsCanBeActive()) 832 if (!scrollableArea()->scrollbarsCanBeActive())
824 return; 833 return;
825 834
826 if (ScrollbarThemeMacCommon::isOverlayAPIAvailable()) { 835 if (ScrollbarThemeMacCommon::isOverlayAPIAvailable()) {
827 if (!supportsUIStateTransitionProgress()) 836 if (!supportsUIStateTransitionProgress())
828 return; 837 return;
829 if (ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar)) 838 if (ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar))
830 [painter mouseExitedScroller]; 839 [painter mouseExitedScroller];
831 } 840 }
832 } 841 }
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 1079
1071 ScrollbarThemeMacOverlayAPI* macTheme = macOverlayScrollbarTheme(); 1080 ScrollbarThemeMacOverlayAPI* macTheme = macOverlayScrollbarTheme();
1072 if (!macTheme) { 1081 if (!macTheme) {
1073 m_needsScrollerStyleUpdate = false; 1082 m_needsScrollerStyleUpdate = false;
1074 return; 1083 return;
1075 } 1084 }
1076 1085
1077 NSScrollerStyle newStyle = [m_scrollbarPainterController.get() scrollerStyle ]; 1086 NSScrollerStyle newStyle = [m_scrollbarPainterController.get() scrollerStyle ];
1078 1087
1079 if (Scrollbar* verticalScrollbar = scrollableArea()->verticalScrollbar()) { 1088 if (Scrollbar* verticalScrollbar = scrollableArea()->verticalScrollbar()) {
1089 verticalScrollbar->setTrackBackgroundNeedsRepaint(true);
1090 verticalScrollbar->setThumbNeedsRepaint(true);
1080 verticalScrollbar->setNeedsPaintInvalidation(); 1091 verticalScrollbar->setNeedsPaintInvalidation();
1081 1092
1082 ScrollbarPainter oldVerticalPainter = [m_scrollbarPainterController.get( ) verticalScrollerImp]; 1093 ScrollbarPainter oldVerticalPainter = [m_scrollbarPainterController.get( ) verticalScrollerImp];
1083 ScrollbarPainter newVerticalPainter = [NSClassFromString(@"NSScrollerImp ") scrollerImpWithStyle:newStyle 1094 ScrollbarPainter newVerticalPainter = [NSClassFromString(@"NSScrollerImp ") scrollerImpWithStyle:newStyle
1084 controlSize:(NSControlSize)verticalScrollbar->controlSize() 1095 controlSize:(NSControlSize)verticalScrollbar->controlSize()
1085 horizontal:NO 1096 horizontal:NO
1086 replacingScrollerImp:oldVerticalPainter]; 1097 replacingScrollerImp:oldVerticalPainter];
1087 [m_scrollbarPainterController.get() setVerticalScrollerImp:newVerticalPa inter]; 1098 [m_scrollbarPainterController.get() setVerticalScrollerImp:newVerticalPa inter];
1088 macTheme->setNewPainterForScrollbar(verticalScrollbar, newVerticalPainte r); 1099 macTheme->setNewPainterForScrollbar(verticalScrollbar, newVerticalPainte r);
1089 1100
1090 // The different scrollbar styles have different thicknesses, so we must re-set the 1101 // The different scrollbar styles have different thicknesses, so we must re-set the
1091 // frameRect to the new thickness, and the re-layout below will ensure t he position 1102 // frameRect to the new thickness, and the re-layout below will ensure t he position
1092 // and length are properly updated. 1103 // and length are properly updated.
1093 int thickness = macTheme->scrollbarThickness(verticalScrollbar->controlS ize()); 1104 int thickness = macTheme->scrollbarThickness(verticalScrollbar->controlS ize());
1094 verticalScrollbar->setFrameRect(IntRect(0, 0, thickness, thickness)); 1105 verticalScrollbar->setFrameRect(IntRect(0, 0, thickness, thickness));
1095 } 1106 }
1096 1107
1097 if (Scrollbar* horizontalScrollbar = scrollableArea()->horizontalScrollbar() ) { 1108 if (Scrollbar* horizontalScrollbar = scrollableArea()->horizontalScrollbar() ) {
1109 horizontalScrollbar->setTrackBackgroundNeedsRepaint(true);
1110 horizontalScrollbar->setThumbNeedsRepaint(true);
1098 horizontalScrollbar->setNeedsPaintInvalidation(); 1111 horizontalScrollbar->setNeedsPaintInvalidation();
1099 1112
1100 ScrollbarPainter oldHorizontalPainter = [m_scrollbarPainterController.ge t() horizontalScrollerImp]; 1113 ScrollbarPainter oldHorizontalPainter = [m_scrollbarPainterController.ge t() horizontalScrollerImp];
1101 ScrollbarPainter newHorizontalPainter = [NSClassFromString(@"NSScrollerI mp") scrollerImpWithStyle:newStyle 1114 ScrollbarPainter newHorizontalPainter = [NSClassFromString(@"NSScrollerI mp") scrollerImpWithStyle:newStyle
1102 controlSize:(NSControlSize)horizontalScrollbar->controlSize() 1115 controlSize:(NSControlSize)horizontalScrollbar->controlSize()
1103 horizontal:YES 1116 horizontal:YES
1104 replacingScrollerImp:oldHorizontalPainter]; 1117 replacingScrollerImp:oldHorizontalPainter];
1105 [m_scrollbarPainterController.get() setHorizontalScrollerImp:newHorizont alPainter]; 1118 [m_scrollbarPainterController.get() setHorizontalScrollerImp:newHorizont alPainter];
1106 macTheme->setNewPainterForScrollbar(horizontalScrollbar, newHorizontalPa inter); 1119 macTheme->setNewPainterForScrollbar(horizontalScrollbar, newHorizontalPa inter);
1107 1120
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1172 return; 1185 return;
1173 1186
1174 m_visibleScrollerThumbRect = rectInViewCoordinates; 1187 m_visibleScrollerThumbRect = rectInViewCoordinates;
1175 } 1188 }
1176 1189
1177 bool ScrollAnimatorMac::canUseCoordinatedScrollbar() { 1190 bool ScrollAnimatorMac::canUseCoordinatedScrollbar() {
1178 return ScrollbarThemeMacCommon::isOverlayAPIAvailable(); 1191 return ScrollbarThemeMacCommon::isOverlayAPIAvailable();
1179 } 1192 }
1180 1193
1181 } // namespace blink 1194 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698