Commit 8b80a9bd authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Replace nested min/max calls with base::ClampToRange() in ash/.

Bug: 1000055
Change-Id: I68b4037c827698f701c46ac7ef552c9c08d5cd70
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1793251
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#694901}
parent 9a05e40a
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "ash/accessibility/layer_animation_info.h" #include "ash/accessibility/layer_animation_info.h"
#include "base/numerics/ranges.h"
namespace ash { namespace ash {
void ComputeOpacity(LayerAnimationInfo* animation_info, void ComputeOpacity(LayerAnimationInfo* animation_info,
...@@ -33,7 +35,7 @@ void ComputeOpacity(LayerAnimationInfo* animation_info, ...@@ -33,7 +35,7 @@ void ComputeOpacity(LayerAnimationInfo* animation_info,
} }
// Layer::SetOpacity will throw an error if we're not within 0...1. // Layer::SetOpacity will throw an error if we're not within 0...1.
opacity = std::min(std::max(opacity, 0.0f), 1.0f); opacity = base::ClampToRange(opacity, 0.0f, 1.0f);
animation_info->opacity = opacity; animation_info->opacity = opacity;
} }
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "ash/public/cpp/window_properties.h" #include "ash/public/cpp/window_properties.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h" #include "base/metrics/user_metrics.h"
#include "base/numerics/ranges.h"
#include "ui/aura/window_tree_host.h" #include "ui/aura/window_tree_host.h"
#include "ui/base/hit_test.h" #include "ui/base/hit_test.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
...@@ -98,7 +99,7 @@ float HidePositionStartValue() { ...@@ -98,7 +99,7 @@ float HidePositionStartValue() {
// animations to the expected range so that gfx::Tween::CalculateValue() can be // animations to the expected range so that gfx::Tween::CalculateValue() can be
// used. // used.
double CapAnimationValue(double value) { double CapAnimationValue(double value) {
return std::min(1.0, std::max(0.0, value)); return base::ClampToRange(value, 0.0, 1.0);
} }
// Returns a |views::BoxLayout| layout manager with the settings needed by // Returns a |views::BoxLayout| layout manager with the settings needed by
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <algorithm> #include <algorithm>
#include "ash/public/cpp/pagination/pagination_model_observer.h" #include "ash/public/cpp/pagination/pagination_model_observer.h"
#include "base/numerics/ranges.h"
#include "ui/gfx/animation/slide_animation.h" #include "ui/gfx/animation/slide_animation.h"
namespace ash { namespace ash {
...@@ -245,7 +246,7 @@ int PaginationModel::CalculateTargetPage(int delta) const { ...@@ -245,7 +246,7 @@ int PaginationModel::CalculateTargetPage(int delta) const {
else if (target_page > end_page && selected_page_ == end_page) else if (target_page > end_page && selected_page_ == end_page)
end_page = total_pages_; end_page = total_pages_;
return std::max(start_page, std::min(end_page, target_page)); return base::ClampToRange(target_page, start_page, end_page);
} }
base::TimeDelta PaginationModel::GetTransitionAnimationSlideDuration() const { base::TimeDelta PaginationModel::GetTransitionAnimationSlideDuration() const {
......
...@@ -72,6 +72,7 @@ ...@@ -72,6 +72,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/numerics/ranges.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chromeos/constants/chromeos_switches.h" #include "chromeos/constants/chromeos_switches.h"
...@@ -347,8 +348,8 @@ class RootWindowTargeter : public aura::WindowTargeter { ...@@ -347,8 +348,8 @@ class RootWindowTargeter : public aura::WindowTargeter {
gfx::Point FitPointToBounds(const gfx::Point p, const gfx::Rect& bounds) { gfx::Point FitPointToBounds(const gfx::Point p, const gfx::Rect& bounds) {
return gfx::Point( return gfx::Point(
std::min(std::max(bounds.x(), p.x()), bounds.right() - 1), base::ClampToRange(p.x(), bounds.x(), bounds.right() - 1),
std::min(std::max(bounds.y(), p.y()), bounds.bottom() - 1)); base::ClampToRange(p.y(), bounds.y(), bounds.bottom() - 1));
} }
ui::EventType last_mouse_event_type_ = ui::ET_UNKNOWN; ui::EventType last_mouse_event_type_ = ui::ET_UNKNOWN;
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "ash/shelf/shelf_focus_cycler.h" #include "ash/shelf/shelf_focus_cycler.h"
#include "ash/shelf/shelf_widget.h" #include "ash/shelf/shelf_widget.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h" #include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "base/numerics/ranges.h"
#include "ui/compositor/paint_recorder.h" #include "ui/compositor/paint_recorder.h"
#include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/gfx/geometry/insets.h" #include "ui/gfx/geometry/insets.h"
...@@ -328,7 +329,7 @@ int ScrollableShelfView::CalculateScrollUpperBound() const { ...@@ -328,7 +329,7 @@ int ScrollableShelfView::CalculateScrollUpperBound() const {
float ScrollableShelfView::CalculateClampedScrollOffset(float scroll) const { float ScrollableShelfView::CalculateClampedScrollOffset(float scroll) const {
const float scroll_upper_bound = CalculateScrollUpperBound(); const float scroll_upper_bound = CalculateScrollUpperBound();
scroll = std::min(scroll_upper_bound, std::max(0.f, scroll)); scroll = base::ClampToRange(scroll, 0.0f, scroll_upper_bound);
return scroll; return scroll;
} }
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/containers/adapters.h" #include "base/containers/adapters.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/numerics/ranges.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "chromeos/constants/chromeos_switches.h" #include "chromeos/constants/chromeos_switches.h"
...@@ -1571,7 +1572,7 @@ void ShelfView::MoveDragViewTo(int primary_axis_coordinate) { ...@@ -1571,7 +1572,7 @@ void ShelfView::MoveDragViewTo(int primary_axis_coordinate) {
*view_model_, drag_view_, shelf_->IsHorizontalAlignment(), *view_model_, drag_view_, shelf_->IsHorizontalAlignment(),
drag_view_->x(), drag_view_->y()); drag_view_->x(), drag_view_->y());
target_index = target_index =
std::min(indices.second, std::max(target_index, indices.first)); base::ClampToRange(target_index, indices.first, indices.second);
if (target_index == current_index) if (target_index == current_index)
return; return;
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_constants.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/numerics/ranges.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chromeos/services/network_config/public/cpp/cros_network_config_util.h" #include "chromeos/services/network_config/public/cpp/cros_network_config_util.h"
#include "chromeos/services/network_config/public/mojom/cros_network_config.mojom.h" #include "chromeos/services/network_config/public/mojom/cros_network_config.mojom.h"
...@@ -204,7 +205,7 @@ gfx::ImageSkia* ConnectingWirelessImage(ImageType image_type, ...@@ -204,7 +205,7 @@ gfx::ImageSkia* ConnectingWirelessImage(ImageType image_type,
static gfx::ImageSkia* s_arcs_images_dark[kImageCount]; static gfx::ImageSkia* s_arcs_images_dark[kImageCount];
static gfx::ImageSkia* s_arcs_images_light[kImageCount]; static gfx::ImageSkia* s_arcs_images_light[kImageCount];
int index = animation * nextafter(static_cast<float>(kImageCount), 0); int index = animation * nextafter(static_cast<float>(kImageCount), 0);
index = std::max(std::min(index, kImageCount - 1), 0); index = base::ClampToRange(index, 0, kImageCount - 1);
gfx::ImageSkia** images; gfx::ImageSkia** images;
bool dark = IconTypeIsDark(icon_type); bool dark = IconTypeIsDark(icon_type);
if (image_type == BARS) if (image_type == BARS)
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/i18n/time_formatting.h" #include "base/i18n/time_formatting.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/numerics/ranges.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chromeos/dbus/power/power_manager_client.h" #include "chromeos/dbus/power/power_manager_client.h"
...@@ -97,8 +98,8 @@ class BatteryImageSource : public gfx::CanvasImageSource { ...@@ -97,8 +98,8 @@ class BatteryImageSource : public gfx::CanvasImageSource {
float charge_level = float charge_level =
std::floor(info_.charge_percent / 100.0 * icon_bounds.height()); std::floor(info_.charge_percent / 100.0 * icon_bounds.height());
const float min_charge_level = dsf * kMinVisualChargeLevel; const float min_charge_level = dsf * kMinVisualChargeLevel;
charge_level = std::max(std::min(charge_level, icon_bounds.height()), charge_level = base::ClampToRange(charge_level, min_charge_level,
min_charge_level); icon_bounds.height());
const float charge_y = icon_bounds.bottom() - charge_level; const float charge_y = icon_bounds.bottom() - charge_level;
gfx::RectF clip_rect(0, charge_y, size().width() * dsf, gfx::RectF clip_rect(0, charge_y, size().width() * dsf,
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <numeric> #include <numeric>
#include "base/macros.h" #include "base/macros.h"
#include "base/numerics/ranges.h"
#include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkPath.h" #include "third_party/skia/include/core/SkPath.h"
...@@ -299,7 +300,7 @@ void TrayBubbleView::SetBottomPadding(int padding) { ...@@ -299,7 +300,7 @@ void TrayBubbleView::SetBottomPadding(int padding) {
} }
void TrayBubbleView::SetWidth(int width) { void TrayBubbleView::SetWidth(int width) {
width = std::max(std::min(width, params_.max_width), params_.min_width); width = base::ClampToRange(width, params_.min_width, params_.max_width);
if (preferred_width_ == width) if (preferred_width_ == width)
return; return;
preferred_width_ = width; preferred_width_ = width;
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "ash/wm/wm_event.h" #include "ash/wm/wm_event.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h" #include "base/metrics/user_metrics.h"
#include "base/numerics/ranges.h"
#include "base/optional.h" #include "base/optional.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/system/sys_info.h" #include "base/system/sys_info.h"
...@@ -97,10 +98,10 @@ constexpr char kSplitViewResizeWithOverviewMaxLatencyHistogram[] = ...@@ -97,10 +98,10 @@ constexpr char kSplitViewResizeWithOverviewMaxLatencyHistogram[] =
gfx::Point GetBoundedPosition(const gfx::Point& location_in_screen, gfx::Point GetBoundedPosition(const gfx::Point& location_in_screen,
const gfx::Rect& bounds_in_screen) { const gfx::Rect& bounds_in_screen) {
return gfx::Point( return gfx::Point(
std::max(std::min(location_in_screen.x(), bounds_in_screen.right() - 1), base::ClampToRange(location_in_screen.x(), bounds_in_screen.x(),
bounds_in_screen.x()), bounds_in_screen.right() - 1),
std::max(std::min(location_in_screen.y(), bounds_in_screen.bottom() - 1), base::ClampToRange(location_in_screen.y(), bounds_in_screen.y(),
bounds_in_screen.y())); bounds_in_screen.bottom() - 1));
} }
WindowStateType GetStateTypeFromSnapPosition( WindowStateType GetStateTypeFromSnapPosition(
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "ash/wm/window_state.h" #include "ash/wm/window_state.h"
#include "ash/wm/window_util.h" #include "ash/wm/window_util.h"
#include "ash/wm/wm_event.h" #include "ash/wm/wm_event.h"
#include "base/numerics/ranges.h"
#include "ui/aura/client/focus_client.h" #include "ui/aura/client/focus_client.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/aura/window_delegate.h" #include "ui/aura/window_delegate.h"
...@@ -40,7 +41,7 @@ int GetDefaultSnappedWindowWidth(aura::Window* window) { ...@@ -40,7 +41,7 @@ int GetDefaultSnappedWindowWidth(aura::Window* window) {
window->delegate() ? window->delegate()->GetMinimumSize().width() : 0; window->delegate() ? window->delegate()->GetMinimumSize().width() : 0;
int ideal_width = int ideal_width =
static_cast<int>(work_area_width * kSnappedWidthWorkspaceRatio); static_cast<int>(work_area_width * kSnappedWidthWorkspaceRatio);
return std::min(work_area_width, std::max(ideal_width, min_width)); return base::ClampToRange(ideal_width, min_width, work_area_width);
} }
// Return true if the window or one of its ancestor returns true from // Return true if the window or one of its ancestor returns true from
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment