| 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/common/wm/panels/panel_layout_manager.h" | 5 #include "ash/common/wm/panels/panel_layout_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "ash/common/shelf/wm_shelf.h" | 11 #include "ash/common/shelf/wm_shelf.h" |
| 12 #include "ash/common/shelf/wm_shelf_util.h" | 12 #include "ash/common/shelf/wm_shelf_util.h" |
| 13 #include "ash/common/wm/overview/window_selector_controller.h" | 13 #include "ash/common/wm/overview/window_selector_controller.h" |
| 14 #include "ash/common/wm/window_animation_types.h" | 14 #include "ash/common/wm/window_animation_types.h" |
| 15 #include "ash/common/wm/window_parenting_utils.h" | 15 #include "ash/common/wm/window_parenting_utils.h" |
| 16 #include "ash/common/wm/window_state.h" | 16 #include "ash/common/wm/window_state.h" |
| 17 #include "ash/common/wm_lookup.h" | 17 #include "ash/common/wm_lookup.h" |
| 18 #include "ash/common/wm_shell.h" | 18 #include "ash/common/wm_shell.h" |
| 19 #include "ash/common/wm_window.h" | 19 #include "ash/common/wm_window.h" |
| 20 #include "ash/common/wm_window_property.h" | 20 #include "ash/common/wm_window_property.h" |
| 21 #include "ash/public/cpp/shell_window_ids.h" | 21 #include "ash/public/cpp/shell_window_ids.h" |
| 22 #include "ash/root_window_controller.h" | 22 #include "ash/root_window_controller.h" |
| 23 #include "ash/wm/window_properties.h" |
| 23 #include "base/auto_reset.h" | 24 #include "base/auto_reset.h" |
| 24 #include "third_party/skia/include/core/SkColor.h" | 25 #include "third_party/skia/include/core/SkColor.h" |
| 25 #include "third_party/skia/include/core/SkPath.h" | 26 #include "third_party/skia/include/core/SkPath.h" |
| 26 #include "ui/compositor/scoped_layer_animation_settings.h" | 27 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 27 #include "ui/gfx/canvas.h" | 28 #include "ui/gfx/canvas.h" |
| 28 #include "ui/gfx/geometry/rect.h" | 29 #include "ui/gfx/geometry/rect.h" |
| 29 #include "ui/gfx/geometry/vector2d.h" | 30 #include "ui/gfx/geometry/vector2d.h" |
| 30 #include "ui/views/background.h" | 31 #include "ui/views/background.h" |
| 31 #include "ui/views/widget/widget.h" | 32 #include "ui/views/widget/widget.h" |
| 32 | 33 |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 wm::ReparentTransientChildrenOfChild(child, old_parent, child->GetParent()); | 353 wm::ReparentTransientChildrenOfChild(child, old_parent, child->GetParent()); |
| 353 DCHECK(child->GetParent()->GetShellWindowId() != | 354 DCHECK(child->GetParent()->GetShellWindowId() != |
| 354 kShellWindowId_PanelContainer); | 355 kShellWindowId_PanelContainer); |
| 355 return; | 356 return; |
| 356 } | 357 } |
| 357 PanelInfo panel_info; | 358 PanelInfo panel_info; |
| 358 panel_info.window = child; | 359 panel_info.window = child; |
| 359 panel_info.callout_widget = new PanelCalloutWidget(panel_container_); | 360 panel_info.callout_widget = new PanelCalloutWidget(panel_container_); |
| 360 panel_info.slide_in = child != dragged_panel_; | 361 panel_info.slide_in = child != dragged_panel_; |
| 361 panel_windows_.push_back(panel_info); | 362 panel_windows_.push_back(panel_info); |
| 362 child->AddObserver(this); | 363 child->aura_window()->AddObserver(this); |
| 363 child->GetWindowState()->AddObserver(this); | 364 child->GetWindowState()->AddObserver(this); |
| 364 Relayout(); | 365 Relayout(); |
| 365 } | 366 } |
| 366 | 367 |
| 367 void PanelLayoutManager::OnWillRemoveWindowFromLayout(WmWindow* child) {} | 368 void PanelLayoutManager::OnWillRemoveWindowFromLayout(WmWindow* child) {} |
| 368 | 369 |
| 369 void PanelLayoutManager::OnWindowRemovedFromLayout(WmWindow* child) { | 370 void PanelLayoutManager::OnWindowRemovedFromLayout(WmWindow* child) { |
| 370 if (child->GetType() == ui::wm::WINDOW_TYPE_POPUP) | 371 if (child->GetType() == ui::wm::WINDOW_TYPE_POPUP) |
| 371 return; | 372 return; |
| 372 | 373 |
| 373 PanelList::iterator found = | 374 PanelList::iterator found = |
| 374 std::find(panel_windows_.begin(), panel_windows_.end(), child); | 375 std::find(panel_windows_.begin(), panel_windows_.end(), child); |
| 375 if (found != panel_windows_.end()) { | 376 if (found != panel_windows_.end()) { |
| 376 delete found->callout_widget; | 377 delete found->callout_widget; |
| 377 panel_windows_.erase(found); | 378 panel_windows_.erase(found); |
| 378 } | 379 } |
| 379 if (restore_windows_on_shelf_visible_) | 380 if (restore_windows_on_shelf_visible_) |
| 380 restore_windows_on_shelf_visible_->Remove(child); | 381 restore_windows_on_shelf_visible_->Remove(child->aura_window()); |
| 381 child->RemoveObserver(this); | 382 child->aura_window()->RemoveObserver(this); |
| 382 child->GetWindowState()->RemoveObserver(this); | 383 child->GetWindowState()->RemoveObserver(this); |
| 383 | 384 |
| 384 if (dragged_panel_ == child) | 385 if (dragged_panel_ == child) |
| 385 dragged_panel_ = NULL; | 386 dragged_panel_ = NULL; |
| 386 | 387 |
| 387 if (last_active_panel_ == child) | 388 if (last_active_panel_ == child) |
| 388 last_active_panel_ = NULL; | 389 last_active_panel_ = NULL; |
| 389 | 390 |
| 390 Relayout(); | 391 Relayout(); |
| 391 } | 392 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 } | 446 } |
| 446 | 447 |
| 447 void PanelLayoutManager::OnShelfAlignmentChanged(WmWindow* root_window) { | 448 void PanelLayoutManager::OnShelfAlignmentChanged(WmWindow* root_window) { |
| 448 if (root_window_controller_->GetWindow() == root_window) | 449 if (root_window_controller_->GetWindow() == root_window) |
| 449 Relayout(); | 450 Relayout(); |
| 450 } | 451 } |
| 451 | 452 |
| 452 ///////////////////////////////////////////////////////////////////////////// | 453 ///////////////////////////////////////////////////////////////////////////// |
| 453 // PanelLayoutManager, WindowObserver implementation: | 454 // PanelLayoutManager, WindowObserver implementation: |
| 454 | 455 |
| 455 void PanelLayoutManager::OnWindowPropertyChanged(WmWindow* window, | 456 void PanelLayoutManager::OnWindowPropertyChanged(aura::Window* window, |
| 456 WmWindowProperty property) { | 457 const void* key, |
| 458 intptr_t old) { |
| 457 // Trigger a relayout to position the panels whenever the panel icon is set | 459 // Trigger a relayout to position the panels whenever the panel icon is set |
| 458 // or changes. | 460 // or changes. |
| 459 if (property == WmWindowProperty::SHELF_ID) | 461 if (key == kShelfIDKey) |
| 460 Relayout(); | 462 Relayout(); |
| 461 } | 463 } |
| 462 | 464 |
| 463 ///////////////////////////////////////////////////////////////////////////// | 465 ///////////////////////////////////////////////////////////////////////////// |
| 464 // PanelLayoutManager, WindowStateObserver implementation: | 466 // PanelLayoutManager, WindowStateObserver implementation: |
| 465 | 467 |
| 466 void PanelLayoutManager::OnPostWindowStateTypeChange( | 468 void PanelLayoutManager::OnPostWindowStateTypeChange( |
| 467 wm::WindowState* window_state, | 469 wm::WindowState* window_state, |
| 468 wm::WindowStateType old_type) { | 470 wm::WindowStateType old_type) { |
| 469 // If the shelf is currently hidden then windows will not actually be shown | 471 // If the shelf is currently hidden then windows will not actually be shown |
| 470 // but the set to restore when the shelf becomes visible is updated. | 472 // but the set to restore when the shelf becomes visible is updated. |
| 471 if (restore_windows_on_shelf_visible_) { | 473 if (restore_windows_on_shelf_visible_) { |
| 472 if (window_state->IsMinimized()) { | 474 if (window_state->IsMinimized()) { |
| 473 MinimizePanel(window_state->window()); | 475 MinimizePanel(window_state->window()); |
| 474 restore_windows_on_shelf_visible_->Remove(window_state->window()); | 476 restore_windows_on_shelf_visible_->Remove( |
| 477 window_state->window()->aura_window()); |
| 475 } else { | 478 } else { |
| 476 restore_windows_on_shelf_visible_->Add(window_state->window()); | 479 restore_windows_on_shelf_visible_->Add( |
| 480 window_state->window()->aura_window()); |
| 477 } | 481 } |
| 478 return; | 482 return; |
| 479 } | 483 } |
| 480 | 484 |
| 481 if (window_state->IsMinimized()) | 485 if (window_state->IsMinimized()) |
| 482 MinimizePanel(window_state->window()); | 486 MinimizePanel(window_state->window()); |
| 483 else | 487 else |
| 484 RestorePanel(window_state->window()); | 488 RestorePanel(window_state->window()); |
| 485 } | 489 } |
| 486 | 490 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 508 // PanelLayoutManager, ShelfLayoutManagerObserver implementation: | 512 // PanelLayoutManager, ShelfLayoutManagerObserver implementation: |
| 509 | 513 |
| 510 void PanelLayoutManager::WillChangeVisibilityState( | 514 void PanelLayoutManager::WillChangeVisibilityState( |
| 511 ShelfVisibilityState new_state) { | 515 ShelfVisibilityState new_state) { |
| 512 // On entering / leaving full screen mode the shelf visibility state is | 516 // On entering / leaving full screen mode the shelf visibility state is |
| 513 // changed to / from SHELF_HIDDEN. In this state, panel windows should hide | 517 // changed to / from SHELF_HIDDEN. In this state, panel windows should hide |
| 514 // to allow the full-screen application to use the full screen. | 518 // to allow the full-screen application to use the full screen. |
| 515 bool shelf_hidden = new_state == ash::SHELF_HIDDEN; | 519 bool shelf_hidden = new_state == ash::SHELF_HIDDEN; |
| 516 if (!shelf_hidden) { | 520 if (!shelf_hidden) { |
| 517 if (restore_windows_on_shelf_visible_) { | 521 if (restore_windows_on_shelf_visible_) { |
| 518 std::unique_ptr<WmWindowTracker> restore_windows( | 522 std::unique_ptr<aura::WindowTracker> restore_windows( |
| 519 std::move(restore_windows_on_shelf_visible_)); | 523 std::move(restore_windows_on_shelf_visible_)); |
| 520 for (WmWindow* window : restore_windows->windows()) | 524 for (aura::Window* window : restore_windows->windows()) |
| 521 RestorePanel(window); | 525 RestorePanel(WmWindow::Get(window)); |
| 522 } | 526 } |
| 523 return; | 527 return; |
| 524 } | 528 } |
| 525 | 529 |
| 526 if (restore_windows_on_shelf_visible_) | 530 if (restore_windows_on_shelf_visible_) |
| 527 return; | 531 return; |
| 528 std::unique_ptr<WmWindowTracker> minimized_windows(new WmWindowTracker); | 532 std::unique_ptr<aura::WindowTracker> minimized_windows( |
| 533 new aura::WindowTracker); |
| 529 for (PanelList::iterator iter = panel_windows_.begin(); | 534 for (PanelList::iterator iter = panel_windows_.begin(); |
| 530 iter != panel_windows_.end();) { | 535 iter != panel_windows_.end();) { |
| 531 WmWindow* window = iter->window; | 536 WmWindow* window = iter->window; |
| 532 // Minimizing a panel window may remove it from the panel_windows_ list. | 537 // Minimizing a panel window may remove it from the panel_windows_ list. |
| 533 // Advance the iterator before minimizing it: http://crbug.com/393047. | 538 // Advance the iterator before minimizing it: http://crbug.com/393047. |
| 534 ++iter; | 539 ++iter; |
| 535 if (window != dragged_panel_ && window->IsVisible()) { | 540 if (window != dragged_panel_ && window->IsVisible()) { |
| 536 minimized_windows->Add(window); | 541 minimized_windows->Add(window->aura_window()); |
| 537 window->GetWindowState()->Minimize(); | 542 window->GetWindowState()->Minimize(); |
| 538 } | 543 } |
| 539 } | 544 } |
| 540 restore_windows_on_shelf_visible_ = std::move(minimized_windows); | 545 restore_windows_on_shelf_visible_ = std::move(minimized_windows); |
| 541 } | 546 } |
| 542 | 547 |
| 543 void PanelLayoutManager::OnShelfIconPositionsChanged() { | 548 void PanelLayoutManager::OnShelfIconPositionsChanged() { |
| 544 // TODO: As this is called for every animation step now. Relayout needs to be | 549 // TODO: As this is called for every animation step now. Relayout needs to be |
| 545 // updated to use current icon position instead of use the ideal bounds so | 550 // updated to use current icon position instead of use the ideal bounds so |
| 546 // that the panels slide with their icons instead of jumping. | 551 // that the panels slide with their icons instead of jumping. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 !BoundsAdjacent(panel->GetBounds(), shelf_bounds))) { | 627 !BoundsAdjacent(panel->GetBounds(), shelf_bounds))) { |
| 623 continue; | 628 continue; |
| 624 } | 629 } |
| 625 | 630 |
| 626 // If the shelf is currently hidden (full-screen mode), minimize panel until | 631 // If the shelf is currently hidden (full-screen mode), minimize panel until |
| 627 // full-screen mode is exited. When a panel is dragged from another display | 632 // full-screen mode is exited. When a panel is dragged from another display |
| 628 // the shelf state does not update before the panel is added so we exclude | 633 // the shelf state does not update before the panel is added so we exclude |
| 629 // the dragged panel. | 634 // the dragged panel. |
| 630 if (panel != dragged_panel_ && restore_windows_on_shelf_visible_) { | 635 if (panel != dragged_panel_ && restore_windows_on_shelf_visible_) { |
| 631 panel->GetWindowState()->Minimize(); | 636 panel->GetWindowState()->Minimize(); |
| 632 restore_windows_on_shelf_visible_->Add(panel); | 637 restore_windows_on_shelf_visible_->Add(panel->aura_window()); |
| 633 continue; | 638 continue; |
| 634 } | 639 } |
| 635 | 640 |
| 636 gfx::Rect icon_bounds = shelf_->GetScreenBoundsOfItemIconForWindow(panel); | 641 gfx::Rect icon_bounds = shelf_->GetScreenBoundsOfItemIconForWindow(panel); |
| 637 | 642 |
| 638 // If both the icon width and height are 0 then there is no icon in the | 643 // If both the icon width and height are 0 then there is no icon in the |
| 639 // shelf. If the shelf is hidden, one of the height or width will be | 644 // shelf. If the shelf is hidden, one of the height or width will be |
| 640 // 0 but the position in the shelf and major dimension is still reported | 645 // 0 but the position in the shelf and major dimension is still reported |
| 641 // correctly and the panel can be aligned above where the hidden icon is. | 646 // correctly and the panel can be aligned above where the hidden icon is. |
| 642 if (icon_bounds.width() == 0 && icon_bounds.height() == 0) | 647 if (icon_bounds.width() == 0 && icon_bounds.height() == 0) |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 916 } | 921 } |
| 917 } | 922 } |
| 918 // This bounds change will have caused a change to the Shelf which does not | 923 // This bounds change will have caused a change to the Shelf which does not |
| 919 // propogate automatically to this class, so manually recalculate bounds. | 924 // propogate automatically to this class, so manually recalculate bounds. |
| 920 OnWindowResized(); | 925 OnWindowResized(); |
| 921 } | 926 } |
| 922 | 927 |
| 923 void PanelLayoutManager::OnKeyboardClosed() {} | 928 void PanelLayoutManager::OnKeyboardClosed() {} |
| 924 | 929 |
| 925 } // namespace ash | 930 } // namespace ash |
| OLD | NEW |