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"
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"
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.
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 bool IsDraggingTrayEnabled() {
81 static bool dragging_tray_allowed
= CommandLine::ForCurrentProcess()->
82 HasSwitch(ash::switches::kAshEnableTrayDragging
);
83 return dragging_tray_allowed
;
89 const int ShelfLayoutManager::kWorkspaceAreaVisibleInset
= 2;
92 const int ShelfLayoutManager::kWorkspaceAreaAutoHideInset
= 5;
95 const int ShelfLayoutManager::kAutoHideSize
= 3;
98 const int ShelfLayoutManager::kShelfItemInset
= 3;
100 // ShelfLayoutManager::AutoHideEventFilter -------------------------------------
102 // Notifies ShelfLayoutManager any time the mouse moves.
103 class ShelfLayoutManager::AutoHideEventFilter
: public ui::EventHandler
{
105 explicit AutoHideEventFilter(ShelfLayoutManager
* shelf
);
106 virtual ~AutoHideEventFilter();
108 // Returns true if the last mouse event was a mouse drag.
109 bool in_mouse_drag() const { return in_mouse_drag_
; }
111 // Overridden from ui::EventHandler:
112 virtual void OnMouseEvent(ui::MouseEvent
* event
) OVERRIDE
;
113 virtual void OnGestureEvent(ui::GestureEvent
* event
) OVERRIDE
;
116 ShelfLayoutManager
* shelf_
;
118 ShelfGestureHandler gesture_handler_
;
119 DISALLOW_COPY_AND_ASSIGN(AutoHideEventFilter
);
122 ShelfLayoutManager::AutoHideEventFilter::AutoHideEventFilter(
123 ShelfLayoutManager
* shelf
)
125 in_mouse_drag_(false) {
126 Shell::GetInstance()->AddPreTargetHandler(this);
129 ShelfLayoutManager::AutoHideEventFilter::~AutoHideEventFilter() {
130 Shell::GetInstance()->RemovePreTargetHandler(this);
133 void ShelfLayoutManager::AutoHideEventFilter::OnMouseEvent(
134 ui::MouseEvent
* event
) {
135 // This also checks IsShelfWindow() to make sure we don't attempt to hide the
136 // shelf if the mouse down occurs on the shelf.
137 in_mouse_drag_
= (event
->type() == ui::ET_MOUSE_DRAGGED
||
138 (in_mouse_drag_
&& event
->type() != ui::ET_MOUSE_RELEASED
&&
139 event
->type() != ui::ET_MOUSE_CAPTURE_CHANGED
)) &&
140 !shelf_
->IsShelfWindow(static_cast<aura::Window
*>(event
->target()));
141 if (event
->type() == ui::ET_MOUSE_MOVED
)
142 shelf_
->UpdateAutoHideState();
146 void ShelfLayoutManager::AutoHideEventFilter::OnGestureEvent(
147 ui::GestureEvent
* event
) {
148 if (shelf_
->IsShelfWindow(static_cast<aura::Window
*>(event
->target()))) {
149 if (gesture_handler_
.ProcessGestureEvent(*event
))
150 event
->StopPropagation();
154 // ShelfLayoutManager:UpdateShelfObserver --------------------------------------
156 // UpdateShelfObserver is used to delay updating the background until the
157 // animation completes.
158 class ShelfLayoutManager::UpdateShelfObserver
159 : public ui::ImplicitAnimationObserver
{
161 explicit UpdateShelfObserver(ShelfLayoutManager
* shelf
) : shelf_(shelf
) {
162 shelf_
->update_shelf_observer_
= this;
169 virtual void OnImplicitAnimationsCompleted() OVERRIDE
{
171 shelf_
->UpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE
);
176 virtual ~UpdateShelfObserver() {
178 shelf_
->update_shelf_observer_
= NULL
;
181 // Shelf we're in. NULL if deleted before we're deleted.
182 ShelfLayoutManager
* shelf_
;
184 DISALLOW_COPY_AND_ASSIGN(UpdateShelfObserver
);
187 // ShelfLayoutManager ----------------------------------------------------------
189 ShelfLayoutManager::ShelfLayoutManager(ShelfWidget
* shelf
)
190 : SnapToPixelLayoutManager(shelf
->GetNativeView()->parent()),
191 root_window_(shelf
->GetNativeView()->GetRootWindow()),
192 updating_bounds_(false),
193 auto_hide_behavior_(SHELF_AUTO_HIDE_BEHAVIOR_NEVER
),
194 alignment_(SHELF_ALIGNMENT_BOTTOM
),
196 workspace_controller_(NULL
),
197 window_overlaps_shelf_(false),
198 mouse_over_shelf_when_auto_hide_timer_started_(false),
199 bezel_event_filter_(new ShelfBezelEventFilter(this)),
200 gesture_drag_status_(GESTURE_DRAG_NONE
),
201 gesture_drag_amount_(0.f
),
202 gesture_drag_auto_hide_state_(SHELF_AUTO_HIDE_SHOWN
),
203 update_shelf_observer_(NULL
),
204 duration_override_in_ms_(0) {
205 Shell::GetInstance()->AddShellObserver(this);
206 Shell::GetInstance()->lock_state_controller()->AddObserver(this);
207 aura::client::GetActivationClient(root_window_
)->AddObserver(this);
208 Shell::GetInstance()->session_state_delegate()->AddSessionStateObserver(this);
211 ShelfLayoutManager::~ShelfLayoutManager() {
212 if (update_shelf_observer_
)
213 update_shelf_observer_
->Detach();
215 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver
, observers_
, WillDeleteShelf());
216 Shell::GetInstance()->RemoveShellObserver(this);
217 Shell::GetInstance()->lock_state_controller()->RemoveObserver(this);
218 aura::client::GetActivationClient(root_window_
)->RemoveObserver(this);
219 Shell::GetInstance()->
220 session_state_delegate()->RemoveSessionStateObserver(this);
223 void ShelfLayoutManager::SetAutoHideBehavior(ShelfAutoHideBehavior behavior
) {
224 if (auto_hide_behavior_
== behavior
)
226 auto_hide_behavior_
= behavior
;
227 UpdateVisibilityState();
228 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver
, observers_
,
229 OnAutoHideBehaviorChanged(root_window_
,
230 auto_hide_behavior_
));
233 void ShelfLayoutManager::PrepareForShutdown() {
234 // Clear all event filters, otherwise sometimes those filters may catch
235 // synthesized mouse event and cause crashes during the shutdown.
236 set_workspace_controller(NULL
);
237 auto_hide_event_filter_
.reset();
238 bezel_event_filter_
.reset();
241 bool ShelfLayoutManager::IsVisible() const {
242 // status_area_widget() may be NULL during the shutdown.
243 return shelf_
->status_area_widget() &&
244 shelf_
->status_area_widget()->IsVisible() &&
245 (state_
.visibility_state
== SHELF_VISIBLE
||
246 (state_
.visibility_state
== SHELF_AUTO_HIDE
&&
247 state_
.auto_hide_state
== SHELF_AUTO_HIDE_SHOWN
));
250 bool ShelfLayoutManager::SetAlignment(ShelfAlignment alignment
) {
251 if (alignment_
== alignment
)
254 // This should not be called during the lock screen transitions.
255 DCHECK(!Shell::GetInstance()->session_state_delegate()->IsScreenLocked());
256 alignment_
= alignment
;
257 shelf_
->SetAlignment(alignment
);
262 ShelfAlignment
ShelfLayoutManager::GetAlignment() const {
263 // When the screen is locked, the shelf is forced into bottom alignment.
264 if (Shell::GetInstance()->session_state_delegate()->IsScreenLocked())
265 return SHELF_ALIGNMENT_BOTTOM
;
269 gfx::Rect
ShelfLayoutManager::GetIdealBounds() {
271 ScreenUtil::GetDisplayBoundsInParent(shelf_
->GetNativeView()));
272 int width
= 0, height
= 0;
273 GetShelfSize(&width
, &height
);
274 return SelectValueForShelfAlignment(
275 gfx::Rect(bounds
.x(), bounds
.bottom() - height
, bounds
.width(), height
),
276 gfx::Rect(bounds
.x(), bounds
.y(), width
, bounds
.height()),
277 gfx::Rect(bounds
.right() - width
, bounds
.y(), width
, bounds
.height()),
278 gfx::Rect(bounds
.x(), bounds
.y(), bounds
.width(), height
));
281 void ShelfLayoutManager::LayoutShelf() {
282 TargetBounds target_bounds
;
283 CalculateTargetBounds(state_
, &target_bounds
);
284 UpdateBoundsAndOpacity(target_bounds
, false, NULL
);
286 if (shelf_
->shelf()) {
287 // This is not part of UpdateBoundsAndOpacity() because
288 // SetShelfViewBounds() sets the bounds immediately and does not animate.
289 // The height of the ShelfView for a horizontal shelf and the width of
290 // the ShelfView for a vertical shelf are set when |shelf_|'s bounds
291 // are changed via UpdateBoundsAndOpacity(). This sets the origin and the
292 // dimension in the other direction.
293 shelf_
->shelf()->SetShelfViewBounds(
294 target_bounds
.shelf_bounds_in_shelf
);
298 ShelfVisibilityState
ShelfLayoutManager::CalculateShelfVisibility() {
299 switch(auto_hide_behavior_
) {
300 case SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
:
301 return SHELF_AUTO_HIDE
;
302 case SHELF_AUTO_HIDE_BEHAVIOR_NEVER
:
303 return SHELF_VISIBLE
;
304 case SHELF_AUTO_HIDE_ALWAYS_HIDDEN
:
307 return SHELF_VISIBLE
;
310 void ShelfLayoutManager::UpdateVisibilityState() {
311 // Bail out early when there is no |workspace_controller_|, which happens
312 // during shutdown after PrepareForShutdown.
313 if (!workspace_controller_
)
316 if (Shell::GetInstance()->session_state_delegate()->IsScreenLocked()) {
317 SetState(SHELF_VISIBLE
);
319 // TODO(zelidrag): Verify shelf drag animation still shows on the device
320 // when we are in SHELF_AUTO_HIDE_ALWAYS_HIDDEN.
321 WorkspaceWindowState
window_state(workspace_controller_
->GetWindowState());
322 switch (window_state
) {
323 case WORKSPACE_WINDOW_STATE_FULL_SCREEN
: {
324 const aura::Window
* fullscreen_window
= GetRootWindowController(
325 root_window_
)->GetWindowForFullscreenMode();
326 if (fullscreen_window
&& wm::GetWindowState(fullscreen_window
)->
327 hide_shelf_when_fullscreen()) {
328 SetState(SHELF_HIDDEN
);
330 // The shelf is sometimes not hidden when in immersive fullscreen.
331 // Force the shelf to be auto hidden in this case.
332 SetState(SHELF_AUTO_HIDE
);
337 case WORKSPACE_WINDOW_STATE_MAXIMIZED
:
338 SetState(CalculateShelfVisibility());
341 case WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF
:
342 case WORKSPACE_WINDOW_STATE_DEFAULT
:
343 SetState(CalculateShelfVisibility());
344 SetWindowOverlapsShelf(window_state
==
345 WORKSPACE_WINDOW_STATE_WINDOW_OVERLAPS_SHELF
);
351 void ShelfLayoutManager::UpdateAutoHideState() {
352 ShelfAutoHideState auto_hide_state
=
353 CalculateAutoHideState(state_
.visibility_state
);
354 if (auto_hide_state
!= state_
.auto_hide_state
) {
355 if (auto_hide_state
== SHELF_AUTO_HIDE_HIDDEN
) {
356 // Hides happen immediately.
357 SetState(state_
.visibility_state
);
359 if (!auto_hide_timer_
.IsRunning()) {
360 mouse_over_shelf_when_auto_hide_timer_started_
=
361 shelf_
->GetWindowBoundsInScreen().Contains(
362 Shell::GetScreen()->GetCursorScreenPoint());
364 auto_hide_timer_
.Start(
366 base::TimeDelta::FromMilliseconds(kAutoHideDelayMS
),
367 this, &ShelfLayoutManager::UpdateAutoHideStateNow
);
374 void ShelfLayoutManager::SetWindowOverlapsShelf(bool value
) {
375 window_overlaps_shelf_
= value
;
376 UpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE
);
379 void ShelfLayoutManager::AddObserver(ShelfLayoutManagerObserver
* observer
) {
380 observers_
.AddObserver(observer
);
383 void ShelfLayoutManager::RemoveObserver(ShelfLayoutManagerObserver
* observer
) {
384 observers_
.RemoveObserver(observer
);
387 ////////////////////////////////////////////////////////////////////////////////
388 // ShelfLayoutManager, Gesture functions:
390 void ShelfLayoutManager::OnGestureEdgeSwipe(const ui::GestureEvent
& gesture
) {
391 if (visibility_state() == SHELF_AUTO_HIDE
) {
392 gesture_drag_auto_hide_state_
= SHELF_AUTO_HIDE_SHOWN
;
393 gesture_drag_status_
= GESTURE_DRAG_COMPLETE_IN_PROGRESS
;
394 UpdateVisibilityState();
395 gesture_drag_status_
= GESTURE_DRAG_NONE
;
399 void ShelfLayoutManager::StartGestureDrag(const ui::GestureEvent
& gesture
) {
400 gesture_drag_status_
= GESTURE_DRAG_IN_PROGRESS
;
401 gesture_drag_amount_
= 0.f
;
402 gesture_drag_auto_hide_state_
= visibility_state() == SHELF_AUTO_HIDE
?
403 auto_hide_state() : SHELF_AUTO_HIDE_SHOWN
;
404 UpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE
);
407 ShelfLayoutManager::DragState
ShelfLayoutManager::UpdateGestureDrag(
408 const ui::GestureEvent
& gesture
) {
409 bool horizontal
= IsHorizontalAlignment();
410 gesture_drag_amount_
+= horizontal
? gesture
.details().scroll_y() :
411 gesture
.details().scroll_x();
414 // Start reveling the status menu when:
415 // - dragging up on an already visible shelf
416 // - dragging up on a hidden shelf, but it is currently completely visible.
417 if (horizontal
&& gesture
.details().scroll_y() < 0) {
419 if (gesture_drag_auto_hide_state_
== SHELF_AUTO_HIDE_HIDDEN
&& shelf_
)
420 min_height
= shelf_
->GetContentsView()->GetPreferredSize().height();
422 if (min_height
< shelf_
->GetWindowBoundsInScreen().height() &&
423 gesture
.root_location().x() >=
424 shelf_
->status_area_widget()->GetWindowBoundsInScreen().x() &&
425 IsDraggingTrayEnabled())
432 void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent
& gesture
) {
433 bool horizontal
= IsHorizontalAlignment();
434 bool should_change
= false;
435 if (gesture
.type() == ui::ET_GESTURE_SCROLL_END
) {
436 // The visibility of the shelf changes only if the shelf was dragged X%
437 // along the correct axis. If the shelf was already visible, then the
438 // direction of the drag does not matter.
439 const float kDragHideThreshold
= 0.4f
;
440 gfx::Rect bounds
= GetIdealBounds();
441 float drag_ratio
= fabs(gesture_drag_amount_
) /
442 (horizontal
? bounds
.height() : bounds
.width());
443 if (gesture_drag_auto_hide_state_
== SHELF_AUTO_HIDE_SHOWN
) {
444 should_change
= drag_ratio
> kDragHideThreshold
;
446 bool correct_direction
= false;
447 switch (GetAlignment()) {
448 case SHELF_ALIGNMENT_BOTTOM
:
449 case SHELF_ALIGNMENT_RIGHT
:
450 correct_direction
= gesture_drag_amount_
< 0;
452 case SHELF_ALIGNMENT_LEFT
:
453 case SHELF_ALIGNMENT_TOP
:
454 correct_direction
= gesture_drag_amount_
> 0;
457 should_change
= correct_direction
&& drag_ratio
> kDragHideThreshold
;
459 } else if (gesture
.type() == ui::ET_SCROLL_FLING_START
) {
460 if (gesture_drag_auto_hide_state_
== SHELF_AUTO_HIDE_SHOWN
) {
461 should_change
= horizontal
? fabs(gesture
.details().velocity_y()) > 0 :
462 fabs(gesture
.details().velocity_x()) > 0;
464 should_change
= SelectValueForShelfAlignment(
465 gesture
.details().velocity_y() < 0,
466 gesture
.details().velocity_x() > 0,
467 gesture
.details().velocity_x() < 0,
468 gesture
.details().velocity_y() > 0);
474 if (!should_change
) {
479 shelf_
->Deactivate();
480 shelf_
->status_area_widget()->Deactivate();
482 gesture_drag_auto_hide_state_
=
483 gesture_drag_auto_hide_state_
== SHELF_AUTO_HIDE_SHOWN
?
484 SHELF_AUTO_HIDE_HIDDEN
: SHELF_AUTO_HIDE_SHOWN
;
485 ShelfAutoHideBehavior new_auto_hide_behavior
=
486 gesture_drag_auto_hide_state_
== SHELF_AUTO_HIDE_SHOWN
?
487 SHELF_AUTO_HIDE_BEHAVIOR_NEVER
: SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS
;
489 // When in fullscreen and the shelf is forced to be auto hidden, the auto hide
490 // behavior affects neither the visibility state nor the auto hide state. Set
491 // |gesture_drag_status_| to GESTURE_DRAG_COMPLETE_IN_PROGRESS to set the auto
492 // hide state to |gesture_drag_auto_hide_state_|.
493 gesture_drag_status_
= GESTURE_DRAG_COMPLETE_IN_PROGRESS
;
494 if (auto_hide_behavior_
!= new_auto_hide_behavior
)
495 SetAutoHideBehavior(new_auto_hide_behavior
);
497 UpdateVisibilityState();
498 gesture_drag_status_
= GESTURE_DRAG_NONE
;
501 void ShelfLayoutManager::CancelGestureDrag() {
502 gesture_drag_status_
= GESTURE_DRAG_CANCEL_IN_PROGRESS
;
503 UpdateVisibilityState();
504 gesture_drag_status_
= GESTURE_DRAG_NONE
;
507 void ShelfLayoutManager::SetAnimationDurationOverride(
508 int duration_override_in_ms
) {
509 duration_override_in_ms_
= duration_override_in_ms
;
512 ////////////////////////////////////////////////////////////////////////////////
513 // ShelfLayoutManager, aura::LayoutManager implementation:
515 void ShelfLayoutManager::OnWindowResized() {
519 void ShelfLayoutManager::SetChildBounds(aura::Window
* child
,
520 const gfx::Rect
& requested_bounds
) {
521 SnapToPixelLayoutManager::SetChildBounds(child
, requested_bounds
);
522 // We may contain other widgets (such as frame maximize bubble) but they don't
523 // effect the layout in anyway.
524 if (!updating_bounds_
&&
525 ((shelf_
->GetNativeView() == child
) ||
526 (shelf_
->status_area_widget()->GetNativeView() == child
))) {
531 void ShelfLayoutManager::OnLockStateChanged(bool locked
) {
532 // Force the shelf to layout for alignment (bottom if locked, restore
533 // the previous alignment otherwise).
534 state_
.is_screen_locked
= locked
;
535 shelf_
->SetAlignment(locked
? SHELF_ALIGNMENT_BOTTOM
: alignment_
);
536 UpdateVisibilityState();
540 void ShelfLayoutManager::OnWindowActivated(aura::Window
* gained_active
,
541 aura::Window
* lost_active
) {
542 UpdateAutoHideStateNow();
545 bool ShelfLayoutManager::IsHorizontalAlignment() const {
546 return GetAlignment() == SHELF_ALIGNMENT_BOTTOM
||
547 GetAlignment() == SHELF_ALIGNMENT_TOP
;
551 ShelfLayoutManager
* ShelfLayoutManager::ForShelf(aura::Window
* window
) {
552 ShelfWidget
* shelf
= RootWindowController::ForShelf(window
)->shelf();
553 return shelf
? shelf
->shelf_layout_manager() : NULL
;
556 ////////////////////////////////////////////////////////////////////////////////
557 // ShelfLayoutManager, private:
559 ShelfLayoutManager::TargetBounds::TargetBounds() : opacity(0.0f
) {}
560 ShelfLayoutManager::TargetBounds::~TargetBounds() {}
562 void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state
) {
563 if (!shelf_
->GetNativeView())
567 state
.visibility_state
= visibility_state
;
568 state
.auto_hide_state
= CalculateAutoHideState(visibility_state
);
569 state
.window_state
= workspace_controller_
?
570 workspace_controller_
->GetWindowState() : WORKSPACE_WINDOW_STATE_DEFAULT
;
572 // Force an update because gesture drags affect the shelf bounds and we
573 // should animate back to the normal bounds at the end of a gesture.
575 (gesture_drag_status_
== GESTURE_DRAG_CANCEL_IN_PROGRESS
||
576 gesture_drag_status_
== GESTURE_DRAG_COMPLETE_IN_PROGRESS
);
578 if (!force_update
&& state_
.Equals(state
))
579 return; // Nothing changed.
581 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver
, observers_
,
582 WillChangeVisibilityState(visibility_state
));
584 if (state
.visibility_state
== SHELF_AUTO_HIDE
) {
585 // When state is SHELF_AUTO_HIDE we need to track when the mouse is over the
586 // shelf to unhide it. AutoHideEventFilter does that for us.
587 if (!auto_hide_event_filter_
)
588 auto_hide_event_filter_
.reset(new AutoHideEventFilter(this));
590 auto_hide_event_filter_
.reset(NULL
);
595 State old_state
= state_
;
598 BackgroundAnimatorChangeType change_type
= BACKGROUND_CHANGE_ANIMATE
;
599 bool delay_background_change
= false;
601 // Do not animate the background when:
602 // - Going from a hidden / auto hidden shelf in fullscreen to a visible shelf
603 // in maximized mode.
604 // - Going from an auto hidden shelf in maximized mode to a visible shelf in
606 if (state
.visibility_state
== SHELF_VISIBLE
&&
607 state
.window_state
== WORKSPACE_WINDOW_STATE_MAXIMIZED
&&
608 old_state
.visibility_state
!= SHELF_VISIBLE
) {
609 change_type
= BACKGROUND_CHANGE_IMMEDIATE
;
611 // Delay the animation when the shelf was hidden, and has just been made
612 // visible (e.g. using a gesture-drag).
613 if (state
.visibility_state
== SHELF_VISIBLE
&&
614 old_state
.visibility_state
== SHELF_AUTO_HIDE
&&
615 old_state
.auto_hide_state
== SHELF_AUTO_HIDE_HIDDEN
) {
616 delay_background_change
= true;
620 if (delay_background_change
) {
621 if (update_shelf_observer_
)
622 update_shelf_observer_
->Detach();
623 // UpdateShelfBackground deletes itself when the animation is done.
624 update_shelf_observer_
= new UpdateShelfObserver(this);
626 UpdateShelfBackground(change_type
);
629 shelf_
->SetDimsShelf(
630 state
.visibility_state
== SHELF_VISIBLE
&&
631 state
.window_state
== WORKSPACE_WINDOW_STATE_MAXIMIZED
);
633 TargetBounds target_bounds
;
634 CalculateTargetBounds(state_
, &target_bounds
);
635 UpdateBoundsAndOpacity(target_bounds
, true,
636 delay_background_change
? update_shelf_observer_
: NULL
);
638 // OnAutoHideStateChanged Should be emitted when:
639 // - firstly state changed to auto-hide from other state
640 // - or, auto_hide_state has changed
641 if ((old_state
.visibility_state
!= state_
.visibility_state
&&
642 state_
.visibility_state
== SHELF_AUTO_HIDE
) ||
643 old_state
.auto_hide_state
!= state_
.auto_hide_state
) {
644 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver
, observers_
,
645 OnAutoHideStateChanged(state_
.auto_hide_state
));
649 void ShelfLayoutManager::UpdateBoundsAndOpacity(
650 const TargetBounds
& target_bounds
,
652 ui::ImplicitAnimationObserver
* observer
) {
653 base::AutoReset
<bool> auto_reset_updating_bounds(&updating_bounds_
, true);
655 ui::ScopedLayerAnimationSettings
shelf_animation_setter(
656 GetLayer(shelf_
)->GetAnimator());
657 ui::ScopedLayerAnimationSettings
status_animation_setter(
658 GetLayer(shelf_
->status_area_widget())->GetAnimator());
660 int duration
= duration_override_in_ms_
? duration_override_in_ms_
:
661 kCrossFadeDurationMS
;
662 shelf_animation_setter
.SetTransitionDuration(
663 base::TimeDelta::FromMilliseconds(duration
));
664 shelf_animation_setter
.SetTweenType(gfx::Tween::EASE_OUT
);
665 shelf_animation_setter
.SetPreemptionStrategy(
666 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET
);
667 status_animation_setter
.SetTransitionDuration(
668 base::TimeDelta::FromMilliseconds(duration
));
669 status_animation_setter
.SetTweenType(gfx::Tween::EASE_OUT
);
670 status_animation_setter
.SetPreemptionStrategy(
671 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET
);
674 shelf_animation_setter
.SetTransitionDuration(base::TimeDelta());
675 status_animation_setter
.SetTransitionDuration(base::TimeDelta());
678 status_animation_setter
.AddObserver(observer
);
680 GetLayer(shelf_
)->SetOpacity(target_bounds
.opacity
);
681 shelf_
->SetBounds(ScreenUtil::ConvertRectToScreen(
682 shelf_
->GetNativeView()->parent(),
683 target_bounds
.shelf_bounds_in_root
));
685 GetLayer(shelf_
->status_area_widget())->SetOpacity(
686 target_bounds
.status_opacity
);
688 // Having a window which is visible but does not have an opacity is an illegal
689 // state. We therefore show / hide the shelf here if required.
690 if (!target_bounds
.status_opacity
)
691 shelf_
->status_area_widget()->Hide();
692 else if (target_bounds
.status_opacity
)
693 shelf_
->status_area_widget()->Show();
695 // TODO(harrym): Once status area widget is a child view of shelf
696 // this can be simplified.
697 gfx::Rect status_bounds
= target_bounds
.status_bounds_in_shelf
;
698 status_bounds
.set_x(status_bounds
.x() +
699 target_bounds
.shelf_bounds_in_root
.x());
700 status_bounds
.set_y(status_bounds
.y() +
701 target_bounds
.shelf_bounds_in_root
.y());
702 shelf_
->status_area_widget()->SetBounds(
703 ScreenUtil::ConvertRectToScreen(
704 shelf_
->status_area_widget()->GetNativeView()->parent(),
706 SessionStateDelegate
* session_state_delegate
=
707 Shell::GetInstance()->session_state_delegate();
708 if (!state_
.is_screen_locked
) {
710 // If user session is blocked (login to new user session or add user to
711 // the existing session - multi-profile) then give 100% of work area only if
712 // keyboard is not shown.
713 if (!session_state_delegate
->IsUserSessionBlocked() ||
714 !keyboard_bounds_
.IsEmpty()) {
715 insets
= target_bounds
.work_area_insets
;
717 Shell::GetInstance()->SetDisplayWorkAreaInsets(root_window_
, insets
);
721 void ShelfLayoutManager::StopAnimating() {
722 GetLayer(shelf_
)->GetAnimator()->StopAnimating();
723 GetLayer(shelf_
->status_area_widget())->GetAnimator()->StopAnimating();
726 void ShelfLayoutManager::GetShelfSize(int* width
, int* height
) {
727 *width
= *height
= 0;
728 gfx::Size
status_size(
729 shelf_
->status_area_widget()->GetWindowBoundsInScreen().size());
730 if (IsHorizontalAlignment())
731 *height
= kShelfSize
;
736 void ShelfLayoutManager::AdjustBoundsBasedOnAlignment(int inset
,
737 gfx::Rect
* bounds
) const {
738 bounds
->Inset(SelectValueForShelfAlignment(
739 gfx::Insets(0, 0, inset
, 0),
740 gfx::Insets(0, inset
, 0, 0),
741 gfx::Insets(0, 0, 0, inset
),
742 gfx::Insets(inset
, 0, 0, 0)));
745 void ShelfLayoutManager::CalculateTargetBounds(
747 TargetBounds
* target_bounds
) {
748 const gfx::Rect
available_bounds(root_window_
->bounds());
749 gfx::Rect
status_size(
750 shelf_
->status_area_widget()->GetWindowBoundsInScreen().size());
751 int shelf_width
= 0, shelf_height
= 0;
752 GetShelfSize(&shelf_width
, &shelf_height
);
753 if (IsHorizontalAlignment())
754 shelf_width
= available_bounds
.width();
756 shelf_height
= available_bounds
.height();
758 if (state
.visibility_state
== SHELF_AUTO_HIDE
&&
759 state
.auto_hide_state
== SHELF_AUTO_HIDE_HIDDEN
) {
760 // Auto-hidden shelf always starts with the default size. If a gesture-drag
761 // is in progress, then the call to UpdateTargetBoundsForGesture() below
762 // takes care of setting the height properly.
763 if (IsHorizontalAlignment())
764 shelf_height
= kAutoHideSize
;
766 shelf_width
= kAutoHideSize
;
767 } else if (state
.visibility_state
== SHELF_HIDDEN
||
768 (!keyboard_bounds_
.IsEmpty() && !keyboard::IsKeyboardOverscrollEnabled()))
770 if (IsHorizontalAlignment())
776 int bottom_shelf_vertical_offset
= available_bounds
.bottom();
777 if (keyboard_bounds_
.IsEmpty())
778 bottom_shelf_vertical_offset
-= shelf_height
;
780 bottom_shelf_vertical_offset
-= keyboard_bounds_
.height();
782 target_bounds
->shelf_bounds_in_root
= SelectValueForShelfAlignment(
783 gfx::Rect(available_bounds
.x(), bottom_shelf_vertical_offset
,
784 available_bounds
.width(), shelf_height
),
785 gfx::Rect(available_bounds
.x(), available_bounds
.y(),
786 shelf_width
, available_bounds
.height()),
787 gfx::Rect(available_bounds
.right() - shelf_width
, available_bounds
.y(),
788 shelf_width
, available_bounds
.height()),
789 gfx::Rect(available_bounds
.x(), available_bounds
.y(),
790 available_bounds
.width(), shelf_height
));
792 if (IsHorizontalAlignment())
793 status_size
.set_height(kShelfSize
);
795 status_size
.set_width(kShelfSize
);
797 target_bounds
->status_bounds_in_shelf
= SelectValueForShelfAlignment(
798 gfx::Rect(base::i18n::IsRTL() ? 0 : shelf_width
- status_size
.width(),
799 0, status_size
.width(), status_size
.height()),
800 gfx::Rect(shelf_width
- status_size
.width(),
801 shelf_height
- status_size
.height(), status_size
.width(),
802 status_size
.height()),
803 gfx::Rect(0, shelf_height
- status_size
.height(),
804 status_size
.width(), status_size
.height()),
805 gfx::Rect(base::i18n::IsRTL() ? 0 : shelf_width
- status_size
.width(),
806 shelf_height
- status_size
.height(),
807 status_size
.width(), status_size
.height()));
809 target_bounds
->work_area_insets
= SelectValueForShelfAlignment(
810 gfx::Insets(0, 0, GetWorkAreaSize(state
, shelf_height
), 0),
811 gfx::Insets(0, GetWorkAreaSize(state
, shelf_width
), 0, 0),
812 gfx::Insets(0, 0, 0, GetWorkAreaSize(state
, shelf_width
)),
813 gfx::Insets(GetWorkAreaSize(state
, shelf_height
), 0, 0, 0));
815 // TODO(varkha): The functionality of managing insets for display areas
816 // should probably be pushed to a separate component. This would simplify or
817 // remove entirely the dependency on keyboard and dock.
819 if (!keyboard_bounds_
.IsEmpty() && !keyboard::IsKeyboardOverscrollEnabled()) {
820 // Also push in the work area inset for the keyboard if it is visible.
821 gfx::Insets
keyboard_insets(0, 0, keyboard_bounds_
.height(), 0);
822 target_bounds
->work_area_insets
+= keyboard_insets
;
825 // Also push in the work area inset for the dock if it is visible.
826 if (!dock_bounds_
.IsEmpty()) {
827 gfx::Insets
dock_insets(
828 0, (dock_bounds_
.x() > 0 ? 0 : dock_bounds_
.width()),
829 0, (dock_bounds_
.x() > 0 ? dock_bounds_
.width() : 0));
830 target_bounds
->work_area_insets
+= dock_insets
;
833 target_bounds
->opacity
=
834 (gesture_drag_status_
== GESTURE_DRAG_IN_PROGRESS
||
835 state
.visibility_state
== SHELF_VISIBLE
||
836 state
.visibility_state
== SHELF_AUTO_HIDE
) ? 1.0f
: 0.0f
;
837 target_bounds
->status_opacity
=
838 (state
.visibility_state
== SHELF_AUTO_HIDE
&&
839 state
.auto_hide_state
== SHELF_AUTO_HIDE_HIDDEN
&&
840 gesture_drag_status_
!= GESTURE_DRAG_IN_PROGRESS
) ?
841 0.0f
: target_bounds
->opacity
;
843 if (gesture_drag_status_
== GESTURE_DRAG_IN_PROGRESS
)
844 UpdateTargetBoundsForGesture(target_bounds
);
846 // This needs to happen after calling UpdateTargetBoundsForGesture(), because
847 // that can change the size of the shelf.
848 target_bounds
->shelf_bounds_in_shelf
= SelectValueForShelfAlignment(
850 shelf_width
- status_size
.width(),
851 target_bounds
->shelf_bounds_in_root
.height()),
852 gfx::Rect(0, 0, target_bounds
->shelf_bounds_in_root
.width(),
853 shelf_height
- status_size
.height()),
854 gfx::Rect(0, 0, target_bounds
->shelf_bounds_in_root
.width(),
855 shelf_height
- status_size
.height()),
857 shelf_width
- status_size
.width(),
858 target_bounds
->shelf_bounds_in_root
.height()));
861 void ShelfLayoutManager::UpdateTargetBoundsForGesture(
862 TargetBounds
* target_bounds
) const {
863 CHECK_EQ(GESTURE_DRAG_IN_PROGRESS
, gesture_drag_status_
);
864 bool horizontal
= IsHorizontalAlignment();
865 const gfx::Rect
& available_bounds(root_window_
->bounds());
866 int resistance_free_region
= 0;
868 if (gesture_drag_auto_hide_state_
== SHELF_AUTO_HIDE_HIDDEN
&&
869 visibility_state() == SHELF_AUTO_HIDE
&&
870 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN
) {
871 // If the shelf was hidden when the drag started (and the state hasn't
872 // changed since then, e.g. because the tray-menu was shown because of the
873 // drag), then allow the drag some resistance-free region at first to make
874 // sure the shelf sticks with the finger until the shelf is visible.
875 resistance_free_region
= kShelfSize
- kAutoHideSize
;
878 bool resist
= SelectValueForShelfAlignment(
879 gesture_drag_amount_
< -resistance_free_region
,
880 gesture_drag_amount_
> resistance_free_region
,
881 gesture_drag_amount_
< -resistance_free_region
,
882 gesture_drag_amount_
> resistance_free_region
);
884 float translate
= 0.f
;
886 float diff
= fabsf(gesture_drag_amount_
) - resistance_free_region
;
887 diff
= std::min(diff
, sqrtf(diff
));
888 if (gesture_drag_amount_
< 0)
889 translate
= -resistance_free_region
- diff
;
891 translate
= resistance_free_region
+ diff
;
893 translate
= gesture_drag_amount_
;
897 // Move and size the shelf with the gesture.
898 int shelf_height
= target_bounds
->shelf_bounds_in_root
.height() - translate
;
899 shelf_height
= std::max(shelf_height
, kAutoHideSize
);
900 target_bounds
->shelf_bounds_in_root
.set_height(shelf_height
);
901 if (GetAlignment() == SHELF_ALIGNMENT_BOTTOM
) {
902 target_bounds
->shelf_bounds_in_root
.set_y(
903 available_bounds
.bottom() - shelf_height
);
906 target_bounds
->status_bounds_in_shelf
.set_y(0);
908 // Move and size the shelf with the gesture.
909 int shelf_width
= target_bounds
->shelf_bounds_in_root
.width();
910 bool right_aligned
= GetAlignment() == SHELF_ALIGNMENT_RIGHT
;
912 shelf_width
-= translate
;
914 shelf_width
+= translate
;
915 shelf_width
= std::max(shelf_width
, kAutoHideSize
);
916 target_bounds
->shelf_bounds_in_root
.set_width(shelf_width
);
918 target_bounds
->shelf_bounds_in_root
.set_x(
919 available_bounds
.right() - shelf_width
);
923 target_bounds
->status_bounds_in_shelf
.set_x(0);
925 target_bounds
->status_bounds_in_shelf
.set_x(
926 target_bounds
->shelf_bounds_in_root
.width() -
931 void ShelfLayoutManager::UpdateShelfBackground(
932 BackgroundAnimatorChangeType type
) {
933 const ShelfBackgroundType
background_type(GetShelfBackgroundType());
934 shelf_
->SetPaintsBackground(background_type
, type
);
935 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver
, observers_
,
936 OnBackgroundUpdated(background_type
, type
));
939 ShelfBackgroundType
ShelfLayoutManager::GetShelfBackgroundType() const {
940 if (state_
.visibility_state
!= SHELF_AUTO_HIDE
&&
941 state_
.window_state
== WORKSPACE_WINDOW_STATE_MAXIMIZED
) {
942 return SHELF_BACKGROUND_MAXIMIZED
;
945 if (gesture_drag_status_
== GESTURE_DRAG_IN_PROGRESS
||
946 (!state_
.is_screen_locked
&& window_overlaps_shelf_
) ||
947 (state_
.visibility_state
== SHELF_AUTO_HIDE
)) {
948 return SHELF_BACKGROUND_OVERLAP
;
951 return SHELF_BACKGROUND_DEFAULT
;
954 void ShelfLayoutManager::UpdateAutoHideStateNow() {
955 SetState(state_
.visibility_state
);
957 // If the state did not change, the auto hide timer may still be running.
961 void ShelfLayoutManager::StopAutoHideTimer() {
962 auto_hide_timer_
.Stop();
963 mouse_over_shelf_when_auto_hide_timer_started_
= false;
966 gfx::Rect
ShelfLayoutManager::GetAutoHideShowShelfRegionInScreen() const {
967 gfx::Rect shelf_bounds_in_screen
= shelf_
->GetWindowBoundsInScreen();
968 gfx::Vector2d offset
= SelectValueForShelfAlignment(
969 gfx::Vector2d(0, shelf_bounds_in_screen
.height()),
970 gfx::Vector2d(-kMaxAutoHideShowShelfRegionSize
, 0),
971 gfx::Vector2d(shelf_bounds_in_screen
.width(), 0),
972 gfx::Vector2d(0, -kMaxAutoHideShowShelfRegionSize
));
974 gfx::Rect show_shelf_region_in_screen
= shelf_bounds_in_screen
;
975 show_shelf_region_in_screen
+= offset
;
976 if (IsHorizontalAlignment())
977 show_shelf_region_in_screen
.set_height(kMaxAutoHideShowShelfRegionSize
);
979 show_shelf_region_in_screen
.set_width(kMaxAutoHideShowShelfRegionSize
);
981 // TODO: Figure out if we need any special handling when the keyboard is
983 return show_shelf_region_in_screen
;
986 ShelfAutoHideState
ShelfLayoutManager::CalculateAutoHideState(
987 ShelfVisibilityState visibility_state
) const {
988 if (visibility_state
!= SHELF_AUTO_HIDE
|| !shelf_
)
989 return SHELF_AUTO_HIDE_HIDDEN
;
991 Shell
* shell
= Shell::GetInstance();
992 if (shell
->GetAppListTargetVisibility())
993 return SHELF_AUTO_HIDE_SHOWN
;
995 if (shelf_
->status_area_widget() &&
996 shelf_
->status_area_widget()->ShouldShowShelf())
997 return SHELF_AUTO_HIDE_SHOWN
;
999 if (shelf_
->shelf() && shelf_
->shelf()->IsShowingMenu())
1000 return SHELF_AUTO_HIDE_SHOWN
;
1002 if (shelf_
->shelf() && shelf_
->shelf()->IsShowingOverflowBubble())
1003 return SHELF_AUTO_HIDE_SHOWN
;
1005 if (shelf_
->IsActive() ||
1006 (shelf_
->status_area_widget() &&
1007 shelf_
->status_area_widget()->IsActive()))
1008 return SHELF_AUTO_HIDE_SHOWN
;
1010 const std::vector
<aura::Window
*> windows
=
1011 ash::MruWindowTracker::BuildWindowList(false);
1013 // Process the window list and check if there are any visible windows.
1014 bool visible_window
= false;
1015 for (size_t i
= 0; i
< windows
.size(); ++i
) {
1016 if (windows
[i
] && windows
[i
]->IsVisible() &&
1017 !wm::GetWindowState(windows
[i
])->IsMinimized() &&
1018 root_window_
== windows
[i
]->GetRootWindow()) {
1019 visible_window
= true;
1023 // If there are no visible windows do not hide the shelf.
1024 if (!visible_window
)
1025 return SHELF_AUTO_HIDE_SHOWN
;
1027 if (gesture_drag_status_
== GESTURE_DRAG_COMPLETE_IN_PROGRESS
)
1028 return gesture_drag_auto_hide_state_
;
1030 // Don't show if the user is dragging the mouse.
1031 if (auto_hide_event_filter_
.get() && auto_hide_event_filter_
->in_mouse_drag())
1032 return SHELF_AUTO_HIDE_HIDDEN
;
1034 // Ignore the mouse position if mouse events are disabled.
1035 aura::client::CursorClient
* cursor_client
= aura::client::GetCursorClient(
1036 shelf_
->GetNativeWindow()->GetRootWindow());
1037 if (!cursor_client
->IsMouseEventsEnabled())
1038 return SHELF_AUTO_HIDE_HIDDEN
;
1040 gfx::Rect shelf_region
= shelf_
->GetWindowBoundsInScreen();
1041 if (shelf_
->status_area_widget() &&
1042 shelf_
->status_area_widget()->IsMessageBubbleShown() &&
1044 // Increase the the hit test area to prevent the shelf from disappearing
1045 // when the mouse is over the bubble gap.
1046 ShelfAlignment alignment
= GetAlignment();
1047 shelf_region
.Inset(alignment
== SHELF_ALIGNMENT_RIGHT
?
1048 -kNotificationBubbleGapHeight
: 0,
1049 alignment
== SHELF_ALIGNMENT_BOTTOM
?
1050 -kNotificationBubbleGapHeight
: 0,
1051 alignment
== SHELF_ALIGNMENT_LEFT
?
1052 -kNotificationBubbleGapHeight
: 0,
1053 alignment
== SHELF_ALIGNMENT_TOP
?
1054 -kNotificationBubbleGapHeight
: 0);
1057 gfx::Point cursor_position_in_screen
=
1058 Shell::GetScreen()->GetCursorScreenPoint();
1059 if (shelf_region
.Contains(cursor_position_in_screen
))
1060 return SHELF_AUTO_HIDE_SHOWN
;
1062 // When the shelf is auto hidden and the shelf is on the boundary between two
1063 // displays, it is hard to trigger showing the shelf. For instance, if a
1064 // user's primary display is left of their secondary display, it is hard to
1065 // unautohide a left aligned shelf on the secondary display.
1066 // It is hard because:
1067 // - It is hard to stop the cursor in the shelf "light bar" and not overshoot.
1068 // - The cursor is warped to the other display if the cursor gets to the edge
1070 // Show the shelf if the cursor started on the shelf and the user overshot the
1071 // shelf slightly to make it easier to show the shelf in this situation. We
1072 // do not check |auto_hide_timer_|.IsRunning() because it returns false when
1073 // the timer's task is running.
1074 if ((state_
.auto_hide_state
== SHELF_AUTO_HIDE_SHOWN
||
1075 mouse_over_shelf_when_auto_hide_timer_started_
) &&
1076 GetAutoHideShowShelfRegionInScreen().Contains(
1077 cursor_position_in_screen
)) {
1078 return SHELF_AUTO_HIDE_SHOWN
;
1081 return SHELF_AUTO_HIDE_HIDDEN
;
1084 bool ShelfLayoutManager::IsShelfWindow(aura::Window
* window
) {
1087 return (shelf_
&& shelf_
->GetNativeWindow()->Contains(window
)) ||
1088 (shelf_
->status_area_widget() &&
1089 shelf_
->status_area_widget()->GetNativeWindow()->Contains(window
));
1092 int ShelfLayoutManager::GetWorkAreaSize(const State
& state
, int size
) const {
1093 if (state
.visibility_state
== SHELF_VISIBLE
)
1095 if (state
.visibility_state
== SHELF_AUTO_HIDE
)
1096 return kAutoHideSize
;
1100 void ShelfLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect
& new_bounds
) {
1101 bool keyboard_is_about_to_hide
= false;
1102 if (new_bounds
.IsEmpty() && !keyboard_bounds_
.IsEmpty())
1103 keyboard_is_about_to_hide
= true;
1105 keyboard_bounds_
= new_bounds
;
1108 SessionStateDelegate
* session_state_delegate
=
1109 Shell::GetInstance()->session_state_delegate();
1111 // On login screen if keyboard has been just hidden, update bounds just once
1112 // but ignore target_bounds.work_area_insets since shelf overlaps with login
1114 if (session_state_delegate
->IsUserSessionBlocked() &&
1115 keyboard_is_about_to_hide
) {
1116 Shell::GetInstance()->SetDisplayWorkAreaInsets(root_window_
, gfx::Insets());
1120 void ShelfLayoutManager::OnDockBoundsChanging(
1121 const gfx::Rect
& dock_bounds
,
1122 DockedWindowLayoutManagerObserver::Reason reason
) {
1123 // Skip shelf layout in case docked notification originates from this class.
1124 if (reason
== DISPLAY_INSETS_CHANGED
)
1126 if (dock_bounds_
!= dock_bounds
) {
1127 dock_bounds_
= dock_bounds
;
1129 UpdateVisibilityState();
1130 UpdateShelfBackground(BACKGROUND_CHANGE_ANIMATE
);
1134 void ShelfLayoutManager::OnLockStateEvent(LockStateObserver::EventType event
) {
1135 if (event
== EVENT_LOCK_ANIMATION_STARTED
) {
1136 // Enter the screen locked state.
1137 state_
.is_screen_locked
= true;
1141 void ShelfLayoutManager::SessionStateChanged(
1142 SessionStateDelegate::SessionState state
) {
1143 TargetBounds target_bounds
;
1144 CalculateTargetBounds(state_
, &target_bounds
);
1145 UpdateBoundsAndOpacity(target_bounds
, true, NULL
);
1146 UpdateVisibilityState();