| 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/shelf/shelf_layout_manager.h" | 5 #include "ash/common/shelf/shelf_layout_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "ash/animation/animation_change_type.h" | 11 #include "ash/animation/animation_change_type.h" |
| 12 #include "ash/common/keyboard/keyboard_observer_register.h" |
| 12 #include "ash/common/session/session_controller.h" | 13 #include "ash/common/session/session_controller.h" |
| 13 #include "ash/common/session/session_state_delegate.h" | 14 #include "ash/common/session/session_state_delegate.h" |
| 14 #include "ash/common/shelf/shelf_constants.h" | 15 #include "ash/common/shelf/shelf_constants.h" |
| 15 #include "ash/common/shelf/shelf_layout_manager_observer.h" | 16 #include "ash/common/shelf/shelf_layout_manager_observer.h" |
| 16 #include "ash/common/shelf/shelf_widget.h" | 17 #include "ash/common/shelf/shelf_widget.h" |
| 17 #include "ash/common/shelf/wm_shelf.h" | 18 #include "ash/common/shelf/wm_shelf.h" |
| 18 #include "ash/common/system/status_area_widget.h" | 19 #include "ash/common/system/status_area_widget.h" |
| 19 #include "ash/common/wm/fullscreen_window_finder.h" | 20 #include "ash/common/wm/fullscreen_window_finder.h" |
| 20 #include "ash/common/wm/mru_window_tracker.h" | 21 #include "ash/common/wm/mru_window_tracker.h" |
| 21 #include "ash/common/wm/window_state.h" | 22 #include "ash/common/wm/window_state.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 87 |
| 87 // UpdateShelfObserver is used to delay updating the background until the | 88 // UpdateShelfObserver is used to delay updating the background until the |
| 88 // animation completes. | 89 // animation completes. |
| 89 class ShelfLayoutManager::UpdateShelfObserver | 90 class ShelfLayoutManager::UpdateShelfObserver |
| 90 : public ui::ImplicitAnimationObserver { | 91 : public ui::ImplicitAnimationObserver { |
| 91 public: | 92 public: |
| 92 explicit UpdateShelfObserver(ShelfLayoutManager* shelf) : shelf_(shelf) { | 93 explicit UpdateShelfObserver(ShelfLayoutManager* shelf) : shelf_(shelf) { |
| 93 shelf_->update_shelf_observer_ = this; | 94 shelf_->update_shelf_observer_ = this; |
| 94 } | 95 } |
| 95 | 96 |
| 96 void Detach() { shelf_ = NULL; } | 97 void Detach() { shelf_ = nullptr; } |
| 97 | 98 |
| 98 void OnImplicitAnimationsCompleted() override { | 99 void OnImplicitAnimationsCompleted() override { |
| 99 if (shelf_) | 100 if (shelf_) |
| 100 shelf_->MaybeUpdateShelfBackground(AnimationChangeType::ANIMATE); | 101 shelf_->MaybeUpdateShelfBackground(AnimationChangeType::ANIMATE); |
| 101 delete this; | 102 delete this; |
| 102 } | 103 } |
| 103 | 104 |
| 104 private: | 105 private: |
| 105 ~UpdateShelfObserver() override { | 106 ~UpdateShelfObserver() override { |
| 106 if (shelf_) | 107 if (shelf_) |
| 107 shelf_->update_shelf_observer_ = NULL; | 108 shelf_->update_shelf_observer_ = nullptr; |
| 108 } | 109 } |
| 109 | 110 |
| 110 // Shelf we're in. NULL if deleted before we're deleted. | 111 // Shelf we're in. nullptr if deleted before we're deleted. |
| 111 ShelfLayoutManager* shelf_; | 112 ShelfLayoutManager* shelf_; |
| 112 | 113 |
| 113 DISALLOW_COPY_AND_ASSIGN(UpdateShelfObserver); | 114 DISALLOW_COPY_AND_ASSIGN(UpdateShelfObserver); |
| 114 }; | 115 }; |
| 115 | 116 |
| 116 ShelfLayoutManager::State::State() | 117 ShelfLayoutManager::State::State() |
| 117 : visibility_state(SHELF_VISIBLE), | 118 : visibility_state(SHELF_VISIBLE), |
| 118 auto_hide_state(SHELF_AUTO_HIDE_HIDDEN), | 119 auto_hide_state(SHELF_AUTO_HIDE_HIDDEN), |
| 119 window_state(wm::WORKSPACE_WINDOW_STATE_DEFAULT), | 120 window_state(wm::WORKSPACE_WINDOW_STATE_DEFAULT), |
| 120 pre_lock_screen_animation_active(false), | 121 pre_lock_screen_animation_active(false), |
| (...skipping 22 matching lines...) Expand all Loading... |
| 143 ShelfLayoutManager::ShelfLayoutManager(ShelfWidget* shelf_widget, | 144 ShelfLayoutManager::ShelfLayoutManager(ShelfWidget* shelf_widget, |
| 144 WmShelf* wm_shelf) | 145 WmShelf* wm_shelf) |
| 145 : updating_bounds_(false), | 146 : updating_bounds_(false), |
| 146 shelf_widget_(shelf_widget), | 147 shelf_widget_(shelf_widget), |
| 147 wm_shelf_(wm_shelf), | 148 wm_shelf_(wm_shelf), |
| 148 window_overlaps_shelf_(false), | 149 window_overlaps_shelf_(false), |
| 149 mouse_over_shelf_when_auto_hide_timer_started_(false), | 150 mouse_over_shelf_when_auto_hide_timer_started_(false), |
| 150 gesture_drag_status_(GESTURE_DRAG_NONE), | 151 gesture_drag_status_(GESTURE_DRAG_NONE), |
| 151 gesture_drag_amount_(0.f), | 152 gesture_drag_amount_(0.f), |
| 152 gesture_drag_auto_hide_state_(SHELF_AUTO_HIDE_SHOWN), | 153 gesture_drag_auto_hide_state_(SHELF_AUTO_HIDE_SHOWN), |
| 153 update_shelf_observer_(NULL), | 154 update_shelf_observer_(nullptr), |
| 154 chromevox_panel_height_(0), | 155 chromevox_panel_height_(0), |
| 155 duration_override_in_ms_(0), | 156 duration_override_in_ms_(0), |
| 156 shelf_background_type_(SHELF_BACKGROUND_OVERLAP) { | 157 shelf_background_type_(SHELF_BACKGROUND_OVERLAP), |
| 158 keyboard_observer_(this) { |
| 157 DCHECK(shelf_widget_); | 159 DCHECK(shelf_widget_); |
| 158 DCHECK(wm_shelf_); | 160 DCHECK(wm_shelf_); |
| 159 Shell::GetInstance()->AddShellObserver(this); | 161 Shell::GetInstance()->AddShellObserver(this); |
| 160 WmShell::Get()->AddLockStateObserver(this); | 162 WmShell::Get()->AddLockStateObserver(this); |
| 161 Shell::GetInstance()->activation_client()->AddObserver(this); | 163 Shell::GetInstance()->activation_client()->AddObserver(this); |
| 162 WmShell::Get()->session_controller()->AddSessionStateObserver(this); | 164 WmShell::Get()->session_controller()->AddSessionStateObserver(this); |
| 163 state_.session_state = | 165 state_.session_state = |
| 164 WmShell::Get()->session_controller()->GetSessionState(); | 166 WmShell::Get()->session_controller()->GetSessionState(); |
| 165 } | 167 } |
| 166 | 168 |
| 167 ShelfLayoutManager::~ShelfLayoutManager() { | 169 ShelfLayoutManager::~ShelfLayoutManager() { |
| 168 if (update_shelf_observer_) | 170 if (update_shelf_observer_) |
| 169 update_shelf_observer_->Detach(); | 171 update_shelf_observer_->Detach(); |
| 170 | 172 |
| 171 for (auto& observer : observers_) | 173 for (auto& observer : observers_) |
| 172 observer.WillDeleteShelfLayoutManager(); | 174 observer.WillDeleteShelfLayoutManager(); |
| 173 Shell::GetInstance()->RemoveShellObserver(this); | 175 Shell::GetInstance()->RemoveShellObserver(this); |
| 174 WmShell::Get()->RemoveLockStateObserver(this); | 176 WmShell::Get()->RemoveLockStateObserver(this); |
| 175 WmShell::Get()->session_controller()->RemoveSessionStateObserver(this); | 177 WmShell::Get()->session_controller()->RemoveSessionStateObserver(this); |
| 176 } | 178 } |
| 177 | 179 |
| 178 void ShelfLayoutManager::PrepareForShutdown() { | 180 void ShelfLayoutManager::PrepareForShutdown() { |
| 179 in_shutdown_ = true; | 181 in_shutdown_ = true; |
| 180 // Stop observing changes to avoid updating a partially destructed shelf. | 182 // Stop observing changes to avoid updating a partially destructed shelf. |
| 181 Shell::GetInstance()->activation_client()->RemoveObserver(this); | 183 Shell::GetInstance()->activation_client()->RemoveObserver(this); |
| 182 } | 184 } |
| 183 | 185 |
| 184 bool ShelfLayoutManager::IsVisible() const { | 186 bool ShelfLayoutManager::IsVisible() const { |
| 185 // status_area_widget() may be NULL during the shutdown. | 187 // status_area_widget() may be nullptr during the shutdown. |
| 186 return shelf_widget_->status_area_widget() && | 188 return shelf_widget_->status_area_widget() && |
| 187 shelf_widget_->status_area_widget()->IsVisible() && | 189 shelf_widget_->status_area_widget()->IsVisible() && |
| 188 (state_.visibility_state == SHELF_VISIBLE || | 190 (state_.visibility_state == SHELF_VISIBLE || |
| 189 (state_.visibility_state == SHELF_AUTO_HIDE && | 191 (state_.visibility_state == SHELF_AUTO_HIDE && |
| 190 state_.auto_hide_state == SHELF_AUTO_HIDE_SHOWN)); | 192 state_.auto_hide_state == SHELF_AUTO_HIDE_SHOWN)); |
| 191 } | 193 } |
| 192 | 194 |
| 193 gfx::Rect ShelfLayoutManager::GetIdealBounds() { | 195 gfx::Rect ShelfLayoutManager::GetIdealBounds() { |
| 194 const int shelf_size = GetShelfConstant(SHELF_SIZE); | 196 const int shelf_size = GetShelfConstant(SHELF_SIZE); |
| 195 WmWindow* shelf_window = WmWindow::Get(shelf_widget_->GetNativeWindow()); | 197 WmWindow* shelf_window = WmWindow::Get(shelf_widget_->GetNativeWindow()); |
| 196 gfx::Rect rect(wm::GetDisplayBoundsInParent(shelf_window)); | 198 gfx::Rect rect(wm::GetDisplayBoundsInParent(shelf_window)); |
| 197 return SelectValueForShelfAlignment( | 199 return SelectValueForShelfAlignment( |
| 198 gfx::Rect(rect.x(), rect.bottom() - shelf_size, rect.width(), shelf_size), | 200 gfx::Rect(rect.x(), rect.bottom() - shelf_size, rect.width(), shelf_size), |
| 199 gfx::Rect(rect.x(), rect.y(), shelf_size, rect.height()), | 201 gfx::Rect(rect.x(), rect.y(), shelf_size, rect.height()), |
| 200 gfx::Rect(rect.right() - shelf_size, rect.y(), shelf_size, | 202 gfx::Rect(rect.right() - shelf_size, rect.y(), shelf_size, |
| 201 rect.height())); | 203 rect.height())); |
| 202 } | 204 } |
| 203 | 205 |
| 204 gfx::Size ShelfLayoutManager::GetPreferredSize() { | 206 gfx::Size ShelfLayoutManager::GetPreferredSize() { |
| 205 TargetBounds target_bounds; | 207 TargetBounds target_bounds; |
| 206 CalculateTargetBounds(state_, &target_bounds); | 208 CalculateTargetBounds(state_, &target_bounds); |
| 207 return target_bounds.shelf_bounds_in_root.size(); | 209 return target_bounds.shelf_bounds_in_root.size(); |
| 208 } | 210 } |
| 209 | 211 |
| 210 void ShelfLayoutManager::LayoutShelfAndUpdateBounds(bool change_work_area) { | 212 void ShelfLayoutManager::LayoutShelfAndUpdateBounds(bool change_work_area) { |
| 211 TargetBounds target_bounds; | 213 TargetBounds target_bounds; |
| 212 CalculateTargetBounds(state_, &target_bounds); | 214 CalculateTargetBounds(state_, &target_bounds); |
| 213 UpdateBoundsAndOpacity(target_bounds, false, change_work_area, NULL); | 215 UpdateBoundsAndOpacity(target_bounds, false, change_work_area, nullptr); |
| 214 | 216 |
| 215 // Update insets in ShelfWindowTargeter when shelf bounds change. | 217 // Update insets in ShelfWindowTargeter when shelf bounds change. |
| 216 for (auto& observer : observers_) | 218 for (auto& observer : observers_) |
| 217 observer.WillChangeVisibilityState(visibility_state()); | 219 observer.WillChangeVisibilityState(visibility_state()); |
| 218 } | 220 } |
| 219 | 221 |
| 220 void ShelfLayoutManager::LayoutShelf() { | 222 void ShelfLayoutManager::LayoutShelf() { |
| 221 LayoutShelfAndUpdateBounds(true); | 223 LayoutShelfAndUpdateBounds(true); |
| 222 } | 224 } |
| 223 | 225 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 void ShelfLayoutManager::OnShelfAutoHideBehaviorChanged(WmWindow* root_window) { | 400 void ShelfLayoutManager::OnShelfAutoHideBehaviorChanged(WmWindow* root_window) { |
| 399 UpdateVisibilityState(); | 401 UpdateVisibilityState(); |
| 400 } | 402 } |
| 401 | 403 |
| 402 void ShelfLayoutManager::OnPinnedStateChanged(WmWindow* pinned_window) { | 404 void ShelfLayoutManager::OnPinnedStateChanged(WmWindow* pinned_window) { |
| 403 // Shelf needs to be hidden on entering to pinned mode, or restored | 405 // Shelf needs to be hidden on entering to pinned mode, or restored |
| 404 // on exiting from pinned mode. | 406 // on exiting from pinned mode. |
| 405 UpdateVisibilityState(); | 407 UpdateVisibilityState(); |
| 406 } | 408 } |
| 407 | 409 |
| 410 void ShelfLayoutManager::OnVirtualKeyboardStateChanged(bool activated, |
| 411 WmWindow* root_window) { |
| 412 UpdateKeyboardObserverFromStateChanged( |
| 413 activated, root_window, |
| 414 WmWindow::Get(shelf_widget_->GetNativeWindow())->GetRootWindow(), |
| 415 &keyboard_observer_); |
| 416 } |
| 417 |
| 408 void ShelfLayoutManager::OnWindowActivated(ActivationReason reason, | 418 void ShelfLayoutManager::OnWindowActivated(ActivationReason reason, |
| 409 aura::Window* gained_active, | 419 aura::Window* gained_active, |
| 410 aura::Window* lost_active) { | 420 aura::Window* lost_active) { |
| 411 UpdateAutoHideStateNow(); | 421 UpdateAutoHideStateNow(); |
| 412 } | 422 } |
| 413 | 423 |
| 414 void ShelfLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { | 424 void ShelfLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { |
| 415 bool keyboard_is_about_to_hide = false; | 425 bool keyboard_is_about_to_hide = false; |
| 416 if (new_bounds.IsEmpty() && !keyboard_bounds_.IsEmpty()) | 426 if (new_bounds.IsEmpty() && !keyboard_bounds_.IsEmpty()) |
| 417 keyboard_is_about_to_hide = true; | 427 keyboard_is_about_to_hide = true; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 428 // On login screen if keyboard has been just hidden, update bounds just once | 438 // On login screen if keyboard has been just hidden, update bounds just once |
| 429 // but ignore target_bounds.work_area_insets since shelf overlaps with login | 439 // but ignore target_bounds.work_area_insets since shelf overlaps with login |
| 430 // window. | 440 // window. |
| 431 if (WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked() && | 441 if (WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked() && |
| 432 keyboard_is_about_to_hide) { | 442 keyboard_is_about_to_hide) { |
| 433 WmWindow* window = WmWindow::Get(shelf_widget_->GetNativeWindow()); | 443 WmWindow* window = WmWindow::Get(shelf_widget_->GetNativeWindow()); |
| 434 WmShell::Get()->SetDisplayWorkAreaInsets(window, gfx::Insets()); | 444 WmShell::Get()->SetDisplayWorkAreaInsets(window, gfx::Insets()); |
| 435 } | 445 } |
| 436 } | 446 } |
| 437 | 447 |
| 438 void ShelfLayoutManager::OnKeyboardClosed() {} | 448 void ShelfLayoutManager::OnKeyboardClosed() { |
| 449 keyboard_observer_.RemoveAll(); |
| 450 } |
| 439 | 451 |
| 440 ShelfBackgroundType ShelfLayoutManager::GetShelfBackgroundType() const { | 452 ShelfBackgroundType ShelfLayoutManager::GetShelfBackgroundType() const { |
| 441 if (state_.pre_lock_screen_animation_active) | 453 if (state_.pre_lock_screen_animation_active) |
| 442 return SHELF_BACKGROUND_DEFAULT; | 454 return SHELF_BACKGROUND_DEFAULT; |
| 443 | 455 |
| 444 // Handle all non active screen states, including OOBE and pre-login. | 456 // Handle all non active screen states, including OOBE and pre-login. |
| 445 if (state_.session_state != session_manager::SessionState::ACTIVE) | 457 if (state_.session_state != session_manager::SessionState::ACTIVE) |
| 446 return SHELF_BACKGROUND_OVERLAP; | 458 return SHELF_BACKGROUND_OVERLAP; |
| 447 | 459 |
| 448 if (state_.visibility_state != SHELF_AUTO_HIDE && | 460 if (state_.visibility_state != SHELF_AUTO_HIDE && |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 // |update_shelf_observer_| deletes itself when the animation is done. | 542 // |update_shelf_observer_| deletes itself when the animation is done. |
| 531 update_shelf_observer_ = new UpdateShelfObserver(this); | 543 update_shelf_observer_ = new UpdateShelfObserver(this); |
| 532 } else { | 544 } else { |
| 533 MaybeUpdateShelfBackground(change_type); | 545 MaybeUpdateShelfBackground(change_type); |
| 534 } | 546 } |
| 535 | 547 |
| 536 TargetBounds target_bounds; | 548 TargetBounds target_bounds; |
| 537 CalculateTargetBounds(state_, &target_bounds); | 549 CalculateTargetBounds(state_, &target_bounds); |
| 538 UpdateBoundsAndOpacity( | 550 UpdateBoundsAndOpacity( |
| 539 target_bounds, true /* animate */, true /* change_work_area */, | 551 target_bounds, true /* animate */, true /* change_work_area */, |
| 540 delay_background_change ? update_shelf_observer_ : NULL); | 552 delay_background_change ? update_shelf_observer_ : nullptr); |
| 541 | 553 |
| 542 // OnAutoHideStateChanged Should be emitted when: | 554 // OnAutoHideStateChanged Should be emitted when: |
| 543 // - firstly state changed to auto-hide from other state | 555 // - firstly state changed to auto-hide from other state |
| 544 // - or, auto_hide_state has changed | 556 // - or, auto_hide_state has changed |
| 545 if ((old_state.visibility_state != state_.visibility_state && | 557 if ((old_state.visibility_state != state_.visibility_state && |
| 546 state_.visibility_state == SHELF_AUTO_HIDE) || | 558 state_.visibility_state == SHELF_AUTO_HIDE) || |
| 547 old_state.auto_hide_state != state_.auto_hide_state) { | 559 old_state.auto_hide_state != state_.auto_hide_state) { |
| 548 for (auto& observer : observers_) | 560 for (auto& observer : observers_) |
| 549 observer.OnAutoHideStateChanged(state_.auto_hide_state); | 561 observer.OnAutoHideStateChanged(state_.auto_hide_state); |
| 550 } | 562 } |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1012 } | 1024 } |
| 1013 | 1025 |
| 1014 // Force the shelf to layout for alignment (bottom if locked, restore the | 1026 // Force the shelf to layout for alignment (bottom if locked, restore the |
| 1015 // previous alignment otherwise). | 1027 // previous alignment otherwise). |
| 1016 if (was_locked != state_.IsScreenLocked()) | 1028 if (was_locked != state_.IsScreenLocked()) |
| 1017 UpdateShelfVisibilityAfterLoginUIChange(); | 1029 UpdateShelfVisibilityAfterLoginUIChange(); |
| 1018 | 1030 |
| 1019 TargetBounds target_bounds; | 1031 TargetBounds target_bounds; |
| 1020 CalculateTargetBounds(state_, &target_bounds); | 1032 CalculateTargetBounds(state_, &target_bounds); |
| 1021 UpdateBoundsAndOpacity(target_bounds, true /* animate */, | 1033 UpdateBoundsAndOpacity(target_bounds, true /* animate */, |
| 1022 true /* change_work_area */, NULL); | 1034 true /* change_work_area */, nullptr); |
| 1023 UpdateVisibilityState(); | 1035 UpdateVisibilityState(); |
| 1024 } | 1036 } |
| 1025 | 1037 |
| 1026 void ShelfLayoutManager::UpdateShelfVisibilityAfterLoginUIChange() { | 1038 void ShelfLayoutManager::UpdateShelfVisibilityAfterLoginUIChange() { |
| 1027 UpdateVisibilityState(); | 1039 UpdateVisibilityState(); |
| 1028 LayoutShelf(); | 1040 LayoutShelf(); |
| 1029 } | 1041 } |
| 1030 | 1042 |
| 1031 float ShelfLayoutManager::ComputeTargetOpacity(const State& state) { | 1043 float ShelfLayoutManager::ComputeTargetOpacity(const State& state) { |
| 1032 if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS || | 1044 if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS || |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1137 gesture_drag_status_ = GESTURE_DRAG_NONE; | 1149 gesture_drag_status_ = GESTURE_DRAG_NONE; |
| 1138 } | 1150 } |
| 1139 | 1151 |
| 1140 void ShelfLayoutManager::CancelGestureDrag() { | 1152 void ShelfLayoutManager::CancelGestureDrag() { |
| 1141 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS; | 1153 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS; |
| 1142 UpdateVisibilityState(); | 1154 UpdateVisibilityState(); |
| 1143 gesture_drag_status_ = GESTURE_DRAG_NONE; | 1155 gesture_drag_status_ = GESTURE_DRAG_NONE; |
| 1144 } | 1156 } |
| 1145 | 1157 |
| 1146 } // namespace ash | 1158 } // namespace ash |
| OLD | NEW |