Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(138)

Side by Side Diff: ash/shelf/shelf_layout_manager.cc

Issue 2243513004: mash: Partially migrate WorkspaceController to ash common. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix test failures and crashes. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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* root_window_controller =
233 if (!workspace_controller_ || !shelf_widget_->shelf()) 230 shelf_window ? shelf_window->GetRootWindowController() : nullptr;
231 // Bail out early before the shelf is initialized or after it is destroyed.
232 if (!root_window_controller || !shelf_widget_->shelf() || in_shutdown_)
234 return; 233 return;
235 234
236 if (state_.is_screen_locked || state_.is_adding_user_screen) { 235 if (state_.is_screen_locked || state_.is_adding_user_screen) {
237 SetState(SHELF_VISIBLE); 236 SetState(SHELF_VISIBLE);
238 } else if (WmShell::Get()->IsPinned()) { 237 } else if (WmShell::Get()->IsPinned()) {
239 SetState(SHELF_HIDDEN); 238 SetState(SHELF_HIDDEN);
240 } else { 239 } else {
241 // TODO(zelidrag): Verify shelf drag animation still shows on the device 240 // TODO(zelidrag): Verify shelf drag animation still shows on the device
242 // when we are in SHELF_AUTO_HIDE_ALWAYS_HIDDEN. 241 // when we are in SHELF_AUTO_HIDE_ALWAYS_HIDDEN.
243 wm::WorkspaceWindowState window_state( 242 wm::WorkspaceWindowState window_state(
244 workspace_controller_->GetWindowState()); 243 root_window_controller->GetWorkspaceWindowState());
245 switch (window_state) { 244 switch (window_state) {
246 case wm::WORKSPACE_WINDOW_STATE_FULL_SCREEN: { 245 case wm::WORKSPACE_WINDOW_STATE_FULL_SCREEN: {
247 if (IsShelfHiddenForFullscreen()) { 246 if (IsShelfHiddenForFullscreen()) {
248 SetState(SHELF_HIDDEN); 247 SetState(SHELF_HIDDEN);
249 } else { 248 } else {
250 // The shelf is sometimes not hidden when in immersive fullscreen. 249 // The shelf is sometimes not hidden when in immersive fullscreen.
251 // Force the shelf to be auto hidden in this case. 250 // Force the shelf to be auto hidden in this case.
252 SetState(SHELF_AUTO_HIDE); 251 SetState(SHELF_AUTO_HIDE);
253 } 252 }
254 break; 253 break;
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 457
459 //////////////////////////////////////////////////////////////////////////////// 458 ////////////////////////////////////////////////////////////////////////////////
460 // ShelfLayoutManager, private: 459 // ShelfLayoutManager, private:
461 460
462 ShelfLayoutManager::TargetBounds::TargetBounds() 461 ShelfLayoutManager::TargetBounds::TargetBounds()
463 : opacity(0.0f), status_opacity(0.0f) {} 462 : opacity(0.0f), status_opacity(0.0f) {}
464 463
465 ShelfLayoutManager::TargetBounds::~TargetBounds() {} 464 ShelfLayoutManager::TargetBounds::~TargetBounds() {}
466 465
467 void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) { 466 void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) {
468 if (!shelf_widget_->GetNativeView()) 467 WmWindow* shelf_window = WmLookup::Get()->GetWindowForWidget(shelf_widget_);
468 if (!shelf_window)
James Cook 2016/08/11 23:27:35 nit: Is this check really needed? It seems like sh
msw 2016/08/12 00:17:15 Not needed here or above for ash_unittests. A dry-
469 return; 469 return;
470 470
471 State state; 471 State state;
472 state.visibility_state = visibility_state; 472 state.visibility_state = visibility_state;
473 state.auto_hide_state = CalculateAutoHideState(visibility_state); 473 state.auto_hide_state = CalculateAutoHideState(visibility_state);
474 state.window_state = workspace_controller_ 474
475 ? workspace_controller_->GetWindowState() 475 WmRootWindowController* controller = shelf_window->GetRootWindowController();
476 : wm::WORKSPACE_WINDOW_STATE_DEFAULT; 476 state.window_state = controller ? controller->GetWorkspaceWindowState()
477 : wm::WORKSPACE_WINDOW_STATE_DEFAULT;
477 // Preserve the log in screen states. 478 // Preserve the log in screen states.
478 state.is_adding_user_screen = state_.is_adding_user_screen; 479 state.is_adding_user_screen = state_.is_adding_user_screen;
479 state.is_screen_locked = state_.is_screen_locked; 480 state.is_screen_locked = state_.is_screen_locked;
480 481
481 // Force an update because gesture drags affect the shelf bounds and we 482 // 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. 483 // should animate back to the normal bounds at the end of a gesture.
483 bool force_update = 484 bool force_update =
484 (gesture_drag_status_ == GESTURE_DRAG_CANCEL_IN_PROGRESS || 485 (gesture_drag_status_ == GESTURE_DRAG_CANCEL_IN_PROGRESS ||
485 gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS); 486 gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS);
486 487
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 gesture_drag_status_ = GESTURE_DRAG_NONE; 1137 gesture_drag_status_ = GESTURE_DRAG_NONE;
1137 } 1138 }
1138 1139
1139 void ShelfLayoutManager::CancelGestureDrag() { 1140 void ShelfLayoutManager::CancelGestureDrag() {
1140 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS; 1141 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS;
1141 UpdateVisibilityState(); 1142 UpdateVisibilityState();
1142 gesture_drag_status_ = GESTURE_DRAG_NONE; 1143 gesture_drag_status_ = GESTURE_DRAG_NONE;
1143 } 1144 }
1144 1145
1145 } // namespace ash 1146 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698