Commit 3e9a6775 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

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

Bug: 1000055
Change-Id: Ide9895a75b1db5f27a22a94d5cc3c48f6e9322ec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1791625
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarJamie Walch <jamiewalch@chromium.org>
Cr-Commit-Position: refs/heads/master@{#694963}
parent cb229963
......@@ -5,6 +5,7 @@
#include "remoting/client/input/touch_input_scaler.h"
#include "base/logging.h"
#include "base/numerics/ranges.h"
#include "remoting/proto/event.pb.h"
namespace remoting {
......@@ -28,7 +29,7 @@ float Scale(float value, int output_max, int input_max) {
// |input_max|.
float ScaleAndClamp(float value, int output_max, int input_max) {
value = Scale(value, output_max, input_max);
return std::max(0.0f, std::min(static_cast<float>(output_max), value));
return base::ClampToRange(value, 0.0f, float{output_max});
}
} // namespace
......
......@@ -9,6 +9,7 @@
#include "base/command_line.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/numerics/ranges.h"
#include "remoting/base/logging.h"
#include "remoting/host/linux/x11_util.h"
#include "ui/gfx/x/x11.h"
......@@ -217,10 +218,10 @@ std::list<ScreenResolution> DesktopResizerX11::GetSupportedResolutions(
XRRGetScreenSizeRange(display_, root_,
&min_width, &min_height,
&max_width, &max_height);
int width = std::min(std::max(preferred.dimensions().width(), min_width),
max_width);
int height = std::min(std::max(preferred.dimensions().height(), min_height),
max_height);
int width = base::ClampToRange(preferred.dimensions().width(), min_width,
max_width);
int height = base::ClampToRange(preferred.dimensions().height(), min_height,
max_height);
// Additionally impose a minimum size of 640x480, since anything smaller
// doesn't seem very useful.
ScreenResolution actual(
......
......@@ -18,6 +18,7 @@
#include "base/guid.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/numerics/ranges.h"
#include "base/stl_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
......@@ -104,8 +105,8 @@ const wchar_t kSecurityLayerValueName[] = L"SecurityLayer";
webrtc::DesktopSize GetBoundedRdpDesktopSize(int width, int height) {
return webrtc::DesktopSize(
std::min(kMaxRdpScreenWidth, std::max(kMinRdpScreenWidth, width)),
std::min(kMaxRdpScreenHeight, std::max(kMinRdpScreenHeight, height)));
base::ClampToRange(width, kMinRdpScreenWidth, kMaxRdpScreenWidth),
base::ClampToRange(height, kMinRdpScreenHeight, kMaxRdpScreenHeight));
}
// DesktopSession implementation which attaches to the host's physical console.
......
......@@ -15,6 +15,7 @@
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted.h"
#include "base/numerics/ranges.h"
#include "base/optional.h"
#include "base/single_thread_task_runner.h"
#include "base/stl_util.h"
......@@ -76,8 +77,8 @@ void ParseMouseMoveEvent(const MouseEvent& event, std::vector<INPUT>* output) {
int width = GetSystemMetrics(SM_CXVIRTUALSCREEN);
int height = GetSystemMetrics(SM_CYVIRTUALSCREEN);
if (width > 1 && height > 1) {
int x = std::max(0, std::min(width, event.x()));
int y = std::max(0, std::min(height, event.y()));
int x = base::ClampToRange(event.x(), 0, width);
int y = base::ClampToRange(event.y(), 0, height);
input.mi.dx = static_cast<int>((x * 65535) / (width - 1));
input.mi.dy = static_cast<int>((y * 65535) / (height - 1));
input.mi.dwFlags =
......
......@@ -7,6 +7,7 @@
#include <algorithm>
#include "base/logging.h"
#include "base/numerics/ranges.h"
#include "remoting/proto/event.pb.h"
namespace remoting {
......@@ -35,13 +36,13 @@ void MouseInputFilter::InjectMouseEvent(const MouseEvent& event) {
int x = out_event.x() * output_size_.WidthAsPixels();
x = (x + input_size_.WidthAsDips() / 2) / input_size_.WidthAsDips();
out_event.set_x(output_offset_.x() +
std::max(0, std::min(output_size_.WidthAsPixels(), x)));
base::ClampToRange(x, 0, output_size_.WidthAsPixels()));
}
if (out_event.has_y()) {
int y = out_event.y() * output_size_.HeightAsPixels();
y = (y + input_size_.HeightAsDips() / 2) / input_size_.HeightAsDips();
out_event.set_y(output_offset_.y() +
std::max(0, std::min(output_size_.HeightAsPixels(), y)));
base::ClampToRange(y, 0, output_size_.HeightAsPixels()));
}
InputFilter::InjectMouseEvent(out_event);
......
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