Chromium Code Reviews| 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 11 matching lines...) Expand all Loading... | |
| 22 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
| 23 #include "ui/gfx/rect.h" | 23 #include "ui/gfx/rect.h" |
| 24 | 24 |
| 25 namespace ash { | 25 namespace ash { |
| 26 namespace internal { | 26 namespace internal { |
| 27 | 27 |
| 28 // Minimum, maximum width of the dock area and a width of the gap | 28 // Minimum, maximum width of the dock area and a width of the gap |
| 29 const int DockedWindowLayoutManager::kMinDockWidth = 200; | 29 const int DockedWindowLayoutManager::kMinDockWidth = 200; |
| 30 const int DockedWindowLayoutManager::kMaxDockWidth = 450; | 30 const int DockedWindowLayoutManager::kMaxDockWidth = 450; |
| 31 const int DockedWindowLayoutManager::kMinDockGap = 2; | 31 const int DockedWindowLayoutManager::kMinDockGap = 2; |
| 32 const int kWindowIdealSpacing = 4; | |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 DockedWindowLayoutManager* GetDockLayoutManager(aura::Window* window, | 36 DockedWindowLayoutManager* GetDockLayoutManager(aura::Window* window, |
| 36 const gfx::Point& location) { | 37 const gfx::Point& location) { |
| 37 gfx::Rect near_location(location, gfx::Size()); | 38 gfx::Rect near_location(location, gfx::Size()); |
| 38 aura::Window* dock = Shell::GetContainer( | 39 aura::Window* dock = Shell::GetContainer( |
| 39 wm::GetRootWindowMatching(near_location), | 40 wm::GetRootWindowMatching(near_location), |
| 40 kShellWindowId_DockedContainer); | 41 kShellWindowId_DockedContainer); |
| 41 return static_cast<internal::DockedWindowLayoutManager*>( | 42 return static_cast<internal::DockedWindowLayoutManager*>( |
| 42 dock->layout_manager()); | 43 dock->layout_manager()); |
| 43 } | 44 } |
| 44 | 45 |
| 45 // Certain windows (minimized, hidden or popups) do not matter to docking. | 46 // Certain windows (minimized, hidden or popups) do not matter to docking. |
| 46 bool IsUsedByLayout(aura::Window* window) { | 47 bool IsUsedByLayout(aura::Window* window) { |
| 47 return (window->IsVisible() && | 48 return (window->IsVisible() && |
| 48 !wm::IsWindowMinimized(window) && | 49 !wm::IsWindowMinimized(window) && |
| 49 window->type() != aura::client::WINDOW_TYPE_POPUP); | 50 window->type() != aura::client::WINDOW_TYPE_POPUP); |
| 50 } | 51 } |
| 51 | 52 |
| 53 struct VisibleWindowPositionInfo { | |
| 54 VisibleWindowPositionInfo() | |
| 55 : major_pos(0), | |
| 56 major_length(0), | |
| 57 window(NULL) {} | |
| 58 | |
| 59 int major_pos; | |
| 60 int major_length; | |
| 61 aura::Window* window; | |
| 62 }; | |
| 63 | |
| 64 bool CompareWindowMajor(const VisibleWindowPositionInfo& win1, | |
| 65 const VisibleWindowPositionInfo& win2) { | |
| 66 return win1.major_pos < win2.major_pos; | |
| 67 } | |
| 68 | |
| 69 void FanOutWindows(std::vector<VisibleWindowPositionInfo>::iterator first, | |
| 70 std::vector<VisibleWindowPositionInfo>::iterator last, | |
| 71 int min_major, | |
| 72 int max_major) { | |
| 73 int num_windows = last - first; | |
| 74 if (num_windows <= 0) | |
| 75 return; | |
| 76 if (num_windows == 1) { | |
| 77 (*first).major_pos = std::max(min_major, std::min( | |
| 78 max_major, (*first).major_pos)); | |
| 79 return; | |
| 80 } | |
| 81 | |
| 82 // If there are more than one window, fan them out from minimum position to | |
| 83 // maximum position leaving equal gaps or overlapping by the same amount. | |
| 84 int available_room = max_major - min_major + (*first).major_length / 2 + | |
| 85 (*(last - 1)).major_length - (*(last - 1)).major_length / 2; | |
| 86 for (std::vector<VisibleWindowPositionInfo>::iterator iter = first; | |
| 87 iter != last; ++iter) { | |
| 88 available_room -= (*iter).major_length; | |
| 89 } | |
| 90 const int delta = available_room / | |
| 91 (available_room > 0 ? num_windows + 1 : num_windows - 1); | |
| 92 int major_pos = (available_room > 0) ? delta : 0; | |
| 93 for (std::vector<VisibleWindowPositionInfo>::iterator iter = first; | |
| 94 iter != last; ++iter) { | |
| 95 major_pos += (*iter).major_length / 2; | |
| 96 (*iter).major_pos = std::max(min_major, std::min(max_major, major_pos)); | |
| 97 major_pos += (*iter).major_length - (*iter).major_length / 2 + delta; | |
| 98 } | |
| 99 } | |
| 100 | |
| 52 } // namespace | 101 } // namespace |
| 53 | 102 |
| 54 //////////////////////////////////////////////////////////////////////////////// | 103 //////////////////////////////////////////////////////////////////////////////// |
| 55 // DockLayoutManager public implementation: | 104 // DockLayoutManager public implementation: |
| 56 DockedWindowLayoutManager::DockedWindowLayoutManager( | 105 DockedWindowLayoutManager::DockedWindowLayoutManager( |
| 57 aura::Window* dock_container) | 106 aura::Window* dock_container) |
| 58 : dock_container_(dock_container), | 107 : dock_container_(dock_container), |
| 59 in_layout_(false), | 108 in_layout_(false), |
| 109 dragged_former_child_(NULL), | |
| 60 dragged_window_(NULL), | 110 dragged_window_(NULL), |
| 61 launcher_(NULL), | 111 launcher_(NULL), |
| 62 shelf_layout_manager_(NULL), | 112 shelf_layout_manager_(NULL), |
| 63 shelf_hidden_(false), | 113 shelf_hidden_(false), |
| 64 docked_width_(0), | 114 docked_width_(0), |
| 65 alignment_(DOCKED_ALIGNMENT_NONE) { | 115 alignment_(DOCKED_ALIGNMENT_NONE), |
| 116 last_active_(NULL) { | |
| 66 DCHECK(dock_container); | 117 DCHECK(dock_container); |
| 67 aura::client::GetActivationClient(Shell::GetPrimaryRootWindow())-> | 118 aura::client::GetActivationClient(Shell::GetPrimaryRootWindow())-> |
| 68 AddObserver(this); | 119 AddObserver(this); |
| 69 Shell::GetInstance()->AddShellObserver(this); | 120 Shell::GetInstance()->AddShellObserver(this); |
| 70 } | 121 } |
| 71 | 122 |
| 72 DockedWindowLayoutManager::~DockedWindowLayoutManager() { | 123 DockedWindowLayoutManager::~DockedWindowLayoutManager() { |
| 73 Shutdown(); | 124 Shutdown(); |
| 74 } | 125 } |
| 75 | 126 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 window->type() != aura::client::WINDOW_TYPE_POPUP) { | 177 window->type() != aura::client::WINDOW_TYPE_POPUP) { |
| 127 found_docked_window = true; | 178 found_docked_window = true; |
| 128 break; | 179 break; |
| 129 } | 180 } |
| 130 } | 181 } |
| 131 if (!found_docked_window) | 182 if (!found_docked_window) |
| 132 alignment_ = AlignmentOfWindow(dragged_window_); | 183 alignment_ = AlignmentOfWindow(dragged_window_); |
| 133 } | 184 } |
| 134 dragged_window_ = NULL; | 185 dragged_window_ = NULL; |
| 135 | 186 |
| 187 // We no longer need |dragged_former_child_| if it is added back; | |
| 188 if (dragged_former_child_) { | |
| 189 if (dragged_former_child_->parent() != dock_container_) | |
| 190 dragged_former_child_->RemoveObserver(this); | |
| 191 dragged_former_child_ = NULL; | |
| 192 } | |
| 193 | |
| 136 Relayout(); | 194 Relayout(); |
| 137 UpdateDockBounds(); | 195 UpdateDockBounds(); |
| 138 } | 196 } |
| 139 | 197 |
| 140 // static | 198 // static |
| 141 bool DockedWindowLayoutManager::ShouldWindowDock(aura::Window* window, | 199 bool DockedWindowLayoutManager::ShouldWindowDock(aura::Window* window, |
| 142 const gfx::Point& location) { | 200 const gfx::Point& location) { |
| 143 DockedWindowLayoutManager* layout_manager = GetDockLayoutManager(window, | 201 DockedWindowLayoutManager* layout_manager = GetDockLayoutManager(window, |
| 144 location); | 202 location); |
| 145 const DockedAlignment alignment = layout_manager->CalculateAlignment(); | 203 const DockedAlignment alignment = layout_manager->CalculateAlignment(); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 | 292 |
| 235 void DockedWindowLayoutManager::OnWindowAddedToLayout(aura::Window* child) { | 293 void DockedWindowLayoutManager::OnWindowAddedToLayout(aura::Window* child) { |
| 236 if (child->type() == aura::client::WINDOW_TYPE_POPUP) | 294 if (child->type() == aura::client::WINDOW_TYPE_POPUP) |
| 237 return; | 295 return; |
| 238 LOG(INFO) << "Added to dock " << | 296 LOG(INFO) << "Added to dock " << |
| 239 Shell::GetScreen()->GetDisplayNearestWindow(dock_container_).id(); | 297 Shell::GetScreen()->GetDisplayNearestWindow(dock_container_).id(); |
| 240 | 298 |
| 241 // If this is the first window getting docked - update alignment. | 299 // If this is the first window getting docked - update alignment. |
| 242 if (alignment_ == DOCKED_ALIGNMENT_NONE) | 300 if (alignment_ == DOCKED_ALIGNMENT_NONE) |
| 243 alignment_ = AlignmentOfWindow(child); | 301 alignment_ = AlignmentOfWindow(child); |
| 244 child->AddObserver(this); | 302 // We no longer need |dragged_former_child_| if it is added back. |
| 303 if (child == dragged_former_child_) | |
| 304 dragged_former_child_ = NULL; | |
| 305 else | |
| 306 child->AddObserver(this); | |
| 245 Relayout(); | 307 Relayout(); |
| 246 UpdateDockBounds(); | 308 UpdateDockBounds(); |
| 247 } | 309 } |
| 248 | 310 |
| 249 void DockedWindowLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) { | 311 void DockedWindowLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) { |
| 250 if (child->type() == aura::client::WINDOW_TYPE_POPUP) | 312 if (child->type() == aura::client::WINDOW_TYPE_POPUP) |
| 251 return; | 313 return; |
| 252 LOG(INFO) << "Removed from dock " << | 314 LOG(INFO) << "Removed from dock " << |
| 253 Shell::GetScreen()->GetDisplayNearestWindow(dock_container_).id(); | 315 Shell::GetScreen()->GetDisplayNearestWindow(dock_container_).id(); |
| 254 | 316 |
| 255 // Try to find a child that is not a popup and is not being dragged. | 317 // Try to find a child that is not a popup and is not being dragged. |
| 256 bool found_docked_window = false; | 318 bool found_docked_window = false; |
| 257 for (size_t i = 0; i < dock_container_->children().size(); ++i) { | 319 for (size_t i = 0; i < dock_container_->children().size(); ++i) { |
| 258 aura::Window* window(dock_container_->children()[i]); | 320 aura::Window* window(dock_container_->children()[i]); |
| 259 if (window != dragged_window_ && | 321 if (window != dragged_window_ && |
| 260 window->type() != aura::client::WINDOW_TYPE_POPUP) { | 322 window->type() != aura::client::WINDOW_TYPE_POPUP) { |
| 261 found_docked_window = true; | 323 found_docked_window = true; |
| 262 break; | 324 break; |
| 263 } | 325 } |
| 264 } | 326 } |
| 265 if (!found_docked_window) | 327 if (!found_docked_window) |
| 266 alignment_ = DOCKED_ALIGNMENT_NONE; | 328 alignment_ = DOCKED_ALIGNMENT_NONE; |
| 267 | 329 |
| 268 child->RemoveObserver(this); | 330 // Keep track of former children if they are dragged as they can be reparented |
| 331 // temporarily just for the drag. | |
| 332 if (child == dragged_window_) | |
| 333 dragged_former_child_ = child; | |
| 334 else | |
| 335 child->RemoveObserver(this); | |
| 336 | |
| 269 // Close the dock and expand workspace work area. | 337 // Close the dock and expand workspace work area. |
| 270 Relayout(); | 338 Relayout(); |
| 271 | 339 |
| 272 // When a panel is removed from this layout manager it may still be dragged. | 340 // When a panel is removed from this layout manager it may still be dragged. |
| 273 // Delay updating dock and workspace bounds until the drag is completed. This | 341 // Delay updating dock and workspace bounds until the drag is completed. This |
| 274 // preserves the docked area width until the panel drag is finished. | 342 // preserves the docked area width until the panel drag is finished. |
| 275 if (child->type() != aura::client::WINDOW_TYPE_PANEL) | 343 if (child->type() != aura::client::WINDOW_TYPE_PANEL) |
| 276 UpdateDockBounds(); | 344 UpdateDockBounds(); |
| 277 } | 345 } |
| 278 | 346 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 // The window property will still be set, but no actual change will occur | 405 // The window property will still be set, but no actual change will occur |
| 338 // until WillChangeVisibilityState is called when the shelf is visible again | 406 // until WillChangeVisibilityState is called when the shelf is visible again |
| 339 if (shelf_hidden_) | 407 if (shelf_hidden_) |
| 340 return; | 408 return; |
| 341 if (wm::IsWindowMinimized(window)) | 409 if (wm::IsWindowMinimized(window)) |
| 342 MinimizeWindow(window); | 410 MinimizeWindow(window); |
| 343 else | 411 else |
| 344 RestoreWindow(window); | 412 RestoreWindow(window); |
| 345 } | 413 } |
| 346 | 414 |
| 415 void DockedWindowLayoutManager::OnWindowBoundsChanged( | |
| 416 aura::Window* window, | |
| 417 const gfx::Rect& old_bounds, | |
| 418 const gfx::Rect& new_bounds) { | |
| 419 if (window == dragged_former_child_) | |
| 420 Relayout(); | |
| 421 if (window == dragged_former_child_) | |
| 422 LOG(INFO) << "OnWindowBoundsChanged"; | |
| 423 } | |
| 424 | |
| 347 //////////////////////////////////////////////////////////////////////////////// | 425 //////////////////////////////////////////////////////////////////////////////// |
| 348 // DockLayoutManager, aura::client::ActivationChangeObserver implementation: | 426 // DockLayoutManager, aura::client::ActivationChangeObserver implementation: |
| 349 | 427 |
| 350 void DockedWindowLayoutManager::OnWindowActivated(aura::Window* gained_active, | 428 void DockedWindowLayoutManager::OnWindowActivated(aura::Window* gained_active, |
| 351 aura::Window* lost_active) { | 429 aura::Window* lost_active) { |
| 352 // Ignore if the window that is not managed by this was activated. | 430 // Ignore if the window that is not managed by this was activated. |
| 353 aura::Window* ancestor = NULL; | 431 aura::Window* ancestor = NULL; |
| 354 for (aura::Window* parent = gained_active; | 432 for (aura::Window* parent = gained_active; |
| 355 parent; parent = parent->parent()) { | 433 parent; parent = parent->parent()) { |
| 356 if (parent->parent() == dock_container_) { | 434 if (parent->parent() == dock_container_) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 return DOCKED_ALIGNMENT_NONE; | 498 return DOCKED_ALIGNMENT_NONE; |
| 421 } | 499 } |
| 422 | 500 |
| 423 void DockedWindowLayoutManager::Relayout() { | 501 void DockedWindowLayoutManager::Relayout() { |
| 424 if (in_layout_ || alignment_ == DOCKED_ALIGNMENT_NONE) | 502 if (in_layout_ || alignment_ == DOCKED_ALIGNMENT_NONE) |
| 425 return; | 503 return; |
| 426 base::AutoReset<bool> auto_reset_in_layout(&in_layout_, true); | 504 base::AutoReset<bool> auto_reset_in_layout(&in_layout_, true); |
| 427 | 505 |
| 428 gfx::Rect dock_bounds = dock_container_->bounds(); | 506 gfx::Rect dock_bounds = dock_container_->bounds(); |
| 429 aura::Window* active_window = NULL; | 507 aura::Window* active_window = NULL; |
| 508 std::vector<VisibleWindowPositionInfo> visible_windows; | |
| 430 docked_width_ = 0; | 509 docked_width_ = 0; |
| 431 for (size_t i = 0; i < dock_container_->children().size(); ++i) { | 510 for (size_t i = 0; i < dock_container_->children().size(); ++i) { |
| 432 aura::Window* window(dock_container_->children()[i]); | 511 aura::Window* window(dock_container_->children()[i]); |
| 433 | 512 |
| 434 if (!IsUsedByLayout(window)) | 513 if (!IsUsedByLayout(window)) |
| 435 continue; | 514 continue; |
| 436 | 515 |
| 437 // If the shelf is currently hidden (full-screen mode), hide window until | 516 // If the shelf is currently hidden (full-screen mode), hide window until |
| 438 // full-screen mode is exited. | 517 // full-screen mode is exited. |
| 439 if (shelf_hidden_) { | 518 if (shelf_hidden_) { |
| 440 // The call to Hide does not set the minimize property, so the window will | 519 // The call to Hide does not set the minimize property, so the window will |
| 441 // be restored when the shelf becomes visible again. | 520 // be restored when the shelf becomes visible again. |
| 442 window->Hide(); | 521 window->Hide(); |
| 443 continue; | 522 continue; |
| 444 } | 523 } |
| 445 | 524 |
| 446 if (window->HasFocus() || | 525 if (window->HasFocus() || |
| 447 window->Contains( | 526 window->Contains( |
| 448 aura::client::GetFocusClient(window)->GetFocusedWindow())) { | 527 aura::client::GetFocusClient(window)->GetFocusedWindow())) { |
| 449 DCHECK(!active_window); | 528 DCHECK(!active_window); |
| 450 active_window = window; | 529 active_window = window; |
| 451 } | 530 } |
| 452 | 531 |
| 453 // all docked windows other than the one currently dragged remain stuck | 532 VisibleWindowPositionInfo position_info; |
| 454 // to the screen edge | 533 position_info.major_length = window->GetTargetBounds().height(); |
| 534 position_info.major_pos = | |
| 535 window->GetTargetBounds().y() + position_info.major_length / 2; | |
| 536 position_info.window = window; | |
| 537 visible_windows.push_back(position_info); | |
| 538 } | |
| 539 | |
| 540 // Consider windows that were formerly children of the |dock_container_| | |
| 541 // when fanning out other child windows. | |
| 542 if (dragged_former_child_) { | |
| 543 VisibleWindowPositionInfo position_info; | |
| 544 position_info.major_length = | |
| 545 dragged_former_child_->GetTargetBounds().height(); | |
| 546 position_info.major_pos = dragged_former_child_->GetTargetBounds().y() + | |
| 547 position_info.major_length / 2; | |
| 548 position_info.window = dragged_former_child_; | |
| 549 visible_windows.push_back(position_info); | |
|
flackr
2013/07/16 22:05:45
The window position is entirely based on the major
varkha
2013/07/18 21:56:59
Done.
| |
| 550 } | |
| 551 | |
| 552 // Sort windows by their center positions and fan out overlapping | |
| 553 // windows. The fan out method may result in new overlapping windows however | |
| 554 // it is unlikely that this overlap will completely obscure a window. | |
| 555 std::sort(visible_windows.begin(), visible_windows.end(), CompareWindowMajor); | |
| 556 if (!visible_windows.empty()) { | |
| 557 gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow( | |
| 558 dock_container_); | |
| 559 const gfx::Rect work_area = display.work_area(); | |
| 560 int min_major = work_area.y() + | |
| 561 (*visible_windows.begin()).major_length / 2; | |
| 562 int max_major = work_area.bottom() - | |
| 563 (*visible_windows.rbegin()).major_length / 2; | |
| 564 FanOutWindows(visible_windows.begin(), visible_windows.end(), | |
| 565 min_major, max_major); | |
|
flackr
2013/07/16 22:05:45
Since there's only one pass / one iteration, it wo
varkha
2013/07/18 21:56:59
Done.
| |
| 566 } | |
| 567 | |
| 568 for (size_t i = 0; i < visible_windows.size(); ++i) { | |
| 569 aura::Window* window(visible_windows[i].window); | |
| 570 | |
| 571 // All docked windows other than the one currently dragged remain stuck | |
| 572 // to the screen edge. | |
| 573 if (window == dragged_window_) | |
| 574 continue; | |
| 455 gfx::Rect bounds = window->GetTargetBounds(); | 575 gfx::Rect bounds = window->GetTargetBounds(); |
| 456 if (window != dragged_window_) { | 576 bounds.set_y(visible_windows[i].major_pos - |
| 457 switch (alignment_) { | 577 visible_windows[i].major_length / 2); |
| 458 case DOCKED_ALIGNMENT_LEFT: | 578 switch (alignment_) { |
| 459 bounds.set_x(0); | 579 case DOCKED_ALIGNMENT_LEFT: |
| 460 break; | 580 bounds.set_x(0); |
| 461 case DOCKED_ALIGNMENT_RIGHT: | 581 break; |
| 462 bounds.set_x(dock_bounds.right() - bounds.width()); | 582 case DOCKED_ALIGNMENT_RIGHT: |
| 463 break; | 583 bounds.set_x(dock_bounds.right() - bounds.width()); |
| 464 case DOCKED_ALIGNMENT_NONE: | 584 break; |
| 465 NOTREACHED() << "Relayout called when dock alignment is 'NONE'"; | 585 case DOCKED_ALIGNMENT_NONE: |
| 466 break; | 586 NOTREACHED() << "Relayout called when dock alignment is 'NONE'"; |
| 467 } | 587 break; |
| 468 // Keep the dock at least kMinDockWidth when all windows in it overhang. | |
| 469 docked_width_ = std::min(kMaxDockWidth, | |
| 470 std::max(docked_width_, | |
| 471 bounds.width() > kMaxDockWidth ? | |
| 472 kMinDockWidth : bounds.width())); | |
| 473 } | 588 } |
| 589 // Keep the dock at least kMinDockWidth when all windows in it overhang. | |
| 590 docked_width_ = std::min(kMaxDockWidth, | |
| 591 std::max(docked_width_, | |
| 592 bounds.width() > kMaxDockWidth ? | |
| 593 kMinDockWidth : bounds.width())); | |
| 474 if (bounds != window->GetTargetBounds()) | 594 if (bounds != window->GetTargetBounds()) |
| 475 LOG(INFO) << "Moved from " << window->GetTargetBounds().ToString() << | 595 LOG(INFO) << "Moved from " << window->GetTargetBounds().ToString() << |
| 476 " to " << bounds.ToString(); | 596 " to " << bounds.ToString(); |
| 477 SetChildBoundsDirect(window, bounds); | 597 SetChildBoundsDirect(window, bounds); |
| 478 } | 598 } |
| 479 UpdateStacking(active_window); | 599 UpdateStacking(active_window); |
| 480 } | 600 } |
| 481 | 601 |
| 482 void DockedWindowLayoutManager::UpdateDockBounds() { | 602 void DockedWindowLayoutManager::UpdateDockBounds() { |
| 483 int dock_inset = docked_width_ + (docked_width_ > 0 ? kMinDockGap : 0); | 603 int dock_inset = docked_width_ + (docked_width_ > 0 ? kMinDockGap : 0); |
| 484 gfx::Rect bounds = gfx::Rect( | 604 gfx::Rect bounds = gfx::Rect( |
| 485 alignment_ == DOCKED_ALIGNMENT_RIGHT ? | 605 alignment_ == DOCKED_ALIGNMENT_RIGHT ? |
| 486 dock_container_->bounds().right() - dock_inset: | 606 dock_container_->bounds().right() - dock_inset: |
| 487 dock_container_->bounds().x(), | 607 dock_container_->bounds().x(), |
| 488 dock_container_->bounds().y(), | 608 dock_container_->bounds().y(), |
| 489 dock_inset, | 609 dock_inset, |
| 490 dock_container_->bounds().height()); | 610 dock_container_->bounds().height()); |
| 491 docked_bounds_ = bounds + | 611 docked_bounds_ = bounds + |
| 492 dock_container_->GetBoundsInScreen().OffsetFromOrigin(); | 612 dock_container_->GetBoundsInScreen().OffsetFromOrigin(); |
| 493 LOG(INFO) << "Dock bounds set to " << docked_bounds_.ToString(); | 613 LOG(INFO) << "Dock bounds set to " << docked_bounds_.ToString(); |
| 494 FOR_EACH_OBSERVER( | 614 FOR_EACH_OBSERVER( |
| 495 DockedWindowLayoutManagerObserver, | 615 DockedWindowLayoutManagerObserver, |
| 496 observer_list_, | 616 observer_list_, |
| 497 OnDockBoundsChanging(bounds)); | 617 OnDockBoundsChanging(bounds)); |
| 498 } | 618 } |
| 499 | 619 |
| 500 void DockedWindowLayoutManager::UpdateStacking(aura::Window* active_window) { | 620 void DockedWindowLayoutManager::UpdateStacking(aura::Window* active_window) { |
| 501 // TODO(varkha): Implement restacking to ensure that all docked windows are at | 621 if (!active_window) { |
| 502 // least partially visible and selectable. | 622 if (!last_active_) |
| 623 return; | |
| 624 active_window = last_active_; | |
| 625 } | |
| 626 | |
| 627 // We want to to stack the windows like a deck of cards: | |
| 628 // ,--,--,--,-------.--.--. | |
| 629 // | | | | | | | | |
| 630 // | | | | | | | | |
|
flackr
2013/07/16 22:05:45
nit: Should be a vertical deck of cards.
varkha
2013/07/18 21:56:59
Done.
| |
| 631 // | |
| 632 // We use the middle of each window to figure out how to stack the window. | |
| 633 // This allows us to update the stacking when a window is being dragged around | |
| 634 // by the titlebar. | |
| 635 std::map<int, aura::Window*> window_ordering; | |
| 636 for (aura::Window::Windows::const_iterator it = | |
| 637 dock_container_->children().begin(); | |
| 638 it != dock_container_->children().end(); ++it) { | |
| 639 gfx::Rect bounds = (*it)->bounds(); | |
| 640 window_ordering.insert(std::make_pair(bounds.y() + bounds.height() / 2, | |
| 641 *it)); | |
| 642 } | |
| 643 // Consider windows that were formerly children of the |dock_container_| | |
| 644 // when fanning out other child windows. | |
| 645 if (dragged_former_child_) { | |
| 646 gfx::Rect bounds = dragged_former_child_->bounds(); | |
| 647 window_ordering.insert(std::make_pair(bounds.y() + bounds.height() / 2, | |
| 648 dragged_former_child_)); | |
| 649 } | |
| 650 | |
| 651 | |
|
flackr
2013/07/16 22:05:45
nit: Only one empty line.
varkha
2013/07/18 21:56:59
Done.
| |
| 652 aura::Window* previous_window = NULL; | |
| 653 for (std::map<int, aura::Window*>::const_iterator it = | |
| 654 window_ordering.begin(); | |
| 655 it != window_ordering.end() && it->second != active_window; ++it) { | |
|
flackr
2013/07/16 22:05:45
How about using the midpoint of the active window
varkha
2013/07/18 21:56:59
Done.
| |
| 656 if (previous_window && previous_window->parent() == dock_container_) | |
| 657 dock_container_->StackChildAbove(it->second, previous_window); | |
| 658 previous_window = it->second; | |
| 659 } | |
| 660 | |
| 661 previous_window = NULL; | |
| 662 for (std::map<int, aura::Window*>::const_reverse_iterator it = | |
| 663 window_ordering.rbegin(); | |
| 664 it != window_ordering.rend() && it->second != active_window; ++it) { | |
| 665 if (previous_window && previous_window->parent() == dock_container_) | |
| 666 dock_container_->StackChildAbove(it->second, previous_window); | |
| 667 previous_window = it->second; | |
| 668 } | |
| 669 | |
| 670 if (active_window && active_window->parent() == dock_container_) | |
| 671 dock_container_->StackChildAtTop(active_window); | |
| 672 if (dragged_window_ && dragged_window_->parent() == dock_container_) | |
| 673 dock_container_->StackChildAtTop(dragged_window_); | |
| 674 last_active_ = active_window; | |
| 503 } | 675 } |
| 504 | 676 |
| 505 //////////////////////////////////////////////////////////////////////////////// | 677 //////////////////////////////////////////////////////////////////////////////// |
| 506 // keyboard::KeyboardControllerObserver implementation: | 678 // keyboard::KeyboardControllerObserver implementation: |
| 507 | 679 |
| 508 void DockedWindowLayoutManager::OnKeyboardBoundsChanging( | 680 void DockedWindowLayoutManager::OnKeyboardBoundsChanging( |
| 509 const gfx::Rect& keyboard_bounds) { | 681 const gfx::Rect& keyboard_bounds) { |
| 510 // This bounds change will have caused a change to the Shelf which does not | 682 // This bounds change will have caused a change to the Shelf which does not |
| 511 // propagate automatically to this class, so manually recalculate bounds. | 683 // propagate automatically to this class, so manually recalculate bounds. |
| 512 UpdateDockBounds(); | 684 UpdateDockBounds(); |
| 513 } | 685 } |
| 514 | 686 |
| 515 } // namespace internal | 687 } // namespace internal |
| 516 } // namespace ash | 688 } // namespace ash |
| OLD | NEW |