CefWindowDelegate
Header: cef_window_delegate.h
Category: Views Framework
Overview
Browser-process UI toolkit: windows, panels, layouts, buttons, textfields, and their delegates.
CefWindowDelegate
Source File: include/views/cef_window_delegate.h
Process / Thread Context: Browser Process / UI Thread.
Purpose: Client-implemented delegate interface for handling window events
Methods
virtual void OnWindowCreated(CefRefPtr<CefWindow> window)
Parameters:
window: The window that was just created.
Return Value: void.
Usage Instruction: Good place to build the view hierarchy, add child
Threading Constraint: Browser process UI thread.
virtual void OnWindowClosing(CefRefPtr<CefWindow> window)
Parameters:
window: The window that is about to close.
Return Value: void.
Usage Instruction: Last chance to perform cleanup while the window is
Threading Constraint: Browser process UI thread.
virtual void OnWindowDestroyed(CefRefPtr<CefWindow> window)
Parameters:
window: The window being destroyed.
Return Value: void. Release all references; do not call any methods on
Usage Instruction: Tear down references / state associated with the
Threading Constraint: Browser process UI thread.
virtual void OnWindowActivationChanged(CefRefPtr<CefWindow> window, bool active)
Parameters:
window: The window.active: True if now active, false if deactivated.
Return Value: void.
Usage Instruction: Update UI affordances that depend on activation.
Threading Constraint: Browser process UI thread.
virtual void OnWindowBoundsChanged(CefRefPtr<CefWindow> window, const CefRect& new_bounds)
Parameters:
window: The window.new_bounds: New bounds in DIP screen coordinates.
Return Value: void.
Usage Instruction: Persist window geometry or adjust overlays.
Threading Constraint: Browser process UI thread.
virtual void OnWindowFullscreenTransition(CefRefPtr<CefWindow> window, bool is_completed)
Parameters:
window: The window.is_completed: False at start of an async macOS transition; true after
Return Value: void.
Usage Instruction: Update UI when entering/leaving fullscreen. With
Threading Constraint: Browser process UI thread.
virtual CefRefPtr<CefWindow> GetParentWindow(CefRefPtr<CefWindow> window, bool* is_menu, bool* can_activate_menu)
Parameters:
window: The window being created.is_menu: Out-param — set to true if the window will be displayed as acan_activate_menu: Out-param — set to false ifis_menuis true and
Return Value: The parent window, or NULL for no parent. Parented
Usage Instruction: Create child windows / menus.
Threading Constraint: Browser process UI thread.
virtual bool IsWindowModalDialog(CefRefPtr<CefWindow> window)
Parameters:
window: The window.
Return Value: True to create the window as a window-modal dialog (only
Usage Instruction: Choose window-modal dialog style. For a
Threading Constraint: Browser process UI thread.
virtual CefRect GetInitialBounds(CefRefPtr<CefWindow> window)
Parameters:
window: The window being created.
Return Value: Initial bounds in DIP coordinates. If empty, the window
Usage Instruction: Restore saved geometry.
Threading Constraint: Browser process UI thread.
virtual cef_show_state_t GetInitialShowState(CefRefPtr<CefWindow> window)
Parameters:
window: The window.
Return Value: The initial show state. Default CEF_SHOW_STATE_NORMAL.
Usage Instruction: Start maximized / minimized / fullscreen.
Threading Constraint: Browser process UI thread.
virtual bool IsFrameless(CefRefPtr<CefWindow> window)
Parameters:
window: The window.
Return Value: True to create the window without a frame or title bar.
Usage Instruction: Frameless / chromeless windows.
Threading Constraint: Browser process UI thread.
virtual bool WithStandardWindowButtons(CefRefPtr<CefWindow> window)
Parameters:
window: The window.
Return Value: True to create the window with standard window buttons
Usage Instruction: macOS-specific window chrome configuration.
Threading Constraint: Browser process UI thread.
virtual bool GetTitlebarHeight(CefRefPtr<CefWindow> window, float* titlebar_height)
Parameters:
window: The window.titlebar_height: Out-param — set to the desired title bar height.
Return Value: True if the title bar height should be overridden. On
Usage Instruction: Custom title-bar heights.
Threading Constraint: Browser process UI thread.
virtual cef_state_t AcceptsFirstMouse(CefRefPtr<CefWindow> window)
Parameters:
window: The window.
Return Value: STATE_ENABLED to accept the initial mouse-down event,
Threading Constraint: Browser process UI thread.
virtual bool CanResize(CefRefPtr<CefWindow> window)
Parameters:
window: The window.
Return Value: True if the window can be resized. Default true.
Usage Instruction: Restrict resizing for fixed-size dialogs.
Threading Constraint: Browser process UI thread.
virtual bool CanMaximize(CefRefPtr<CefWindow> window)
Parameters:
window: The window.
Return Value: True if maximize is allowed. Default true.
Usage Instruction: Disable the maximize button.
Threading Constraint: Browser process UI thread.
virtual bool CanMinimize(CefRefPtr<CefWindow> window)
Parameters:
window: The window.
Return Value: True if minimize is allowed. Default true.
Usage Instruction: Disable the minimize button.
Threading Constraint: Browser process UI thread.
virtual bool CanClose(CefRefPtr<CefWindow> window)
Parameters:
window: The window.
Return Value: True if the window can be closed. Called for
Usage Instruction: Prompt "are you sure?" or wait for ongoing work to
Threading Constraint: Browser process UI thread.
virtual bool OnAccelerator(CefRefPtr<CefWindow> window, int command_id)
Parameters:
window: The window.command_id: The id registered viaCefWindow::SetAccelerator.
Return Value: True if the accelerator was handled.
Usage Instruction: Handle keyboard shortcuts.
Threading Constraint: Browser process UI thread.
virtual bool OnKeyEvent(CefRefPtr<CefWindow> window, const CefKeyEvent& event)
Parameters:
window: The window.event: The keyboard event.
Return Value: True if handled; false to allow default handling. Called
Usage Instruction: Last-resort keyboard event handler at the window
Threading Constraint: Browser process UI thread.
virtual void OnThemeColorsChanged(CefRefPtr<CefWindow> window, bool chrome_theme)
Parameters:
window: The window.chrome_theme: True if the notification is for a Chrome theme (vs.
Return Value: void. Theme colors are reset to standard values before
Usage Instruction: React to system dark/light mode changes or Chrome
Threading Constraint: Browser process UI thread.
virtual cef_runtime_style_t GetWindowRuntimeStyle()
Parameters:
- none.
Return Value: The runtime style for this window. Default
Usage Instruction: Choose between Alloy (native CEF) and Chrome styles.
Threading Constraint: Browser process UI thread.
virtual bool GetLinuxWindowProperties(CefRefPtr<CefWindow> window, CefLinuxWindowProperties& properties)
Parameters:
window: The window.properties: Out-param populated with Linux-specific window properties
Return Value: True if properties were provided.
Usage Instruction: Linux-only customization of WM hints.
Threading Constraint: Browser process UI thread.
Usage Example
class MyWindowDelegate : public CefWindowDelegate {
public:
void OnWindowCreated(CefRefPtr<CefWindow> window) override {
// Build the UI here, then show.
auto panel = CefPanel::CreatePanel(nullptr);
auto box = panel->SetToBoxLayout(CefBoxLayoutSettings{});
panel->AddChildView(CefLabelButton::CreateLabelButton(btn_del_, "Save"));
panel->AddChildView(CefTextfield::CreateTextfield(tf_del_));
window->AddChildView(panel);
window->CenterWindow(CefSize(480, 320));
window->Show();
}
bool CanResize(CefRefPtr<CefWindow>) override { return false; }
bool CanMaximize(CefRefPtr<CefWindow>) override { return false; }
bool IsFrameless(CefRefPtr<CefWindow>) override { return true; }
bool OnAccelerator(CefRefPtr<CefWindow>, int cmd) override {
if (cmd == IDC_SAVE) { SaveDocument(); return true; }
return false;
}
};