summaryrefslogtreecommitdiffstats
path: root/ash/wm
diff options
context:
space:
mode:
Diffstat (limited to 'ash/wm')
-rw-r--r--ash/wm/drag_window_resizer.cc13
-rw-r--r--ash/wm/drag_window_resizer_unittest.cc94
2 files changed, 103 insertions, 4 deletions
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