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 4b8c0aaf7e9366f91aa1fd1bf6f8d88f9429b0c9..d79604969009abb412fa689518224d9d096a14cd 100644 |
--- a/ash/wm/workspace/workspace_window_resizer.cc |
+++ b/ash/wm/workspace/workspace_window_resizer.cc |
@@ -10,6 +10,7 @@ |
#include <vector> |
#include "ash/ash_switches.h" |
+#include "ash/display/display_controller.h" |
#include "ash/root_window_controller.h" |
#include "ash/screen_ash.h" |
#include "ash/shell.h" |
@@ -335,6 +336,8 @@ class WindowSize { |
WorkspaceWindowResizer::~WorkspaceWindowResizer() { |
Shell* shell = Shell::GetInstance(); |
shell->cursor_manager()->UnlockCursor(); |
+ if (destroyed_) |
+ *destroyed_ = true; |
} |
// static |
@@ -384,20 +387,33 @@ void WorkspaceWindowResizer::Drag(const gfx::Point& location_in_parent, |
gfx::Point location_in_screen = location_in_parent; |
wm::ConvertPointToScreen(window()->parent(), &location_in_screen); |
- const bool in_original_root = |
- wm::GetRootWindowAt(location_in_screen) == window()->GetRootWindow(); |
+ |
+ aura::RootWindow* root = NULL; |
+ gfx::Display display = |
+ ScreenAsh::FindDisplayContainingPoint(location_in_screen); |
+ // Keep the snap phantom on screen when pointer gets off screen. |
flackr
2013/09/06 02:18:43
This comment sort of describes what we're doing wh
varkha
2013/09/09 15:38:42
Done.
|
+ if (display.is_valid()) { |
+ root = Shell::GetInstance()->display_controller()-> |
+ GetRootWindowForDisplayId(display.id()); |
+ } |
+ bool destroyed = false; |
flackr
2013/09/06 02:18:43
FYI, I'm not especially fond of this pattern, I pu
varkha
2013/09/09 15:38:42
Done.
|
+ destroyed_ = &destroyed; |
+ if (!attached_windows_.empty()) |
+ LayoutAttachedWindows(&bounds); |
flackr
2013/09/06 02:18:43
Presumably this cannot delete the resizer since yo
varkha
2013/09/09 15:38:42
Done.
|
+ if (bounds != window()->bounds()) |
+ window()->SetBounds(bounds); |
+ if (destroyed) |
+ return; |
+ destroyed_ = NULL; |
+ |
+ const bool in_original_root = !root || root == window()->GetRootWindow(); |
// Hide a phantom window for snapping if the cursor is in another root window. |
- if (in_original_root && wm::CanResizeWindow(window())) { |
+ if (in_original_root) { |
UpdateSnapPhantomWindow(location_in_parent, bounds); |
} else { |
snap_type_ = SNAP_NONE; |
snap_phantom_window_controller_.reset(); |
flackr
2013/09/06 02:18:43
Should snap_sizer_ be reset here too since we're n
varkha
2013/09/09 15:38:42
Done.
|
} |
- |
- if (!attached_windows_.empty()) |
- LayoutAttachedWindows(&bounds); |
- if (bounds != window()->bounds()) |
- window()->SetBounds(bounds); |
} |
void WorkspaceWindowResizer::CompleteDrag(int event_flags) { |
@@ -414,7 +430,7 @@ void WorkspaceWindowResizer::CompleteDrag(int event_flags) { |
if (wm::IsWindowNormal(window()) && |
(window()->type() != aura::client::WINDOW_TYPE_PANEL || |
!window()->GetProperty(kPanelAttachedKey)) && |
- (snap_type_ == SNAP_LEFT_EDGE || snap_type_ == SNAP_RIGHT_EDGE)) { |
+ (snap_type_ == SNAP_LEFT || snap_type_ == SNAP_RIGHT)) { |
if (!GetRestoreBoundsInScreen(window())) { |
gfx::Rect initial_bounds = ScreenAsh::ConvertRectToScreen( |
window()->parent(), details_.initial_bounds_in_parent); |
@@ -422,7 +438,11 @@ void WorkspaceWindowResizer::CompleteDrag(int event_flags) { |
initial_bounds : |
details_.restore_bounds); |
} |
- window()->SetBounds(snap_sizer_->target_bounds()); |
+ if (snap_sizer_ && wm::CanResizeWindow(window()) && |
flackr
2013/09/06 02:18:43
Is it possible that snap_sizer_ will not be instan
varkha
2013/09/09 15:38:42
Done.
|
+ !snap_sizer_->ShouldDockWindow() && |
+ !snap_sizer_->target_bounds().IsEmpty()) { |
+ window()->SetBounds(snap_sizer_->target_bounds()); |
+ } |
return; |
} |
} |
@@ -476,7 +496,8 @@ WorkspaceWindowResizer::WorkspaceWindowResizer( |
total_initial_size_(0), |
snap_type_(SNAP_NONE), |
num_mouse_moves_since_bounds_change_(0), |
- magnetism_window_(NULL) { |
+ magnetism_window_(NULL), |
+ destroyed_(NULL) { |
DCHECK(details_.is_resizable); |
Shell* shell = Shell::GetInstance(); |
@@ -503,6 +524,7 @@ WorkspaceWindowResizer::WorkspaceWindowResizer( |
total_initial_size_ += initial_size; |
total_available += std::max(min_size, initial_size) - min_size; |
} |
+ snap_type_ = GetSnapType(details_.initial_location_in_parent); |
} |
gfx::Rect WorkspaceWindowResizer::GetFinalBounds( |
@@ -855,32 +877,46 @@ void WorkspaceWindowResizer::UpdateSnapPhantomWindow(const gfx::Point& location, |
if (!did_move_or_resize_ || details_.window_component != HTCAPTION) |
return; |
- if (!wm::CanSnapWindow(window())) |
- return; |
- |
- if (window()->type() == aura::client::WINDOW_TYPE_PANEL && |
- window()->GetProperty(kPanelAttachedKey)) { |
- return; |
- } |
- |
SnapType last_type = snap_type_; |
snap_type_ = GetSnapType(location); |
if (snap_type_ == SNAP_NONE || snap_type_ != last_type) { |
snap_phantom_window_controller_.reset(); |
+ if (snap_type_ == SNAP_NONE && snap_type_ != last_type) { |
+ // Create and delete a SnapSizer to maintain docked state. |
+ snap_sizer_.reset(new SnapSizer( |
+ window(), |
+ details_.initial_location_in_parent, |
+ (last_type == SNAP_LEFT) ? |
+ SnapSizer::LEFT_EDGE : SnapSizer::RIGHT_EDGE, |
+ internal::SnapSizer::WORKSPACE_DRAG_INPUT)); |
+ } |
snap_sizer_.reset(); |
if (snap_type_ == SNAP_NONE) |
return; |
} |
+ SnapSizer::Edge edge = (snap_type_ == SNAP_LEFT) ? |
+ SnapSizer::LEFT_EDGE : SnapSizer::RIGHT_EDGE; |
+ |
if (!snap_sizer_) { |
- SnapSizer::Edge edge = (snap_type_ == SNAP_LEFT_EDGE) ? |
- SnapSizer::LEFT_EDGE : SnapSizer::RIGHT_EDGE; |
snap_sizer_.reset(new SnapSizer(window(), |
location, |
edge, |
- internal::SnapSizer::OTHER_INPUT)); |
+ internal::SnapSizer::WORKSPACE_DRAG_INPUT)); |
} else { |
snap_sizer_->Update(location); |
} |
+ |
+ // Update phantom window when it is used for side-maximizing. |
+ // In case of docking it will be called directly by the chained resizer. |
+ if (!wm::CanSnapWindow(window()) && !SnapSizer::CanDockWindow(window(), edge)) |
+ return; |
+ |
+ LOG(INFO) << "SNAP BOUNDS " << snap_sizer_->target_bounds().ToString(); |
+ |
+ if (snap_sizer_->target_bounds().IsEmpty()) { |
+ snap_phantom_window_controller_.reset(); |
+ return; |
+ } |
if (!snap_phantom_window_controller_) { |
snap_phantom_window_controller_.reset( |
new PhantomWindowController(window())); |
@@ -920,15 +956,15 @@ void WorkspaceWindowResizer::RestackWindows() { |
} |
} |
-WorkspaceWindowResizer::SnapType WorkspaceWindowResizer::GetSnapType( |
+SnapType WorkspaceWindowResizer::GetSnapType( |
const gfx::Point& location) const { |
// TODO: this likely only wants total display area, not the area of a single |
// display. |
- gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(window())); |
+ gfx::Rect area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window())); |
if (location.x() <= area.x()) |
- return SNAP_LEFT_EDGE; |
+ return SNAP_LEFT; |
if (location.x() >= area.right() - 1) |
- return SNAP_RIGHT_EDGE; |
+ return SNAP_RIGHT; |
return SNAP_NONE; |
} |