Skip to content

CefViewDelegate

Header: cef_view_delegate.h
Category: Views Framework

Overview

Browser-process UI toolkit: windows, panels, layouts, buttons, textfields, and their delegates.

CefViewDelegate

Source File: include/views/cef_view_delegate.h

Process / Thread Context: Browser Process / UI Thread. Header states:

Purpose: Client-implemented delegate interface for receiving view events

Methods

virtual CefSize GetPreferredSize(CefRefPtr<CefView> view)

Parameters:

  • view: The view whose preferred size is being queried.

Return Value: The preferred size. Default returns empty CefSize.

Usage Instruction: Override to provide a custom preferred size; used by

Threading Constraint: Browser process UI thread.

virtual CefSize GetMinimumSize(CefRefPtr<CefView> view)

Parameters:

  • view: The view whose minimum size is being queried.

Return Value: The minimum size; default empty.

Usage Instruction: Override to enforce a minimum.

Threading Constraint: Browser process UI thread.

virtual CefSize GetMaximumSize(CefRefPtr<CefView> view)

Parameters:

  • view: The view whose maximum size is being queried.

Return Value: The maximum size; default empty.

Usage Instruction: Override to enforce a maximum.

Threading Constraint: Browser process UI thread.

virtual int GetHeightForWidth(CefRefPtr<CefView> view, int width)

Parameters:

  • view: The view being queried.
  • width: The width to compute the height for.

Return Value: The desired height for the given width. Default 0, which

Usage Instruction: Override for widgets whose preferred height depends

Threading Constraint: Browser process UI thread.

virtual void OnParentViewChanged(CefRefPtr<CefView> view, bool added, CefRefPtr<CefView> parent)

Parameters:

  • view: The view whose parent changed.
  • added: True if being added to parent, false if removed.
  • parent: The parent view involved in the change.

Return Value: void.

Usage Instruction: Reparenting notifications. **Do not modify the view

Threading Constraint: Browser process UI thread.

virtual void OnChildViewChanged(CefRefPtr<CefView> view, bool added, CefRefPtr<CefView> child)

Parameters:

  • view: The view whose children changed.
  • added: True if child was added, false if removed.
  • child: The child view involved.

Return Value: void.

Usage Instruction: Notifications on hierarchy changes. **Do not modify

Threading Constraint: Browser process UI thread.

virtual void OnWindowChanged(CefRefPtr<CefView> view, bool added)

Parameters:

  • view: The view being added to or removed from a window.
  • added: True if added, false if removed.

Return Value: void.

Usage Instruction: Useful to lazily initialize things once the view is

Threading Constraint: Browser process UI thread.

virtual void OnLayoutChanged(CefRefPtr<CefView> view, const CefRect& new_bounds)

Parameters:

  • view: The view that was laid out.
  • new_bounds: The new bounds (DIP) of the view.

Return Value: void.

Usage Instruction: Update overlay positions or dependent UI when this

Threading Constraint: Browser process UI thread.

virtual void OnFocus(CefRefPtr<CefView> view)

Parameters:

  • view: The view that gained focus.

Return Value: void.

Usage Instruction: Update visuals / state on focus gain.

Threading Constraint: Browser process UI thread.

virtual void OnBlur(CefRefPtr<CefView> view)

Parameters:

  • view: The view that lost focus.

Return Value: void.

Usage Instruction: Update visuals / state on focus loss.

Threading Constraint: Browser process UI thread.

virtual void OnThemeChanged(CefRefPtr<CefView> view)

Parameters:

  • view: The view whose theme changed. Children are notified before

Return Value: void.

Usage Instruction: Optionally override per-View theme colors by calling

Threading Constraint: Browser process UI thread.

Usage Example

cpp
class MyPanelDelegate : public CefPanelDelegate {
 public:
  CefSize GetPreferredSize(CefRefPtr<CefView> view) override {
    return CefSize(320, 200);  // fixed-size panel
  }

  void OnLayoutChanged(CefRefPtr<CefView> view, const CefRect& new_bounds) override {
    LOG(INFO) << "panel laid out at " << new_bounds.ToString();
  }

  void OnFocus(CefRefPtr<CefView> view) override {
    LOG(INFO) << "panel gained focus";
  }
};

Derived from the CEF C++ headers — © Marshall A. Greenblatt, Google Inc. & contributors (BSD-style license). Not an official CEF project.