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