CefView
Header: cef_view.h
Category: Views Framework
Overview
Browser-process UI toolkit: windows, panels, layouts, buttons, textfields, and their delegates.
CefView
Source File: include/views/cef_view.h
Process / Thread Context: Browser Process / UI Thread. Header explicitly states:
Purpose: Base class for all Views. A CefView represents a rectangle within
Methods
virtual CefRefPtr<CefBrowserView> AsBrowserView() = 0
Parameters:
- none.
Return Value: Returns this view cast to CefBrowserView, or NULL if
Usage Instruction: Use for safe down-casting when a generic CefView
Threading Constraint: Must be called on the browser process UI thread.
virtual CefRefPtr<CefButton> AsButton() = 0
Parameters:
- none.
Return Value: This view as CefButton, or NULL.
Usage Instruction: Down-cast helper.
Threading Constraint: Must be called on the browser process UI thread.
virtual CefRefPtr<CefPanel> AsPanel() = 0
Parameters:
- none.
Return Value: This view as CefPanel, or NULL.
Usage Instruction: Down-cast helper. Windows are also Panels.
Threading Constraint: Must be called on the browser process UI thread.
virtual CefRefPtr<CefScrollView> AsScrollView() = 0
Parameters:
- none.
Return Value: This view as CefScrollView, or NULL.
Usage Instruction: Down-cast helper.
Threading Constraint: Must be called on the browser process UI thread.
virtual CefRefPtr<CefTextfield> AsTextfield() = 0
Parameters:
- none.
Return Value: This view as CefTextfield, or NULL.
Usage Instruction: Down-cast helper.
Threading Constraint: Must be called on the browser process UI thread.
virtual CefString GetTypeString() = 0
Parameters:
- none.
Return Value: The type of this view as a string (e.g., "Window",
Usage Instruction: Used primarily for testing and logging.
Threading Constraint: Must be called on the browser process UI thread.
virtual CefString ToString(bool include_children) = 0
Parameters:
include_children: If true, child views are also included in the
Return Value: A string representation of the view, including type and
Usage Instruction: Diagnostic / testing only.
Threading Constraint: Must be called on the browser process UI thread.
virtual bool IsValid() = 0
Parameters:
- none.
Return Value: True if the view is valid.
Usage Instruction: Verify a view pointer is still alive before use.
Threading Constraint: Must be called on the browser process UI thread.
virtual bool IsAttached() = 0
Parameters:
- none.
Return Value: True if this view is currently attached to a parent. A
Usage Instruction: Check before reparenting.
Threading Constraint: Must be called on the browser process UI thread.
virtual bool IsSame(CefRefPtr<CefView> that) = 0
Parameters:
that: Another view to compare against.
Return Value: True if that is the same underlying view as this.
Usage Instruction: Identity comparison (two CefRefPtrs may wrap the
Threading Constraint: Must be called on the browser process UI thread.
virtual CefRefPtr<CefViewDelegate> GetDelegate() = 0
Parameters:
- none.
Return Value: The delegate associated with this view, if any (may be
Usage Instruction: Retrieve the client-provided delegate.
Threading Constraint: Must be called on the browser process UI thread.
virtual CefRefPtr<CefWindow> GetWindow() = 0
Parameters:
- none.
Return Value: The top-level Window hosting this view, or NULL if not yet
Usage Instruction: Walk up to the root window.
Threading Constraint: Must be called on the browser process UI thread.
virtual int GetID() = 0
Parameters:
- none.
Return Value: The view's integer ID. Default is 0.
Usage Instruction: Pair with GetViewForID to locate children by ID.
Threading Constraint: Must be called on the browser process UI thread.
virtual void SetID(int id) = 0
Parameters:
id: An integer ID that should be unique within the subtree where it will
Return Value: void.
Usage Instruction: Tag views so they can be located via GetViewForID.
Threading Constraint: Must be called on the browser process UI thread.
virtual int GetGroupID() = 0
Parameters:
- none.
Return Value: The group id, or -1 if not set.
Usage Instruction: Group-related focus traversal.
Threading Constraint: Must be called on the browser process UI thread.
virtual void SetGroupID(int group_id) = 0
Parameters:
group_id: Identifier for the focus group. Immutable once set.
Return Value: void.
Usage Instruction: Allows arrow-key focus movement between views with the
Threading Constraint: Must be called on the browser process UI thread.
virtual CefRefPtr<CefView> GetParentView() = 0
Parameters:
- none.
Return Value: The containing view, or NULL if unattached.
Usage Instruction: Walk up the view tree.
Threading Constraint: Must be called on the browser process UI thread.
virtual CefRefPtr<CefView> GetViewForID(int id) = 0
Parameters:
id: The id to search for.
Return Value: The first descendant (depth-first) with that id, or NULL.
Usage Instruction: Locate a previously tagged child view.
Threading Constraint: Must be called on the browser process UI thread.
virtual void SetBounds(const CefRect& bounds) = 0
Parameters:
bounds: New size and position in parent coordinates (or DIP screen
Return Value: void.
Usage Instruction: Direct geometry manipulation; normally layouts do
Threading Constraint: Must be called on the browser process UI thread.
virtual CefRect GetBounds() = 0
Parameters:
- none.
Return Value: Bounds in parent coordinates, or DIP screen coordinates if
Usage Instruction: Read geometry.
Threading Constraint: Must be called on the browser process UI thread.
virtual CefRect GetBoundsInScreen() = 0
Parameters:
- none.
Return Value: Bounds in DIP screen coordinates.
Usage Instruction: Position popups/menus relative to the view.
Threading Constraint: Must be called on the browser process UI thread.
virtual void SetSize(const CefSize& size) = 0
Parameters:
size: New size in parent coordinates (or DIP screen if no parent).
Return Value: void.
Usage Instruction: Resize without moving.
Threading Constraint: Must be called on the browser process UI thread.
virtual CefSize GetSize() = 0
Parameters:
- none.
Return Value: Current size.
Usage Instruction: Read size.
Threading Constraint: Must be called on the browser process UI thread.
virtual void SetPosition(const CefPoint& position) = 0
Parameters:
position: New position in parent coordinates (or DIP screen if no parent).
Return Value: void.
Usage Instruction: Move without resizing.
Threading Constraint: Must be called on the browser process UI thread.
virtual CefPoint GetPosition() = 0
Parameters:
- none.
Return Value: Current position.
Usage Instruction: Read position.
Threading Constraint: Must be called on the browser process UI thread.
virtual void SetInsets(const CefInsets& insets) = 0
Parameters:
insets: Insets in parent coordinates (or DIP screen if no parent).
Return Value: void.
Usage Instruction: Pad a view's contents.
Threading Constraint: Must be called on the browser process UI thread.
virtual CefInsets GetInsets() = 0
Parameters:
- none.
Return Value: Current insets.
Usage Instruction: Read insets.
Threading Constraint: Must be called on the browser process UI thread.
virtual CefSize GetPreferredSize() = 0
Parameters:
- none.
Return Value: The size this view would like to be if enough space is
Usage Instruction: Used by layouts to compute child sizes.
Threading Constraint: Must be called on the browser process UI thread.
virtual void SizeToPreferredSize() = 0
Parameters:
- none.
Return Value: void.
Usage Instruction: Resize this view to its preferred size.
Threading Constraint: Must be called on the browser process UI thread.
virtual CefSize GetMinimumSize() = 0
Parameters:
- none.
Return Value: Minimum size.
Usage Instruction: Used by layouts.
Threading Constraint: Must be called on the browser process UI thread.
virtual CefSize GetMaximumSize() = 0
Parameters:
- none.
Return Value: Maximum size.
Usage Instruction: Used by layouts.
Threading Constraint: Must be called on the browser process UI thread.
virtual int GetHeightForWidth(int width) = 0
Parameters:
width: The width to compute a height for.
Return Value: Height necessary to display this view at the given width.
Usage Instruction: Useful for labels and other flow-style content.
Threading Constraint: Must be called on the browser process UI thread.
virtual void InvalidateLayout() = 0
Parameters:
- none.
Return Value: void.
Usage Instruction: Force a re-layout on this view and all parents even
Threading Constraint: Must be called on the browser process UI thread.
virtual void SetVisible(bool visible) = 0
Parameters:
visible: True to show, false to hide.
Return Value: void. If hidden, the view and any focused descendant lose
Usage Instruction: Hide/show widgets. Windows are hidden by default;
Threading Constraint: Must be called on the browser process UI thread.
virtual bool IsVisible() = 0
Parameters:
- none.
Return Value: True if this view is visible (does not guarantee it is
Usage Instruction: Check visibility flag.
Threading Constraint: Must be called on the browser process UI thread.
virtual bool IsDrawn() = 0
Parameters:
- none.
Return Value: True if this view is visible and all of its parents are
Usage Instruction: Determine actual on-screen presence.
Threading Constraint: Must be called on the browser process UI thread.
virtual void SetEnabled(bool enabled) = 0
Parameters:
enabled: True to enable.
Return Value: void. Disabled views do not receive keyboard/mouse input
Usage Instruction: Disable buttons / text fields conditionally.
Threading Constraint: Must be called on the browser process UI thread.
virtual bool IsEnabled() = 0
Parameters:
- none.
Return Value: True if enabled.
Usage Instruction: Query enabled state.
Threading Constraint: Must be called on the browser process UI thread.
virtual void SetFocusable(bool focusable) = 0
Parameters:
focusable: True to allow this view to take focus.
Return Value: void. Clears focus if currently focused and made
Usage Instruction: Mark leaf widgets as focusable.
Threading Constraint: Must be called on the browser process UI thread.
virtual bool IsFocusable() = 0
Parameters:
- none.
Return Value: True if this view is focusable, enabled and drawn.
Usage Instruction: Combined focusability check.
Threading Constraint: Must be called on the browser process UI thread.
virtual bool IsAccessibilityFocusable() = 0
Parameters:
- none.
Return Value: True if this view is focusable when full keyboard access
Usage Instruction: Accessibility-related focusability.
Threading Constraint: Must be called on the browser process UI thread.
virtual bool HasFocus() = 0
Parameters:
- none.
Return Value: True if this view currently has focus within its
Usage Instruction: Detect if a specific widget is focused.
Threading Constraint: Must be called on the browser process UI thread.
virtual void RequestFocus() = 0
Parameters:
- none.
Return Value: void. If focusable, becomes the focused view of the
Usage Instruction: Programmatically move focus.
Threading Constraint: Must be called on the browser process UI thread.
virtual void SetBackgroundColor(cef_color_t color) = 0
Parameters:
color: The new background color. Reset onOnThemeChanged.
Return Value: void.
Usage Instruction: Override background; usually overridden per-theme.
Threading Constraint: Must be called on the browser process UI thread.
virtual cef_color_t GetBackgroundColor() = 0
Parameters:
- none.
Return Value: The background color, or GetThemeColor(CEF_ColorPrimaryBackground)
Usage Instruction: Query background color.
Threading Constraint: Must be called on the browser process UI thread.
virtual cef_color_t GetThemeColor(int color_id) = 0
Parameters:
color_id: A color id fromcef_color_ids.hor a custom id >=
Return Value: The current theme color, or placeholder red if unset.
Usage Instruction: Query theme colors; use CefWindow::SetThemeColor
Threading Constraint: Must be called on the browser process UI thread.
virtual bool ConvertPointToScreen(CefPoint& point) = 0
Parameters:
point: In-out; on input, a point in this view's coordinates; on output,
Return Value: True if conversion succeeded. Requires this view to
Usage Instruction: Position popups, menus, tooltips.
Threading Constraint: Must be called on the browser process UI thread.
virtual bool ConvertPointFromScreen(CefPoint& point) = 0
Parameters:
point: In-out; on input a point in DIP screen coordinates; on output a
Return Value: True on success.
Usage Instruction: Translate screen coords into view-local coords
Threading Constraint: Must be called on the browser process UI thread.
virtual bool ConvertPointToWindow(CefPoint& point) = 0
Parameters:
point: In-out; converted from this view's coordinate system to the
Return Value: True on success.
Usage Instruction: Translate to window-local coordinates.
Threading Constraint: Must be called on the browser process UI thread.
virtual bool ConvertPointFromWindow(CefPoint& point) = 0
Parameters:
point: In-out; converted from window coords to this view's coords.
Return Value: True on success.
Usage Instruction: Translate window-local coords to view-local.
Threading Constraint: Must be called on the browser process UI thread.
virtual bool ConvertPointToView(CefRefPtr<CefView> view, CefPoint& point) = 0
Parameters:
view: The target view. Must be in the same window (need not be in thepoint: In-out point in this view's coordinate system; output is in
Return Value: True on success.
Usage Instruction: Translate coordinates between arbitrary views in
Threading Constraint: Must be called on the browser process UI thread.
virtual bool ConvertPointFromView(CefRefPtr<CefView> view, CefPoint& point) = 0
Parameters:
view: The source view (must be in the same window).point: In-out point inview's coordinate system; output is in this
Return Value: True on success.
Usage Instruction: Reverse direction of ConvertPointToView.
Threading Constraint: Must be called on the browser process UI thread.
Usage Example
// Generic view introspection — given a CefRefPtr<CefView> from a delegate
// callback, branch on its concrete type.
void InspectView(CefRefPtr<CefView> view) {
if (!view || !view->IsValid()) return;
LOG(INFO) << view->GetTypeString() << " id=" << view->GetID();
if (auto btn = view->AsButton()) {
btn->SetEnabled(false);
} else if (auto panel = view->AsPanel()) {
panel->Layout();
}
// Convert the view's origin into screen coordinates for a popup menu.
CefPoint origin(0, 0);
if (view->ConvertPointToScreen(origin)) {
// Show a popup at the view's top-left.
}
}