| Flutter Linux Embedder |

Classes | Functions | Variables
fl_scrolling_manager.cc File Reference
`#include "flutter/shell/platform/linux/fl_scrolling_manager.h"`
`#include "flutter/shell/platform/embedder/embedder.h"`
`#include "flutter/shell/platform/linux/fl_engine_private.h"`

Go to the source code of this file.

## Classes
struct | _FlScrollingManager

## Functions
| G_DEFINE_TYPE (FlScrollingManager, fl_scrolling_manager, G_TYPE_OBJECT)
static void | fl_scrolling_manager_dispose (GObject *object)
static void | fl_scrolling_manager_class_init (FlScrollingManagerClass *klass)
static void | fl_scrolling_manager_init (FlScrollingManager *self)
FlScrollingManager * | fl_scrolling_manager_new (FlEngine *engine, FlutterViewId view_id)
void | fl_scrolling_manager_set_last_mouse_position (FlScrollingManager *self, gdouble x, gdouble y)
void | fl_scrolling_manager_handle_scroll_event (FlScrollingManager *self, GdkEventScroll *scroll_event, gint scale_factor)
void | fl_scrolling_manager_handle_rotation_begin (FlScrollingManager *self)
void | fl_scrolling_manager_handle_rotation_update (FlScrollingManager *self, gdouble rotation)
void | fl_scrolling_manager_handle_rotation_end (FlScrollingManager *self)
void | fl_scrolling_manager_handle_zoom_begin (FlScrollingManager *self)
void | fl_scrolling_manager_handle_zoom_update (FlScrollingManager *self, gdouble scale)
void | fl_scrolling_manager_handle_zoom_end (FlScrollingManager *self)

## Variables
static constexpr int | kMicrosecondsPerMillisecond = 1000

## Function Documentation

## ◆ fl_scrolling_manager_class_init()

static void fl_scrolling_manager_class_init | ( | FlScrollingManagerClass * | klass | ) |
| static

Definition at line 41 of file fl_scrolling_manager.cc.

41 {
42 G_OBJECT_CLASS(klass)->dispose = fl_scrolling_manager_dispose;
43 }
fl_scrolling_manager_dispose
static void fl_scrolling_manager_dispose(GObject *object)
Definition: fl_scrolling_manager.cc:33

References fl_scrolling_manager_dispose().

## ◆ fl_scrolling_manager_dispose()

static void fl_scrolling_manager_dispose | ( | GObject * | object | ) |
| static

Definition at line 33 of file fl_scrolling_manager.cc.

33 {
34 FlScrollingManager* self = FL_SCROLLING_MANAGER(object);
35
36 g_weak_ref_clear(&self->engine);
37
38 G_OBJECT_CLASS(fl_scrolling_manager_parent_class)->dispose(object);
39 }

Referenced by fl_scrolling_manager_class_init().

## ◆ fl_scrolling_manager_handle_rotation_begin()

void fl_scrolling_manager_handle_rotation_begin | ( | FlScrollingManager * | manager | ) |

fl_scrolling_manager_handle_rotation_begin: @manager: an #FlScrollingManager.

Inform the scrolling manager that a rotation gesture has begun.

Definition at line 153 of file fl_scrolling_manager.cc.

153 {
154 g_return_if_fail(FL_IS_SCROLLING_MANAGER(self));
155
156 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
157 if (engine == nullptr) {
158 return;
159 }
160
161 self->rotate_started = TRUE;
162 if (!self->zoom_started) {
163 self->scale = 1;
164 self->rotation = 0;
165 fl_engine_send_pointer_pan_zoom_event(
166 engine, self->view_id, g_get_real_time(), self->last_x, self->last_y,
167 kPanZoomStart, 0, 0, 0, 0);
168 }
169 }
g_autoptr
g_autoptr(GMutexLocker) locker
TRUE
return TRUE
Definition: fl_compositor_software.cc:68
fl_engine_send_pointer_pan_zoom_event
void fl_engine_send_pointer_pan_zoom_event(FlEngine *self, FlutterViewId view_id, size_t timestamp, double x, double y, FlutterPointerPhase phase, double pan_x, double pan_y, double scale, double rotation)
Definition: fl_engine.cc:1314

References fl_engine_send_pointer_pan_zoom_event(), g_autoptr(), and TRUE.

Referenced by gesture_rotation_begin_cb(), and TEST().

## ◆ fl_scrolling_manager_handle_rotation_end()

void fl_scrolling_manager_handle_rotation_end | ( | FlScrollingManager * | manager | ) |

fl_scrolling_manager_handle_rotation_end: @manager: an #FlScrollingManager.

Inform the scrolling manager that a rotation gesture has ended.

Definition at line 186 of file fl_scrolling_manager.cc.

186 {
187 g_return_if_fail(FL_IS_SCROLLING_MANAGER(self));
188
189 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
190 if (engine == nullptr) {
191 return;
192 }
193
194 self->rotate_started = FALSE;
195 if (!self->zoom_started) {
196 fl_engine_send_pointer_pan_zoom_event(
197 engine, self->view_id, g_get_real_time(), self->last_x, self->last_y,
198 kPanZoomEnd, 0, 0, 0, 0);
199 }
200 }

References fl_engine_send_pointer_pan_zoom_event(), and g_autoptr().

Referenced by gesture_rotation_end_cb(), and TEST().

## ◆ fl_scrolling_manager_handle_rotation_update()

void fl_scrolling_manager_handle_rotation_update | ( | FlScrollingManager * | manager,
|  | gdouble | rotation
| ) |  |

fl_scrolling_manager_handle_rotation_update: @manager: an #FlScrollingManager. @rotation: the rotation angle, in radians.

Inform the scrolling manager that a rotation gesture has updated.

Definition at line 171 of file fl_scrolling_manager.cc.

172 {
173 g_return_if_fail(FL_IS_SCROLLING_MANAGER(self));
174
175 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
176 if (engine == nullptr) {
177 return;
178 }
179
180 self->rotation = rotation;
181 fl_engine_send_pointer_pan_zoom_event(
182 engine, self->view_id, g_get_real_time(), self->last_x, self->last_y,
183 kPanZoomUpdate, 0, 0, self->scale, self->rotation);
184 }

References fl_engine_send_pointer_pan_zoom_event(), and g_autoptr().

Referenced by gesture_rotation_update_cb(), and TEST().

## ◆ fl_scrolling_manager_handle_scroll_event()

void fl_scrolling_manager_handle_scroll_event | ( | FlScrollingManager * | manager,
|  | GdkEventScroll * | event,
|  | gint | scale_factor
| ) |  |

fl_scrolling_manager_handle_scroll_event: @manager: an #FlScrollingManager. @event: the scroll event. @scale_factor: the GTK scaling factor of the window.

Inform the scrolling manager of a scroll event.

Definition at line 71 of file fl_scrolling_manager.cc.

73 {
74 g_return_if_fail(FL_IS_SCROLLING_MANAGER(self));
75
76 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
77 if (engine == nullptr) {
78 return;
79 }
80
81 GdkEvent* event = reinterpret_cast<GdkEvent*>(scroll_event);
82
83 guint event_time = gdk_event_get_time(event);
84 gdouble event_x = 0.0, event_y = 0.0;
85 gdk_event_get_coords(event, &event_x, &event_y);
86 gdouble scroll_delta_x = 0.0, scroll_delta_y = 0.0;
87 GdkScrollDirection event_direction = GDK_SCROLL_SMOOTH;
88 if (gdk_event_get_scroll_direction(event, &event_direction)) {
89 if (event_direction == GDK_SCROLL_UP) {
90 scroll_delta_x = 0;
91 scroll_delta_y = -1;
92 } else if (event_direction == GDK_SCROLL_DOWN) {
93 scroll_delta_x = 0;
94 scroll_delta_y = 1;
95 } else if (event_direction == GDK_SCROLL_LEFT) {
96 scroll_delta_x = -1;
97 scroll_delta_y = 0;
98 } else if (event_direction == GDK_SCROLL_RIGHT) {
99 scroll_delta_x = 1;
100 scroll_delta_y = 0;
101 }
102 } else {
103 gdk_event_get_scroll_deltas(event, &scroll_delta_x, &scroll_delta_y);
104 }
105
106 // The multiplier is taken from the Chromium source
107 // (ui/events/x/events_x_utils.cc).
108 const int kScrollOffsetMultiplier = 53;
109 scroll_delta_x *= kScrollOffsetMultiplier * scale_factor;
110 scroll_delta_y *= kScrollOffsetMultiplier * scale_factor;
111
112 if (gdk_device_get_source(gdk_event_get_source_device(event)) ==
113 GDK_SOURCE_TOUCHPAD) {
114 scroll_delta_x *= -1;
115 scroll_delta_y *= -1;
116 if (gdk_event_is_scroll_stop_event(event)) {
117 fl_engine_send_pointer_pan_zoom_event(
118 engine, self->view_id, event_time * kMicrosecondsPerMillisecond,
119 event_x * scale_factor, event_y * scale_factor, kPanZoomEnd,
120 self->pan_x, self->pan_y, 0, 0);
121 self->pan_started = FALSE;
122 } else {
123 if (!self->pan_started) {
124 self->pan_x = 0;
125 self->pan_y = 0;
126 fl_engine_send_pointer_pan_zoom_event(
127 engine, self->view_id, event_time * kMicrosecondsPerMillisecond,
128 event_x * scale_factor, event_y * scale_factor, kPanZoomStart, 0, 0,
129 0, 0);
130 self->pan_started = TRUE;
131 }
132 self->pan_x += scroll_delta_x;
133 self->pan_y += scroll_delta_y;
134 fl_engine_send_pointer_pan_zoom_event(
135 engine, self->view_id, event_time * kMicrosecondsPerMillisecond,
136 event_x * scale_factor, event_y * scale_factor, kPanZoomUpdate,
137 self->pan_x, self->pan_y, 1, 0);
138 }
139 } else {
140 self->last_x = event_x * scale_factor;
141 self->last_y = event_y * scale_factor;
142 fl_engine_send_mouse_pointer_event(
143 engine, self->view_id,
144 FlutterPointerPhase::kMove /* arbitrary value, phase will be ignored as
145 this is a discrete scroll event */
146 ,
147 event_time * kMicrosecondsPerMillisecond, event_x * scale_factor,
148 event_y * scale_factor, kFlutterPointerDeviceKindMouse, scroll_delta_x,
149 scroll_delta_y, 0);
150 }
151 }
fl_engine_send_mouse_pointer_event
void fl_engine_send_mouse_pointer_event(FlEngine *self, FlutterViewId view_id, FlutterPointerPhase phase, size_t timestamp, double x, double y, FlutterPointerDeviceKind device_kind, double scroll_delta_x, double scroll_delta_y, int64_t buttons)
Definition: fl_engine.cc:1132
kMicrosecondsPerMillisecond
static constexpr int kMicrosecondsPerMillisecond
Definition: fl_scrolling_manager.cc:9

References fl_engine_send_mouse_pointer_event(), fl_engine_send_pointer_pan_zoom_event(), g_autoptr(), kMicrosecondsPerMillisecond, and TRUE.

Referenced by scroll_event_cb(), and TEST().

## ◆ fl_scrolling_manager_handle_zoom_begin()

void fl_scrolling_manager_handle_zoom_begin | ( | FlScrollingManager * | manager | ) |

fl_scrolling_manager_handle_zoom_begin: @manager: an #FlScrollingManager.

Inform the scrolling manager that a zoom gesture has begun.

Definition at line 202 of file fl_scrolling_manager.cc.

202 {
203 g_return_if_fail(FL_IS_SCROLLING_MANAGER(self));
204
205 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
206 if (engine == nullptr) {
207 return;
208 }
209
210 self->zoom_started = TRUE;
211 if (!self->rotate_started) {
212 self->scale = 1;
213 self->rotation = 0;
214 fl_engine_send_pointer_pan_zoom_event(
215 engine, self->view_id, g_get_real_time(), self->last_x, self->last_y,
216 kPanZoomStart, 0, 0, 0, 0);
217 }
218 }

References fl_engine_send_pointer_pan_zoom_event(), g_autoptr(), and TRUE.

Referenced by gesture_zoom_begin_cb(), and TEST().

## ◆ fl_scrolling_manager_handle_zoom_end()

void fl_scrolling_manager_handle_zoom_end | ( | FlScrollingManager * | manager | ) |

fl_scrolling_manager_handle_zoom_end: @manager: an #FlScrollingManager.

Inform the scrolling manager that a zoom gesture has ended.

Definition at line 235 of file fl_scrolling_manager.cc.

235 {
236 g_return_if_fail(FL_IS_SCROLLING_MANAGER(self));
237
238 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
239 if (engine == nullptr) {
240 return;
241 }
242
243 self->zoom_started = FALSE;
244 if (!self->rotate_started) {
245 fl_engine_send_pointer_pan_zoom_event(
246 engine, self->view_id, g_get_real_time(), self->last_x, self->last_y,
247 kPanZoomEnd, 0, 0, 0, 0);
248 }
249 }

References fl_engine_send_pointer_pan_zoom_event(), and g_autoptr().

Referenced by gesture_zoom_end_cb(), and TEST().

## ◆ fl_scrolling_manager_handle_zoom_update()

void fl_scrolling_manager_handle_zoom_update | ( | FlScrollingManager * | manager,
|  | gdouble | scale
| ) |  |

fl_scrolling_manager_handle_zoom_update: @manager: an #FlScrollingManager. @scale: the zoom scale.

Inform the scrolling manager that a zoom gesture has updated.

Definition at line 220 of file fl_scrolling_manager.cc.

221 {
222 g_return_if_fail(FL_IS_SCROLLING_MANAGER(self));
223
224 g_autoptr(FlEngine) engine = FL_ENGINE(g_weak_ref_get(&self->engine));
225 if (engine == nullptr) {
226 return;
227 }
228
229 self->scale = scale;
230 fl_engine_send_pointer_pan_zoom_event(
231 engine, self->view_id, g_get_real_time(), self->last_x, self->last_y,
232 kPanZoomUpdate, 0, 0, self->scale, self->rotation);
233 }

References fl_engine_send_pointer_pan_zoom_event(), and g_autoptr().

Referenced by gesture_zoom_update_cb(), and TEST().

## ◆ fl_scrolling_manager_init()

static void fl_scrolling_manager_init | ( | FlScrollingManager * | self | ) |
| static

Definition at line 45 of file fl_scrolling_manager.cc.

45 {}

## ◆ fl_scrolling_manager_new()

FlScrollingManager* fl_scrolling_manager_new | ( | FlEngine * | engine,
|  | FlutterViewId | view_id
| ) |  |

fl_scrolling_manager_new: @engine: an #FlEngine. @view_id: the view being managed.

Create a new #FlScrollingManager.

Returns: a new #FlScrollingManager.

Definition at line 47 of file fl_scrolling_manager.cc.

48 {
49 g_return_val_if_fail(FL_IS_ENGINE(engine), nullptr);
50
51 FlScrollingManager* self = FL_SCROLLING_MANAGER(
52 g_object_new(fl_scrolling_manager_get_type(), nullptr));
53
54 g_weak_ref_init(&self->engine, engine);
55 self->view_id = view_id;
56 self->pan_started = FALSE;
57 self->zoom_started = FALSE;
58 self->rotate_started = FALSE;
59
60 return self;
61 }
view_id
G_BEGIN_DECLS FlutterViewId view_id
Definition: fl_view_accessible.h:49

References view_id.

Referenced by init_scrolling(), and TEST().

## ◆ fl_scrolling_manager_set_last_mouse_position()

void fl_scrolling_manager_set_last_mouse_position | ( | FlScrollingManager * | manager,
|  | gdouble | x,
|  | gdouble | y
| ) |  |

fl_scrolling_manager_set_last_mouse_position: @manager: an #FlScrollingManager. @x: the mouse x-position, in window coordinates. @y: the mouse y-position, in window coordinates.

Inform the scrolling manager of the mouse position. This position will be used when sending scroll pointer events.

Definition at line 63 of file fl_scrolling_manager.cc.

65 {
66 g_return_if_fail(FL_IS_SCROLLING_MANAGER(self));
67 self->last_x = x;
68 self->last_y = y;
69 }

Referenced by set_scrolling_position().

## ◆ G_DEFINE_TYPE()

G_DEFINE_TYPE | ( | FlScrollingManager | ,
|  | fl_scrolling_manager | ,
|  | G_TYPE_OBJECT |
| ) |  |

## Variable Documentation

## ◆ kMicrosecondsPerMillisecond

constexpr int kMicrosecondsPerMillisecond = 1000
| static constexpr

Definition at line 9 of file fl_scrolling_manager.cc.

Referenced by fl_scrolling_manager_handle_scroll_event().