77#include < gmodule.h>
88
99#include < cstring>
10- #include < string>
11- #include < unordered_map>
12- #include < vector>
1310
1411#include " flutter/common/constants.h"
1512#include " flutter/shell/platform/common/engine_switches.h"
@@ -480,7 +477,8 @@ static void fl_engine_init(FlEngine* self) {
480477
481478 self->texture_registrar = fl_texture_registrar_new (self);
482479
483- self->pointer_states = g_hash_table_new_full (g_direct_hash, g_direct_equal, nullptr , nullptr );
480+ self->pointer_states =
481+ g_hash_table_new_full (g_direct_hash, g_direct_equal, nullptr , nullptr );
484482}
485483
486484FlEngine* fl_engine_new_with_renderer (FlDartProject* project,
@@ -910,7 +908,6 @@ void fl_engine_send_mouse_pointer_event(FlEngine* self,
910908 self->embedder_api .SendPointerEvent (self->engine , &fl_event, 1 );
911909}
912910
913-
914911// Set's |event_data|'s phase to either kMove or kHover depending on the current
915912// primary mouse button state.
916913void SetEventPhaseFromCursorButtonState (FlEngine* self,
@@ -929,59 +926,60 @@ void SetEventPhaseFromCursorButtonState(FlEngine* self,
929926 }
930927}
931928
932-
933-
934929void fl_engine_send_pointer_event (FlEngine* self,
935- FlutterViewId view_id,
936- const FlutterPointerEvent& event_data){
930+ FlutterViewId view_id,
931+ const FlutterPointerEvent& event_data) {
937932 g_return_if_fail (FL_IS_ENGINE (self));
938933
939934 if (self->engine == nullptr ) {
940935 return ;
941936 }
942-
937+
943938 // Copy the event data to avoid modifying the caller's data.
944- auto event_data_copy = event_data;
939+ FlutterPointerEvent event_data_copy = event_data;
945940
946- // Create a virtual pointer ID that is unique across all device types
941+ // Create a virtual pointer ID that is unique across all device types
947942 // to prevent pointers from clashing in the engine's converter
948943 // (lib/ui/window/pointer_data_packet_converter.cc)
949- int32_t pointer_id = (static_cast <int32_t >(event_data_copy.device_kind ) << 28 ) | event_data_copy.device ;
944+ int32_t pointer_id =
945+ (static_cast <int32_t >(event_data_copy.device_kind ) << 28 ) |
946+ event_data_copy.device ;
950947
951948 // Add the pointer state if it doesn't exist.
952- auto state = g_new (PointerState, 1 );
953- state->device_kind = event_data_copy.device_kind ;
954- state->pointer_id = pointer_id;
955-
956- bool added = g_hash_table_insert (self->pointer_states , GINT_TO_POINTER (pointer_id), state);
957- if (!added) {
958- g_free (state);
959- state = static_cast <PointerState*>(g_hash_table_lookup (self->pointer_states , GINT_TO_POINTER (pointer_id)));
960- }
961-
962- // Modify the phase based on the cursor button state.
963- if (event_data_copy.phase != FlutterPointerPhase::kRemove ) {
964- SetEventPhaseFromCursorButtonState (self, &event_data_copy, state);
949+ PointerState* state = static_cast <PointerState*>(
950+ g_hash_table_lookup (self->pointer_states , GINT_TO_POINTER (pointer_id)));
951+ if (state == nullptr ) {
952+ state = g_new (PointerState, 1 );
953+ state->device_kind = event_data_copy.device_kind ;
954+ state->pointer_id = pointer_id;
955+ state->buttons = 0 ;
956+ state->flutter_state_is_down = false ;
957+ state->flutter_state_is_added = false ;
958+ g_hash_table_insert (self->pointer_states , GINT_TO_POINTER (pointer_id),
959+ state);
965960 }
966961
967- // Modify the state based on the event.
962+ // Modify the button state based on the event's phase .
968963 if (event_data_copy.phase == FlutterPointerPhase::kDown ) {
969- state->buttons |= event_data_copy. buttons ;
970- state-> flutter_state_is_down = true ;
964+ state->buttons |=
965+ FlutterPointerMouseButtons:: kFlutterPointerButtonMousePrimary ;
971966 } else if (event_data_copy.phase == FlutterPointerPhase::kUp ) {
972- state->buttons &= ~event_data_copy.buttons ;
973- state->flutter_state_is_down = false ;
967+ state->buttons &=
968+ ~FlutterPointerMouseButtons::kFlutterPointerButtonMousePrimary ;
969+ }
970+
971+ // Get the real phase based on the current button state.
972+ if (event_data_copy.phase != FlutterPointerPhase::kRemove &&
973+ event_data_copy.phase != FlutterPointerPhase::kAdd ) {
974+ SetEventPhaseFromCursorButtonState (self, &event_data_copy, state);
974975 }
975976
976977 // If sending anything other than an add, and the pointer isn't already added,
977978 // synthesize an add to satisfy Flutter's expectations about events.
978979 if (!state->flutter_state_is_added &&
979980 event_data_copy.phase != FlutterPointerPhase::kAdd ) {
980- FlutterPointerEvent event = {} ;
981+ FlutterPointerEvent event = event_data_copy ;
981982 event.phase = FlutterPointerPhase::kAdd ;
982- event.x = event_data_copy.x ;
983- event.y = event_data_copy.y ;
984- event.buttons = 0 ;
985983 fl_engine_send_pointer_event (self, view_id, event);
986984 }
987985
@@ -1007,10 +1005,15 @@ void fl_engine_send_pointer_event(FlEngine* self,
10071005
10081006 self->embedder_api .SendPointerEvent (self->engine , &event, 1 );
10091007
1010- if (event_data_copy .phase == FlutterPointerPhase::kAdd ) {
1008+ if (event .phase == FlutterPointerPhase::kAdd ) {
10111009 state->flutter_state_is_added = true ;
1012- } else if (event_data_copy.phase == FlutterPointerPhase::kRemove ) {
1013- g_hash_table_remove (self->pointer_states , GINT_TO_POINTER (state->pointer_id ));
1010+ } else if (event.phase == FlutterPointerPhase::kDown ) {
1011+ state->flutter_state_is_down = true ;
1012+ } else if (event.phase == FlutterPointerPhase::kUp ) {
1013+ state->flutter_state_is_down = false ;
1014+ } else if (event.phase == FlutterPointerPhase::kRemove ) {
1015+ g_hash_table_remove (self->pointer_states ,
1016+ GINT_TO_POINTER (state->pointer_id ));
10141017 }
10151018}
10161019
0 commit comments