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

Unified Diff: ui/gfx/animation/tween.cc

Issue 649203003: Type conversion fixes, ui/gfx/ edition. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/animation/linear_animation.cc ('k') | ui/gfx/color_analysis.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/animation/tween.cc
diff --git a/ui/gfx/animation/tween.cc b/ui/gfx/animation/tween.cc
index 483d772b5b4d47f4f7ba7f65d391f665df5819db..ecb928d49135bb974ed944a1243575c6d140ee6b 100644
--- a/ui/gfx/animation/tween.cc
+++ b/ui/gfx/animation/tween.cc
@@ -14,6 +14,7 @@
#include "base/basictypes.h"
#include "base/logging.h"
+#include "base/numerics/safe_conversions.h"
#include "ui/gfx/geometry/cubic_bezier.h"
#include "ui/gfx/safe_integer_conversions.h"
@@ -71,7 +72,7 @@ double Tween::CalculateValue(Tween::Type type, double state) {
namespace {
uint8 FloatToColorByte(float f) {
- return std::min(std::max(ToRoundedInt(f * 255.f), 0), 255);
+ return base::saturated_cast<uint8>(ToRoundedInt(f * 255.f));
}
uint8 BlendColorComponents(uint8 start,
@@ -149,7 +150,8 @@ int Tween::IntValueBetween(double value, int start, int target) {
//static
int Tween::LinearIntValueBetween(double value, int start, int target) {
- return std::floor(0.5 + DoubleValueBetween(value, start, target));
+ // NOTE: Do not use ToRoundedInt()! See comments on function declaration.
+ return ToFlooredInt(0.5 + DoubleValueBetween(value, start, target));
}
// static
« no previous file with comments | « ui/gfx/animation/linear_animation.cc ('k') | ui/gfx/color_analysis.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698