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 | 9 |
10 #include "ash/display/display_controller.h" | 10 #include "ash/display/display_controller.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "ui/gfx/transform.h" | 27 #include "ui/gfx/transform.h" |
28 | 28 |
29 namespace ash { | 29 namespace ash { |
30 namespace internal { | 30 namespace internal { |
31 | 31 |
32 namespace { | 32 namespace { |
33 | 33 |
34 // Duration of the animation when snapping the window into place. | 34 // Duration of the animation when snapping the window into place. |
35 const int kSnapDurationMS = 100; | 35 const int kSnapDurationMS = 100; |
36 | 36 |
| 37 // The maximum opacity of the drag phantom window. |
| 38 const float kMaxOpacity = 0.8f; |
| 39 |
37 // Returns true if should snap to the edge. | 40 // Returns true if should snap to the edge. |
38 bool ShouldSnapToEdge(int distance_from_edge, int grid_size) { | 41 bool ShouldSnapToEdge(int distance_from_edge, int grid_size) { |
39 return distance_from_edge <= grid_size / 2 && | 42 return distance_from_edge <= grid_size / 2 && |
40 distance_from_edge > -grid_size * 2; | 43 distance_from_edge > -grid_size * 2; |
41 } | 44 } |
42 | 45 |
43 // Returns true if Ash has more than one root window. | 46 // Returns true if Ash has more than one root window. |
44 bool HasSecondaryRootWindow() { | 47 bool HasSecondaryRootWindow() { |
45 return Shell::GetAllRootWindows().size() > 1; | 48 return Shell::GetAllRootWindows().size() > 1; |
46 } | 49 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 | 117 |
115 const bool in_original_root = (window()->GetRootWindow() == current_root); | 118 const bool in_original_root = (window()->GetRootWindow() == current_root); |
116 // Hide a phantom window for snapping if the cursor is in another root window. | 119 // Hide a phantom window for snapping if the cursor is in another root window. |
117 if (in_original_root) | 120 if (in_original_root) |
118 UpdateSnapPhantomWindow(location_in_parent, bounds, grid_size); | 121 UpdateSnapPhantomWindow(location_in_parent, bounds, grid_size); |
119 else | 122 else |
120 snap_phantom_window_controller_.reset(); | 123 snap_phantom_window_controller_.reset(); |
121 | 124 |
122 // Show a phantom window for dragging in another root window. | 125 // Show a phantom window for dragging in another root window. |
123 if (HasSecondaryRootWindow()) | 126 if (HasSecondaryRootWindow()) |
124 UpdateDragPhantomWindow(bounds); | 127 UpdateDragPhantomWindow(bounds, in_original_root); |
125 else | 128 else |
126 drag_phantom_window_controller_.reset(); | 129 drag_phantom_window_controller_.reset(); |
127 | 130 |
128 if (!attached_windows_.empty()) | 131 if (!attached_windows_.empty()) |
129 LayoutAttachedWindows(bounds, grid_size); | 132 LayoutAttachedWindows(bounds, grid_size); |
130 if (bounds != details_.window->bounds()) | 133 if (bounds != details_.window->bounds()) |
131 details_.window->SetBounds(bounds); | 134 details_.window->SetBounds(bounds); |
132 // WARNING: we may have been deleted. | 135 // WARNING: we may have been deleted. |
133 } | 136 } |
134 | 137 |
135 void WorkspaceWindowResizer::CompleteDrag(int event_flags) { | 138 void WorkspaceWindowResizer::CompleteDrag(int event_flags) { |
| 139 window()->layer()->SetOpacity(details_.initial_opacity); |
136 drag_phantom_window_controller_.reset(); | 140 drag_phantom_window_controller_.reset(); |
137 snap_phantom_window_controller_.reset(); | 141 snap_phantom_window_controller_.reset(); |
138 if (!did_move_or_resize_ || details_.window_component != HTCAPTION) | 142 if (!did_move_or_resize_ || details_.window_component != HTCAPTION) |
139 return; | 143 return; |
140 | 144 |
141 if (snap_type_ == SNAP_LEFT_EDGE || snap_type_ == SNAP_RIGHT_EDGE) { | 145 if (snap_type_ == SNAP_LEFT_EDGE || snap_type_ == SNAP_RIGHT_EDGE) { |
142 if (!GetRestoreBoundsInScreen(details_.window)) | 146 if (!GetRestoreBoundsInScreen(details_.window)) |
143 SetRestoreBoundsInParent(details_.window, details_.initial_bounds); | 147 SetRestoreBoundsInParent(details_.window, details_.initial_bounds); |
144 details_.window->SetBounds(snap_sizer_->target_bounds()); | 148 details_.window->SetBounds(snap_sizer_->target_bounds()); |
145 return; | 149 return; |
(...skipping 29 matching lines...) Expand all Loading... |
175 | 179 |
176 ui::ScopedLayerAnimationSettings scoped_setter( | 180 ui::ScopedLayerAnimationSettings scoped_setter( |
177 details_.window->layer()->GetAnimator()); | 181 details_.window->layer()->GetAnimator()); |
178 // Use a small duration since the grid is small. | 182 // Use a small duration since the grid is small. |
179 scoped_setter.SetTransitionDuration( | 183 scoped_setter.SetTransitionDuration( |
180 base::TimeDelta::FromMilliseconds(kSnapDurationMS)); | 184 base::TimeDelta::FromMilliseconds(kSnapDurationMS)); |
181 details_.window->SetBounds(bounds); | 185 details_.window->SetBounds(bounds); |
182 } | 186 } |
183 | 187 |
184 void WorkspaceWindowResizer::RevertDrag() { | 188 void WorkspaceWindowResizer::RevertDrag() { |
| 189 window()->layer()->SetOpacity(details_.initial_opacity); |
185 drag_phantom_window_controller_.reset(); | 190 drag_phantom_window_controller_.reset(); |
186 snap_phantom_window_controller_.reset(); | 191 snap_phantom_window_controller_.reset(); |
187 | 192 |
188 if (!did_move_or_resize_) | 193 if (!did_move_or_resize_) |
189 return; | 194 return; |
190 | 195 |
191 details_.window->SetBounds(details_.initial_bounds); | 196 details_.window->SetBounds(details_.initial_bounds); |
192 if (details_.window_component == HTRIGHT) { | 197 if (details_.window_component == HTRIGHT) { |
193 int last_x = details_.initial_bounds.right(); | 198 int last_x = details_.initial_bounds.right(); |
194 for (size_t i = 0; i < attached_windows_.size(); ++i) { | 199 for (size_t i = 0; i < attached_windows_.size(); ++i) { |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 case HTRIGHT: | 438 case HTRIGHT: |
434 return x; | 439 return x; |
435 case HTBOTTOM: | 440 case HTBOTTOM: |
436 return y; | 441 return y; |
437 default: | 442 default: |
438 NOTREACHED(); | 443 NOTREACHED(); |
439 } | 444 } |
440 return 0; | 445 return 0; |
441 } | 446 } |
442 | 447 |
443 void WorkspaceWindowResizer::UpdateDragPhantomWindow(const gfx::Rect& bounds) { | 448 void WorkspaceWindowResizer::UpdateDragPhantomWindow(const gfx::Rect& bounds, |
| 449 bool in_original_root) { |
444 if (!did_move_or_resize_ || details_.window_component != HTCAPTION || | 450 if (!did_move_or_resize_ || details_.window_component != HTCAPTION || |
445 !ShouldAllowMouseWarp()) { | 451 !ShouldAllowMouseWarp()) { |
446 return; | 452 return; |
447 } | 453 } |
448 | 454 |
449 // It's available. Show a phantom window on the display if needed. | 455 // It's available. Show a phantom window on the display if needed. |
450 aura::RootWindow* another_root = | 456 aura::RootWindow* another_root = |
451 GetAnotherRootWindow(window()->GetRootWindow()); | 457 GetAnotherRootWindow(window()->GetRootWindow()); |
452 const gfx::Rect root_bounds_in_screen(another_root->GetBoundsInScreen()); | 458 const gfx::Rect root_bounds_in_screen(another_root->GetBoundsInScreen()); |
453 const gfx::Rect bounds_in_screen = | 459 const gfx::Rect bounds_in_screen = |
454 ScreenAsh::ConvertRectToScreen(window()->parent(), bounds); | 460 ScreenAsh::ConvertRectToScreen(window()->parent(), bounds); |
455 const gfx::Rect phantom(root_bounds_in_screen.Intersect(bounds_in_screen)); | 461 const gfx::Rect bounds_in_another_root = |
| 462 root_bounds_in_screen.Intersect(bounds_in_screen); |
456 | 463 |
457 if (!phantom.IsEmpty()) { | 464 const float fraction_in_another_window = |
| 465 (bounds_in_another_root.width() * bounds_in_another_root.height()) / |
| 466 static_cast<float>(bounds.width() * bounds.height()); |
| 467 const float phantom_opacity = |
| 468 !in_original_root ? 1 : (kMaxOpacity * fraction_in_another_window); |
| 469 const float window_opacity = |
| 470 in_original_root ? 1 : (kMaxOpacity * (1 - fraction_in_another_window)); |
| 471 |
| 472 if (fraction_in_another_window > 0) { |
458 if (!drag_phantom_window_controller_.get()) { | 473 if (!drag_phantom_window_controller_.get()) { |
459 drag_phantom_window_controller_.reset( | 474 drag_phantom_window_controller_.reset( |
460 new PhantomWindowController(window())); | 475 new PhantomWindowController(window())); |
461 drag_phantom_window_controller_->Show(phantom); | 476 drag_phantom_window_controller_->set_style( |
| 477 PhantomWindowController::STYLE_WINDOW); |
| 478 // Always show the drag phantom on the |another_root| window. |
| 479 drag_phantom_window_controller_->SetDestinationDisplay( |
| 480 gfx::Screen::GetDisplayMatching(another_root->GetBoundsInScreen())); |
| 481 drag_phantom_window_controller_->Show(bounds_in_screen); |
462 } else { | 482 } else { |
463 drag_phantom_window_controller_->SetBounds(phantom); // no animation | 483 // No animation. |
| 484 drag_phantom_window_controller_->SetBounds(bounds_in_screen); |
464 } | 485 } |
| 486 drag_phantom_window_controller_->SetOpacity(phantom_opacity); |
| 487 window()->layer()->SetOpacity(window_opacity); |
465 } else { | 488 } else { |
466 drag_phantom_window_controller_.reset(); | 489 drag_phantom_window_controller_.reset(); |
| 490 window()->layer()->SetOpacity(1.0f); |
467 } | 491 } |
468 } | 492 } |
469 | 493 |
470 void WorkspaceWindowResizer::UpdateSnapPhantomWindow(const gfx::Point& location, | 494 void WorkspaceWindowResizer::UpdateSnapPhantomWindow(const gfx::Point& location, |
471 const gfx::Rect& bounds, | 495 const gfx::Rect& bounds, |
472 int grid_size) { | 496 int grid_size) { |
473 if (!did_move_or_resize_ || details_.window_component != HTCAPTION) | 497 if (!did_move_or_resize_ || details_.window_component != HTCAPTION) |
474 return; | 498 return; |
475 | 499 |
476 SnapType last_type = snap_type_; | 500 SnapType last_type = snap_type_; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 } | 565 } |
542 | 566 |
543 bool WorkspaceWindowResizer::ShouldAllowMouseWarp() const { | 567 bool WorkspaceWindowResizer::ShouldAllowMouseWarp() const { |
544 return (details_.window_component == HTCAPTION) && | 568 return (details_.window_component == HTCAPTION) && |
545 (window()->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_NONE) && | 569 (window()->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_NONE) && |
546 (window()->type() == aura::client::WINDOW_TYPE_NORMAL); | 570 (window()->type() == aura::client::WINDOW_TYPE_NORMAL); |
547 } | 571 } |
548 | 572 |
549 } // namespace internal | 573 } // namespace internal |
550 } // namespace ash | 574 } // namespace ash |
OLD | NEW |