shell/platform/fuchsia/flutter/pointer_delegate.cc
flutter::PointerData CreateMouseDraft(const fup_MouseEvent& event,
                                      const flutter::PointerData::Change phase,
                                      const fup_ViewParameters& view_parameters,
                                      const fup_MouseDeviceInfo& device_info) {
  FML_DCHECK(HasValidatedMouseSample(event)) << "precondition";
  const auto& sample = event.pointer_sample();

  flutter::PointerData ptr;
  ptr.Clear();
  ptr.time_stamp = event.timestamp() / 1000;  // in microseconds
  ptr.change = phase;
  ptr.kind = flutter::PointerData::DeviceKind::kMouse;
  ptr.device = sample.device_id();

  // View parameters can change mid-interaction; apply transform on the fly.
  auto logical =
      ViewportToViewCoordinates(sample.position_in_viewport(),
                                view_parameters.viewport_to_view_transform);
  ptr.physical_x = logical[0];  // Not yet physical; adjusted in PlatformView.
  ptr.physical_y = logical[1];  // Not yet physical; adjusted in PlatformView.

  // Ensure gesture recognition: DOWN starts in the logical view space.
  if (ptr.change == flutter::PointerData::Change::kDown) {
    auto [x, y] =
        ClampToViewSpace(ptr.physical_x, ptr.physical_y, view_parameters);
    ptr.physical_x = x;
    ptr.physical_y = y;
  }

  if (sample.has_pressed_buttons()) {
    int64_t flutter_buttons = 0;
    const auto& pressed = sample.pressed_buttons();
    for (size_t idx = 0; idx < pressed.size(); ++idx) {
      const uint8_t button_id = pressed[idx];
      FML_DCHECK(device_info.has_buttons()) << "API guarantee";
      // Priority 0 maps to kPrimaryButton, and so on.
      for (uint8_t prio = 0; prio < device_info.buttons().size(); ++prio) {
        if (button_id == device_info.buttons()[prio]) {
          flutter_buttons |= (1 << prio);
        }
      }
    }
    FML_DCHECK(flutter_buttons != 0);
    ptr.buttons = flutter_buttons;
  }

  // Fuchsia currently provides scroll data in "ticks", not physical pixels.
  // However, Flutter expects scroll data in physical pixels. To compensate for
  // lack of guidance, we make up a "reasonable amount".
  // TODO(fxbug.dev/85388): Replace with physical pixel scroll.
  const int kScrollOffsetMultiplier = 20;

  if (sample.has_scroll_v()) {
    ptr.signal_kind = flutter::PointerData::SignalKind::kScroll;
    double dy = -sample.scroll_v() * kScrollOffsetMultiplier;  // logical amount
    ptr.scroll_delta_y = dy;  // Not yet physical; adjusted in Platform View.
  }

  if (sample.has_scroll_h()) {
    ptr.signal_kind = flutter::PointerData::SignalKind::kScroll;
    double dx = sample.scroll_h() * kScrollOffsetMultiplier;  // logical amount
    ptr.scroll_delta_x = dx;  // Not yet physical; adjusted in Platform View.
  }

  return ptr;
}
// It returns a "draft" because the coordinates are logical. Later, view pixel
// ratio is applied to obtain physical coordinates.
//
// Phase data is computed before this call; it involves state tracking based on
// button-down state.
//
// Button data, if available, gets packed into the |buttons| field, in flutter
// button order (kMousePrimaryButton, etc). The device-assigned button IDs are
// provided in priority order in MouseEvent.device_info (at the start of channel
// connection), and maps from device button ID (given in fup_MouseEvent) to
// flutter button ID (flutter::PointerData).
//
// Scroll data, if available, gets packed into the |scroll_delta_x| or
// |scroll_delta_y| fields, and the |signal_kind| field is set to kScroll.
// The PointerDataPacketConverter reads this field to synthesize events to match
// Flutter's expected pointer stream.
// TODO(fxbug.dev/87073): PointerDataPacketConverter should synthesize a
// discrete scroll event on kDown or kUp, to match engine expectations.
//
// Flutter gestures expect a gesture to start within the logical view space, and
// is not tolerant of floating point drift. This function coerces just the DOWN
// event's coordinate to start within the logical view.
It returns a "draft" because the coordinates are logical. Later, view pixel
ratio is applied to obtain physical coordinates.

Phase data is computed before this call; it involves state tracking based on
button-down state.

Button data, if available, gets packed into the |buttons| field, in flutter
button order (kMousePrimaryButton, etc). The device-assigned button IDs are
provided in priority order in MouseEvent.device_info (at the start of channel
connection), and maps from device button ID (given in fup_MouseEvent) to
flutter button ID (flutter::PointerData).



Flutter gestures expect a gesture to start within the logical view space, and
is not tolerant of floating point drift. This function coerces just the DOWN
event's coordinate to start within the logical view.
It returns a " draft " because the coordinates are logical . Later view pixel ratio is applied to obtain physical coordinates . Phase data is computed before this call ; it involves state tracking based on button - down state . Button data if available gets packed into the |buttons| field in flutter button order ( kMousePrimaryButton etc ) . The device - assigned button IDs are provided in priority order in MouseEvent . device_info ( at the start of channel connection ) and maps from device button ID ( given in fup_MouseEvent ) to flutter button ID ( flutter :: PointerData ) . Flutter gestures expect a gesture to start within the logical view space and is not tolerant of floating point drift . This function coerces just the DOWN event ' s coordinate to start within the logical view .
flutter::PointerData CreateMouseDraft(const fup_MouseEvent& event,
                                      const flutter::PointerData::Change phase,
                                      const fup_ViewParameters& view_parameters,
                                      const fup_MouseDeviceInfo& device_info) {
  FML_DCHECK(HasValidatedMouseSample(event)) << "precondition";
  const auto& sample = event.pointer_sample();
  flutter::PointerData ptr;
  ptr.Clear();
  ptr.time_stamp = event.timestamp() / 1000;  
  ptr.change = phase;
  ptr.kind = flutter::PointerData::DeviceKind::kMouse;
  ptr.device = sample.device_id();
  auto logical =
      ViewportToViewCoordinates(sample.position_in_viewport(),
                                view_parameters.viewport_to_view_transform);
  ptr.physical_x = logical[0];  
  ptr.physical_y = logical[1];  
  if (ptr.change == flutter::PointerData::Change::kDown) {
    auto [x, y] =
        ClampToViewSpace(ptr.physical_x, ptr.physical_y, view_parameters);
    ptr.physical_x = x;
    ptr.physical_y = y;
  }
  if (sample.has_pressed_buttons()) {
    int64_t flutter_buttons = 0;
    const auto& pressed = sample.pressed_buttons();
    for (size_t idx = 0; idx < pressed.size(); ++idx) {
      const uint8_t button_id = pressed[idx];
      FML_DCHECK(device_info.has_buttons()) << "API guarantee";
      for (uint8_t prio = 0; prio < device_info.buttons().size(); ++prio) {
        if (button_id == device_info.buttons()[prio]) {
          flutter_buttons |= (1 << prio);
        }
      }
    }
    FML_DCHECK(flutter_buttons != 0);
    ptr.buttons = flutter_buttons;
  }
  const int kScrollOffsetMultiplier = 20;
  if (sample.has_scroll_v()) {
    ptr.signal_kind = flutter::PointerData::SignalKind::kScroll;
    double dy = -sample.scroll_v() * kScrollOffsetMultiplier;  
    ptr.scroll_delta_y = dy;  
  }
  if (sample.has_scroll_h()) {
    ptr.signal_kind = flutter::PointerData::SignalKind::kScroll;
    double dx = sample.scroll_h() * kScrollOffsetMultiplier;  
    ptr.scroll_delta_x = dx;  
  }
  return ptr;
}
flutter :: PointerData CreateMouseDraft ( const fup_MouseEvent & event , const flutter :: PointerData :: Change phase , const fup_ViewParameters & view_parameters , const fup_MouseDeviceInfo & device_info ) { FML_DCHECK ( HasValidatedMouseSample ( event ) ) << " " ; const auto & sample = event . pointer_sample ( ) ; flutter :: PointerData ptr ; ptr . Clear ( ) ; ptr . time_stamp = event . timestamp ( ) / 1000 ; ptr . change = phase ; ptr . kind = flutter :: PointerData :: DeviceKind :: kMouse ; ptr . device = sample . device_id ( ) ; auto logical = ViewportToViewCoordinates ( sample . position_in_viewport ( ) , view_parameters . viewport_to_view_transform ) ; ptr . physical_x = logical [ 0 ] ; ptr . physical_y = logical [ 1 ] ; if ( ptr . change == flutter :: PointerData :: Change :: kDown ) { auto [ x , y ] = ClampToViewSpace ( ptr . physical_x , ptr . physical_y , view_parameters ) ; ptr . physical_x = x ; ptr . physical_y = y ; } if ( sample . has_pressed_buttons ( ) ) { int64_t flutter_buttons = 0 ; const auto & pressed = sample . pressed_buttons ( ) ; for ( size_t idx = 0 ; idx < pressed . size ( ) ; ++ idx ) { const uint8_t button_id = pressed [ idx ] ; FML_DCHECK ( device_info . has_buttons ( ) ) << " " ; for ( uint8_t prio = 0 ; prio < device_info . buttons ( ) . size ( ) ; ++ prio ) { if ( button_id == device_info . buttons ( ) [ prio ] ) { flutter_buttons |= ( 1 << prio ) ; } } } FML_DCHECK ( flutter_buttons != 0 ) ; ptr . buttons = flutter_buttons ; } const int kScrollOffsetMultiplier = 20 ; if ( sample . has_scroll_v ( ) ) { ptr . signal_kind = flutter :: PointerData :: SignalKind :: kScroll ; double dy = - sample . scroll_v ( ) * kScrollOffsetMultiplier ; ptr . scroll_delta_y = dy ; } if ( sample . has_scroll_h ( ) ) { ptr . signal_kind = flutter :: PointerData :: SignalKind :: kScroll ; double dx = sample . scroll_h ( ) * kScrollOffsetMultiplier ; ptr . scroll_delta_x = dx ; } return ptr ; }
It returns a "draft" because the coordinates are logical.
It returns a " draft " because the coordinates are logical .
// in microseconds // View parameters can change mid-interaction; apply transform on the fly. // Not yet physical; adjusted in PlatformView. // Not yet physical; adjusted in PlatformView. // Ensure gesture recognition: DOWN starts in the logical view space. // Priority 0 maps to kPrimaryButton, and so on. // Fuchsia currently provides scroll data in "ticks", not physical pixels. // However, Flutter expects scroll data in physical pixels. To compensate for // lack of guidance, we make up a "reasonable amount". // TODO(fxbug.dev/85388): Replace with physical pixel scroll. // logical amount // Not yet physical; adjusted in Platform View. // logical amount // Not yet physical; adjusted in Platform View.