Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Unified Diff: ash/wm/workspace/workspace_window_resizer.cc

Issue 10834097: Allow the user to drag a window from one display to another (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ash/wm/workspace/workspace_window_resizer.cc
diff --git a/ash/wm/workspace/workspace_window_resizer.cc b/ash/wm/workspace/workspace_window_resizer.cc
index c4dc9a0ff753ce7b2d83215f7426e561021a8318..4b376bfa4a32776a6e7b7b436415ba12037479f1 100644
--- a/ash/wm/workspace/workspace_window_resizer.cc
+++ b/ash/wm/workspace/workspace_window_resizer.cc
@@ -41,6 +41,20 @@ bool ShouldSnapToEdge(int distance_from_edge, int grid_size) {
distance_from_edge > -grid_size * 2;
}
+bool HasSecondaryRootWindow() {
+ return Shell::GetAllRootWindows().size() > 1;
+}
+
+aura::RootWindow* GetAnotherRootWindow(aura::RootWindow* root_window) {
+ Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
+ if (root_windows.size() < 2)
+ return NULL; // an extended display is not connected.
+ DCHECK_EQ(2U, root_windows.size());
+ if (root_windows[0] == root_window)
+ return root_windows[1];
+ return root_windows[0];
+}
+
} // namespace
// static
@@ -70,14 +84,14 @@ void WorkspaceWindowResizer::Drag(const gfx::Point& location, int event_flags) {
std::pair<aura::RootWindow*, gfx::Point> actual_location =
wm::GetRootWindowRelativeToWindow(window()->parent(), location);
- // TODO(yusukes): Implement dragging a window from one display to another.
aura::RootWindow* current_root = actual_location.first;
- if (current_root != window()->GetRootWindow())
- return;
+ gfx::Point location_in_screen = actual_location.second;
+ wm::ConvertPointToScreen(current_root, &location_in_screen);
int grid_size = event_flags & ui::EF_CONTROL_DOWN ?
0 : ash::Shell::GetInstance()->GetGridSize();
- gfx::Rect bounds = CalculateBoundsForDrag(details_, location, grid_size);
+ gfx::Rect bounds = // in |window()->GetRootWindow()|'s coordinates.
+ CalculateBoundsForDrag(details_, location_in_screen, grid_size);
if (wm::IsWindowNormal(details_.window))
AdjustBoundsForMainWindow(&bounds, grid_size);
@@ -86,7 +100,21 @@ void WorkspaceWindowResizer::Drag(const gfx::Point& location, int event_flags) {
RestackWindows();
did_move_or_resize_ = true;
}
- UpdatePhantomWindow(location, bounds, grid_size);
+
+ const bool in_original_root = (window()->GetRootWindow() == current_root);
+ // Hide a phantom window for snapping if the cursor is in another root window.
+ if (in_original_root)
+ UpdatePhantomWindow(location, bounds, grid_size);
+ else
+ phantom_window_controller_.reset();
+
+ // Show a phantom window for dragging in another root window.
+ aura::RootWindow* another_root =
+ GetAnotherRootWindow(window()->GetRootWindow());
+ gfx::Rect bounds_in_screen =
+ ScreenAsh::ConvertRectToScreen(window()->GetRootWindow(), bounds);
+ UpdateDragPhantomWindow(another_root, bounds_in_screen);
+
if (!attached_windows_.empty())
LayoutAttachedWindows(bounds, grid_size);
if (bounds != details_.window->bounds())
@@ -95,6 +123,7 @@ void WorkspaceWindowResizer::Drag(const gfx::Point& location, int event_flags) {
}
void WorkspaceWindowResizer::CompleteDrag(int event_flags) {
+ drag_phantom_window_controller_.reset();
phantom_window_controller_.reset();
if (!did_move_or_resize_ || details_.window_component != HTCAPTION)
return;
@@ -140,6 +169,7 @@ void WorkspaceWindowResizer::CompleteDrag(int event_flags) {
}
void WorkspaceWindowResizer::RevertDrag() {
+ drag_phantom_window_controller_.reset();
phantom_window_controller_.reset();
if (!did_move_or_resize_)
@@ -312,17 +342,23 @@ void WorkspaceWindowResizer::CalculateAttachedSizes(
void WorkspaceWindowResizer::AdjustBoundsForMainWindow(
gfx::Rect* bounds, int grid_size) const {
- // Always keep kMinOnscreenHeight on the bottom.
+ // Always keep kMinOnscreenHeight on the bottom except when an extended
+ // display is available and a window is being dragged.
gfx::Rect work_area(
ScreenAsh::GetDisplayWorkAreaBoundsInParent(details_.window));
int max_y = AlignToGridRoundUp(work_area.bottom() - kMinOnscreenHeight,
grid_size);
- if (bounds->y() > max_y)
+ if ((details_.window_component != HTCAPTION || !HasSecondaryRootWindow()) &&
+ bounds->y() > max_y) {
bounds->set_y(max_y);
+ }
- // Don't allow dragging above the top of the display.
- if (bounds->y() <= work_area.y())
+ // Don't allow dragging above the top of the display except when an extended
+ // display is available and a window is being dragged.
+ if ((details_.window_component != HTCAPTION || !HasSecondaryRootWindow()) &&
+ bounds->y() <= work_area.y()) {
bounds->set_y(work_area.y());
+ }
if (grid_size >= 0 && details_.window_component == HTCAPTION)
SnapToWorkAreaEdges(work_area, bounds, grid_size);
@@ -391,6 +427,38 @@ int WorkspaceWindowResizer::PrimaryAxisCoordinate(int x, int y) const {
return 0;
}
+void WorkspaceWindowResizer::UpdateDragPhantomWindow(
+ aura::RootWindow* another_root,
+ const gfx::Rect& window_bounds_in_screen) {
+ if (!did_move_or_resize_ || details_.window_component != HTCAPTION ||
+ !ShouldAllowMouseWarp()) {
+ return;
+ }
+
+ if (!another_root) {
+ // An extended display is not available.
+ drag_phantom_window_controller_.reset();
+ return;
+ }
+
+ // It's available. Show a phantom window on the display if needed.
+ const gfx::Rect root_bounds_in_screen(another_root->GetBoundsInScreen());
+ const gfx::Rect phantom(
+ root_bounds_in_screen.Intersect(window_bounds_in_screen));
+
+ if (!phantom.IsEmpty()) {
+ if (!drag_phantom_window_controller_.get()) {
+ drag_phantom_window_controller_.reset(
+ new PhantomWindowController(window()));
+ drag_phantom_window_controller_->Show(phantom);
+ } else {
+ drag_phantom_window_controller_->SetBounds(phantom); // no animation
+ }
+ } else {
+ drag_phantom_window_controller_.reset();
+ }
+}
+
void WorkspaceWindowResizer::UpdatePhantomWindow(const gfx::Point& location,
const gfx::Rect& bounds,
int grid_size) {
« ash/wm/default_window_resizer.cc ('K') | « ash/wm/workspace/workspace_window_resizer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698