cef/libcef/browser/screen_util.cc
Nik Pavlov d3a2237a5a alloy: mac: Fix default popup window positioning (see issue #3244)
Popup windows will be created on the display that best matches the requested
coordinates. The requested size will apply to the content area (as required by
JS documentation) and window size will be reduced if necessary to fit within the
target display. The requested origin will apply to the window (including frame)
and will be modified if necessary so that the window is fully visible on the
target display.

This change does not implement popup positioning for cefclient which uses an
application-created parent window.

This change grants access to the getScreenDetails JS API without user prompt.
2022-06-27 10:29:16 +00:00

40 lines
1.1 KiB
C++

// 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>
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;
if (excess > 0)
start = start - excess;
return start;
}
} // namespace
CefRect MakeVisibleOnScreenRect(const CefRect& rect, const CefRect& screen) {
const int width = std::clamp(rect.width, kMinWidth, screen.width);
const int height = std::clamp(rect.height, kMinHeight, screen.height);
const int right_border = screen.x + screen.width;
const int x = clamp_segment_start(rect.x, width, screen.x, right_border);
const int bottom_border = screen.y + screen.height;
const int y = clamp_segment_start(rect.y, height, screen.y, bottom_border);
return CefRect(x, y, width, height);
}