OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/dock/docked_window_layout_manager.h" | 5 #include "ash/wm/dock/docked_window_layout_manager.h" |
6 | 6 |
7 #include "ash/launcher/launcher.h" | 7 #include "ash/launcher/launcher.h" |
8 #include "ash/screen_ash.h" | 8 #include "ash/screen_ash.h" |
9 #include "ash/shelf/shelf_layout_manager.h" | 9 #include "ash/shelf/shelf_layout_manager.h" |
10 #include "ash/shelf/shelf_types.h" | 10 #include "ash/shelf/shelf_types.h" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "ui/aura/focus_manager.h" | 21 #include "ui/aura/focus_manager.h" |
22 #include "ui/aura/root_window.h" | 22 #include "ui/aura/root_window.h" |
23 #include "ui/aura/window.h" | 23 #include "ui/aura/window.h" |
24 #include "ui/gfx/rect.h" | 24 #include "ui/gfx/rect.h" |
25 | 25 |
26 namespace ash { | 26 namespace ash { |
27 namespace internal { | 27 namespace internal { |
28 | 28 |
29 // Minimum, maximum width of the dock area and a width of the gap | 29 // Minimum, maximum width of the dock area and a width of the gap |
30 const int DockedWindowLayoutManager::kMinDockWidth = 200; | 30 const int DockedWindowLayoutManager::kMinDockWidth = 200; |
31 const int DockedWindowLayoutManager::kMaxDockWidth = 450; | 31 const int DockedWindowLayoutManager::kMaxDockWidth = 360; |
32 const int DockedWindowLayoutManager::kMinDockGap = 2; | 32 const int DockedWindowLayoutManager::kMinDockGap = 2; |
33 const int kWindowIdealSpacing = 4; | 33 const int kWindowIdealSpacing = 4; |
34 | 34 |
35 namespace { | 35 namespace { |
36 | 36 |
37 const SkColor kDockBackgroundColor = SkColorSetARGB(0xff, 0x10, 0x10, 0x10); | 37 const SkColor kDockBackgroundColor = SkColorSetARGB(0xff, 0x10, 0x10, 0x10); |
38 const float kDockBackgroundOpacity = 0.5f; | 38 const float kDockBackgroundOpacity = 0.5f; |
39 | 39 |
40 class DockedBackgroundWidget : public views::Widget { | 40 class DockedBackgroundWidget : public views::Widget { |
41 public: | 41 public: |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 } | 200 } |
201 | 201 |
202 void DockedWindowLayoutManager::DockDraggedWindow(aura::Window* window) { | 202 void DockedWindowLayoutManager::DockDraggedWindow(aura::Window* window) { |
203 OnWindowDocked(window); | 203 OnWindowDocked(window); |
204 Relayout(); | 204 Relayout(); |
205 } | 205 } |
206 | 206 |
207 void DockedWindowLayoutManager::UndockDraggedWindow() { | 207 void DockedWindowLayoutManager::UndockDraggedWindow() { |
208 OnWindowUndocked(); | 208 OnWindowUndocked(); |
209 Relayout(); | 209 Relayout(); |
210 UpdateDockBounds(); | |
210 is_dragged_from_dock_ = false; | 211 is_dragged_from_dock_ = false; |
211 } | 212 } |
212 | 213 |
213 void DockedWindowLayoutManager::FinishDragging() { | 214 void DockedWindowLayoutManager::FinishDragging() { |
214 DCHECK(dragged_window_); | 215 DCHECK(dragged_window_); |
215 if (is_dragged_window_docked_) | 216 if (is_dragged_window_docked_) |
216 OnWindowUndocked(); | 217 OnWindowUndocked(); |
217 DCHECK (!is_dragged_window_docked_); | 218 DCHECK (!is_dragged_window_docked_); |
218 // Stop observing a window unless it is docked container's child in which | 219 // Stop observing a window unless it is docked container's child in which |
219 // case it needs to keep being observed after the drag completes. | 220 // case it needs to keep being observed after the drag completes. |
220 if (dragged_window_->parent() != dock_container_) | 221 if (dragged_window_->parent() != dock_container_) { |
221 dragged_window_->RemoveObserver(this); | 222 dragged_window_->RemoveObserver(this); |
223 if (last_active_window_ == dragged_window_) | |
224 last_active_window_ = NULL; | |
225 } | |
222 dragged_window_ = NULL; | 226 dragged_window_ = NULL; |
227 dragged_bounds_ = gfx::Rect(); | |
223 Relayout(); | 228 Relayout(); |
224 UpdateDockBounds(); | 229 UpdateDockBounds(); |
225 } | 230 } |
226 | 231 |
227 void DockedWindowLayoutManager::SetLauncher(ash::Launcher* launcher) { | 232 void DockedWindowLayoutManager::SetLauncher(ash::Launcher* launcher) { |
228 DCHECK(!launcher_); | 233 DCHECK(!launcher_); |
229 DCHECK(!shelf_layout_manager_); | 234 DCHECK(!shelf_layout_manager_); |
230 launcher_ = launcher; | 235 launcher_ = launcher; |
231 if (launcher_->shelf_widget()) { | 236 if (launcher_->shelf_widget()) { |
232 shelf_layout_manager_ = ash::internal::ShelfLayoutManager::ForLauncher( | 237 shelf_layout_manager_ = ash::internal::ShelfLayoutManager::ForLauncher( |
233 launcher_->shelf_widget()->GetNativeWindow()); | 238 launcher_->shelf_widget()->GetNativeWindow()); |
234 WillChangeVisibilityState(shelf_layout_manager_->visibility_state()); | 239 WillChangeVisibilityState(shelf_layout_manager_->visibility_state()); |
235 shelf_layout_manager_->AddObserver(this); | 240 shelf_layout_manager_->AddObserver(this); |
236 } | 241 } |
237 } | 242 } |
238 | 243 |
239 DockedAlignment DockedWindowLayoutManager::GetAlignmentOfWindow( | 244 DockedAlignment DockedWindowLayoutManager::GetAlignmentOfWindow( |
240 const aura::Window* window) const { | 245 const aura::Window* window) const { |
241 const gfx::Rect& bounds(window->GetBoundsInScreen()); | 246 const gfx::Rect& bounds(window->GetBoundsInScreen()); |
242 const gfx::Rect docked_bounds = dock_container_->GetBoundsInScreen(); | |
243 | 247 |
244 // Do not allow docking if a window is vertically maximized (as is the case | 248 // Test overlap with an existing docked area first. |
245 // when it is snapped). | 249 if (docked_bounds_.Intersects(bounds) && |
246 const gfx::Rect work_area = | 250 alignment_ != DOCKED_ALIGNMENT_NONE) { |
247 Shell::GetScreen()->GetDisplayNearestWindow(dock_container_).work_area(); | 251 // A window is being added to other docked windows (on the same side). |
248 if (bounds.y() == work_area.y() && bounds.height() == work_area.height()) | 252 return alignment_; |
249 return DOCKED_ALIGNMENT_NONE; | 253 } |
250 | 254 |
251 // Do not allow docking on the same side as launcher shelf. | 255 const gfx::Rect container_bounds = dock_container_->GetBoundsInScreen(); |
252 ShelfAlignment shelf_alignment = SHELF_ALIGNMENT_BOTTOM; | 256 if (bounds.x() <= container_bounds.x() && |
253 if (launcher_) | 257 bounds.right() > container_bounds.x()) { |
254 shelf_alignment = launcher_->alignment(); | |
255 | |
256 if (bounds.x() == docked_bounds.x() && | |
257 shelf_alignment != SHELF_ALIGNMENT_LEFT) { | |
258 return DOCKED_ALIGNMENT_LEFT; | 258 return DOCKED_ALIGNMENT_LEFT; |
259 } | 259 } else if (bounds.x() < container_bounds.right() && |
260 if (bounds.right() == docked_bounds.right() && | 260 bounds.right() >= container_bounds.right()) { |
261 shelf_alignment != SHELF_ALIGNMENT_RIGHT) { | |
262 return DOCKED_ALIGNMENT_RIGHT; | 261 return DOCKED_ALIGNMENT_RIGHT; |
263 } | 262 } |
264 return DOCKED_ALIGNMENT_NONE; | 263 return DOCKED_ALIGNMENT_NONE; |
265 } | 264 } |
266 | 265 |
267 DockedAlignment DockedWindowLayoutManager::CalculateAlignment() const { | 266 DockedAlignment DockedWindowLayoutManager::CalculateAlignment() const { |
268 // Find a child that is not being dragged and is not a popup. | 267 // Find a child that is not being dragged and is not a popup. |
269 // If such exists the current alignment is returned - even if some of the | 268 // If such exists the current alignment is returned - even if some of the |
270 // children are hidden or minimized (so they can be restored without losing | 269 // children are hidden or minimized (so they can be restored without losing |
271 // the docked state). | 270 // the docked state). |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
537 active_window = dragged_window_; | 536 active_window = dragged_window_; |
538 } | 537 } |
539 | 538 |
540 // Calculate free space or overlap. | 539 // Calculate free space or overlap. |
541 gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow( | 540 gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow( |
542 dock_container_); | 541 dock_container_); |
543 const gfx::Rect work_area = display.work_area(); | 542 const gfx::Rect work_area = display.work_area(); |
544 int available_room = work_area.height(); | 543 int available_room = work_area.height(); |
545 for (aura::Window::Windows::const_iterator iter = visible_windows.begin(); | 544 for (aura::Window::Windows::const_iterator iter = visible_windows.begin(); |
546 iter != visible_windows.end(); ++iter) { | 545 iter != visible_windows.end(); ++iter) { |
547 available_room -= (*iter)->bounds().height(); | 546 int height = (*iter)->bounds().height(); |
flackr
2013/09/10 17:59:44
nit: Storing height is unnecessary for now.
varkha
2013/09/10 21:49:35
Done.
| |
547 available_room -= height; | |
548 } | 548 } |
549 const int num_windows = visible_windows.size(); | 549 const int num_windows = visible_windows.size(); |
550 const float delta = (float)available_room / | 550 const float delta = (float)available_room / |
551 ((available_room > 0 || num_windows <= 1) ? | 551 ((available_room > 0 || num_windows <= 1) ? |
552 num_windows + 1 : num_windows - 1); | 552 num_windows + 1 : num_windows - 1); |
553 float y_pos = work_area.y() + ((available_room > 0) ? delta : 0); | 553 float y_pos = work_area.y() + ((available_room > 0) ? delta : 0); |
554 | 554 |
555 // Sort windows by their center positions and fan out overlapping | 555 // Sort windows by their center positions and fan out overlapping |
556 // windows. | 556 // windows. |
557 std::sort(visible_windows.begin(), | 557 std::sort(visible_windows.begin(), |
558 visible_windows.end(), | 558 visible_windows.end(), |
559 CompareWindowPos(is_dragged_from_dock_ ? dragged_window_ : NULL, | 559 CompareWindowPos(is_dragged_from_dock_ ? dragged_window_ : NULL, |
560 delta)); | 560 delta)); |
561 is_dragged_from_dock_ = true; | 561 is_dragged_from_dock_ = true; |
562 for (aura::Window::Windows::const_iterator iter = visible_windows.begin(); | 562 for (aura::Window::Windows::const_iterator iter = visible_windows.begin(); |
563 iter != visible_windows.end(); ++iter) { | 563 iter != visible_windows.end(); ++iter) { |
564 aura::Window* window = *iter; | 564 aura::Window* window = *iter; |
565 gfx::Rect bounds = window->GetBoundsInScreen(); | 565 gfx::Rect bounds = window->GetBoundsInScreen(); |
566 | 566 |
567 DockedAlignment alignment = alignment_; | |
568 if (alignment == DOCKED_ALIGNMENT_NONE && window == dragged_window_) { | |
569 alignment = GetAlignmentOfWindow(window); | |
570 if (alignment == DOCKED_ALIGNMENT_NONE) | |
571 bounds.set_size(gfx::Size()); | |
572 } | |
573 | |
574 // Restrict width. | |
575 if (bounds.width() > kMaxDockWidth) | |
576 bounds.set_width(kMaxDockWidth); | |
577 | |
567 // Fan out windows evenly distributing the overlap or remaining free space. | 578 // Fan out windows evenly distributing the overlap or remaining free space. |
568 bounds.set_y(std::max(work_area.y(), | 579 bounds.set_y(std::max(work_area.y(), |
569 std::min(work_area.bottom() - bounds.height(), | 580 std::min(work_area.bottom() - bounds.height(), |
570 static_cast<int>(y_pos + 0.5)))); | 581 static_cast<int>(y_pos + 0.5)))); |
571 y_pos += bounds.height() + delta; | 582 y_pos += bounds.height() + delta; |
572 | 583 |
573 // All docked windows other than the one currently dragged remain stuck | 584 // All docked windows other than the one currently dragged remain stuck |
574 // to the screen edge. | 585 // to the screen edge. |
575 switch (alignment_) { | 586 switch (alignment) { |
576 case DOCKED_ALIGNMENT_LEFT: | 587 case DOCKED_ALIGNMENT_LEFT: |
577 bounds.set_x(dock_bounds.x()); | 588 bounds.set_x(dock_bounds.x()); |
578 break; | 589 break; |
579 case DOCKED_ALIGNMENT_RIGHT: | 590 case DOCKED_ALIGNMENT_RIGHT: |
580 bounds.set_x(dock_bounds.right() - bounds.width()); | 591 bounds.set_x(dock_bounds.right() - bounds.width()); |
581 break; | 592 break; |
582 case DOCKED_ALIGNMENT_NONE: | 593 case DOCKED_ALIGNMENT_NONE: |
583 break; | 594 break; |
584 } | 595 } |
585 if (window == dragged_window_) { | 596 if (window == dragged_window_) { |
586 dragged_bounds_ = bounds; | 597 dragged_bounds_ = bounds; |
587 continue; | 598 continue; |
588 } | 599 } |
600 // If the following asserts it is probably because not all the children | |
601 // have been removed when dock was closed. | |
589 DCHECK_NE(alignment_, DOCKED_ALIGNMENT_NONE); | 602 DCHECK_NE(alignment_, DOCKED_ALIGNMENT_NONE); |
590 // Keep the dock at least kMinDockWidth when all windows in it overhang. | 603 // Keep the dock at least kMinDockWidth when all windows in it overhang. |
591 docked_width_ = std::min(kMaxDockWidth, | 604 docked_width_ = std::min(kMaxDockWidth, |
592 std::max(docked_width_, | 605 std::max(docked_width_, |
593 bounds.width() > kMaxDockWidth ? | 606 bounds.width() > kMaxDockWidth ? |
594 kMinDockWidth : bounds.width())); | 607 kMinDockWidth : bounds.width())); |
595 bounds = ScreenAsh::ConvertRectFromScreen(dock_container_, bounds); | 608 bounds = ScreenAsh::ConvertRectFromScreen(dock_container_, bounds); |
596 SetChildBoundsDirect(window, bounds); | 609 SetChildBoundsDirect(window, bounds); |
597 } | 610 } |
598 UpdateStacking(active_window); | 611 UpdateStacking(active_window); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
686 | 699 |
687 void DockedWindowLayoutManager::OnKeyboardBoundsChanging( | 700 void DockedWindowLayoutManager::OnKeyboardBoundsChanging( |
688 const gfx::Rect& keyboard_bounds) { | 701 const gfx::Rect& keyboard_bounds) { |
689 // This bounds change will have caused a change to the Shelf which does not | 702 // This bounds change will have caused a change to the Shelf which does not |
690 // propagate automatically to this class, so manually recalculate bounds. | 703 // propagate automatically to this class, so manually recalculate bounds. |
691 UpdateDockBounds(); | 704 UpdateDockBounds(); |
692 } | 705 } |
693 | 706 |
694 } // namespace internal | 707 } // namespace internal |
695 } // namespace ash | 708 } // namespace ash |
OLD | NEW |