| Index: ash/wm/dock/docked_window_resizer.cc
|
| diff --git a/ash/wm/dock/docked_window_resizer.cc b/ash/wm/dock/docked_window_resizer.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2c72bb8fac4a323c99123d786bc320d0f934843e
|
| --- /dev/null
|
| +++ b/ash/wm/dock/docked_window_resizer.cc
|
| @@ -0,0 +1,121 @@
|
| +// Copyright (c) 2013 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/docked_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/docked_window_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 {
|
| +
|
| +DockedWindowResizer::~DockedWindowResizer() {
|
| +}
|
| +
|
| +// static
|
| +DockedWindowResizer*
|
| +DockedWindowResizer::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 DockedWindowResizer(next_window_resizer, details) : NULL;
|
| +}
|
| +
|
| +void DockedWindowResizer::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 DockedWindowResizer::CompleteDrag(int event_flags) {
|
| + // The root window can change when dragging into a different screen.
|
| + next_window_resizer_->CompleteDrag(event_flags);
|
| + FinishDragging();
|
| +}
|
| +
|
| +void DockedWindowResizer::RevertDrag() {
|
| + next_window_resizer_->RevertDrag();
|
| + FinishDragging();
|
| +}
|
| +
|
| +aura::Window* DockedWindowResizer::GetTarget() {
|
| + return next_window_resizer_->GetTarget();
|
| +}
|
| +
|
| +DockedWindowResizer::DockedWindowResizer(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::DockedWindowLayoutManager*>(
|
| + dock_container->layout_manager());
|
| +}
|
| +
|
| +void DockedWindowResizer::StartedDragging() {
|
| + // Tell the dock layout manager that we are dragging this window.
|
| + was_docked_ = IsWindowDocked(GetTarget());
|
| + dock_layout_->StartDragging(GetTarget());
|
| +}
|
| +
|
| +void DockedWindowResizer::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);
|
| + }
|
| + dock_layout_->FinishDragging();
|
| +}
|
| +
|
| +} // namespace aura
|
|
|