Flutter Engine
Loading...
Searching...
No Matches
pointer_data_packet_converter.h
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
#ifndef FLUTTER_LIB_UI_WINDOW_POINTER_DATA_PACKET_CONVERTER_H_
6
#define FLUTTER_LIB_UI_WINDOW_POINTER_DATA_PACKET_CONVERTER_H_
7
8
#include <cstring>
9
#include <map>
10
#include <memory>
11
#include <vector>
12
13
#include "
flutter/fml/macros.h
"
14
#include "
flutter/lib/ui/window/pointer_data_packet.h
"
15
16
namespace
flutter
{
17
18
//------------------------------------------------------------------------------
19
/// The current information about a pointer.
20
///
21
/// This struct is used by PointerDataPacketConverter to fill in necessary
22
/// information for the raw pointer packet sent from embedding. This struct also
23
/// stores the button state of the last pointer down, up, move, or hover event.
24
/// When an embedder issues a pointer up or down event where the pointer's
25
/// position has changed since the last move or hover event,
26
/// PointerDataPacketConverter generates a synthetic move or hover to notify the
27
/// framework. In these cases, these events must be issued with the button state
28
/// prior to the pointer up or down.
29
///
30
struct
PointerState
{
31
int64_t
pointer_identifier
;
32
bool
is_down
;
33
bool
is_pan_zoom_active
;
34
double
physical_x
;
35
double
physical_y
;
36
double
pan_x
;
37
double
pan_y
;
38
double
scale
;
39
double
rotation
;
40
int64_t
buttons
;
41
int64_t
view_id
;
42
};
43
44
//------------------------------------------------------------------------------
45
/// Converter to convert the raw pointer data packet from the platforms.
46
///
47
/// Framework requires certain information to process pointer data. e.g. pointer
48
/// identifier and the delta of pointer moment. The converter keeps track each
49
/// pointer state and fill in those information appropriately.
50
///
51
/// The converter is also resposible for providing a clean pointer data stream.
52
/// It will attempt to correct the stream if the it contains illegal pointer
53
/// transitions.
54
///
55
/// Example 1 Missing Add:
56
///
57
/// Down(position x) -> Up(position x)
58
///
59
/// ###After Conversion###
60
///
61
/// Synthesized_Add(position x) -> Down(position x) -> Up(position x)
62
///
63
/// Example 2 Missing another move:
64
///
65
/// Add(position x) -> Down(position x) -> Move(position y) ->
66
/// Up(position z)
67
///
68
/// ###After Conversion###
69
///
70
/// Add(position x) -> Down(position x) -> Move(position y) ->
71
/// Synthesized_Move(position z) -> Up(position z)
72
///
73
/// Platform view is the only client that uses this class to convert all the
74
/// incoming pointer packet and is responsible for the life cycle of its
75
/// instance.
76
///
77
class
PointerDataPacketConverter
{
78
public
:
79
// Used by PointerDataPacketConverter to query the system status.
80
//
81
// Typically RuntimeController.
82
class
Delegate
{
83
public
:
84
Delegate
() =
default
;
85
86
virtual
~Delegate
() =
default
;
87
88
// Returns true if the specified view exists.
89
virtual
bool
ViewExists
(int64_t
view_id
)
const
= 0;
90
};
91
92
//----------------------------------------------------------------------------
93
/// @brief Create a PointerDataPacketConverter.
94
///
95
/// @param[in] delegate A delegate to fulfill the query to the app state.
96
/// The delegate must exist throughout the lifetime
97
/// of this class. Typically `RuntimeController`.
98
explicit
PointerDataPacketConverter
(
const
Delegate
& delegate);
99
~PointerDataPacketConverter
();
100
101
//----------------------------------------------------------------------------
102
/// @brief Converts pointer data packet into a form that framework
103
/// understands. The raw pointer data packet from embedding does
104
/// not have sufficient information and may contain illegal
105
/// pointer transitions. This method will fill out that
106
/// information and attempt to correct pointer transitions.
107
///
108
/// Pointer data with invalid view IDs will be ignored.
109
///
110
/// @param[in] packet The raw pointer packet sent from
111
/// embedding.
112
///
113
/// @return A full converted packet with all the required information
114
/// filled. It may contain synthetic pointer data as the result of
115
/// converter's attempt to correct illegal pointer transitions.
116
///
117
std::unique_ptr<PointerDataPacket>
Convert
(
const
PointerDataPacket
& packet);
118
119
private
:
120
const
Delegate
& delegate_;
121
122
// A map from pointer device ID to the state of the pointer.
123
std::map<int64_t, PointerState> states_;
124
125
int64_t pointer_ = 0;
126
127
void
ConvertPointerData(
PointerData
pointer_data,
128
std::vector<PointerData>& converted_pointers);
129
130
PointerState
EnsurePointerState(
PointerData
pointer_data);
131
132
void
UpdateDeltaAndState(
PointerData
& pointer_data,
PointerState
& state);
133
134
void
UpdatePointerIdentifier(
PointerData
& pointer_data,
135
PointerState
& state,
136
bool
start_new_pointer);
137
138
bool
LocationNeedsUpdate(
const
PointerData
pointer_data,
139
const
PointerState
state);
140
141
FML_DISALLOW_COPY_AND_ASSIGN
(
PointerDataPacketConverter
);
142
};
143
144
}
// namespace flutter
145
146
#endif
// FLUTTER_LIB_UI_WINDOW_POINTER_DATA_PACKET_CONVERTER_H_
flutter::PointerDataPacketConverter::Delegate
Definition
pointer_data_packet_converter.h:82
flutter::PointerDataPacketConverter::Delegate::~Delegate
virtual ~Delegate()=default
flutter::PointerDataPacketConverter::Delegate::Delegate
Delegate()=default
flutter::PointerDataPacketConverter::Delegate::ViewExists
virtual bool ViewExists(int64_t view_id) const =0
flutter::PointerDataPacketConverter
Definition
pointer_data_packet_converter.h:77
flutter::PointerDataPacketConverter::~PointerDataPacketConverter
~PointerDataPacketConverter()
flutter::PointerDataPacketConverter::Convert
std::unique_ptr< PointerDataPacket > Convert(const PointerDataPacket &packet)
Converts pointer data packet into a form that framework understands. The raw pointer data packet from...
Definition
pointer_data_packet_converter.cc:19
flutter::PointerDataPacket
Definition
pointer_data_packet.h:16
view_id
G_BEGIN_DECLS FlutterViewId view_id
Definition
fl_view_accessible.h:49
macros.h
FML_DISALLOW_COPY_AND_ASSIGN
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition
macros.h:27
flutter
Definition
asset_manager.cc:10
pointer_data_packet.h
flutter::PointerData
Definition
pointer_data.h:38
flutter::PointerState
Definition
pointer_data_packet_converter.h:30
flutter::PointerState::physical_y
double physical_y
Definition
pointer_data_packet_converter.h:35
flutter::PointerState::rotation
double rotation
Definition
pointer_data_packet_converter.h:39
flutter::PointerState::buttons
int64_t buttons
Definition
pointer_data_packet_converter.h:40
flutter::PointerState::pan_y
double pan_y
Definition
pointer_data_packet_converter.h:37
flutter::PointerState::is_pan_zoom_active
bool is_pan_zoom_active
Definition
pointer_data_packet_converter.h:33
flutter::PointerState::is_down
bool is_down
Definition
pointer_data_packet_converter.h:32
flutter::PointerState::physical_x
double physical_x
Definition
pointer_data_packet_converter.h:34
flutter::PointerState::scale
double scale
Definition
pointer_data_packet_converter.h:38
flutter::PointerState::pan_x
double pan_x
Definition
pointer_data_packet_converter.h:36
flutter::PointerState::view_id
int64_t view_id
Definition
pointer_data_packet_converter.h:41
flutter::PointerState::pointer_identifier
int64_t pointer_identifier
Definition
pointer_data_packet_converter.h:31
lib
ui
window
pointer_data_packet_converter.h
Generated on Thu Nov 6 2025 16:11:25 for Flutter Engine by
1.9.8