Flutter Engine
flutter::KeyEventHandler Class Reference

#include <key_event_handler.h>

Inheritance diagram for flutter::KeyEventHandler:
flutter::KeyboardHookHandler flutter::KeyboardHookHandler

Public Member Functions

 KeyEventHandler (flutter::BinaryMessenger *messenger)
 
virtual ~KeyEventHandler ()
 
void KeyboardHook (GLFWwindow *window, int key, int scancode, int action, int mods) override
 
void CharHook (GLFWwindow *window, unsigned int code_point) override
 
 KeyEventHandler (flutter::BinaryMessenger *messenger)
 
virtual ~KeyEventHandler ()
 
void KeyboardHook (FlutterWindowsView *window, int key, int scancode, int action, char32_t character) override
 
void TextHook (FlutterWindowsView *window, const std::u16string &text) override
 
- Public Member Functions inherited from flutter::KeyboardHookHandler
virtual ~KeyboardHookHandler ()=default
 
virtual ~KeyboardHookHandler ()=default
 

Detailed Description

Definition at line 21 of file key_event_handler.h.

Constructor & Destructor Documentation

◆ KeyEventHandler() [1/2]

flutter::KeyEventHandler::KeyEventHandler ( flutter::BinaryMessenger messenger)
explicit

Definition at line 104 of file key_event_handler.cc.

References ~KeyEventHandler().

105  : channel_(
107  messenger,
108  kChannelName,
static const JsonMessageCodec & GetInstance()
static constexpr char kChannelName[]

◆ ~KeyEventHandler() [1/2]

flutter::KeyEventHandler::~KeyEventHandler ( )
virtualdefault

Referenced by KeyEventHandler().

◆ KeyEventHandler() [2/2]

flutter::KeyEventHandler::KeyEventHandler ( flutter::BinaryMessenger messenger)
explicit

◆ ~KeyEventHandler() [2/2]

virtual flutter::KeyEventHandler::~KeyEventHandler ( )
virtual

Member Function Documentation

◆ CharHook()

void flutter::KeyEventHandler::CharHook ( GLFWwindow *  window,
unsigned int  code_point 
)
overridevirtual

Implements flutter::KeyboardHookHandler.

Definition at line 113 of file key_event_handler.cc.

113 {}

◆ KeyboardHook() [1/2]

void flutter::KeyEventHandler::KeyboardHook ( GLFWwindow *  window,
int  key,
int  scancode,
int  action,
int  mods 
)
overridevirtual

Implements flutter::KeyboardHookHandler.

Definition at line 115 of file key_event_handler.cc.

References event, kGLFWKey, kKeyCodeKey, kKeyDown, kKeyMapKey, kKeyUp, kLinuxKeyMap, kModifiersKey, kScanCodeKey, kToolkitKey, flutter::kTypeKey, and kUnicodeScalarValues.

119  {
120  // TODO: Translate to a cross-platform key code system rather than passing
121  // the native key code.
122  rapidjson::Document event(rapidjson::kObjectType);
123  auto& allocator = event.GetAllocator();
124  event.AddMember(kKeyCodeKey, key, allocator);
125  event.AddMember(kKeyMapKey, kLinuxKeyMap, allocator);
126  event.AddMember(kScanCodeKey, scancode, allocator);
127  event.AddMember(kModifiersKey, mods, allocator);
128  event.AddMember(kToolkitKey, kGLFWKey, allocator);
129 
130  uint32_t unicodeInt;
131  bool result = GetUTF32CodePointFromGLFWKey(key, scancode, &unicodeInt);
132  if (result) {
133  event.AddMember(kUnicodeScalarValues, unicodeInt, allocator);
134  }
135 
136  switch (action) {
137  case GLFW_PRESS:
138  case GLFW_REPEAT:
139  event.AddMember(kTypeKey, kKeyDown, allocator);
140  break;
141  case GLFW_RELEASE:
142  event.AddMember(kTypeKey, kKeyUp, allocator);
143  break;
144  default:
145  std::cerr << "Unknown key event action: " << action << std::endl;
146  return;
147  }
148  channel_->Send(event);
149 }
static constexpr char kLinuxKeyMap[]
static constexpr char kScanCodeKey[]
static constexpr char kKeyMapKey[]
static constexpr char kKeyCodeKey[]
static constexpr char kUnicodeScalarValues[]
static constexpr char kToolkitKey[]
SemanticsAction action
GdkEventButton * event
Definition: fl_view.cc:62
static constexpr char kKeyDown[]
static constexpr char kModifiersKey[]
static constexpr char kGLFWKey[]
constexpr char kTypeKey[]
Definition: shell.cc:39
static constexpr char kKeyUp[]

◆ KeyboardHook() [2/2]

void flutter::KeyEventHandler::KeyboardHook ( FlutterWindowsView window,
int  key,
int  scancode,
int  action,
char32_t  character 
)
overridevirtual

Implements flutter::KeyboardHookHandler.

Definition at line 98 of file key_event_handler.cc.

References event, kCharacterCodePointKey, kKeyCodeKey, kKeyDown, kKeyMapKey, kKeyUp, kModifiersKey, kScanCodeKey, flutter::kTypeKey, and kWindowsKeyMap.

102  {
103  // TODO: Translate to a cross-platform key code system rather than passing
104  // the native key code.
105  rapidjson::Document event(rapidjson::kObjectType);
106  auto& allocator = event.GetAllocator();
107  event.AddMember(kKeyCodeKey, key, allocator);
108  event.AddMember(kScanCodeKey, scancode, allocator);
109  event.AddMember(kCharacterCodePointKey, character, allocator);
110  event.AddMember(kKeyMapKey, kWindowsKeyMap, allocator);
111  event.AddMember(kModifiersKey, GetModsForKeyState(), allocator);
112 
113  switch (action) {
114  case WM_KEYDOWN:
115  event.AddMember(kTypeKey, kKeyDown, allocator);
116  break;
117  case WM_KEYUP:
118  event.AddMember(kTypeKey, kKeyUp, allocator);
119  break;
120  default:
121  std::cerr << "Unknown key event action: " << action << std::endl;
122  return;
123  }
124  channel_->Send(event);
125 }
static constexpr char kCharacterCodePointKey[]
static constexpr char kKeyUp[]
static constexpr char kModifiersKey[]
SemanticsAction action
static constexpr char kScanCodeKey[]
static constexpr char kKeyMapKey[]
static constexpr char kWindowsKeyMap[]
GdkEventButton * event
Definition: fl_view.cc:62
static constexpr char kKeyDown[]
constexpr char kTypeKey[]
Definition: shell.cc:39
static constexpr char kKeyCodeKey[]

◆ TextHook()

void flutter::KeyEventHandler::TextHook ( FlutterWindowsView window,
const std::u16string &  text 
)
overridevirtual

Implements flutter::KeyboardHookHandler.

Definition at line 95 of file key_event_handler.cc.

96  {}

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