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.
|
|
|
|
|
|
|
|
#ifndef CEF_LIBCEF_BROWSER_VIEWS_WINDOW_VIEW_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_VIEWS_WINDOW_VIEW_H_
|
|
|
|
#pragma once
|
|
|
|
|
2024-01-12 00:32:08 +01:00
|
|
|
#include <optional>
|
2021-08-28 03:55:15 +02:00
|
|
|
#include <vector>
|
|
|
|
|
2024-05-11 17:48:38 +02:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2024-05-13 23:36:09 +02:00
|
|
|
#include "base/memory/weak_ptr.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/include/views/cef_window.h"
|
|
|
|
#include "cef/include/views/cef_window_delegate.h"
|
|
|
|
#include "cef/libcef/browser/views/overlay_view_host.h"
|
|
|
|
#include "cef/libcef/browser/views/panel_view.h"
|
|
|
|
#include "cef/libcef/browser/views/widget_destruction_observer.h"
|
2021-06-04 03:34:56 +02:00
|
|
|
#include "third_party/skia/include/core/SkRegion.h"
|
2016-05-25 01:35:43 +02:00
|
|
|
#include "ui/display/display.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
#include "ui/views/widget/widget_delegate.h"
|
2021-08-28 03:55:15 +02:00
|
|
|
#include "ui/views/widget/widget_observer.h"
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// Manages the views-based root window. This object will be deleted
|
|
|
|
// automatically when the associated root window is destroyed.
|
2017-05-17 11:29:28 +02:00
|
|
|
class CefWindowView
|
2021-08-28 03:55:15 +02:00
|
|
|
: public CefPanelView<views::WidgetDelegateView, CefWindowDelegate>,
|
|
|
|
public views::WidgetObserver {
|
2016-01-19 21:09:01 +01:00
|
|
|
public:
|
2021-12-06 21:40:25 +01:00
|
|
|
using ParentClass =
|
|
|
|
CefPanelView<views::WidgetDelegateView, CefWindowDelegate>;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
class Delegate {
|
|
|
|
public:
|
|
|
|
// Returns true to signal that the Widget can be closed.
|
|
|
|
virtual bool CanWidgetClose() = 0;
|
|
|
|
|
2017-02-17 00:19:43 +01:00
|
|
|
// Called when the underlying platform window is closing.
|
|
|
|
virtual void OnWindowClosing() = 0;
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// Called when the WindowView is about to be deleted.
|
|
|
|
virtual void OnWindowViewDeleted() = 0;
|
|
|
|
|
|
|
|
protected:
|
2024-01-20 23:48:57 +01:00
|
|
|
virtual ~Delegate() = default;
|
2016-01-19 21:09:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// |cef_delegate| may be nullptr.
|
|
|
|
// |window_delegate| must be non-nullptr.
|
2017-05-17 11:29:28 +02:00
|
|
|
CefWindowView(CefWindowDelegate* cef_delegate, Delegate* window_delegate);
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2021-12-06 21:40:25 +01:00
|
|
|
CefWindowView(const CefWindowView&) = delete;
|
|
|
|
CefWindowView& operator=(const CefWindowView&) = delete;
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// Create the Widget.
|
2022-04-08 22:48:56 +02:00
|
|
|
void CreateWidget(gfx::AcceleratedWidget parent_widget);
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// Returns the CefWindow associated with this view. See comments on
|
|
|
|
// CefViewView::GetCefView.
|
|
|
|
CefRefPtr<CefWindow> GetCefWindow() const;
|
|
|
|
|
|
|
|
// views::WidgetDelegate methods:
|
|
|
|
bool CanMinimize() const override;
|
|
|
|
bool CanMaximize() const override;
|
2021-04-21 00:52:34 +02:00
|
|
|
std::u16string GetWindowTitle() const override;
|
2021-07-23 18:40:13 +02:00
|
|
|
ui::ImageModel GetWindowIcon() override;
|
|
|
|
ui::ImageModel GetWindowAppIcon() override;
|
2017-02-17 00:19:43 +01:00
|
|
|
void WindowClosing() override;
|
2016-01-19 21:09:01 +01:00
|
|
|
views::View* GetContentsView() override;
|
|
|
|
views::ClientView* CreateClientView(views::Widget* widget) override;
|
2020-08-29 00:39:23 +02:00
|
|
|
std::unique_ptr<views::NonClientFrameView> CreateNonClientFrameView(
|
2016-01-19 21:09:01 +01:00
|
|
|
views::Widget* widget) override;
|
|
|
|
bool ShouldDescendIntoChildForEventHandling(
|
|
|
|
gfx::NativeView child,
|
|
|
|
const gfx::Point& location) override;
|
2017-08-25 23:41:30 +02:00
|
|
|
bool MaybeGetMinimumSize(gfx::Size* size) const override;
|
|
|
|
bool MaybeGetMaximumSize(gfx::Size* size) const override;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// views::View methods:
|
|
|
|
void ViewHierarchyChanged(
|
2019-04-16 16:38:48 +02:00
|
|
|
const views::ViewHierarchyChangedDetails& details) override;
|
2024-03-29 17:48:33 +01:00
|
|
|
void OnThemeChanged() override;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2021-08-28 03:55:15 +02:00
|
|
|
// views::WidgetObserver methods:
|
2022-04-12 21:46:09 +02:00
|
|
|
void OnWidgetActivationChanged(views::Widget* widget, bool active) override;
|
2021-08-28 03:55:15 +02:00
|
|
|
void OnWidgetBoundsChanged(views::Widget* widget,
|
|
|
|
const gfx::Rect& new_bounds) override;
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// Returns the Display containing this Window.
|
2016-05-25 01:35:43 +02:00
|
|
|
display::Display GetDisplay() const;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// Set/get the window title.
|
2021-04-21 00:52:34 +02:00
|
|
|
void SetTitle(const std::u16string& title);
|
|
|
|
std::u16string title() const { return title_; }
|
2016-01-19 21:09:01 +01:00
|
|
|
|
|
|
|
// Set/get the window icon. This should be a 16x16 icon suitable for use in
|
|
|
|
// the Windows's title bar.
|
|
|
|
void SetWindowIcon(CefRefPtr<CefImage> window_icon);
|
|
|
|
CefRefPtr<CefImage> window_icon() const { return window_icon_; }
|
|
|
|
|
|
|
|
// Set/get the window app icon. This should be a larger icon for use in the
|
|
|
|
// host environment app switching UI. On Windows, this is the ICON_BIG used in
|
|
|
|
// Alt-Tab list and Windows taskbar. The Window icon will be used by default
|
|
|
|
// if no Window App icon is specified.
|
|
|
|
void SetWindowAppIcon(CefRefPtr<CefImage> window_app_icon);
|
|
|
|
CefRefPtr<CefImage> window_app_icon() const { return window_app_icon_; }
|
|
|
|
|
2021-08-28 03:55:15 +02:00
|
|
|
CefRefPtr<CefOverlayController> 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
|
|
|
|
2024-04-10 23:34:11 +02:00
|
|
|
// Called from CefOverlayViewHost::Cleanup().
|
|
|
|
void RemoveOverlayView(CefOverlayViewHost* host, views::View* host_view);
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// Set/get the draggable regions.
|
2017-05-17 11:29:28 +02:00
|
|
|
void SetDraggableRegions(const std::vector<CefDraggableRegion>& regions);
|
2016-01-19 21:09:01 +01:00
|
|
|
SkRegion* draggable_region() const { return draggable_region_.get(); }
|
|
|
|
|
2024-01-12 00:32:08 +01:00
|
|
|
// Called from CefOverlayViewHost::SetOverlayBounds().
|
|
|
|
void OnOverlayBoundsChanged();
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// Returns the NonClientFrameView for this Window. May be nullptr.
|
|
|
|
views::NonClientFrameView* GetNonClientFrameView() const;
|
|
|
|
|
2023-04-12 20:34:39 +02:00
|
|
|
// Optionally modify the bounding box for the Chrome Find bar.
|
|
|
|
void UpdateFindBarBoundingBox(gfx::Rect* bounds) const;
|
|
|
|
|
2024-01-12 00:32:08 +01:00
|
|
|
// Optionally modify the top inset for Chrome dialogs.
|
|
|
|
void UpdateDialogTopInset(int* dialog_top_y) const;
|
|
|
|
|
|
|
|
std::optional<float> GetTitlebarHeight(bool required) const;
|
2023-06-14 10:20:02 +02:00
|
|
|
bool IsFrameless() const { return is_frameless_; }
|
|
|
|
|
2024-03-29 17:48:33 +01:00
|
|
|
// Called before ThemeChanged() for native or Chrome theme changes.
|
|
|
|
void OnThemeColorsChanged(bool chrome_theme);
|
|
|
|
|
2023-06-14 10:20:02 +02:00
|
|
|
// The Widget that hosts us, if we're a modal dialog. May return nullptr
|
|
|
|
// during initialization and destruction.
|
|
|
|
views::Widget* host_widget() const;
|
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
bool IsAlloyStyle() const { return is_alloy_style_; }
|
|
|
|
bool IsChromeStyle() const { return !is_alloy_style_; }
|
|
|
|
|
2024-05-13 23:36:09 +02:00
|
|
|
Delegate* window_delegate() const { return window_delegate_.get(); }
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
private:
|
2024-04-10 23:34:11 +02:00
|
|
|
// Called after Widget teardown starts, before |this| is deleted.
|
2021-07-23 18:40:13 +02:00
|
|
|
void DeleteDelegate();
|
|
|
|
|
2021-08-28 03:55:15 +02:00
|
|
|
void MoveOverlaysIfNecessary();
|
2024-01-12 00:32:08 +01:00
|
|
|
void InvalidateExclusionRegions();
|
|
|
|
|
|
|
|
void UpdateBoundingBox(gfx::Rect* bounds, bool add_titlebar_height) const;
|
2021-08-28 03:55:15 +02:00
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// Not owned by this object.
|
2024-05-11 17:48:38 +02:00
|
|
|
raw_ptr<Delegate> window_delegate_;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2024-04-17 18:01:26 +02:00
|
|
|
// True if the window is Alloy style, otherwise Chrome style.
|
|
|
|
const bool is_alloy_style_;
|
|
|
|
|
2016-01-19 21:09:01 +01:00
|
|
|
// True if the window is frameless. It might still be resizable and draggable.
|
2023-06-14 10:20:02 +02:00
|
|
|
bool is_frameless_ = false;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2021-04-21 00:52:34 +02:00
|
|
|
std::u16string title_;
|
2016-01-19 21:09:01 +01:00
|
|
|
CefRefPtr<CefImage> window_icon_;
|
|
|
|
CefRefPtr<CefImage> window_app_icon_;
|
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<SkRegion> draggable_region_;
|
2023-04-12 20:34:39 +02:00
|
|
|
std::vector<gfx::Rect> draggable_rects_;
|
2016-01-19 21:09:01 +01:00
|
|
|
|
2024-01-12 00:32:08 +01:00
|
|
|
mutable int last_dialog_top_y_ = -1;
|
|
|
|
mutable int last_dialog_top_inset_ = -1;
|
|
|
|
|
2023-06-14 10:20:02 +02:00
|
|
|
// Tracks the Widget that hosts us, if we're a modal dialog.
|
|
|
|
std::unique_ptr<WidgetDestructionObserver> host_widget_destruction_observer_;
|
|
|
|
|
2021-08-28 03:55:15 +02:00
|
|
|
// Hosts for overlay widgets.
|
2024-05-13 23:36:09 +02:00
|
|
|
std::vector<raw_ptr<CefOverlayViewHost>> overlay_hosts_;
|
|
|
|
|
|
|
|
base::WeakPtrFactory<CefWindowView> weak_ptr_factory_{this};
|
2016-01-19 21:09:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_VIEWS_WINDOW_VIEW_H_
|