| Flutter Linux Embedder |

Classes | Functions | Variables
fl_scrolling_manager.cc File Reference
`#include "flutter/shell/platform/linux/fl_scrolling_manager.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 (FlScrollingViewDelegate *view_delegate)
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 }

References fl_scrolling_manager_dispose().

## ◆ fl_scrolling_manager_dispose()

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

Definition at line 29 of file fl_scrolling_manager.cc.

29 {
30 FlScrollingManager* self = FL_SCROLLING_MANAGER(object);
31
32 if (self->view_delegate != nullptr) {
33 g_object_remove_weak_pointer(
34 object, reinterpret_cast<gpointer*>(&self->view_delegate));
35 self->view_delegate = nullptr;
36 }
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 151 of file fl_scrolling_manager.cc.

151 {
152 g_return_if_fail(FL_IS_SCROLLING_MANAGER(self));
153
154 self->rotate_started = TRUE;
155 if (!self->zoom_started) {
156 self->scale = 1;
157 self->rotation = 0;
158 fl_scrolling_view_delegate_send_pointer_pan_zoom_event(
159 self->view_delegate, g_get_real_time(), self->last_x, self->last_y,
160 kPanZoomStart, 0, 0, 0, 0);
161 }
162 }

References fl_scrolling_view_delegate_send_pointer_pan_zoom_event(), and TRUE.

Referenced by gesture_rotation_begin_cb().

## ◆ 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 174 of file fl_scrolling_manager.cc.

174 {
175 g_return_if_fail(FL_IS_SCROLLING_MANAGER(self));
176
177 self->rotate_started = FALSE;
178 if (!self->zoom_started) {
179 fl_scrolling_view_delegate_send_pointer_pan_zoom_event(
180 self->view_delegate, g_get_real_time(), self->last_x, self->last_y,
181 kPanZoomEnd, 0, 0, 0, 0);
182 }
183 }

References fl_scrolling_view_delegate_send_pointer_pan_zoom_event().

Referenced by gesture_rotation_end_cb().

## ◆ 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 164 of file fl_scrolling_manager.cc.

165 {
166 g_return_if_fail(FL_IS_SCROLLING_MANAGER(self));
167
168 self->rotation = rotation;
169 fl_scrolling_view_delegate_send_pointer_pan_zoom_event(
170 self->view_delegate, g_get_real_time(), self->last_x, self->last_y,
171 kPanZoomUpdate, 0, 0, self->scale, self->rotation);
172 }

References fl_scrolling_view_delegate_send_pointer_pan_zoom_event().

Referenced by gesture_rotation_update_cb().

## ◆ 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 74 of file fl_scrolling_manager.cc.

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

References event, fl_scrolling_view_delegate_send_mouse_pointer_event(), fl_scrolling_view_delegate_send_pointer_pan_zoom_event(), kMicrosecondsPerMillisecond, and TRUE.

Referenced by scroll_event_cb().

## ◆ 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 185 of file fl_scrolling_manager.cc.

185 {
186 g_return_if_fail(FL_IS_SCROLLING_MANAGER(self));
187
188 self->zoom_started = TRUE;
189 if (!self->rotate_started) {
190 self->scale = 1;
191 self->rotation = 0;
192 fl_scrolling_view_delegate_send_pointer_pan_zoom_event(
193 self->view_delegate, g_get_real_time(), self->last_x, self->last_y,
194 kPanZoomStart, 0, 0, 0, 0);
195 }
196 }

References fl_scrolling_view_delegate_send_pointer_pan_zoom_event(), and TRUE.

Referenced by gesture_zoom_begin_cb().

## ◆ 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 208 of file fl_scrolling_manager.cc.

208 {
209 g_return_if_fail(FL_IS_SCROLLING_MANAGER(self));
210
211 self->zoom_started = FALSE;
212 if (!self->rotate_started) {
213 fl_scrolling_view_delegate_send_pointer_pan_zoom_event(
214 self->view_delegate, g_get_real_time(), self->last_x, self->last_y,
215 kPanZoomEnd, 0, 0, 0, 0);
216 }
217 }

References fl_scrolling_view_delegate_send_pointer_pan_zoom_event().

Referenced by gesture_zoom_end_cb().

## ◆ 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 198 of file fl_scrolling_manager.cc.

199 {
200 g_return_if_fail(FL_IS_SCROLLING_MANAGER(self));
201
202 self->scale = scale;
203 fl_scrolling_view_delegate_send_pointer_pan_zoom_event(
204 self->view_delegate, g_get_real_time(), self->last_x, self->last_y,
205 kPanZoomUpdate, 0, 0, self->scale, self->rotation);
206 }

References fl_scrolling_view_delegate_send_pointer_pan_zoom_event().

Referenced by gesture_zoom_update_cb().

## ◆ 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 | ( | FlScrollingViewDelegate * | view_delegate | ) |

fl_scrolling_manager_new: @view_delegate: An interface that the manager requires to communicate with the platform. Usually implemented by FlView.

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_SCROLLING_VIEW_DELEGATE(view_delegate), nullptr);
50
51 FlScrollingManager* self = FL_SCROLLING_MANAGER(
52 g_object_new(fl_scrolling_manager_get_type(), nullptr));
53
54 self->view_delegate = view_delegate;
55 g_object_add_weak_pointer(
56 G_OBJECT(view_delegate),
57 reinterpret_cast<gpointer*>(&(self->view_delegate)));
58
59 self->pan_started = FALSE;
60 self->zoom_started = FALSE;
61 self->rotate_started = FALSE;
62
63 return self;
64 }

Referenced by init_scrolling().

## ◆ 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 66 of file fl_scrolling_manager.cc.

68 {
69 g_return_if_fail(FL_IS_SCROLLING_MANAGER(self));
70 self->last_x = x;
71 self->last_y = y;
72 }

Referenced by send_pointer_button_event().

## ◆ 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 7 of file fl_scrolling_manager.cc.

Referenced by fl_scrolling_manager_handle_scroll_event().

event
FlKeyEvent * event
Definition: fl_key_channel_responder.cc:118
fl_scrolling_manager_dispose
static void fl_scrolling_manager_dispose(GObject *object)
Definition: fl_scrolling_manager.cc:29
fl_scrolling_view_delegate_send_mouse_pointer_event
void fl_scrolling_view_delegate_send_mouse_pointer_event(FlScrollingViewDelegate *self, 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_scrolling_view_delegate.cc:14
TRUE
return TRUE
Definition: fl_pixel_buffer_texture_test.cc:53
kMicrosecondsPerMillisecond
static constexpr int kMicrosecondsPerMillisecond
Definition: fl_scrolling_manager.cc:7
fl_scrolling_view_delegate_send_pointer_pan_zoom_event
void fl_scrolling_view_delegate_send_pointer_pan_zoom_event(FlScrollingViewDelegate *self, size_t timestamp, double x, double y, FlutterPointerPhase phase, double pan_x, double pan_y, double scale, double rotation)
Definition: fl_scrolling_view_delegate.cc:30