Commit 081e1375 authored by Collin Baker's avatar Collin Baker Committed by Commit Bot

Treat up-swipe as a close regardless of container height

When the user doesn't swipe, the container is animated open or closed based on
the final height from dragging upon gesture end. Previously, only down-swipes
were treated specially: swiping down fast enough opened the container regardless
of its height.

This treats swiping up specially too, causing the container to close.

Bug: None
Change-Id: I7555e00dbddb21128175d36a2209139c15cf52d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2128968
Commit-Queue: Collin Baker <collinbaker@chromium.org>
Reviewed-by: default avatardpapad <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#755129}
parent 9c016da3
...@@ -190,7 +190,7 @@ class WebUITabStripContainerView::DragToOpenHandler : public ui::EventHandler { ...@@ -190,7 +190,7 @@ class WebUITabStripContainerView::DragToOpenHandler : public ui::EventHandler {
break; break;
case ui::ET_GESTURE_SCROLL_END: case ui::ET_GESTURE_SCROLL_END:
if (drag_in_progress_) { if (drag_in_progress_) {
container_->EndDragToOpen(false); container_->EndDragToOpen();
event->SetHandled(); event->SetHandled();
drag_in_progress_ = false; drag_in_progress_ = false;
} }
...@@ -206,7 +206,16 @@ class WebUITabStripContainerView::DragToOpenHandler : public ui::EventHandler { ...@@ -206,7 +206,16 @@ class WebUITabStripContainerView::DragToOpenHandler : public ui::EventHandler {
// have been sent. Tell the container a drag began. // have been sent. Tell the container a drag began.
container_->UpdateHeightForDragToOpen(0.0f); container_->UpdateHeightForDragToOpen(0.0f);
} }
container_->EndDragToOpen(event->details().swipe_down());
if (event->details().swipe_down() || event->details().swipe_up()) {
container_->EndDragToOpen(event->details().swipe_down()
? FlingDirection::kDown
: FlingDirection::kUp);
} else {
// Treat a sideways swipe as a normal drag end.
container_->EndDragToOpen();
}
event->SetHandled(); event->SetHandled();
drag_in_progress_ = false; drag_in_progress_ = false;
break; break;
...@@ -215,7 +224,7 @@ class WebUITabStripContainerView::DragToOpenHandler : public ui::EventHandler { ...@@ -215,7 +224,7 @@ class WebUITabStripContainerView::DragToOpenHandler : public ui::EventHandler {
// If an unsupported gesture is sent, ensure that we still // If an unsupported gesture is sent, ensure that we still
// finish the drag on gesture end. Otherwise, the container // finish the drag on gesture end. Otherwise, the container
// will be stuck partially open. // will be stuck partially open.
container_->EndDragToOpen(false); container_->EndDragToOpen();
event->SetHandled(); event->SetHandled();
drag_in_progress_ = false; drag_in_progress_ = false;
} }
...@@ -423,18 +432,25 @@ void WebUITabStripContainerView::UpdateHeightForDragToOpen(float height_delta) { ...@@ -423,18 +432,25 @@ void WebUITabStripContainerView::UpdateHeightForDragToOpen(float height_delta) {
PreferredSizeChanged(); PreferredSizeChanged();
} }
void WebUITabStripContainerView::EndDragToOpen(bool fling_to_open) { void WebUITabStripContainerView::EndDragToOpen(
base::Optional<FlingDirection> fling_direction) {
if (!current_drag_height_) if (!current_drag_height_)
return; return;
const int final_drag_height = *current_drag_height_; const int final_drag_height = *current_drag_height_;
current_drag_height_ = base::nullopt; current_drag_height_ = base::nullopt;
// If we are at least halfway open by now, animate fully open. // If this wasn't a fling, determine whether to open or close based on
// Otherwise, animate back to closed. // final height.
const double open_proportion = const double open_proportion =
static_cast<double>(final_drag_height) / desired_height_; static_cast<double>(final_drag_height) / desired_height_;
const bool opening = fling_to_open || open_proportion >= 0.5; bool opening = open_proportion >= 0.5;
if (fling_direction) {
// If this was a fling, ignore the final height and use the fling
// direction.
opening = fling_direction == FlingDirection::kDown;
}
if (opening) { if (opening) {
iph_tracker_->NotifyEvent(feature_engagement::events::kWebUITabStripOpened); iph_tracker_->NotifyEvent(feature_engagement::events::kWebUITabStripOpened);
RecordTabStripUIOpenHistogram(TabStripUIOpenAction::kToolbarDrag); RecordTabStripUIOpenHistogram(TabStripUIOpenAction::kToolbarDrag);
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define CHROME_BROWSER_UI_VIEWS_FRAME_WEBUI_TAB_STRIP_CONTAINER_VIEW_H_ #define CHROME_BROWSER_UI_VIEWS_FRAME_WEBUI_TAB_STRIP_CONTAINER_VIEW_H_
#include <memory> #include <memory>
#include <set>
#include "base/optional.h" #include "base/optional.h"
#include "base/scoped_observer.h" #include "base/scoped_observer.h"
...@@ -92,10 +93,16 @@ class WebUITabStripContainerView : public TabStripUIEmbedder, ...@@ -92,10 +93,16 @@ class WebUITabStripContainerView : public TabStripUIEmbedder,
// Called as we are dragged open. // Called as we are dragged open.
void UpdateHeightForDragToOpen(float height_delta); void UpdateHeightForDragToOpen(float height_delta);
// Called when drag-to-open finishes. If |fling_to_open| is true, the enum class FlingDirection {
// user released their touch with a high enough velocity that we kUp,
// should animate open regardless of the final height. kDown,
void EndDragToOpen(bool fling_to_open); };
// Called when drag-to-open finishes. If |fling_direction| is present,
// the user released their touch with a high velocity. We should use
// just this direction to animate open or closed.
void EndDragToOpen(
base::Optional<FlingDirection> fling_direction = base::nullopt);
void SetContainerTargetVisibility(bool target_visible); void SetContainerTargetVisibility(bool target_visible);
......
...@@ -143,3 +143,5 @@ TEST_F(WebUITabStripDevToolsTest, DevToolsWindowHasNoTabStrip) { ...@@ -143,3 +143,5 @@ TEST_F(WebUITabStripDevToolsTest, DevToolsWindowHasNoTabStrip) {
ui::TouchUiController::TouchUiScoperForTesting reenable_touch_mode(true); ui::TouchUiController::TouchUiScoperForTesting reenable_touch_mode(true);
EXPECT_EQ(nullptr, browser_view()->webui_tab_strip()); EXPECT_EQ(nullptr, browser_view()->webui_tab_strip());
} }
// TODO(crbug.com/1066624): add coverage of open and close gestures.
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