Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit cbbb677

Browse files
committed
Review Changes
1 parent 306cfff commit cbbb677

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

shell/platform/linux/fl_key_event_plugin.cc

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "flutter/shell/platform/linux/fl_key_event_plugin.h"
66

7+
#include <gtk/gtk.h>
78
#include <deque>
89

910
#include "flutter/shell/platform/linux/fl_text_input_plugin.h"
@@ -42,6 +43,9 @@ static void fl_key_event_plugin_dispose(GObject* object) {
4243
FlKeyEventPlugin* self = FL_KEY_EVENT_PLUGIN(object);
4344

4445
g_clear_object(&self->channel);
46+
g_object_remove_weak_pointer(
47+
G_OBJECT(self->text_input_plugin),
48+
reinterpret_cast<gpointer*>(&(self->text_input_plugin)));
4549

4650
G_OBJECT_CLASS(fl_key_event_plugin_parent_class)->dispose(object);
4751
}
@@ -50,9 +54,7 @@ static void fl_key_event_plugin_class_init(FlKeyEventPluginClass* klass) {
5054
G_OBJECT_CLASS(klass)->dispose = fl_key_event_plugin_dispose;
5155
}
5256

53-
static void fl_key_event_plugin_init(FlKeyEventPlugin* self) {
54-
self->pendingEvents.clear();
55-
}
57+
static void fl_key_event_plugin_init(FlKeyEventPlugin* self) {}
5658

5759
FlKeyEventPlugin* fl_key_event_plugin_new(
5860
FlBinaryMessenger* messenger,
@@ -104,6 +106,8 @@ void fl_remove_pending_event(FlKeyEventPlugin* self, uint64_t id) {
104106
id);
105107
return;
106108
}
109+
gdk_event_free(
110+
reinterpret_cast<GdkEvent*>(self->pendingEvents.front().second));
107111
self->pendingEvents.pop_front();
108112
}
109113

@@ -134,12 +138,15 @@ void fl_handle_response(GObject* object,
134138
gpointer user_data) {
135139
_KeyEventResponseData* data =
136140
reinterpret_cast<_KeyEventResponseData*>(user_data);
137-
if (data->self == nullptr) {
138-
// Weak pointer to the plugin has been destroyed.
139-
return;
140-
}
141+
142+
// Will also return if the weak pointer has been destroyed.
141143
g_return_if_fail(FL_IS_KEY_EVENT_PLUGIN(data->self));
142144

145+
FlKeyEventPlugin* self = data->self;
146+
// Don't need to weak pointer anymore.
147+
g_object_remove_weak_pointer(G_OBJECT(self),
148+
reinterpret_cast<gpointer*>(&(data->self)));
149+
143150
g_autoptr(GError) error = nullptr;
144151
FlBasicMessageChannel* messageChannel = FL_BASIC_MESSAGE_CHANNEL(object);
145152
FlValue* message =
@@ -152,7 +159,7 @@ void fl_handle_response(GObject* object,
152159
g_autoptr(FlValue) handled_value = fl_value_lookup_string(message, "handled");
153160
bool handled = false;
154161
if (handled_value != nullptr) {
155-
GdkEventKey* event = fl_find_pending_event(data->self, data->id);
162+
GdkEventKey* event = fl_find_pending_event(self, data->id);
156163
if (event == nullptr) {
157164
g_warning(
158165
"Event response for event id %ld received, but event was received "
@@ -161,16 +168,16 @@ void fl_handle_response(GObject* object,
161168
} else {
162169
handled = fl_value_get_bool(handled_value);
163170
if (!handled) {
164-
if (data->self->text_input_plugin != nullptr) {
171+
if (self->text_input_plugin != nullptr) {
165172
// Propagate the event to the text input plugin.
166173
handled = fl_text_input_plugin_filter_keypress(
167-
data->self->text_input_plugin, event);
174+
self->text_input_plugin, event);
168175
}
169176
// Dispatch the event to other GTK windows if the text input plugin
170177
// didn't handle it. We keep track of the event id so we can recognize
171178
// the event when our window receives it again and not respond to it. If
172179
// the response callback is set, then use that instead.
173-
if (!handled && data->self->response_callback == nullptr) {
180+
if (!handled && self->response_callback == nullptr) {
174181
gdk_event_put(reinterpret_cast<GdkEvent*>(event));
175182
}
176183
}
@@ -180,11 +187,11 @@ void fl_handle_response(GObject* object,
180187
if (handled) {
181188
// Because the event was handled, we no longer need to track it. Unhandled
182189
// events will be removed when the event is re-dispatched to the window.
183-
fl_remove_pending_event(data->self, data->id);
190+
fl_remove_pending_event(self, data->id);
184191
}
185192

186-
if (data->self->response_callback != nullptr) {
187-
data->self->response_callback(object, message, handled, data->user_data);
193+
if (self->response_callback != nullptr) {
194+
self->response_callback(object, message, handled, data->user_data);
188195
}
189196
}
190197

shell/platform/linux/fl_key_event_plugin.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ G_DECLARE_FINAL_TYPE(FlKeyEventPlugin,
2929
/**
3030
* FlKeyEventPluginCallback:
3131
* @source_object: (nullable): the object the key event was started with.
32-
* @handled: a boolean indicating if the key event was handled or not.
32+
* @message: the message returned from the framework.
33+
* @handled: a boolean indicating whether the key event was handled in the
34+
*framework.
3335
* @user_data: user data passed to the callback.
3436
*
3537
* Type definition for a function that will be called when a key event is
@@ -45,10 +47,10 @@ typedef void (*FlKeyEventPluginCallback)(GObject* source_object,
4547
* @messenger: an #FlBinaryMessenger.
4648
* @response_callback: the callback to call when a response is received. If not
4749
* given (nullptr), then the default response callback is
48-
* used. Typically used for tests to receive event information.
49-
* If specified, unhandled events will not be re-dispatched.
50-
* @text_input_plugin: The #FlTextInputPlugin to send key events to if the framework
51-
* doesn't handle them.
50+
* used. Typically used for tests to receive event
51+
* information. If specified, unhandled events will not be re-dispatched.
52+
* @text_input_plugin: The #FlTextInputPlugin to send key events to if the
53+
* framework doesn't handle them.
5254
* @channel_name: the name of the channel to send key events to the framework
5355
* on. If not given (nullptr), then the standard key event
5456
* channel name is used. Typically used for tests to send on a

0 commit comments

Comments
 (0)