2022-06-27 12:29:16 +02:00
|
|
|
// Copyright (c) 2022 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "libcef/browser/screen_util.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
2022-10-25 01:47:04 +02:00
|
|
|
#include "ui/gfx/geometry/rect.h"
|
|
|
|
|
2022-06-27 12:29:16 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
constexpr int kMinWidth = 0;
|
|
|
|
constexpr int kMinHeight = 0;
|
|
|
|
|
|
|
|
// Makes sure that line segment lies entirely between min and max.
|
|
|
|
int clamp_segment_start(int start, int len, int min, int max) {
|
|
|
|
start = std::clamp(start, min, max);
|
|
|
|
const int end = start + len;
|
|
|
|
const int excess = end - max;
|
|
|
|
|
2023-01-02 23:59:03 +01:00
|
|
|
if (excess > 0) {
|
2022-06-27 12:29:16 +02:00
|
|
|
start = start - excess;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2022-06-27 12:29:16 +02:00
|
|
|
|
|
|
|
return start;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2022-10-25 01:47:04 +02:00
|
|
|
gfx::Rect MakeVisibleOnScreenRect(const gfx::Rect& rect,
|
|
|
|
const gfx::Rect& screen) {
|
|
|
|
const int width = std::clamp(rect.width(), kMinWidth, screen.width());
|
|
|
|
const int height = std::clamp(rect.height(), kMinHeight, screen.height());
|
2022-06-27 12:29:16 +02:00
|
|
|
|
2022-10-25 01:47:04 +02:00
|
|
|
const int right_border = screen.x() + screen.width();
|
|
|
|
const int x = clamp_segment_start(rect.x(), width, screen.x(), right_border);
|
2022-06-27 12:29:16 +02:00
|
|
|
|
2022-10-25 01:47:04 +02:00
|
|
|
const int bottom_border = screen.y() + screen.height();
|
|
|
|
const int y =
|
|
|
|
clamp_segment_start(rect.y(), height, screen.y(), bottom_border);
|
2022-06-27 12:29:16 +02:00
|
|
|
|
2022-10-25 01:47:04 +02:00
|
|
|
return gfx::Rect(x, y, width, height);
|
2022-06-27 12:29:16 +02:00
|
|
|
}
|