2016-01-19 21:09:01 +01:00
|
|
|
// Copyright 2016 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/views/window_view.h"
|
|
|
|
|
2024-01-20 23:48:57 +01:00
|
|
|
#include <memory>
|
|
|
|
|
2023-11-21 20:17:55 +01:00
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2024-01-26 03:12:43 +01:00
|
|
|
#include "ui/base/ozone_buildflags.h"
|
|
|
|
#if BUILDFLAG(IS_OZONE_X11)
|
2023-11-21 20:17:55 +01:00
|
|
|
// Include first due to redefinition of x11::EventMask.
|
|
|
|
#include "ui/base/x/x11_util.h"
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2021-02-18 02:58:25 +01:00
|
|
|
#include "libcef/browser/chrome/views/chrome_browser_frame.h"
|
2023-04-12 20:34:39 +02:00
|
|
|
#include "libcef/browser/geometry_util.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
#include "libcef/browser/image_impl.h"
|
2017-08-04 00:55:19 +02:00
|
|
|
#include "libcef/browser/views/window_impl.h"
|
2021-02-18 02:58:25 +01:00
|
|
|
#include "libcef/features/runtime.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
#include "ui/base/hit_test.h"
|
2023-06-14 10:20:02 +02:00
|
|
|
#include "ui/display/screen.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
#include "ui/views/widget/widget.h"
|
|
|
|
#include "ui/views/window/native_frame_view.h"
|
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2024-01-26 03:12:43 +01:00
|
|
|
#if BUILDFLAG(IS_OZONE_X11)
|
2023-12-06 21:16:15 +01:00
|
|
|
#include "ui/gfx/x/atom_cache.h"
|
2023-06-14 10:20:02 +02:00
|
|
|
#include "ui/linux/linux_ui_delegate.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
#endif
|
2021-12-16 23:35:54 +01:00
|
|
|
#endif
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2023-06-14 10:20:02 +02:00
|
|
|
#if BUILDFLAG(IS_OZONE)
|
|
|
|
#include "ui/ozone/public/ozone_platform.h"
|
|
|
|
#endif
|
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2023-06-16 11:11:20 +02:00
|
|
|
#include <dwmapi.h>
|
2024-01-20 23:48:57 +01:00
|
|
|
|
2023-06-16 11:11:20 +02:00
|
|
|
#include "base/win/windows_version.h"
|
2023-06-14 10:20:02 +02:00
|
|
|
#include "ui/display/win/screen_win.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
#include "ui/views/win/hwnd_util.h"
|
|
|
|
#endif
|
|
|
|
|
2021-02-23 21:08:33 +01:00
|
|
|
#if defined(USE_AURA)
|
|
|
|
#include "ui/aura/window.h"
|
|
|
|
#endif
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Specialize ClientView to handle Widget-related events.
|
|
|
|
class ClientViewEx : public views::ClientView {
|
|
|
|
public:
|
|
|
|
ClientViewEx(views::Widget* widget,
|
|
|
|
views::View* contents_view,
|
|
|
|
CefWindowView::Delegate* window_delegate)
|
2017-05-17 11:29:28 +02:00
|
|
|
: views::ClientView(widget, contents_view),
|
|
|
|
window_delegate_(window_delegate) {
|
2016-01-19 21:09:01 +01:00
|
|
|
DCHECK(window_delegate_);
|
|
|
|
}
|
|
|
|
|
2021-12-06 21:40:25 +01:00
|
|
|
ClientViewEx(const ClientViewEx&) = delete;
|
|
|
|
ClientViewEx& operator=(const ClientViewEx&) = delete;
|
|
|
|
|
2020-08-29 00:39:23 +02:00
|
|
|
views::CloseRequestResult OnWindowCloseRequested() override {
|
|
|
|
return window_delegate_->CanWidgetClose()
|
|
|
|
? views::CloseRequestResult::kCanClose
|
|
|
|
: views::CloseRequestResult::kCannotClose;
|
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
CefWindowView::Delegate* window_delegate_; // Not owned by this object.
|
|
|
|
};
|
|
|
|
|
|
|
|
// Extend NativeFrameView with draggable region handling.
|
|
|
|
class NativeFrameViewEx : public views::NativeFrameView {
|
|
|
|
public:
|
2017-05-17 11:29:28 +02:00
|
|
|
NativeFrameViewEx(views::Widget* widget, CefWindowView* view)
|
|
|
|
: views::NativeFrameView(widget), widget_(widget), view_(view) {}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2021-12-06 21:40:25 +01:00
|
|
|
NativeFrameViewEx(const NativeFrameViewEx&) = delete;
|
|
|
|
NativeFrameViewEx& operator=(const NativeFrameViewEx&) = delete;
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
gfx::Rect GetWindowBoundsForClientBounds(
|
|
|
|
const gfx::Rect& client_bounds) const override {
|
2023-06-14 10:20:02 +02:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
|
|
|
// From NativeFrameView::GetWindowBoundsForClientBounds:
|
|
|
|
gfx::Rect window_bounds = client_bounds;
|
|
|
|
// Enforce minimum size (1, 1) in case that |client_bounds| is passed with
|
|
|
|
// empty size.
|
|
|
|
if (window_bounds.IsEmpty()) {
|
|
|
|
window_bounds.set_size(gfx::Size(1, 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!view_->IsFrameless()) {
|
2024-01-12 00:32:08 +01:00
|
|
|
if (auto titlebar_height = view_->GetTitlebarHeight(/*required=*/true)) {
|
2023-06-14 10:20:02 +02:00
|
|
|
window_bounds.Inset(gfx::Insets::TLBR(-(*titlebar_height), 0, 0, 0));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return window_bounds;
|
|
|
|
#elif BUILDFLAG(IS_WIN)
|
|
|
|
HWND window = views::HWNDForWidget(widget_);
|
|
|
|
CHECK(window);
|
|
|
|
|
|
|
|
const DWORD style = GetWindowLong(window, GWL_STYLE);
|
|
|
|
const DWORD ex_style = GetWindowLong(window, GWL_EXSTYLE);
|
2024-01-20 23:48:57 +01:00
|
|
|
const bool has_menu = !(style & WS_CHILD) && (GetMenu(window) != nullptr);
|
2023-06-14 10:20:02 +02:00
|
|
|
|
|
|
|
// Convert from DIP to pixel coordinates using a method that can handle
|
|
|
|
// multiple displays with different DPI.
|
|
|
|
const auto screen_rect =
|
|
|
|
display::win::ScreenWin::DIPToScreenRect(window, client_bounds);
|
|
|
|
|
|
|
|
RECT rect = {screen_rect.x(), screen_rect.y(),
|
|
|
|
screen_rect.x() + screen_rect.width(),
|
|
|
|
screen_rect.y() + screen_rect.height()};
|
|
|
|
AdjustWindowRectEx(&rect, style, has_menu, ex_style);
|
|
|
|
|
|
|
|
// Keep the original origin while potentially increasing the size to include
|
|
|
|
// the frame non-client area.
|
|
|
|
gfx::Rect pixel_rect(screen_rect.x(), screen_rect.y(),
|
|
|
|
rect.right - rect.left, rect.bottom - rect.top);
|
|
|
|
|
|
|
|
// Convert back to DIP.
|
|
|
|
return display::win::ScreenWin::ScreenToDIPRect(window, pixel_rect);
|
2016-01-19 21:09:01 +01:00
|
|
|
#else
|
|
|
|
// Use the default implementation.
|
|
|
|
return views::NativeFrameView::GetWindowBoundsForClientBounds(
|
|
|
|
client_bounds);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int NonClientHitTest(const gfx::Point& point) override {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (widget_->IsFullscreen()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return HTCLIENT;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// Test for mouse clicks that fall within the draggable region.
|
|
|
|
SkRegion* draggable_region = view_->draggable_region();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (draggable_region && draggable_region->contains(point.x(), point.y())) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return HTCAPTION;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
return views::NativeFrameView::NonClientHitTest(point);
|
|
|
|
}
|
|
|
|
|
2023-06-16 11:11:20 +02:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
|
|
|
void OnThemeChanged() override {
|
|
|
|
views::NativeFrameView::OnThemeChanged();
|
|
|
|
|
|
|
|
// Value was 19 prior to Windows 10 20H1, according to
|
|
|
|
// https://stackoverflow.com/a/70693198
|
|
|
|
const DWORD dwAttribute =
|
|
|
|
base::win::GetVersion() >= base::win::Version::WIN10_20H1
|
|
|
|
? DWMWA_USE_IMMERSIVE_DARK_MODE
|
|
|
|
: 19;
|
|
|
|
|
|
|
|
// From BrowserFrameViewWin::SetSystemMicaTitlebarAttributes:
|
|
|
|
const BOOL dark_titlebar_enabled = GetNativeTheme()->ShouldUseDarkColors();
|
|
|
|
DwmSetWindowAttribute(views::HWNDForWidget(widget_), dwAttribute,
|
|
|
|
&dark_titlebar_enabled,
|
|
|
|
sizeof(dark_titlebar_enabled));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
private:
|
|
|
|
// Not owned by this object.
|
|
|
|
views::Widget* widget_;
|
|
|
|
CefWindowView* view_;
|
|
|
|
};
|
|
|
|
|
|
|
|
// The area inside the frame border that can be clicked and dragged for resizing
|
|
|
|
// the window. Only used in restored mode.
|
|
|
|
const int kResizeBorderThickness = 4;
|
|
|
|
|
2016-12-14 14:27:10 +01:00
|
|
|
// The distance from each window corner that triggers diagonal resizing. Only
|
2016-01-19 21:09:01 +01:00
|
|
|
// used in restored mode.
|
|
|
|
const int kResizeAreaCornerSize = 16;
|
|
|
|
|
|
|
|
// Implement NonClientFrameView without the system default caption and icon but
|
|
|
|
// with a resizable border. Based on AppWindowFrameView and CustomFrameView.
|
|
|
|
class CaptionlessFrameView : public views::NonClientFrameView {
|
|
|
|
public:
|
2017-05-17 11:29:28 +02:00
|
|
|
CaptionlessFrameView(views::Widget* widget, CefWindowView* view)
|
|
|
|
: widget_(widget), view_(view) {}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2021-12-06 21:40:25 +01:00
|
|
|
CaptionlessFrameView(const CaptionlessFrameView&) = delete;
|
|
|
|
CaptionlessFrameView& operator=(const CaptionlessFrameView&) = delete;
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
gfx::Rect GetBoundsForClientView() const override {
|
|
|
|
return client_view_bounds_;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Rect GetWindowBoundsForClientBounds(
|
|
|
|
const gfx::Rect& client_bounds) const override {
|
2016-12-14 14:27:10 +01:00
|
|
|
return client_bounds;
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int NonClientHitTest(const gfx::Point& point) override {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (widget_->IsFullscreen()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return HTCLIENT;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// Sanity check.
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!bounds().Contains(point)) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return HTNOWHERE;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// Check the frame first, as we allow a small area overlapping the contents
|
|
|
|
// to be used for resize handles.
|
|
|
|
bool can_ever_resize = widget_->widget_delegate()
|
|
|
|
? widget_->widget_delegate()->CanResize()
|
|
|
|
: false;
|
|
|
|
// Don't allow overlapping resize handles when the window is maximized or
|
|
|
|
// fullscreen, as it can't be resized in those states.
|
|
|
|
int resize_border_thickness = ResizeBorderThickness();
|
2017-05-17 11:29:28 +02:00
|
|
|
int frame_component = GetHTComponentForFrame(
|
2022-04-21 20:58:48 +02:00
|
|
|
point,
|
|
|
|
gfx::Insets::VH(resize_border_thickness, resize_border_thickness),
|
2017-05-17 11:29:28 +02:00
|
|
|
kResizeAreaCornerSize, kResizeAreaCornerSize, can_ever_resize);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (frame_component != HTNOWHERE) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return frame_component;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// Test for mouse clicks that fall within the draggable region.
|
|
|
|
SkRegion* draggable_region = view_->draggable_region();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (draggable_region && draggable_region->contains(point.x(), point.y())) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return HTCAPTION;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
int client_component = widget_->client_view()->NonClientHitTest(point);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (client_component != HTNOWHERE) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return client_component;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// Caption is a safe default.
|
|
|
|
return HTCAPTION;
|
|
|
|
}
|
|
|
|
|
2019-01-17 10:56:52 +01:00
|
|
|
void GetWindowMask(const gfx::Size& size, SkPath* window_mask) override {
|
2016-01-19 21:09:01 +01:00
|
|
|
// Nothing to do here.
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResetWindowControls() override {
|
|
|
|
// Nothing to do here.
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateWindowIcon() override {
|
|
|
|
// Nothing to do here.
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateWindowTitle() override {
|
|
|
|
// Nothing to do here.
|
|
|
|
}
|
|
|
|
|
|
|
|
void SizeConstraintsChanged() override {
|
|
|
|
// Nothing to do here.
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnPaint(gfx::Canvas* canvas) override {
|
|
|
|
// Nothing to do here.
|
|
|
|
}
|
|
|
|
|
|
|
|
void Layout() override {
|
2016-12-14 14:27:10 +01:00
|
|
|
client_view_bounds_.SetRect(0, 0, width(), height());
|
2021-08-04 20:20:31 +02:00
|
|
|
views::NonClientFrameView::Layout();
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2017-07-27 01:19:27 +02:00
|
|
|
gfx::Size CalculatePreferredSize() const override {
|
2017-05-17 11:29:28 +02:00
|
|
|
return widget_->non_client_view()
|
|
|
|
->GetWindowBoundsForClientBounds(
|
|
|
|
gfx::Rect(widget_->client_view()->GetPreferredSize()))
|
|
|
|
.size();
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Size GetMinimumSize() const override {
|
2017-05-17 11:29:28 +02:00
|
|
|
return widget_->non_client_view()
|
|
|
|
->GetWindowBoundsForClientBounds(
|
|
|
|
gfx::Rect(widget_->client_view()->GetMinimumSize()))
|
|
|
|
.size();
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Size GetMaximumSize() const override {
|
|
|
|
gfx::Size max_size = widget_->client_view()->GetMaximumSize();
|
|
|
|
gfx::Size converted_size =
|
2017-05-17 11:29:28 +02:00
|
|
|
widget_->non_client_view()
|
|
|
|
->GetWindowBoundsForClientBounds(gfx::Rect(max_size))
|
|
|
|
.size();
|
2016-01-19 21:09:01 +01:00
|
|
|
return gfx::Size(max_size.width() == 0 ? 0 : converted_size.width(),
|
|
|
|
max_size.height() == 0 ? 0 : converted_size.height());
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
int ResizeBorderThickness() const {
|
2017-05-17 11:29:28 +02:00
|
|
|
return (widget_->IsMaximized() || widget_->IsFullscreen()
|
|
|
|
? 0
|
|
|
|
: kResizeBorderThickness);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Not owned by this object.
|
|
|
|
views::Widget* widget_;
|
|
|
|
CefWindowView* view_;
|
|
|
|
|
|
|
|
// The bounds of the client view, in this view's coordinates.
|
|
|
|
gfx::Rect client_view_bounds_;
|
|
|
|
};
|
|
|
|
|
2017-01-23 18:36:54 +01:00
|
|
|
bool IsWindowBorderHit(int code) {
|
2017-05-17 11:29:28 +02:00
|
|
|
// On Windows HTLEFT = 10 and HTBORDER = 18. Values are not ordered the same
|
|
|
|
// in base/hit_test.h for non-Windows platforms.
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2017-01-23 18:36:54 +01:00
|
|
|
return code >= HTLEFT && code <= HTBORDER;
|
|
|
|
#else
|
|
|
|
return code == HTLEFT || code == HTRIGHT || code == HTTOP ||
|
|
|
|
code == HTTOPLEFT || code == HTTOPRIGHT || code == HTBOTTOM ||
|
|
|
|
code == HTBOTTOMLEFT || code == HTBOTTOMRIGHT || code == HTBORDER;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-06-14 10:20:02 +02:00
|
|
|
// Based on UpdateModalDialogPosition() from
|
|
|
|
// components/constrained_window/constrained_window_views.cc
|
|
|
|
void UpdateModalDialogPosition(views::Widget* widget,
|
|
|
|
views::Widget* host_widget) {
|
|
|
|
// Do not forcibly update the dialog widget position if it is being dragged.
|
|
|
|
if (widget->HasCapture()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const gfx::Size& size = widget->GetRootView()->GetPreferredSize();
|
|
|
|
const gfx::Size& host_size =
|
|
|
|
host_widget->GetClientAreaBoundsInScreen().size();
|
|
|
|
|
|
|
|
// Center the dialog. Position is relative to the host.
|
|
|
|
gfx::Point position;
|
|
|
|
position.set_x((host_size.width() - size.width()) / 2);
|
|
|
|
position.set_y((host_size.height() - size.height()) / 2);
|
|
|
|
|
|
|
|
// Align the first row of pixels inside the border. This is the apparent top
|
|
|
|
// of the dialog.
|
|
|
|
position.set_y(position.y() -
|
|
|
|
widget->non_client_view()->frame_view()->GetInsets().top());
|
|
|
|
|
|
|
|
const bool supports_global_screen_coordinates =
|
|
|
|
#if !BUILDFLAG(IS_OZONE)
|
|
|
|
true;
|
|
|
|
#else
|
|
|
|
ui::OzonePlatform::GetInstance()
|
|
|
|
->GetPlatformProperties()
|
|
|
|
.supports_global_screen_coordinates;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (widget->is_top_level() && supports_global_screen_coordinates) {
|
|
|
|
position += host_widget->GetClientAreaBoundsInScreen().OffsetFromOrigin();
|
|
|
|
// If the dialog extends partially off any display, clamp its position to
|
|
|
|
// be fully visible within that display. If the dialog doesn't intersect
|
|
|
|
// with any display clamp its position to be fully on the nearest display.
|
|
|
|
gfx::Rect display_rect = gfx::Rect(position, size);
|
|
|
|
const display::Display display =
|
|
|
|
display::Screen::GetScreen()->GetDisplayNearestView(
|
|
|
|
view_util::GetNativeView(host_widget));
|
|
|
|
const gfx::Rect work_area = display.work_area();
|
|
|
|
if (!work_area.Contains(display_rect)) {
|
|
|
|
display_rect.AdjustToFit(work_area);
|
|
|
|
}
|
|
|
|
position = display_rect.origin();
|
|
|
|
}
|
|
|
|
|
|
|
|
widget->SetBounds(gfx::Rect(position, size));
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
CefWindowView::CefWindowView(CefWindowDelegate* cef_delegate,
|
|
|
|
Delegate* window_delegate)
|
2023-06-14 10:20:02 +02:00
|
|
|
: ParentClass(cef_delegate), window_delegate_(window_delegate) {
|
2016-01-19 21:09:01 +01:00
|
|
|
DCHECK(window_delegate_);
|
|
|
|
}
|
|
|
|
|
2022-04-08 22:48:56 +02:00
|
|
|
void CefWindowView::CreateWidget(gfx::AcceleratedWidget parent_widget) {
|
2016-01-19 21:09:01 +01:00
|
|
|
DCHECK(!GetWidget());
|
|
|
|
|
|
|
|
// |widget| is owned by the NativeWidget and will be destroyed in response to
|
|
|
|
// a native destruction message.
|
2021-02-18 02:58:25 +01:00
|
|
|
views::Widget* widget = cef::IsChromeRuntimeEnabled() ? new ChromeBrowserFrame
|
|
|
|
: new views::Widget;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
views::Widget::InitParams params;
|
|
|
|
params.delegate = this;
|
2022-04-08 22:48:56 +02:00
|
|
|
|
2023-06-14 10:20:02 +02:00
|
|
|
views::Widget* host_widget = nullptr;
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
bool can_activate = true;
|
2022-04-08 22:48:56 +02:00
|
|
|
bool can_resize = true;
|
|
|
|
|
|
|
|
const bool has_native_parent = parent_widget != gfx::kNullAcceleratedWidget;
|
|
|
|
if (has_native_parent) {
|
|
|
|
params.parent_widget = parent_widget;
|
|
|
|
|
|
|
|
// Remove the window frame.
|
|
|
|
is_frameless_ = true;
|
|
|
|
|
|
|
|
// See CalculateWindowStylesFromInitParams in
|
|
|
|
// ui/views/widget/widget_hwnd_utils.cc for the conversion of |params| to
|
|
|
|
// Windows style flags.
|
|
|
|
// - Set the WS_CHILD flag.
|
|
|
|
params.child = true;
|
|
|
|
// - Set the WS_VISIBLE flag.
|
|
|
|
params.type = views::Widget::InitParams::TYPE_CONTROL;
|
|
|
|
// - Don't set the WS_EX_COMPOSITED flag.
|
|
|
|
params.opacity = views::Widget::InitParams::WindowOpacity::kOpaque;
|
|
|
|
} else {
|
|
|
|
params.type = views::Widget::InitParams::TYPE_WINDOW;
|
|
|
|
}
|
2017-08-04 00:55:19 +02:00
|
|
|
|
2021-07-23 18:40:13 +02:00
|
|
|
// WidgetDelegate::DeleteDelegate() will delete |this| after executing the
|
|
|
|
// registered callback.
|
|
|
|
SetOwnedByWidget(true);
|
|
|
|
RegisterDeleteDelegateCallback(
|
|
|
|
base::BindOnce(&CefWindowView::DeleteDelegate, base::Unretained(this)));
|
|
|
|
|
2017-08-04 00:55:19 +02:00
|
|
|
if (cef_delegate()) {
|
|
|
|
CefRefPtr<CefWindow> cef_window = GetCefWindow();
|
|
|
|
|
2020-09-02 20:25:25 +02:00
|
|
|
auto bounds = cef_delegate()->GetInitialBounds(cef_window);
|
|
|
|
params.bounds = gfx::Rect(bounds.x, bounds.y, bounds.width, bounds.height);
|
|
|
|
|
2022-04-08 22:48:56 +02:00
|
|
|
if (has_native_parent) {
|
|
|
|
DCHECK(!params.bounds.IsEmpty());
|
|
|
|
} else {
|
|
|
|
is_frameless_ = cef_delegate()->IsFrameless(cef_window);
|
2023-02-28 19:34:12 +01:00
|
|
|
|
2023-03-16 18:19:50 +01:00
|
|
|
params.native_widget =
|
|
|
|
view_util::CreateNativeWidget(widget, cef_window, cef_delegate());
|
2023-02-28 19:34:12 +01:00
|
|
|
|
2022-04-08 22:48:56 +02:00
|
|
|
can_resize = cef_delegate()->CanResize(cef_window);
|
|
|
|
|
|
|
|
const auto show_state = cef_delegate()->GetInitialShowState(cef_window);
|
|
|
|
switch (show_state) {
|
|
|
|
case CEF_SHOW_STATE_NORMAL:
|
|
|
|
params.show_state = ui::SHOW_STATE_NORMAL;
|
|
|
|
break;
|
|
|
|
case CEF_SHOW_STATE_MINIMIZED:
|
|
|
|
params.show_state = ui::SHOW_STATE_MINIMIZED;
|
|
|
|
break;
|
|
|
|
case CEF_SHOW_STATE_MAXIMIZED:
|
|
|
|
params.show_state = ui::SHOW_STATE_MAXIMIZED;
|
|
|
|
break;
|
|
|
|
case CEF_SHOW_STATE_FULLSCREEN:
|
|
|
|
params.show_state = ui::SHOW_STATE_FULLSCREEN;
|
|
|
|
break;
|
2024-01-29 19:38:25 +01:00
|
|
|
case CEF_SHOW_STATE_HIDDEN:
|
|
|
|
#if BUILDFLAG(IS_MAC)
|
|
|
|
params.show_state = ui::SHOW_STATE_HIDDEN;
|
|
|
|
#else
|
|
|
|
params.show_state = ui::SHOW_STATE_MINIMIZED;
|
|
|
|
#endif
|
|
|
|
break;
|
2022-04-08 22:48:56 +02:00
|
|
|
}
|
2021-09-07 16:04:55 +02:00
|
|
|
|
2022-04-08 22:48:56 +02:00
|
|
|
bool is_menu = false;
|
|
|
|
bool can_activate_menu = true;
|
|
|
|
CefRefPtr<CefWindow> parent_window = cef_delegate()->GetParentWindow(
|
|
|
|
cef_window, &is_menu, &can_activate_menu);
|
|
|
|
if (parent_window && !parent_window->IsSame(cef_window)) {
|
|
|
|
CefWindowImpl* parent_window_impl =
|
|
|
|
static_cast<CefWindowImpl*>(parent_window.get());
|
|
|
|
params.parent = view_util::GetNativeView(parent_window_impl->widget());
|
2023-06-14 10:20:02 +02:00
|
|
|
|
|
|
|
// Aura uses the same types for NativeView and NativeWindow, which can
|
|
|
|
// be confusing. Verify that we set |params.parent| correctly (to the
|
|
|
|
// expected internal::NativeWidgetPrivate) for Widget::Init usage.
|
|
|
|
DCHECK(views::Widget::GetWidgetForNativeView(params.parent));
|
|
|
|
|
2022-04-08 22:48:56 +02:00
|
|
|
if (is_menu) {
|
|
|
|
// Don't clip the window to parent bounds.
|
|
|
|
params.type = views::Widget::InitParams::TYPE_MENU;
|
|
|
|
|
|
|
|
// Don't set "always on top" for the window.
|
|
|
|
params.z_order = ui::ZOrderLevel::kNormal;
|
|
|
|
|
|
|
|
can_activate = can_activate_menu;
|
2023-06-14 10:20:02 +02:00
|
|
|
} else {
|
|
|
|
// Create a top-level window that is moveable and can exceed the
|
|
|
|
// bounds of the parent window. By not setting |params.child| here we
|
|
|
|
// cause OnBeforeWidgetInit to create a views::DesktopNativeWidgetAura
|
|
|
|
// instead of a views::NativeWidgetAura. We need to use this desktop
|
|
|
|
// variant with browser windows to get proper focus and shutdown
|
|
|
|
// behavior.
|
|
|
|
|
|
|
|
#if !BUILDFLAG(IS_LINUX)
|
|
|
|
// SetModalType doesn't work on Linux (no implementation in
|
|
|
|
// DesktopWindowTreeHostLinux::InitModalType). See the X11-specific
|
|
|
|
// implementation below that may work with some window managers.
|
|
|
|
if (cef_delegate()->IsWindowModalDialog(cef_window)) {
|
|
|
|
SetModalType(ui::MODAL_TYPE_WINDOW);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
host_widget = parent_window_impl->widget();
|
2022-04-08 22:48:56 +02:00
|
|
|
}
|
2017-08-04 00:55:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-12-14 14:27:10 +01:00
|
|
|
|
2020-09-02 20:25:25 +02:00
|
|
|
if (params.bounds.IsEmpty()) {
|
|
|
|
// The window will be placed on the default screen with origin (0,0).
|
|
|
|
params.bounds = gfx::Rect(CalculatePreferredSize());
|
2022-04-11 22:54:33 +02:00
|
|
|
if (params.bounds.IsEmpty()) {
|
|
|
|
// Choose a reasonable default size.
|
|
|
|
params.bounds.set_size({800, 600});
|
|
|
|
}
|
2020-09-02 20:25:25 +02:00
|
|
|
}
|
|
|
|
|
2022-04-08 22:48:56 +02:00
|
|
|
if (can_activate) {
|
|
|
|
// Cause WidgetDelegate::CanActivate to return true.
|
|
|
|
params.activatable = views::Widget::InitParams::Activatable::kYes;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetCanResize(can_resize);
|
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-01-19 21:09:01 +01:00
|
|
|
if (is_frameless_) {
|
2016-12-14 14:27:10 +01:00
|
|
|
// Don't show the native window caption. Setting this value on Linux will
|
|
|
|
// result in window resize artifacts.
|
|
|
|
params.remove_standard_frame = true;
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
2016-12-14 14:27:10 +01:00
|
|
|
#endif
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2019-10-01 15:55:16 +02:00
|
|
|
widget->Init(std::move(params));
|
2021-08-28 03:55:15 +02:00
|
|
|
widget->AddObserver(this);
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// |widget| should now be associated with |this|.
|
|
|
|
DCHECK_EQ(widget, GetWidget());
|
|
|
|
// |widget| must be top-level for focus handling to work correctly.
|
|
|
|
DCHECK(widget->is_top_level());
|
2017-08-04 00:55:19 +02:00
|
|
|
|
|
|
|
if (can_activate) {
|
|
|
|
// |widget| must be activatable for focus handling to work correctly.
|
|
|
|
DCHECK(widget->widget_delegate()->CanActivate());
|
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2024-01-26 03:12:43 +01:00
|
|
|
#if BUILDFLAG(IS_OZONE_X11)
|
2023-06-14 10:20:02 +02:00
|
|
|
auto x11window = static_cast<x11::Window>(view_util::GetWindowHandle(widget));
|
2023-06-28 10:46:38 +02:00
|
|
|
CHECK(x11window != x11::Window::None);
|
2023-06-14 10:20:02 +02:00
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
if (is_frameless_) {
|
2023-06-14 10:20:02 +02:00
|
|
|
ui::SetUseOSWindowFrame(x11window, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (host_widget) {
|
|
|
|
auto parent = static_cast<gfx::AcceleratedWidget>(
|
|
|
|
view_util::GetWindowHandle(host_widget));
|
|
|
|
CHECK(parent);
|
|
|
|
|
2023-12-06 21:16:15 +01:00
|
|
|
auto connection = x11::Connection::Get();
|
|
|
|
|
2023-06-14 10:20:02 +02:00
|
|
|
if (cef_delegate() && cef_delegate()->IsWindowModalDialog(GetCefWindow())) {
|
|
|
|
// The presence of _NET_WM_STATE_MODAL in _NET_SUPPORTED indicates
|
|
|
|
// possible window manager support. However, some window managers still
|
|
|
|
// don't support this properly.
|
|
|
|
x11::Atom modal_atom = x11::GetAtom("_NET_WM_STATE_MODAL");
|
2023-12-06 21:16:15 +01:00
|
|
|
if (connection->WmSupportsHint(modal_atom)) {
|
2023-06-14 10:20:02 +02:00
|
|
|
ui::SetWMSpecState(x11window, true, modal_atom, x11::Atom::None);
|
|
|
|
} else {
|
|
|
|
LOG(ERROR)
|
|
|
|
<< "Window modal dialogs are not supported by the window manager";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// From GtkUiPlatformX11::SetGtkWidgetTransientFor:
|
2023-12-06 21:16:15 +01:00
|
|
|
connection->SetProperty(x11window, x11::Atom::WM_TRANSIENT_FOR,
|
|
|
|
x11::Atom::WINDOW, parent);
|
|
|
|
connection->SetProperty(x11window, x11::GetAtom("_NET_WM_WINDOW_TYPE"),
|
|
|
|
x11::Atom::ATOM,
|
|
|
|
x11::GetAtom("_NET_WM_WINDOW_TYPE_DIALOG"));
|
2023-06-14 10:20:02 +02:00
|
|
|
|
|
|
|
ui::LinuxUiDelegate::GetInstance()->SetTransientWindowForParent(
|
|
|
|
parent, static_cast<gfx::AcceleratedWidget>(x11window));
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
2021-12-16 23:35:54 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
2023-06-14 10:20:02 +02:00
|
|
|
|
|
|
|
if (host_widget) {
|
|
|
|
// Position |widget| relative to |host_widget|.
|
|
|
|
UpdateModalDialogPosition(widget, host_widget);
|
|
|
|
|
|
|
|
// Track the lifespan of |host_widget|, which may be destroyed before
|
|
|
|
// |widget|.
|
|
|
|
host_widget_destruction_observer_ =
|
|
|
|
std::make_unique<WidgetDestructionObserver>(host_widget);
|
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefWindow> CefWindowView::GetCefWindow() const {
|
|
|
|
CefRefPtr<CefWindow> window = GetCefPanel()->AsWindow();
|
|
|
|
DCHECK(window);
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowView::DeleteDelegate() {
|
|
|
|
// Remove all child Views before deleting the Window so that notifications
|
|
|
|
// resolve correctly.
|
2021-08-20 01:40:49 +02:00
|
|
|
RemoveAllChildViews();
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
window_delegate_->OnWindowViewDeleted();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefWindowView::CanMinimize() const {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!cef_delegate()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
return cef_delegate()->CanMinimize(GetCefWindow());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefWindowView::CanMaximize() const {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!cef_delegate()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return true;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
return cef_delegate()->CanMaximize(GetCefWindow());
|
|
|
|
}
|
|
|
|
|
2021-04-21 00:52:34 +02:00
|
|
|
std::u16string CefWindowView::GetWindowTitle() const {
|
2016-01-19 21:09:01 +01:00
|
|
|
return title_;
|
|
|
|
}
|
|
|
|
|
2021-07-23 18:40:13 +02:00
|
|
|
ui::ImageModel CefWindowView::GetWindowIcon() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!window_icon_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return ParentClass::GetWindowIcon();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-07-23 18:40:13 +02:00
|
|
|
auto image_skia =
|
|
|
|
static_cast<CefImageImpl*>(window_icon_.get())
|
|
|
|
->GetForced1xScaleRepresentation(GetDisplay().device_scale_factor());
|
|
|
|
return ui::ImageModel::FromImageSkia(image_skia);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2021-07-23 18:40:13 +02:00
|
|
|
ui::ImageModel CefWindowView::GetWindowAppIcon() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!window_app_icon_) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return ParentClass::GetWindowAppIcon();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-07-23 18:40:13 +02:00
|
|
|
auto image_skia =
|
|
|
|
static_cast<CefImageImpl*>(window_app_icon_.get())
|
|
|
|
->GetForced1xScaleRepresentation(GetDisplay().device_scale_factor());
|
|
|
|
return ui::ImageModel::FromImageSkia(image_skia);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2017-02-17 00:19:43 +01:00
|
|
|
void CefWindowView::WindowClosing() {
|
2023-06-14 10:20:02 +02:00
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2024-01-26 03:12:43 +01:00
|
|
|
#if BUILDFLAG(IS_OZONE_X11)
|
2023-06-14 10:20:02 +02:00
|
|
|
if (host_widget()) {
|
|
|
|
auto parent = static_cast<gfx::AcceleratedWidget>(
|
|
|
|
view_util::GetWindowHandle(host_widget()));
|
|
|
|
CHECK(parent);
|
|
|
|
|
|
|
|
// From GtkUiPlatformX11::ClearTransientFor:
|
|
|
|
ui::LinuxUiDelegate::GetInstance()->SetTransientWindowForParent(
|
|
|
|
parent, static_cast<gfx::AcceleratedWidget>(x11::Window::None));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2017-02-17 00:19:43 +01:00
|
|
|
window_delegate_->OnWindowClosing();
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
views::View* CefWindowView::GetContentsView() {
|
|
|
|
// |this| will be the "Contents View" hosted by the Widget via ClientView and
|
|
|
|
// RootView.
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
views::ClientView* CefWindowView::CreateClientView(views::Widget* widget) {
|
|
|
|
return new ClientViewEx(widget, GetContentsView(), window_delegate_);
|
|
|
|
}
|
|
|
|
|
2020-08-29 00:39:23 +02:00
|
|
|
std::unique_ptr<views::NonClientFrameView>
|
|
|
|
CefWindowView::CreateNonClientFrameView(views::Widget* widget) {
|
2016-01-19 21:09:01 +01:00
|
|
|
if (is_frameless_) {
|
|
|
|
// Custom frame type that doesn't render a caption.
|
2020-08-29 00:39:23 +02:00
|
|
|
return std::make_unique<CaptionlessFrameView>(widget, this);
|
2016-01-19 21:09:01 +01:00
|
|
|
} else if (widget->ShouldUseNativeFrame()) {
|
|
|
|
// DesktopNativeWidgetAura::CreateNonClientFrameView() returns
|
|
|
|
// NativeFrameView by default. Extend that type.
|
2020-08-29 00:39:23 +02:00
|
|
|
return std::make_unique<NativeFrameViewEx>(widget, this);
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2019-10-04 12:57:29 +02:00
|
|
|
// Use Chromium provided CustomFrameView. In case if we would like to
|
|
|
|
// customize the frame, provide own implementation.
|
2016-01-19 21:09:01 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefWindowView::ShouldDescendIntoChildForEventHandling(
|
|
|
|
gfx::NativeView child,
|
|
|
|
const gfx::Point& location) {
|
|
|
|
if (is_frameless_) {
|
|
|
|
// If the window is resizable it should claim mouse events that fall on the
|
|
|
|
// window border.
|
|
|
|
views::NonClientFrameView* ncfv = GetNonClientFrameView();
|
|
|
|
if (ncfv) {
|
|
|
|
int result = ncfv->NonClientHitTest(location);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (IsWindowBorderHit(result)) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return false;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The window should claim mouse events that fall within the draggable region.
|
|
|
|
return !draggable_region_.get() ||
|
|
|
|
!draggable_region_->contains(location.x(), location.y());
|
|
|
|
}
|
|
|
|
|
2017-08-25 23:41:30 +02:00
|
|
|
bool CefWindowView::MaybeGetMinimumSize(gfx::Size* size) const {
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2017-08-25 23:41:30 +02:00
|
|
|
// Resize is disabled on Linux by returning the preferred size as the min/max
|
|
|
|
// size.
|
|
|
|
if (!CanResize()) {
|
|
|
|
*size = CalculatePreferredSize();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefWindowView::MaybeGetMaximumSize(gfx::Size* size) const {
|
2022-01-24 18:58:02 +01:00
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2017-08-25 23:41:30 +02:00
|
|
|
// Resize is disabled on Linux by returning the preferred size as the min/max
|
|
|
|
// size.
|
|
|
|
if (!CanResize()) {
|
|
|
|
*size = CalculatePreferredSize();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void CefWindowView::ViewHierarchyChanged(
|
2019-04-16 16:38:48 +02:00
|
|
|
const views::ViewHierarchyChangedDetails& details) {
|
2016-01-19 21:09:01 +01:00
|
|
|
if (details.child == this) {
|
|
|
|
// This View's parent types (RootView, ClientView) are not exposed via the
|
|
|
|
// CEF API. Therefore don't send notifications about this View's parent
|
|
|
|
// changes.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ParentClass::ViewHierarchyChanged(details);
|
|
|
|
}
|
|
|
|
|
2022-04-12 21:46:09 +02:00
|
|
|
void CefWindowView::OnWidgetActivationChanged(views::Widget* widget,
|
|
|
|
bool active) {
|
|
|
|
if (cef_delegate()) {
|
|
|
|
cef_delegate()->OnWindowActivationChanged(GetCefWindow(), active);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-28 03:55:15 +02:00
|
|
|
void CefWindowView::OnWidgetBoundsChanged(views::Widget* widget,
|
|
|
|
const gfx::Rect& new_bounds) {
|
|
|
|
MoveOverlaysIfNecessary();
|
2022-10-28 20:17:18 +02:00
|
|
|
|
|
|
|
if (cef_delegate()) {
|
|
|
|
cef_delegate()->OnWindowBoundsChanged(
|
|
|
|
GetCefWindow(), {new_bounds.x(), new_bounds.y(), new_bounds.width(),
|
|
|
|
new_bounds.height()});
|
|
|
|
}
|
2021-08-28 03:55:15 +02:00
|
|
|
}
|
|
|
|
|
2016-05-25 01:35:43 +02:00
|
|
|
display::Display CefWindowView::GetDisplay() const {
|
2016-01-19 21:09:01 +01:00
|
|
|
const views::Widget* widget = GetWidget();
|
|
|
|
if (widget) {
|
|
|
|
return view_util::GetDisplayMatchingBounds(
|
|
|
|
widget->GetWindowBoundsInScreen(), false);
|
|
|
|
}
|
2016-05-25 01:35:43 +02:00
|
|
|
return display::Display();
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2021-04-21 00:52:34 +02:00
|
|
|
void CefWindowView::SetTitle(const std::u16string& title) {
|
2016-01-19 21:09:01 +01:00
|
|
|
title_ = title;
|
|
|
|
views::Widget* widget = GetWidget();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (widget) {
|
2016-01-19 21:09:01 +01:00
|
|
|
widget->UpdateWindowTitle();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowView::SetWindowIcon(CefRefPtr<CefImage> window_icon) {
|
|
|
|
if (std::max(window_icon->GetWidth(), window_icon->GetHeight()) != 16U) {
|
|
|
|
DLOG(ERROR) << "Window icons must be 16 DIP in size.";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
window_icon_ = window_icon;
|
|
|
|
views::Widget* widget = GetWidget();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (widget) {
|
2016-01-19 21:09:01 +01:00
|
|
|
widget->UpdateWindowIcon();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowView::SetWindowAppIcon(CefRefPtr<CefImage> window_app_icon) {
|
|
|
|
window_app_icon_ = window_app_icon;
|
|
|
|
views::Widget* widget = GetWidget();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (widget) {
|
2016-01-19 21:09:01 +01:00
|
|
|
widget->UpdateWindowIcon();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
|
2021-08-28 03:55:15 +02:00
|
|
|
CefRefPtr<CefOverlayController> CefWindowView::AddOverlayView(
|
|
|
|
CefRefPtr<CefView> view,
|
2023-10-25 11:16:57 +02:00
|
|
|
cef_docking_mode_t docking_mode,
|
|
|
|
bool can_activate) {
|
2021-08-28 03:55:15 +02:00
|
|
|
DCHECK(view.get());
|
|
|
|
DCHECK(view->IsValid());
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!view.get() || !view->IsValid()) {
|
2021-08-28 03:55:15 +02:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-08-28 03:55:15 +02:00
|
|
|
|
|
|
|
views::Widget* widget = GetWidget();
|
|
|
|
if (widget) {
|
|
|
|
// Owned by the View hierarchy. Acts as a z-order reference for the overlay.
|
|
|
|
auto overlay_host_view = AddChildView(std::make_unique<views::View>());
|
|
|
|
|
|
|
|
overlay_hosts_.push_back(
|
|
|
|
std::make_unique<CefOverlayViewHost>(this, docking_mode));
|
|
|
|
|
|
|
|
auto& overlay_host = overlay_hosts_.back();
|
2023-10-25 11:16:57 +02:00
|
|
|
overlay_host->Init(overlay_host_view, view, can_activate);
|
2021-08-28 03:55:15 +02:00
|
|
|
|
|
|
|
return overlay_host->controller();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowView::MoveOverlaysIfNecessary() {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (overlay_hosts_.empty()) {
|
2021-08-28 03:55:15 +02:00
|
|
|
return;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2021-08-28 03:55:15 +02:00
|
|
|
for (auto& overlay_host : overlay_hosts_) {
|
|
|
|
overlay_host->MoveIfNecessary();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-12 00:32:08 +01:00
|
|
|
void CefWindowView::InvalidateExclusionRegions() {
|
|
|
|
if (last_dialog_top_inset_ != -1) {
|
|
|
|
last_dialog_top_y_ = last_dialog_top_inset_ = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
void CefWindowView::SetDraggableRegions(
|
|
|
|
const std::vector<CefDraggableRegion>& regions) {
|
2024-01-12 00:32:08 +01:00
|
|
|
if (regions.empty() && !draggable_region_) {
|
|
|
|
// Still empty.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
InvalidateExclusionRegions();
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
if (regions.empty()) {
|
2024-01-12 00:32:08 +01:00
|
|
|
draggable_region_.reset();
|
2023-04-12 20:34:39 +02:00
|
|
|
draggable_rects_.clear();
|
2016-01-19 21:09:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-01-20 23:48:57 +01:00
|
|
|
draggable_region_ = std::make_unique<SkRegion>();
|
2016-01-19 21:09:01 +01:00
|
|
|
for (const CefDraggableRegion& region : regions) {
|
|
|
|
draggable_region_->op(
|
2019-10-01 15:55:16 +02:00
|
|
|
{region.bounds.x, region.bounds.y,
|
|
|
|
region.bounds.x + region.bounds.width,
|
|
|
|
region.bounds.y + region.bounds.height},
|
2016-01-19 21:09:01 +01:00
|
|
|
region.draggable ? SkRegion::kUnion_Op : SkRegion::kDifference_Op);
|
2023-04-12 20:34:39 +02:00
|
|
|
|
|
|
|
if (region.draggable) {
|
2024-01-20 23:48:57 +01:00
|
|
|
draggable_rects_.emplace_back(region.bounds.x, region.bounds.y,
|
|
|
|
region.bounds.width, region.bounds.height);
|
2023-04-12 20:34:39 +02:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-12 00:32:08 +01:00
|
|
|
void CefWindowView::OnOverlayBoundsChanged() {
|
|
|
|
InvalidateExclusionRegions();
|
|
|
|
}
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
views::NonClientFrameView* CefWindowView::GetNonClientFrameView() const {
|
|
|
|
const views::Widget* widget = GetWidget();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!widget) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
|
|
|
if (!widget->non_client_view()) {
|
2016-01-19 21:09:01 +01:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2016-01-19 21:09:01 +01:00
|
|
|
return widget->non_client_view()->frame_view();
|
|
|
|
}
|
2023-04-12 20:34:39 +02:00
|
|
|
|
2024-01-12 00:32:08 +01:00
|
|
|
void CefWindowView::UpdateBoundingBox(gfx::Rect* bounds,
|
|
|
|
bool add_titlebar_height) const {
|
2023-04-12 20:34:39 +02:00
|
|
|
// Max distance from the edges of |bounds| to qualify for subtraction.
|
|
|
|
const int kMaxDistance = 10;
|
|
|
|
|
|
|
|
for (auto& overlay_host : overlay_hosts_) {
|
|
|
|
*bounds = SubtractOverlayFromBoundingBox(*bounds, overlay_host->bounds(),
|
|
|
|
kMaxDistance);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& rect : draggable_rects_) {
|
|
|
|
*bounds = SubtractOverlayFromBoundingBox(*bounds, rect, kMaxDistance);
|
|
|
|
}
|
|
|
|
|
2024-01-12 00:32:08 +01:00
|
|
|
if (auto titlebar_height = GetTitlebarHeight(add_titlebar_height)) {
|
2023-04-12 20:34:39 +02:00
|
|
|
gfx::Insets inset;
|
|
|
|
if (add_titlebar_height) {
|
|
|
|
inset.set_top(*titlebar_height);
|
|
|
|
} else if (bounds->y() < *titlebar_height) {
|
|
|
|
inset.set_top(*titlebar_height - bounds->y());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!inset.IsEmpty()) {
|
|
|
|
bounds->Inset(inset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-12 00:32:08 +01:00
|
|
|
void CefWindowView::UpdateFindBarBoundingBox(gfx::Rect* bounds) const {
|
|
|
|
#if BUILDFLAG(IS_MAC)
|
|
|
|
// For framed windows on macOS we must add the titlebar height.
|
|
|
|
const bool add_titlebar_height = !is_frameless_;
|
|
|
|
#else
|
|
|
|
const bool add_titlebar_height = false;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
UpdateBoundingBox(bounds, add_titlebar_height);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefWindowView::UpdateDialogTopInset(int* dialog_top_y) const {
|
|
|
|
if (*dialog_top_y == last_dialog_top_y_ && last_dialog_top_inset_ != -1) {
|
|
|
|
// Return the cached value.
|
|
|
|
*dialog_top_y = last_dialog_top_inset_;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const views::Widget* widget = GetWidget();
|
|
|
|
if (!widget) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfx::Rect bounds(widget->GetSize());
|
|
|
|
if (*dialog_top_y > 0) {
|
|
|
|
// Start with the value computed in
|
|
|
|
// BrowserViewLayout::LayoutBookmarkAndInfoBars.
|
|
|
|
gfx::Insets inset;
|
|
|
|
inset.set_top(*dialog_top_y);
|
|
|
|
bounds.Inset(inset);
|
|
|
|
}
|
|
|
|
|
|
|
|
UpdateBoundingBox(&bounds, /*add_titlebar_height=*/false);
|
|
|
|
|
|
|
|
last_dialog_top_y_ = *dialog_top_y;
|
|
|
|
last_dialog_top_inset_ = bounds.y();
|
|
|
|
|
|
|
|
*dialog_top_y = bounds.y();
|
|
|
|
}
|
|
|
|
|
2023-06-14 10:20:02 +02:00
|
|
|
views::Widget* CefWindowView::host_widget() const {
|
|
|
|
if (host_widget_destruction_observer_) {
|
|
|
|
return host_widget_destruction_observer_->widget();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2024-01-12 00:32:08 +01:00
|
|
|
std::optional<float> CefWindowView::GetTitlebarHeight(bool required) const {
|
2023-04-12 20:34:39 +02:00
|
|
|
if (cef_delegate()) {
|
|
|
|
float title_bar_height = 0;
|
|
|
|
const bool has_title_bar_height =
|
|
|
|
cef_delegate()->GetTitlebarHeight(GetCefWindow(), &title_bar_height);
|
|
|
|
if (has_title_bar_height) {
|
|
|
|
return title_bar_height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if BUILDFLAG(IS_MAC)
|
2024-01-12 00:32:08 +01:00
|
|
|
if (required) {
|
2023-04-12 20:34:39 +02:00
|
|
|
// For framed windows on macOS we must include the titlebar height in the
|
|
|
|
// UpdateFindBarBoundingBox() calculation.
|
|
|
|
return view_util::GetNSWindowTitleBarHeight(
|
|
|
|
const_cast<views::Widget*>(GetWidget()));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2024-01-12 00:32:08 +01:00
|
|
|
return std::nullopt;
|
2023-04-12 20:34:39 +02:00
|
|
|
}
|