views: Add support for accelerators (issue #2102)

This commit is contained in:
Marshall Greenblatt
2017-02-16 18:19:43 -05:00
parent e4867b5afb
commit bd1b80198f
35 changed files with 948 additions and 74 deletions

View File

@@ -63,6 +63,18 @@ typedef struct _cef_browser_view_t {
///
struct _cef_browser_t* (CEF_CALLBACK *get_browser)(
struct _cef_browser_view_t* self);
///
// Sets whether accelerators registered with cef_window_t::SetAccelerator are
// triggered before or after the event is sent to the cef_browser_t. If
// |prefer_accelerators| is true (1) then the matching accelerator will be
// triggered immediately and the event will not be sent to the cef_browser_t.
// If |prefer_accelerators| is false (0) then the matching accelerator will
// only be triggered if the event is not handled by web content or by
// cef_keyboard_handler_t. The default value is false (0).
///
void (CEF_CALLBACK *set_prefer_accelerators)(struct _cef_browser_view_t* self,
int prefer_accelerators);
} cef_browser_view_t;

View File

@@ -269,6 +269,27 @@ typedef struct _cef_window_t {
///
void (CEF_CALLBACK *send_mouse_events)(struct _cef_window_t* self,
cef_mouse_button_type_t button, int mouse_down, int mouse_up);
///
// Set the keyboard accelerator for the specified |command_id|. |key_code| can
// be any virtual key or character value. cef_window_delegate_t::OnAccelerator
// will be called if the keyboard combination is triggered while this window
// has focus.
///
void (CEF_CALLBACK *set_accelerator)(struct _cef_window_t* self,
int command_id, int key_code, int shift_pressed, int ctrl_pressed,
int alt_pressed);
///
// Remove the keyboard accelerator for the specified |command_id|.
///
void (CEF_CALLBACK *remove_accelerator)(struct _cef_window_t* self,
int command_id);
///
// Remove all keyboard accelerators.
///
void (CEF_CALLBACK *remove_all_accelerators)(struct _cef_window_t* self);
} cef_window_t;

View File

@@ -103,6 +103,22 @@ typedef struct _cef_window_delegate_t {
///
int (CEF_CALLBACK *can_close)(struct _cef_window_delegate_t* self,
struct _cef_window_t* window);
///
// Called when a keyboard accelerator registered with
// cef_window_t::SetAccelerator is triggered. Return true (1) if the
// accelerator was handled or false (0) otherwise.
///
int (CEF_CALLBACK *on_accelerator)(struct _cef_window_delegate_t* self,
struct _cef_window_t* window, int command_id);
///
// Called after all other controls in the window have had a chance to handle
// the event. |event| contains information about the keyboard event. Return
// true (1) if the keyboard event was handled or false (0) otherwise.
///
int (CEF_CALLBACK *on_key_event)(struct _cef_window_delegate_t* self,
struct _cef_window_t* window, const struct _cef_key_event_t* event);
} cef_window_delegate_t;

View File

@@ -74,6 +74,18 @@ class CefBrowserView : public CefView {
///
/*--cef()--*/
virtual CefRefPtr<CefBrowser> GetBrowser() =0;
///
// Sets whether accelerators registered with CefWindow::SetAccelerator are
// triggered before or after the event is sent to the CefBrowser. If
// |prefer_accelerators| is true then the matching accelerator will be
// triggered immediately and the event will not be sent to the CefBrowser. If
// |prefer_accelerators| is false then the matching accelerator will only be
// triggered if the event is not handled by web content or by
// CefKeyboardHandler. The default value is false.
///
/*--cef()--*/
virtual void SetPreferAccelerators(bool prefer_accelerators) =0;
};
#endif // CEF_INCLUDE_VIEWS_CEF_BROWSER_VIEW_H_

View File

@@ -289,6 +289,30 @@ class CefWindow : public CefPanel {
virtual void SendMouseEvents(cef_mouse_button_type_t button,
bool mouse_down,
bool mouse_up) =0;
///
// Set the keyboard accelerator for the specified |command_id|. |key_code| can
// be any virtual key or character value. CefWindowDelegate::OnAccelerator
// will be called if the keyboard combination is triggered while this window
// has focus.
///
/*--cef()--*/
virtual void SetAccelerator(int command_id,
int key_code,
bool shift_pressed,
bool ctrl_pressed,
bool alt_pressed) =0;
///
// Remove the keyboard accelerator for the specified |command_id|.
///
/*--cef()--*/
virtual void RemoveAccelerator(int command_id) =0;
///
// Remove all keyboard accelerators.
///
/*--cef()--*/
virtual void RemoveAllAccelerators() =0;
};
#endif // CEF_INCLUDE_VIEWS_CEF_WINDOW_H_

View File

@@ -95,6 +95,24 @@ class CefWindowDelegate : public CefPanelDelegate {
///
/*--cef()--*/
virtual bool CanClose(CefRefPtr<CefWindow> window) { return true; }
///
// Called when a keyboard accelerator registered with
// CefWindow::SetAccelerator is triggered. Return true if the accelerator was
// handled or false otherwise.
///
/*--cef()--*/
virtual bool OnAccelerator(CefRefPtr<CefWindow> window,
int command_id) { return false; }
///
// Called after all other controls in the window have had a chance to
// handle the event. |event| contains information about the keyboard event.
// Return true if the keyboard event was handled or false otherwise.
///
/*--cef()--*/
virtual bool OnKeyEvent(CefRefPtr<CefWindow> window,
const CefKeyEvent& event) { return false; }
};
#endif // CEF_INCLUDE_VIEWS_CEF_WINDOW_DELEGATE_H_