Commit 93c41270 authored by Collin Baker's avatar Collin Baker Committed by Commit Bot

Handle ET_GESTURE_SWIPE for WebUI tab strip drag-to-open

When a swipe happens, an ET_GESTURE_SCROLL_END is not sent. This would
cause the tab strip to get stuck partially open in some cases.

With this CL, the tab strip will always fully open after a swipe. This
also adds ET_GESTURE_END handling to avoid similar bugs if an
unsupported gesture is sent.

Bug: 1043374
Change-Id: I98397e7557eb3e40fb1de04f429866925c60daed
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2070969
Commit-Queue: Collin Baker <collinbaker@chromium.org>
Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#744452}
parent 8e76b19a
......@@ -165,15 +165,39 @@ class WebUITabStripContainerView::DragToOpenHandler : public ui::EventHandler {
void OnGestureEvent(ui::GestureEvent* event) override {
switch (event->type()) {
case ui::ET_GESTURE_SCROLL_BEGIN:
drag_in_progress_ = true;
event->SetHandled();
break;
case ui::ET_GESTURE_SCROLL_UPDATE:
DCHECK(drag_in_progress_);
container_->UpdateHeightForDragToOpen(event->details().scroll_y());
event->SetHandled();
break;
case ui::ET_GESTURE_SCROLL_END:
container_->EndDragToOpen();
DCHECK(drag_in_progress_);
container_->EndDragToOpen(false);
event->SetHandled();
drag_in_progress_ = false;
break;
case ui::ET_GESTURE_SWIPE:
// If a touch is released at high velocity, the scroll gesture
// is "converted" to a swipe gesture. Note that a
// ET_GESTURE_SCROLL_END event will not be sent. ET_GESTURE_END
// is still sent after, however.
DCHECK(drag_in_progress_);
container_->EndDragToOpen(event->details().swipe_down());
event->SetHandled();
drag_in_progress_ = false;
break;
case ui::ET_GESTURE_END:
if (drag_in_progress_) {
// If an unsupported gesture is sent, ensure that we still
// finish the drag on gesture end. Otherwise, the container
// will be stuck partially open.
container_->EndDragToOpen(false);
event->SetHandled();
drag_in_progress_ = false;
}
break;
default:
break;
......@@ -183,6 +207,11 @@ class WebUITabStripContainerView::DragToOpenHandler : public ui::EventHandler {
private:
WebUITabStripContainerView* const container_;
views::View* const drag_handle_;
// True between ET_GESTURE_SCROLL_BEGIN event received and gesture
// end. Used to track when an unsupported gesture ends to reset the
// container to a good state.
bool drag_in_progress_ = false;
};
WebUITabStripContainerView::WebUITabStripContainerView(
......@@ -338,7 +367,7 @@ void WebUITabStripContainerView::UpdateHeightForDragToOpen(int height_delta) {
PreferredSizeChanged();
}
void WebUITabStripContainerView::EndDragToOpen() {
void WebUITabStripContainerView::EndDragToOpen(bool fling_to_open) {
if (!current_drag_height_)
return;
......@@ -349,7 +378,7 @@ void WebUITabStripContainerView::EndDragToOpen() {
// Otherwise, animate back to closed.
const double open_proportion =
static_cast<double>(final_drag_height) / desired_height_;
const bool opening = open_proportion >= 0.5;
const bool opening = fling_to_open || open_proportion >= 0.5;
if (opening) {
iph_tracker_->NotifyEvent(feature_engagement::events::kWebUITabStripOpened);
RecordTabStripUIOpenHistogram(TabStripUIOpenAction::kToolbarDrag);
......
......@@ -80,8 +80,14 @@ class WebUITabStripContainerView : public TabStripUIEmbedder,
class AutoCloser;
class DragToOpenHandler;
// Called as we are dragged open.
void UpdateHeightForDragToOpen(int height_delta);
void EndDragToOpen();
// Called when drag-to-open finishes. If |fling_to_open| is true, the
// user released their touch with a high enough velocity that we
// should animate open regardless of the final height.
void EndDragToOpen(bool fling_to_open);
void SetContainerTargetVisibility(bool target_visible);
// When the container is open, it intercepts most tap and click
......
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