| 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..4b0e30e37a393f07e1f88ce89d503dcb495fbae8 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"
|
| @@ -25,6 +26,7 @@
|
| #include "ash/wm/workspace/phantom_window_controller.h"
|
| #include "ash/wm/workspace/snap_sizer.h"
|
| #include "base/command_line.h"
|
| +#include "base/memory/weak_ptr.h"
|
| #include "ui/aura/client/aura_constants.h"
|
| #include "ui/aura/client/screen_position_client.h"
|
| #include "ui/aura/client/window_types.h"
|
| @@ -378,26 +380,53 @@ void WorkspaceWindowResizer::Drag(const gfx::Point& location_in_parent,
|
| if (!details_.restore_bounds.IsEmpty())
|
| ClearRestoreBounds(window());
|
| RestackWindows();
|
| + DCHECK(!snap_sizer_);
|
| + if (snap_type_ == SNAP_LEFT || snap_type_ == SNAP_RIGHT) {
|
| + // Create SnapSizer if a window is snapped to maintain docked state.
|
| + snap_sizer_.reset(new SnapSizer(
|
| + window(),
|
| + details_.initial_location_in_parent,
|
| + (snap_type_ == SNAP_LEFT) ?
|
| + SnapSizer::LEFT_EDGE : SnapSizer::RIGHT_EDGE,
|
| + internal::SnapSizer::WORKSPACE_DRAG_INPUT));
|
| + }
|
| }
|
| did_move_or_resize_ = true;
|
| }
|
|
|
| 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);
|
| + // Track the last screen that the pointer was on to keep the snap phantom
|
| + // window there.
|
| + if (display.is_valid()) {
|
| + root = Shell::GetInstance()->display_controller()->
|
| + GetRootWindowForDisplayId(display.id());
|
| + }
|
| + if (!attached_windows_.empty())
|
| + LayoutAttachedWindows(&bounds);
|
| + if (bounds != window()->bounds()) {
|
| + // SetBounds needs to be called to update the layout which affects where the
|
| + // phantom window is drawn. Keep track if the window was destroyed during
|
| + // the drag and quit early if so.
|
| + base::WeakPtr<WorkspaceWindowResizer> resizer(
|
| + weak_ptr_factory_.GetWeakPtr());
|
| + window()->SetBounds(bounds);
|
| + if (!resizer)
|
| + return;
|
| + }
|
| + 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();
|
| + snap_sizer_.reset();
|
| }
|
| -
|
| - if (!attached_windows_.empty())
|
| - LayoutAttachedWindows(&bounds);
|
| - if (bounds != window()->bounds())
|
| - window()->SetBounds(bounds);
|
| }
|
|
|
| void WorkspaceWindowResizer::CompleteDrag(int event_flags) {
|
| @@ -414,7 +443,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 +451,12 @@ void WorkspaceWindowResizer::CompleteDrag(int event_flags) {
|
| initial_bounds :
|
| details_.restore_bounds);
|
| }
|
| - window()->SetBounds(snap_sizer_->target_bounds());
|
| + DCHECK(snap_sizer_);
|
| + if (wm::CanResizeWindow(window()) &&
|
| + !snap_sizer_->ShouldDockWindow() &&
|
| + !snap_sizer_->target_bounds().IsEmpty()) {
|
| + window()->SetBounds(snap_sizer_->target_bounds());
|
| + }
|
| return;
|
| }
|
| }
|
| @@ -474,9 +508,10 @@ WorkspaceWindowResizer::WorkspaceWindowResizer(
|
| did_move_or_resize_(false),
|
| total_min_(0),
|
| total_initial_size_(0),
|
| - snap_type_(SNAP_NONE),
|
| + snap_type_(GetSnapType(details_.initial_location_in_parent)),
|
| num_mouse_moves_since_bounds_change_(0),
|
| - magnetism_window_(NULL) {
|
| + magnetism_window_(NULL),
|
| + weak_ptr_factory_(this) {
|
| DCHECK(details_.is_resizable);
|
|
|
| Shell* shell = Shell::GetInstance();
|
| @@ -855,14 +890,6 @@ 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) {
|
| @@ -871,16 +898,27 @@ void WorkspaceWindowResizer::UpdateSnapPhantomWindow(const gfx::Point& location,
|
| 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;
|
| +
|
| + 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 +958,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;
|
| }
|
|
|
|
|