diff options
author | skuhne@chromium.org <skuhne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-30 05:22:33 +0000 |
---|---|---|
committer | skuhne@chromium.org <skuhne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-30 05:22:33 +0000 |
commit | 79e7e602c4ac1c8031977a6725ea81b77f4abb24 (patch) | |
tree | ae3488ff3ae6b54ee94b947f21f180f17022ad86 | |
parent | c14b4b3bfcc1e77e8a5b31436a3668f0fc6ccecd (diff) | |
download | chromium_src-79e7e602c4ac1c8031977a6725ea81b77f4abb24.zip chromium_src-79e7e602c4ac1c8031977a6725ea81b77f4abb24.tar.gz chromium_src-79e7e602c4ac1c8031977a6725ea81b77f4abb24.tar.bz2 |
Animating and fading a dragged window when dragged onto a multi user icon in the tray
BUG=312550
TEST=unittest (& visually tested)
Review URL: https://codereview.chromium.org/50763005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@231766 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ash/session_state_delegate.h | 2 | ||||
-rw-r--r-- | ash/session_state_delegate_stub.cc | 2 | ||||
-rw-r--r-- | ash/session_state_delegate_stub.h | 2 | ||||
-rw-r--r-- | ash/system/tray/system_tray.cc | 5 | ||||
-rw-r--r-- | ash/system/tray/system_tray.h | 4 | ||||
-rw-r--r-- | ash/system/user/tray_user.cc | 2 | ||||
-rw-r--r-- | ash/test/test_session_state_delegate.cc | 6 | ||||
-rw-r--r-- | ash/test/test_session_state_delegate.h | 10 | ||||
-rw-r--r-- | ash/wm/drag_window_resizer.cc | 13 | ||||
-rw-r--r-- | ash/wm/drag_window_resizer_unittest.cc | 94 | ||||
-rw-r--r-- | chrome/browser/ui/ash/session_state_delegate_chromeos.cc | 2 | ||||
-rw-r--r-- | chrome/browser/ui/ash/session_state_delegate_chromeos.h | 2 | ||||
-rw-r--r-- | chrome/browser/ui/ash/session_state_delegate_views.cc | 2 | ||||
-rw-r--r-- | chrome/browser/ui/ash/session_state_delegate_views.h | 2 |
14 files changed, 133 insertions, 15 deletions
diff --git a/ash/session_state_delegate.h b/ash/session_state_delegate.h index 7fac828..47570ff 100644 --- a/ash/session_state_delegate.h +++ b/ash/session_state_delegate.h @@ -109,7 +109,7 @@ class ASH_EXPORT SessionStateDelegate { // is therefore shown on the desktop of every user. virtual bool TransferWindowToDesktopOfUser( aura::Window* window, - ash::MultiProfileIndex index) const = 0; + ash::MultiProfileIndex index) = 0; }; } // namespace ash diff --git a/ash/session_state_delegate_stub.cc b/ash/session_state_delegate_stub.cc index 91602b3..6daa593 100644 --- a/ash/session_state_delegate_stub.cc +++ b/ash/session_state_delegate_stub.cc @@ -95,7 +95,7 @@ void SessionStateDelegateStub::RemoveSessionStateObserver( bool SessionStateDelegateStub::TransferWindowToDesktopOfUser( aura::Window* window, - ash::MultiProfileIndex index) const { + ash::MultiProfileIndex index) { return false; } diff --git a/ash/session_state_delegate_stub.h b/ash/session_state_delegate_stub.h index 894759d..6fe1eb9 100644 --- a/ash/session_state_delegate_stub.h +++ b/ash/session_state_delegate_stub.h @@ -45,7 +45,7 @@ class SessionStateDelegateStub : public SessionStateDelegate { ash::SessionStateObserver* observer) OVERRIDE; virtual bool TransferWindowToDesktopOfUser( aura::Window* window, - ash::MultiProfileIndex index) const OVERRIDE; + ash::MultiProfileIndex index) OVERRIDE; private: bool screen_locked_; diff --git a/ash/system/tray/system_tray.cc b/ash/system/tray/system_tray.cc index 769eb03..4782ec3 100644 --- a/ash/system/tray/system_tray.cc +++ b/ash/system/tray/system_tray.cc @@ -674,6 +674,11 @@ views::View* SystemTray::GetTrayItemViewForTest(SystemTrayItem* item) { return it == tray_item_map_.end() ? NULL : it->second; } +void SystemTray::AddTrayUserItemForTest(internal::TrayUser* tray_user) { + AddTrayItem(tray_user); + user_items_.push_back(tray_user); +} + bool SystemTray::PerformAction(const ui::Event& event) { // If we're already showing the default view, hide it; otherwise, show it // (and hide any popup that's currently shown). diff --git a/ash/system/tray/system_tray.h b/ash/system/tray/system_tray.h index 2d1b6db..7b1681d 100644 --- a/ash/system/tray/system_tray.h +++ b/ash/system/tray/system_tray.h @@ -154,6 +154,10 @@ class ASH_EXPORT SystemTray : public internal::TrayBackgroundView, // Get the tray item view (or NULL) for a given |tray_item| in a unit test. views::View* GetTrayItemViewForTest(SystemTrayItem* tray_item); + // Add a tray user item for testing purposes. Note: The passed |tray_user| + // will be owned by the SystemTray after the call. + void AddTrayUserItemForTest(internal::TrayUser* tray_user); + private: // Creates the default set of items for the sytem tray. void CreateItems(SystemTrayDelegate* delegate); diff --git a/ash/system/user/tray_user.cc b/ash/system/user/tray_user.cc index ba62612..7804200 100644 --- a/ash/system/user/tray_user.cc +++ b/ash/system/user/tray_user.cc @@ -1148,7 +1148,7 @@ bool TrayUser::CanDropWindowHereToTransferToUser( } bool TrayUser::TransferWindowToUser(aura::Window* window) { - const SessionStateDelegate* session_state_delegate = + SessionStateDelegate* session_state_delegate = ash::Shell::GetInstance()->session_state_delegate(); return session_state_delegate->TransferWindowToDesktopOfUser(window, GetTrayIndex()); diff --git a/ash/test/test_session_state_delegate.cc b/ash/test/test_session_state_delegate.cc index 0373602..8032f4f 100644 --- a/ash/test/test_session_state_delegate.cc +++ b/ash/test/test_session_state_delegate.cc @@ -34,7 +34,8 @@ TestSessionStateDelegate::TestSessionStateDelegate() should_lock_screen_before_suspending_(false), screen_locked_(false), user_adding_screen_running_(false), - logged_in_users_(1) { + logged_in_users_(1), + num_transfer_to_desktop_of_user_calls_(0) { } TestSessionStateDelegate::~TestSessionStateDelegate() { @@ -160,7 +161,8 @@ void TestSessionStateDelegate::RemoveSessionStateObserver( bool TestSessionStateDelegate::TransferWindowToDesktopOfUser( aura::Window* window, - ash::MultiProfileIndex index) const { + ash::MultiProfileIndex index) { + num_transfer_to_desktop_of_user_calls_++; return false; } diff --git a/ash/test/test_session_state_delegate.h b/ash/test/test_session_state_delegate.h index 553f1ea..fcd375d 100644 --- a/ash/test/test_session_state_delegate.h +++ b/ash/test/test_session_state_delegate.h @@ -48,7 +48,7 @@ class TestSessionStateDelegate : public SessionStateDelegate { ash::SessionStateObserver* observer) OVERRIDE; virtual bool TransferWindowToDesktopOfUser( aura::Window* window, - ash::MultiProfileIndex index) const OVERRIDE; + ash::MultiProfileIndex index) OVERRIDE; // TODO(oshima): Use state machine instead of using boolean variables. @@ -76,6 +76,11 @@ class TestSessionStateDelegate : public SessionStateDelegate { // running now. void SetUserAddingScreenRunning(bool user_adding_screen_running); + // Returns the number of calls to TransferWindowToDesktopOfUser. + int num_transfer_to_desktop_of_user_calls() { + return num_transfer_to_desktop_of_user_calls_; + } + private: // Whether a session is in progress and there is an active user. bool has_active_user_; @@ -107,6 +112,9 @@ class TestSessionStateDelegate : public SessionStateDelegate { // A test user image. gfx::ImageSkia null_image_; + // The number of calls which happened to TransferWindowToDesktopOfUser. + int num_transfer_to_desktop_of_user_calls_; + DISALLOW_COPY_AND_ASSIGN(TestSessionStateDelegate); }; diff --git a/ash/wm/drag_window_resizer.cc b/ash/wm/drag_window_resizer.cc index 4c07b65..5713cf8 100644 --- a/ash/wm/drag_window_resizer.cc +++ b/ash/wm/drag_window_resizer.cc @@ -31,6 +31,9 @@ namespace { // The maximum opacity of the drag phantom window. const float kMaxOpacity = 0.8f; +// The opacity of the window when dragging it over a user item in the tray. +const float kOpacityWhenDraggedOverUserIcon = 0.4f; + // Returns true if Ash has more than one root window. bool HasSecondaryRootWindow() { return Shell::GetAllRootWindows().size() > 1; @@ -80,11 +83,12 @@ void DragWindowResizer::Drag(const gfx::Point& location, int event_flags) { base::WeakPtr<DragWindowResizer> resizer(weak_ptr_factory_.GetWeakPtr()); // If we are on top of a window to desktop transfer button, we move the window - // temporarily back to where it was initially (showing that we do something). - gfx::Point filtered_location = GetTrayUserItemAtPoint(location) ? - details_.initial_location_in_parent : location; + // temporarily back to where it was initially and make it semi-transparent. + GetTarget()->layer()->SetOpacity( + GetTrayUserItemAtPoint(location) ? kOpacityWhenDraggedOverUserIcon : + details_.initial_opacity); - next_window_resizer_->Drag(filtered_location, event_flags); + next_window_resizer_->Drag(location, event_flags); if (!resizer) return; @@ -260,6 +264,7 @@ bool DragWindowResizer::TryDraggingToNewUser() { // it's thing and return the transparency to its original value. int old_opacity = GetTarget()->layer()->opacity(); GetTarget()->layer()->SetOpacity(0); + GetTarget()->SetBounds(details_.initial_bounds_in_parent); if (!tray_user->TransferWindowToUser(details_.window)) { GetTarget()->layer()->SetOpacity(old_opacity); return false; diff --git a/ash/wm/drag_window_resizer_unittest.cc b/ash/wm/drag_window_resizer_unittest.cc index 6bf3d6a..844cbaa 100644 --- a/ash/wm/drag_window_resizer_unittest.cc +++ b/ash/wm/drag_window_resizer_unittest.cc @@ -23,6 +23,13 @@ #include "ui/gfx/screen.h" #include "ui/views/widget/widget.h" +#if defined(OS_CHROMEOS) +#include "ash/system/tray/system_tray.h" +#include "ash/system/user/tray_user.h" +#include "ash/test/test_session_state_delegate.h" +#include "ash/test/test_shell_delegate.h" +#endif + namespace ash { namespace internal { namespace { @@ -566,5 +573,92 @@ TEST_F(DragWindowResizerTest, MoveWindowAcrossDisplays) { } } +#if defined(OS_CHROMEOS) +// Checks that moving a window to another desktop will properly set and reset +// the transparency. +TEST_F(DragWindowResizerTest, DragToOtherDesktopOpacity) { + // Set up a few things we need for multi profile. + ash::test::TestSessionStateDelegate* session_delegate = + static_cast<ash::test::TestSessionStateDelegate*>( + ash::Shell::GetInstance()->session_state_delegate()); + session_delegate->set_logged_in_users(2); + ash::test::TestShellDelegate* shell_delegate = + static_cast<ash::test::TestShellDelegate*>( + ash::Shell::GetInstance()->delegate()); + shell_delegate->set_multi_profiles_enabled(true); + + // Create one other user where we can drag our stuff onto. + SystemTray* tray = Shell::GetPrimaryRootWindowController()->GetSystemTray(); + TrayUser* tray_user = new TrayUser(tray, 1); + tray->AddTrayUserItemForTest(tray_user); + + // Move the view somewhere where we can hit it. + views::View* view = tray->GetTrayItemViewForTest(tray_user); + view->SetBounds(80, 0, 20, 20); + gfx::Point center = view->GetBoundsInScreen().CenterPoint(); + + gfx::Rect initial_bounds = gfx::Rect(0, 0, 50, 60); + // Drag the window over the icon and let it drop. Test that the window's + // layer gets transparent and reverts back. + { + aura::Window* window = window_.get(); + window->SetBoundsInScreen(initial_bounds, + Shell::GetScreen()->GetPrimaryDisplay()); + // Grab (0, 0) of the window. + scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( + window, gfx::Point(), HTCAPTION)); + ASSERT_TRUE(resizer.get()); + EXPECT_EQ(1.0, window->layer()->opacity()); + resizer->Drag(center, 0); + EXPECT_NE(1.0, window->layer()->opacity()); + EXPECT_EQ(0, session_delegate->num_transfer_to_desktop_of_user_calls()); + resizer->CompleteDrag(0); + EXPECT_EQ(1.0, window->layer()->opacity()); + EXPECT_EQ(1, session_delegate->num_transfer_to_desktop_of_user_calls()); + EXPECT_EQ(initial_bounds.ToString(), window->bounds().ToString()); + } + + // Drag the window over the icon and cancel the operation. Test that the + // window's layer gets transparent and reverts back. + { + aura::Window* window = window_.get(); + window->SetBoundsInScreen(initial_bounds, + Shell::GetScreen()->GetPrimaryDisplay()); + // Grab (0, 0) of the window. + scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( + window, gfx::Point(), HTCAPTION)); + ASSERT_TRUE(resizer.get()); + EXPECT_EQ(1.0, window->layer()->opacity()); + resizer->Drag(center, 0); + EXPECT_NE(1.0, window->layer()->opacity()); + resizer->RevertDrag(); + EXPECT_EQ(1.0, window->layer()->opacity()); + EXPECT_EQ(1, session_delegate->num_transfer_to_desktop_of_user_calls()); + EXPECT_EQ(initial_bounds.ToString(), window->bounds().ToString()); + } + + // Drag the window over the icon and somewhere else and see that it properly + // reverts its transparency. + { + aura::Window* window = window_.get(); + window->SetBoundsInScreen(initial_bounds, + Shell::GetScreen()->GetPrimaryDisplay()); + // Grab (0, 0) of the window. + scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( + window, gfx::Point(), HTCAPTION)); + ASSERT_TRUE(resizer.get()); + EXPECT_EQ(1.0, window->layer()->opacity()); + resizer->Drag(center, 0); + EXPECT_NE(1.0, window->layer()->opacity()); + resizer->Drag(gfx::Point(), 0); + EXPECT_EQ(1.0, window->layer()->opacity()); + resizer->CompleteDrag(0); + EXPECT_EQ(1, session_delegate->num_transfer_to_desktop_of_user_calls()); + EXPECT_NE(initial_bounds.ToString(), window->bounds().ToString()); + } +} +#endif + + } // namespace internal } // namespace ash diff --git a/chrome/browser/ui/ash/session_state_delegate_chromeos.cc b/chrome/browser/ui/ash/session_state_delegate_chromeos.cc index e1ff42b..b519eda 100644 --- a/chrome/browser/ui/ash/session_state_delegate_chromeos.cc +++ b/chrome/browser/ui/ash/session_state_delegate_chromeos.cc @@ -169,7 +169,7 @@ void SessionStateDelegateChromeos::RemoveSessionStateObserver( bool SessionStateDelegateChromeos::TransferWindowToDesktopOfUser( aura::Window* window, - ash::MultiProfileIndex index) const { + ash::MultiProfileIndex index) { chrome::MultiUserWindowManager* window_manager = chrome::MultiUserWindowManager::GetInstance(); if (!window_manager || window_manager->GetWindowOwner(window).empty()) diff --git a/chrome/browser/ui/ash/session_state_delegate_chromeos.h b/chrome/browser/ui/ash/session_state_delegate_chromeos.h index 24a7964..45a6fe6 100644 --- a/chrome/browser/ui/ash/session_state_delegate_chromeos.h +++ b/chrome/browser/ui/ash/session_state_delegate_chromeos.h @@ -49,7 +49,7 @@ class SessionStateDelegateChromeos ash::SessionStateObserver* observer) OVERRIDE; virtual bool TransferWindowToDesktopOfUser( aura::Window* window, - ash::MultiProfileIndex index) const OVERRIDE; + ash::MultiProfileIndex index) OVERRIDE; // UserManager::UserSessionStateObserver: virtual void ActiveUserChanged(const chromeos::User* active_user) OVERRIDE; virtual void UserAddedToSession(const chromeos::User* added_user) OVERRIDE; diff --git a/chrome/browser/ui/ash/session_state_delegate_views.cc b/chrome/browser/ui/ash/session_state_delegate_views.cc index 2998204..4c86889 100644 --- a/chrome/browser/ui/ash/session_state_delegate_views.cc +++ b/chrome/browser/ui/ash/session_state_delegate_views.cc @@ -103,7 +103,7 @@ void SessionStateDelegate::RemoveSessionStateObserver( bool SessionStateDelegate::TransferWindowToDesktopOfUser( aura::Window* window, - ash::MultiProfileIndex index) const { + ash::MultiProfileIndex index) { NOTIMPLEMENTED(); return false; } diff --git a/chrome/browser/ui/ash/session_state_delegate_views.h b/chrome/browser/ui/ash/session_state_delegate_views.h index 238c1b4..aa055ea 100644 --- a/chrome/browser/ui/ash/session_state_delegate_views.h +++ b/chrome/browser/ui/ash/session_state_delegate_views.h @@ -46,7 +46,7 @@ class SessionStateDelegate : public ash::SessionStateDelegate { ash::SessionStateObserver* observer) OVERRIDE; virtual bool TransferWindowToDesktopOfUser( aura::Window* window, - ash::MultiProfileIndex index) const OVERRIDE; + ash::MultiProfileIndex index) OVERRIDE; private: DISALLOW_COPY_AND_ASSIGN(SessionStateDelegate); }; |