Commit 4c6f3b8b authored by minch's avatar minch Committed by Commit Bot

back_gesture: Get x drag amount from touch events.

scroll_x() of gesture event is not reliable after checked on physical
device. Get the x drag amount from touch events as y drag amount.

Fling event is supported, which means the |drag_progress_| might
hasn't reached full progress while COMPLETING the drag.

Bug: 1002733
Change-Id: I66dfb4110e2e8f34445d67a5e5cc25681b3f8708
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1879821
Commit-Queue: Min Chen <minch@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709295}
parent cfae60c9
......@@ -232,8 +232,6 @@ void BackGestureAffordance::Abort() {
void BackGestureAffordance::Complete() {
DCHECK_EQ(State::DRAGGING, state_);
DCHECK_LE(1.f, drag_progress_);
state_ = State::COMPLETING;
animation_ = std::make_unique<gfx::LinearAnimation>(
......
......@@ -539,10 +539,12 @@ void ToplevelWindowEventHandler::OnTouchEvent(ui::TouchEvent* event) {
if (event->type() == ui::ET_TOUCH_RELEASED)
first_touch_id_ = ui::kPointerIdUnknown;
if (event->type() == ui::ET_TOUCH_PRESSED)
y_drag_amount_ = 0;
else
if (event->type() == ui::ET_TOUCH_PRESSED) {
x_drag_amount_ = y_drag_amount_ = 0;
} else {
x_drag_amount_ += (event->location().x() - last_touch_point_.x());
y_drag_amount_ += (event->location().y() - last_touch_point_.y());
}
last_touch_point_ = event->location();
}
......@@ -909,7 +911,6 @@ bool ToplevelWindowEventHandler::HandleGoingBackFromLeftEdge(
going_back_started_ = StartedAwayFromLeftArea(event);
if (!going_back_started_)
break;
x_drag_amount_ = 0;
back_gesture_affordance_ =
std::make_unique<BackGestureAffordance>(screen_location);
return true;
......@@ -918,7 +919,6 @@ bool ToplevelWindowEventHandler::HandleGoingBackFromLeftEdge(
if (!going_back_started_)
break;
DCHECK(back_gesture_affordance_);
x_drag_amount_ += event->details().scroll_x();
back_gesture_affordance_->SetDragProgress(x_drag_amount_, y_drag_amount_);
return true;
case ui::ET_GESTURE_SCROLL_END:
......@@ -927,7 +927,7 @@ bool ToplevelWindowEventHandler::HandleGoingBackFromLeftEdge(
break;
DCHECK(back_gesture_affordance_);
if ((event->type() == ui::ET_GESTURE_SCROLL_END &&
screen_location.x() >= kSwipingDistanceForGoingBack) ||
x_drag_amount_ >= kSwipingDistanceForGoingBack) ||
(event->type() == ui::ET_SCROLL_FLING_START &&
event->details().velocity_x() >= kFlingVelocityForGoingBack)) {
aura::Window* root_window =
......
......@@ -193,17 +193,12 @@ class ASH_EXPORT ToplevelWindowEventHandler
// True if swiping from left edge to go to previous page is in progress.
bool going_back_started_ = false;
// Tracks the y-axis drag amount through touch events. Used for back gesture
// affordance in tablet mode. The gesture movement of back gesture can't be
// recognized by GestureRecognizer, which leads to wrong gesture locations of
// back gesture. See crbug.com/1015464 for the details.
int y_drag_amount_ = 0;
// Tracks the x-axis drag amount through gesture events. Used for back gesture
// affordance in tablet mode. Note, gets the drag amount from gesture events
// instead of touch events, since the x location of the gestures is reliable
// during back gesture movements.
// Tracks the x-axis and y-axis drag amount through touch events. Used for
// back gesture affordance in tablet mode. The gesture movement of back
// gesture can't be recognized by GestureRecognizer, which leads to wrong
// gesture locations of back gesture. See crbug.com/1015464 for the details.
int x_drag_amount_ = 0;
int y_drag_amount_ = 0;
// Position of last touch event. Used to calculate |y_drag_amount_|. Note,
// only touch events from |first_touch_id_| will be recorded.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment