Flutter Engine
The Flutter Engine
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
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};
42
43//------------------------------------------------------------------------------
44/// Converter to convert the raw pointer data packet from the platforms.
45///
46/// Framework requires certain information to process pointer data. e.g. pointer
47/// identifier and the delta of pointer moment. The converter keeps track each
48/// pointer state and fill in those information appropriately.
49///
50/// The converter is also resposible for providing a clean pointer data stream.
51/// It will attempt to correct the stream if the it contains illegal pointer
52/// transitions.
53///
54/// Example 1 Missing Add:
55///
56/// Down(position x) -> Up(position x)
57///
58/// ###After Conversion###
59///
60/// Synthesized_Add(position x) -> Down(position x) -> Up(position x)
61///
62/// Example 2 Missing another move:
63///
64/// Add(position x) -> Down(position x) -> Move(position y) ->
65/// Up(position z)
66///
67/// ###After Conversion###
68///
69/// Add(position x) -> Down(position x) -> Move(position y) ->
70/// Synthesized_Move(position z) -> Up(position z)
71///
72/// Platform view is the only client that uses this class to convert all the
73/// incoming pointer packet and is responsible for the life cycle of its
74/// instance.
75///
77 public:
78 // Used by PointerDataPacketConverter to query the system status.
79 //
80 // Typically RuntimeController.
81 class Delegate {
82 public:
83 Delegate() = default;
84
85 virtual ~Delegate() = default;
86
87 // Returns true if the specified view exists.
88 virtual bool ViewExists(int64_t view_id) const = 0;
89 };
90
91 //----------------------------------------------------------------------------
92 /// @brief Create a PointerDataPacketConverter.
93 ///
94 /// @param[in] delegate A delegate to fulfill the query to the app state.
95 /// The delegate must exist throughout the lifetime
96 /// of this class. Typically `RuntimeController`.
97 explicit PointerDataPacketConverter(const Delegate& delegate);
99
100 //----------------------------------------------------------------------------
101 /// @brief Converts pointer data packet into a form that framework
102 /// understands. The raw pointer data packet from embedding does
103 /// not have sufficient information and may contain illegal
104 /// pointer transitions. This method will fill out that
105 /// information and attempt to correct pointer transitions.
106 ///
107 /// Pointer data with invalid view IDs will be ignored.
108 ///
109 /// @param[in] packet The raw pointer packet sent from
110 /// embedding.
111 ///
112 /// @return A full converted packet with all the required information
113 /// filled. It may contain synthetic pointer data as the result of
114 /// converter's attempt to correct illegal pointer transitions.
115 ///
116 std::unique_ptr<PointerDataPacket> Convert(const PointerDataPacket& packet);
117
118 private:
119 const Delegate& delegate_;
120
121 // A map from pointer device ID to the state of the pointer.
122 std::map<int64_t, PointerState> states_;
123
124 int64_t pointer_ = 0;
125
126 void ConvertPointerData(PointerData pointer_data,
127 std::vector<PointerData>& converted_pointers);
128
129 PointerState EnsurePointerState(PointerData pointer_data);
130
131 void UpdateDeltaAndState(PointerData& pointer_data, PointerState& state);
132
133 void UpdatePointerIdentifier(PointerData& pointer_data,
135 bool start_new_pointer);
136
137 bool LocationNeedsUpdate(const PointerData pointer_data,
138 const PointerState state);
139
140 FML_DISALLOW_COPY_AND_ASSIGN(PointerDataPacketConverter);
141};
142
143} // namespace flutter
144
145#endif // FLUTTER_LIB_UI_WINDOW_POINTER_DATA_PACKET_CONVERTER_H_
virtual bool ViewExists(int64_t view_id) const =0
PointerDataPacketConverter(const Delegate &delegate)
Create a PointerDataPacketConverter.
std::unique_ptr< PointerDataPacket > Convert(const PointerDataPacket &packet)
Converts pointer data packet into a form that framework understands. The raw pointer data packet from...
AtkStateType state