#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/window_tree_client.h"
#include "ui/aura/root_window.h"
+#include "ui/aura/test/event_generator.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/base/hit_test.h"
#include "ui/base/ui_base_types.h"
if (window_type_ == ui::wm::WINDOW_TYPE_PANEL) {
test::TestShelfDelegate* shelf_delegate =
test::TestShelfDelegate::instance();
- shelf_delegate->AddLauncherItem(window);
+ shelf_delegate->AddShelfItem(window);
PanelLayoutManager* manager =
static_cast<PanelLayoutManager*>(
Shell::GetContainer(window->GetRootWindow(),
bool test_panels() const { return window_type_ == ui::wm::WINDOW_TYPE_PANEL; }
+ aura::test::TestWindowDelegate* delegate() {
+ return &delegate_;
+ }
+
const gfx::Point& initial_location_in_parent() const {
return initial_location_in_parent_;
}
DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0);
// The window should be docked at the right edge.
- EXPECT_EQ(window->GetRootWindow()->bounds().right(),
+ EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
window->GetBoundsInScreen().right());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id());
}
DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), +4);
// The window should be docked at the right edge.
- EXPECT_EQ(window->GetRootWindow()->bounds().right(),
+ EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
window->GetBoundsInScreen().right());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id());
}
// The window right should be past the screen edge but not docked.
// Initial touch point is 70px to the right which helps to find where the edge
// should be.
- EXPECT_EQ(window->GetRootWindow()->bounds().right() +
+ EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right() +
window->bounds().width() - kGrabOffsetX - kUndershootBy - 1,
window->GetBoundsInScreen().right());
EXPECT_EQ(internal::kShellWindowId_DefaultContainer,
DragRelativeToEdge(DOCKED_EDGE_LEFT, window.get(), 0);
// The window should be docked at the left edge.
- EXPECT_EQ(window->GetRootWindow()->bounds().x(),
+ EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().x(),
window->GetBoundsInScreen().x());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id());
}
DragRelativeToEdge(DOCKED_EDGE_LEFT, window.get(), -4);
// The window should be docked at the left edge.
- EXPECT_EQ(window->GetRootWindow()->bounds().x(),
+ EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().x(),
window->GetBoundsInScreen().x());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id());
}
DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0);
// The window should be docked at the right edge.
- EXPECT_EQ(window->GetRootWindow()->bounds().right(),
+ EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
window->GetBoundsInScreen().right());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id());
shell->SetShelfAlignment(SHELF_ALIGNMENT_RIGHT,
shell->GetPrimaryRootWindow());
// The window should have moved and get attached to the left dock.
- EXPECT_EQ(window->GetRootWindow()->bounds().x(),
+ EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().x(),
window->GetBoundsInScreen().x());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id());
shell->SetShelfAlignment(SHELF_ALIGNMENT_LEFT,
shell->GetPrimaryRootWindow());
// The window should have moved and get attached to the right edge.
- EXPECT_EQ(window->GetRootWindow()->bounds().right(),
+ EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
window->GetBoundsInScreen().right());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id());
shell->SetShelfAlignment(SHELF_ALIGNMENT_BOTTOM,
shell->GetPrimaryRootWindow());
// The window should stay in the right edge.
- EXPECT_EQ(window->GetRootWindow()->bounds().right(),
+ EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
window->GetBoundsInScreen().right());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id());
}
// The window should be docked at the right edge.
// Its width should shrink to ideal width.
- EXPECT_EQ(window->GetRootWindow()->bounds().right(),
+ EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
window->GetBoundsInScreen().right());
EXPECT_EQ(ideal_width(), window->GetBoundsInScreen().width());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id());
DragEnd();
// The window should be still attached to the right edge.
- EXPECT_EQ(window->GetRootWindow()->bounds().right(),
+ EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
window->GetBoundsInScreen().right());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id());
// Try to detach by dragging left by kSnapToDockDistance or more.
// The window should get undocked.
const int left_edge = window->bounds().x();
- ASSERT_NO_FATAL_FAILURE(DragStart(window.get()));
+ ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(
+ window.get(), 10, 0));
+ DragMove(-32, -10);
+ // Release the mouse and the window should be no longer attached to the dock.
+ DragEnd();
+
+ // The window should be floating on the desktop again and moved to the left.
+ EXPECT_EQ(left_edge - 32, window->GetBoundsInScreen().x());
+ EXPECT_EQ(internal::kShellWindowId_DefaultContainer,
+ window->parent()->id());
+}
+
+// Dock on the right side, and undock by dragging the right edge of the window
+// header. This test is useful because both the position of the dragged window
+// and the position of the mouse are used in determining whether a window should
+// be undocked.
+TEST_P(DockedWindowResizerTest, AttachTryDetachDragRightEdgeOfHeader) {
+ if (!SupportsHostWindowResize())
+ return;
+
+ scoped_ptr<aura::Window> window(CreateTestWindow(
+ gfx::Rect(0, 0, ideal_width() + 10, 201)));
+ DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0);
+
+ // The window should be docked at the right edge.
+ // Its width should shrink to ideal width.
+ EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
+ window->GetBoundsInScreen().right());
+ EXPECT_EQ(ideal_width(), window->GetBoundsInScreen().width());
+ EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id());
+
+ // Try to detach by dragging left less than kSnapToDockDistance.
+ // The window should stay docked.
+ ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(
+ window.get(), ideal_width() - 10, 0));
+ DragMove(-4, -10);
+ // Release the mouse and the window should be still attached to the dock.
+ DragEnd();
+
+ // The window should be still attached to the right edge.
+ EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
+ window->GetBoundsInScreen().right());
+ EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id());
+
+ // Try to detach by dragging left by kSnapToDockDistance or more.
+ // The window should get undocked.
+ const int left_edge = window->bounds().x();
+ ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(
+ window.get(), ideal_width() - 10, 0));
DragMove(-32, -10);
// Release the mouse and the window should be no longer attached to the dock.
DragEnd();
DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0);
// The window should be docked at the right edge.
- EXPECT_EQ(window->GetRootWindow()->bounds().right(),
+ EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
window->GetBoundsInScreen().right());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id());
DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0);
// The window should be docked at the right edge.
- EXPECT_EQ(window->GetRootWindow()->bounds().right(),
+ EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
window->GetBoundsInScreen().right());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id());
DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 50);
// Both windows should be docked at the right edge.
- EXPECT_EQ(w1->GetRootWindow()->bounds().right(),
+ EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
w1->GetBoundsInScreen().right());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id());
- EXPECT_EQ(w2->GetRootWindow()->bounds().right(),
+ EXPECT_EQ(w2->GetRootWindow()->GetBoundsInScreen().right(),
w2->GetBoundsInScreen().right());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id());
DragEnd();
// The first window should be still docked.
- EXPECT_EQ(w1->GetRootWindow()->bounds().right(),
+ EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
w1->GetBoundsInScreen().right());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id());
DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
// w1 should be docked at the right edge.
- EXPECT_EQ(w1->GetRootWindow()->bounds().right(),
+ EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
w1->GetBoundsInScreen().right());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id());
DragToVerticalPositionAndToEdge(DOCKED_EDGE_LEFT, w2.get(), 50);
// The first window should be docked at the right edge.
- EXPECT_EQ(w1->GetRootWindow()->bounds().right(),
+ EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
w1->GetBoundsInScreen().right());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id());
DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0);
// The window should be docked at the right edge.
- EXPECT_EQ(window->GetRootWindow()->bounds().right(),
+ EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
window->GetBoundsInScreen().right());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id());
DragRelativeToEdge(DOCKED_EDGE_RIGHT, window.get(), 0);
// The window should be docked at the right edge.
- EXPECT_EQ(window->GetRootWindow()->bounds().right(),
+ EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
window->GetBoundsInScreen().right());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id());
DragMove(100, 0);
EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id());
DragEnd();
- EXPECT_EQ(window->GetRootWindow()->bounds().right(),
+ EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
window->GetBoundsInScreen().right());
EXPECT_EQ(internal::kShellWindowId_DockedContainer,
window->parent()->id());
DragMove(window->bounds().width()/2 - 5, 0);
EXPECT_EQ(CorrectContainerIdDuringDrag(), window->parent()->id());
DragEnd();
- EXPECT_NE(window->GetRootWindow()->bounds().right(),
+ EXPECT_NE(window->GetRootWindow()->GetBoundsInScreen().right(),
window->GetBoundsInScreen().right());
EXPECT_EQ(internal::kShellWindowId_DefaultContainer,
window->parent()->id());
DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
// A window should be docked at the right edge.
- EXPECT_EQ(w1->GetRootWindow()->bounds().right(),
+ EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
w1->GetBoundsInScreen().right());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id());
DockedWindowLayoutManager* manager =
DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 100);
// Both windows should now be docked at the right edge.
- EXPECT_EQ(w2->GetRootWindow()->bounds().right(),
+ EXPECT_EQ(w2->GetRootWindow()->GetBoundsInScreen().right(),
w2->GetBoundsInScreen().right());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id());
// Dock width should be set to a wider window.
DragEnd();
// The first window should be still docked.
- EXPECT_EQ(w1->GetRootWindow()->bounds().right(),
+ EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
w1->GetBoundsInScreen().right());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id());
// The second window should be still docked.
- EXPECT_EQ(w2->GetRootWindow()->bounds().right(),
+ EXPECT_EQ(w2->GetRootWindow()->GetBoundsInScreen().right(),
w2->GetBoundsInScreen().right());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id());
DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
// A window should be docked at the right edge.
- EXPECT_EQ(w1->GetRootWindow()->bounds().right(),
+ EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
w1->GetBoundsInScreen().right());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id());
DockedWindowLayoutManager* manager =
EXPECT_EQ(w1->bounds().width(), docked_width(manager));
ASSERT_NO_FATAL_FAILURE(DragStartAtOffsetFromWindowOrigin(w2.get(), 25, 5));
- DragMove(w2->GetRootWindow()->bounds().right()
+ DragMove(w2->GetRootWindow()->bounds().width()
-w2->bounds().width()
-(w2->bounds().width()/2 + 20)
-w2->bounds().x(),
50 - w2->bounds().y());
DragEnd();
// The first window should be still docked.
- EXPECT_EQ(w1->GetRootWindow()->bounds().right(),
+ EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
w1->GetBoundsInScreen().right());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id());
// The second window should be floating on the desktop.
- EXPECT_EQ(w2->GetRootWindow()->bounds().right() -
+ EXPECT_EQ(w2->GetRootWindow()->GetBoundsInScreen().right() -
(w2->bounds().width()/2 + 20),
w2->GetBoundsInScreen().right());
EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w2->parent()->id());
DragToVerticalPositionAndToEdge(DOCKED_EDGE_LEFT, w1.get(), 20);
// A window should be docked at the left edge.
- EXPECT_EQ(w1->GetRootWindow()->bounds().x(),
+ EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().x(),
w1->GetBoundsInScreen().x());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id());
DockedWindowLayoutManager* manager =
static_cast<DockedWindowLayoutManager*>(w1->parent()->layout_manager());
// The first window should be docked.
- EXPECT_EQ(w1->GetRootWindow()->bounds().x(),
+ EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().x(),
w1->GetBoundsInScreen().x());
// Dock width should be set to that of a single docked window.
EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id());
min_dock_gap(),
50);
// The second window should be floating on the desktop.
- EXPECT_EQ(w2->GetRootWindow()->bounds().x() + (w1->bounds().right() + 20),
+ EXPECT_EQ(w2->GetRootWindow()->GetBoundsInScreen().x() +
+ (w1->bounds().right() + 20),
w2->GetBoundsInScreen().x());
EXPECT_EQ(internal::kShellWindowId_DefaultContainer, w2->parent()->id());
// Dock width should be set to that of a single docked window.
DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
// A window should be docked at the right edge.
- EXPECT_EQ(w1->GetRootWindow()->bounds().right(),
+ EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
w1->GetBoundsInScreen().right());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id());
DockedWindowLayoutManager* manager =
DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w2.get(), 100);
// Both windows should now be docked at the right edge.
- EXPECT_EQ(w2->GetRootWindow()->bounds().right(),
+ EXPECT_EQ(w2->GetRootWindow()->GetBoundsInScreen().right(),
w2->GetBoundsInScreen().right());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, w2->parent()->id());
// Dock width should be set to a wider window.
DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
// A window should be docked at the right edge.
- EXPECT_EQ(w1->GetRootWindow()->bounds().right(),
+ EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
w1->GetBoundsInScreen().right());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id());
DockedWindowLayoutManager* manager =
wm::WindowState* window_state = wm::GetWindowState(w1.get());
DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
// A window should be docked at the right edge.
- EXPECT_EQ(w1->GetRootWindow()->bounds().right(),
+ EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
w1->GetBoundsInScreen().right());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id());
DockedWindowLayoutManager* manager =
// Dock again.
DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, w1.get(), 20);
// A window should be docked at the right edge.
- EXPECT_EQ(w1->GetRootWindow()->bounds().right(),
+ EXPECT_EQ(w1->GetRootWindow()->GetBoundsInScreen().right(),
w1->GetBoundsInScreen().right());
EXPECT_EQ(internal::kShellWindowId_DockedContainer, w1->parent()->id());
EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
EXPECT_TRUE(window_state->IsSnapped());
}
+// Tests that a window is undocked if the window is maximized via a keyboard
+// accelerator during a drag.
+TEST_P(DockedWindowResizerTest, MaximizedDuringDrag) {
+ if (!SupportsHostWindowResize() || test_panels())
+ return;
+
+ scoped_ptr<aura::Window> window(CreateTestWindow(
+ gfx::Rect(0, 0, ideal_width(), 201)));
+ wm::WindowState* window_state = wm::GetWindowState(window.get());
+
+ // Dock the window to the right edge.
+ DragToVerticalPositionAndToEdge(DOCKED_EDGE_RIGHT, window.get(), 20);
+ EXPECT_EQ(window->GetRootWindow()->GetBoundsInScreen().right(),
+ window->GetBoundsInScreen().right());
+ EXPECT_EQ(internal::kShellWindowId_DockedContainer, window->parent()->id());
+ DockedWindowLayoutManager* manager =
+ static_cast<DockedWindowLayoutManager*>(
+ window->parent()->layout_manager());
+ EXPECT_EQ(DOCKED_ALIGNMENT_RIGHT, docked_alignment(manager));
+ EXPECT_EQ(window->bounds().width(), docked_width(manager));
+ EXPECT_TRUE(window_state->IsDocked());
+
+ // Maximize the window while in a real drag. In particular,
+ // ToplevelWindowEventHandler::ScopedWindowResizer::OnWindowShowTypeChanged()
+ // must be called in order for the maximized window's size to be correct.
+ delegate()->set_window_component(HTCAPTION);
+ aura::test::EventGenerator& generator = GetEventGenerator();
+ generator.MoveMouseTo(window->GetBoundsInScreen().origin());
+ generator.PressLeftButton();
+ generator.MoveMouseBy(10, 10);
+ window_state->Maximize();
+ generator.ReleaseLeftButton();
+
+ // |window| should get undocked.
+ EXPECT_EQ(internal::kShellWindowId_DefaultContainer, window->parent()->id());
+ EXPECT_EQ(0, docked_width(manager));
+ EXPECT_EQ(
+ ScreenUtil::GetMaximizedWindowBoundsInParent(window.get()).ToString(),
+ window->bounds().ToString());
+ EXPECT_TRUE(window_state->IsMaximized());
+}
+
// Tests run twice - on both panels and normal windows
INSTANTIATE_TEST_CASE_P(NormalOrPanel,
DockedWindowResizerTest,