Flutter Engine
The Flutter Engine
Macros | Functions
fl_scrolling_manager.h File Reference
#include <gdk/gdk.h>
#include "flutter/shell/platform/linux/fl_scrolling_view_delegate.h"

Go to the source code of this file.

Macros

#define FL_TYPE_SCROLLING_MANAGER   fl_scrolling_manager_get_type()
 

Functions

 G_DECLARE_FINAL_TYPE (FlScrollingManager, fl_scrolling_manager, FL, SCROLLING_MANAGER, GObject)
 
FlScrollingManager * fl_scrolling_manager_new (FlScrollingViewDelegate *view_delegate)
 
void fl_scrolling_manager_set_last_mouse_position (FlScrollingManager *manager, gdouble x, gdouble y)
 
void fl_scrolling_manager_handle_scroll_event (FlScrollingManager *manager, GdkEventScroll *event, gint scale_factor)
 
void fl_scrolling_manager_handle_rotation_begin (FlScrollingManager *manager)
 
void fl_scrolling_manager_handle_rotation_update (FlScrollingManager *manager, gdouble rotation)
 
void fl_scrolling_manager_handle_rotation_end (FlScrollingManager *manager)
 
void fl_scrolling_manager_handle_zoom_begin (FlScrollingManager *manager)
 
void fl_scrolling_manager_handle_zoom_update (FlScrollingManager *manager, gdouble scale)
 
void fl_scrolling_manager_handle_zoom_end (FlScrollingManager *manager)
 

Macro Definition Documentation

◆ FL_TYPE_SCROLLING_MANAGER

#define FL_TYPE_SCROLLING_MANAGER   fl_scrolling_manager_get_type()

Definition at line 14 of file fl_scrolling_manager.h.

Function Documentation

◆ 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;
159 self->view_delegate, g_get_real_time(), self->last_x, self->last_y,
160 kPanZoomStart, 0, 0, 0, 0);
161 }
162}
@ kPanZoomStart
A pan/zoom started on this pointer.
Definition: embedder.h:999
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)

◆ 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) {
180 self->view_delegate, g_get_real_time(), self->last_x, self->last_y,
181 kPanZoomEnd, 0, 0, 0, 0);
182 }
183}
@ kPanZoomEnd
The pan/zoom ended.
Definition: embedder.h:1003
return FALSE

◆ 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;
170 self->view_delegate, g_get_real_time(), self->last_x, self->last_y,
171 kPanZoomUpdate, 0, 0, self->scale, self->rotation);
172}
@ kPanZoomUpdate
The pan/zoom updated.
Definition: embedder.h:1001

◆ 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)) {
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;
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;
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;
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}
@ kMove
Definition: embedder.h:985
@ kFlutterPointerDeviceKindMouse
Definition: embedder.h:1008
FlKeyEvent * event
static constexpr int kMicrosecondsPerMillisecond
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)

◆ 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;
193 self->view_delegate, g_get_real_time(), self->last_x, self->last_y,
194 kPanZoomStart, 0, 0, 0, 0);
195 }
196}

◆ 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) {
214 self->view_delegate, g_get_real_time(), self->last_x, self->last_y,
215 kPanZoomEnd, 0, 0, 0, 0);
216 }
217}

◆ 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;
204 self->view_delegate, g_get_real_time(), self->last_x, self->last_y,
205 kPanZoomUpdate, 0, 0, self->scale, self->rotation);
206}
const Scalar scale

◆ 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}

◆ 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}
double y
double x

◆ G_DECLARE_FINAL_TYPE()

G_DECLARE_FINAL_TYPE ( FlScrollingManager  ,
fl_scrolling_manager  ,
FL  ,
SCROLLING_MANAGER  ,
GObject   
)