Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply formatter
  • Loading branch information
moffatman committed Oct 20, 2022
commit 9b7431e9b73ba2770d8a45219b457a073a112783
4 changes: 3 additions & 1 deletion shell/platform/windows/direct_manipulation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ HRESULT DirectManipulationEventHandler::OnViewportStatusChanged(
owner_->binding_handler_delegate->OnPointerPanZoomEnd(GetDeviceId());
}
} else if (previous == DIRECTMANIPULATION_INERTIA) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We only compare the previous status but not the current, does it mean if the inertia movement dies out naturally it will also dispatch a cancel event?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current should always be DIRECTMANIPULATION_READY whether it dies out naturally or is cancelled. We can only tell if it's cancelled prematurely by seeing if the last event still had meaningful velocity left (hadn't already decelerated to near-zero).

if (owner_->binding_handler_delegate && std::max(std::abs(last_pan_delta_x_), std::abs(last_pan_delta_y_)) > 0.01) {
if (owner_->binding_handler_delegate &&
(std::max)(std::abs(last_pan_delta_x_), std::abs(last_pan_delta_y_)) >
0.01) {
owner_->binding_handler_delegate->OnScrollInertiaCancel(GetDeviceId());
}
// Need to reset the content transform to its original position
Expand Down
3 changes: 2 additions & 1 deletion shell/platform/windows/direct_manipulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ class DirectManipulationEventHandler
// A flag is needed to ensure that false events created as the reset occurs
// are not sent to the flutter framework.
bool during_synthesized_reset_ = false;
// Store whether current events are from synthetic inertia rather than user input.
// Store whether current events are from synthetic inertia rather than user
// input.
bool during_inertia_ = false;
// Store the difference between the last pan offsets to determine if inertia
// has been cancelled in the middle of an animation.
Expand Down
55 changes: 26 additions & 29 deletions shell/platform/windows/direct_manipulation_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -287,26 +287,25 @@ TEST(DirectManipulationTest, TestInertiaCancelSentForUserCancel) {
DIRECTMANIPULATION_RUNNING);
// Have pan_y change by 10 between inertia updates.
EXPECT_CALL(content, GetContentTransform(_, 6))
.WillOnce(::testing::Invoke(
[](float* transform, DWORD size) {
transform[0] = 1;
transform[4] = 0;
transform[5] = 100;
return S_OK;
}));
.WillOnce(::testing::Invoke([](float* transform, DWORD size) {
transform[0] = 1;
transform[4] = 0;
transform[5] = 100;
return S_OK;
}));
handler->OnContentUpdated((IDirectManipulationViewport*)&viewport,
(IDirectManipulationContent*)&content);
EXPECT_CALL(content, GetContentTransform(_, 6))
.WillOnce(::testing::Invoke(
[](float* transform, DWORD size) {
transform[0] = 1;
transform[4] = 0;
transform[5] = 110;
return S_OK;
}));
.WillOnce(::testing::Invoke([](float* transform, DWORD size) {
transform[0] = 1;
transform[4] = 0;
transform[5] = 110;
return S_OK;
}));
handler->OnContentUpdated((IDirectManipulationViewport*)&viewport,
(IDirectManipulationContent*)&content);
// This looks like an interruption in the middle of synthetic inertia because of user input.
// This looks like an interruption in the middle of synthetic inertia because
// of user input.
EXPECT_CALL(delegate, OnScrollInertiaCancel(device_id));
handler->OnViewportStatusChanged((IDirectManipulationViewport*)&viewport,
DIRECTMANIPULATION_READY,
Expand Down Expand Up @@ -341,23 +340,21 @@ TEST(DirectManipulationTest, TestInertiaCamcelNotSentAtInertiaEnd) {
DIRECTMANIPULATION_RUNNING);
// Have no change in pan between events.
EXPECT_CALL(content, GetContentTransform(_, 6))
.WillOnce(::testing::Invoke(
[](float* transform, DWORD size) {
transform[0] = 1;
transform[4] = 0;
transform[5] = 140;
return S_OK;
}));
.WillOnce(::testing::Invoke([](float* transform, DWORD size) {
transform[0] = 1;
transform[4] = 0;
transform[5] = 140;
return S_OK;
}));
handler->OnContentUpdated((IDirectManipulationViewport*)&viewport,
(IDirectManipulationContent*)&content);
EXPECT_CALL(content, GetContentTransform(_, 6))
.WillOnce(::testing::Invoke(
[](float* transform, DWORD size) {
transform[0] = 1;
transform[4] = 0;
transform[5] = 140;
return S_OK;
}));
.WillOnce(::testing::Invoke([](float* transform, DWORD size) {
transform[0] = 1;
transform[4] = 0;
transform[5] = 140;
return S_OK;
}));
handler->OnContentUpdated((IDirectManipulationViewport*)&viewport,
(IDirectManipulationContent*)&content);
// OnScrollInertiaCancel should not be called.
Expand Down
10 changes: 7 additions & 3 deletions shell/platform/windows/flutter_windows_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -505,13 +505,17 @@ void FlutterWindowsView::SendScroll(double x,
SendPointerEventWithData(event, state);
}

void FlutterWindowsView::SendScrollInertiaCancel(int32_t device_id, double x, double y) {
auto state = GetOrCreatePointerState(kFlutterPointerDeviceKindTrackpad, device_id);
void FlutterWindowsView::SendScrollInertiaCancel(int32_t device_id,
double x,
double y) {
auto state =
GetOrCreatePointerState(kFlutterPointerDeviceKindTrackpad, device_id);

FlutterPointerEvent event = {};
event.x = x;
event.y = y;
event.signal_kind = FlutterPointerSignalKind::kFlutterPointerSignalKindScrollInertiaCancel;
event.signal_kind =
FlutterPointerSignalKind::kFlutterPointerSignalKindScrollInertiaCancel;
SetEventPhaseFromCursorButtonState(&event, state);
SendPointerEventWithData(event, state);
}
Expand Down
4 changes: 1 addition & 3 deletions shell/platform/windows/flutter_windows_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,7 @@ class FlutterWindowsView : public WindowBindingHandlerDelegate,
int32_t device_id);

// Reports scroll inertia cancel events to Flutter engine.
void SendScrollInertiaCancel(int32_t device_id,
double x,
double y);
void SendScrollInertiaCancel(int32_t device_id, double x, double y);

// Creates a PointerState object unless it already exists.
PointerState* GetOrCreatePointerState(FlutterPointerDeviceKind device_kind,
Expand Down