| 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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 // On login screen if keyboard has been just hidden, update bounds just once | 429 // 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 | 430 // but ignore target_bounds.work_area_insets since shelf overlaps with login |
| 430 // window. | 431 // window. |
| 431 if (WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked() && | 432 if (WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked() && |
| 432 keyboard_is_about_to_hide) { | 433 keyboard_is_about_to_hide) { |
| 433 WmWindow* window = WmWindow::Get(shelf_widget_->GetNativeWindow()); | 434 WmWindow* window = WmWindow::Get(shelf_widget_->GetNativeWindow()); |
| 434 WmShell::Get()->SetDisplayWorkAreaInsets(window, gfx::Insets()); | 435 WmShell::Get()->SetDisplayWorkAreaInsets(window, gfx::Insets()); |
| 435 } | 436 } |
| 436 } | 437 } |
| 437 | 438 |
| 438 void ShelfLayoutManager::OnKeyboardClosed() {} | 439 void ShelfLayoutManager::OnKeyboardClosed() { |
| 440 keyboard_observer_.RemoveAll(); |
| 441 } |
| 439 | 442 |
| 440 ShelfBackgroundType ShelfLayoutManager::GetShelfBackgroundType() const { | 443 ShelfBackgroundType ShelfLayoutManager::GetShelfBackgroundType() const { |
| 441 if (state_.pre_lock_screen_animation_active) | 444 if (state_.pre_lock_screen_animation_active) |
| 442 return SHELF_BACKGROUND_DEFAULT; | 445 return SHELF_BACKGROUND_DEFAULT; |
| 443 | 446 |
| 444 // Handle all non active screen states, including OOBE and pre-login. | 447 // Handle all non active screen states, including OOBE and pre-login. |
| 445 if (state_.session_state != session_manager::SessionState::ACTIVE) | 448 if (state_.session_state != session_manager::SessionState::ACTIVE) |
| 446 return SHELF_BACKGROUND_OVERLAP; | 449 return SHELF_BACKGROUND_OVERLAP; |
| 447 | 450 |
| 448 if (state_.visibility_state != SHELF_AUTO_HIDE && | 451 if (state_.visibility_state != SHELF_AUTO_HIDE && |
| 449 state_.window_state == wm::WORKSPACE_WINDOW_STATE_MAXIMIZED) { | 452 state_.window_state == wm::WORKSPACE_WINDOW_STATE_MAXIMIZED) { |
| 450 return SHELF_BACKGROUND_MAXIMIZED; | 453 return SHELF_BACKGROUND_MAXIMIZED; |
| 451 } | 454 } |
| 452 | 455 |
| 453 if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS || | 456 if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS || |
| 454 window_overlaps_shelf_ || state_.visibility_state == SHELF_AUTO_HIDE) { | 457 window_overlaps_shelf_ || state_.visibility_state == SHELF_AUTO_HIDE) { |
| 455 return SHELF_BACKGROUND_OVERLAP; | 458 return SHELF_BACKGROUND_OVERLAP; |
| 456 } | 459 } |
| 457 | 460 |
| 458 return SHELF_BACKGROUND_DEFAULT; | 461 return SHELF_BACKGROUND_DEFAULT; |
| 459 } | 462 } |
| 460 | 463 |
| 461 void ShelfLayoutManager::SetChromeVoxPanelHeight(int height) { | 464 void ShelfLayoutManager::SetChromeVoxPanelHeight(int height) { |
| 462 chromevox_panel_height_ = height; | 465 chromevox_panel_height_ = height; |
| 463 LayoutShelf(); | 466 LayoutShelf(); |
| 464 } | 467 } |
| 465 | 468 |
| 469 void ShelfLayoutManager::StartObservingKeyboard( |
| 470 keyboard::KeyboardController* keyboard_controller) { |
| 471 DCHECK(!keyboard_observer_.IsObservingSources()); |
| 472 keyboard_observer_.Add(keyboard_controller); |
| 473 } |
| 474 |
| 475 void ShelfLayoutManager::StopObservingKeyboard( |
| 476 keyboard::KeyboardController* keyboard_controller) { |
| 477 if (keyboard_observer_.IsObserving(keyboard_controller)) |
| 478 keyboard_observer_.Remove(keyboard_controller); |
| 479 } |
| 480 |
| 466 //////////////////////////////////////////////////////////////////////////////// | 481 //////////////////////////////////////////////////////////////////////////////// |
| 467 // ShelfLayoutManager, private: | 482 // ShelfLayoutManager, private: |
| 468 | 483 |
| 469 ShelfLayoutManager::TargetBounds::TargetBounds() | 484 ShelfLayoutManager::TargetBounds::TargetBounds() |
| 470 : opacity(0.0f), status_opacity(0.0f) {} | 485 : opacity(0.0f), status_opacity(0.0f) {} |
| 471 | 486 |
| 472 ShelfLayoutManager::TargetBounds::~TargetBounds() {} | 487 ShelfLayoutManager::TargetBounds::~TargetBounds() {} |
| 473 | 488 |
| 474 void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) { | 489 void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) { |
| 475 State state; | 490 State state; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 // |update_shelf_observer_| deletes itself when the animation is done. | 545 // |update_shelf_observer_| deletes itself when the animation is done. |
| 531 update_shelf_observer_ = new UpdateShelfObserver(this); | 546 update_shelf_observer_ = new UpdateShelfObserver(this); |
| 532 } else { | 547 } else { |
| 533 MaybeUpdateShelfBackground(change_type); | 548 MaybeUpdateShelfBackground(change_type); |
| 534 } | 549 } |
| 535 | 550 |
| 536 TargetBounds target_bounds; | 551 TargetBounds target_bounds; |
| 537 CalculateTargetBounds(state_, &target_bounds); | 552 CalculateTargetBounds(state_, &target_bounds); |
| 538 UpdateBoundsAndOpacity( | 553 UpdateBoundsAndOpacity( |
| 539 target_bounds, true /* animate */, true /* change_work_area */, | 554 target_bounds, true /* animate */, true /* change_work_area */, |
| 540 delay_background_change ? update_shelf_observer_ : NULL); | 555 delay_background_change ? update_shelf_observer_ : nullptr); |
| 541 | 556 |
| 542 // OnAutoHideStateChanged Should be emitted when: | 557 // OnAutoHideStateChanged Should be emitted when: |
| 543 // - firstly state changed to auto-hide from other state | 558 // - firstly state changed to auto-hide from other state |
| 544 // - or, auto_hide_state has changed | 559 // - or, auto_hide_state has changed |
| 545 if ((old_state.visibility_state != state_.visibility_state && | 560 if ((old_state.visibility_state != state_.visibility_state && |
| 546 state_.visibility_state == SHELF_AUTO_HIDE) || | 561 state_.visibility_state == SHELF_AUTO_HIDE) || |
| 547 old_state.auto_hide_state != state_.auto_hide_state) { | 562 old_state.auto_hide_state != state_.auto_hide_state) { |
| 548 for (auto& observer : observers_) | 563 for (auto& observer : observers_) |
| 549 observer.OnAutoHideStateChanged(state_.auto_hide_state); | 564 observer.OnAutoHideStateChanged(state_.auto_hide_state); |
| 550 } | 565 } |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1012 } | 1027 } |
| 1013 | 1028 |
| 1014 // Force the shelf to layout for alignment (bottom if locked, restore the | 1029 // Force the shelf to layout for alignment (bottom if locked, restore the |
| 1015 // previous alignment otherwise). | 1030 // previous alignment otherwise). |
| 1016 if (was_locked != state_.IsScreenLocked()) | 1031 if (was_locked != state_.IsScreenLocked()) |
| 1017 UpdateShelfVisibilityAfterLoginUIChange(); | 1032 UpdateShelfVisibilityAfterLoginUIChange(); |
| 1018 | 1033 |
| 1019 TargetBounds target_bounds; | 1034 TargetBounds target_bounds; |
| 1020 CalculateTargetBounds(state_, &target_bounds); | 1035 CalculateTargetBounds(state_, &target_bounds); |
| 1021 UpdateBoundsAndOpacity(target_bounds, true /* animate */, | 1036 UpdateBoundsAndOpacity(target_bounds, true /* animate */, |
| 1022 true /* change_work_area */, NULL); | 1037 true /* change_work_area */, nullptr); |
| 1023 UpdateVisibilityState(); | 1038 UpdateVisibilityState(); |
| 1024 } | 1039 } |
| 1025 | 1040 |
| 1026 void ShelfLayoutManager::UpdateShelfVisibilityAfterLoginUIChange() { | 1041 void ShelfLayoutManager::UpdateShelfVisibilityAfterLoginUIChange() { |
| 1027 UpdateVisibilityState(); | 1042 UpdateVisibilityState(); |
| 1028 LayoutShelf(); | 1043 LayoutShelf(); |
| 1029 } | 1044 } |
| 1030 | 1045 |
| 1031 float ShelfLayoutManager::ComputeTargetOpacity(const State& state) { | 1046 float ShelfLayoutManager::ComputeTargetOpacity(const State& state) { |
| 1032 if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS || | 1047 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; | 1152 gesture_drag_status_ = GESTURE_DRAG_NONE; |
| 1138 } | 1153 } |
| 1139 | 1154 |
| 1140 void ShelfLayoutManager::CancelGestureDrag() { | 1155 void ShelfLayoutManager::CancelGestureDrag() { |
| 1141 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS; | 1156 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS; |
| 1142 UpdateVisibilityState(); | 1157 UpdateVisibilityState(); |
| 1143 gesture_drag_status_ = GESTURE_DRAG_NONE; | 1158 gesture_drag_status_ = GESTURE_DRAG_NONE; |
| 1144 } | 1159 } |
| 1145 | 1160 |
| 1146 } // namespace ash | 1161 } // namespace ash |
| OLD | NEW |