Flutter Engine
The Flutter Engine
Classes | Public Types | Public Member Functions | List of all members
flutter::KeyboardKeyEmbedderHandler Class Reference

#include <keyboard_key_embedder_handler.h>

Inheritance diagram for flutter::KeyboardKeyEmbedderHandler:
flutter::KeyboardKeyHandler::KeyboardKeyHandlerDelegate

Public Types

using SendEventHandler = std::function< void(const FlutterKeyEvent &, FlutterKeyEventCallback, void *)>
 
using GetKeyStateHandler = std::function< SHORT(int)>
 
using MapVirtualKeyToScanCode = std::function< SHORT(UINT, bool)>
 

Public Member Functions

 KeyboardKeyEmbedderHandler (SendEventHandler send_event, GetKeyStateHandler get_key_state, MapVirtualKeyToScanCode map_vk_to_scan)
 
virtual ~KeyboardKeyEmbedderHandler ()
 
void KeyboardHook (int key, int scancode, int action, char32_t character, bool extended, bool was_down, std::function< void(bool)> callback) override
 
void SyncModifiersIfNeeded (int modifiers_state) override
 
std::map< uint64_t, uint64_t > GetPressedState () override
 
- Public Member Functions inherited from flutter::KeyboardKeyHandler::KeyboardKeyHandlerDelegate
virtual void KeyboardHook (int key, int scancode, int action, char32_t character, bool extended, bool was_down, KeyEventCallback callback)=0
 
virtual void SyncModifiersIfNeeded (int modifiers_state)=0
 
virtual std::map< uint64_t, uint64_t > GetPressedState ()=0
 
virtual ~KeyboardKeyHandlerDelegate ()
 

Detailed Description

Definition at line 34 of file keyboard_key_embedder_handler.h.

Member Typedef Documentation

◆ GetKeyStateHandler

Definition at line 41 of file keyboard_key_embedder_handler.h.

◆ MapVirtualKeyToScanCode

Definition at line 42 of file keyboard_key_embedder_handler.h.

◆ SendEventHandler

Definition at line 37 of file keyboard_key_embedder_handler.h.

Constructor & Destructor Documentation

◆ KeyboardKeyEmbedderHandler()

flutter::KeyboardKeyEmbedderHandler::KeyboardKeyEmbedderHandler ( SendEventHandler  send_event,
GetKeyStateHandler  get_key_state,
MapVirtualKeyToScanCode  map_vk_to_scan 
)
explicit

Definition at line 59 of file keyboard_key_embedder_handler.cc.

63 : perform_send_event_(send_event),
64 get_key_state_(get_key_state),
65 response_id_(1) {
66 InitCriticalKeys(map_virtual_key_to_scan_code);
67}

◆ ~KeyboardKeyEmbedderHandler()

flutter::KeyboardKeyEmbedderHandler::~KeyboardKeyEmbedderHandler ( )
virtualdefault

Member Function Documentation

◆ GetPressedState()

std::map< uint64_t, uint64_t > flutter::KeyboardKeyEmbedderHandler::GetPressedState ( )
overridevirtual

Implements flutter::KeyboardKeyHandler::KeyboardKeyHandlerDelegate.

Definition at line 353 of file keyboard_key_embedder_handler.cc.

353 {
354 return pressingRecords_;
355}

◆ KeyboardHook()

void flutter::KeyboardKeyEmbedderHandler::KeyboardHook ( int  key,
int  scancode,
int  action,
char32_t  character,
bool  extended,
bool  was_down,
std::function< void(bool)>  callback 
)
overridevirtual

Implements flutter::KeyboardKeyHandler::KeyboardKeyHandlerDelegate.

Definition at line 325 of file keyboard_key_embedder_handler.cc.

332 {
333 sent_any_events = false;
334 KeyboardHookImpl(key, scancode, action, character, extended, was_down,
335 std::move(callback));
336 if (!sent_any_events) {
337 FlutterKeyEvent empty_event{
338 .struct_size = sizeof(FlutterKeyEvent),
339 .timestamp = static_cast<double>(
340 std::chrono::duration_cast<std::chrono::microseconds>(
341 std::chrono::high_resolution_clock::now().time_since_epoch())
342 .count()),
344 .physical = 0,
345 .logical = 0,
346 .character = empty_character,
347 .synthesized = false,
348 };
349 SendEvent(empty_event, nullptr, nullptr);
350 }
351}
GLenum type
@ kFlutterKeyEventTypeDown
Definition: embedder.h:1076
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
size_t struct_size
The size of this struct. Must be sizeof(FlutterKeyEvent).
Definition: embedder.h:1112

◆ SyncModifiersIfNeeded()

void flutter::KeyboardKeyEmbedderHandler::SyncModifiersIfNeeded ( int  modifiers_state)
overridevirtual

Implements flutter::KeyboardKeyHandler::KeyboardKeyHandlerDelegate.

Definition at line 500 of file keyboard_key_embedder_handler.cc.

500 {
501 // TODO(bleroux): consider exposing these constants in flutter_key_map.g.cc?
502 const uint64_t physical_shift_left =
503 windowsToPhysicalMap_.at(kScanCodeShiftLeft);
504 const uint64_t physical_shift_right =
505 windowsToPhysicalMap_.at(kScanCodeShiftRight);
506 const uint64_t logical_shift_left =
507 windowsToLogicalMap_.at(kKeyCodeShiftLeft);
508 const uint64_t physical_control_left =
509 windowsToPhysicalMap_.at(kScanCodeControlLeft);
510 const uint64_t physical_control_right =
511 windowsToPhysicalMap_.at(kScanCodeControlRight);
512 const uint64_t logical_control_left =
513 windowsToLogicalMap_.at(kKeyCodeControlLeft);
514
515 bool shift_pressed = (modifiers_state & kShift) != 0;
516 SynthesizeIfNeeded(physical_shift_left, physical_shift_right,
517 logical_shift_left, shift_pressed);
518 bool control_pressed = (modifiers_state & kControl) != 0;
519 SynthesizeIfNeeded(physical_control_left, physical_control_right,
520 logical_control_left, control_pressed);
521}
constexpr int kShift
constexpr int kKeyCodeShiftLeft
constexpr int kScanCodeShiftRight
constexpr int kScanCodeShiftLeft
constexpr int kScanCodeControlRight
constexpr int kScanCodeControlLeft
constexpr int kKeyCodeControlLeft
constexpr int kControl

The documentation for this class was generated from the following files: