Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | List of all members
flutter_runner::Keyboard Class Referencefinal

#include <keyboard.h>

Public Member Functions

 Keyboard ()
 
bool ConsumeEvent (fuchsia::ui::input3::KeyEvent event)
 
uint32_t Modifiers ()
 
uint32_t LastCodePoint ()
 
uint32_t LastHIDUsage ()
 
uint16_t LastHIDUsagePage ()
 
uint16_t LastHIDUsageID ()
 

Detailed Description

Definition at line 15 of file keyboard.h.

Constructor & Destructor Documentation

◆ Keyboard()

flutter_runner::Keyboard::Keyboard ( )
explicit

Definition at line 163 of file keyboard.cc.

164 : any_events_received_(false),
165 stateful_caps_lock_(false),
166 left_shift_(false),
167 right_shift_(false),
168 left_alt_(false),
169 right_alt_(false),
170 left_ctrl_(false),
171 right_ctrl_(false),
172 last_event_() {}

Member Function Documentation

◆ ConsumeEvent()

bool flutter_runner::Keyboard::ConsumeEvent ( fuchsia::ui::input3::KeyEvent  event)

Definition at line 174 of file keyboard.cc.

174 {
175 if (!event.has_type()) {
176 return false;
177 }
178 if (!event.has_key() && !event.has_key_meaning()) {
179 return false;
180 }
181 // Check if the time sequence of the events is correct.
182 last_event_ = std::move(event);
183 any_events_received_ = true;
184
185 if (!event.has_key()) {
186 // The key only has key meaning. Key meaning currently can not
187 // update the modifier state, so we just short-circuit the table
188 // below.
189 return true;
190 }
191
192 const Key& key = last_event_.key();
193 const KeyEventType& event_type = last_event_.type();
194 switch (event_type) {
195 // For modifier keys, a SYNC is the same as a press.
196 case KeyEventType::SYNC:
197 switch (key) {
198 case Key::CAPS_LOCK:
199 stateful_caps_lock_ = true;
200 break;
201 case Key::LEFT_ALT:
202 left_alt_ = true;
203 break;
204 case Key::LEFT_CTRL:
205 left_ctrl_ = true;
206 break;
207 case Key::LEFT_SHIFT:
208 left_shift_ = true;
209 break;
210 case Key::RIGHT_ALT:
211 right_alt_ = true;
212 break;
213 case Key::RIGHT_CTRL:
214 right_ctrl_ = true;
215 break;
216 case Key::RIGHT_SHIFT:
217 right_shift_ = true;
218 break;
219 default:
220 // no-op
221 break;
222 }
223 break;
224 case KeyEventType::PRESSED:
225 switch (key) {
226 case Key::CAPS_LOCK:
227 stateful_caps_lock_ = !stateful_caps_lock_;
228 break;
229 case Key::LEFT_ALT:
230 left_alt_ = true;
231 break;
232 case Key::LEFT_CTRL:
233 left_ctrl_ = true;
234 break;
235 case Key::LEFT_SHIFT:
236 left_shift_ = true;
237 break;
238 case Key::RIGHT_ALT:
239 right_alt_ = true;
240 break;
241 case Key::RIGHT_CTRL:
242 right_ctrl_ = true;
243 break;
244 case Key::RIGHT_SHIFT:
245 right_shift_ = true;
246 break;
247 default:
248 // No-op
249 break;
250 }
251 break;
252 case KeyEventType::RELEASED:
253 switch (key) {
254 case Key::CAPS_LOCK:
255 // No-op.
256 break;
257 case Key::LEFT_ALT:
258 left_alt_ = false;
259 break;
260 case Key::LEFT_CTRL:
261 left_ctrl_ = false;
262 break;
263 case Key::LEFT_SHIFT:
264 left_shift_ = false;
265 break;
266 case Key::RIGHT_ALT:
267 right_alt_ = false;
268 break;
269 case Key::RIGHT_CTRL:
270 right_ctrl_ = false;
271 break;
272 case Key::RIGHT_SHIFT:
273 right_shift_ = false;
274 break;
275 default:
276 // No-op
277 break;
278 }
279 break;
280 case KeyEventType::CANCEL:
281 // No-op?
282 break;
283 default:
284 // No-op
285 break;
286 }
287 return true;
288}
ax::mojom::Event event_type
FlKeyEvent * event
KeyEventType
Definition key_data.h:22

◆ LastCodePoint()

uint32_t flutter_runner::Keyboard::LastCodePoint ( )

Definition at line 307 of file keyboard.cc.

307 {
308 // If the key has a meaning, and if the meaning is a code point, always have
309 // that code point take precedence over any other keymap.
310 if (last_event_.has_key_meaning()) {
311 const auto& key_meaning = last_event_.key_meaning();
312 if (key_meaning.is_codepoint()) {
313 return key_meaning.codepoint();
314 }
315 }
316 static const int qwerty_map_size =
317 sizeof(QWERTY_TO_CODE_POINTS) / sizeof(QWERTY_TO_CODE_POINTS[0]);
318 if (!IsKeys()) {
319 return 0;
320 }
321 const auto usage = LastHIDUsageID();
322 if (usage < qwerty_map_size) {
323 return QWERTY_TO_CODE_POINTS[usage][IsShift() & 1];
324 }
325 // Any other keys don't have a code point.
326 return 0;
327}
static void usage(char *argv0)

◆ LastHIDUsage()

uint32_t flutter_runner::Keyboard::LastHIDUsage ( )

Definition at line 341 of file keyboard.cc.

341 {
342 return GetLastKey() & 0xFFFFFFFF;
343}

◆ LastHIDUsageID()

uint16_t flutter_runner::Keyboard::LastHIDUsageID ( )

Definition at line 345 of file keyboard.cc.

345 {
346 return GetLastKey() & 0xFFFF;
347}

◆ LastHIDUsagePage()

uint16_t flutter_runner::Keyboard::LastHIDUsagePage ( )

Definition at line 349 of file keyboard.cc.

349 {
350 return (GetLastKey() >> 16) & 0xFFFF;
351}

◆ Modifiers()

uint32_t flutter_runner::Keyboard::Modifiers ( )

Definition at line 298 of file keyboard.cc.

298 {
299 return kModifierNone + (kModifierLeftShift * left_shift_) +
300 (kModifierLeftAlt * left_alt_) + (kModifierLeftControl * left_ctrl_) +
301 (kModifierRightShift * right_shift_) +
302 (kModifierRightAlt * right_alt_) +
303 (kModifierRightControl * right_ctrl_) +
304 (kModifierCapsLock * stateful_caps_lock_);
305}

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