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

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

Issue 1530723004: Use clampTo instead of chaining std::max(std::min(...)) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More rebase Created 4 years, 12 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 20 matching lines...) Expand all
31 #include "platform/animation/TimingFunction.h" 31 #include "platform/animation/TimingFunction.h"
32 #include "platform/geometry/FloatRect.h" 32 #include "platform/geometry/FloatRect.h"
33 #include "platform/geometry/IntRect.h" 33 #include "platform/geometry/IntRect.h"
34 #include "platform/mac/BlockExceptions.h" 34 #include "platform/mac/BlockExceptions.h"
35 #include "platform/mac/NSScrollerImpDetails.h" 35 #include "platform/mac/NSScrollerImpDetails.h"
36 #include "platform/scroll/ScrollableArea.h" 36 #include "platform/scroll/ScrollableArea.h"
37 #include "platform/scroll/ScrollbarTheme.h" 37 #include "platform/scroll/ScrollbarTheme.h"
38 #include "platform/scroll/ScrollbarThemeMacCommon.h" 38 #include "platform/scroll/ScrollbarThemeMacCommon.h"
39 #include "platform/scroll/ScrollbarThemeMacOverlayAPI.h" 39 #include "platform/scroll/ScrollbarThemeMacOverlayAPI.h"
40 #include "wtf/MainThread.h" 40 #include "wtf/MainThread.h"
41 #include "wtf/MathExtras.h"
41 #include "wtf/PassOwnPtr.h" 42 #include "wtf/PassOwnPtr.h"
42 43
43 using namespace blink; 44 using namespace blink;
44 45
45 static bool supportsUIStateTransitionProgress() 46 static bool supportsUIStateTransitionProgress()
46 { 47 {
47 // FIXME: This is temporary until all platforms that support ScrollbarPainte r support this part of the API. 48 // FIXME: This is temporary until all platforms that support ScrollbarPainte r support this part of the API.
48 static bool globalSupportsUIStateTransitionProgress = [NSClassFromString(@"N SScrollerImp") instancesRespondToSelector:@selector(mouseEnteredScroller)]; 49 static bool globalSupportsUIStateTransitionProgress = [NSClassFromString(@"N SScrollerImp") instancesRespondToSelector:@selector(mouseEnteredScroller)];
49 return globalSupportsUIStateTransitionProgress; 50 return globalSupportsUIStateTransitionProgress;
50 } 51 }
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 private: 335 private:
335 void timerFired(Timer<WebScrollbarPartAnimationTimer>*) 336 void timerFired(Timer<WebScrollbarPartAnimationTimer>*)
336 { 337 {
337 double currentTime = WTF::currentTime(); 338 double currentTime = WTF::currentTime();
338 double delta = currentTime - m_startTime; 339 double delta = currentTime - m_startTime;
339 340
340 if (delta >= m_duration) 341 if (delta >= m_duration)
341 m_timer.stop(); 342 m_timer.stop();
342 343
343 double fraction = delta / m_duration; 344 double fraction = delta / m_duration;
344 fraction = std::min(1.0, fraction); 345 fraction = clampTo(fraction, 0.0, 1.0);
345 fraction = std::max(0.0, fraction);
346 double progress = m_timingFunction->evaluate(fraction, 0.001); 346 double progress = m_timingFunction->evaluate(fraction, 0.001);
347 [m_animation setCurrentProgress:progress]; 347 [m_animation setCurrentProgress:progress];
348 } 348 }
349 349
350 Timer<WebScrollbarPartAnimationTimer> m_timer; 350 Timer<WebScrollbarPartAnimationTimer> m_timer;
351 double m_startTime; // In seconds. 351 double m_startTime; // In seconds.
352 double m_duration; // In seconds. 352 double m_duration; // In seconds.
353 WebScrollbarPartAnimation* m_animation; // Weak, owns this. 353 WebScrollbarPartAnimation* m_animation; // Weak, owns this.
354 RefPtr<CubicBezierTimingFunction> m_timingFunction; 354 RefPtr<CubicBezierTimingFunction> m_timingFunction;
355 }; 355 };
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 { 761 {
762 [m_scrollAnimationHelper.get() _stopRun]; 762 [m_scrollAnimationHelper.get() _stopRun];
763 immediateScrollTo(offset); 763 immediateScrollTo(offset);
764 } 764 }
765 765
766 FloatPoint ScrollAnimatorMac::adjustScrollPositionIfNecessary(const FloatPoint& position) const 766 FloatPoint ScrollAnimatorMac::adjustScrollPositionIfNecessary(const FloatPoint& position) const
767 { 767 {
768 IntPoint minPos = m_scrollableArea->minimumScrollPosition(); 768 IntPoint minPos = m_scrollableArea->minimumScrollPosition();
769 IntPoint maxPos = m_scrollableArea->maximumScrollPosition(); 769 IntPoint maxPos = m_scrollableArea->maximumScrollPosition();
770 770
771 float newX = std::max<float>(std::min<float>(position.x(), maxPos.x()), minP os.x()); 771 float newX = clampTo<float, float>(position.x(), minPos.x(), maxPos.x());
772 float newY = std::max<float>(std::min<float>(position.y(), maxPos.y()), minP os.y()); 772 float newY = clampTo<float, float>(position.y(), minPos.y(), maxPos.y());
773 773
774 return FloatPoint(newX, newY); 774 return FloatPoint(newX, newY);
775 } 775 }
776 776
777 void ScrollAnimatorMac::immediateScrollTo(const FloatPoint& newPosition) 777 void ScrollAnimatorMac::immediateScrollTo(const FloatPoint& newPosition)
778 { 778 {
779 FloatPoint adjustedPosition = adjustScrollPositionIfNecessary(newPosition); 779 FloatPoint adjustedPosition = adjustScrollPositionIfNecessary(newPosition);
780 780
781 bool positionChanged = adjustedPosition.x() != m_currentPosX || adjustedPosi tion.y() != m_currentPosY; 781 bool positionChanged = adjustedPosition.x() != m_currentPosX || adjustedPosi tion.y() != m_currentPosY;
782 if (!positionChanged && !scrollableArea()->scrollOriginChanged()) 782 if (!positionChanged && !scrollableArea()->scrollOriginChanged())
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 return; 1196 return;
1197 1197
1198 m_visibleScrollerThumbRect = rectInViewCoordinates; 1198 m_visibleScrollerThumbRect = rectInViewCoordinates;
1199 } 1199 }
1200 1200
1201 bool ScrollAnimatorMac::canUseCoordinatedScrollbar() { 1201 bool ScrollAnimatorMac::canUseCoordinatedScrollbar() {
1202 return ScrollbarThemeMacCommon::isOverlayAPIAvailable(); 1202 return ScrollbarThemeMacCommon::isOverlayAPIAvailable();
1203 } 1203 }
1204 1204
1205 } // namespace blink 1205 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698