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"
15
16namespace 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///
32 bool is_down;
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///
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);
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
142};
143
144} // namespace flutter
145
146#endif // FLUTTER_LIB_UI_WINDOW_POINTER_DATA_PACKET_CONVERTER_H_
virtual bool ViewExists(int64_t view_id) const =0
std::unique_ptr< PointerDataPacket > Convert(const PointerDataPacket &packet)
Converts pointer data packet into a form that framework understands. The raw pointer data packet from...
G_BEGIN_DECLS FlutterViewId view_id
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27