Flutter Engine
The 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
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:
80
81 //----------------------------------------------------------------------------
82 /// @brief Converts pointer data packet into a form that framework
83 /// understands. The raw pointer data packet from embedding does
84 /// not have sufficient information and may contain illegal
85 /// pointer transitions. This method will fill out that
86 /// information and attempt to correct pointer transitions.
87 ///
88 /// @param[in] packet The raw pointer packet sent from
89 /// embedding.
90 ///
91 /// @return A full converted packet with all the required information
92 /// filled.
93 /// It may contain synthetic pointer data as the result of
94 /// converter's attempt to correct illegal pointer transitions.
95 ///
96 std::unique_ptr<PointerDataPacket> Convert(
97 std::unique_ptr<PointerDataPacket> packet);
98
99 private:
100 std::map<int64_t, PointerState> states_;
101
102 int64_t pointer_ = 0;
103
104 void ConvertPointerData(PointerData pointer_data,
105 std::vector<PointerData>& converted_pointers);
106
107 PointerState EnsurePointerState(PointerData pointer_data);
108
109 void UpdateDeltaAndState(PointerData& pointer_data, PointerState& state);
110
111 void UpdatePointerIdentifier(PointerData& pointer_data,
113 bool start_new_pointer);
114
115 bool LocationNeedsUpdate(const PointerData pointer_data,
116 const PointerState state);
117
119};
120
121} // namespace flutter
122
123#endif // FLUTTER_LIB_UI_WINDOW_POINTER_DATA_PACKET_CONVERTER_H_
std::unique_ptr< PointerDataPacket > Convert(std::unique_ptr< PointerDataPacket > packet)
Converts pointer data packet into a form that framework understands. The raw pointer data packet from...
AtkStateType state
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27