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/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 <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "ash/common/material_design/material_design_controller.h" | 11 #include "ash/common/material_design/material_design_controller.h" |
| 12 #include "ash/common/session/session_state_delegate.h" | 12 #include "ash/common/session/session_state_delegate.h" |
| 13 #include "ash/common/shelf/shelf_constants.h" | 13 #include "ash/common/shelf/shelf_constants.h" |
| 14 #include "ash/common/shelf/shelf_delegate.h" | 14 #include "ash/common/shelf/shelf_delegate.h" |
| 15 #include "ash/common/shelf/wm_shelf_util.h" | 15 #include "ash/common/shelf/wm_shelf_util.h" |
| 16 #include "ash/common/shell_window_ids.h" | 16 #include "ash/common/shell_window_ids.h" |
| 17 #include "ash/common/system/status_area_widget.h" | 17 #include "ash/common/system/status_area_widget.h" |
| 18 #include "ash/common/wm/fullscreen_window_finder.h" | 18 #include "ash/common/wm/fullscreen_window_finder.h" |
| 19 #include "ash/common/wm/mru_window_tracker.h" | 19 #include "ash/common/wm/mru_window_tracker.h" |
| 20 #include "ash/common/wm/window_state.h" | 20 #include "ash/common/wm/window_state.h" |
| 21 #include "ash/common/wm/wm_screen_util.h" | 21 #include "ash/common/wm/wm_screen_util.h" |
| 22 #include "ash/common/wm_lookup.h" | 22 #include "ash/common/wm_lookup.h" |
| 23 #include "ash/common/wm_root_window_controller.h" | 23 #include "ash/common/wm_root_window_controller.h" |
| 24 #include "ash/common/wm_root_window_controller_observer.h" | 24 #include "ash/common/wm_root_window_controller_observer.h" |
| 25 #include "ash/common/wm_shell.h" | 25 #include "ash/common/wm_shell.h" |
| 26 #include "ash/common/wm_window.h" | 26 #include "ash/common/wm_window.h" |
| 27 #include "ash/shelf/shelf.h" | 27 #include "ash/shelf/shelf.h" |
| 28 #include "ash/shelf/shelf_layout_manager_observer.h" | 28 #include "ash/shelf/shelf_layout_manager_observer.h" |
| 29 #include "ash/wm/workspace_controller.h" | |
| 30 #include "base/auto_reset.h" | 29 #include "base/auto_reset.h" |
| 31 #include "base/i18n/rtl.h" | 30 #include "base/i18n/rtl.h" |
| 32 #include "ui/compositor/layer.h" | 31 #include "ui/compositor/layer.h" |
| 33 #include "ui/compositor/layer_animation_observer.h" | 32 #include "ui/compositor/layer_animation_observer.h" |
| 34 #include "ui/compositor/layer_animator.h" | 33 #include "ui/compositor/layer_animator.h" |
| 35 #include "ui/compositor/scoped_layer_animation_settings.h" | 34 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 36 #include "ui/display/display.h" | 35 #include "ui/display/display.h" |
| 37 #include "ui/display/screen.h" | 36 #include "ui/display/screen.h" |
| 38 #include "ui/events/event.h" | 37 #include "ui/events/event.h" |
| 39 #include "ui/keyboard/keyboard_util.h" | 38 #include "ui/keyboard/keyboard_util.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 WmRootWindowController* root_window_controller_; | 136 WmRootWindowController* root_window_controller_; |
| 138 | 137 |
| 139 DISALLOW_COPY_AND_ASSIGN(RootWindowControllerObserverImpl); | 138 DISALLOW_COPY_AND_ASSIGN(RootWindowControllerObserverImpl); |
| 140 }; | 139 }; |
| 141 | 140 |
| 142 // ShelfLayoutManager ---------------------------------------------------------- | 141 // ShelfLayoutManager ---------------------------------------------------------- |
| 143 | 142 |
| 144 ShelfLayoutManager::ShelfLayoutManager(ShelfWidget* shelf_widget) | 143 ShelfLayoutManager::ShelfLayoutManager(ShelfWidget* shelf_widget) |
| 145 : updating_bounds_(false), | 144 : updating_bounds_(false), |
| 146 shelf_widget_(shelf_widget), | 145 shelf_widget_(shelf_widget), |
| 147 workspace_controller_(NULL), | |
| 148 window_overlaps_shelf_(false), | 146 window_overlaps_shelf_(false), |
| 149 mouse_over_shelf_when_auto_hide_timer_started_(false), | 147 mouse_over_shelf_when_auto_hide_timer_started_(false), |
| 150 gesture_drag_status_(GESTURE_DRAG_NONE), | 148 gesture_drag_status_(GESTURE_DRAG_NONE), |
| 151 gesture_drag_amount_(0.f), | 149 gesture_drag_amount_(0.f), |
| 152 gesture_drag_auto_hide_state_(SHELF_AUTO_HIDE_SHOWN), | 150 gesture_drag_auto_hide_state_(SHELF_AUTO_HIDE_SHOWN), |
| 153 update_shelf_observer_(NULL), | 151 update_shelf_observer_(NULL), |
| 154 chromevox_panel_height_(0), | 152 chromevox_panel_height_(0), |
| 155 duration_override_in_ms_(0), | 153 duration_override_in_ms_(0), |
| 156 root_window_controller_observer_( | 154 root_window_controller_observer_( |
| 157 new RootWindowControllerObserverImpl(this)) { | 155 new RootWindowControllerObserverImpl(this)) { |
| 158 WmShell::Get()->AddShellObserver(this); | 156 WmShell::Get()->AddShellObserver(this); |
| 159 WmShell::Get()->AddLockStateObserver(this); | 157 WmShell::Get()->AddLockStateObserver(this); |
| 160 WmShell::Get()->AddActivationObserver(this); | 158 WmShell::Get()->AddActivationObserver(this); |
| 161 WmShell::Get()->GetSessionStateDelegate()->AddSessionStateObserver(this); | 159 WmShell::Get()->GetSessionStateDelegate()->AddSessionStateObserver(this); |
| 162 } | 160 } |
| 163 | 161 |
| 164 ShelfLayoutManager::~ShelfLayoutManager() { | 162 ShelfLayoutManager::~ShelfLayoutManager() { |
| 165 if (update_shelf_observer_) | 163 if (update_shelf_observer_) |
| 166 update_shelf_observer_->Detach(); | 164 update_shelf_observer_->Detach(); |
| 167 | 165 |
| 168 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, | 166 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, |
| 169 WillDeleteShelfLayoutManager()); | 167 WillDeleteShelfLayoutManager()); |
| 170 WmShell::Get()->RemoveShellObserver(this); | 168 WmShell::Get()->RemoveShellObserver(this); |
| 171 WmShell::Get()->RemoveLockStateObserver(this); | 169 WmShell::Get()->RemoveLockStateObserver(this); |
| 172 WmShell::Get()->GetSessionStateDelegate()->RemoveSessionStateObserver(this); | 170 WmShell::Get()->GetSessionStateDelegate()->RemoveSessionStateObserver(this); |
| 173 } | 171 } |
| 174 | 172 |
| 175 void ShelfLayoutManager::PrepareForShutdown() { | 173 void ShelfLayoutManager::PrepareForShutdown() { |
| 176 in_shutdown_ = true; | 174 in_shutdown_ = true; |
| 177 set_workspace_controller(nullptr); | |
| 178 // Stop observing changes to avoid updating a partially destructed shelf. | 175 // Stop observing changes to avoid updating a partially destructed shelf. |
| 179 WmShell::Get()->RemoveActivationObserver(this); | 176 WmShell::Get()->RemoveActivationObserver(this); |
| 180 } | 177 } |
| 181 | 178 |
| 182 bool ShelfLayoutManager::IsVisible() const { | 179 bool ShelfLayoutManager::IsVisible() const { |
| 183 // status_area_widget() may be NULL during the shutdown. | 180 // status_area_widget() may be NULL during the shutdown. |
| 184 return shelf_widget_->status_area_widget() && | 181 return shelf_widget_->status_area_widget() && |
| 185 shelf_widget_->status_area_widget()->IsVisible() && | 182 shelf_widget_->status_area_widget()->IsVisible() && |
| 186 (state_.visibility_state == SHELF_VISIBLE || | 183 (state_.visibility_state == SHELF_VISIBLE || |
| 187 (state_.visibility_state == SHELF_AUTO_HIDE && | 184 (state_.visibility_state == SHELF_AUTO_HIDE && |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 221 return SHELF_AUTO_HIDE; | 218 return SHELF_AUTO_HIDE; |
| 222 case SHELF_AUTO_HIDE_BEHAVIOR_NEVER: | 219 case SHELF_AUTO_HIDE_BEHAVIOR_NEVER: |
| 223 return SHELF_VISIBLE; | 220 return SHELF_VISIBLE; |
| 224 case SHELF_AUTO_HIDE_ALWAYS_HIDDEN: | 221 case SHELF_AUTO_HIDE_ALWAYS_HIDDEN: |
| 225 return SHELF_HIDDEN; | 222 return SHELF_HIDDEN; |
| 226 } | 223 } |
| 227 return SHELF_VISIBLE; | 224 return SHELF_VISIBLE; |
| 228 } | 225 } |
| 229 | 226 |
| 230 void ShelfLayoutManager::UpdateVisibilityState() { | 227 void ShelfLayoutManager::UpdateVisibilityState() { |
| 231 // Bail out early when there is no |workspace_controller_|, which happens | 228 WmWindow* shelf_window = WmLookup::Get()->GetWindowForWidget(shelf_widget_); |
| 232 // during shutdown after PrepareForShutdown. Also bail before a shelf exists. | 229 WmRootWindowController* controller = shelf_window->GetRootWindowController(); |
|
James Cook
2016/08/12 01:52:50
optional: I liked the old name better, |controller
msw
2016/08/12 04:01:57
Acknowledged; I'll leave it as-is.
| |
| 233 if (!workspace_controller_ || !shelf_widget_->shelf()) | 230 // Bail out early before the shelf is initialized or after it is destroyed. |
| 231 if (!controller || !shelf_widget_->shelf() || in_shutdown_) | |
| 234 return; | 232 return; |
| 235 | 233 |
| 236 if (state_.is_screen_locked || state_.is_adding_user_screen) { | 234 if (state_.is_screen_locked || state_.is_adding_user_screen) { |
| 237 SetState(SHELF_VISIBLE); | 235 SetState(SHELF_VISIBLE); |
| 238 } else if (WmShell::Get()->IsPinned()) { | 236 } else if (WmShell::Get()->IsPinned()) { |
| 239 SetState(SHELF_HIDDEN); | 237 SetState(SHELF_HIDDEN); |
| 240 } else { | 238 } else { |
| 241 // TODO(zelidrag): Verify shelf drag animation still shows on the device | 239 // TODO(zelidrag): Verify shelf drag animation still shows on the device |
| 242 // when we are in SHELF_AUTO_HIDE_ALWAYS_HIDDEN. | 240 // when we are in SHELF_AUTO_HIDE_ALWAYS_HIDDEN. |
| 243 wm::WorkspaceWindowState window_state( | 241 wm::WorkspaceWindowState window_state( |
| 244 workspace_controller_->GetWindowState()); | 242 controller->GetWorkspaceWindowState()); |
| 245 switch (window_state) { | 243 switch (window_state) { |
| 246 case wm::WORKSPACE_WINDOW_STATE_FULL_SCREEN: { | 244 case wm::WORKSPACE_WINDOW_STATE_FULL_SCREEN: { |
| 247 if (IsShelfHiddenForFullscreen()) { | 245 if (IsShelfHiddenForFullscreen()) { |
| 248 SetState(SHELF_HIDDEN); | 246 SetState(SHELF_HIDDEN); |
| 249 } else { | 247 } else { |
| 250 // The shelf is sometimes not hidden when in immersive fullscreen. | 248 // The shelf is sometimes not hidden when in immersive fullscreen. |
| 251 // Force the shelf to be auto hidden in this case. | 249 // Force the shelf to be auto hidden in this case. |
| 252 SetState(SHELF_AUTO_HIDE); | 250 SetState(SHELF_AUTO_HIDE); |
| 253 } | 251 } |
| 254 break; | 252 break; |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 458 | 456 |
| 459 //////////////////////////////////////////////////////////////////////////////// | 457 //////////////////////////////////////////////////////////////////////////////// |
| 460 // ShelfLayoutManager, private: | 458 // ShelfLayoutManager, private: |
| 461 | 459 |
| 462 ShelfLayoutManager::TargetBounds::TargetBounds() | 460 ShelfLayoutManager::TargetBounds::TargetBounds() |
| 463 : opacity(0.0f), status_opacity(0.0f) {} | 461 : opacity(0.0f), status_opacity(0.0f) {} |
| 464 | 462 |
| 465 ShelfLayoutManager::TargetBounds::~TargetBounds() {} | 463 ShelfLayoutManager::TargetBounds::~TargetBounds() {} |
| 466 | 464 |
| 467 void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) { | 465 void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) { |
| 468 if (!shelf_widget_->GetNativeView()) | |
| 469 return; | |
| 470 | |
| 471 State state; | 466 State state; |
| 472 state.visibility_state = visibility_state; | 467 state.visibility_state = visibility_state; |
| 473 state.auto_hide_state = CalculateAutoHideState(visibility_state); | 468 state.auto_hide_state = CalculateAutoHideState(visibility_state); |
| 474 state.window_state = workspace_controller_ | 469 |
| 475 ? workspace_controller_->GetWindowState() | 470 WmWindow* shelf_window = WmLookup::Get()->GetWindowForWidget(shelf_widget_); |
| 476 : wm::WORKSPACE_WINDOW_STATE_DEFAULT; | 471 WmRootWindowController* controller = shelf_window->GetRootWindowController(); |
| 472 state.window_state = controller ? controller->GetWorkspaceWindowState() | |
| 473 : wm::WORKSPACE_WINDOW_STATE_DEFAULT; | |
| 477 // Preserve the log in screen states. | 474 // Preserve the log in screen states. |
| 478 state.is_adding_user_screen = state_.is_adding_user_screen; | 475 state.is_adding_user_screen = state_.is_adding_user_screen; |
| 479 state.is_screen_locked = state_.is_screen_locked; | 476 state.is_screen_locked = state_.is_screen_locked; |
| 480 | 477 |
| 481 // Force an update because gesture drags affect the shelf bounds and we | 478 // Force an update because gesture drags affect the shelf bounds and we |
| 482 // should animate back to the normal bounds at the end of a gesture. | 479 // should animate back to the normal bounds at the end of a gesture. |
| 483 bool force_update = | 480 bool force_update = |
| 484 (gesture_drag_status_ == GESTURE_DRAG_CANCEL_IN_PROGRESS || | 481 (gesture_drag_status_ == GESTURE_DRAG_CANCEL_IN_PROGRESS || |
| 485 gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS); | 482 gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS); |
| 486 | 483 |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 852 else | 849 else |
| 853 show_shelf_region_in_screen.set_width(kMaxAutoHideShowShelfRegionSize); | 850 show_shelf_region_in_screen.set_width(kMaxAutoHideShowShelfRegionSize); |
| 854 | 851 |
| 855 // TODO: Figure out if we need any special handling when the keyboard is | 852 // TODO: Figure out if we need any special handling when the keyboard is |
| 856 // visible. | 853 // visible. |
| 857 return show_shelf_region_in_screen; | 854 return show_shelf_region_in_screen; |
| 858 } | 855 } |
| 859 | 856 |
| 860 ShelfAutoHideState ShelfLayoutManager::CalculateAutoHideState( | 857 ShelfAutoHideState ShelfLayoutManager::CalculateAutoHideState( |
| 861 ShelfVisibilityState visibility_state) const { | 858 ShelfVisibilityState visibility_state) const { |
| 862 if (visibility_state != SHELF_AUTO_HIDE || !shelf_widget_ || | 859 if (visibility_state != SHELF_AUTO_HIDE || !shelf_widget_ || |
|
James Cook
2016/08/12 01:52:49
optional: Maybe not needed?
msw
2016/08/12 04:01:57
We can remove these separately.
| |
| 863 !shelf_widget_->shelf()) | 860 !shelf_widget_->shelf()) |
| 864 return SHELF_AUTO_HIDE_HIDDEN; | 861 return SHELF_AUTO_HIDE_HIDDEN; |
| 865 | 862 |
| 866 const int64_t shelf_display_id = WmLookup::Get() | 863 const int64_t shelf_display_id = WmLookup::Get() |
| 867 ->GetWindowForWidget(shelf_widget_) | 864 ->GetWindowForWidget(shelf_widget_) |
| 868 ->GetDisplayNearestWindow() | 865 ->GetDisplayNearestWindow() |
| 869 .id(); | 866 .id(); |
| 870 | 867 |
| 871 // Unhide the shelf only on the active screen when the AppList is shown | 868 // Unhide the shelf only on the active screen when the AppList is shown |
| 872 // (crbug.com/312445). | 869 // (crbug.com/312445). |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 955 mouse_over_shelf_when_auto_hide_timer_started_) && | 952 mouse_over_shelf_when_auto_hide_timer_started_) && |
| 956 GetAutoHideShowShelfRegionInScreen().Contains( | 953 GetAutoHideShowShelfRegionInScreen().Contains( |
| 957 cursor_position_in_screen)) { | 954 cursor_position_in_screen)) { |
| 958 return SHELF_AUTO_HIDE_SHOWN; | 955 return SHELF_AUTO_HIDE_SHOWN; |
| 959 } | 956 } |
| 960 | 957 |
| 961 return SHELF_AUTO_HIDE_HIDDEN; | 958 return SHELF_AUTO_HIDE_HIDDEN; |
| 962 } | 959 } |
| 963 | 960 |
| 964 bool ShelfLayoutManager::IsShelfWindow(WmWindow* window) { | 961 bool ShelfLayoutManager::IsShelfWindow(WmWindow* window) { |
| 965 if (!window || !shelf_widget_) | 962 if (!window || !shelf_widget_) |
|
James Cook
2016/08/12 01:52:49
optional: I also wondered if this one was needed.
msw
2016/08/12 04:01:57
We can remove these separately.
| |
| 966 return false; | 963 return false; |
| 967 WmWindow* shelf_window = WmLookup::Get()->GetWindowForWidget(shelf_widget_); | 964 WmWindow* shelf_window = WmLookup::Get()->GetWindowForWidget(shelf_widget_); |
| 968 WmWindow* status_window = | 965 WmWindow* status_window = |
| 969 WmLookup::Get()->GetWindowForWidget(shelf_widget_->status_area_widget()); | 966 WmLookup::Get()->GetWindowForWidget(shelf_widget_->status_area_widget()); |
| 970 return (shelf_window && shelf_window->Contains(window)) || | 967 return (shelf_window && shelf_window->Contains(window)) || |
| 971 (status_window && status_window->Contains(window)); | 968 (status_window && status_window->Contains(window)); |
| 972 } | 969 } |
| 973 | 970 |
| 974 int ShelfLayoutManager::GetWorkAreaInsets(const State& state, int size) const { | 971 int ShelfLayoutManager::GetWorkAreaInsets(const State& state, int size) const { |
| 975 if (state.visibility_state == SHELF_VISIBLE) | 972 if (state.visibility_state == SHELF_VISIBLE) |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1103 gesture.details().velocity_x() < 0); | 1100 gesture.details().velocity_x() < 0); |
| 1104 } | 1101 } |
| 1105 } else { | 1102 } else { |
| 1106 NOTREACHED(); | 1103 NOTREACHED(); |
| 1107 } | 1104 } |
| 1108 | 1105 |
| 1109 if (!should_change) { | 1106 if (!should_change) { |
| 1110 CancelGestureDrag(); | 1107 CancelGestureDrag(); |
| 1111 return; | 1108 return; |
| 1112 } | 1109 } |
| 1113 if (shelf_widget_) { | 1110 if (shelf_widget_) { |
|
James Cook
2016/08/12 01:52:50
optional: This one too.
msw
2016/08/12 04:01:57
We can remove these separately.
| |
| 1114 shelf_widget_->Deactivate(); | 1111 shelf_widget_->Deactivate(); |
| 1115 shelf_widget_->status_area_widget()->Deactivate(); | 1112 shelf_widget_->status_area_widget()->Deactivate(); |
| 1116 } | 1113 } |
| 1117 gesture_drag_auto_hide_state_ = | 1114 gesture_drag_auto_hide_state_ = |
| 1118 gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN | 1115 gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN |
| 1119 ? SHELF_AUTO_HIDE_HIDDEN | 1116 ? SHELF_AUTO_HIDE_HIDDEN |
| 1120 : SHELF_AUTO_HIDE_SHOWN; | 1117 : SHELF_AUTO_HIDE_SHOWN; |
| 1121 ShelfAutoHideBehavior new_auto_hide_behavior = | 1118 ShelfAutoHideBehavior new_auto_hide_behavior = |
| 1122 gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN | 1119 gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN |
| 1123 ? SHELF_AUTO_HIDE_BEHAVIOR_NEVER | 1120 ? SHELF_AUTO_HIDE_BEHAVIOR_NEVER |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1136 gesture_drag_status_ = GESTURE_DRAG_NONE; | 1133 gesture_drag_status_ = GESTURE_DRAG_NONE; |
| 1137 } | 1134 } |
| 1138 | 1135 |
| 1139 void ShelfLayoutManager::CancelGestureDrag() { | 1136 void ShelfLayoutManager::CancelGestureDrag() { |
| 1140 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS; | 1137 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS; |
| 1141 UpdateVisibilityState(); | 1138 UpdateVisibilityState(); |
| 1142 gesture_drag_status_ = GESTURE_DRAG_NONE; | 1139 gesture_drag_status_ = GESTURE_DRAG_NONE; |
| 1143 } | 1140 } |
| 1144 | 1141 |
| 1145 } // namespace ash | 1142 } // namespace ash |
| OLD | NEW |