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