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 <cstring> | 9 #include <cstring> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "ash/accelerators/accelerator_commands.h" | 13 #include "ash/accelerators/accelerator_commands.h" |
14 #include "ash/ash_switches.h" | 14 #include "ash/ash_switches.h" |
15 #include "ash/root_window_controller.h" | 15 #include "ash/root_window_controller.h" |
16 #include "ash/screen_util.h" | 16 #include "ash/screen_util.h" |
17 #include "ash/session/session_state_delegate.h" | 17 #include "ash/session/session_state_delegate.h" |
18 #include "ash/shelf/shelf.h" | 18 #include "ash/shelf/shelf.h" |
19 #include "ash/shelf/shelf_bezel_event_filter.h" | 19 #include "ash/shelf/shelf_bezel_event_filter.h" |
20 #include "ash/shelf/shelf_constants.h" | 20 #include "ash/shelf/shelf_constants.h" |
21 #include "ash/shelf/shelf_layout_manager_observer.h" | 21 #include "ash/shelf/shelf_layout_manager_observer.h" |
22 #include "ash/shelf/shelf_util.h" | 22 #include "ash/shelf/shelf_util.h" |
23 #include "ash/shelf/shelf_widget.h" | 23 #include "ash/shelf/shelf_widget.h" |
24 #include "ash/shell.h" | 24 #include "ash/shell.h" |
25 #include "ash/shell_window_ids.h" | 25 #include "ash/shell_window_ids.h" |
26 #include "ash/system/status_area_widget.h" | 26 #include "ash/system/status_area_widget.h" |
27 #include "ash/wm/aura/wm_window_aura.h" | |
27 #include "ash/wm/common/window_state.h" | 28 #include "ash/wm/common/window_state.h" |
29 #include "ash/wm/common/wm_root_window_controller.h" | |
30 #include "ash/wm/common/wm_root_window_controller_observer.h" | |
28 #include "ash/wm/gestures/shelf_gesture_handler.h" | 31 #include "ash/wm/gestures/shelf_gesture_handler.h" |
29 #include "ash/wm/lock_state_controller.h" | 32 #include "ash/wm/lock_state_controller.h" |
30 #include "ash/wm/mru_window_tracker.h" | 33 #include "ash/wm/mru_window_tracker.h" |
31 #include "ash/wm/window_animations.h" | 34 #include "ash/wm/window_animations.h" |
32 #include "ash/wm/window_state_aura.h" | 35 #include "ash/wm/window_state_aura.h" |
33 #include "ash/wm/window_util.h" | 36 #include "ash/wm/window_util.h" |
34 #include "ash/wm/workspace_controller.h" | 37 #include "ash/wm/workspace_controller.h" |
35 #include "base/auto_reset.h" | 38 #include "base/auto_reset.h" |
36 #include "base/command_line.h" | 39 #include "base/command_line.h" |
37 #include "base/command_line.h" | 40 #include "base/command_line.h" |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 if (shelf_) | 179 if (shelf_) |
177 shelf_->update_shelf_observer_ = NULL; | 180 shelf_->update_shelf_observer_ = NULL; |
178 } | 181 } |
179 | 182 |
180 // Shelf we're in. NULL if deleted before we're deleted. | 183 // Shelf we're in. NULL if deleted before we're deleted. |
181 ShelfLayoutManager* shelf_; | 184 ShelfLayoutManager* shelf_; |
182 | 185 |
183 DISALLOW_COPY_AND_ASSIGN(UpdateShelfObserver); | 186 DISALLOW_COPY_AND_ASSIGN(UpdateShelfObserver); |
184 }; | 187 }; |
185 | 188 |
189 // ShelfLayoutManager::RootWindowControllerObserverImpl ------------------------ | |
190 | |
191 // NOTE: OnShelfAlignmentChanged() is implemented by way of | |
sky
2016/04/27 20:48:05
This is subtle and a bit unfortunate. But I think
| |
192 // WmRootWindowControllerObserver to avoid ordering issues. The way | |
193 // WmRootWindowControllerObserver is wired in means | |
194 // WmRootWindowControllerObservers may be notified after ShellObservers. | |
James Cook
2016/04/27 23:24:24
The part that I missed in thinking about this was
sky
2016/04/27 23:33:28
I copied what you have here.
| |
195 // By making this code use a WmRootWindowControllerObservers we get sane | |
196 // ordering (or at least ordering as we've always had it in ash). | |
197 class ShelfLayoutManager::RootWindowControllerObserverImpl | |
198 : public wm::WmRootWindowControllerObserver { | |
199 public: | |
200 explicit RootWindowControllerObserverImpl( | |
201 ShelfLayoutManager* shelf_layout_manager) | |
202 : shelf_layout_manager_(shelf_layout_manager) {} | |
203 ~RootWindowControllerObserverImpl() override {} | |
204 | |
205 // WmRootWindowControllerObserver: | |
206 void OnShelfAlignmentChanged() override { | |
207 shelf_layout_manager_->LayoutShelf(); | |
208 } | |
209 | |
210 private: | |
211 ShelfLayoutManager* shelf_layout_manager_; | |
212 | |
213 DISALLOW_COPY_AND_ASSIGN(RootWindowControllerObserverImpl); | |
214 }; | |
215 | |
186 // ShelfLayoutManager ---------------------------------------------------------- | 216 // ShelfLayoutManager ---------------------------------------------------------- |
187 | 217 |
188 ShelfLayoutManager::ShelfLayoutManager(ShelfWidget* shelf) | 218 ShelfLayoutManager::ShelfLayoutManager(ShelfWidget* shelf) |
189 : SnapToPixelLayoutManager(shelf->GetNativeView()->parent()), | 219 : SnapToPixelLayoutManager(shelf->GetNativeView()->parent()), |
190 root_window_(shelf->GetNativeView()->GetRootWindow()), | 220 root_window_(shelf->GetNativeView()->GetRootWindow()), |
191 updating_bounds_(false), | 221 updating_bounds_(false), |
192 shelf_(shelf), | 222 shelf_(shelf), |
193 workspace_controller_(NULL), | 223 workspace_controller_(NULL), |
194 window_overlaps_shelf_(false), | 224 window_overlaps_shelf_(false), |
195 mouse_over_shelf_when_auto_hide_timer_started_(false), | 225 mouse_over_shelf_when_auto_hide_timer_started_(false), |
196 bezel_event_filter_(new ShelfBezelEventFilter(this)), | 226 bezel_event_filter_(new ShelfBezelEventFilter(this)), |
197 gesture_drag_status_(GESTURE_DRAG_NONE), | 227 gesture_drag_status_(GESTURE_DRAG_NONE), |
198 gesture_drag_amount_(0.f), | 228 gesture_drag_amount_(0.f), |
199 gesture_drag_auto_hide_state_(SHELF_AUTO_HIDE_SHOWN), | 229 gesture_drag_auto_hide_state_(SHELF_AUTO_HIDE_SHOWN), |
200 update_shelf_observer_(NULL), | 230 update_shelf_observer_(NULL), |
201 chromevox_panel_height_(0), | 231 chromevox_panel_height_(0), |
202 duration_override_in_ms_(0) { | 232 duration_override_in_ms_(0), |
233 root_window_controller_observer_( | |
234 new RootWindowControllerObserverImpl(this)) { | |
203 Shell::GetInstance()->AddShellObserver(this); | 235 Shell::GetInstance()->AddShellObserver(this); |
236 wm::WmWindowAura::Get(root_window_) | |
237 ->GetRootWindowController() | |
238 ->AddObserver(root_window_controller_observer_.get()); | |
204 Shell::GetInstance()->lock_state_controller()->AddObserver(this); | 239 Shell::GetInstance()->lock_state_controller()->AddObserver(this); |
205 aura::client::GetActivationClient(root_window_)->AddObserver(this); | 240 aura::client::GetActivationClient(root_window_)->AddObserver(this); |
206 Shell::GetInstance()->session_state_delegate()->AddSessionStateObserver(this); | 241 Shell::GetInstance()->session_state_delegate()->AddSessionStateObserver(this); |
207 } | 242 } |
208 | 243 |
209 ShelfLayoutManager::~ShelfLayoutManager() { | 244 ShelfLayoutManager::~ShelfLayoutManager() { |
210 if (update_shelf_observer_) | 245 if (update_shelf_observer_) |
211 update_shelf_observer_->Detach(); | 246 update_shelf_observer_->Detach(); |
212 | 247 |
213 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, WillDeleteShelf()); | 248 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, WillDeleteShelf()); |
214 Shell::GetInstance()->RemoveShellObserver(this); | 249 Shell::GetInstance()->RemoveShellObserver(this); |
215 Shell::GetInstance()->lock_state_controller()->RemoveObserver(this); | 250 Shell::GetInstance()->lock_state_controller()->RemoveObserver(this); |
216 Shell::GetInstance()-> | 251 Shell::GetInstance()-> |
217 session_state_delegate()->RemoveSessionStateObserver(this); | 252 session_state_delegate()->RemoveSessionStateObserver(this); |
253 wm::WmWindowAura::Get(root_window_) | |
254 ->GetRootWindowController() | |
255 ->RemoveObserver(root_window_controller_observer_.get()); | |
218 } | 256 } |
219 | 257 |
220 void ShelfLayoutManager::PrepareForShutdown() { | 258 void ShelfLayoutManager::PrepareForShutdown() { |
221 // Clear all event filters, otherwise sometimes those filters may catch | 259 // Clear all event filters, otherwise sometimes those filters may catch |
222 // synthesized mouse event and cause crashes during the shutdown. | 260 // synthesized mouse event and cause crashes during the shutdown. |
223 set_workspace_controller(NULL); | 261 set_workspace_controller(NULL); |
224 auto_hide_event_filter_.reset(); | 262 auto_hide_event_filter_.reset(); |
225 bezel_event_filter_.reset(); | 263 bezel_event_filter_.reset(); |
226 // Stop observing window change, otherwise we can attempt to update a | 264 // Stop observing window change, otherwise we can attempt to update a |
227 // partially destructed shelf. | 265 // partially destructed shelf. |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
470 } | 508 } |
471 } | 509 } |
472 | 510 |
473 void ShelfLayoutManager::OnLockStateChanged(bool locked) { | 511 void ShelfLayoutManager::OnLockStateChanged(bool locked) { |
474 // Force the shelf to layout for alignment (bottom if locked, restore | 512 // Force the shelf to layout for alignment (bottom if locked, restore |
475 // the previous alignment otherwise). | 513 // the previous alignment otherwise). |
476 state_.is_screen_locked = locked; | 514 state_.is_screen_locked = locked; |
477 UpdateShelfVisibilityAfterLoginUIChange(); | 515 UpdateShelfVisibilityAfterLoginUIChange(); |
478 } | 516 } |
479 | 517 |
480 void ShelfLayoutManager::OnShelfAlignmentChanged(aura::Window* root_window) { | |
481 LayoutShelf(); | |
482 } | |
483 | |
484 void ShelfLayoutManager::OnShelfAutoHideBehaviorChanged( | 518 void ShelfLayoutManager::OnShelfAutoHideBehaviorChanged( |
485 aura::Window* root_window) { | 519 aura::Window* root_window) { |
486 UpdateVisibilityState(); | 520 UpdateVisibilityState(); |
487 } | 521 } |
488 | 522 |
489 void ShelfLayoutManager::OnWindowActivated( | 523 void ShelfLayoutManager::OnWindowActivated( |
490 aura::client::ActivationChangeObserver::ActivationReason reason, | 524 aura::client::ActivationChangeObserver::ActivationReason reason, |
491 aura::Window* gained_active, | 525 aura::Window* gained_active, |
492 aura::Window* lost_active) { | 526 aura::Window* lost_active) { |
493 UpdateAutoHideStateNow(); | 527 UpdateAutoHideStateNow(); |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1101 UpdateBoundsAndOpacity(target_bounds, true, NULL); | 1135 UpdateBoundsAndOpacity(target_bounds, true, NULL); |
1102 UpdateVisibilityState(); | 1136 UpdateVisibilityState(); |
1103 } | 1137 } |
1104 | 1138 |
1105 void ShelfLayoutManager::UpdateShelfVisibilityAfterLoginUIChange() { | 1139 void ShelfLayoutManager::UpdateShelfVisibilityAfterLoginUIChange() { |
1106 UpdateVisibilityState(); | 1140 UpdateVisibilityState(); |
1107 LayoutShelf(); | 1141 LayoutShelf(); |
1108 } | 1142 } |
1109 | 1143 |
1110 } // namespace ash | 1144 } // namespace ash |
OLD | NEW |