mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-01-19 13:11:13 +01:00
0b99f92e97
A modal dialog is a child CefWindow that implements some special behaviors relative to a parent CefWindow. Like any CefWindow it can be framed with titlebar or frameless, and optionally contain draggable regions (subject to platform limitations described below). Modal dialogs are shown centered on the parent window (inside a single display) and always stay on top of the parent window in z-order. Sizing behavior and available window buttons are controlled via the usual CefWindowDelegate callbacks. For example, the dialog can have a preferred size with resize, minimize and maximize disabled (via GetPreferredSize, CanResize, CanMinimize and CanMaximize respectively). This change adds support for two modality modes. With window modality all controls in the parent window are disabled. With browser modality only the browser view in the parent window is disabled. Both modality modes require that a valid parent window be returned via GetParentWindow. For window modality return true from IsWindowModalDialog and call CefWindow::Show. For browser modality return false from IsWindowModalDialog (the default value) and call CefWindow::ShowAsBrowserModalDialog with a reference to the parent window's browser view. Window modal dialog behavior depends on the platform. On Windows and Linux these dialogs have a titlebar and can be moved independent of the parent window. On macOS these dialogs do not have a titlebar, move with the parent window, and do not support draggable regions (because they are implemented using sheets). On Linux disabling the parent window controls requires a window manager the supports _NET_WM_STATE_MODAL. Browser modal dialog behavior is similar on all platforms. The dialog will be automatically sized and positioned relative to the parent window's browser view. Closing the parent window or navigating the parent browser view will dismiss the dialog. The dialog can also be moved independent of the parent window though it will be recentered when the parent window itself is resized or redisplayed. On MacOS the dialog will move along with the parent window while on Windows and Linux the parent window can be moved independently. To test: Use the Tests > Dialog Window menu option in cefclient with Views enabled (`--use-views` or `--enable-chrome-runtime` command-line flag). Browser modal dialog is the default behavior. For window modal dialog add the `--use-window-modal-dialog` command-line flag.
174 lines
6.0 KiB
C++
174 lines
6.0 KiB
C++
// 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_IMPL_H_
|
|
#define CEF_LIBCEF_BROWSER_VIEWS_WINDOW_IMPL_H_
|
|
#pragma once
|
|
|
|
#include <map>
|
|
|
|
#include "include/views/cef_window.h"
|
|
#include "include/views/cef_window_delegate.h"
|
|
|
|
#include "libcef/browser/menu_model_impl.h"
|
|
#include "libcef/browser/views/panel_impl.h"
|
|
#include "libcef/browser/views/window_view.h"
|
|
|
|
#include "ui/base/accelerators/accelerator.h"
|
|
#include "ui/views/controls/menu/menu_runner.h"
|
|
#include "ui/views/widget/widget.h"
|
|
|
|
namespace views {
|
|
class MenuButton;
|
|
}
|
|
|
|
class CefWindowImpl
|
|
: public CefPanelImpl<CefWindowView, CefWindow, CefWindowDelegate>,
|
|
public CefWindowView::Delegate,
|
|
public ui::AcceleratorTarget {
|
|
public:
|
|
using ParentClass = CefPanelImpl<CefWindowView, CefWindow, CefWindowDelegate>;
|
|
|
|
CefWindowImpl(const CefWindowImpl&) = delete;
|
|
CefWindowImpl& operator=(const CefWindowImpl&) = delete;
|
|
|
|
// Create a new CefWindow instance. |delegate| may be nullptr. |parent_widget|
|
|
// will be used when creating a Chrome child window.
|
|
static CefRefPtr<CefWindowImpl> Create(CefRefPtr<CefWindowDelegate> delegate,
|
|
gfx::AcceleratedWidget parent_widget);
|
|
|
|
// CefWindow methods:
|
|
void Show() override;
|
|
void ShowAsBrowserModalDialog(
|
|
CefRefPtr<CefBrowserView> browser_view) override;
|
|
void Hide() override;
|
|
void CenterWindow(const CefSize& size) override;
|
|
void Close() override;
|
|
bool IsClosed() override;
|
|
void Activate() override;
|
|
void Deactivate() override;
|
|
bool IsActive() override;
|
|
void BringToTop() override;
|
|
void SetAlwaysOnTop(bool on_top) override;
|
|
bool IsAlwaysOnTop() override;
|
|
void Maximize() override;
|
|
void Minimize() override;
|
|
void Restore() override;
|
|
void SetFullscreen(bool fullscreen) override;
|
|
bool IsMaximized() override;
|
|
bool IsMinimized() override;
|
|
bool IsFullscreen() override;
|
|
void SetTitle(const CefString& title) override;
|
|
CefString GetTitle() override;
|
|
void SetWindowIcon(CefRefPtr<CefImage> image) override;
|
|
CefRefPtr<CefImage> GetWindowIcon() override;
|
|
void SetWindowAppIcon(CefRefPtr<CefImage> image) override;
|
|
CefRefPtr<CefImage> GetWindowAppIcon() override;
|
|
CefRefPtr<CefOverlayController> AddOverlayView(
|
|
CefRefPtr<CefView> view,
|
|
cef_docking_mode_t docking_mode) override;
|
|
void ShowMenu(CefRefPtr<CefMenuModel> menu_model,
|
|
const CefPoint& screen_point,
|
|
cef_menu_anchor_position_t anchor_position) override;
|
|
void CancelMenu() override;
|
|
CefRefPtr<CefDisplay> GetDisplay() override;
|
|
CefRect GetClientAreaBoundsInScreen() override;
|
|
void SetDraggableRegions(
|
|
const std::vector<CefDraggableRegion>& regions) override;
|
|
CefWindowHandle GetWindowHandle() override;
|
|
void SendKeyPress(int key_code, uint32_t event_flags) override;
|
|
void SendMouseMove(int screen_x, int screen_y) override;
|
|
void SendMouseEvents(cef_mouse_button_type_t button,
|
|
bool mouse_down,
|
|
bool mouse_up) override;
|
|
void SetAccelerator(int command_id,
|
|
int key_code,
|
|
bool shift_pressed,
|
|
bool ctrl_pressed,
|
|
bool alt_pressed) override;
|
|
void RemoveAccelerator(int command_id) override;
|
|
void RemoveAllAccelerators() override;
|
|
|
|
// CefViewAdapter methods:
|
|
void Detach() override;
|
|
|
|
// CefPanel methods:
|
|
CefRefPtr<CefWindow> AsWindow() override { return this; }
|
|
|
|
// CefView methods:
|
|
void SetBounds(const CefRect& bounds) override;
|
|
CefRect GetBounds() override;
|
|
CefRect GetBoundsInScreen() override;
|
|
void SetSize(const CefSize& bounds) override;
|
|
void SetPosition(const CefPoint& position) override;
|
|
void SizeToPreferredSize() override;
|
|
void SetVisible(bool visible) override;
|
|
bool IsVisible() override;
|
|
bool IsDrawn() override;
|
|
void SetBackgroundColor(cef_color_t color) override;
|
|
|
|
// CefWindowView::Delegate methods:
|
|
bool CanWidgetClose() override;
|
|
void OnWindowClosing() override;
|
|
void OnWindowViewDeleted() override;
|
|
|
|
// CefViewAdapter methods:
|
|
std::string GetDebugType() override { return "Window"; }
|
|
void GetDebugInfo(base::Value::Dict* info, bool include_children) override;
|
|
|
|
// ui::AcceleratorTarget methods:
|
|
bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
|
|
bool CanHandleAccelerators() const override;
|
|
|
|
// Called for key events that have not been handled by other controls in the
|
|
// window. Returns true if the event was handled.
|
|
bool OnKeyEvent(const CefKeyEvent& event);
|
|
|
|
void ShowMenu(views::MenuButton* menu_button,
|
|
CefRefPtr<CefMenuModel> menu_model,
|
|
const CefPoint& screen_point,
|
|
cef_menu_anchor_position_t anchor_position);
|
|
void MenuClosed();
|
|
|
|
views::Widget* widget() const { return widget_; }
|
|
|
|
private:
|
|
// Create a new implementation object.
|
|
// Always call Initialize() after creation.
|
|
// |delegate| may be nullptr.
|
|
explicit CefWindowImpl(CefRefPtr<CefWindowDelegate> delegate);
|
|
|
|
// CefViewImpl methods:
|
|
CefWindowView* CreateRootView() override;
|
|
void InitializeRootView() override;
|
|
|
|
// Initialize the Widget.
|
|
void CreateWidget(gfx::AcceleratedWidget parent_widget);
|
|
|
|
views::Widget* widget_;
|
|
|
|
// True if the window has been destroyed.
|
|
bool destroyed_;
|
|
|
|
// The currently active menu model and runner.
|
|
CefRefPtr<CefMenuModelImpl> menu_model_;
|
|
std::unique_ptr<views::MenuRunner> menu_runner_;
|
|
|
|
// Map of command_id to accelerator.
|
|
using AcceleratorMap = std::map<int, ui::Accelerator>;
|
|
AcceleratorMap accelerator_map_;
|
|
|
|
#if defined(USE_AURA)
|
|
// Native widget's handler to receive events after the event target.
|
|
std::unique_ptr<ui::EventHandler> unhandled_key_event_handler_;
|
|
#endif
|
|
|
|
// True if this window was shown using ShowAsBrowserModalDialog().
|
|
bool shown_as_browser_modal_ = false;
|
|
|
|
IMPLEMENT_REFCOUNTING_DELETE_ON_UIT(CefWindowImpl);
|
|
};
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_VIEWS_WINDOW_IMPL_H_
|