Commit c38f941e authored by mazda@chromium.org's avatar mazda@chromium.org

Extract the code of showing a dragging window on another display from PhantomWindowController.

PhantomWindowController shows two styles of window, STYLE_SHADOW and STYLE_DRAGGING.
Although STYLE_SHADOW is specific to workspace, STYLE_DRAGGING is not specific to
workspace. This CL separates this feature into two classes so that the
STYLE_DRAGGING part can be used from non-workspace specific code

- Extract the STYLE_DRAGGING part from PhantomWindowController into DragWindowController.
- Move the ownership of the copied window layer from WorkspaceWindowResizer to
  DragWindowController.

BUG=156519


Review URL: https://chromiumcodereview.appspot.com/11280283

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@171048 0039d316-1c4b-4281-b951-d872f2087c98
parent 793202cb
......@@ -299,6 +299,8 @@
'wm/default_window_resizer.h',
'wm/dialog_frame_view.cc',
'wm/dialog_frame_view.h',
'wm/drag_window_controller.cc',
'wm/drag_window_controller.h',
'wm/event_client_impl.cc',
'wm/event_client_impl.h',
'wm/event_rewriter_event_filter.cc',
......
......@@ -93,7 +93,7 @@ const int kShellWindowId_SettingBubbleContainer = 19;
// region selector for partial screenshots.
const int kShellWindowId_OverlayContainer = 20;
// ID of the window created by PhantomWindowController.
// ID of the window created by PhantomWindowController or DragWindowController.
const int kShellWindowId_PhantomWindow = 21;
// The topmost container, used for power off animation.
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/wm/drag_window_controller.h"
#include "ash/shell_window_ids.h"
#include "ash/wm/window_util.h"
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/window.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/views/corewm/shadow_types.h"
#include "ui/views/corewm/window_util.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
namespace ash {
namespace internal {
DragWindowController::DragWindowController(aura::Window* window)
: window_(window),
drag_widget_(NULL),
layer_(NULL) {
}
DragWindowController::~DragWindowController() {
Hide();
}
void DragWindowController::SetDestinationDisplay(
const gfx::Display& dst_display) {
dst_display_ = dst_display;
}
void DragWindowController::Show() {
if (!drag_widget_)
CreateDragWidget(window_->GetBoundsInScreen());
drag_widget_->Show();
}
void DragWindowController::SetBounds(const gfx::Rect& bounds) {
DCHECK(drag_widget_);
bounds_ = bounds;
SetBoundsInternal(bounds);
}
void DragWindowController::Hide() {
if (drag_widget_) {
drag_widget_->Close();
drag_widget_ = NULL;
}
if (layer_) {
views::corewm::DeepDeleteLayers(layer_);
layer_ = NULL;
}
}
void DragWindowController::SetOpacity(float opacity) {
DCHECK(drag_widget_);
ui::Layer* layer = drag_widget_->GetNativeWindow()->layer();
ui::ScopedLayerAnimationSettings scoped_setter(layer->GetAnimator());
layer->SetOpacity(opacity);
}
void DragWindowController::CreateDragWidget(const gfx::Rect& bounds) {
DCHECK(!drag_widget_);
drag_widget_ = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
params.transparent = true;
params.parent = window_->parent();
params.can_activate = false;
params.keep_on_top = true;
drag_widget_->set_focus_on_creation(false);
drag_widget_->Init(params);
drag_widget_->SetVisibilityChangedAnimationsEnabled(false);
drag_widget_->GetNativeWindow()->SetName("DragWindow");
drag_widget_->GetNativeWindow()->set_id(kShellWindowId_PhantomWindow);
// Show shadow for the dragging window.
SetShadowType(drag_widget_->GetNativeWindow(),
views::corewm::SHADOW_TYPE_RECTANGULAR);
SetBoundsInternal(bounds);
drag_widget_->StackAbove(window_);
RecreateWindowLayers();
aura::Window* window = drag_widget_->GetNativeWindow();
layer_->SetVisible(true);
window->layer()->Add(layer_);
window->layer()->StackAtTop(layer_);
// Show the widget after all the setups.
drag_widget_->Show();
// Fade the window in.
ui::Layer* widget_layer = drag_widget_->GetNativeWindow()->layer();
widget_layer->SetOpacity(0);
ui::ScopedLayerAnimationSettings scoped_setter(widget_layer->GetAnimator());
widget_layer->SetOpacity(1);
}
void DragWindowController::SetBoundsInternal(const gfx::Rect& bounds) {
aura::Window* window = drag_widget_->GetNativeWindow();
aura::client::ScreenPositionClient* screen_position_client =
aura::client::GetScreenPositionClient(window->GetRootWindow());
if (screen_position_client && dst_display_.is_valid())
screen_position_client->SetBounds(window, bounds, dst_display_);
else
drag_widget_->SetBounds(bounds);
}
void DragWindowController::RecreateWindowLayers() {
DCHECK(!layer_);
layer_ = views::corewm::RecreateWindowLayers(window_, true);
layer_->set_delegate(window_->layer()->delegate());
// Place the layer at (0, 0) of the DragWindowController's window.
gfx::Rect layer_bounds = layer_->bounds();
layer_bounds.set_origin(gfx::Point(0, 0));
layer_->SetBounds(layer_bounds);
layer_->SetVisible(false);
// Detach it from the current container.
layer_->parent()->Remove(layer_);
}
} // namespace internal
} // namespace ash
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_WM_DRAG_WINDOW_CONTROLLER_H_
#define ASH_WM_DRAG_WINDOW_CONTROLLER_H_
#include "ash/ash_export.h"
#include "base/basictypes.h"
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "ui/gfx/display.h"
#include "ui/gfx/rect.h"
namespace aura {
class Window;
}
namespace ui {
class Layer;
}
namespace views {
class Widget;
}
namespace ash {
namespace internal {
// DragWindowController is responsible for showing a semi-transparent window
// while dragging a window across displays.
class ASH_EXPORT DragWindowController {
public:
explicit DragWindowController(aura::Window* window);
virtual ~DragWindowController();
// Sets the display where the window is placed after the window is dropped.
void SetDestinationDisplay(const gfx::Display& dst_display);
// Shows the drag window at the specified location (coordinates of the
// parent). If |layer| is non-NULL, it is shown on top of the drag window.
// |layer| is owned by the caller.
// This does not immediately show the window.
void Show();
// Hides the drag window.
void Hide();
// This is used to set bounds for the drag window immediately. This should
// be called only when the drag window is already visible.
void SetBounds(const gfx::Rect& bounds);
// Sets the opacity of the drag window.
void SetOpacity(float opacity);
private:
FRIEND_TEST_ALL_PREFIXES(WorkspaceWindowResizerTest, DragWindowController);
// Creates and shows the |drag_widget_| at |bounds|.
// |layer| is shown on top of the drag window if it is non-NULL.
// |layer| is not owned by this object.
void CreateDragWidget(const gfx::Rect& bounds);
// Sets bounds of the drag window. The window is shown on |dst_display_|
// if its id() is valid. Otherwise, a display nearest to |bounds| is chosen.
void SetBoundsInternal(const gfx::Rect& bounds);
// Recreates a fresh layer for |window_| and all its child windows.
void RecreateWindowLayers();
// Window the drag window is placed beneath.
aura::Window* window_;
// The display where the drag is placed. When dst_display_.id() is
// kInvalidDisplayID (i.e. the default), a display nearest to the current
// |bounds_| is automatically used.
gfx::Display dst_display_;
// Initially the bounds of |window_|. Each time Show() is invoked
// |start_bounds_| is then reset to the bounds of |drag_widget_| and
// |bounds_| is set to the value passed into Show(). The animation animates
// between these two values.
gfx::Rect bounds_;
views::Widget* drag_widget_;
// The copy of window_->layer() and its children. This object is the owner of
// the layer.
ui::Layer* layer_;
DISALLOW_COPY_AND_ASSIGN(DragWindowController);
};
} // namespace internal
} // namespace ash
#endif // ASH_WM_DRAG_WINDOW_CONTROLLER_H_
......@@ -73,7 +73,7 @@ SystemGestureStatus SystemPinchHandler::ProcessGestureEvent(
gfx::Rect bounds =
GetPhantomWindowScreenBounds(target_, event.location());
if (phantom_state_ != PHANTOM_WINDOW_NORMAL || phantom_.IsShowing())
phantom_.Show(bounds, NULL);
phantom_.Show(bounds);
break;
}
......
......@@ -389,7 +389,7 @@ void FrameMaximizeButton::UpdateSnap(const gfx::Point& location,
snap_sizer_->Update(LocationForSnapSizer(location));
phantom_window_->Show(ScreenAsh::ConvertRectToScreen(
frame_->GetWidget()->GetNativeView()->parent(),
snap_sizer_->target_bounds()), NULL);
snap_sizer_->target_bounds()));
}
return;
}
......@@ -425,7 +425,7 @@ void FrameMaximizeButton::UpdateSnap(const gfx::Point& location,
maximizer_->SetSnapType(snap_type_);
}
phantom_window_->Show(
ScreenBoundsForType(snap_type_, *snap_sizer_.get()), NULL);
ScreenBoundsForType(snap_type_, *snap_sizer_.get()));
}
SnapType FrameMaximizeButton::SnapTypeForLocation(
......
......@@ -8,19 +8,12 @@
#include "ash/shell_window_ids.h"
#include "ash/wm/coordinate_conversion.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
#include "ui/aura/window_delegate.h"
#include "ui/aura/window_observer.h"
#include "ui/base/animation/slide_animation.h"
#include "ui/base/animation/tween.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/screen.h"
#include "ui/gfx/skia_util.h"
#include "ui/views/corewm/shadow_types.h"
#include "ui/views/painter.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
......@@ -84,20 +77,14 @@ class EdgePainter : public views::Painter {
PhantomWindowController::PhantomWindowController(aura::Window* window)
: window_(window),
phantom_below_window_(NULL),
phantom_widget_(NULL),
style_(STYLE_SHADOW) {
phantom_widget_(NULL) {
}
PhantomWindowController::~PhantomWindowController() {
Hide();
}
void PhantomWindowController::SetDestinationDisplay(
const gfx::Display& dst_display) {
dst_display_ = dst_display;
}
void PhantomWindowController::Show(const gfx::Rect& bounds, ui::Layer* layer) {
void PhantomWindowController::Show(const gfx::Rect& bounds) {
if (bounds == bounds_)
return;
bounds_ = bounds;
......@@ -105,7 +92,7 @@ void PhantomWindowController::Show(const gfx::Rect& bounds, ui::Layer* layer) {
// Show the phantom at the bounds of the window. We'll animate to the target
// bounds.
start_bounds_ = window_->GetBoundsInScreen();
CreatePhantomWidget(start_bounds_, layer);
CreatePhantomWidget(start_bounds_);
} else {
start_bounds_ = phantom_widget_->GetWindowBoundsInScreen();
}
......@@ -115,13 +102,6 @@ void PhantomWindowController::Show(const gfx::Rect& bounds, ui::Layer* layer) {
animation_->Show();
}
void PhantomWindowController::SetBounds(const gfx::Rect& bounds) {
DCHECK(IsShowing());
animation_.reset();
bounds_ = bounds;
SetBoundsInternal(bounds);
}
void PhantomWindowController::Hide() {
if (phantom_widget_)
phantom_widget_->Close();
......@@ -132,31 +112,13 @@ bool PhantomWindowController::IsShowing() const {
return phantom_widget_ != NULL;
}
void PhantomWindowController::set_style(Style style) {
// Cannot change |style_| after the widget is initialized.
DCHECK(!phantom_widget_);
style_ = style;
}
void PhantomWindowController::SetOpacity(float opacity) {
DCHECK(phantom_widget_);
ui::Layer* layer = phantom_widget_->GetNativeWindow()->layer();
ui::ScopedLayerAnimationSettings scoped_setter(layer->GetAnimator());
layer->SetOpacity(opacity);
}
float PhantomWindowController::GetOpacity() const {
DCHECK(phantom_widget_);
return phantom_widget_->GetNativeWindow()->layer()->opacity();
}
void PhantomWindowController::AnimationProgressed(
const ui::Animation* animation) {
SetBoundsInternal(animation->CurrentValueBetween(start_bounds_, bounds_));
phantom_widget_->SetBounds(
animation->CurrentValueBetween(start_bounds_, bounds_));
}
void PhantomWindowController::CreatePhantomWidget(const gfx::Rect& bounds,
ui::Layer* layer) {
void PhantomWindowController::CreatePhantomWidget(const gfx::Rect& bounds) {
DCHECK(!phantom_widget_);
phantom_widget_ = new views::Widget;
views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
......@@ -173,29 +135,16 @@ void PhantomWindowController::CreatePhantomWidget(const gfx::Rect& bounds,
phantom_widget_->SetVisibilityChangedAnimationsEnabled(false);
phantom_widget_->GetNativeWindow()->SetName("PhantomWindow");
phantom_widget_->GetNativeWindow()->set_id(kShellWindowId_PhantomWindow);
if (style_ == STYLE_SHADOW) {
views::View* content_view = new views::View;
content_view->set_background(
views::Background::CreateBackgroundPainter(true, new EdgePainter));
phantom_widget_->SetContentsView(content_view);
} else if (style_ == STYLE_DRAGGING) {
// Show shadow for the dragging window.
SetShadowType(phantom_widget_->GetNativeWindow(),
views::corewm::SHADOW_TYPE_RECTANGULAR);
}
SetBoundsInternal(bounds);
phantom_widget_->SetBounds(bounds);
if (phantom_below_window_)
phantom_widget_->StackBelow(phantom_below_window_);
else
phantom_widget_->StackAbove(window_);
if (layer) {
aura::Window* window = phantom_widget_->GetNativeWindow();
layer->SetVisible(true);
window->layer()->Add(layer);
window->layer()->StackAtTop(layer);
}
// Show the widget after all the setups.
phantom_widget_->Show();
......@@ -206,17 +155,5 @@ void PhantomWindowController::CreatePhantomWidget(const gfx::Rect& bounds,
widget_layer->SetOpacity(1);
}
void PhantomWindowController::SetBoundsInternal(const gfx::Rect& bounds) {
aura::Window* window = phantom_widget_->GetNativeWindow();
aura::client::ScreenPositionClient* screen_position_client =
aura::client::GetScreenPositionClient(window->GetRootWindow());
if (screen_position_client &&
dst_display_.id() != gfx::Display::kInvalidDisplayID) {
screen_position_client->SetBounds(window, bounds, dst_display_);
} else {
phantom_widget_->SetBounds(bounds);
}
}
} // namespace internal
} // namespace ash
......@@ -10,16 +10,13 @@
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "ui/base/animation/animation_delegate.h"
#include "ui/gfx/display.h"
#include "ui/gfx/rect.h"
namespace aura {
class RootWindow;
class Window;
}
namespace ui {
class Layer;
class SlideAnimation;
}
......@@ -34,17 +31,9 @@ namespace internal {
// of a window. It's used used during dragging a window to show a snap location.
class ASH_EXPORT PhantomWindowController : public ui::AnimationDelegate {
public:
enum Style {
STYLE_SHADOW, // for window snapping.
STYLE_DRAGGING, // for window dragging.
};
explicit PhantomWindowController(aura::Window* window);
virtual ~PhantomWindowController();
// Sets the display where the phantom is placed.
void SetDestinationDisplay(const gfx::Display& dst_display);
// Bounds last passed to Show().
const gfx::Rect& bounds() const { return bounds_; }
......@@ -52,11 +41,7 @@ class ASH_EXPORT PhantomWindowController : public ui::AnimationDelegate {
// parent). If |layer| is non-NULL, it is shown on top of the phantom window.
// |layer| is owned by the caller.
// This does not immediately show the window.
void Show(const gfx::Rect& bounds, ui::Layer* layer);
// This is used to set bounds for the phantom window immediately. This should
// be called only when the phantom window is already visible.
void SetBounds(const gfx::Rect& bounds);
void Show(const gfx::Rect& bounds);
// Hides the phantom.
void Hide();
......@@ -70,14 +55,6 @@ class ASH_EXPORT PhantomWindowController : public ui::AnimationDelegate {
phantom_below_window_ = phantom_below_window;
}
// Sets/gets the style of the phantom window.
void set_style(Style style);
Style style() const { return style_; }
// Sets/gets the opacity of the phantom window.
void SetOpacity(float opacity);
float GetOpacity() const;
// ui::AnimationDelegate overrides:
virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE;
......@@ -87,20 +64,11 @@ class ASH_EXPORT PhantomWindowController : public ui::AnimationDelegate {
// Creates and shows the |phantom_widget_| at |bounds|.
// |layer| is shown on top of the phantom window if it is non-NULL.
// |layer| is not owned by this object.
void CreatePhantomWidget(const gfx::Rect& bounds, ui::Layer* layer);
// Sets bounds of the phantom window. The window is shown on |dst_display_|
// if its id() is valid. Otherwise, a display nearest to |bounds| is chosen.
void SetBoundsInternal(const gfx::Rect& bounds);
void CreatePhantomWidget(const gfx::Rect& bounds);
// Window the phantom is placed beneath.
aura::Window* window_;
// The display where the phantom is placed. When dst_display_.id() is
// kInvalidDisplayID (i.e. the default), a display nearest to the current
// |bounds_| is automatically used.
gfx::Display dst_display_;
// If set, the phantom window should get stacked below this window.
aura::Window* phantom_below_window_;
......@@ -116,9 +84,6 @@ class ASH_EXPORT PhantomWindowController : public ui::AnimationDelegate {
// Used to transition the bounds.
scoped_ptr<ui::SlideAnimation> animation_;
// The style of the phantom window.
Style style_;
DISALLOW_COPY_AND_ASSIGN(PhantomWindowController);
};
......
......@@ -17,6 +17,7 @@
#include "ash/wm/coordinate_conversion.h"
#include "ash/wm/cursor_manager.h"
#include "ash/wm/default_window_resizer.h"
#include "ash/wm/drag_window_controller.h"
#include "ash/wm/property_util.h"
#include "ash/wm/window_util.h"
#include "ash/wm/workspace/phantom_window_controller.h"
......@@ -29,7 +30,6 @@
#include "ui/compositor/layer.h"
#include "ui/gfx/screen.h"
#include "ui/gfx/transform.h"
#include "ui/views/corewm/window_util.h"
namespace ash {
......@@ -312,14 +312,6 @@ WorkspaceWindowResizer::~WorkspaceWindowResizer() {
shell->mouse_cursor_filter()->HideSharedEdgeIndicator();
shell->cursor_manager()->UnlockCursor();
// Delete phantom controllers first so that they will never see the deleted
// |layer_|.
snap_phantom_window_controller_.reset();
drag_phantom_window_controller_.reset();
if (layer_)
views::corewm::DeepDeleteLayers(layer_);
if (destroyed_)
*destroyed_ = true;
}
......@@ -380,16 +372,16 @@ void WorkspaceWindowResizer::Drag(const gfx::Point& location_in_parent,
}
// Show a phantom window for dragging in another root window.
if (HasSecondaryRootWindow())
UpdateDragPhantomWindow(bounds, in_original_root);
UpdateDragWindow(bounds, in_original_root);
else
drag_phantom_window_controller_.reset();
drag_window_controller_.reset();
}
void WorkspaceWindowResizer::CompleteDrag(int event_flags) {
wm::SetUserHasChangedWindowPositionOrSize(details_.window, true);
window()->layer()->SetOpacity(details_.initial_opacity);
drag_phantom_window_controller_.reset();
drag_window_controller_.reset();
snap_phantom_window_controller_.reset();
if (!did_move_or_resize_ || details_.window_component != HTCAPTION)
return;
......@@ -431,7 +423,7 @@ void WorkspaceWindowResizer::CompleteDrag(int event_flags) {
void WorkspaceWindowResizer::RevertDrag() {
window()->layer()->SetOpacity(details_.initial_opacity);
drag_phantom_window_controller_.reset();
drag_window_controller_.reset();
snap_phantom_window_controller_.reset();
Shell::GetInstance()->mouse_cursor_filter()->HideSharedEdgeIndicator();
......@@ -477,7 +469,6 @@ WorkspaceWindowResizer::WorkspaceWindowResizer(
total_initial_size_(0),
snap_type_(SNAP_NONE),
num_mouse_moves_since_bounds_change_(0),
layer_(NULL),
destroyed_(NULL),
magnetism_window_(NULL) {
DCHECK(details_.is_resizable);
......@@ -827,7 +818,7 @@ int WorkspaceWindowResizer::PrimaryAxisCoordinate(int x, int y) const {
return 0;
}
void WorkspaceWindowResizer::UpdateDragPhantomWindow(const gfx::Rect& bounds,
void WorkspaceWindowResizer::UpdateDragWindow(const gfx::Rect& bounds,
bool in_original_root) {
if (!did_move_or_resize_ || details_.window_component != HTCAPTION ||
!ShouldAllowMouseWarp()) {
......@@ -852,26 +843,22 @@ void WorkspaceWindowResizer::UpdateDragPhantomWindow(const gfx::Rect& bounds,
in_original_root ? 1 : (kMaxOpacity * (1 - fraction_in_another_window));
if (fraction_in_another_window > 0) {
if (!drag_phantom_window_controller_.get()) {
drag_phantom_window_controller_.reset(
new PhantomWindowController(window()));
drag_phantom_window_controller_->set_style(
PhantomWindowController::STYLE_DRAGGING);
if (!drag_window_controller_.get()) {
drag_window_controller_.reset(
new DragWindowController(window()));
// Always show the drag phantom on the |another_root| window.
drag_phantom_window_controller_->SetDestinationDisplay(
drag_window_controller_->SetDestinationDisplay(
Shell::GetScreen()->GetDisplayMatching(
another_root->GetBoundsInScreen()));
if (!layer_)
RecreateWindowLayers();
drag_phantom_window_controller_->Show(bounds_in_screen, layer_);
drag_window_controller_->Show();
} else {
// No animation.
drag_phantom_window_controller_->SetBounds(bounds_in_screen);
drag_window_controller_->SetBounds(bounds_in_screen);
}
drag_phantom_window_controller_->SetOpacity(phantom_opacity);
drag_window_controller_->SetOpacity(phantom_opacity);
window()->layer()->SetOpacity(window_opacity);
} else {
drag_phantom_window_controller_.reset();
drag_window_controller_.reset();
window()->layer()->SetOpacity(1.0f);
}
}
......@@ -907,7 +894,7 @@ void WorkspaceWindowResizer::UpdateSnapPhantomWindow(const gfx::Point& location,
new PhantomWindowController(window()));
}
snap_phantom_window_controller_->Show(ScreenAsh::ConvertRectToScreen(
window()->parent(), snap_sizer_->target_bounds()), NULL);
window()->parent(), snap_sizer_->target_bounds()));
}
void WorkspaceWindowResizer::RestackWindows() {
......@@ -959,18 +946,5 @@ bool WorkspaceWindowResizer::ShouldAllowMouseWarp() const {
(window()->type() == aura::client::WINDOW_TYPE_NORMAL);
}
void WorkspaceWindowResizer::RecreateWindowLayers() {
DCHECK(!layer_);
layer_ = views::corewm::RecreateWindowLayers(window(), true);
layer_->set_delegate(window()->layer()->delegate());
// Place the layer at (0, 0) of the PhantomWindowController's window.
gfx::Rect layer_bounds = layer_->bounds();
layer_bounds.set_origin(gfx::Point(0, 0));
layer_->SetBounds(layer_bounds);
layer_->SetVisible(false);
// Detach it from the current container.
layer_->parent()->Remove(layer_);
}
} // namespace internal
} // namespace ash
......@@ -25,6 +25,7 @@ class Layer;
namespace ash {
namespace internal {
class DragWindowController;
class PhantomWindowController;
class SnapSizer;
class WindowSize;
......@@ -76,7 +77,7 @@ class ASH_EXPORT WorkspaceWindowResizer : public WindowResizer {
const std::vector<aura::Window*>& attached_windows);
private:
FRIEND_TEST_ALL_PREFIXES(WorkspaceWindowResizerTest, PhantomStyle);
FRIEND_TEST_ALL_PREFIXES(WorkspaceWindowResizerTest, DragWindowController);
FRIEND_TEST_ALL_PREFIXES(WorkspaceWindowResizerTest, CancelSnapPhantom);
FRIEND_TEST_ALL_PREFIXES(WorkspaceWindowResizerTest, PhantomSnapMaxSize);
......@@ -168,7 +169,7 @@ class ASH_EXPORT WorkspaceWindowResizer : public WindowResizer {
// Updates the bounds of the phantom window for window dragging. Set true on
// |in_original_root| if the pointer is still in |window()->GetRootWindow()|.
void UpdateDragPhantomWindow(const gfx::Rect& bounds, bool in_original_root);
void UpdateDragWindow(const gfx::Rect& bounds, bool in_original_root);
// Restacks the windows z-order position so that one of the windows is at the
// top of the z-order, and the rest directly underneath it.
......@@ -181,9 +182,6 @@ class ASH_EXPORT WorkspaceWindowResizer : public WindowResizer {
// Returns true if we should allow the mouse pointer to warp.
bool ShouldAllowMouseWarp() const;
// Recreates a fresh layer for window() and all its child windows.
void RecreateWindowLayers();
aura::Window* window() const { return details_.window; }
const Details details_;
......@@ -208,7 +206,7 @@ class ASH_EXPORT WorkspaceWindowResizer : public WindowResizer {
scoped_ptr<PhantomWindowController> snap_phantom_window_controller_;
// Shows a semi-transparent image of the window being dragged.
scoped_ptr<PhantomWindowController> drag_phantom_window_controller_;
scoped_ptr<DragWindowController> drag_window_controller_;
// Used to determine the target position of a snap.
scoped_ptr<SnapSizer> snap_sizer_;
......@@ -224,10 +222,6 @@ class ASH_EXPORT WorkspaceWindowResizer : public WindowResizer {
// The mouse location passed to Drag().
gfx::Point last_mouse_location_;
// The copy of window()->layer() and its children. This object is the owner of
// the layer.
ui::Layer* layer_;
// If non-NULL the destructor sets this to true. Used to determine if this has
// been deleted.
bool* destroyed_;
......
......@@ -13,12 +13,13 @@
#include "ash/test/ash_test_base.h"
#include "ash/test/cursor_manager_test_api.h"
#include "ash/wm/cursor_manager.h"
#include "ash/wm/drag_window_controller.h"
#include "ash/wm/property_util.h"
#include "ash/wm/shelf_layout_manager.h"
#include "ash/wm/window_util.h"
#include "ash/wm/workspace_controller.h"
#include "ash/wm/workspace/snap_sizer.h"
#include "ash/wm/workspace/phantom_window_controller.h"
#include "ash/wm/workspace/snap_sizer.h"
#include "ash/wm/workspace_controller.h"
#include "base/string_number_conversions.h"
#include "base/stringprintf.h"
#include "ui/aura/client/aura_constants.h"
......@@ -607,8 +608,8 @@ TEST_F(WorkspaceWindowResizerTest,
}
}
// Verifies the style of the drag phantom window is correct.
TEST_F(WorkspaceWindowResizerTest, PhantomStyle) {
// Verifies the drag window controller is instanciated appropriately.
TEST_F(WorkspaceWindowResizerTest, DragWindowController) {
UpdateDisplay("800x600,800x600");
Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
ASSERT_EQ(2U, root_windows.size());
......@@ -622,41 +623,42 @@ TEST_F(WorkspaceWindowResizerTest, PhantomStyle) {
window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
ASSERT_TRUE(resizer.get());
EXPECT_FALSE(resizer->snap_phantom_window_controller_.get());
EXPECT_FALSE(resizer->drag_phantom_window_controller_.get());
EXPECT_FALSE(resizer->drag_window_controller_.get());
// The pointer is inside the primary root. Both phantoms should be NULL.
resizer->Drag(CalculateDragPoint(*resizer, 10, 10), 0);
EXPECT_FALSE(resizer->snap_phantom_window_controller_.get());
EXPECT_FALSE(resizer->drag_phantom_window_controller_.get());
EXPECT_FALSE(resizer->drag_window_controller_.get());
// The window spans both root windows.
resizer->Drag(CalculateDragPoint(*resizer, 798, 10), 0);
EXPECT_FALSE(resizer->snap_phantom_window_controller_.get());
PhantomWindowController* controller =
resizer->drag_phantom_window_controller_.get();
DragWindowController* controller =
resizer->drag_window_controller_.get();
ASSERT_TRUE(controller);
EXPECT_EQ(PhantomWindowController::STYLE_DRAGGING, controller->style());
ASSERT_TRUE(controller->drag_widget_);
ui::Layer* drag_layer =
controller->drag_widget_->GetNativeWindow()->layer();
ASSERT_TRUE(drag_layer);
// Check if |resizer->layer_| is properly set to the phantom widget.
const std::vector<ui::Layer*>& layers =
controller->phantom_widget_->GetNativeWindow()->layer()->children();
const std::vector<ui::Layer*>& layers = drag_layer->children();
EXPECT_FALSE(layers.empty());
EXPECT_EQ(resizer->layer_, layers.back());
EXPECT_EQ(controller->layer_, layers.back());
// |window_| should be opaque since the pointer is still on the primary
// root window. The phantom should be semi-transparent.
EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity());
EXPECT_GT(1.0f, controller->GetOpacity());
EXPECT_GT(1.0f, drag_layer->opacity());
// Enter the pointer to the secondary display.
resizer->Drag(CalculateDragPoint(*resizer, 800, 10), 0);
EXPECT_FALSE(resizer->snap_phantom_window_controller_.get());
controller = resizer->drag_phantom_window_controller_.get();
controller = resizer->drag_window_controller_.get();
ASSERT_TRUE(controller);
EXPECT_EQ(PhantomWindowController::STYLE_DRAGGING, controller->style());
// |window_| should be transparent, and the phantom should be opaque.
EXPECT_GT(1.0f, window_->layer()->opacity());
EXPECT_FLOAT_EQ(1.0f, controller->GetOpacity());
EXPECT_FLOAT_EQ(1.0f, drag_layer->opacity());
resizer->CompleteDrag(0);
EXPECT_EQ(root_windows[1], window_->GetRootWindow());
......@@ -673,7 +675,7 @@ TEST_F(WorkspaceWindowResizerTest, PhantomStyle) {
window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
ASSERT_TRUE(resizer.get());
EXPECT_FALSE(resizer->snap_phantom_window_controller_.get());
EXPECT_FALSE(resizer->drag_phantom_window_controller_.get());
EXPECT_FALSE(resizer->drag_window_controller_.get());
resizer->Drag(CalculateDragPoint(*resizer, 0, 610), 0);
resizer->RevertDrag();
......@@ -697,7 +699,7 @@ TEST_F(WorkspaceWindowResizerTest, CancelSnapPhantom) {
window_.get(), gfx::Point(), HTCAPTION, empty_windows()));
ASSERT_TRUE(resizer.get());
EXPECT_FALSE(resizer->snap_phantom_window_controller_.get());
EXPECT_FALSE(resizer->drag_phantom_window_controller_.get());
EXPECT_FALSE(resizer->drag_window_controller_.get());
EXPECT_EQ(WorkspaceWindowResizer::SNAP_NONE, resizer->snap_type_);
// The pointer is on the edge but not shared. Both controllers should be
......@@ -705,10 +707,9 @@ TEST_F(WorkspaceWindowResizerTest, CancelSnapPhantom) {
resizer->Drag(CalculateDragPoint(*resizer, 799, 0), 0);
EXPECT_TRUE(resizer->snap_phantom_window_controller_.get());
EXPECT_EQ(WorkspaceWindowResizer::SNAP_RIGHT_EDGE, resizer->snap_type_);
PhantomWindowController* controller =
resizer->drag_phantom_window_controller_.get();
DragWindowController* controller =
resizer->drag_window_controller_.get();
ASSERT_TRUE(controller);
EXPECT_EQ(PhantomWindowController::STYLE_DRAGGING, controller->style());
// Move the cursor across the edge. Now the snap phantom controller
// should be canceled.
......@@ -716,9 +717,8 @@ TEST_F(WorkspaceWindowResizerTest, CancelSnapPhantom) {
EXPECT_FALSE(resizer->snap_phantom_window_controller_.get());
EXPECT_EQ(WorkspaceWindowResizer::SNAP_NONE, resizer->snap_type_);
controller =
resizer->drag_phantom_window_controller_.get();
resizer->drag_window_controller_.get();
ASSERT_TRUE(controller);
EXPECT_EQ(PhantomWindowController::STYLE_DRAGGING, controller->style());
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment