| 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/shelf/shelf_layout_manager.h" | 5 #include "ash/shelf/shelf_layout_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <cstring> | 9 #include <cstring> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 // Bail out early when there is no |workspace_controller_|, which happens | 272 // Bail out early when there is no |workspace_controller_|, which happens |
| 273 // during shutdown after PrepareForShutdown. Also bail before a shelf exists. | 273 // during shutdown after PrepareForShutdown. Also bail before a shelf exists. |
| 274 if (!workspace_controller_ || !shelf_->shelf()) | 274 if (!workspace_controller_ || !shelf_->shelf()) |
| 275 return; | 275 return; |
| 276 | 276 |
| 277 if (state_.is_screen_locked || state_.is_adding_user_screen) { | 277 if (state_.is_screen_locked || state_.is_adding_user_screen) { |
| 278 SetState(SHELF_VISIBLE); | 278 SetState(SHELF_VISIBLE); |
| 279 } else { | 279 } else { |
| 280 // TODO(zelidrag): Verify shelf drag animation still shows on the device | 280 // TODO(zelidrag): Verify shelf drag animation still shows on the device |
| 281 // when we are in SHELF_AUTO_HIDE_ALWAYS_HIDDEN. | 281 // when we are in SHELF_AUTO_HIDE_ALWAYS_HIDDEN. |
| 282 WorkspaceWindowState window_state(workspace_controller_->GetWindowState()); | 282 wm::WorkspaceWindowState window_state( |
| 283 workspace_controller_->GetWindowState()); |
| 283 switch (window_state) { | 284 switch (window_state) { |
| 284 case WORKSPACE_WINDOW_STATE_FULL_SCREEN: { | 285 case wm::WORKSPACE_WINDOW_STATE_FULL_SCREEN: { |
| 285 const aura::Window* fullscreen_window = GetRootWindowController( | 286 const aura::Window* fullscreen_window = GetRootWindowController( |
| 286 root_window_)->GetWindowForFullscreenMode(); | 287 root_window_)->GetWindowForFullscreenMode(); |
| 287 if (fullscreen_window && wm::GetWindowState(fullscreen_window)-> | 288 if (fullscreen_window && wm::GetWindowState(fullscreen_window)-> |
| 288 hide_shelf_when_fullscreen()) { | 289 hide_shelf_when_fullscreen()) { |
| 289 SetState(SHELF_HIDDEN); | 290 SetState(SHELF_HIDDEN); |
| 290 } else { | 291 } else { |
| 291 // The shelf is sometimes not hidden when in immersive fullscreen. | 292 // The shelf is sometimes not hidden when in immersive fullscreen. |
| 292 // Force the shelf to be auto hidden in this case. | 293 // Force the shelf to be auto hidden in this case. |
| 293 SetState(SHELF_AUTO_HIDE); | 294 SetState(SHELF_AUTO_HIDE); |
| 294 } | 295 } |
| 295 break; | 296 break; |
| 296 } | 297 } |
| 297 | 298 |
| 298 case WORKSPACE_WINDOW_STATE_MAXIMIZED: | 299 case wm::WORKSPACE_WINDOW_STATE_MAXIMIZED: |
| 299 SetState(CalculateShelfVisibility()); | 300 SetState(CalculateShelfVisibility()); |
| 300 break; | 301 break; |
| 301 | 302 |
| 302 case WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF: | 303 case wm::WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF: |
| 303 case WORKSPACE_WINDOW_STATE_DEFAULT: | 304 case wm::WORKSPACE_WINDOW_STATE_DEFAULT: |
| 304 SetState(CalculateShelfVisibility()); | 305 SetState(CalculateShelfVisibility()); |
| 305 SetWindowOverlapsShelf(window_state == | 306 SetWindowOverlapsShelf( |
| 306 WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF); | 307 window_state == wm::WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF); |
| 307 break; | 308 break; |
| 308 } | 309 } |
| 309 } | 310 } |
| 310 } | 311 } |
| 311 | 312 |
| 312 void ShelfLayoutManager::UpdateAutoHideState() { | 313 void ShelfLayoutManager::UpdateAutoHideState() { |
| 313 ShelfAutoHideState auto_hide_state = | 314 ShelfAutoHideState auto_hide_state = |
| 314 CalculateAutoHideState(state_.visibility_state); | 315 CalculateAutoHideState(state_.visibility_state); |
| 315 if (auto_hide_state != state_.auto_hide_state) { | 316 if (auto_hide_state != state_.auto_hide_state) { |
| 316 if (auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) { | 317 if (auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) { |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 | 510 |
| 510 ShelfLayoutManager::TargetBounds::~TargetBounds() {} | 511 ShelfLayoutManager::TargetBounds::~TargetBounds() {} |
| 511 | 512 |
| 512 void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) { | 513 void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) { |
| 513 if (!shelf_->GetNativeView()) | 514 if (!shelf_->GetNativeView()) |
| 514 return; | 515 return; |
| 515 | 516 |
| 516 State state; | 517 State state; |
| 517 state.visibility_state = visibility_state; | 518 state.visibility_state = visibility_state; |
| 518 state.auto_hide_state = CalculateAutoHideState(visibility_state); | 519 state.auto_hide_state = CalculateAutoHideState(visibility_state); |
| 519 state.window_state = workspace_controller_ ? | 520 state.window_state = workspace_controller_ |
| 520 workspace_controller_->GetWindowState() : WORKSPACE_WINDOW_STATE_DEFAULT; | 521 ? workspace_controller_->GetWindowState() |
| 522 : wm::WORKSPACE_WINDOW_STATE_DEFAULT; |
| 521 // Preserve the log in screen states. | 523 // Preserve the log in screen states. |
| 522 state.is_adding_user_screen = state_.is_adding_user_screen; | 524 state.is_adding_user_screen = state_.is_adding_user_screen; |
| 523 state.is_screen_locked = state_.is_screen_locked; | 525 state.is_screen_locked = state_.is_screen_locked; |
| 524 | 526 |
| 525 // Force an update because gesture drags affect the shelf bounds and we | 527 // Force an update because gesture drags affect the shelf bounds and we |
| 526 // should animate back to the normal bounds at the end of a gesture. | 528 // should animate back to the normal bounds at the end of a gesture. |
| 527 bool force_update = | 529 bool force_update = |
| 528 (gesture_drag_status_ == GESTURE_DRAG_CANCEL_IN_PROGRESS || | 530 (gesture_drag_status_ == GESTURE_DRAG_CANCEL_IN_PROGRESS || |
| 529 gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS); | 531 gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS); |
| 530 | 532 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 550 | 552 |
| 551 BackgroundAnimatorChangeType change_type = BACKGROUND_CHANGE_ANIMATE; | 553 BackgroundAnimatorChangeType change_type = BACKGROUND_CHANGE_ANIMATE; |
| 552 bool delay_background_change = false; | 554 bool delay_background_change = false; |
| 553 | 555 |
| 554 // Do not animate the background when: | 556 // Do not animate the background when: |
| 555 // - Going from a hidden / auto hidden shelf in fullscreen to a visible shelf | 557 // - Going from a hidden / auto hidden shelf in fullscreen to a visible shelf |
| 556 // in maximized mode. | 558 // in maximized mode. |
| 557 // - Going from an auto hidden shelf in maximized mode to a visible shelf in | 559 // - Going from an auto hidden shelf in maximized mode to a visible shelf in |
| 558 // maximized mode. | 560 // maximized mode. |
| 559 if (state.visibility_state == SHELF_VISIBLE && | 561 if (state.visibility_state == SHELF_VISIBLE && |
| 560 state.window_state == WORKSPACE_WINDOW_STATE_MAXIMIZED && | 562 state.window_state == wm::WORKSPACE_WINDOW_STATE_MAXIMIZED && |
| 561 old_state.visibility_state != SHELF_VISIBLE) { | 563 old_state.visibility_state != SHELF_VISIBLE) { |
| 562 change_type = BACKGROUND_CHANGE_IMMEDIATE; | 564 change_type = BACKGROUND_CHANGE_IMMEDIATE; |
| 563 } else { | 565 } else { |
| 564 // Delay the animation when the shelf was hidden, and has just been made | 566 // Delay the animation when the shelf was hidden, and has just been made |
| 565 // visible (e.g. using a gesture-drag). | 567 // visible (e.g. using a gesture-drag). |
| 566 if (state.visibility_state == SHELF_VISIBLE && | 568 if (state.visibility_state == SHELF_VISIBLE && |
| 567 old_state.visibility_state == SHELF_AUTO_HIDE && | 569 old_state.visibility_state == SHELF_AUTO_HIDE && |
| 568 old_state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) { | 570 old_state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) { |
| 569 delay_background_change = true; | 571 delay_background_change = true; |
| 570 } | 572 } |
| 571 } | 573 } |
| 572 | 574 |
| 573 if (delay_background_change) { | 575 if (delay_background_change) { |
| 574 if (update_shelf_observer_) | 576 if (update_shelf_observer_) |
| 575 update_shelf_observer_->Detach(); | 577 update_shelf_observer_->Detach(); |
| 576 // UpdateShelfBackground deletes itself when the animation is done. | 578 // UpdateShelfBackground deletes itself when the animation is done. |
| 577 update_shelf_observer_ = new UpdateShelfObserver(this); | 579 update_shelf_observer_ = new UpdateShelfObserver(this); |
| 578 } else { | 580 } else { |
| 579 UpdateShelfBackground(change_type); | 581 UpdateShelfBackground(change_type); |
| 580 } | 582 } |
| 581 | 583 |
| 582 shelf_->SetDimsShelf( | 584 shelf_->SetDimsShelf(state.visibility_state == SHELF_VISIBLE && |
| 583 state.visibility_state == SHELF_VISIBLE && | 585 state.window_state == |
| 584 state.window_state == WORKSPACE_WINDOW_STATE_MAXIMIZED); | 586 wm::WORKSPACE_WINDOW_STATE_MAXIMIZED); |
| 585 | 587 |
| 586 TargetBounds target_bounds; | 588 TargetBounds target_bounds; |
| 587 CalculateTargetBounds(state_, &target_bounds); | 589 CalculateTargetBounds(state_, &target_bounds); |
| 588 UpdateBoundsAndOpacity(target_bounds, true, | 590 UpdateBoundsAndOpacity(target_bounds, true, |
| 589 delay_background_change ? update_shelf_observer_ : NULL); | 591 delay_background_change ? update_shelf_observer_ : NULL); |
| 590 | 592 |
| 591 // OnAutoHideStateChanged Should be emitted when: | 593 // OnAutoHideStateChanged Should be emitted when: |
| 592 // - firstly state changed to auto-hide from other state | 594 // - firstly state changed to auto-hide from other state |
| 593 // - or, auto_hide_state has changed | 595 // - or, auto_hide_state has changed |
| 594 if ((old_state.visibility_state != state_.visibility_state && | 596 if ((old_state.visibility_state != state_.visibility_state && |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 void ShelfLayoutManager::UpdateShelfBackground( | 870 void ShelfLayoutManager::UpdateShelfBackground( |
| 869 BackgroundAnimatorChangeType type) { | 871 BackgroundAnimatorChangeType type) { |
| 870 const ShelfBackgroundType background_type(GetShelfBackgroundType()); | 872 const ShelfBackgroundType background_type(GetShelfBackgroundType()); |
| 871 shelf_->SetPaintsBackground(background_type, type); | 873 shelf_->SetPaintsBackground(background_type, type); |
| 872 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, | 874 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, |
| 873 OnBackgroundUpdated(background_type, type)); | 875 OnBackgroundUpdated(background_type, type)); |
| 874 } | 876 } |
| 875 | 877 |
| 876 ShelfBackgroundType ShelfLayoutManager::GetShelfBackgroundType() const { | 878 ShelfBackgroundType ShelfLayoutManager::GetShelfBackgroundType() const { |
| 877 if (state_.visibility_state != SHELF_AUTO_HIDE && | 879 if (state_.visibility_state != SHELF_AUTO_HIDE && |
| 878 state_.window_state == WORKSPACE_WINDOW_STATE_MAXIMIZED) { | 880 state_.window_state == wm::WORKSPACE_WINDOW_STATE_MAXIMIZED) { |
| 879 return SHELF_BACKGROUND_MAXIMIZED; | 881 return SHELF_BACKGROUND_MAXIMIZED; |
| 880 } | 882 } |
| 881 | 883 |
| 882 if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS || | 884 if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS || |
| 883 (!state_.is_screen_locked && !state_.is_adding_user_screen && | 885 (!state_.is_screen_locked && !state_.is_adding_user_screen && |
| 884 window_overlaps_shelf_) || | 886 window_overlaps_shelf_) || |
| 885 (state_.visibility_state == SHELF_AUTO_HIDE)) { | 887 (state_.visibility_state == SHELF_AUTO_HIDE)) { |
| 886 return SHELF_BACKGROUND_OVERLAP; | 888 return SHELF_BACKGROUND_OVERLAP; |
| 887 } | 889 } |
| 888 | 890 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1097 UpdateBoundsAndOpacity(target_bounds, true, NULL); | 1099 UpdateBoundsAndOpacity(target_bounds, true, NULL); |
| 1098 UpdateVisibilityState(); | 1100 UpdateVisibilityState(); |
| 1099 } | 1101 } |
| 1100 | 1102 |
| 1101 void ShelfLayoutManager::UpdateShelfVisibilityAfterLoginUIChange() { | 1103 void ShelfLayoutManager::UpdateShelfVisibilityAfterLoginUIChange() { |
| 1102 UpdateVisibilityState(); | 1104 UpdateVisibilityState(); |
| 1103 LayoutShelf(); | 1105 LayoutShelf(); |
| 1104 } | 1106 } |
| 1105 | 1107 |
| 1106 } // namespace ash | 1108 } // namespace ash |
| OLD | NEW |