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

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: Sprinkle in some tests 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->setNeedsPaintThumb(true);
436 break; 437 break;
437 case ExpansionTransition: 438 case ExpansionTransition:
438 [_scrollbarPainter.get() setExpansionTransitionProgress:currentValue]; 439 [_scrollbarPainter.get() setExpansionTransitionProgress:currentValue];
440 _scrollbar->setNeedsPaintThumb(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,
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->setNeedsPaintThumb(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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 1079
1063 ScrollbarThemeMacOverlayAPI* macTheme = macOverlayScrollbarTheme(); 1080 ScrollbarThemeMacOverlayAPI* macTheme = macOverlayScrollbarTheme();
1064 if (!macTheme) { 1081 if (!macTheme) {
1065 m_needsScrollerStyleUpdate = false; 1082 m_needsScrollerStyleUpdate = false;
1066 return; 1083 return;
1067 } 1084 }
1068 1085
1069 NSScrollerStyle newStyle = [m_scrollbarPainterController.get() scrollerStyle ]; 1086 NSScrollerStyle newStyle = [m_scrollbarPainterController.get() scrollerStyle ];
1070 1087
1071 if (Scrollbar* verticalScrollbar = scrollableArea()->verticalScrollbar()) { 1088 if (Scrollbar* verticalScrollbar = scrollableArea()->verticalScrollbar()) {
1089 verticalScrollbar->setNeedsPaintTrack(true);
1090 verticalScrollbar->setNeedsPaintThumb(true);
1072 verticalScrollbar->setNeedsPaintInvalidation(); 1091 verticalScrollbar->setNeedsPaintInvalidation();
1073 1092
1074 ScrollbarPainter oldVerticalPainter = [m_scrollbarPainterController.get( ) verticalScrollerImp]; 1093 ScrollbarPainter oldVerticalPainter = [m_scrollbarPainterController.get( ) verticalScrollerImp];
1075 ScrollbarPainter newVerticalPainter = [NSClassFromString(@"NSScrollerImp ") scrollerImpWithStyle:newStyle 1094 ScrollbarPainter newVerticalPainter = [NSClassFromString(@"NSScrollerImp ") scrollerImpWithStyle:newStyle
1076 controlSize:(NSControlSize)verticalScrollbar->controlSize() 1095 controlSize:(NSControlSize)verticalScrollbar->controlSize()
1077 horizontal:NO 1096 horizontal:NO
1078 replacingScrollerImp:oldVerticalPainter]; 1097 replacingScrollerImp:oldVerticalPainter];
1079 [m_scrollbarPainterController.get() setVerticalScrollerImp:newVerticalPa inter]; 1098 [m_scrollbarPainterController.get() setVerticalScrollerImp:newVerticalPa inter];
1080 macTheme->setNewPainterForScrollbar(verticalScrollbar, newVerticalPainte r); 1099 macTheme->setNewPainterForScrollbar(verticalScrollbar, newVerticalPainte r);
1081 1100
1082 // 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
1083 // 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
1084 // and length are properly updated. 1103 // and length are properly updated.
1085 int thickness = macTheme->scrollbarThickness(verticalScrollbar->controlS ize()); 1104 int thickness = macTheme->scrollbarThickness(verticalScrollbar->controlS ize());
1086 verticalScrollbar->setFrameRect(IntRect(0, 0, thickness, thickness)); 1105 verticalScrollbar->setFrameRect(IntRect(0, 0, thickness, thickness));
1087 } 1106 }
1088 1107
1089 if (Scrollbar* horizontalScrollbar = scrollableArea()->horizontalScrollbar() ) { 1108 if (Scrollbar* horizontalScrollbar = scrollableArea()->horizontalScrollbar() ) {
1109 horizontalScrollbar->setNeedsPaintTrack(true);
1110 horizontalScrollbar->setNeedsPaintThumb(true);
1090 horizontalScrollbar->setNeedsPaintInvalidation(); 1111 horizontalScrollbar->setNeedsPaintInvalidation();
1091 1112
1092 ScrollbarPainter oldHorizontalPainter = [m_scrollbarPainterController.ge t() horizontalScrollerImp]; 1113 ScrollbarPainter oldHorizontalPainter = [m_scrollbarPainterController.ge t() horizontalScrollerImp];
1093 ScrollbarPainter newHorizontalPainter = [NSClassFromString(@"NSScrollerI mp") scrollerImpWithStyle:newStyle 1114 ScrollbarPainter newHorizontalPainter = [NSClassFromString(@"NSScrollerI mp") scrollerImpWithStyle:newStyle
1094 controlSize:(NSControlSize)horizontalScrollbar->controlSize() 1115 controlSize:(NSControlSize)horizontalScrollbar->controlSize()
1095 horizontal:YES 1116 horizontal:YES
1096 replacingScrollerImp:oldHorizontalPainter]; 1117 replacingScrollerImp:oldHorizontalPainter];
1097 [m_scrollbarPainterController.get() setHorizontalScrollerImp:newHorizont alPainter]; 1118 [m_scrollbarPainterController.get() setHorizontalScrollerImp:newHorizont alPainter];
1098 macTheme->setNewPainterForScrollbar(horizontalScrollbar, newHorizontalPa inter); 1119 macTheme->setNewPainterForScrollbar(horizontalScrollbar, newHorizontalPa inter);
1099 1120
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 return; 1185 return;
1165 1186
1166 m_visibleScrollerThumbRect = rectInViewCoordinates; 1187 m_visibleScrollerThumbRect = rectInViewCoordinates;
1167 } 1188 }
1168 1189
1169 bool ScrollAnimatorMac::canUseCoordinatedScrollbar() { 1190 bool ScrollAnimatorMac::canUseCoordinatedScrollbar() {
1170 return ScrollbarThemeMacCommon::isOverlayAPIAvailable(); 1191 return ScrollbarThemeMacCommon::isOverlayAPIAvailable();
1171 } 1192 }
1172 1193
1173 } // namespace blink 1194 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698