Commit d9c08f21 authored by Taylor Bergquist's avatar Taylor Bergquist Committed by Commit Bot

Add enum for TabDragController mode and replace various state flags with it.

Also changes what happens when the drag ends during a nested move loop.  It
now exits the move loop (which triggers a drag end) instead of immediately
ending the drag.

This is the first step in a larger refactoring for TabDragController:
go/tabdragcontroller-untangling

Change-Id: I6cabc5237a604320c934bb8b5d4bbc9ff6d231f0
Reviewed-on: https://chromium-review.googlesource.com/c/1285085
Commit-Queue: Taylor Bergquist <tbergquist@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611352}
parent e0f020f5
......@@ -114,18 +114,20 @@ class TabDragController : public views::WidgetObserver,
EventSource event_source() const { return event_source_; }
// See description above fields for details on these.
bool active() const { return active_; }
bool active() const { return current_state_ != DragState::kStopped; }
const TabStrip* attached_tabstrip() const { return attached_tabstrip_; }
// Returns true if a drag started.
bool started_drag() const { return started_drag_; }
bool started_drag() const { return current_state_ != DragState::kNotStarted; }
// Returns true if mutating the TabStripModel.
bool is_mutating() const { return is_mutating_; }
// Returns true if we've detached from a tabstrip and are running a nested
// move message loop.
bool is_dragging_window() const { return is_dragging_window_; }
bool is_dragging_window() const {
return current_state_ == DragState::kDraggingWindow;
}
// Returns true if currently dragging a tab with |contents|.
bool IsDraggingTab(content::WebContents* contents);
......@@ -143,6 +145,24 @@ class TabDragController : public views::WidgetObserver,
static const int kMovedMouseLeft = 1 << 0;
static const int kMovedMouseRight = 1 << 1;
enum class DragState {
// The drag has not yet started; the user has not dragged far enough to
// begin a session.
kNotStarted,
// The session is dragging a set of tabs within |attached_tabstrip_|.
kDraggingTabs,
// The session is dragging a window; |attached_tabstrip_| is that window's
// tabstrip.
kDraggingWindow,
// The session is waiting for the nested move loop to exit to transition
// to kDraggingTabs. Not used on all platforms.
kWaitingToDragTabs,
// The session is waiting for the nested move loop to exit to end the drag.
kWaitingToStop,
// The drag session has completed or been canceled.
kStopped
};
enum class Liveness {
ALIVE,
DELETED,
......@@ -166,15 +186,6 @@ class TabDragController : public views::WidgetObserver,
DONT_RELEASE_CAPTURE,
};
// Specifies what should happen when RunMoveLoop completes.
enum EndRunLoopBehavior {
// Indicates the drag should end.
END_RUN_LOOP_STOP_DRAGGING,
// Indicates the drag should continue.
END_RUN_LOOP_CONTINUE_DRAGGING
};
// Enumeration of the possible positions the detached tab may detach from.
enum DetachPosition {
DETACH_BEFORE,
......@@ -473,6 +484,8 @@ class TabDragController : public views::WidgetObserver,
// property.
void SetDeferredTargetTabstrip(TabStrip* deferred_target_tabstrip);
DragState current_state_;
// Whether a drag to |window| should be blocked (for example, if the window
// is showing a modal).
bool ShouldDisallowDrag(gfx::NativeWindow window);
......@@ -544,12 +557,6 @@ class TabDragController : public views::WidgetObserver,
// StartMoveStackedTimerIfNecessary().
base::OneShotTimer move_stacked_timer_;
// Did the mouse move enough that we started a drag?
bool started_drag_;
// Is the drag active?
bool active_;
DragData drag_data_;
// Index of the source tab in |drag_data_|.
......@@ -591,9 +598,6 @@ class TabDragController : public views::WidgetObserver,
// The following are needed when detaching into a browser
// (|detach_into_browser_| is true).
// See description above getter.
bool is_dragging_window_;
// True if |attached_tabstrip_| is in a browser specifically created for
// the drag.
bool is_dragging_new_browser_;
......@@ -608,11 +612,6 @@ class TabDragController : public views::WidgetObserver,
// maximized).
bool did_restore_window_;
EndRunLoopBehavior end_run_loop_behavior_;
// If true, we're waiting for a move loop to complete.
bool waiting_for_run_loop_to_exit_;
// The TabStrip to attach to after the move loop completes.
TabStrip* tab_strip_to_attach_to_after_exit_;
......
......@@ -246,6 +246,11 @@ void TabDragControllerTest::HandleGestureEvent(TabStrip* tab_strip,
tab_strip->OnGestureEvent(event);
}
bool TabDragControllerTest::HasDragStarted(const TabStrip* tab_strip) const {
return tab_strip->drag_controller_ &&
tab_strip->drag_controller_->started_drag();
}
void TabDragControllerTest::SetUp() {
#if defined(USE_AURA)
// This needs to be disabled as it can interfere with when events are
......@@ -1210,6 +1215,31 @@ IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
EXPECT_FALSE(GetIsDragged(browser()));
}
IN_PROC_BROWSER_TEST_P(DetachToBrowserTabDragControllerTest,
DragDoesntStartFromClick) {
// Add another tab.
AddTabAndResetBrowser(browser());
TabStrip* tab_strip = GetTabStripForBrowser(browser());
// Click on the first tab, but don't move it.
gfx::Point tab_0_center(GetCenterInScreenCoordinates(tab_strip->tab_at(0)));
EXPECT_TRUE(PressInput(tab_0_center));
// A drag session should exist, but the drag should not have started.
EXPECT_TRUE(tab_strip->IsDragSessionActive());
EXPECT_TRUE(TabDragController::IsActive());
EXPECT_FALSE(HasDragStarted(tab_strip));
// Move the mouse enough to start the drag. It doesn't matter whether this
// is enough to create a window or not.
EXPECT_TRUE(DragInputTo(gfx::Point(tab_0_center.x() + 20, tab_0_center.y())));
// Drag should now have started.
EXPECT_TRUE(HasDragStarted(tab_strip));
EXPECT_TRUE(ReleaseInput());
}
#if defined(OS_CHROMEOS)
// TODO(sky,sad): Disabled as it fails due to resize locks with a real
// compositor. crbug.com/331924
......
......@@ -50,6 +50,8 @@ class TabDragControllerTest : public InProcessBrowserTest {
protected:
void HandleGestureEvent(TabStrip* tab_strip, ui::GestureEvent* event);
bool HasDragStarted(const TabStrip* tab_strip) const;
// InProcessBrowserTest:
void SetUp() override;
......
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