361 {
362 FML_LOG(INFO) <<
"Flutter - PointerDelegate started.";
363 if (touch_responder_) {
364 FML_LOG(
ERROR) <<
"PointerDelegate::WatchLoop() must be called once.";
365 return;
366 }
367
368 touch_responder_ = [
this,
callback](std::vector<fup_TouchEvent> events) {
369 TRACE_EVENT0(
"flutter",
"PointerDelegate::TouchHandler");
370 FML_DCHECK(touch_responses_.empty()) <<
"precondition";
371 std::vector<flutter::PointerData> to_client;
373 IssueTouchTraceEvent(
event);
375 response;
376 if (
event.has_view_parameters()) {
377 touch_view_parameters_ = std::move(
event.view_parameters());
378 }
379 if (HasValidatedTouchSample(
event)) {
380 const auto& sample = event.pointer_sample();
381 const auto& ixn = sample.interaction();
383 !
event.has_interaction_result()) {
384 touch_buffer_.emplace(ixn, std::vector<flutter::PointerData>());
385 }
386
387 FML_DCHECK(touch_view_parameters_.has_value()) <<
"API guarantee";
388 auto events = CreateTouchDraft(
event, touch_view_parameters_.value());
389 if (touch_buffer_.count(ixn) > 0) {
390 InsertIntoBuffer(std::move(events), &touch_buffer_[ixn]);
391 } else {
392 InsertIntoBuffer(std::move(events), &to_client);
393 }
394
395 response.set_response_type(fup_TouchResponseType::YES);
396 }
397 if (
event.has_interaction_result()) {
398 const auto&
result =
event.interaction_result();
399 const auto& ixn =
result.interaction;
400 if (
result.status == fup_TouchIxnStatus::GRANTED &&
401 touch_buffer_.count(ixn) > 0) {
403 to_client.insert(to_client.end(), touch_buffer_[ixn].begin(),
404 touch_buffer_[ixn].end());
405 }
406 touch_buffer_.erase(ixn);
407 }
408 touch_responses_.push_back(std::move(response));
409 }
411
412 touch_source_->Watch(std::move(touch_responses_),
413 touch_responder_);
414 touch_responses_.clear();
415 };
416
417 mouse_responder_ = [
this,
callback](std::vector<fup_MouseEvent> events) {
418 TRACE_EVENT0(
"flutter",
"PointerDelegate::MouseHandler");
419 std::vector<flutter::PointerData> to_client;
421 IssueMouseTraceEvent(
event);
422 if (
event.has_device_info()) {
423 const auto& id = event.device_info().id();
424 mouse_device_info_[
id] = std::move(*
event.mutable_device_info());
425 }
426 if (
event.has_view_parameters()) {
427 mouse_view_parameters_ = std::move(
event.view_parameters());
428 }
429 if (HasValidatedMouseSample(
event)) {
430 const auto& sample = event.pointer_sample();
431 const auto& id = sample.device_id();
432 const bool any_button_down = sample.has_pressed_buttons();
433 FML_DCHECK(mouse_view_parameters_.has_value()) <<
"API guarantee";
434 FML_DCHECK(mouse_device_info_.count(
id) > 0) <<
"API guarantee";
435
436 const auto phase = ComputePhase(any_button_down, mouse_down_, id);
438 CreateMouseDraft(
event, phase, mouse_view_parameters_.value(),
439 mouse_device_info_[id]);
440 to_client.emplace_back(std::move(
data));
441 }
442 }
444 mouse_source_->Watch( mouse_responder_);
445 };
446
447
448 touch_source_->Watch(std::move(touch_responses_), touch_responder_);
449 touch_responses_.clear();
450 if (mouse_source_) {
451 mouse_source_->Watch( mouse_responder_);
452 }
453}
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
#define FML_DCHECK(condition)
fuchsia::ui::pointer::MouseEvent fup_MouseEvent
fuchsia::ui::pointer::TouchResponse fup_TouchResponse
fuchsia::ui::pointer::TouchEvent fup_TouchEvent
std::shared_ptr< const fml::Mapping > data
#define TRACE_EVENT0(category_group, name)