Skip to content

CefMenuButton

Header: cef_menu_button.h
Category: Views Framework

Overview

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

CefMenuButton

Source File: include/views/cef_menu_button.h

Process / Thread Context: Browser Process / UI Thread.

Purpose: A button that shows a menu when clicked with the left mouse

Methods

static CefRefPtr<CefMenuButton> CreateMenuButton(CefRefPtr<CefMenuButtonDelegate> delegate, const CefString& text)

Parameters:

  • delegate: A CefMenuButtonDelegate that calls ShowMenu() when the
  • text: Initial text and default accessible name.

Return Value: A new MenuButton. The header documents that with_frame

Usage Instruction: Static factory for menu trigger buttons.

Threading Constraint: Browser process UI thread.

virtual void ShowMenu(CefRefPtr<CefMenuModel> menu_model, const CefPoint& screen_point, cef_menu_anchor_position_t anchor_position) = 0

Parameters:

  • menu_model: The menu contents.
  • screen_point: Menu position in screen coordinates.
  • anchor_position: How the menu anchors relative to screen_point.

Return Value: void.

Usage Instruction: Should be called from

Threading Constraint: Browser process UI thread.

virtual void TriggerMenu() = 0

Parameters:

  • none.

Return Value: void. Results in a call to

Usage Instruction: Programmatically open the menu (e.g., from a

Threading Constraint: Browser process UI thread.

Usage Example

cpp
auto menu = CefMenuModel::CreateMenuModel(menu_proxy);
menu->AddItem(1, "Open");
menu->AddItem(2, "Save");
menu->AddSeparator();
menu->AddItem(3, "Exit");

auto menu_btn = CefMenuButton::CreateMenuButton(new MyMenuBtnDelegate(), "File");
panel->AddChildView(menu_btn);

// In MyMenuBtnDelegate::OnMenuButtonPressed:
//   button->ShowMenu(menu, screen_point, CEF_MENU_ANCHOR_TOPLEFT);

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