CefTextfieldDelegate
Header: cef_textfield_delegate.h
Category: Views Framework
Overview
Browser-process UI toolkit: windows, panels, layouts, buttons, textfields, and their delegates.
CefTextfieldDelegate
Source File: include/views/cef_textfield_delegate.h
Process / Thread Context: Browser Process / UI Thread.
Purpose: Client-implemented delegate for Textfield events: keyboard event
Methods
virtual bool OnKeyEvent(CefRefPtr<CefTextfield> textfield, const CefKeyEvent& event)
Parameters:
textfield: The textfield that received the event.event: The keyboard event.
Return Value: True if the event was handled; false to allow default
Usage Instruction: Intercept special keys (e.g., Esc to clear, Enter
Threading Constraint: Browser process UI thread.
virtual void OnAfterUserAction(CefRefPtr<CefTextfield> textfield)
Parameters:
textfield: The textfield after a user action.
Return Value: void.
Usage Instruction: Update dependent UI (e.g., enable/disable a "Submit"
Threading Constraint: Browser process UI thread.
Usage Example
cpp
class SearchFieldDelegate : public CefTextfieldDelegate {
public:
bool OnKeyEvent(CefRefPtr<CefTextfield> tf, const CefKeyEvent& e) override {
if (e.type == KEYEVENT_RAWKEYDOWN && e.windows_key_code == VKEY_RETURN) {
SubmitSearch(tf->GetText());
return true;
}
return false;
}
void OnAfterUserAction(CefRefPtr<CefTextfield> tf) override {
bool has_text = !tf->GetText().empty();
submit_btn_->SetEnabled(has_text);
}
CefRefPtr<CefButton> submit_btn_;
};