Skip to content

CefTextfield

Header: cef_textfield.h
Category: Views Framework

Overview

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

CefTextfield

Source File: include/views/cef_textfield.h

Process / Thread Context: Browser Process / UI Thread.

Purpose: A custom-rendered text input control (no platform-specific native

Methods

static CefRefPtr<CefTextfield> CreateTextfield(CefRefPtr<CefTextfieldDelegate> delegate)

Parameters:

  • delegate: Optional CefTextfieldDelegate.

Return Value: A new Textfield.

Usage Instruction: Static factory.

Threading Constraint: Browser process UI thread.

virtual void SetPasswordInput(bool password_input) = 0

Parameters:

  • password_input: True to display text as asterisks.

Return Value: void.

Usage Instruction: For password / secret entry.

Threading Constraint: Browser process UI thread.

virtual bool IsPasswordInput() = 0

Parameters:

  • none.

Return Value: True if password input mode is active.

Usage Instruction: Query mode.

Threading Constraint: Browser process UI thread.

virtual void SetReadOnly(bool read_only) = 0

Parameters:

  • read_only: True to make the field read-only.

Return Value: void.

Usage Instruction: Display non-editable text.

Threading Constraint: Browser process UI thread.

virtual bool IsReadOnly() = 0

Parameters:

  • none.

Return Value: True if read-only.

Usage Instruction: Query mode.

Threading Constraint: Browser process UI thread.

virtual CefString GetText() = 0

Parameters:

  • none.

Return Value: The currently displayed text.

Usage Instruction: Read content.

Threading Constraint: Browser process UI thread.

virtual void SetText(const CefString& text) = 0

Parameters:

  • text: New contents. If the cursor is outside the new range it is

Return Value: void.

Usage Instruction: Replace entire contents.

Threading Constraint: Browser process UI thread.

virtual void AppendText(const CefString& text) = 0

Parameters:

  • text: Text to append.

Return Value: void.

Usage Instruction: Append to existing content.

Threading Constraint: Browser process UI thread.

virtual void InsertOrReplaceText(const CefString& text) = 0

Parameters:

  • text: Text to insert.

Return Value: void. Replaces any currently selected text, or inserts

Usage Instruction: Insertion while preserving undo history.

Threading Constraint: Browser process UI thread.

virtual bool HasSelection() = 0

Parameters:

  • none.

Return Value: True if there is any selected text.

Usage Instruction: Conditional copy/cut operations.

Threading Constraint: Browser process UI thread.

virtual CefString GetSelectedText() = 0

Parameters:

  • none.

Return Value: The currently selected text.

Usage Instruction: Implement copy.

Threading Constraint: Browser process UI thread.

virtual void SelectAll(bool reversed) = 0

Parameters:

  • reversed: If true the selection ends at the logical beginning,

Return Value: void.

Usage Instruction: Select-all behavior.

Threading Constraint: Browser process UI thread.

virtual void ClearSelection() = 0

Parameters:

  • none.

Return Value: void. Clears selection, caret goes to end.

Usage Instruction: Remove selection.

Threading Constraint: Browser process UI thread.

virtual CefRange GetSelectedRange() = 0

Parameters:

  • none.

Return Value: The selected logical text range (UTF-16 code unit

Usage Instruction: Range introspection.

Threading Constraint: Browser process UI thread.

virtual void SelectRange(const CefRange& range) = 0

Parameters:

  • range: The logical range to select.

Return Value: void.

Usage Instruction: Programmatic selection.

Threading Constraint: Browser process UI thread.

virtual size_t GetCursorPosition() = 0

Parameters:

  • none.

Return Value: Selection background color.

Usage Instruction: Legacy.

Threading Constraint: Browser process UI thread.

virtual void SetFontList(const CefString& font_list) = 0

Parameters:

  • font_list: Font description string (same format as

Return Value: void.

Usage Instruction: Set the field's font.

Threading Constraint: Browser process UI thread.

virtual void ApplyTextColor(cef_color_t color, const CefRange& range) = 0

Parameters:

  • color: The color to apply.
  • range: The logical range. If empty, the color is applied to the entire

Return Value: void. Does not change the default text color.

Usage Instruction: Range-specific coloring (e.g., syntax

Threading Constraint: Browser process UI thread.

virtual void ApplyTextStyle(cef_text_style_t style, bool add, const CefRange& range) = 0

Parameters:

  • style: The style to apply (e.g., bold, italic, underline, strike).
  • add: True to add the style; false to remove it.
  • range: The logical range; empty means the entire contents.

Return Value: void. Does not change the default style.

Usage Instruction: Range-specific styling.

Threading Constraint: Browser process UI thread.

virtual bool IsCommandEnabled(cef_text_field_commands_t command_id) = 0

Return Value: True if the command is currently enabled.

Usage Instruction: Update menu item enable state.

Threading Constraint: Browser process UI thread.

virtual void ExecuteCommand(cef_text_field_commands_t command_id) = 0

Parameters:

  • command_id: The command to execute.

Return Value: void.

Usage Instruction: Trigger edit commands from menu items /

Threading Constraint: Browser process UI thread.

virtual void ClearEditHistory() = 0

Parameters:

  • none.

Return Value: void.

Usage Instruction: Clear undo/redo history (e.g., after

Threading Constraint: Browser process UI thread.

virtual void SetPlaceholderText(const CefString& text) = 0

Parameters:

  • text: Placeholder text shown when the field is empty.

Return Value: void.

Usage Instruction: Provide input hints.

Threading Constraint: Browser process UI thread.

virtual CefString GetPlaceholderText() = 0

Parameters:

  • color: Color for the placeholder text.

Return Value: void.

Usage Instruction: Legacy.

Threading Constraint: Browser process UI thread.

virtual void SetAccessibleName(const CefString& name) = 0

Parameters:

  • name: The accessible name for AT.

Return Value: void.

Usage Instruction: Screen-reader labeling (especially useful when no

Threading Constraint: Browser process UI thread.

Usage Example

cpp
auto tf = CefTextfield::CreateTextfield(new MyTfDelegate());
tf->SetPlaceholderText("Enter search query...");
tf->SetFontList("Segoe UI, 14px");
tf->SetAccessibleName("Search field");
tf->ApplyTextColor(cef_color_set_argb(255, 200, 0, 0), CefRange(0, 5));
panel->AddChildView(tf);

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