Flutter Engine
The Flutter Engine
mock_im_context.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "flutter/shell/platform/linux/testing/mock_im_context.h"
6
7using namespace flutter::testing;
8
9G_DECLARE_FINAL_TYPE(FlMockIMContext,
10 fl_mock_im_context,
11 FL,
12 MOCK_IM_CONTEXT,
13 GtkIMContext)
14
15struct _FlMockIMContext {
16 GtkIMContext parent_instance;
17 MockIMContext* mock;
18};
19
20G_DEFINE_TYPE(FlMockIMContext, fl_mock_im_context, GTK_TYPE_IM_CONTEXT)
21
22static void fl_mock_im_context_set_client_window(GtkIMContext* context,
23 GdkWindow* window) {
24 FlMockIMContext* self = FL_MOCK_IM_CONTEXT(context);
25 self->mock->gtk_im_context_set_client_window(context, window);
26}
27
28static void fl_mock_im_context_get_preedit_string(GtkIMContext* context,
29 gchar** str,
30 PangoAttrList** attrs,
31 gint* cursor_pos) {
32 FlMockIMContext* self = FL_MOCK_IM_CONTEXT(context);
33 self->mock->gtk_im_context_get_preedit_string(context, str, attrs,
34 cursor_pos);
35}
36
37static gboolean fl_mock_im_context_filter_keypress(GtkIMContext* context,
38 GdkEventKey* event) {
39 FlMockIMContext* self = FL_MOCK_IM_CONTEXT(context);
40 return self->mock->gtk_im_context_filter_keypress(context, event);
41}
42
43static void fl_mock_im_context_focus_in(GtkIMContext* context) {
44 FlMockIMContext* self = FL_MOCK_IM_CONTEXT(context);
45 self->mock->gtk_im_context_focus_in(context);
46}
47
48static void fl_mock_im_context_focus_out(GtkIMContext* context) {
49 FlMockIMContext* self = FL_MOCK_IM_CONTEXT(context);
50 self->mock->gtk_im_context_focus_out(context);
51}
52
53static void fl_mock_im_context_reset(GtkIMContext* context) {
54 FlMockIMContext* self = FL_MOCK_IM_CONTEXT(context);
55 self->mock->gtk_im_context_reset(context);
56}
57
58static void fl_mock_im_context_set_cursor_location(GtkIMContext* context,
59 GdkRectangle* area) {
60 FlMockIMContext* self = FL_MOCK_IM_CONTEXT(context);
61 self->mock->gtk_im_context_set_cursor_location(context, area);
62}
63
64static void fl_mock_im_context_set_use_preedit(GtkIMContext* context,
65 gboolean use_preedit) {
66 FlMockIMContext* self = FL_MOCK_IM_CONTEXT(context);
67 self->mock->gtk_im_context_set_use_preedit(context, use_preedit);
68}
69
70static void fl_mock_im_context_set_surrounding(GtkIMContext* context,
71 const gchar* text,
72 gint len,
73 gint cursor_index) {
74 FlMockIMContext* self = FL_MOCK_IM_CONTEXT(context);
75 self->mock->gtk_im_context_set_surrounding(context, text, len, cursor_index);
76}
77
78static gboolean fl_mock_im_context_get_surrounding(GtkIMContext* context,
79 gchar** text,
80 gint* cursor_index) {
81 FlMockIMContext* self = FL_MOCK_IM_CONTEXT(context);
82 return self->mock->gtk_im_context_get_surrounding(context, text,
83 cursor_index);
84}
85
86static void fl_mock_im_context_class_init(FlMockIMContextClass* klass) {
87 GtkIMContextClass* im_context_class = GTK_IM_CONTEXT_CLASS(klass);
88 im_context_class->set_client_window = fl_mock_im_context_set_client_window;
89 im_context_class->get_preedit_string = fl_mock_im_context_get_preedit_string;
90 im_context_class->filter_keypress = fl_mock_im_context_filter_keypress;
91 im_context_class->focus_in = fl_mock_im_context_focus_in;
92 im_context_class->focus_out = fl_mock_im_context_focus_out;
93 im_context_class->reset = fl_mock_im_context_reset;
94 im_context_class->set_cursor_location =
96 im_context_class->set_use_preedit = fl_mock_im_context_set_use_preedit;
97 im_context_class->set_surrounding = fl_mock_im_context_set_surrounding;
98 im_context_class->get_surrounding = fl_mock_im_context_get_surrounding;
99}
100
101static void fl_mock_im_context_init(FlMockIMContext* self) {}
102
103static GtkIMContext* fl_mock_im_context_new(MockIMContext* mock) {
104 FlMockIMContext* self =
105 FL_MOCK_IM_CONTEXT(g_object_new(fl_mock_im_context_get_type(), nullptr));
106 self->mock = mock;
107 return GTK_IM_CONTEXT(self);
108}
109
110MockIMContext::~MockIMContext() {
111 if (FL_IS_MOCK_IM_CONTEXT(instance_)) {
112 g_clear_object(&instance_);
113 }
114}
115
116MockIMContext::operator GtkIMContext*() {
117 if (instance_ == nullptr) {
118 instance_ = fl_mock_im_context_new(this);
119 }
120 return instance_;
121}
GLFWwindow * window
Definition: main.cc:45
G_DEFINE_TYPE(FlBasicMessageChannelResponseHandle, fl_basic_message_channel_response_handle, G_TYPE_OBJECT) static void fl_basic_message_channel_response_handle_dispose(GObject *object)
FlKeyEvent * event
std::u16string text
static void fl_mock_im_context_set_use_preedit(GtkIMContext *context, gboolean use_preedit)
static void fl_mock_im_context_init(FlMockIMContext *self)
static gboolean fl_mock_im_context_filter_keypress(GtkIMContext *context, GdkEventKey *event)
static void fl_mock_im_context_focus_in(GtkIMContext *context)
static void fl_mock_im_context_get_preedit_string(GtkIMContext *context, gchar **str, PangoAttrList **attrs, gint *cursor_pos)
static GtkIMContext * fl_mock_im_context_new(MockIMContext *mock)
static void fl_mock_im_context_focus_out(GtkIMContext *context)
static gboolean fl_mock_im_context_get_surrounding(GtkIMContext *context, gchar **text, gint *cursor_index)
static void fl_mock_im_context_set_client_window(GtkIMContext *context, GdkWindow *window)
static void fl_mock_im_context_class_init(FlMockIMContextClass *klass)
static void fl_mock_im_context_set_surrounding(GtkIMContext *context, const gchar *text, gint len, gint cursor_index)
static void fl_mock_im_context_set_cursor_location(GtkIMContext *context, GdkRectangle *area)
static void fl_mock_im_context_reset(GtkIMContext *context)
G_DECLARE_FINAL_TYPE(FlMockIMContext, fl_mock_im_context, FL, MOCK_IM_CONTEXT, GtkIMContext) struct _FlMockIMContext