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

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

Issue 2387883002: Use float for scroll offset. (Closed)
Patch Set: 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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 } 115 }
116 116
117 - (void)invalidate { 117 - (void)invalidate {
118 _animator = 0; 118 _animator = 0;
119 } 119 }
120 120
121 - (NSRect)bounds { 121 - (NSRect)bounds {
122 if (!_animator) 122 if (!_animator)
123 return NSZeroRect; 123 return NSZeroRect;
124 124
125 blink::FloatPoint currentPosition = _animator->currentPosition(); 125 blink::ScrollOffset currentOffset = _animator->currentOffset();
126 return NSMakeRect(currentPosition.x(), currentPosition.y(), 0, 0); 126 return NSMakeRect(currentOffset.width(), currentOffset.height(), 0, 0);
127 } 127 }
128 128
129 - (void)_immediateScrollToPoint:(NSPoint)newPosition { 129 - (void)_immediateScrollToPoint:(NSPoint)newPosition {
130 if (!_animator) 130 if (!_animator)
131 return; 131 return;
132 _animator->immediateScrollToPointForScrollAnimation(newPosition); 132 _animator->immediateScrollToOffsetForScrollAnimation(
133 toScrollOffset(newPosition));
133 } 134 }
134 135
135 - (NSPoint)_pixelAlignProposedScrollPosition:(NSPoint)newOrigin { 136 - (NSPoint)_pixelAlignProposedScrollPosition:(NSPoint)newOrigin {
136 return newOrigin; 137 return newOrigin;
137 } 138 }
138 139
139 - (NSSize)convertSizeToBase:(NSSize)size { 140 - (NSSize)convertSizeToBase:(NSSize)size {
140 return abs(size); 141 return abs(size);
141 } 142 }
142 143
(...skipping 575 matching lines...) Expand 10 before | Expand all | Expand 10 after
718 [m_horizontalScrollbarPainterDelegate.get() invalidate]; 719 [m_horizontalScrollbarPainterDelegate.get() invalidate];
719 [m_verticalScrollbarPainterDelegate.get() invalidate]; 720 [m_verticalScrollbarPainterDelegate.get() invalidate];
720 [m_scrollAnimationHelperDelegate.get() invalidate]; 721 [m_scrollAnimationHelperDelegate.get() invalidate];
721 END_BLOCK_OBJC_EXCEPTIONS; 722 END_BLOCK_OBJC_EXCEPTIONS;
722 723
723 m_initialScrollbarPaintTaskFactory->cancel(); 724 m_initialScrollbarPaintTaskFactory->cancel();
724 m_sendContentAreaScrolledTaskFactory->cancel(); 725 m_sendContentAreaScrolledTaskFactory->cancel();
725 } 726 }
726 727
727 ScrollResult ScrollAnimatorMac::userScroll(ScrollGranularity granularity, 728 ScrollResult ScrollAnimatorMac::userScroll(ScrollGranularity granularity,
728 const FloatSize& delta) { 729 const ScrollOffset& delta) {
729 m_haveScrolledSincePageLoad = true; 730 m_haveScrolledSincePageLoad = true;
730 731
731 if (!m_scrollableArea->scrollAnimatorEnabled()) 732 if (!m_scrollableArea->scrollAnimatorEnabled())
732 return ScrollAnimatorBase::userScroll(granularity, delta); 733 return ScrollAnimatorBase::userScroll(granularity, delta);
733 734
734 if (granularity == ScrollByPixel || granularity == ScrollByPrecisePixel) 735 if (granularity == ScrollByPixel || granularity == ScrollByPrecisePixel)
735 return ScrollAnimatorBase::userScroll(granularity, delta); 736 return ScrollAnimatorBase::userScroll(granularity, delta);
736 737
737 FloatSize consumedDelta = computeDeltaToConsume(delta); 738 ScrollOffset consumedDelta = computeDeltaToConsume(delta);
738 FloatPoint newPos = m_currentPos + consumedDelta; 739 ScrollOffset newOffset = m_currentOffset + consumedDelta;
739 if (m_currentPos == newPos) 740 if (m_currentOffset == newOffset)
740 return ScrollResult(); 741 return ScrollResult();
741 742
742 // Prevent clobbering an existing animation on an unscrolled axis. 743 // Prevent clobbering an existing animation on an unscrolled axis.
743 if ([m_scrollAnimationHelper.get() _isAnimating]) { 744 if ([m_scrollAnimationHelper.get() _isAnimating]) {
744 NSPoint targetOrigin = [m_scrollAnimationHelper.get() targetOrigin]; 745 NSPoint targetOrigin = [m_scrollAnimationHelper.get() targetOrigin];
745 if (!delta.width()) 746 if (!delta.width())
746 newPos.setX(targetOrigin.x); 747 newOffset.setWidth(targetOrigin.x);
747 if (!delta.height()) 748 if (!delta.height())
748 newPos.setY(targetOrigin.y); 749 newOffset.setHeight(targetOrigin.y);
749 } 750 }
750 751
751 NSPoint newPoint = NSMakePoint(newPos.x(), newPos.y()); 752 NSPoint newPoint = NSMakePoint(newOffset.width(), newOffset.height());
752 [m_scrollAnimationHelper.get() scrollToPoint:newPoint]; 753 [m_scrollAnimationHelper.get() scrollToPoint:newPoint];
753 754
754 // TODO(bokan): This has different semantics on ScrollResult than ScrollAnimat or, 755 // TODO(bokan): This has different semantics on ScrollResult than ScrollAnimat or,
755 // which only returns unused delta if there's no animation and we don't start one. 756 // which only returns unused delta if there's no animation and we don't start one.
756 return ScrollResult(consumedDelta.width(), consumedDelta.height(), 757 return ScrollResult(consumedDelta.width(), consumedDelta.height(),
757 delta.width() - consumedDelta.width(), 758 delta.width() - consumedDelta.width(),
758 delta.height() - consumedDelta.height()); 759 delta.height() - consumedDelta.height());
759 } 760 }
760 761
761 void ScrollAnimatorMac::scrollToOffsetWithoutAnimation( 762 void ScrollAnimatorMac::scrollToOffsetWithoutAnimation(
762 const FloatPoint& offset) { 763 const ScrollOffset& offset) {
763 [m_scrollAnimationHelper.get() _stopRun]; 764 [m_scrollAnimationHelper.get() _stopRun];
764 immediateScrollTo(offset); 765 immediateScrollTo(offset);
765 } 766 }
766 767
767 FloatPoint ScrollAnimatorMac::adjustScrollPositionIfNecessary( 768 ScrollOffset ScrollAnimatorMac::adjustScrollOffsetIfNecessary(
768 const FloatPoint& position) const { 769 const ScrollOffset& offset) const {
769 IntPoint minPos = m_scrollableArea->minimumScrollPosition(); 770 ScrollOffset minOffset = m_scrollableArea->minimumScrollOffset();
770 IntPoint maxPos = m_scrollableArea->maximumScrollPosition(); 771 ScrollOffset maxOffset = m_scrollableArea->maximumScrollOffset();
771 772
772 float newX = clampTo<float, float>(position.x(), minPos.x(), maxPos.x()); 773 float newX = clampTo<float, float>(offset.width(), minOffset.width(),
773 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());
774 777
775 return FloatPoint(newX, newY); 778 return ScrollOffset(newX, newY);
776 } 779 }
777 780
778 void ScrollAnimatorMac::immediateScrollTo(const FloatPoint& newPosition) { 781 void ScrollAnimatorMac::immediateScrollTo(const ScrollOffset& newOffset) {
779 FloatPoint adjustedPosition = adjustScrollPositionIfNecessary(newPosition); 782 ScrollOffset adjustedOffset = adjustScrollOffsetIfNecessary(newOffset);
780 783
781 bool positionChanged = adjustedPosition != m_currentPos; 784 bool offsetChanged = adjustedOffset != m_currentOffset;
782 if (!positionChanged && !getScrollableArea()->scrollOriginChanged()) 785 if (!offsetChanged && !getScrollableArea()->scrollOriginChanged())
783 return; 786 return;
784 787
785 FloatSize delta = adjustedPosition - m_currentPos; 788 ScrollOffset delta = adjustedOffset - m_currentOffset;
786 789
787 m_currentPos = adjustedPosition; 790 m_currentOffset = adjustedOffset;
788 notifyContentAreaScrolled(delta); 791 notifyContentAreaScrolled(delta);
789 notifyPositionChanged(); 792 notifyOffsetChanged();
790 } 793 }
791 794
792 void ScrollAnimatorMac::immediateScrollToPointForScrollAnimation( 795 void ScrollAnimatorMac::immediateScrollToOffsetForScrollAnimation(
793 const FloatPoint& newPosition) { 796 const ScrollOffset& newOffset) {
794 ASSERT(m_scrollAnimationHelper); 797 ASSERT(m_scrollAnimationHelper);
795 immediateScrollTo(newPosition); 798 immediateScrollTo(newOffset);
796 } 799 }
797 800
798 void ScrollAnimatorMac::contentAreaWillPaint() const { 801 void ScrollAnimatorMac::contentAreaWillPaint() const {
799 if (!getScrollableArea()->scrollbarsCanBeActive()) 802 if (!getScrollableArea()->scrollbarsCanBeActive())
800 return; 803 return;
801 [m_scrollbarPainterController.get() contentAreaWillDraw]; 804 [m_scrollbarPainterController.get() contentAreaWillDraw];
802 } 805 }
803 806
804 void ScrollAnimatorMac::mouseEnteredContentArea() const { 807 void ScrollAnimatorMac::mouseEnteredContentArea() const {
805 if (!getScrollableArea()->scrollbarsCanBeActive()) 808 if (!getScrollableArea()->scrollbarsCanBeActive())
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 if (ScrollbarThemeMac::recommendedScrollerStyle() != NSScrollerStyleOverlay) 941 if (ScrollbarThemeMac::recommendedScrollerStyle() != NSScrollerStyleOverlay)
939 return true; 942 return true;
940 943
941 // Overlay scrollbars should participate in hit testing whenever they are at a ll visible. 944 // Overlay scrollbars should participate in hit testing whenever they are at a ll visible.
942 ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar); 945 ScrollbarPainter painter = scrollbarPainterForScrollbar(scrollbar);
943 if (!painter) 946 if (!painter)
944 return false; 947 return false;
945 return [painter knobAlpha] > 0; 948 return [painter knobAlpha] > 0;
946 } 949 }
947 950
948 void ScrollAnimatorMac::notifyContentAreaScrolled(const FloatSize& delta) { 951 void ScrollAnimatorMac::notifyContentAreaScrolled(const ScrollOffset& delta) {
949 // This function is called when a page is going into the page cache, but the p age 952 // This function is called when a page is going into the page cache, but the p age
950 // isn't really scrolling in that case. We should only pass the message on to the 953 // isn't really scrolling in that case. We should only pass the message on to the
951 // ScrollbarPainterController when we're really scrolling on an active page. 954 // ScrollbarPainterController when we're really scrolling on an active page.
952 if (getScrollableArea()->scrollbarsCanBeActive()) 955 if (getScrollableArea()->scrollbarsCanBeActive())
953 sendContentAreaScrolledSoon(delta); 956 sendContentAreaScrolledSoon(delta);
954 } 957 }
955 958
956 bool ScrollAnimatorMac::setScrollbarsVisibleForTesting(bool show) { 959 bool ScrollAnimatorMac::setScrollbarsVisibleForTesting(bool show) {
957 if (show) 960 if (show)
958 [m_scrollbarPainterController.get() flashScrollers]; 961 [m_scrollbarPainterController.get() flashScrollers];
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 ScrollbarPainter newVerticalPainter = [NSClassFromString(@"NSScrollerImp") 1008 ScrollbarPainter newVerticalPainter = [NSClassFromString(@"NSScrollerImp")
1006 scrollerImpWithStyle:newStyle 1009 scrollerImpWithStyle:newStyle
1007 controlSize:(NSControlSize)verticalScrollbar->controlSize() 1010 controlSize:(NSControlSize)verticalScrollbar->controlSize()
1008 horizontal:NO 1011 horizontal:NO
1009 replacingScrollerImp:oldVerticalPainter]; 1012 replacingScrollerImp:oldVerticalPainter];
1010 [m_scrollbarPainterController.get() 1013 [m_scrollbarPainterController.get()
1011 setVerticalScrollerImp:newVerticalPainter]; 1014 setVerticalScrollerImp:newVerticalPainter];
1012 macTheme->setNewPainterForScrollbar(*verticalScrollbar, newVerticalPainter); 1015 macTheme->setNewPainterForScrollbar(*verticalScrollbar, newVerticalPainter);
1013 1016
1014 // The different scrollbar styles have different thicknesses, so we must re- set the 1017 // The different scrollbar styles have different thicknesses, so we must re- set the
1015 // frameRect to the new thickness, and the re-layout below will ensure the p osition 1018 // frameRect to the new thickness, and the re-layout below will ensure the o ffset
1016 // and length are properly updated. 1019 // and length are properly updated.
1017 int thickness = 1020 int thickness =
1018 macTheme->scrollbarThickness(verticalScrollbar->controlSize()); 1021 macTheme->scrollbarThickness(verticalScrollbar->controlSize());
1019 verticalScrollbar->setFrameRect(IntRect(0, 0, thickness, thickness)); 1022 verticalScrollbar->setFrameRect(IntRect(0, 0, thickness, thickness));
1020 } 1023 }
1021 1024
1022 if (Scrollbar* horizontalScrollbar = 1025 if (Scrollbar* horizontalScrollbar =
1023 getScrollableArea()->horizontalScrollbar()) { 1026 getScrollableArea()->horizontalScrollbar()) {
1024 horizontalScrollbar->setNeedsPaintInvalidation(AllParts); 1027 horizontalScrollbar->setNeedsPaintInvalidation(AllParts);
1025 1028
1026 ScrollbarPainter oldHorizontalPainter = 1029 ScrollbarPainter oldHorizontalPainter =
1027 [m_scrollbarPainterController.get() horizontalScrollerImp]; 1030 [m_scrollbarPainterController.get() horizontalScrollerImp];
1028 ScrollbarPainter newHorizontalPainter = [NSClassFromString(@"NSScrollerImp") 1031 ScrollbarPainter newHorizontalPainter = [NSClassFromString(@"NSScrollerImp")
1029 scrollerImpWithStyle:newStyle 1032 scrollerImpWithStyle:newStyle
1030 controlSize:(NSControlSize)horizontalScrollbar->controlSize() 1033 controlSize:(NSControlSize)horizontalScrollbar->controlSize()
1031 horizontal:YES 1034 horizontal:YES
1032 replacingScrollerImp:oldHorizontalPainter]; 1035 replacingScrollerImp:oldHorizontalPainter];
1033 [m_scrollbarPainterController.get() 1036 [m_scrollbarPainterController.get()
1034 setHorizontalScrollerImp:newHorizontalPainter]; 1037 setHorizontalScrollerImp:newHorizontalPainter];
1035 macTheme->setNewPainterForScrollbar(*horizontalScrollbar, 1038 macTheme->setNewPainterForScrollbar(*horizontalScrollbar,
1036 newHorizontalPainter); 1039 newHorizontalPainter);
1037 1040
1038 // The different scrollbar styles have different thicknesses, so we must re- set the 1041 // The different scrollbar styles have different thicknesses, so we must re- set the
1039 // frameRect to the new thickness, and the re-layout below will ensure the p osition 1042 // frameRect to the new thickness, and the re-layout below will ensure the o ffset
1040 // and length are properly updated. 1043 // and length are properly updated.
1041 int thickness = 1044 int thickness =
1042 macTheme->scrollbarThickness(horizontalScrollbar->controlSize()); 1045 macTheme->scrollbarThickness(horizontalScrollbar->controlSize());
1043 horizontalScrollbar->setFrameRect(IntRect(0, 0, thickness, thickness)); 1046 horizontalScrollbar->setFrameRect(IntRect(0, 0, thickness, thickness));
1044 } 1047 }
1045 1048
1046 // If m_needsScrollerStyleUpdate is true, then the page is restoring from the page cache, and 1049 // If m_needsScrollerStyleUpdate is true, then the page is restoring from the page cache, and
1047 // a relayout will happen on its own. Otherwise, we must initiate a re-layout ourselves. 1050 // a relayout will happen on its own. Otherwise, we must initiate a re-layout ourselves.
1048 if (!m_needsScrollerStyleUpdate) 1051 if (!m_needsScrollerStyleUpdate)
1049 getScrollableArea()->scrollbarStyleChanged(); 1052 getScrollableArea()->scrollbarStyleChanged();
(...skipping 15 matching lines...) Expand all
1065 m_initialScrollbarPaintTaskFactory->cancel(); 1068 m_initialScrollbarPaintTaskFactory->cancel();
1066 } 1069 }
1067 1070
1068 void ScrollAnimatorMac::initialScrollbarPaintTask() { 1071 void ScrollAnimatorMac::initialScrollbarPaintTask() {
1069 // To force the scrollbars to flash, we have to call hide first. Otherwise, th e ScrollbarPainterController 1072 // To force the scrollbars to flash, we have to call hide first. Otherwise, th e ScrollbarPainterController
1070 // might think that the scrollbars are already showing and bail early. 1073 // might think that the scrollbars are already showing and bail early.
1071 [m_scrollbarPainterController.get() hideOverlayScrollers]; 1074 [m_scrollbarPainterController.get() hideOverlayScrollers];
1072 [m_scrollbarPainterController.get() flashScrollers]; 1075 [m_scrollbarPainterController.get() flashScrollers];
1073 } 1076 }
1074 1077
1075 void ScrollAnimatorMac::sendContentAreaScrolledSoon(const FloatSize& delta) { 1078 void ScrollAnimatorMac::sendContentAreaScrolledSoon(const ScrollOffset& delta) {
1076 m_contentAreaScrolledTimerScrollDelta = delta; 1079 m_contentAreaScrolledTimerScrollDelta = delta;
1077 1080
1078 if (!m_sendContentAreaScrolledTaskFactory->isPending()) 1081 if (!m_sendContentAreaScrolledTaskFactory->isPending())
1079 m_taskRunner->postTask( 1082 m_taskRunner->postTask(
1080 BLINK_FROM_HERE, 1083 BLINK_FROM_HERE,
1081 m_sendContentAreaScrolledTaskFactory->cancelAndCreate()); 1084 m_sendContentAreaScrolledTaskFactory->cancelAndCreate());
1082 } 1085 }
1083 1086
1084 void ScrollAnimatorMac::sendContentAreaScrolledTask() { 1087 void ScrollAnimatorMac::sendContentAreaScrolledTask() {
1085 if (supportsContentAreaScrolledInDirection()) { 1088 if (supportsContentAreaScrolledInDirection()) {
1086 [m_scrollbarPainterController.get() 1089 [m_scrollbarPainterController.get()
1087 contentAreaScrolledInDirection:NSMakePoint( 1090 contentAreaScrolledInDirection:NSMakePoint(
1088 m_contentAreaScrolledTimerScrollDelta 1091 m_contentAreaScrolledTimerScrollDelta
1089 .width(), 1092 .width(),
1090 m_contentAreaScrolledTimerScrollDelta 1093 m_contentAreaScrolledTimerScrollDelta
1091 .height())]; 1094 .height())];
1092 m_contentAreaScrolledTimerScrollDelta = FloatSize(); 1095 m_contentAreaScrolledTimerScrollDelta = ScrollOffset();
1093 } else 1096 } else
1094 [m_scrollbarPainterController.get() contentAreaScrolled]; 1097 [m_scrollbarPainterController.get() contentAreaScrolled];
1095 } 1098 }
1096 1099
1097 void ScrollAnimatorMac::setVisibleScrollerThumbRect( 1100 void ScrollAnimatorMac::setVisibleScrollerThumbRect(
1098 const IntRect& scrollerThumb) { 1101 const IntRect& scrollerThumb) {
1099 IntRect rectInViewCoordinates = scrollerThumb; 1102 IntRect rectInViewCoordinates = scrollerThumb;
1100 if (Scrollbar* verticalScrollbar = m_scrollableArea->verticalScrollbar()) 1103 if (Scrollbar* verticalScrollbar = m_scrollableArea->verticalScrollbar())
1101 rectInViewCoordinates = 1104 rectInViewCoordinates =
1102 verticalScrollbar->convertToContainingWidget(scrollerThumb); 1105 verticalScrollbar->convertToContainingWidget(scrollerThumb);
1103 1106
1104 if (rectInViewCoordinates == m_visibleScrollerThumbRect) 1107 if (rectInViewCoordinates == m_visibleScrollerThumbRect)
1105 return; 1108 return;
1106 1109
1107 m_visibleScrollerThumbRect = rectInViewCoordinates; 1110 m_visibleScrollerThumbRect = rectInViewCoordinates;
1108 } 1111 }
1109 1112
1110 } // namespace blink 1113 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698