flutter_flutter/shell/platform/linux/fl_key_event_plugin.h
Greg Spencer bdadaad20d
Add delayed event delivery for Linux. (#22577)
This changes the text handling so that keyboard events are sent to the framework first for handling, and then passed to the text input plugin, so that the framework has a chance to handle keys before they get given to the text field.

This is complicated by the async nature of the interaction with the framework, since GTK wants a synchronous response. So, in this change, I always tell GTK that the event was handled, and if it wasn't, then I re-dispatch the event once we know one way or the other.
2020-12-03 15:00:37 -08:00

90 lines
3.3 KiB
C

// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_SHELL_PLATFORM_LINUX_FL_KEY_EVENT_PLUGIN_H_
#define FLUTTER_SHELL_PLATFORM_LINUX_FL_KEY_EVENT_PLUGIN_H_
#include "flutter/shell/platform/linux/fl_text_input_plugin.h"
#include "flutter/shell/platform/linux/public/flutter_linux/fl_binary_messenger.h"
#include "flutter/shell/platform/linux/public/flutter_linux/fl_value.h"
#include <gdk/gdk.h>
G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE(FlKeyEventPlugin,
fl_key_event_plugin,
FL,
KEY_EVENT_PLUGIN,
GObject);
/**
* FlKeyEventPlugin:
*
* #FlKeyEventPlugin is a plugin that implements the shell side
* of SystemChannels.keyEvent from the Flutter services library.
*/
/**
* FlKeyEventPluginCallback:
* @source_object: (nullable): the object the key event was started with.
* @message: the message returned from the framework.
* @handled: a boolean indicating whether the key event was handled in the
* framework.
* @user_data: user data passed to the callback.
*
* Type definition for a function that will be called when a key event is
* received from the engine.
**/
typedef void (*FlKeyEventPluginCallback)(GObject* source_object,
FlValue* message,
bool handled,
gpointer user_data);
/**
* fl_key_event_plugin_new:
* @messenger: an #FlBinaryMessenger.
* @response_callback: the callback to call when a response is received. If not
* given (nullptr), then the default response callback is
* used. Typically used for tests to receive event
* information. If specified, unhandled events will not be
* re-dispatched.
* @text_input_plugin: The #FlTextInputPlugin to send key events to if the
* framework doesn't handle them.
* @channel_name: the name of the channel to send key events to the framework
* on. If not given (nullptr), then the standard key event
* channel name is used. Typically used for tests to send on a
* test channel.
*
* Creates a new plugin that implements SystemChannels.keyEvent from the
* Flutter services library.
*
* Returns: a new #FlKeyEventPlugin.
*/
FlKeyEventPlugin* fl_key_event_plugin_new(
FlBinaryMessenger* messenger,
FlTextInputPlugin* text_input_plugin,
FlKeyEventPluginCallback response_callback = nullptr,
const char* channel_name = nullptr);
/**
* fl_key_event_plugin_send_key_event:
* @plugin: an #FlKeyEventPlugin.
* @event: a #GdkEventKey.
* @user_data: a pointer to user data to send to the response callback via the
* messenger.
*
* @returns %TRUE if this key event should be considered handled and
* event propagation stopped.
*
* Sends a key event to Flutter.
*/
bool fl_key_event_plugin_send_key_event(FlKeyEventPlugin* plugin,
GdkEventKey* event,
gpointer user_data = nullptr);
G_END_DECLS
#endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_KEY_EVENT_PLUGIN_H_