| 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 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 | 94 |
| 95 DISALLOW_COPY_AND_ASSIGN(CalloutWidgetBackground); | 95 DISALLOW_COPY_AND_ASSIGN(CalloutWidgetBackground); |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 struct VisiblePanelPositionInfo { | 98 struct VisiblePanelPositionInfo { |
| 99 VisiblePanelPositionInfo() | 99 VisiblePanelPositionInfo() |
| 100 : min_major(0), | 100 : min_major(0), |
| 101 max_major(0), | 101 max_major(0), |
| 102 major_pos(0), | 102 major_pos(0), |
| 103 major_length(0), | 103 major_length(0), |
| 104 window(NULL), | 104 window(nullptr), |
| 105 slide_in(false) {} | 105 slide_in(false) {} |
| 106 | 106 |
| 107 int min_major; | 107 int min_major; |
| 108 int max_major; | 108 int max_major; |
| 109 int major_pos; | 109 int major_pos; |
| 110 int major_length; | 110 int major_length; |
| 111 WmWindow* window; | 111 WmWindow* window; |
| 112 bool slide_in; | 112 bool slide_in; |
| 113 }; | 113 }; |
| 114 | 114 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 } | 238 } |
| 239 | 239 |
| 240 //////////////////////////////////////////////////////////////////////////////// | 240 //////////////////////////////////////////////////////////////////////////////// |
| 241 // PanelLayoutManager public implementation: | 241 // PanelLayoutManager public implementation: |
| 242 PanelLayoutManager::PanelLayoutManager(WmWindow* panel_container) | 242 PanelLayoutManager::PanelLayoutManager(WmWindow* panel_container) |
| 243 : panel_container_(panel_container), | 243 : panel_container_(panel_container), |
| 244 root_window_controller_(panel_container->GetRootWindowController()), | 244 root_window_controller_(panel_container->GetRootWindowController()), |
| 245 in_add_window_(false), | 245 in_add_window_(false), |
| 246 in_layout_(false), | 246 in_layout_(false), |
| 247 show_callout_widgets_(true), | 247 show_callout_widgets_(true), |
| 248 dragged_panel_(NULL), | 248 dragged_panel_(nullptr), |
| 249 shelf_(nullptr), | 249 shelf_(nullptr), |
| 250 last_active_panel_(NULL), | 250 last_active_panel_(nullptr), |
| 251 keyboard_observer_(this), |
| 251 weak_factory_(this) { | 252 weak_factory_(this) { |
| 252 DCHECK(panel_container); | 253 DCHECK(panel_container); |
| 253 WmShell* shell = panel_container->GetShell(); | 254 WmShell* shell = panel_container->GetShell(); |
| 254 Shell::GetInstance()->activation_client()->AddObserver(this); | 255 Shell::GetInstance()->activation_client()->AddObserver(this); |
| 255 shell->AddDisplayObserver(this); | 256 shell->AddDisplayObserver(this); |
| 256 Shell::GetInstance()->AddShellObserver(this); | 257 Shell::GetInstance()->AddShellObserver(this); |
| 257 } | 258 } |
| 258 | 259 |
| 259 PanelLayoutManager::~PanelLayoutManager() { | 260 PanelLayoutManager::~PanelLayoutManager() { |
| 260 Shutdown(); | 261 Shutdown(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 287 Shell::GetInstance()->RemoveShellObserver(this); | 288 Shell::GetInstance()->RemoveShellObserver(this); |
| 288 } | 289 } |
| 289 | 290 |
| 290 void PanelLayoutManager::StartDragging(WmWindow* panel) { | 291 void PanelLayoutManager::StartDragging(WmWindow* panel) { |
| 291 DCHECK(!dragged_panel_); | 292 DCHECK(!dragged_panel_); |
| 292 dragged_panel_ = panel; | 293 dragged_panel_ = panel; |
| 293 Relayout(); | 294 Relayout(); |
| 294 } | 295 } |
| 295 | 296 |
| 296 void PanelLayoutManager::FinishDragging() { | 297 void PanelLayoutManager::FinishDragging() { |
| 297 dragged_panel_ = NULL; | 298 dragged_panel_ = nullptr; |
| 298 Relayout(); | 299 Relayout(); |
| 299 } | 300 } |
| 300 | 301 |
| 301 void PanelLayoutManager::SetShelf(WmShelf* shelf) { | 302 void PanelLayoutManager::SetShelf(WmShelf* shelf) { |
| 302 DCHECK(!shelf_); | 303 DCHECK(!shelf_); |
| 303 shelf_ = shelf; | 304 shelf_ = shelf; |
| 304 shelf_->AddObserver(this); | 305 shelf_->AddObserver(this); |
| 305 WillChangeVisibilityState(shelf_->GetVisibilityState()); | 306 WillChangeVisibilityState(shelf_->GetVisibilityState()); |
| 306 } | 307 } |
| 307 | 308 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 if (found != panel_windows_.end()) { | 379 if (found != panel_windows_.end()) { |
| 379 delete found->callout_widget; | 380 delete found->callout_widget; |
| 380 panel_windows_.erase(found); | 381 panel_windows_.erase(found); |
| 381 } | 382 } |
| 382 if (restore_windows_on_shelf_visible_) | 383 if (restore_windows_on_shelf_visible_) |
| 383 restore_windows_on_shelf_visible_->Remove(child->aura_window()); | 384 restore_windows_on_shelf_visible_->Remove(child->aura_window()); |
| 384 child->aura_window()->RemoveObserver(this); | 385 child->aura_window()->RemoveObserver(this); |
| 385 child->GetWindowState()->RemoveObserver(this); | 386 child->GetWindowState()->RemoveObserver(this); |
| 386 | 387 |
| 387 if (dragged_panel_ == child) | 388 if (dragged_panel_ == child) |
| 388 dragged_panel_ = NULL; | 389 dragged_panel_ = nullptr; |
| 389 | 390 |
| 390 if (last_active_panel_ == child) | 391 if (last_active_panel_ == child) |
| 391 last_active_panel_ = NULL; | 392 last_active_panel_ = nullptr; |
| 392 | 393 |
| 393 Relayout(); | 394 Relayout(); |
| 394 } | 395 } |
| 395 | 396 |
| 396 void PanelLayoutManager::OnChildWindowVisibilityChanged(WmWindow* child, | 397 void PanelLayoutManager::OnChildWindowVisibilityChanged(WmWindow* child, |
| 397 bool visible) { | 398 bool visible) { |
| 398 if (visible) | 399 if (visible) |
| 399 child->GetWindowState()->Restore(); | 400 child->GetWindowState()->Restore(); |
| 400 Relayout(); | 401 Relayout(); |
| 401 } | 402 } |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 restore_windows_on_shelf_visible_ = std::move(minimized_windows); | 551 restore_windows_on_shelf_visible_ = std::move(minimized_windows); |
| 551 } | 552 } |
| 552 | 553 |
| 553 void PanelLayoutManager::OnShelfIconPositionsChanged() { | 554 void PanelLayoutManager::OnShelfIconPositionsChanged() { |
| 554 // TODO: As this is called for every animation step now. Relayout needs to be | 555 // TODO: As this is called for every animation step now. Relayout needs to be |
| 555 // updated to use current icon position instead of use the ideal bounds so | 556 // updated to use current icon position instead of use the ideal bounds so |
| 556 // that the panels slide with their icons instead of jumping. | 557 // that the panels slide with their icons instead of jumping. |
| 557 Relayout(); | 558 Relayout(); |
| 558 } | 559 } |
| 559 | 560 |
| 561 void PanelLayoutManager::StartObservingKeyboard( |
| 562 keyboard::KeyboardController* keyboard_controller) { |
| 563 DCHECK(!keyboard_observer_.IsObservingSources()); |
| 564 keyboard_observer_.Add(keyboard_controller); |
| 565 } |
| 566 |
| 567 void PanelLayoutManager::StopObservingKeyboard( |
| 568 keyboard::KeyboardController* keyboard_controller) { |
| 569 if (keyboard_observer_.IsObserving(keyboard_controller)) |
| 570 keyboard_observer_.Remove(keyboard_controller); |
| 571 } |
| 572 |
| 560 //////////////////////////////////////////////////////////////////////////////// | 573 //////////////////////////////////////////////////////////////////////////////// |
| 561 // PanelLayoutManager private implementation: | 574 // PanelLayoutManager private implementation: |
| 562 | 575 |
| 563 void PanelLayoutManager::MinimizePanel(WmWindow* panel) { | 576 void PanelLayoutManager::MinimizePanel(WmWindow* panel) { |
| 564 // Clusterfuzz can trigger panel accelerators before the shelf is created. | 577 // Clusterfuzz can trigger panel accelerators before the shelf is created. |
| 565 // TODO(jamescook): Revert this after http://crbug.com/648964 is fixed. | 578 // TODO(jamescook): Revert this after http://crbug.com/648964 is fixed. |
| 566 if (!shelf_) | 579 if (!shelf_) |
| 567 return; | 580 return; |
| 568 | 581 |
| 569 panel->SetVisibilityAnimationType( | 582 panel->SetVisibilityAnimationType( |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 785 } | 798 } |
| 786 | 799 |
| 787 WmWindow* previous_panel = nullptr; | 800 WmWindow* previous_panel = nullptr; |
| 788 for (std::map<int, WmWindow*>::const_iterator it = window_ordering.begin(); | 801 for (std::map<int, WmWindow*>::const_iterator it = window_ordering.begin(); |
| 789 it != window_ordering.end() && it->second != active_panel; ++it) { | 802 it != window_ordering.end() && it->second != active_panel; ++it) { |
| 790 if (previous_panel) | 803 if (previous_panel) |
| 791 panel_container_->StackChildAbove(it->second, previous_panel); | 804 panel_container_->StackChildAbove(it->second, previous_panel); |
| 792 previous_panel = it->second; | 805 previous_panel = it->second; |
| 793 } | 806 } |
| 794 | 807 |
| 795 previous_panel = NULL; | 808 previous_panel = nullptr; |
| 796 for (std::map<int, WmWindow*>::const_reverse_iterator it = | 809 for (std::map<int, WmWindow*>::const_reverse_iterator it = |
| 797 window_ordering.rbegin(); | 810 window_ordering.rbegin(); |
| 798 it != window_ordering.rend() && it->second != active_panel; ++it) { | 811 it != window_ordering.rend() && it->second != active_panel; ++it) { |
| 799 if (previous_panel) | 812 if (previous_panel) |
| 800 panel_container_->StackChildAbove(it->second, previous_panel); | 813 panel_container_->StackChildAbove(it->second, previous_panel); |
| 801 previous_panel = it->second; | 814 previous_panel = it->second; |
| 802 } | 815 } |
| 803 | 816 |
| 804 panel_container_->StackChildAtTop(active_panel); | 817 panel_container_->StackChildAtTop(active_panel); |
| 805 if (dragged_panel_ && dragged_panel_->GetParent() == panel_container_) | 818 if (dragged_panel_ && dragged_panel_->GetParent() == panel_container_) |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 } else if (panel_state->HasRestoreBounds()) { | 936 } else if (panel_state->HasRestoreBounds()) { |
| 924 // Keyboard hidden, restore original bounds if they exist. | 937 // Keyboard hidden, restore original bounds if they exist. |
| 925 panel->SetBoundsDirect(panel_state->GetRestoreBoundsInScreen()); | 938 panel->SetBoundsDirect(panel_state->GetRestoreBoundsInScreen()); |
| 926 } | 939 } |
| 927 } | 940 } |
| 928 // This bounds change will have caused a change to the Shelf which does not | 941 // This bounds change will have caused a change to the Shelf which does not |
| 929 // propogate automatically to this class, so manually recalculate bounds. | 942 // propogate automatically to this class, so manually recalculate bounds. |
| 930 OnWindowResized(); | 943 OnWindowResized(); |
| 931 } | 944 } |
| 932 | 945 |
| 933 void PanelLayoutManager::OnKeyboardClosed() {} | 946 void PanelLayoutManager::OnKeyboardClosed() { |
| 947 keyboard_observer_.RemoveAll(); |
| 948 } |
| 934 | 949 |
| 935 } // namespace ash | 950 } // namespace ash |
| OLD | NEW |