FamilyInfoFetcher: Use kid.family.readonly scope instead of kid.family
[chromium-blink-merge.git] / ash / shelf / shelf_layout_manager.cc
blob1971f62e63b7e9dcf4eed06afcea088367719c3e
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
3 // found in the LICENSE file.
5 #include "ash/shelf/shelf_layout_manager.h"
7 #include <algorithm>
8 #include <cmath>
9 #include <cstring>
10 #include <string>
11 #include <vector>
13 #include "ash/accelerators/accelerator_commands.h"
14 #include "ash/ash_switches.h"
15 #include "ash/root_window_controller.h"
16 #include "ash/screen_util.h"
17 #include "ash/session/session_state_delegate.h"
18 #include "ash/shelf/shelf.h"
19 #include "ash/shelf/shelf_bezel_event_filter.h"
20 #include "ash/shelf/shelf_constants.h"
21 #include "ash/shelf/shelf_layout_manager_observer.h"
22 #include "ash/shelf/shelf_widget.h"
23 #include "ash/shell.h"
24 #include "ash/shell_window_ids.h"
25 #include "ash/system/status_area_widget.h"
26 #include "ash/wm/gestures/shelf_gesture_handler.h"
27 #include "ash/wm/lock_state_controller.h"
28 #include "ash/wm/mru_window_tracker.h"
29 #include "ash/wm/window_animations.h"
30 #include "ash/wm/window_state.h"
31 #include "ash/wm/window_util.h"
32 #include "ash/wm/workspace_controller.h"
33 #include "base/auto_reset.h"
34 #include "base/command_line.h"
35 #include "base/command_line.h"
36 #include "base/i18n/rtl.h"
37 #include "base/strings/string_number_conversions.h"
38 #include "base/strings/string_util.h"
39 #include "ui/aura/client/cursor_client.h"
40 #include "ui/aura/window_event_dispatcher.h"
41 #include "ui/base/ui_base_switches.h"
42 #include "ui/compositor/layer.h"
43 #include "ui/compositor/layer_animation_observer.h"
44 #include "ui/compositor/layer_animator.h"
45 #include "ui/compositor/scoped_layer_animation_settings.h"
46 #include "ui/events/event.h"
47 #include "ui/events/event_handler.h"
48 #include "ui/gfx/screen.h"
49 #include "ui/keyboard/keyboard_util.h"
50 #include "ui/views/widget/widget.h"
51 #include "ui/wm/public/activation_client.h"
53 namespace ash {
54 namespace {
56 // Delay before showing the shelf. This is after the mouse stops moving.
57 const int kAutoHideDelayMS = 200;
59 // To avoid hiding the shelf when the mouse transitions from a message bubble
60 // into the shelf, the hit test area is enlarged by this amount of pixels to
61 // keep the shelf from hiding.
62 const int kNotificationBubbleGapHeight = 6;
64 // The maximum size of the region on the display opposing the shelf managed by
65 // this ShelfLayoutManager which can trigger showing the shelf.
66 // For instance:
67 // - Primary display is left of secondary display.
68 // - Shelf is left aligned
69 // - This ShelfLayoutManager manages the shelf for the secondary display.
70 // |kMaxAutoHideShowShelfRegionSize| refers to the maximum size of the region
71 // from the right edge of the primary display which can trigger showing the
72 // auto hidden shelf. The region is used to make it easier to trigger showing
73 // the auto hidden shelf when the shelf is on the boundary between displays.
74 const int kMaxAutoHideShowShelfRegionSize = 10;
76 ui::Layer* GetLayer(views::Widget* widget) {
77 return widget->GetNativeView()->layer();
80 } // namespace
82 // static
83 const int ShelfLayoutManager::kWorkspaceAreaVisibleInset = 2;
85 // static
86 const int ShelfLayoutManager::kWorkspaceAreaAutoHideInset = 5;
88 // static
89 const int ShelfLayoutManager::kAutoHideSize = 3;
91 // static
92 const int ShelfLayoutManager::kShelfItemInset = 3;
94 // ShelfLayoutManager::AutoHideEventFilter -------------------------------------
96 // Notifies ShelfLayoutManager any time the mouse moves.
97 class ShelfLayoutManager::AutoHideEventFilter : public ui::EventHandler {
98 public:
99 explicit AutoHideEventFilter(ShelfLayoutManager* shelf);
100 ~AutoHideEventFilter() override;
102 // Returns true if the last mouse event was a mouse drag.
103 bool in_mouse_drag() const { return in_mouse_drag_; }
105 // Overridden from ui::EventHandler:
106 void OnMouseEvent(ui::MouseEvent* event) override;
107 void OnGestureEvent(ui::GestureEvent* event) override;
109 private:
110 ShelfLayoutManager* shelf_;
111 bool in_mouse_drag_;
112 ShelfGestureHandler gesture_handler_;
113 DISALLOW_COPY_AND_ASSIGN(AutoHideEventFilter);
116 ShelfLayoutManager::AutoHideEventFilter::AutoHideEventFilter(
117 ShelfLayoutManager* shelf)
118 : shelf_(shelf),
119 in_mouse_drag_(false) {
120 Shell::GetInstance()->AddPreTargetHandler(this);
123 ShelfLayoutManager::AutoHideEventFilter::~AutoHideEventFilter() {
124 Shell::GetInstance()->RemovePreTargetHandler(this);
127 void ShelfLayoutManager::AutoHideEventFilter::OnMouseEvent(
128 ui::MouseEvent* event) {
129 // This also checks IsShelfWindow() to make sure we don't attempt to hide the
130 // shelf if the mouse down occurs on the shelf.
131 in_mouse_drag_ = (event->type() == ui::ET_MOUSE_DRAGGED ||
132 (in_mouse_drag_ && event->type() != ui::ET_MOUSE_RELEASED &&
133 event->type() != ui::ET_MOUSE_CAPTURE_CHANGED)) &&
134 !shelf_->IsShelfWindow(static_cast<aura::Window*>(event->target()));
135 if (event->type() == ui::ET_MOUSE_MOVED)
136 shelf_->UpdateAutoHideState();
137 return;
140 void ShelfLayoutManager::AutoHideEventFilter::OnGestureEvent(
141 ui::GestureEvent* event) {
142 if (shelf_->IsShelfWindow(static_cast<aura::Window*>(event->target()))) {
143 if (gesture_handler_.ProcessGestureEvent(*event))
144 event->StopPropagation();
148 // ShelfLayoutManager:UpdateShelfObserver --------------------------------------
150 // UpdateShelfObserver is used to delay updating the background until the
151 // animation completes.
152 class ShelfLayoutManager::UpdateShelfObserver
153 : public ui::ImplicitAnimationObserver {
154 public:
155 explicit UpdateShelfObserver(ShelfLayoutManager* shelf) : shelf_(shelf) {
156 shelf_->update_shelf_observer_ = this;
159 void Detach() {
160 shelf_ = NULL;
163 void OnImplicitAnimationsCompleted() override {
164 if (shelf_)
165 shelf_->UpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE);
166 delete this;
169 private:
170 ~UpdateShelfObserver() override {
171 if (shelf_)
172 shelf_->update_shelf_observer_ = NULL;
175 // Shelf we're in. NULL if deleted before we're deleted.
176 ShelfLayoutManager* shelf_;
178 DISALLOW_COPY_AND_ASSIGN(UpdateShelfObserver);
181 // ShelfLayoutManager ----------------------------------------------------------
183 ShelfLayoutManager::ShelfLayoutManager(ShelfWidget* shelf)
184 : SnapToPixelLayoutManager(shelf->GetNativeView()->parent()),
185 root_window_(shelf->GetNativeView()->GetRootWindow()),
186 updating_bounds_(false),
187 auto_hide_behavior_(SHELF_AUTO_HIDE_BEHAVIOR_NEVER),
188 alignment_(SHELF_ALIGNMENT_BOTTOM),
189 shelf_(shelf),
190 workspace_controller_(NULL),
191 window_overlaps_shelf_(false),
192 mouse_over_shelf_when_auto_hide_timer_started_(false),
193 bezel_event_filter_(new ShelfBezelEventFilter(this)),
194 gesture_drag_status_(GESTURE_DRAG_NONE),
195 gesture_drag_amount_(0.f),
196 gesture_drag_auto_hide_state_(SHELF_AUTO_HIDE_SHOWN),
197 update_shelf_observer_(NULL),
198 duration_override_in_ms_(0) {
199 Shell::GetInstance()->AddShellObserver(this);
200 Shell::GetInstance()->lock_state_controller()->AddObserver(this);
201 aura::client::GetActivationClient(root_window_)->AddObserver(this);
202 Shell::GetInstance()->session_state_delegate()->AddSessionStateObserver(this);
205 ShelfLayoutManager::~ShelfLayoutManager() {
206 if (update_shelf_observer_)
207 update_shelf_observer_->Detach();
209 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, WillDeleteShelf());
210 Shell::GetInstance()->RemoveShellObserver(this);
211 Shell::GetInstance()->lock_state_controller()->RemoveObserver(this);
212 Shell::GetInstance()->
213 session_state_delegate()->RemoveSessionStateObserver(this);
216 void ShelfLayoutManager::SetAutoHideBehavior(ShelfAutoHideBehavior behavior) {
217 if (auto_hide_behavior_ == behavior)
218 return;
219 auto_hide_behavior_ = behavior;
220 UpdateVisibilityState();
221 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_,
222 OnAutoHideBehaviorChanged(root_window_,
223 auto_hide_behavior_));
226 void ShelfLayoutManager::PrepareForShutdown() {
227 // Clear all event filters, otherwise sometimes those filters may catch
228 // synthesized mouse event and cause crashes during the shutdown.
229 set_workspace_controller(NULL);
230 auto_hide_event_filter_.reset();
231 bezel_event_filter_.reset();
232 // Stop observing window change, otherwise we can attempt to update a
233 // partially destructed shelf.
234 aura::client::GetActivationClient(root_window_)->RemoveObserver(this);
237 bool ShelfLayoutManager::IsVisible() const {
238 // status_area_widget() may be NULL during the shutdown.
239 return shelf_->status_area_widget() &&
240 shelf_->status_area_widget()->IsVisible() &&
241 (state_.visibility_state == SHELF_VISIBLE ||
242 (state_.visibility_state == SHELF_AUTO_HIDE &&
243 state_.auto_hide_state == SHELF_AUTO_HIDE_SHOWN));
246 bool ShelfLayoutManager::SetAlignment(ShelfAlignment alignment) {
247 if (alignment_ == alignment)
248 return false;
250 alignment_ = alignment;
251 // The shelf will itself move to the bottom while locked or obscured by user
252 // login. If a request is sent to move while being obscured, we postpone the
253 // move until the user session is resumed.
254 if (IsAlignmentLocked())
255 return false;
257 // This should not be called during the lock screen transitions.
258 shelf_->SetAlignment(alignment);
259 LayoutShelf();
260 return true;
263 ShelfAlignment ShelfLayoutManager::GetAlignment() const {
264 // When the screen is locked or a user gets added, the shelf is forced into
265 // bottom alignment.
266 if (IsAlignmentLocked())
267 return SHELF_ALIGNMENT_BOTTOM;
268 return alignment_;
271 gfx::Rect ShelfLayoutManager::GetIdealBounds() {
272 gfx::Rect bounds(
273 ScreenUtil::GetDisplayBoundsInParent(shelf_->GetNativeView()));
274 int width = 0, height = 0;
275 GetShelfSize(&width, &height);
276 return SelectValueForShelfAlignment(
277 gfx::Rect(bounds.x(), bounds.bottom() - height, bounds.width(), height),
278 gfx::Rect(bounds.x(), bounds.y(), width, bounds.height()),
279 gfx::Rect(bounds.right() - width, bounds.y(), width, bounds.height()),
280 gfx::Rect(bounds.x(), bounds.y(), bounds.width(), height));
283 void ShelfLayoutManager::LayoutShelf() {
284 TargetBounds target_bounds;
285 CalculateTargetBounds(state_, &target_bounds);
286 UpdateBoundsAndOpacity(target_bounds, false, NULL);
288 if (shelf_->shelf()) {
289 // This is not part of UpdateBoundsAndOpacity() because
290 // SetShelfViewBounds() sets the bounds immediately and does not animate.
291 // The height of the ShelfView for a horizontal shelf and the width of
292 // the ShelfView for a vertical shelf are set when |shelf_|'s bounds
293 // are changed via UpdateBoundsAndOpacity(). This sets the origin and the
294 // dimension in the other direction.
295 shelf_->shelf()->SetShelfViewBounds(
296 target_bounds.shelf_bounds_in_shelf);
300 ShelfVisibilityState ShelfLayoutManager::CalculateShelfVisibility() {
301 switch(auto_hide_behavior_) {
302 case SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS:
303 return SHELF_AUTO_HIDE;
304 case SHELF_AUTO_HIDE_BEHAVIOR_NEVER:
305 return SHELF_VISIBLE;
306 case SHELF_AUTO_HIDE_ALWAYS_HIDDEN:
307 return SHELF_HIDDEN;
309 return SHELF_VISIBLE;
312 void ShelfLayoutManager::UpdateVisibilityState() {
313 // Bail out early when there is no |workspace_controller_|, which happens
314 // during shutdown after PrepareForShutdown.
315 if (!workspace_controller_)
316 return;
318 if (state_.is_screen_locked || state_.is_adding_user_screen) {
319 SetState(SHELF_VISIBLE);
320 } else {
321 // TODO(zelidrag): Verify shelf drag animation still shows on the device
322 // when we are in SHELF_AUTO_HIDE_ALWAYS_HIDDEN.
323 WorkspaceWindowState window_state(workspace_controller_->GetWindowState());
324 switch (window_state) {
325 case WORKSPACE_WINDOW_STATE_FULL_SCREEN: {
326 const aura::Window* fullscreen_window = GetRootWindowController(
327 root_window_)->GetWindowForFullscreenMode();
328 if (fullscreen_window && wm::GetWindowState(fullscreen_window)->
329 hide_shelf_when_fullscreen()) {
330 SetState(SHELF_HIDDEN);
331 } else {
332 // The shelf is sometimes not hidden when in immersive fullscreen.
333 // Force the shelf to be auto hidden in this case.
334 SetState(SHELF_AUTO_HIDE);
336 break;
339 case WORKSPACE_WINDOW_STATE_MAXIMIZED:
340 SetState(CalculateShelfVisibility());
341 break;
343 case WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF:
344 case WORKSPACE_WINDOW_STATE_DEFAULT:
345 SetState(CalculateShelfVisibility());
346 SetWindowOverlapsShelf(window_state ==
347 WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF);
348 break;
353 void ShelfLayoutManager::UpdateAutoHideState() {
354 ShelfAutoHideState auto_hide_state =
355 CalculateAutoHideState(state_.visibility_state);
356 if (auto_hide_state != state_.auto_hide_state) {
357 if (auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) {
358 // Hides happen immediately.
359 SetState(state_.visibility_state);
360 } else {
361 if (!auto_hide_timer_.IsRunning()) {
362 mouse_over_shelf_when_auto_hide_timer_started_ =
363 shelf_->GetWindowBoundsInScreen().Contains(
364 Shell::GetScreen()->GetCursorScreenPoint());
366 auto_hide_timer_.Start(
367 FROM_HERE,
368 base::TimeDelta::FromMilliseconds(kAutoHideDelayMS),
369 this, &ShelfLayoutManager::UpdateAutoHideStateNow);
371 } else {
372 StopAutoHideTimer();
376 void ShelfLayoutManager::SetWindowOverlapsShelf(bool value) {
377 window_overlaps_shelf_ = value;
378 UpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE);
381 void ShelfLayoutManager::AddObserver(ShelfLayoutManagerObserver* observer) {
382 observers_.AddObserver(observer);
385 void ShelfLayoutManager::RemoveObserver(ShelfLayoutManagerObserver* observer) {
386 observers_.RemoveObserver(observer);
389 ////////////////////////////////////////////////////////////////////////////////
390 // ShelfLayoutManager, Gesture functions:
392 void ShelfLayoutManager::OnGestureEdgeSwipe(const ui::GestureEvent& gesture) {
393 if (visibility_state() == SHELF_AUTO_HIDE) {
394 gesture_drag_auto_hide_state_ = SHELF_AUTO_HIDE_SHOWN;
395 gesture_drag_status_ = GESTURE_DRAG_COMPLETE_IN_PROGRESS;
396 UpdateVisibilityState();
397 gesture_drag_status_ = GESTURE_DRAG_NONE;
401 void ShelfLayoutManager::StartGestureDrag(const ui::GestureEvent& gesture) {
402 gesture_drag_status_ = GESTURE_DRAG_IN_PROGRESS;
403 gesture_drag_amount_ = 0.f;
404 gesture_drag_auto_hide_state_ = visibility_state() == SHELF_AUTO_HIDE ?
405 auto_hide_state() : SHELF_AUTO_HIDE_SHOWN;
406 UpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE);
409 void ShelfLayoutManager::UpdateGestureDrag(
410 const ui::GestureEvent& gesture) {
411 bool horizontal = IsHorizontalAlignment();
412 gesture_drag_amount_ += horizontal ? gesture.details().scroll_y() :
413 gesture.details().scroll_x();
414 LayoutShelf();
417 void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) {
418 bool horizontal = IsHorizontalAlignment();
419 bool should_change = false;
420 if (gesture.type() == ui::ET_GESTURE_SCROLL_END) {
421 // The visibility of the shelf changes only if the shelf was dragged X%
422 // along the correct axis. If the shelf was already visible, then the
423 // direction of the drag does not matter.
424 const float kDragHideThreshold = 0.4f;
425 gfx::Rect bounds = GetIdealBounds();
426 float drag_ratio = fabs(gesture_drag_amount_) /
427 (horizontal ? bounds.height() : bounds.width());
428 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN) {
429 should_change = drag_ratio > kDragHideThreshold;
430 } else {
431 bool correct_direction = false;
432 switch (GetAlignment()) {
433 case SHELF_ALIGNMENT_BOTTOM:
434 case SHELF_ALIGNMENT_RIGHT:
435 correct_direction = gesture_drag_amount_ < 0;
436 break;
437 case SHELF_ALIGNMENT_LEFT:
438 case SHELF_ALIGNMENT_TOP:
439 correct_direction = gesture_drag_amount_ > 0;
440 break;
442 should_change = correct_direction && drag_ratio > kDragHideThreshold;
444 } else if (gesture.type() == ui::ET_SCROLL_FLING_START) {
445 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN) {
446 should_change = horizontal ? fabs(gesture.details().velocity_y()) > 0 :
447 fabs(gesture.details().velocity_x()) > 0;
448 } else {
449 should_change = SelectValueForShelfAlignment(
450 gesture.details().velocity_y() < 0,
451 gesture.details().velocity_x() > 0,
452 gesture.details().velocity_x() < 0,
453 gesture.details().velocity_y() > 0);
455 } else {
456 NOTREACHED();
459 if (!should_change) {
460 CancelGestureDrag();
461 return;
463 if (shelf_) {
464 shelf_->Deactivate();
465 shelf_->status_area_widget()->Deactivate();
467 gesture_drag_auto_hide_state_ =
468 gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN ?
469 SHELF_AUTO_HIDE_HIDDEN : SHELF_AUTO_HIDE_SHOWN;
470 ShelfAutoHideBehavior new_auto_hide_behavior =
471 gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN ?
472 SHELF_AUTO_HIDE_BEHAVIOR_NEVER : SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS;
474 // When in fullscreen and the shelf is forced to be auto hidden, the auto hide
475 // behavior affects neither the visibility state nor the auto hide state. Set
476 // |gesture_drag_status_| to GESTURE_DRAG_COMPLETE_IN_PROGRESS to set the auto
477 // hide state to |gesture_drag_auto_hide_state_|.
478 gesture_drag_status_ = GESTURE_DRAG_COMPLETE_IN_PROGRESS;
479 if (auto_hide_behavior_ != new_auto_hide_behavior)
480 SetAutoHideBehavior(new_auto_hide_behavior);
481 else
482 UpdateVisibilityState();
483 gesture_drag_status_ = GESTURE_DRAG_NONE;
486 void ShelfLayoutManager::CancelGestureDrag() {
487 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS;
488 UpdateVisibilityState();
489 gesture_drag_status_ = GESTURE_DRAG_NONE;
492 void ShelfLayoutManager::SetAnimationDurationOverride(
493 int duration_override_in_ms) {
494 duration_override_in_ms_ = duration_override_in_ms;
497 ////////////////////////////////////////////////////////////////////////////////
498 // ShelfLayoutManager, aura::LayoutManager implementation:
500 void ShelfLayoutManager::OnWindowResized() {
501 LayoutShelf();
504 void ShelfLayoutManager::SetChildBounds(aura::Window* child,
505 const gfx::Rect& requested_bounds) {
506 SnapToPixelLayoutManager::SetChildBounds(child, requested_bounds);
507 // We may contain other widgets (such as frame maximize bubble) but they don't
508 // effect the layout in anyway.
509 if (!updating_bounds_ &&
510 ((shelf_->GetNativeView() == child) ||
511 (shelf_->status_area_widget()->GetNativeView() == child))) {
512 LayoutShelf();
516 void ShelfLayoutManager::OnLockStateChanged(bool locked) {
517 // Force the shelf to layout for alignment (bottom if locked, restore
518 // the previous alignment otherwise).
519 state_.is_screen_locked = locked;
520 UpdateShelfVisibilityAfterLoginUIChange();
523 void ShelfLayoutManager::OnWindowActivated(aura::Window* gained_active,
524 aura::Window* lost_active) {
525 UpdateAutoHideStateNow();
528 bool ShelfLayoutManager::IsHorizontalAlignment() const {
529 return GetAlignment() == SHELF_ALIGNMENT_BOTTOM ||
530 GetAlignment() == SHELF_ALIGNMENT_TOP;
533 // static
534 ShelfLayoutManager* ShelfLayoutManager::ForShelf(aura::Window* window) {
535 ShelfWidget* shelf = RootWindowController::ForShelf(window)->shelf();
536 return shelf ? shelf->shelf_layout_manager() : NULL;
539 ////////////////////////////////////////////////////////////////////////////////
540 // ShelfLayoutManager, private:
542 ShelfLayoutManager::TargetBounds::TargetBounds() : opacity(0.0f) {}
543 ShelfLayoutManager::TargetBounds::~TargetBounds() {}
545 void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) {
546 if (!shelf_->GetNativeView())
547 return;
549 State state;
550 state.visibility_state = visibility_state;
551 state.auto_hide_state = CalculateAutoHideState(visibility_state);
552 state.window_state = workspace_controller_ ?
553 workspace_controller_->GetWindowState() : WORKSPACE_WINDOW_STATE_DEFAULT;
554 // Preserve the log in screen states.
555 state.is_adding_user_screen = state_.is_adding_user_screen;
556 state.is_screen_locked = state_.is_screen_locked;
558 // Force an update because gesture drags affect the shelf bounds and we
559 // should animate back to the normal bounds at the end of a gesture.
560 bool force_update =
561 (gesture_drag_status_ == GESTURE_DRAG_CANCEL_IN_PROGRESS ||
562 gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS);
564 if (!force_update && state_.Equals(state))
565 return; // Nothing changed.
567 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_,
568 WillChangeVisibilityState(visibility_state));
570 if (state.visibility_state == SHELF_AUTO_HIDE) {
571 // When state is SHELF_AUTO_HIDE we need to track when the mouse is over the
572 // shelf to unhide it. AutoHideEventFilter does that for us.
573 if (!auto_hide_event_filter_)
574 auto_hide_event_filter_.reset(new AutoHideEventFilter(this));
575 } else {
576 auto_hide_event_filter_.reset(NULL);
579 StopAutoHideTimer();
581 State old_state = state_;
582 state_ = state;
584 BackgroundAnimatorChangeType change_type = BACKGROUND_CHANGE_ANIMATE;
585 bool delay_background_change = false;
587 // Do not animate the background when:
588 // - Going from a hidden / auto hidden shelf in fullscreen to a visible shelf
589 // in maximized mode.
590 // - Going from an auto hidden shelf in maximized mode to a visible shelf in
591 // maximized mode.
592 if (state.visibility_state == SHELF_VISIBLE &&
593 state.window_state == WORKSPACE_WINDOW_STATE_MAXIMIZED &&
594 old_state.visibility_state != SHELF_VISIBLE) {
595 change_type = BACKGROUND_CHANGE_IMMEDIATE;
596 } else {
597 // Delay the animation when the shelf was hidden, and has just been made
598 // visible (e.g. using a gesture-drag).
599 if (state.visibility_state == SHELF_VISIBLE &&
600 old_state.visibility_state == SHELF_AUTO_HIDE &&
601 old_state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) {
602 delay_background_change = true;
606 if (delay_background_change) {
607 if (update_shelf_observer_)
608 update_shelf_observer_->Detach();
609 // UpdateShelfBackground deletes itself when the animation is done.
610 update_shelf_observer_ = new UpdateShelfObserver(this);
611 } else {
612 UpdateShelfBackground(change_type);
615 shelf_->SetDimsShelf(
616 state.visibility_state == SHELF_VISIBLE &&
617 state.window_state == WORKSPACE_WINDOW_STATE_MAXIMIZED);
619 TargetBounds target_bounds;
620 CalculateTargetBounds(state_, &target_bounds);
621 UpdateBoundsAndOpacity(target_bounds, true,
622 delay_background_change ? update_shelf_observer_ : NULL);
624 // OnAutoHideStateChanged Should be emitted when:
625 // - firstly state changed to auto-hide from other state
626 // - or, auto_hide_state has changed
627 if ((old_state.visibility_state != state_.visibility_state &&
628 state_.visibility_state == SHELF_AUTO_HIDE) ||
629 old_state.auto_hide_state != state_.auto_hide_state) {
630 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_,
631 OnAutoHideStateChanged(state_.auto_hide_state));
635 void ShelfLayoutManager::UpdateBoundsAndOpacity(
636 const TargetBounds& target_bounds,
637 bool animate,
638 ui::ImplicitAnimationObserver* observer) {
639 base::AutoReset<bool> auto_reset_updating_bounds(&updating_bounds_, true);
641 ui::ScopedLayerAnimationSettings shelf_animation_setter(
642 GetLayer(shelf_)->GetAnimator());
643 ui::ScopedLayerAnimationSettings status_animation_setter(
644 GetLayer(shelf_->status_area_widget())->GetAnimator());
645 if (animate) {
646 int duration = duration_override_in_ms_ ? duration_override_in_ms_ :
647 kCrossFadeDurationMS;
648 shelf_animation_setter.SetTransitionDuration(
649 base::TimeDelta::FromMilliseconds(duration));
650 shelf_animation_setter.SetTweenType(gfx::Tween::EASE_OUT);
651 shelf_animation_setter.SetPreemptionStrategy(
652 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
653 status_animation_setter.SetTransitionDuration(
654 base::TimeDelta::FromMilliseconds(duration));
655 status_animation_setter.SetTweenType(gfx::Tween::EASE_OUT);
656 status_animation_setter.SetPreemptionStrategy(
657 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
658 } else {
659 StopAnimating();
660 shelf_animation_setter.SetTransitionDuration(base::TimeDelta());
661 status_animation_setter.SetTransitionDuration(base::TimeDelta());
663 if (observer)
664 status_animation_setter.AddObserver(observer);
666 GetLayer(shelf_)->SetOpacity(target_bounds.opacity);
667 shelf_->SetBounds(ScreenUtil::ConvertRectToScreen(
668 shelf_->GetNativeView()->parent(),
669 target_bounds.shelf_bounds_in_root));
671 GetLayer(shelf_->status_area_widget())->SetOpacity(
672 target_bounds.status_opacity);
674 // Having a window which is visible but does not have an opacity is an
675 // illegal state. We therefore hide the shelf here if required.
676 if (!target_bounds.status_opacity)
677 shelf_->status_area_widget()->Hide();
678 // Setting visibility during an animation causes the visibility property to
679 // animate. Override the animation settings to immediately set the
680 // visibility property. Opacity will still animate.
682 // TODO(harrym): Once status area widget is a child view of shelf
683 // this can be simplified.
684 gfx::Rect status_bounds = target_bounds.status_bounds_in_shelf;
685 status_bounds.set_x(status_bounds.x() +
686 target_bounds.shelf_bounds_in_root.x());
687 status_bounds.set_y(status_bounds.y() +
688 target_bounds.shelf_bounds_in_root.y());
689 shelf_->status_area_widget()->SetBounds(
690 ScreenUtil::ConvertRectToScreen(
691 shelf_->status_area_widget()->GetNativeView()->parent(),
692 status_bounds));
693 if (!state_.is_screen_locked) {
694 gfx::Insets insets;
695 // If user session is blocked (login to new user session or add user to
696 // the existing session - multi-profile) then give 100% of work area only
697 // if keyboard is not shown.
698 if (!state_.is_adding_user_screen || !keyboard_bounds_.IsEmpty()) {
699 insets = target_bounds.work_area_insets;
701 Shell::GetInstance()->SetDisplayWorkAreaInsets(root_window_, insets);
705 // Setting visibility during an animation causes the visibility property to
706 // animate. Set the visibility property without an animation.
707 if (target_bounds.status_opacity)
708 shelf_->status_area_widget()->Show();
711 void ShelfLayoutManager::StopAnimating() {
712 GetLayer(shelf_)->GetAnimator()->StopAnimating();
713 GetLayer(shelf_->status_area_widget())->GetAnimator()->StopAnimating();
716 void ShelfLayoutManager::GetShelfSize(int* width, int* height) {
717 *width = *height = 0;
718 gfx::Size status_size(
719 shelf_->status_area_widget()->GetWindowBoundsInScreen().size());
720 if (IsHorizontalAlignment())
721 *height = kShelfSize;
722 else
723 *width = kShelfSize;
726 void ShelfLayoutManager::AdjustBoundsBasedOnAlignment(int inset,
727 gfx::Rect* bounds) const {
728 bounds->Inset(SelectValueForShelfAlignment(
729 gfx::Insets(0, 0, inset, 0),
730 gfx::Insets(0, inset, 0, 0),
731 gfx::Insets(0, 0, 0, inset),
732 gfx::Insets(inset, 0, 0, 0)));
735 void ShelfLayoutManager::CalculateTargetBounds(
736 const State& state,
737 TargetBounds* target_bounds) {
738 const gfx::Rect available_bounds(root_window_->bounds());
739 gfx::Rect status_size(
740 shelf_->status_area_widget()->GetWindowBoundsInScreen().size());
741 int shelf_width = 0, shelf_height = 0;
742 GetShelfSize(&shelf_width, &shelf_height);
743 if (IsHorizontalAlignment())
744 shelf_width = available_bounds.width();
745 else
746 shelf_height = available_bounds.height();
748 if (state.visibility_state == SHELF_AUTO_HIDE &&
749 state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) {
750 // Auto-hidden shelf always starts with the default size. If a gesture-drag
751 // is in progress, then the call to UpdateTargetBoundsForGesture() below
752 // takes care of setting the height properly.
753 if (IsHorizontalAlignment())
754 shelf_height = kAutoHideSize;
755 else
756 shelf_width = kAutoHideSize;
757 } else if (state.visibility_state == SHELF_HIDDEN ||
758 (!keyboard_bounds_.IsEmpty() && !keyboard::IsKeyboardOverscrollEnabled()))
760 if (IsHorizontalAlignment())
761 shelf_height = 0;
762 else
763 shelf_width = 0;
766 int bottom_shelf_vertical_offset = available_bounds.bottom();
767 if (keyboard_bounds_.IsEmpty())
768 bottom_shelf_vertical_offset -= shelf_height;
769 else
770 bottom_shelf_vertical_offset -= keyboard_bounds_.height();
772 target_bounds->shelf_bounds_in_root = SelectValueForShelfAlignment(
773 gfx::Rect(available_bounds.x(), bottom_shelf_vertical_offset,
774 available_bounds.width(), shelf_height),
775 gfx::Rect(available_bounds.x(), available_bounds.y(),
776 shelf_width, available_bounds.height()),
777 gfx::Rect(available_bounds.right() - shelf_width, available_bounds.y(),
778 shelf_width, available_bounds.height()),
779 gfx::Rect(available_bounds.x(), available_bounds.y(),
780 available_bounds.width(), shelf_height));
782 if (IsHorizontalAlignment())
783 status_size.set_height(kShelfSize);
784 else
785 status_size.set_width(kShelfSize);
787 target_bounds->status_bounds_in_shelf = SelectValueForShelfAlignment(
788 gfx::Rect(base::i18n::IsRTL() ? 0 : shelf_width - status_size.width(),
789 0, status_size.width(), status_size.height()),
790 gfx::Rect(shelf_width - status_size.width(),
791 shelf_height - status_size.height(), status_size.width(),
792 status_size.height()),
793 gfx::Rect(0, shelf_height - status_size.height(),
794 status_size.width(), status_size.height()),
795 gfx::Rect(base::i18n::IsRTL() ? 0 : shelf_width - status_size.width(),
796 shelf_height - status_size.height(),
797 status_size.width(), status_size.height()));
799 target_bounds->work_area_insets = SelectValueForShelfAlignment(
800 gfx::Insets(0, 0, GetWorkAreaSize(state, shelf_height), 0),
801 gfx::Insets(0, GetWorkAreaSize(state, shelf_width), 0, 0),
802 gfx::Insets(0, 0, 0, GetWorkAreaSize(state, shelf_width)),
803 gfx::Insets(GetWorkAreaSize(state, shelf_height), 0, 0, 0));
805 // TODO(varkha): The functionality of managing insets for display areas
806 // should probably be pushed to a separate component. This would simplify or
807 // remove entirely the dependency on keyboard and dock.
809 if (!keyboard_bounds_.IsEmpty() && !keyboard::IsKeyboardOverscrollEnabled()) {
810 // Also push in the work area inset for the keyboard if it is visible.
811 gfx::Insets keyboard_insets(0, 0, keyboard_bounds_.height(), 0);
812 target_bounds->work_area_insets += keyboard_insets;
815 // Also push in the work area inset for the dock if it is visible.
816 if (!dock_bounds_.IsEmpty()) {
817 gfx::Insets dock_insets(
818 0, (dock_bounds_.x() > 0 ? 0 : dock_bounds_.width()),
819 0, (dock_bounds_.x() > 0 ? dock_bounds_.width() : 0));
820 target_bounds->work_area_insets += dock_insets;
823 target_bounds->opacity =
824 (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS ||
825 state.visibility_state == SHELF_VISIBLE ||
826 state.visibility_state == SHELF_AUTO_HIDE) ? 1.0f : 0.0f;
827 target_bounds->status_opacity =
828 (state.visibility_state == SHELF_AUTO_HIDE &&
829 state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN &&
830 gesture_drag_status_ != GESTURE_DRAG_IN_PROGRESS) ?
831 0.0f : target_bounds->opacity;
833 if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS)
834 UpdateTargetBoundsForGesture(target_bounds);
836 // This needs to happen after calling UpdateTargetBoundsForGesture(), because
837 // that can change the size of the shelf.
838 target_bounds->shelf_bounds_in_shelf = SelectValueForShelfAlignment(
839 gfx::Rect(0, 0,
840 shelf_width - status_size.width(),
841 target_bounds->shelf_bounds_in_root.height()),
842 gfx::Rect(0, 0, target_bounds->shelf_bounds_in_root.width(),
843 shelf_height - status_size.height()),
844 gfx::Rect(0, 0, target_bounds->shelf_bounds_in_root.width(),
845 shelf_height - status_size.height()),
846 gfx::Rect(0, 0,
847 shelf_width - status_size.width(),
848 target_bounds->shelf_bounds_in_root.height()));
851 void ShelfLayoutManager::UpdateTargetBoundsForGesture(
852 TargetBounds* target_bounds) const {
853 CHECK_EQ(GESTURE_DRAG_IN_PROGRESS, gesture_drag_status_);
854 bool horizontal = IsHorizontalAlignment();
855 const gfx::Rect& available_bounds(root_window_->bounds());
856 int resistance_free_region = 0;
858 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN &&
859 visibility_state() == SHELF_AUTO_HIDE &&
860 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) {
861 // If the shelf was hidden when the drag started (and the state hasn't
862 // changed since then, e.g. because the tray-menu was shown because of the
863 // drag), then allow the drag some resistance-free region at first to make
864 // sure the shelf sticks with the finger until the shelf is visible.
865 resistance_free_region = kShelfSize - kAutoHideSize;
868 bool resist = SelectValueForShelfAlignment(
869 gesture_drag_amount_ < -resistance_free_region,
870 gesture_drag_amount_ > resistance_free_region,
871 gesture_drag_amount_ < -resistance_free_region,
872 gesture_drag_amount_ > resistance_free_region);
874 float translate = 0.f;
875 if (resist) {
876 float diff = fabsf(gesture_drag_amount_) - resistance_free_region;
877 diff = std::min(diff, sqrtf(diff));
878 if (gesture_drag_amount_ < 0)
879 translate = -resistance_free_region - diff;
880 else
881 translate = resistance_free_region + diff;
882 } else {
883 translate = gesture_drag_amount_;
886 if (horizontal) {
887 // Move and size the shelf with the gesture.
888 int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate;
889 shelf_height = std::max(shelf_height, kAutoHideSize);
890 target_bounds->shelf_bounds_in_root.set_height(shelf_height);
891 if (GetAlignment() == SHELF_ALIGNMENT_BOTTOM) {
892 target_bounds->shelf_bounds_in_root.set_y(
893 available_bounds.bottom() - shelf_height);
896 target_bounds->status_bounds_in_shelf.set_y(0);
897 } else {
898 // Move and size the shelf with the gesture.
899 int shelf_width = target_bounds->shelf_bounds_in_root.width();
900 bool right_aligned = GetAlignment() == SHELF_ALIGNMENT_RIGHT;
901 if (right_aligned)
902 shelf_width -= translate;
903 else
904 shelf_width += translate;
905 shelf_width = std::max(shelf_width, kAutoHideSize);
906 target_bounds->shelf_bounds_in_root.set_width(shelf_width);
907 if (right_aligned) {
908 target_bounds->shelf_bounds_in_root.set_x(
909 available_bounds.right() - shelf_width);
912 if (right_aligned)
913 target_bounds->status_bounds_in_shelf.set_x(0);
914 else
915 target_bounds->status_bounds_in_shelf.set_x(
916 target_bounds->shelf_bounds_in_root.width() -
917 kShelfSize);
921 void ShelfLayoutManager::UpdateShelfBackground(
922 BackgroundAnimatorChangeType type) {
923 const ShelfBackgroundType background_type(GetShelfBackgroundType());
924 shelf_->SetPaintsBackground(background_type, type);
925 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_,
926 OnBackgroundUpdated(background_type, type));
929 ShelfBackgroundType ShelfLayoutManager::GetShelfBackgroundType() const {
930 if (state_.visibility_state != SHELF_AUTO_HIDE &&
931 state_.window_state == WORKSPACE_WINDOW_STATE_MAXIMIZED) {
932 return SHELF_BACKGROUND_MAXIMIZED;
935 if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS ||
936 (!state_.is_screen_locked && !state_.is_adding_user_screen &&
937 window_overlaps_shelf_) ||
938 (state_.visibility_state == SHELF_AUTO_HIDE)) {
939 return SHELF_BACKGROUND_OVERLAP;
942 return SHELF_BACKGROUND_DEFAULT;
945 void ShelfLayoutManager::UpdateAutoHideStateNow() {
946 SetState(state_.visibility_state);
948 // If the state did not change, the auto hide timer may still be running.
949 StopAutoHideTimer();
952 void ShelfLayoutManager::StopAutoHideTimer() {
953 auto_hide_timer_.Stop();
954 mouse_over_shelf_when_auto_hide_timer_started_ = false;
957 gfx::Rect ShelfLayoutManager::GetAutoHideShowShelfRegionInScreen() const {
958 gfx::Rect shelf_bounds_in_screen = shelf_->GetWindowBoundsInScreen();
959 gfx::Vector2d offset = SelectValueForShelfAlignment(
960 gfx::Vector2d(0, shelf_bounds_in_screen.height()),
961 gfx::Vector2d(-kMaxAutoHideShowShelfRegionSize, 0),
962 gfx::Vector2d(shelf_bounds_in_screen.width(), 0),
963 gfx::Vector2d(0, -kMaxAutoHideShowShelfRegionSize));
965 gfx::Rect show_shelf_region_in_screen = shelf_bounds_in_screen;
966 show_shelf_region_in_screen += offset;
967 if (IsHorizontalAlignment())
968 show_shelf_region_in_screen.set_height(kMaxAutoHideShowShelfRegionSize);
969 else
970 show_shelf_region_in_screen.set_width(kMaxAutoHideShowShelfRegionSize);
972 // TODO: Figure out if we need any special handling when the keyboard is
973 // visible.
974 return show_shelf_region_in_screen;
977 ShelfAutoHideState ShelfLayoutManager::CalculateAutoHideState(
978 ShelfVisibilityState visibility_state) const {
979 if (visibility_state != SHELF_AUTO_HIDE || !shelf_)
980 return SHELF_AUTO_HIDE_HIDDEN;
982 Shell* shell = Shell::GetInstance();
983 // Unhide the shelf only on the active screen when the AppList is shown
984 // (crbug.com/312445).
985 if (shell->GetAppListTargetVisibility()) {
986 aura::Window* active_window = wm::GetActiveWindow();
987 aura::Window* shelf_window = shelf_->GetNativeWindow();
988 if (active_window && shelf_window &&
989 active_window->GetRootWindow() == shelf_window->GetRootWindow()) {
990 return SHELF_AUTO_HIDE_SHOWN;
994 if (shelf_->status_area_widget() &&
995 shelf_->status_area_widget()->ShouldShowShelf())
996 return SHELF_AUTO_HIDE_SHOWN;
998 if (shelf_->shelf() && shelf_->shelf()->IsShowingMenu())
999 return SHELF_AUTO_HIDE_SHOWN;
1001 if (shelf_->shelf() && shelf_->shelf()->IsShowingOverflowBubble())
1002 return SHELF_AUTO_HIDE_SHOWN;
1004 if (shelf_->IsActive() ||
1005 (shelf_->status_area_widget() &&
1006 shelf_->status_area_widget()->IsActive()))
1007 return SHELF_AUTO_HIDE_SHOWN;
1009 const std::vector<aura::Window*> windows =
1010 shell->mru_window_tracker()->BuildWindowListIgnoreModal();
1012 // Process the window list and check if there are any visible windows.
1013 bool visible_window = false;
1014 for (size_t i = 0; i < windows.size(); ++i) {
1015 if (windows[i] && windows[i]->IsVisible() &&
1016 !wm::GetWindowState(windows[i])->IsMinimized() &&
1017 root_window_ == windows[i]->GetRootWindow()) {
1018 visible_window = true;
1019 break;
1022 // If there are no visible windows do not hide the shelf.
1023 if (!visible_window)
1024 return SHELF_AUTO_HIDE_SHOWN;
1026 if (gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS)
1027 return gesture_drag_auto_hide_state_;
1029 // Don't show if the user is dragging the mouse.
1030 if (auto_hide_event_filter_.get() && auto_hide_event_filter_->in_mouse_drag())
1031 return SHELF_AUTO_HIDE_HIDDEN;
1033 // Ignore the mouse position if mouse events are disabled.
1034 aura::client::CursorClient* cursor_client = aura::client::GetCursorClient(
1035 shelf_->GetNativeWindow()->GetRootWindow());
1036 if (!cursor_client->IsMouseEventsEnabled())
1037 return SHELF_AUTO_HIDE_HIDDEN;
1039 gfx::Rect shelf_region = shelf_->GetWindowBoundsInScreen();
1040 if (shelf_->status_area_widget() &&
1041 shelf_->status_area_widget()->IsMessageBubbleShown() &&
1042 IsVisible()) {
1043 // Increase the the hit test area to prevent the shelf from disappearing
1044 // when the mouse is over the bubble gap.
1045 ShelfAlignment alignment = GetAlignment();
1046 shelf_region.Inset(alignment == SHELF_ALIGNMENT_RIGHT ?
1047 -kNotificationBubbleGapHeight : 0,
1048 alignment == SHELF_ALIGNMENT_BOTTOM ?
1049 -kNotificationBubbleGapHeight : 0,
1050 alignment == SHELF_ALIGNMENT_LEFT ?
1051 -kNotificationBubbleGapHeight : 0,
1052 alignment == SHELF_ALIGNMENT_TOP ?
1053 -kNotificationBubbleGapHeight : 0);
1056 gfx::Point cursor_position_in_screen =
1057 Shell::GetScreen()->GetCursorScreenPoint();
1058 if (shelf_region.Contains(cursor_position_in_screen))
1059 return SHELF_AUTO_HIDE_SHOWN;
1061 // When the shelf is auto hidden and the shelf is on the boundary between two
1062 // displays, it is hard to trigger showing the shelf. For instance, if a
1063 // user's primary display is left of their secondary display, it is hard to
1064 // unautohide a left aligned shelf on the secondary display.
1065 // It is hard because:
1066 // - It is hard to stop the cursor in the shelf "light bar" and not overshoot.
1067 // - The cursor is warped to the other display if the cursor gets to the edge
1068 // of the display.
1069 // Show the shelf if the cursor started on the shelf and the user overshot the
1070 // shelf slightly to make it easier to show the shelf in this situation. We
1071 // do not check |auto_hide_timer_|.IsRunning() because it returns false when
1072 // the timer's task is running.
1073 if ((state_.auto_hide_state == SHELF_AUTO_HIDE_SHOWN ||
1074 mouse_over_shelf_when_auto_hide_timer_started_) &&
1075 GetAutoHideShowShelfRegionInScreen().Contains(
1076 cursor_position_in_screen)) {
1077 return SHELF_AUTO_HIDE_SHOWN;
1080 return SHELF_AUTO_HIDE_HIDDEN;
1083 bool ShelfLayoutManager::IsShelfWindow(aura::Window* window) {
1084 if (!window)
1085 return false;
1086 return (shelf_ && shelf_->GetNativeWindow()->Contains(window)) ||
1087 (shelf_->status_area_widget() &&
1088 shelf_->status_area_widget()->GetNativeWindow()->Contains(window));
1091 int ShelfLayoutManager::GetWorkAreaSize(const State& state, int size) const {
1092 if (state.visibility_state == SHELF_VISIBLE)
1093 return size;
1094 if (state.visibility_state == SHELF_AUTO_HIDE)
1095 return kAutoHideSize;
1096 return 0;
1099 void ShelfLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) {
1100 bool keyboard_is_about_to_hide = false;
1101 if (new_bounds.IsEmpty() && !keyboard_bounds_.IsEmpty())
1102 keyboard_is_about_to_hide = true;
1104 keyboard_bounds_ = new_bounds;
1105 OnWindowResized();
1107 SessionStateDelegate* session_state_delegate =
1108 Shell::GetInstance()->session_state_delegate();
1110 // On login screen if keyboard has been just hidden, update bounds just once
1111 // but ignore target_bounds.work_area_insets since shelf overlaps with login
1112 // window.
1113 if (session_state_delegate->IsUserSessionBlocked() &&
1114 keyboard_is_about_to_hide) {
1115 Shell::GetInstance()->SetDisplayWorkAreaInsets(root_window_, gfx::Insets());
1119 void ShelfLayoutManager::OnDockBoundsChanging(
1120 const gfx::Rect& dock_bounds,
1121 DockedWindowLayoutManagerObserver::Reason reason) {
1122 // Skip shelf layout in case docked notification originates from this class.
1123 if (reason == DISPLAY_INSETS_CHANGED)
1124 return;
1125 if (dock_bounds_ != dock_bounds) {
1126 dock_bounds_ = dock_bounds;
1127 OnWindowResized();
1128 UpdateVisibilityState();
1129 UpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE);
1133 void ShelfLayoutManager::OnLockStateEvent(LockStateObserver::EventType event) {
1134 if (event == EVENT_LOCK_ANIMATION_STARTED) {
1135 // Enter the screen locked state and update the visibility to avoid an odd
1136 // animation when transitioning the orientation from L/R to bottom.
1137 state_.is_screen_locked = true;
1138 UpdateShelfVisibilityAfterLoginUIChange();
1142 void ShelfLayoutManager::SessionStateChanged(
1143 SessionStateDelegate::SessionState state) {
1144 // Check transition changes to/from the add user to session and change the
1145 // shelf alignment accordingly
1146 bool add_user = state == SessionStateDelegate::SESSION_STATE_LOGIN_SECONDARY;
1147 if (add_user != state_.is_adding_user_screen) {
1148 state_.is_adding_user_screen = add_user;
1149 UpdateShelfVisibilityAfterLoginUIChange();
1150 return;
1152 TargetBounds target_bounds;
1153 CalculateTargetBounds(state_, &target_bounds);
1154 UpdateBoundsAndOpacity(target_bounds, true, NULL);
1155 UpdateVisibilityState();
1158 void ShelfLayoutManager::UpdateShelfVisibilityAfterLoginUIChange() {
1159 shelf_->SetAlignment(GetAlignment());
1160 UpdateVisibilityState();
1161 LayoutShelf();
1164 bool ShelfLayoutManager::IsAlignmentLocked() const {
1165 SessionStateDelegate* session_state_delegate =
1166 Shell::GetInstance()->session_state_delegate();
1167 if (state_.is_screen_locked)
1168 return true;
1169 // The session state becomes active at the start of transitioning to a user
1170 // session, however the session is considered blocked until the full UI is
1171 // ready. Exit early to allow for proper layout.
1172 if (session_state_delegate->GetSessionState() ==
1173 SessionStateDelegate::SESSION_STATE_ACTIVE) {
1174 return false;
1176 if (session_state_delegate->IsUserSessionBlocked() ||
1177 state_.is_adding_user_screen) {
1178 return true;
1180 return false;
1183 } // namespace ash