| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/wm/workspace/workspace_window_resizer.h" | 5 #include "ash/wm/workspace/workspace_window_resizer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 window, point_in_parent, window_component, source); | 88 window, point_in_parent, window_component, source); |
| 89 } | 89 } |
| 90 if (window_resizer) { | 90 if (window_resizer) { |
| 91 window_resizer = internal::DragWindowResizer::Create( | 91 window_resizer = internal::DragWindowResizer::Create( |
| 92 window_resizer, window, point_in_parent, window_component, source); | 92 window_resizer, window, point_in_parent, window_component, source); |
| 93 } | 93 } |
| 94 if (window_resizer && window->type() == aura::client::WINDOW_TYPE_PANEL) { | 94 if (window_resizer && window->type() == aura::client::WINDOW_TYPE_PANEL) { |
| 95 window_resizer = PanelWindowResizer::Create( | 95 window_resizer = PanelWindowResizer::Create( |
| 96 window_resizer, window, point_in_parent, window_component, source); | 96 window_resizer, window, point_in_parent, window_component, source); |
| 97 } | 97 } |
| 98 if (CommandLine::ForCurrentProcess()->HasSwitch( | 98 if (switches::UseDockedWindows() && |
| 99 switches::kAshEnableDockedWindows) && | |
| 100 window_resizer && window->parent() && | 99 window_resizer && window->parent() && |
| 101 !window->transient_parent() && | 100 !window->transient_parent() && |
| 102 (window->parent()->id() == internal::kShellWindowId_DefaultContainer || | 101 (window->parent()->id() == internal::kShellWindowId_DefaultContainer || |
| 103 window->parent()->id() == internal::kShellWindowId_DockedContainer || | 102 window->parent()->id() == internal::kShellWindowId_DockedContainer || |
| 104 window->parent()->id() == internal::kShellWindowId_PanelContainer)) { | 103 window->parent()->id() == internal::kShellWindowId_PanelContainer)) { |
| 105 window_resizer = internal::DockedWindowResizer::Create( | 104 window_resizer = internal::DockedWindowResizer::Create( |
| 106 window_resizer, window, point_in_parent, window_component, source); | 105 window_resizer, window, point_in_parent, window_component, source); |
| 107 } | 106 } |
| 108 window_state->set_window_resizer_(window_resizer); | 107 window_state->set_window_resizer_(window_resizer); |
| 109 return make_scoped_ptr<WindowResizer>(window_resizer); | 108 return make_scoped_ptr<WindowResizer>(window_resizer); |
| 110 } | 109 } |
| 111 | 110 |
| 112 namespace internal { | 111 namespace internal { |
| 113 | 112 |
| 114 namespace { | 113 namespace { |
| 115 | 114 |
| 116 // Snapping distance used instead of WorkspaceWindowResizer::kScreenEdgeInset | 115 // Snapping distance used instead of WorkspaceWindowResizer::kScreenEdgeInset |
| 117 // when resizing a window using touchscreen. | 116 // when resizing a window using touchscreen. |
| 118 const int kScreenEdgeInsetForTouchResize = 32; | 117 const int kScreenEdgeInsetForTouchResize = 32; |
| 119 | 118 |
| 120 // Returns true if the window should stick to the edge. | 119 // Returns true if the window should stick to the edge. |
| 121 bool ShouldStickToEdge(int distance_from_edge, int sticky_size) { | 120 bool ShouldStickToEdge(int distance_from_edge, int sticky_size) { |
| 122 if (CommandLine::ForCurrentProcess()->HasSwitch( | 121 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 123 switches::kAshEnableStickyEdges) || | 122 switches::kAshEnableStickyEdges)) { |
| 124 CommandLine::ForCurrentProcess()->HasSwitch( | 123 // TODO(varkha): Consider keeping snapping behavior for touch drag. |
| 125 switches::kAshEnableDockedWindows)) { | |
| 126 return distance_from_edge < 0 && | 124 return distance_from_edge < 0 && |
| 127 distance_from_edge > -sticky_size; | 125 distance_from_edge > -sticky_size; |
| 128 } | 126 } |
| 129 return distance_from_edge < sticky_size && | 127 return distance_from_edge < sticky_size && |
| 130 distance_from_edge > -sticky_size * 2; | 128 distance_from_edge > -sticky_size * 2; |
| 131 } | 129 } |
| 132 | 130 |
| 133 // Returns the coordinate along the secondary axis to snap to. | 131 // Returns the coordinate along the secondary axis to snap to. |
| 134 int CoordinateAlongSecondaryAxis(SecondaryMagnetismEdge edge, | 132 int CoordinateAlongSecondaryAxis(SecondaryMagnetismEdge edge, |
| 135 int leading, | 133 int leading, |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 | 264 |
| 267 // static | 265 // static |
| 268 const int WorkspaceWindowResizer::kMinOnscreenHeight = 32; | 266 const int WorkspaceWindowResizer::kMinOnscreenHeight = 32; |
| 269 | 267 |
| 270 // static | 268 // static |
| 271 const int WorkspaceWindowResizer::kScreenEdgeInset = 8; | 269 const int WorkspaceWindowResizer::kScreenEdgeInset = 8; |
| 272 | 270 |
| 273 // static | 271 // static |
| 274 const int WorkspaceWindowResizer::kStickyDistancePixels = 64; | 272 const int WorkspaceWindowResizer::kStickyDistancePixels = 64; |
| 275 | 273 |
| 274 // static |
| 275 WorkspaceWindowResizer* WorkspaceWindowResizer::instance_ = NULL; |
| 276 |
| 276 // Represents the width or height of a window with constraints on its minimum | 277 // Represents the width or height of a window with constraints on its minimum |
| 277 // and maximum size. 0 represents a lack of a constraint. | 278 // and maximum size. 0 represents a lack of a constraint. |
| 278 class WindowSize { | 279 class WindowSize { |
| 279 public: | 280 public: |
| 280 WindowSize(int size, int min, int max) | 281 WindowSize(int size, int min, int max) |
| 281 : size_(size), | 282 : size_(size), |
| 282 min_(min), | 283 min_(min), |
| 283 max_(max) { | 284 max_(max) { |
| 284 // Grow the min/max bounds to include the starting size. | 285 // Grow the min/max bounds to include the starting size. |
| 285 if (is_underflowing()) | 286 if (is_underflowing()) |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 | 339 |
| 339 private: | 340 private: |
| 340 int size_; | 341 int size_; |
| 341 int min_; | 342 int min_; |
| 342 int max_; | 343 int max_; |
| 343 }; | 344 }; |
| 344 | 345 |
| 345 WorkspaceWindowResizer::~WorkspaceWindowResizer() { | 346 WorkspaceWindowResizer::~WorkspaceWindowResizer() { |
| 346 Shell* shell = Shell::GetInstance(); | 347 Shell* shell = Shell::GetInstance(); |
| 347 shell->cursor_manager()->UnlockCursor(); | 348 shell->cursor_manager()->UnlockCursor(); |
| 349 if (instance_ == this) |
| 350 instance_ = NULL; |
| 348 } | 351 } |
| 349 | 352 |
| 350 // static | 353 // static |
| 351 WorkspaceWindowResizer* WorkspaceWindowResizer::Create( | 354 WorkspaceWindowResizer* WorkspaceWindowResizer::Create( |
| 352 aura::Window* window, | 355 aura::Window* window, |
| 353 const gfx::Point& location_in_parent, | 356 const gfx::Point& location_in_parent, |
| 354 int window_component, | 357 int window_component, |
| 355 aura::client::WindowMoveSource source, | 358 aura::client::WindowMoveSource source, |
| 356 const std::vector<aura::Window*>& attached_windows) { | 359 const std::vector<aura::Window*>& attached_windows) { |
| 357 Details details(window, location_in_parent, window_component, source); | 360 Details details(window, location_in_parent, window_component, source); |
| 358 return details.is_resizable ? | 361 return details.is_resizable ? |
| 359 new WorkspaceWindowResizer(details, attached_windows) : NULL; | 362 new WorkspaceWindowResizer(details, attached_windows) : NULL; |
| 360 } | 363 } |
| 361 | 364 |
| 362 void WorkspaceWindowResizer::Drag(const gfx::Point& location_in_parent, | 365 void WorkspaceWindowResizer::Drag(const gfx::Point& location_in_parent, |
| 363 int event_flags) { | 366 int event_flags) { |
| 364 last_mouse_location_ = location_in_parent; | 367 last_mouse_location_ = location_in_parent; |
| 365 | 368 |
| 366 int sticky_size; | 369 int sticky_size; |
| 367 if (event_flags & ui::EF_CONTROL_DOWN) { | 370 if (event_flags & ui::EF_CONTROL_DOWN) { |
| 368 sticky_size = 0; | 371 sticky_size = 0; |
| 369 } else if (CommandLine::ForCurrentProcess()->HasSwitch( | 372 } else if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 370 switches::kAshEnableStickyEdges) || | 373 switches::kAshEnableStickyEdges)) { |
| 371 CommandLine::ForCurrentProcess()->HasSwitch( | |
| 372 switches::kAshEnableDockedWindows)) { | |
| 373 sticky_size = kStickyDistancePixels; | 374 sticky_size = kStickyDistancePixels; |
| 374 } else if ((details_.bounds_change & kBoundsChange_Resizes) && | 375 } else if ((details_.bounds_change & kBoundsChange_Resizes) && |
| 375 details_.source == aura::client::WINDOW_MOVE_SOURCE_TOUCH) { | 376 details_.source == aura::client::WINDOW_MOVE_SOURCE_TOUCH) { |
| 376 sticky_size = kScreenEdgeInsetForTouchResize; | 377 sticky_size = kScreenEdgeInsetForTouchResize; |
| 377 } else { | 378 } else { |
| 378 sticky_size = kScreenEdgeInset; | 379 sticky_size = kScreenEdgeInset; |
| 379 } | 380 } |
| 380 // |bounds| is in |window()->parent()|'s coordinates. | 381 // |bounds| is in |window()->parent()|'s coordinates. |
| 381 gfx::Rect bounds = CalculateBoundsForDrag(details_, location_in_parent); | 382 gfx::Rect bounds = CalculateBoundsForDrag(details_, location_in_parent); |
| 382 if (window_state()->IsNormalShowState()) | 383 if (window_state()->IsNormalShowState()) |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 int initial_size = PrimaryAxisSize(attached_windows_[i]->bounds().size()); | 536 int initial_size = PrimaryAxisSize(attached_windows_[i]->bounds().size()); |
| 536 initial_size_.push_back(initial_size); | 537 initial_size_.push_back(initial_size); |
| 537 // If current size is smaller than the min, use the current size as the min. | 538 // If current size is smaller than the min, use the current size as the min. |
| 538 // This way we don't snap on resize. | 539 // This way we don't snap on resize. |
| 539 int min_size = std::min(initial_size, | 540 int min_size = std::min(initial_size, |
| 540 std::max(PrimaryAxisSize(min), kMinOnscreenSize)); | 541 std::max(PrimaryAxisSize(min), kMinOnscreenSize)); |
| 541 total_min_ += min_size; | 542 total_min_ += min_size; |
| 542 total_initial_size_ += initial_size; | 543 total_initial_size_ += initial_size; |
| 543 total_available += std::max(min_size, initial_size) - min_size; | 544 total_available += std::max(min_size, initial_size) - min_size; |
| 544 } | 545 } |
| 546 instance_ = this; |
| 545 } | 547 } |
| 546 | 548 |
| 547 gfx::Rect WorkspaceWindowResizer::GetFinalBounds( | 549 gfx::Rect WorkspaceWindowResizer::GetFinalBounds( |
| 548 const gfx::Rect& bounds) const { | 550 const gfx::Rect& bounds) const { |
| 549 if (snap_phantom_window_controller_.get() && | 551 if (snap_phantom_window_controller_.get() && |
| 550 snap_phantom_window_controller_->IsShowing()) { | 552 snap_phantom_window_controller_->IsShowing()) { |
| 551 return snap_phantom_window_controller_->bounds_in_screen(); | 553 return snap_phantom_window_controller_->bounds_in_screen(); |
| 552 } | 554 } |
| 553 return bounds; | 555 return bounds; |
| 554 } | 556 } |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1009 if (!dock_layout_->is_dragged_window_docked()) | 1011 if (!dock_layout_->is_dragged_window_docked()) |
| 1010 dock_layout_->DockDraggedWindow(window()); | 1012 dock_layout_->DockDraggedWindow(window()); |
| 1011 } else { | 1013 } else { |
| 1012 if (dock_layout_->is_dragged_window_docked()) | 1014 if (dock_layout_->is_dragged_window_docked()) |
| 1013 dock_layout_->UndockDraggedWindow(); | 1015 dock_layout_->UndockDraggedWindow(); |
| 1014 } | 1016 } |
| 1015 } | 1017 } |
| 1016 | 1018 |
| 1017 } // namespace internal | 1019 } // namespace internal |
| 1018 } // namespace ash | 1020 } // namespace ash |
| OLD | NEW |