Skip to content

CefDisplay

Header: cef_display.h
Category: Views Framework

Overview

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

CefDisplay

Source File: include/views/cef_display.h

Process / Thread Context: Browser Process / UI Thread.

Purpose: Represents a physical or virtual display. Provides geometry,

Methods

static CefRefPtr<CefDisplay> GetPrimaryDisplay()

Parameters:

  • none.

Return Value: The primary display.

Usage Instruction: Default positioning.

Threading Constraint: Browser process UI thread.

static CefRefPtr<CefDisplay> GetDisplayNearestPoint(const CefPoint& point, bool input_pixel_coords)

Parameters:

  • point: A point in screen coordinates.
  • input_pixel_coords: True if point is in pixel coordinates rather

Return Value: The display nearest the point.

Usage Instruction: Place a popup on the screen containing a given

Threading Constraint: Browser process UI thread.

static CefRefPtr<CefDisplay> GetDisplayMatchingBounds(const CefRect& bounds, bool input_pixel_coords)

Parameters:

  • bounds: A rectangle in screen coordinates.
  • input_pixel_coords: True if bounds is in pixel coordinates.

Return Value: The display that most closely intersects bounds.

Usage Instruction: Choose a display for window restoration.

Threading Constraint: Browser process UI thread.

static size_t GetDisplayCount()

Parameters:

  • none.

Return Value: Total number of distinct, usable displays (mirrored

Usage Instruction: Multi-monitor enumeration.

Threading Constraint: Browser process UI thread.

static void GetAllDisplays(std::vector<CefRefPtr<CefDisplay>>& displays)

Parameters:

  • displays: Out-vector populated with all distinct, usable displays.

Return Value: void.

Usage Instruction: Enumerate displays.

Threading Constraint: Browser process UI thread.

static CefPoint ConvertScreenPointToPixels(const CefPoint& point)

Parameters:

  • point: A point in DIP screen coordinates.

Return Value: The point converted to pixel screen coordinates. **Only

Usage Instruction: Convert before calling native Windows APIs that

Threading Constraint: Browser process UI thread.

static CefPoint ConvertScreenPointFromPixels(const CefPoint& point)

Parameters:

  • point: A point in pixel screen coordinates.

Return Value: The point converted to DIP screen coordinates. **Only

Usage Instruction: Convert results from native Windows APIs back to

Threading Constraint: Browser process UI thread.

static CefRect ConvertScreenRectToPixels(const CefRect& rect)

Parameters:

  • rect: A rectangle in DIP screen coordinates.

Return Value: The rectangle in pixel screen coordinates. **Only on

Usage Instruction: Rect variant of point conversion.

Threading Constraint: Browser process UI thread.

static CefRect ConvertScreenRectFromPixels(const CefRect& rect)

Parameters:

  • rect: A rectangle in pixel screen coordinates.

Return Value: The rectangle in DIP screen coordinates. **Only on

Usage Instruction: Rect variant of point conversion.

Threading Constraint: Browser process UI thread.

virtual int64_t GetID() = 0

Parameters:

  • none.

Return Value: Unique identifier for this display.

Usage Instruction: Persist display preferences by id.

Threading Constraint: Browser process UI thread.

virtual float GetDeviceScaleFactor() = 0

Parameters:

  • none.

Return Value: The device pixel scale factor (1.0 for ~100–120 DPI,

Usage Instruction: DPI-aware rendering decisions.

Threading Constraint: Browser process UI thread.

virtual void ConvertPointToPixels(CefPoint& point) = 0

Parameters:

  • point: In-out. Input is in DIP; output is in pixels for this display.

Return Value: void.

Usage Instruction: Display-local conversion.

Threading Constraint: Browser process UI thread.

virtual void ConvertPointFromPixels(CefPoint& point) = 0

Parameters:

  • point: In-out. Input is in pixels for this display; output is in DIP.

Return Value: void.

Usage Instruction: Display-local conversion.

Threading Constraint: Browser process UI thread.

virtual CefRect GetBounds() = 0

Parameters:

  • none.

Return Value: The full bounds of this display in DIP screen

Usage Instruction: Layout / placement.

Threading Constraint: Browser process UI thread.

virtual CefRect GetWorkArea() = 0

Parameters:

  • none.

Return Value: The work area (excluding taskbars / docks) in DIP

Usage Instruction: Place windows where they will not be obscured by

Threading Constraint: Browser process UI thread.

virtual int GetRotation() = 0

Parameters:

  • none.

Return Value: Display rotation in degrees (typically 0, 90, 180, 270).

Usage Instruction: Adjust rendering for rotated displays.

Threading Constraint: Browser process UI thread.

Usage Example

cpp
CefRefPtr<CefDisplay> primary = CefDisplay::GetPrimaryDisplay();
CefRect work = primary->GetWorkArea();
window->SetBounds(CefRect(
    work.x + 50, work.y + 50,
    std::min<int>(800, work.width - 100),
    std::min<int>(600, work.height - 100)));

LOG(INFO) << "Scale: " << primary->GetDeviceScaleFactor()
          << " Rotation: " << primary->GetRotation() << "°";

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