Move get_keyboard_state from FlKeyboardViewDelegate to FlKeyboardManager. (flutter/engine#56021)
Like the other associated changes, I've added fl_keyboard_manager_set_get_get_pressed_state_handler for now to keep the tests working.
This commit is contained in:
@@ -45076,7 +45076,6 @@ ORIGIN: ../../../flutter/shell/platform/linux/fl_view.cc + ../../../flutter/LICE
|
||||
ORIGIN: ../../../flutter/shell/platform/linux/fl_view_accessible.cc + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/shell/platform/linux/fl_view_accessible.h + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/shell/platform/linux/fl_view_accessible_test.cc + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/shell/platform/linux/fl_view_private.h + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/shell/platform/linux/fl_view_test.cc + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/shell/platform/linux/fl_window_state_monitor.cc + ../../../flutter/LICENSE
|
||||
ORIGIN: ../../../flutter/shell/platform/linux/fl_window_state_monitor.h + ../../../flutter/LICENSE
|
||||
@@ -47980,7 +47979,6 @@ FILE: ../../../flutter/shell/platform/linux/fl_view.cc
|
||||
FILE: ../../../flutter/shell/platform/linux/fl_view_accessible.cc
|
||||
FILE: ../../../flutter/shell/platform/linux/fl_view_accessible.h
|
||||
FILE: ../../../flutter/shell/platform/linux/fl_view_accessible_test.cc
|
||||
FILE: ../../../flutter/shell/platform/linux/fl_view_private.h
|
||||
FILE: ../../../flutter/shell/platform/linux/fl_view_test.cc
|
||||
FILE: ../../../flutter/shell/platform/linux/fl_window_state_monitor.cc
|
||||
FILE: ../../../flutter/shell/platform/linux/fl_window_state_monitor.h
|
||||
|
||||
@@ -13,7 +13,7 @@ static constexpr char kGetKeyboardStateMethod[] = "getKeyboardState";
|
||||
struct _FlKeyboardHandler {
|
||||
GObject parent_instance;
|
||||
|
||||
GWeakRef view_delegate;
|
||||
FlKeyboardManager* keyboard_manager;
|
||||
|
||||
// The channel used by the framework to query the keyboard pressed state.
|
||||
FlMethodChannel* channel;
|
||||
@@ -25,11 +25,8 @@ G_DEFINE_TYPE(FlKeyboardHandler, fl_keyboard_handler, G_TYPE_OBJECT);
|
||||
static FlMethodResponse* get_keyboard_state(FlKeyboardHandler* self) {
|
||||
g_autoptr(FlValue) result = fl_value_new_map();
|
||||
|
||||
g_autoptr(FlKeyboardViewDelegate) view_delegate =
|
||||
FL_KEYBOARD_VIEW_DELEGATE(g_weak_ref_get(&self->view_delegate));
|
||||
|
||||
GHashTable* pressing_records =
|
||||
fl_keyboard_view_delegate_get_keyboard_state(view_delegate);
|
||||
fl_keyboard_manager_get_pressed_state(self->keyboard_manager);
|
||||
|
||||
g_hash_table_foreach(
|
||||
pressing_records,
|
||||
@@ -69,7 +66,7 @@ static void method_call_handler(FlMethodChannel* channel,
|
||||
static void fl_keyboard_handler_dispose(GObject* object) {
|
||||
FlKeyboardHandler* self = FL_KEYBOARD_HANDLER(object);
|
||||
|
||||
g_weak_ref_clear(&self->view_delegate);
|
||||
g_clear_object(&self->keyboard_manager);
|
||||
g_clear_object(&self->channel);
|
||||
|
||||
G_OBJECT_CLASS(fl_keyboard_handler_parent_class)->dispose(object);
|
||||
@@ -83,13 +80,11 @@ static void fl_keyboard_handler_init(FlKeyboardHandler* self) {}
|
||||
|
||||
FlKeyboardHandler* fl_keyboard_handler_new(
|
||||
FlBinaryMessenger* messenger,
|
||||
FlKeyboardViewDelegate* view_delegate) {
|
||||
g_return_val_if_fail(FL_IS_KEYBOARD_VIEW_DELEGATE(view_delegate), nullptr);
|
||||
|
||||
FlKeyboardManager* keyboard_manager) {
|
||||
FlKeyboardHandler* self = FL_KEYBOARD_HANDLER(
|
||||
g_object_new(fl_keyboard_handler_get_type(), nullptr));
|
||||
|
||||
g_weak_ref_init(&self->view_delegate, view_delegate);
|
||||
self->keyboard_manager = FL_KEYBOARD_MANAGER(g_object_ref(keyboard_manager));
|
||||
|
||||
// Setup the flutter/keyboard channel.
|
||||
g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
|
||||
#include "flutter/shell/platform/linux/fl_keyboard_view_delegate.h"
|
||||
#include "flutter/shell/platform/linux/fl_keyboard_manager.h"
|
||||
#include "flutter/shell/platform/linux/public/flutter_linux/fl_binary_messenger.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
@@ -26,16 +26,15 @@ G_DECLARE_FINAL_TYPE(FlKeyboardHandler,
|
||||
|
||||
/**
|
||||
* fl_keyboard_handler_new:
|
||||
* @view_delegate: An interface that the handler requires to communicate with
|
||||
* the platform. Usually implemented by FlView.
|
||||
* @messenger: a #FlBinaryMessenger.
|
||||
* @keyboard_manager: a #FlKeyboardManager.
|
||||
*
|
||||
* Create a new #FlKeyboardHandler.
|
||||
*
|
||||
* Returns: a new #FlKeyboardHandler.
|
||||
*/
|
||||
FlKeyboardHandler* fl_keyboard_handler_new(
|
||||
FlBinaryMessenger* messenger,
|
||||
FlKeyboardViewDelegate* view_delegate);
|
||||
FlKeyboardHandler* fl_keyboard_handler_new(FlBinaryMessenger* messenger,
|
||||
FlKeyboardManager* keyboard_manager);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
||||
@@ -60,19 +60,8 @@ static void fl_mock_keyboard_handler_delegate_init(
|
||||
static void fl_mock_keyboard_handler_delegate_class_init(
|
||||
FlMockKeyboardHandlerDelegateClass* klass) {}
|
||||
|
||||
static GHashTable* fl_mock_view_keyboard_get_keyboard_state(
|
||||
FlKeyboardViewDelegate* view_delegate) {
|
||||
GHashTable* result = g_hash_table_new(g_direct_hash, g_direct_equal);
|
||||
g_hash_table_insert(result, reinterpret_cast<gpointer>(kMockPhysicalKey),
|
||||
reinterpret_cast<gpointer>(kMockLogicalKey));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void fl_mock_keyboard_handler_delegate_keyboard_view_delegate_iface_init(
|
||||
FlKeyboardViewDelegateInterface* iface) {
|
||||
iface->get_keyboard_state = fl_mock_view_keyboard_get_keyboard_state;
|
||||
}
|
||||
FlKeyboardViewDelegateInterface* iface) {}
|
||||
|
||||
static FlMockKeyboardHandlerDelegate* fl_mock_keyboard_handler_delegate_new() {
|
||||
FlMockKeyboardHandlerDelegate* self = FL_MOCK_KEYBOARD_HANDLER_DELEGATE(
|
||||
@@ -87,9 +76,26 @@ static FlMockKeyboardHandlerDelegate* fl_mock_keyboard_handler_delegate_new() {
|
||||
TEST(FlKeyboardHandlerTest, KeyboardChannelGetPressedState) {
|
||||
::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
|
||||
|
||||
g_autoptr(FlKeyboardHandler) handler = fl_keyboard_handler_new(
|
||||
messenger,
|
||||
FL_KEYBOARD_VIEW_DELEGATE(fl_mock_keyboard_handler_delegate_new()));
|
||||
g_autoptr(FlEngine) engine =
|
||||
FL_ENGINE(g_object_new(fl_engine_get_type(), "binary-messenger",
|
||||
FL_BINARY_MESSENGER(messenger), nullptr));
|
||||
g_autoptr(FlMockKeyboardHandlerDelegate) view_delegate =
|
||||
fl_mock_keyboard_handler_delegate_new();
|
||||
g_autoptr(FlKeyboardManager) manager =
|
||||
fl_keyboard_manager_new(engine, FL_KEYBOARD_VIEW_DELEGATE(view_delegate));
|
||||
fl_keyboard_manager_set_get_pressed_state_handler(
|
||||
manager,
|
||||
[](gpointer user_data) {
|
||||
GHashTable* result = g_hash_table_new(g_direct_hash, g_direct_equal);
|
||||
g_hash_table_insert(result,
|
||||
reinterpret_cast<gpointer>(kMockPhysicalKey),
|
||||
reinterpret_cast<gpointer>(kMockLogicalKey));
|
||||
|
||||
return result;
|
||||
},
|
||||
nullptr);
|
||||
g_autoptr(FlKeyboardHandler) handler =
|
||||
fl_keyboard_handler_new(messenger, manager);
|
||||
EXPECT_NE(handler, nullptr);
|
||||
|
||||
g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
|
||||
|
||||
@@ -129,6 +129,9 @@ struct _FlKeyboardManager {
|
||||
FlKeyboardManagerRedispatchEventHandler redispatch_handler;
|
||||
gpointer redispatch_handler_user_data;
|
||||
|
||||
FlKeyboardManagerGetPressedStateHandler get_pressed_state_handler;
|
||||
gpointer get_pressed_state_handler_user_data;
|
||||
|
||||
FlKeyEmbedderResponder* key_embedder_responder;
|
||||
|
||||
FlKeyChannelResponder* key_channel_responder;
|
||||
@@ -543,8 +546,13 @@ void fl_keyboard_manager_sync_modifier_if_needed(FlKeyboardManager* self,
|
||||
|
||||
GHashTable* fl_keyboard_manager_get_pressed_state(FlKeyboardManager* self) {
|
||||
g_return_val_if_fail(FL_IS_KEYBOARD_MANAGER(self), nullptr);
|
||||
return fl_key_embedder_responder_get_pressed_state(
|
||||
self->key_embedder_responder);
|
||||
if (self->get_pressed_state_handler != nullptr) {
|
||||
return self->get_pressed_state_handler(
|
||||
self->get_pressed_state_handler_user_data);
|
||||
} else {
|
||||
return fl_key_embedder_responder_get_pressed_state(
|
||||
self->key_embedder_responder);
|
||||
}
|
||||
}
|
||||
|
||||
void fl_keyboard_manager_set_send_key_event_handler(
|
||||
@@ -578,3 +586,12 @@ void fl_keyboard_manager_set_redispatch_handler(
|
||||
self->redispatch_handler = redispatch_handler;
|
||||
self->redispatch_handler_user_data = user_data;
|
||||
}
|
||||
|
||||
void fl_keyboard_manager_set_get_pressed_state_handler(
|
||||
FlKeyboardManager* self,
|
||||
FlKeyboardManagerGetPressedStateHandler get_pressed_state_handler,
|
||||
gpointer user_data) {
|
||||
g_return_if_fail(FL_IS_KEYBOARD_MANAGER(self));
|
||||
self->get_pressed_state_handler = get_pressed_state_handler;
|
||||
self->get_pressed_state_handler_user_data = user_data;
|
||||
}
|
||||
|
||||
@@ -148,6 +148,20 @@ void fl_keyboard_manager_set_redispatch_handler(
|
||||
FlKeyboardManagerRedispatchEventHandler redispatch_handler,
|
||||
gpointer user_data);
|
||||
|
||||
typedef GHashTable* (*FlKeyboardManagerGetPressedStateHandler)(
|
||||
gpointer user_data);
|
||||
|
||||
/**
|
||||
* fl_keyboard_manager_set_get_pressed_state_handler:
|
||||
* @manager: the #FlKeyboardManager self.
|
||||
*
|
||||
* Set the handler for gettting the keyboard state, for testing purposes only.
|
||||
*/
|
||||
void fl_keyboard_manager_set_get_pressed_state_handler(
|
||||
FlKeyboardManager* manager,
|
||||
FlKeyboardManagerGetPressedStateHandler get_pressed_state_handler,
|
||||
gpointer user_data);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_KEYBOARD_MANAGER_H_
|
||||
|
||||
@@ -20,10 +20,3 @@ gboolean fl_keyboard_view_delegate_text_filter_key_press(
|
||||
return FL_KEYBOARD_VIEW_DELEGATE_GET_IFACE(self)->text_filter_key_press(
|
||||
self, event);
|
||||
}
|
||||
|
||||
GHashTable* fl_keyboard_view_delegate_get_keyboard_state(
|
||||
FlKeyboardViewDelegate* self) {
|
||||
g_return_val_if_fail(FL_IS_KEYBOARD_VIEW_DELEGATE(self), nullptr);
|
||||
|
||||
return FL_KEYBOARD_VIEW_DELEGATE_GET_IFACE(self)->get_keyboard_state(self);
|
||||
}
|
||||
|
||||
@@ -36,8 +36,6 @@ struct _FlKeyboardViewDelegateInterface {
|
||||
|
||||
gboolean (*text_filter_key_press)(FlKeyboardViewDelegate* delegate,
|
||||
FlKeyEvent* event);
|
||||
|
||||
GHashTable* (*get_keyboard_state)(FlKeyboardViewDelegate* delegate);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -52,16 +50,6 @@ gboolean fl_keyboard_view_delegate_text_filter_key_press(
|
||||
FlKeyboardViewDelegate* delegate,
|
||||
FlKeyEvent* event);
|
||||
|
||||
/**
|
||||
* fl_keyboard_view_delegate_get_keyboard_state:
|
||||
*
|
||||
* Returns the keyboard pressed state. The hash table contains one entry per
|
||||
* pressed keys, mapping from the logical key to the physical key.*
|
||||
*
|
||||
*/
|
||||
GHashTable* fl_keyboard_view_delegate_get_keyboard_state(
|
||||
FlKeyboardViewDelegate* delegate);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_KEYBOARD_VIEW_DELEGATE_H_
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
|
||||
#include "flutter/shell/platform/linux/public/flutter_linux/fl_view.h"
|
||||
|
||||
#include "flutter/shell/platform/linux/fl_view_private.h"
|
||||
|
||||
#include <atk/atk.h>
|
||||
#include <gtk/gtk-a11y.h>
|
||||
|
||||
@@ -146,12 +144,12 @@ static void init_keyboard(FlView* self) {
|
||||
g_clear_object(&self->text_input_handler);
|
||||
self->text_input_handler = fl_text_input_handler_new(
|
||||
messenger, im_context, FL_TEXT_INPUT_VIEW_DELEGATE(self));
|
||||
g_clear_object(&self->keyboard_handler);
|
||||
self->keyboard_handler =
|
||||
fl_keyboard_handler_new(messenger, FL_KEYBOARD_VIEW_DELEGATE(self));
|
||||
g_clear_object(&self->keyboard_manager);
|
||||
self->keyboard_manager =
|
||||
fl_keyboard_manager_new(self->engine, FL_KEYBOARD_VIEW_DELEGATE(self));
|
||||
g_clear_object(&self->keyboard_handler);
|
||||
self->keyboard_handler =
|
||||
fl_keyboard_handler_new(messenger, self->keyboard_manager);
|
||||
}
|
||||
|
||||
static void init_scrolling(FlView* self) {
|
||||
@@ -370,12 +368,6 @@ static void fl_view_keyboard_delegate_iface_init(
|
||||
return fl_text_input_handler_filter_keypress(self->text_input_handler,
|
||||
event);
|
||||
};
|
||||
|
||||
iface->get_keyboard_state =
|
||||
[](FlKeyboardViewDelegate* view_delegate) -> GHashTable* {
|
||||
FlView* self = FL_VIEW(view_delegate);
|
||||
return fl_view_get_keyboard_state(self);
|
||||
};
|
||||
}
|
||||
|
||||
static void fl_view_scrolling_delegate_iface_init(
|
||||
@@ -867,8 +859,3 @@ G_MODULE_EXPORT void fl_view_set_background_color(FlView* self,
|
||||
gdk_rgba_free(self->background_color);
|
||||
self->background_color = gdk_rgba_copy(color);
|
||||
}
|
||||
|
||||
GHashTable* fl_view_get_keyboard_state(FlView* self) {
|
||||
g_return_val_if_fail(FL_IS_VIEW(self), nullptr);
|
||||
return fl_keyboard_manager_get_pressed_state(self->keyboard_manager);
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
// 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_VIEW_PRIVATE_H_
|
||||
#define FLUTTER_SHELL_PLATFORM_LINUX_FL_VIEW_PRIVATE_H_
|
||||
|
||||
#include "flutter/shell/platform/linux/public/flutter_linux/fl_view.h"
|
||||
|
||||
/**
|
||||
* fl_view_get_keyboard_state:
|
||||
* @view: an #FlView.
|
||||
*
|
||||
* Returns the keyboard pressed state. The hash table contains one entry per
|
||||
* pressed keys, mapping from the logical key to the physical key.*
|
||||
*/
|
||||
GHashTable* fl_view_get_keyboard_state(FlView* view);
|
||||
|
||||
#endif // FLUTTER_SHELL_PLATFORM_LINUX_FL_VIEW_PRIVATE_H_
|
||||
@@ -5,7 +5,6 @@
|
||||
#include "flutter/shell/platform/linux/public/flutter_linux/fl_view.h"
|
||||
#include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"
|
||||
#include "flutter/shell/platform/linux/fl_engine_private.h"
|
||||
#include "flutter/shell/platform/linux/fl_view_private.h"
|
||||
#include "flutter/shell/platform/linux/testing/fl_test.h"
|
||||
#include "flutter/shell/platform/linux/testing/fl_test_gtk_logs.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user