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 
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 {
32  bool is_down;
33  double physical_x;
34  double physical_y;
35  int64_t buttons;
36 };
37 
38 //------------------------------------------------------------------------------
39 /// Converter to convert the raw pointer data packet from the platforms.
40 ///
41 /// Framework requires certain information to process pointer data. e.g. pointer
42 /// identifier and the delta of pointer moment. The converter keeps track each
43 /// pointer state and fill in those information appropriately.
44 ///
45 /// The converter is also resposible for providing a clean pointer data stream.
46 /// It will attempt to correct the stream if the it contains illegal pointer
47 /// transitions.
48 ///
49 /// Example 1 Missing Add:
50 ///
51 /// Down(position x) -> Up(position x)
52 ///
53 /// ###After Conversion###
54 ///
55 /// Synthesized_Add(position x) -> Down(position x) -> Up(position x)
56 ///
57 /// Example 2 Missing another move:
58 ///
59 /// Add(position x) -> Down(position x) -> Move(position y) ->
60 /// Up(position z)
61 ///
62 /// ###After Conversion###
63 ///
64 /// Add(position x) -> Down(position x) -> Move(position y) ->
65 /// Synthesized_Move(position z) -> Up(position z)
66 ///
67 /// Platform view is the only client that uses this class to convert all the
68 /// incoming pointer packet and is responsible for the life cycle of its
69 /// instance.
70 ///
72  public:
75 
76  //----------------------------------------------------------------------------
77  /// @brief Converts pointer data packet into a form that framework
78  /// understands. The raw pointer data packet from embedding does
79  /// not have sufficient information and may contain illegal
80  /// pointer transitions. This method will fill out that
81  /// information and attempt to correct pointer transitions.
82  ///
83  /// @param[in] packet The raw pointer packet sent from
84  /// embedding.
85  ///
86  /// @return A full converted packet with all the required information
87  /// filled.
88  /// It may contain synthetic pointer data as the result of
89  /// converter's attempt to correct illegal pointer transitions.
90  ///
91  std::unique_ptr<PointerDataPacket> Convert(
92  std::unique_ptr<PointerDataPacket> packet);
93 
94  private:
95  std::map<int64_t, PointerState> states_;
96 
97  int64_t pointer_;
98 
99  void ConvertPointerData(PointerData pointer_data,
100  std::vector<PointerData>& converted_pointers);
101 
102  PointerState EnsurePointerState(PointerData pointer_data);
103 
104  void UpdateDeltaAndState(PointerData& pointer_data, PointerState& state);
105 
106  void UpdatePointerIdentifier(PointerData& pointer_data,
107  PointerState& state,
108  bool start_new_pointer);
109 
110  bool LocationNeedsUpdate(const PointerData pointer_data,
111  const PointerState state);
112 
114 };
115 
116 } // namespace flutter
117 
118 #endif // FLUTTER_LIB_UI_WINDOW_POINTER_DATA_PACKET_CONVERTER_H_
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition: macros.h:27
AtkStateType state