Move cc::MathUtil::ClampToRange() to base and use it more broadly.

There are many more places in the codebase that can use this pattern; I've not
converted them here.  (Searching for nested mins/maxes is instructive.)

Bug: none
Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel
Change-Id: Ia122ac011712dc1a94bc119b47758aedf75d180d
Reviewed-on: https://chromium-review.googlesource.com/658619
Commit-Queue: Peter Kasting <[email protected]>
Reviewed-by: Jenny Zhang <[email protected]>
Reviewed-by: Zhenyao Mo <[email protected]>
Reviewed-by: Ian Vollick <[email protected]>
Reviewed-by: danakj <[email protected]>
Reviewed-by: Michael Wasserman <[email protected]>
Cr-Commit-Position: refs/heads/master@{#501743}
diff --git a/base/numerics/ranges.h b/base/numerics/ranges.h
new file mode 100644
index 0000000..0ef2288
--- /dev/null
+++ b/base/numerics/ranges.h
@@ -0,0 +1,19 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_NUMERICS_RANGES_H_
+#define BASE_NUMERICS_RANGES_H_
+
+#include <algorithm>
+
+namespace base {
+
+template <typename T>
+T ClampToRange(T value, T min, T max) {
+  return std::min(std::max(value, min), max);
+}
+
+}  // namespace base
+
+#endif  // BASE_NUMERICS_RANGES_H_