diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-25 15:43:23 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-25 15:43:23 +0000 |
commit | f8720ff20cf28e0ddacff4b6855056a78e06fe4a (patch) | |
tree | dc054db671a2759237d7c9d87103b1bc38ff4c5f | |
parent | 11a7caa909151761f5d30743443eede4c58259ad (diff) | |
download | chromium_src-f8720ff20cf28e0ddacff4b6855056a78e06fe4a.zip chromium_src-f8720ff20cf28e0ddacff4b6855056a78e06fe4a.tar.gz chromium_src-f8720ff20cf28e0ddacff4b6855056a78e06fe4a.tar.bz2 |
Makes hiding window conditional when escape is pressed in move loop
Hiding makes sense if a new browser window was created for the drag
(as escape=revert, which means we're going to destroy the
window). But if the drag isn't because of a new window (you selected
all the tabs in a window and started dragging), then revert should
move the window backs to its start location and stop.
BUG=297054
TEST=see bug
R=ben@chromium.org
Review URL: https://codereview.chromium.org/24378002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@225189 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/ui/views/tabs/tab_drag_controller.cc | 7 | ||||
-rw-r--r-- | ui/views/widget/desktop_aura/desktop_native_widget_aura.cc | 6 | ||||
-rw-r--r-- | ui/views/widget/desktop_aura/desktop_native_widget_aura.h | 3 | ||||
-rw-r--r-- | ui/views/widget/desktop_aura/desktop_root_window_host.h | 3 | ||||
-rw-r--r-- | ui/views/widget/desktop_aura/desktop_root_window_host_win.cc | 7 | ||||
-rw-r--r-- | ui/views/widget/desktop_aura/desktop_root_window_host_win.h | 3 | ||||
-rw-r--r-- | ui/views/widget/desktop_aura/desktop_root_window_host_x11.cc | 3 | ||||
-rw-r--r-- | ui/views/widget/desktop_aura/desktop_root_window_host_x11.h | 3 | ||||
-rw-r--r-- | ui/views/widget/native_widget_aura.cc | 5 | ||||
-rw-r--r-- | ui/views/widget/native_widget_aura.h | 3 | ||||
-rw-r--r-- | ui/views/widget/native_widget_private.h | 3 | ||||
-rw-r--r-- | ui/views/widget/native_widget_win.cc | 7 | ||||
-rw-r--r-- | ui/views/widget/native_widget_win.h | 3 | ||||
-rw-r--r-- | ui/views/widget/widget.cc | 8 | ||||
-rw-r--r-- | ui/views/widget/widget.h | 12 | ||||
-rw-r--r-- | ui/views/win/hwnd_message_handler.cc | 21 | ||||
-rw-r--r-- | ui/views/win/hwnd_message_handler.h | 2 |
17 files changed, 69 insertions, 30 deletions
diff --git a/chrome/browser/ui/views/tabs/tab_drag_controller.cc b/chrome/browser/ui/views/tabs/tab_drag_controller.cc index a231b60..a5dd831 100644 --- a/chrome/browser/ui/views/tabs/tab_drag_controller.cc +++ b/chrome/browser/ui/views/tabs/tab_drag_controller.cc @@ -1450,8 +1450,13 @@ void TabDragController::RunMoveLoop(const gfx::Vector2d& drag_offset) { event_source_ == EVENT_SOURCE_MOUSE ? views::Widget::MOVE_LOOP_SOURCE_MOUSE : views::Widget::MOVE_LOOP_SOURCE_TOUCH; + const views::Widget::MoveLoopEscapeBehavior escape_behavior = + is_dragging_new_browser_ ? + views::Widget::MOVE_LOOP_ESCAPE_BEHAVIOR_HIDE : + views::Widget::MOVE_LOOP_ESCAPE_BEHAVIOR_DONT_HIDE; views::Widget::MoveLoopResult result = - move_loop_widget_->RunMoveLoop(drag_offset, move_loop_source); + move_loop_widget_->RunMoveLoop( + drag_offset, move_loop_source, escape_behavior); content::NotificationService::current()->Notify( chrome::NOTIFICATION_TAB_DRAG_LOOP_DONE, content::NotificationService::AllBrowserContextsAndSources(), diff --git a/ui/views/widget/desktop_aura/desktop_native_widget_aura.cc b/ui/views/widget/desktop_aura/desktop_native_widget_aura.cc index d5ed686..7dd3dfe 100644 --- a/ui/views/widget/desktop_aura/desktop_native_widget_aura.cc +++ b/ui/views/widget/desktop_aura/desktop_native_widget_aura.cc @@ -695,10 +695,12 @@ void DesktopNativeWidgetAura::SetInactiveRenderingDisabled(bool value) { Widget::MoveLoopResult DesktopNativeWidgetAura::RunMoveLoop( const gfx::Vector2d& drag_offset, - Widget::MoveLoopSource source) { + Widget::MoveLoopSource source, + Widget::MoveLoopEscapeBehavior escape_behavior) { if (!window_) return Widget::MOVE_LOOP_CANCELED; - return desktop_root_window_host_->RunMoveLoop(drag_offset, source); + return desktop_root_window_host_->RunMoveLoop(drag_offset, source, + escape_behavior); } void DesktopNativeWidgetAura::EndMoveLoop() { diff --git a/ui/views/widget/desktop_aura/desktop_native_widget_aura.h b/ui/views/widget/desktop_aura/desktop_native_widget_aura.h index a70e767..b644e7c 100644 --- a/ui/views/widget/desktop_aura/desktop_native_widget_aura.h +++ b/ui/views/widget/desktop_aura/desktop_native_widget_aura.h @@ -157,7 +157,8 @@ class VIEWS_EXPORT DesktopNativeWidgetAura virtual void SetInactiveRenderingDisabled(bool value) OVERRIDE; virtual Widget::MoveLoopResult RunMoveLoop( const gfx::Vector2d& drag_offset, - Widget::MoveLoopSource source) OVERRIDE; + Widget::MoveLoopSource source, + Widget::MoveLoopEscapeBehavior escape_behavior) OVERRIDE; virtual void EndMoveLoop() OVERRIDE; virtual void SetVisibilityChangedAnimationsEnabled(bool value) OVERRIDE; virtual ui::NativeTheme* GetNativeTheme() const OVERRIDE; diff --git a/ui/views/widget/desktop_aura/desktop_root_window_host.h b/ui/views/widget/desktop_aura/desktop_root_window_host.h index 583b0ac..919bbb7 100644 --- a/ui/views/widget/desktop_aura/desktop_root_window_host.h +++ b/ui/views/widget/desktop_aura/desktop_root_window_host.h @@ -88,7 +88,8 @@ class VIEWS_EXPORT DesktopRootWindowHost { virtual Widget::MoveLoopResult RunMoveLoop( const gfx::Vector2d& drag_offset, - Widget::MoveLoopSource source) = 0; + Widget::MoveLoopSource source, + Widget::MoveLoopEscapeBehavior escape_behavior) = 0; virtual void EndMoveLoop() = 0; virtual void SetVisibilityChangedAnimationsEnabled(bool value) = 0; diff --git a/ui/views/widget/desktop_aura/desktop_root_window_host_win.cc b/ui/views/widget/desktop_aura/desktop_root_window_host_win.cc index ae4a982..80cc7cc 100644 --- a/ui/views/widget/desktop_aura/desktop_root_window_host_win.cc +++ b/ui/views/widget/desktop_aura/desktop_root_window_host_win.cc @@ -308,8 +308,11 @@ void DesktopRootWindowHostWin::ClearNativeFocus() { Widget::MoveLoopResult DesktopRootWindowHostWin::RunMoveLoop( const gfx::Vector2d& drag_offset, - Widget::MoveLoopSource source) { - return message_handler_->RunMoveLoop(drag_offset) ? + Widget::MoveLoopSource source, + Widget::MoveLoopEscapeBehavior escape_behavior) { + const bool hide_on_escape = + escape_behavior == Widget::MOVE_LOOP_ESCAPE_BEHAVIOR_HIDE; + return message_handler_->RunMoveLoop(drag_offset, hide_on_escape) ? Widget::MOVE_LOOP_SUCCESSFUL : Widget::MOVE_LOOP_CANCELED; } diff --git a/ui/views/widget/desktop_aura/desktop_root_window_host_win.h b/ui/views/widget/desktop_aura/desktop_root_window_host_win.h index 3e11208..0946b9f0 100644 --- a/ui/views/widget/desktop_aura/desktop_root_window_host_win.h +++ b/ui/views/widget/desktop_aura/desktop_root_window_host_win.h @@ -79,7 +79,8 @@ class VIEWS_EXPORT DesktopRootWindowHostWin virtual void ClearNativeFocus() OVERRIDE; virtual Widget::MoveLoopResult RunMoveLoop( const gfx::Vector2d& drag_offset, - Widget::MoveLoopSource source) OVERRIDE; + Widget::MoveLoopSource source, + Widget::MoveLoopEscapeBehavior escape_behavior) OVERRIDE; virtual void EndMoveLoop() OVERRIDE; virtual void SetVisibilityChangedAnimationsEnabled(bool value) OVERRIDE; virtual bool ShouldUseNativeFrame() OVERRIDE; diff --git a/ui/views/widget/desktop_aura/desktop_root_window_host_x11.cc b/ui/views/widget/desktop_aura/desktop_root_window_host_x11.cc index eaf36e4..58cb0a5 100644 --- a/ui/views/widget/desktop_aura/desktop_root_window_host_x11.cc +++ b/ui/views/widget/desktop_aura/desktop_root_window_host_x11.cc @@ -443,7 +443,8 @@ void DesktopRootWindowHostX11::ClearNativeFocus() { Widget::MoveLoopResult DesktopRootWindowHostX11::RunMoveLoop( const gfx::Vector2d& drag_offset, - Widget::MoveLoopSource source) { + Widget::MoveLoopSource source, + Widget::MoveLoopEscapeBehavior escape_behavior) { SetCapture(); aura::client::WindowMoveSource window_move_source = diff --git a/ui/views/widget/desktop_aura/desktop_root_window_host_x11.h b/ui/views/widget/desktop_aura/desktop_root_window_host_x11.h index 1c5e196..c2c4eec 100644 --- a/ui/views/widget/desktop_aura/desktop_root_window_host_x11.h +++ b/ui/views/widget/desktop_aura/desktop_root_window_host_x11.h @@ -106,7 +106,8 @@ class VIEWS_EXPORT DesktopRootWindowHostX11 : virtual void ClearNativeFocus() OVERRIDE; virtual Widget::MoveLoopResult RunMoveLoop( const gfx::Vector2d& drag_offset, - Widget::MoveLoopSource source) OVERRIDE; + Widget::MoveLoopSource source, + Widget::MoveLoopEscapeBehavior escape_behavior) OVERRIDE; virtual void EndMoveLoop() OVERRIDE; virtual void SetVisibilityChangedAnimationsEnabled(bool value) OVERRIDE; virtual bool ShouldUseNativeFrame() OVERRIDE; diff --git a/ui/views/widget/native_widget_aura.cc b/ui/views/widget/native_widget_aura.cc index 5c5136b..2c22fbe 100644 --- a/ui/views/widget/native_widget_aura.cc +++ b/ui/views/widget/native_widget_aura.cc @@ -649,7 +649,10 @@ void NativeWidgetAura::SetInactiveRenderingDisabled(bool value) { Widget::MoveLoopResult NativeWidgetAura::RunMoveLoop( const gfx::Vector2d& drag_offset, - Widget::MoveLoopSource source) { + Widget::MoveLoopSource source, + Widget::MoveLoopEscapeBehavior escape_behavior) { + // |escape_behavior| is only needed on windows when running the native message + // loop. if (window_ && window_->parent() && aura::client::GetWindowMoveClient(window_->parent())) { SetCapture(); diff --git a/ui/views/widget/native_widget_aura.h b/ui/views/widget/native_widget_aura.h index dfd3aaf..b3ba511 100644 --- a/ui/views/widget/native_widget_aura.h +++ b/ui/views/widget/native_widget_aura.h @@ -128,7 +128,8 @@ class VIEWS_EXPORT NativeWidgetAura virtual void SetInactiveRenderingDisabled(bool value) OVERRIDE; virtual Widget::MoveLoopResult RunMoveLoop( const gfx::Vector2d& drag_offset, - Widget::MoveLoopSource source) OVERRIDE; + Widget::MoveLoopSource source, + Widget::MoveLoopEscapeBehavior escape_behavior) OVERRIDE; virtual void EndMoveLoop() OVERRIDE; virtual void SetVisibilityChangedAnimationsEnabled(bool value) OVERRIDE; virtual ui::NativeTheme* GetNativeTheme() const OVERRIDE; diff --git a/ui/views/widget/native_widget_private.h b/ui/views/widget/native_widget_private.h index 4654b20..130d882 100644 --- a/ui/views/widget/native_widget_private.h +++ b/ui/views/widget/native_widget_private.h @@ -211,7 +211,8 @@ class VIEWS_EXPORT NativeWidgetPrivate : public NativeWidget { virtual void SetInactiveRenderingDisabled(bool value) = 0; virtual Widget::MoveLoopResult RunMoveLoop( const gfx::Vector2d& drag_offset, - Widget::MoveLoopSource source) = 0; + Widget::MoveLoopSource source, + Widget::MoveLoopEscapeBehavior escape_behavior) = 0; virtual void EndMoveLoop() = 0; virtual void SetVisibilityChangedAnimationsEnabled(bool value) = 0; virtual ui::NativeTheme* GetNativeTheme() const = 0; diff --git a/ui/views/widget/native_widget_win.cc b/ui/views/widget/native_widget_win.cc index 53aed93..afdd6d8 100644 --- a/ui/views/widget/native_widget_win.cc +++ b/ui/views/widget/native_widget_win.cc @@ -440,8 +440,11 @@ void NativeWidgetWin::SetInactiveRenderingDisabled(bool value) { Widget::MoveLoopResult NativeWidgetWin::RunMoveLoop( const gfx::Vector2d& drag_offset, - Widget::MoveLoopSource source) { - return message_handler_->RunMoveLoop(drag_offset) ? + Widget::MoveLoopSource source, + Widget::MoveLoopEscapeBehavior escape_behavior) { + const bool hide_on_escape = + escape_behavior == Widget::MOVE_LOOP_ESCAPE_BEHAVIOR_HIDE; + return message_handler_->RunMoveLoop(drag_offset, hide_on_escape) ? Widget::MOVE_LOOP_SUCCESSFUL : Widget::MOVE_LOOP_CANCELED; } diff --git a/ui/views/widget/native_widget_win.h b/ui/views/widget/native_widget_win.h index cadc6fd..faa690f 100644 --- a/ui/views/widget/native_widget_win.h +++ b/ui/views/widget/native_widget_win.h @@ -142,7 +142,8 @@ class VIEWS_EXPORT NativeWidgetWin : public internal::NativeWidgetPrivate, virtual void SetInactiveRenderingDisabled(bool value) OVERRIDE; virtual Widget::MoveLoopResult RunMoveLoop( const gfx::Vector2d& drag_offset, - Widget::MoveLoopSource source) OVERRIDE; + Widget::MoveLoopSource source, + Widget::MoveLoopEscapeBehavior escape_behavior) OVERRIDE; virtual void EndMoveLoop() OVERRIDE; virtual void SetVisibilityChangedAnimationsEnabled(bool value) OVERRIDE; virtual ui::NativeTheme* GetNativeTheme() const OVERRIDE; diff --git a/ui/views/widget/widget.cc b/ui/views/widget/widget.cc index 168cfdf..a17e007 100644 --- a/ui/views/widget/widget.cc +++ b/ui/views/widget/widget.cc @@ -530,9 +530,11 @@ void Widget::SetVisibilityChangedAnimationsEnabled(bool value) { native_widget_->SetVisibilityChangedAnimationsEnabled(value); } -Widget::MoveLoopResult Widget::RunMoveLoop(const gfx::Vector2d& drag_offset, - MoveLoopSource source) { - return native_widget_->RunMoveLoop(drag_offset, source); +Widget::MoveLoopResult Widget::RunMoveLoop( + const gfx::Vector2d& drag_offset, + MoveLoopSource source, + MoveLoopEscapeBehavior escape_behavior) { + return native_widget_->RunMoveLoop(drag_offset, source, escape_behavior); } void Widget::EndMoveLoop() { diff --git a/ui/views/widget/widget.h b/ui/views/widget/widget.h index 1600f94..120d5c5 100644 --- a/ui/views/widget/widget.h +++ b/ui/views/widget/widget.h @@ -116,6 +116,15 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate, MOVE_LOOP_SOURCE_TOUCH, }; + // Behavior when escape is pressed during a move loop. + enum MoveLoopEscapeBehavior { + // Indicates the window should be hidden. + MOVE_LOOP_ESCAPE_BEHAVIOR_HIDE, + + // Indicates the window should not be hidden. + MOVE_LOOP_ESCAPE_BEHAVIOR_DONT_HIDE, + }; + struct VIEWS_EXPORT InitParams { enum Type { TYPE_WINDOW, // A decorated Window, like a frame window. @@ -395,7 +404,8 @@ class VIEWS_EXPORT Widget : public internal::NativeWidgetDelegate, // corner of the window to the point where the cursor is dragging, and is used // to offset the bounds of the window from the cursor. MoveLoopResult RunMoveLoop(const gfx::Vector2d& drag_offset, - MoveLoopSource source); + MoveLoopSource source, + MoveLoopEscapeBehavior escape_behavior); // Stops a previously started move loop. This is not immediate. void EndMoveLoop(); diff --git a/ui/views/win/hwnd_message_handler.cc b/ui/views/win/hwnd_message_handler.cc index ed53f9f..b2fac0a 100644 --- a/ui/views/win/hwnd_message_handler.cc +++ b/ui/views/win/hwnd_message_handler.cc @@ -52,7 +52,7 @@ namespace { // completed. class MoveLoopMouseWatcher { public: - explicit MoveLoopMouseWatcher(HWNDMessageHandler* host); + MoveLoopMouseWatcher(HWNDMessageHandler* host, bool hide_on_escape); ~MoveLoopMouseWatcher(); // Returns true if the mouse is up, or if we couldn't install the hook. @@ -72,6 +72,9 @@ class MoveLoopMouseWatcher { // HWNDMessageHandler that created us. HWNDMessageHandler* host_; + // Should the window be hidden when escape is pressed? + const bool hide_on_escape_; + // Did we get a mouse up? bool got_mouse_up_; @@ -85,8 +88,10 @@ class MoveLoopMouseWatcher { // static MoveLoopMouseWatcher* MoveLoopMouseWatcher::instance_ = NULL; -MoveLoopMouseWatcher::MoveLoopMouseWatcher(HWNDMessageHandler* host) +MoveLoopMouseWatcher::MoveLoopMouseWatcher(HWNDMessageHandler* host, + bool hide_on_escape) : host_(host), + hide_on_escape_(hide_on_escape), got_mouse_up_(false), mouse_hook_(NULL), key_hook_(NULL) { @@ -149,11 +154,8 @@ LRESULT CALLBACK MoveLoopMouseWatcher::KeyHook(int n_code, &value, sizeof(value)); } - // Hide the window on escape, otherwise the window is visibly going to snap - // back to the original location before we close it. - // This behavior is specific to tab dragging, in that we generally wouldn't - // want this functionality if we have other consumers using this API. - instance_->host_->Hide(); + if (instance_->hide_on_escape_) + instance_->host_->Hide(); } return CallNextHookEx(instance_->key_hook_, n_code, w_param, l_param); } @@ -684,9 +686,10 @@ bool HWNDMessageHandler::IsMaximized() const { return !!::IsZoomed(hwnd()); } -bool HWNDMessageHandler::RunMoveLoop(const gfx::Vector2d& drag_offset) { +bool HWNDMessageHandler::RunMoveLoop(const gfx::Vector2d& drag_offset, + bool hide_on_escape) { ReleaseCapture(); - MoveLoopMouseWatcher watcher(this); + MoveLoopMouseWatcher watcher(this, hide_on_escape); #if defined(USE_AURA) // In Aura, we handle touch events asynchronously. So we need to allow nested // tasks while in windows move loop. diff --git a/ui/views/win/hwnd_message_handler.h b/ui/views/win/hwnd_message_handler.h index 1751a82..751cd72 100644 --- a/ui/views/win/hwnd_message_handler.h +++ b/ui/views/win/hwnd_message_handler.h @@ -108,7 +108,7 @@ class VIEWS_EXPORT HWNDMessageHandler : bool IsMinimized() const; bool IsMaximized() const; - bool RunMoveLoop(const gfx::Vector2d& drag_offset); + bool RunMoveLoop(const gfx::Vector2d& drag_offset, bool hide_on_escape); void EndMoveLoop(); // Tells the HWND its client area has changed. |