Chromium Code Reviews| Index: ash/wm/dock/dock_window_resizer.cc |
| diff --git a/ash/wm/dock/dock_window_resizer.cc b/ash/wm/dock/dock_window_resizer.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..46a9561231ba6bb3e5e9715a53cc4572000db2c8 |
| --- /dev/null |
| +++ b/ash/wm/dock/dock_window_resizer.cc |
| @@ -0,0 +1,121 @@ |
| +// 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/dock/dock_window_resizer.h" |
| + |
| +#include "ash/display/display_controller.h" |
| +#include "ash/launcher/launcher.h" |
| +#include "ash/root_window_controller.h" |
| +#include "ash/screen_ash.h" |
| +#include "ash/shelf/shelf_types.h" |
| +#include "ash/shelf/shelf_widget.h" |
| +#include "ash/shell.h" |
| +#include "ash/shell_window_ids.h" |
| +#include "ash/wm/coordinate_conversion.h" |
| +#include "ash/wm/dock/dock_layout_manager.h" |
| +#include "ash/wm/property_util.h" |
| +#include "ash/wm/window_properties.h" |
| +#include "ash/wm/workspace_controller.h" |
| +#include "ui/aura/client/aura_constants.h" |
| +#include "ui/aura/env.h" |
| +#include "ui/aura/root_window.h" |
| +#include "ui/aura/window.h" |
| +#include "ui/aura/window_delegate.h" |
| +#include "ui/base/hit_test.h" |
| +#include "ui/base/ui_base_types.h" |
| +#include "ui/gfx/screen.h" |
| +#include "ui/views/widget/widget.h" |
| + |
| +namespace ash { |
| + |
| +DockWindowResizer::~DockWindowResizer() { |
| +} |
| + |
| +// static |
| +DockWindowResizer* |
| +DockWindowResizer::Create(WindowResizer* next_window_resizer, |
| + aura::Window* window, |
| + const gfx::Point& location, |
| + int window_component) { |
| + Details details(window, location, window_component); |
| + return details.is_resizable ? |
| + new DockWindowResizer(next_window_resizer, details) : NULL; |
| +} |
| + |
| +void DockWindowResizer::Drag(const gfx::Point& location, int event_flags) { |
| + last_mouse_location_ = location; |
| + wm::ConvertPointToScreen(GetTarget()->parent(), &last_mouse_location_); |
| + if (!did_move_or_resize_) { |
| + did_move_or_resize_ = true; |
| + StartedDragging(); |
| + } |
| + next_window_resizer_->Drag(location, event_flags); |
| +} |
| + |
| +void DockWindowResizer::CompleteDrag(int event_flags) { |
| + // The root window can change when dragging into a different screen. |
| + next_window_resizer_->CompleteDrag(event_flags); |
| + FinishDragging(); |
| +} |
| + |
| +void DockWindowResizer::RevertDrag() { |
| + next_window_resizer_->RevertDrag(); |
| + FinishDragging(); |
| +} |
| + |
| +aura::Window* DockWindowResizer::GetTarget() { |
| + return next_window_resizer_->GetTarget(); |
| +} |
| + |
| +DockWindowResizer::DockWindowResizer(WindowResizer* next_window_resizer, |
| + const Details& details) |
| + : details_(details), |
| + next_window_resizer_(next_window_resizer), |
| + dock_layout_(NULL), |
| + was_docked_(false), |
| + did_move_or_resize_(false) { |
| + DCHECK(details_.is_resizable); |
| + root_window_ = details.window->GetRootWindow(); |
| + aura::Window* dock_container = Shell::GetContainer( |
| + details.window->GetRootWindow(), |
| + internal::kShellWindowId_DockContainer); |
| + DCHECK(dock_container->id() == internal::kShellWindowId_DockContainer); |
| + dock_layout_ = static_cast<internal::DockLayoutManager*>( |
| + dock_container->layout_manager()); |
| +} |
| + |
| +void DockWindowResizer::StartedDragging() { |
| + // Tell the dock layout manager that we are dragging this window. |
| + was_docked_ = IsWindowDocked(GetTarget()); |
| + dock_layout_->StartDragging(GetTarget()); |
| +} |
| + |
| +void DockWindowResizer::FinishDragging() { |
| + if (!did_move_or_resize_) |
| + return; |
| + |
| + aura::Window* window = GetTarget(); |
| + if (was_docked_ && |
| + !IsWindowDocked(window) && |
| + window->parent()->id() == internal::kShellWindowId_DockContainer) { |
| + // Reparent the window back to workspace. |
| + // We need to be careful to give SetDefaultParentByRootWindow location in |
| + // the right root window (matching the logic in DragWindowResizer) based on |
| + // which root window a mouse pointer is in. We want to undock into the right |
| + // screen near the edge of a multiscreen setup (based on where the mouse is) |
| + gfx::Rect near_last_mouse_location(last_mouse_location_, gfx::Size()); |
| + // Reparenting will cause Relayout and possible dock shrinking. |
| + window->SetDefaultParentByRootWindow(root_window_, |
| + near_last_mouse_location); |
| + // A maximized workspace may be active so we may need to switch |
| + // to a parent workspace of the window being dragged out. |
| + internal::WorkspaceController* workspace_controller = |
| + GetRootWindowController( |
| + window->GetRootWindow())->workspace_controller(); |
| + workspace_controller->SetActiveWorkspaceByWindow(window); |
|
Jun Mukai
2013/06/10 20:40:57
This SetActiveworkspaceByWindow may not be necessa
varkha
2013/06/10 21:09:47
Thanks, It will probably be unnecessary once your
|
| + } |
| + dock_layout_->FinishDragging(); |
| +} |
| + |
| +} // namespace aura |