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

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: Remove track opacity 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 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 currentValue = 1 - progress; 423 currentValue = 1 - progress;
424 else 424 else
425 currentValue = progress; 425 currentValue = progress;
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 _scrollbar->setTrackNeedsRepaint(true);
433 break; 434 break;
434 case UIStateTransition: 435 case UIStateTransition:
435 [_scrollbarPainter.get() setUiStateTransitionProgress:currentValue]; 436 [_scrollbarPainter.get() setUiStateTransitionProgress:currentValue];
437 _scrollbar->setThumbNeedsRepaint(true);
438 _scrollbar->setTrackNeedsRepaint(true);
436 break; 439 break;
437 case ExpansionTransition: 440 case ExpansionTransition:
438 [_scrollbarPainter.get() setExpansionTransitionProgress:currentValue]; 441 [_scrollbarPainter.get() setExpansionTransitionProgress:currentValue];
442 _scrollbar->setThumbNeedsRepaint(true);
439 break; 443 break;
440 } 444 }
441 445
442 _scrollbar->setNeedsPaintInvalidation(); 446 _scrollbar->setNeedsPaintInvalidation();
443 } 447 }
444 448
445 - (void)invalidate 449 - (void)invalidate
446 { 450 {
447 BEGIN_BLOCK_OBJC_EXCEPTIONS; 451 BEGIN_BLOCK_OBJC_EXCEPTIONS;
448 [self stopAnimation]; 452 [self stopAnimation];
449 END_BLOCK_OBJC_EXCEPTIONS; 453 END_BLOCK_OBJC_EXCEPTIONS;
450 _scrollbar = 0; 454 _scrollbar = 0;
451 } 455 }
452 456
453 @end 457 @end
454 458
455 @interface WebScrollbarPainterDelegate : NSObject<NSAnimationDelegate> 459 @interface WebScrollbarPainterDelegate : NSObject<NSAnimationDelegate>
456 { 460 {
457 blink::Scrollbar* _scrollbar; 461 blink::Scrollbar* _scrollbar;
458 462
459 RetainPtr<WebScrollbarPartAnimation> _knobAlphaAnimation; 463 RetainPtr<WebScrollbarPartAnimation> _knobAlphaAnimation;
460 RetainPtr<WebScrollbarPartAnimation> _trackAlphaAnimation; 464 RetainPtr<WebScrollbarPartAnimation> _trackAlphaAnimation;
461 RetainPtr<WebScrollbarPartAnimation> _uiStateTransitionAnimation; 465 RetainPtr<WebScrollbarPartAnimation> _uiStateTransitionAnimation;
462 RetainPtr<WebScrollbarPartAnimation> _expansionTransitionAnimation; 466 RetainPtr<WebScrollbarPartAnimation> _expansionTransitionAnimation;
467 BOOL _hasExpandedSinceInvisible;
463 } 468 }
464 - (id)initWithScrollbar:(blink::Scrollbar*)scrollbar; 469 - (id)initWithScrollbar:(blink::Scrollbar*)scrollbar;
465 - (void)updateVisibilityImmediately:(bool)show; 470 - (void)updateVisibilityImmediately:(bool)show;
466 - (void)cancelAnimations; 471 - (void)cancelAnimations;
467 @end 472 @end
468 473
469 @implementation WebScrollbarPainterDelegate 474 @implementation WebScrollbarPainterDelegate
470 475
471 - (id)initWithScrollbar:(blink::Scrollbar*)scrollbar 476 - (id)initWithScrollbar:(blink::Scrollbar*)scrollbar
472 { 477 {
(...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. 640 // 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]]; 641 [_expansionTransitionAnimation.get() setStartValue:[scrollbarPainter uiS tateTransitionProgress]];
637 [_expansionTransitionAnimation.get() setEndValue:1.0]; 642 [_expansionTransitionAnimation.get() setEndValue:1.0];
638 [_expansionTransitionAnimation.get() setDuration:duration]; 643 [_expansionTransitionAnimation.get() setDuration:duration];
639 } 644 }
640 [_expansionTransitionAnimation.get() startAnimation]; 645 [_expansionTransitionAnimation.get() startAnimation];
641 } 646 }
642 647
643 - (void)scrollerImp:(id)scrollerImp overlayScrollerStateChangedTo:(NSUInteger)ne wOverlayScrollerState 648 - (void)scrollerImp:(id)scrollerImp overlayScrollerStateChangedTo:(NSUInteger)ne wOverlayScrollerState
644 { 649 {
650 enum {
chrishtr 2015/11/25 00:28:49 Please document that these are reverse-engineered.
ccameron 2015/11/25 00:34:32 Done.
651 NSScrollerStateInvisible = 0,
652 NSScrollerStateKnob = 1,
653 NSScrollerStateExpanded = 2
654 };
655 // We do not receive notifications about the thumb un-expanding when the scr ollbar fades away. Ensure
656 // that we re-paint the thumb the next time that we transition away from bei ng invisible, so that
657 // the thumb doesn't stick in an expanded state.
658 if (newOverlayScrollerState == NSScrollerStateExpanded) {
659 _hasExpandedSinceInvisible = YES;
660 } else if (newOverlayScrollerState != NSScrollerStateInvisible && _hasExpand edSinceInvisible) {
661 _scrollbar->setThumbNeedsRepaint(true);
662 _hasExpandedSinceInvisible = NO;
663 }
645 } 664 }
646 665
647 - (void)invalidate 666 - (void)invalidate
648 { 667 {
649 _scrollbar = 0; 668 _scrollbar = 0;
650 BEGIN_BLOCK_OBJC_EXCEPTIONS; 669 BEGIN_BLOCK_OBJC_EXCEPTIONS;
651 [_knobAlphaAnimation.get() invalidate]; 670 [_knobAlphaAnimation.get() invalidate];
652 [_trackAlphaAnimation.get() invalidate]; 671 [_trackAlphaAnimation.get() invalidate];
653 [_uiStateTransitionAnimation.get() invalidate]; 672 [_uiStateTransitionAnimation.get() invalidate];
654 [_expansionTransitionAnimation.get() invalidate]; 673 [_expansionTransitionAnimation.get() invalidate];
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 1081
1063 ScrollbarThemeMacOverlayAPI* macTheme = macOverlayScrollbarTheme(); 1082 ScrollbarThemeMacOverlayAPI* macTheme = macOverlayScrollbarTheme();
1064 if (!macTheme) { 1083 if (!macTheme) {
1065 m_needsScrollerStyleUpdate = false; 1084 m_needsScrollerStyleUpdate = false;
1066 return; 1085 return;
1067 } 1086 }
1068 1087
1069 NSScrollerStyle newStyle = [m_scrollbarPainterController.get() scrollerStyle ]; 1088 NSScrollerStyle newStyle = [m_scrollbarPainterController.get() scrollerStyle ];
1070 1089
1071 if (Scrollbar* verticalScrollbar = scrollableArea()->verticalScrollbar()) { 1090 if (Scrollbar* verticalScrollbar = scrollableArea()->verticalScrollbar()) {
1091 verticalScrollbar->setTrackNeedsRepaint(true);
1092 verticalScrollbar->setThumbNeedsRepaint(true);
1072 verticalScrollbar->setNeedsPaintInvalidation(); 1093 verticalScrollbar->setNeedsPaintInvalidation();
1073 1094
1074 ScrollbarPainter oldVerticalPainter = [m_scrollbarPainterController.get( ) verticalScrollerImp]; 1095 ScrollbarPainter oldVerticalPainter = [m_scrollbarPainterController.get( ) verticalScrollerImp];
1075 ScrollbarPainter newVerticalPainter = [NSClassFromString(@"NSScrollerImp ") scrollerImpWithStyle:newStyle 1096 ScrollbarPainter newVerticalPainter = [NSClassFromString(@"NSScrollerImp ") scrollerImpWithStyle:newStyle
1076 controlSize:(NSControlSize)verticalScrollbar->controlSize() 1097 controlSize:(NSControlSize)verticalScrollbar->controlSize()
1077 horizontal:NO 1098 horizontal:NO
1078 replacingScrollerImp:oldVerticalPainter]; 1099 replacingScrollerImp:oldVerticalPainter];
1079 [m_scrollbarPainterController.get() setVerticalScrollerImp:newVerticalPa inter]; 1100 [m_scrollbarPainterController.get() setVerticalScrollerImp:newVerticalPa inter];
1080 macTheme->setNewPainterForScrollbar(verticalScrollbar, newVerticalPainte r); 1101 macTheme->setNewPainterForScrollbar(verticalScrollbar, newVerticalPainte r);
1081 1102
1082 // The different scrollbar styles have different thicknesses, so we must re-set the 1103 // 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 1104 // frameRect to the new thickness, and the re-layout below will ensure t he position
1084 // and length are properly updated. 1105 // and length are properly updated.
1085 int thickness = macTheme->scrollbarThickness(verticalScrollbar->controlS ize()); 1106 int thickness = macTheme->scrollbarThickness(verticalScrollbar->controlS ize());
1086 verticalScrollbar->setFrameRect(IntRect(0, 0, thickness, thickness)); 1107 verticalScrollbar->setFrameRect(IntRect(0, 0, thickness, thickness));
1087 } 1108 }
1088 1109
1089 if (Scrollbar* horizontalScrollbar = scrollableArea()->horizontalScrollbar() ) { 1110 if (Scrollbar* horizontalScrollbar = scrollableArea()->horizontalScrollbar() ) {
1111 horizontalScrollbar->setTrackNeedsRepaint(true);
1112 horizontalScrollbar->setThumbNeedsRepaint(true);
1090 horizontalScrollbar->setNeedsPaintInvalidation(); 1113 horizontalScrollbar->setNeedsPaintInvalidation();
1091 1114
1092 ScrollbarPainter oldHorizontalPainter = [m_scrollbarPainterController.ge t() horizontalScrollerImp]; 1115 ScrollbarPainter oldHorizontalPainter = [m_scrollbarPainterController.ge t() horizontalScrollerImp];
1093 ScrollbarPainter newHorizontalPainter = [NSClassFromString(@"NSScrollerI mp") scrollerImpWithStyle:newStyle 1116 ScrollbarPainter newHorizontalPainter = [NSClassFromString(@"NSScrollerI mp") scrollerImpWithStyle:newStyle
1094 controlSize:(NSControlSize)horizontalScrollbar->controlSize() 1117 controlSize:(NSControlSize)horizontalScrollbar->controlSize()
1095 horizontal:YES 1118 horizontal:YES
1096 replacingScrollerImp:oldHorizontalPainter]; 1119 replacingScrollerImp:oldHorizontalPainter];
1097 [m_scrollbarPainterController.get() setHorizontalScrollerImp:newHorizont alPainter]; 1120 [m_scrollbarPainterController.get() setHorizontalScrollerImp:newHorizont alPainter];
1098 macTheme->setNewPainterForScrollbar(horizontalScrollbar, newHorizontalPa inter); 1121 macTheme->setNewPainterForScrollbar(horizontalScrollbar, newHorizontalPa inter);
1099 1122
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 return; 1187 return;
1165 1188
1166 m_visibleScrollerThumbRect = rectInViewCoordinates; 1189 m_visibleScrollerThumbRect = rectInViewCoordinates;
1167 } 1190 }
1168 1191
1169 bool ScrollAnimatorMac::canUseCoordinatedScrollbar() { 1192 bool ScrollAnimatorMac::canUseCoordinatedScrollbar() {
1170 return ScrollbarThemeMacCommon::isOverlayAPIAvailable(); 1193 return ScrollbarThemeMacCommon::isOverlayAPIAvailable();
1171 } 1194 }
1172 1195
1173 } // namespace blink 1196 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698