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> |
(...skipping 18 matching lines...) Expand all Loading... | |
29 #include "ash/wm/window_properties.h" | 29 #include "ash/wm/window_properties.h" |
30 #include "ash/wm/window_util.h" | 30 #include "ash/wm/window_util.h" |
31 #include "ash/wm/workspace_controller.h" | 31 #include "ash/wm/workspace_controller.h" |
32 #include "base/auto_reset.h" | 32 #include "base/auto_reset.h" |
33 #include "base/command_line.h" | 33 #include "base/command_line.h" |
34 #include "base/command_line.h" | 34 #include "base/command_line.h" |
35 #include "base/i18n/rtl.h" | 35 #include "base/i18n/rtl.h" |
36 #include "base/strings/string_number_conversions.h" | 36 #include "base/strings/string_number_conversions.h" |
37 #include "base/strings/string_util.h" | 37 #include "base/strings/string_util.h" |
38 #include "ui/aura/client/activation_client.h" | 38 #include "ui/aura/client/activation_client.h" |
39 #include "ui/aura/client/cursor_client.h" | |
39 #include "ui/aura/root_window.h" | 40 #include "ui/aura/root_window.h" |
40 #include "ui/base/events/event.h" | 41 #include "ui/base/events/event.h" |
41 #include "ui/base/events/event_handler.h" | 42 #include "ui/base/events/event_handler.h" |
42 #include "ui/base/ui_base_switches.h" | 43 #include "ui/base/ui_base_switches.h" |
43 #include "ui/compositor/layer.h" | 44 #include "ui/compositor/layer.h" |
44 #include "ui/compositor/layer_animation_observer.h" | 45 #include "ui/compositor/layer_animation_observer.h" |
45 #include "ui/compositor/layer_animator.h" | 46 #include "ui/compositor/layer_animator.h" |
46 #include "ui/compositor/scoped_layer_animation_settings.h" | 47 #include "ui/compositor/scoped_layer_animation_settings.h" |
47 #include "ui/gfx/screen.h" | 48 #include "ui/gfx/screen.h" |
48 #include "ui/views/widget/widget.h" | 49 #include "ui/views/widget/widget.h" |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 // Shelf we're in. NULL if deleted before we're deleted. | 190 // Shelf we're in. NULL if deleted before we're deleted. |
190 ShelfLayoutManager* shelf_; | 191 ShelfLayoutManager* shelf_; |
191 | 192 |
192 DISALLOW_COPY_AND_ASSIGN(UpdateShelfObserver); | 193 DISALLOW_COPY_AND_ASSIGN(UpdateShelfObserver); |
193 }; | 194 }; |
194 | 195 |
195 // ShelfLayoutManager ---------------------------------------------------------- | 196 // ShelfLayoutManager ---------------------------------------------------------- |
196 | 197 |
197 ShelfLayoutManager::ShelfLayoutManager(ShelfWidget* shelf) | 198 ShelfLayoutManager::ShelfLayoutManager(ShelfWidget* shelf) |
198 : root_window_(shelf->GetNativeView()->GetRootWindow()), | 199 : root_window_(shelf->GetNativeView()->GetRootWindow()), |
199 in_layout_(false), | 200 updating_bounds_(false), |
200 auto_hide_behavior_(SHELF_AUTO_HIDE_BEHAVIOR_NEVER), | 201 auto_hide_behavior_(SHELF_AUTO_HIDE_BEHAVIOR_NEVER), |
201 alignment_(SHELF_ALIGNMENT_BOTTOM), | 202 alignment_(SHELF_ALIGNMENT_BOTTOM), |
202 shelf_(shelf), | 203 shelf_(shelf), |
203 workspace_controller_(NULL), | 204 workspace_controller_(NULL), |
204 window_overlaps_shelf_(false), | 205 window_overlaps_shelf_(false), |
205 mouse_over_shelf_when_auto_hide_timer_started_(false), | 206 mouse_over_shelf_when_auto_hide_timer_started_(false), |
206 bezel_event_filter_(new ShelfBezelEventFilter(this)), | 207 bezel_event_filter_(new ShelfBezelEventFilter(this)), |
207 gesture_drag_status_(GESTURE_DRAG_NONE), | 208 gesture_drag_status_(GESTURE_DRAG_NONE), |
208 gesture_drag_amount_(0.f), | 209 gesture_drag_amount_(0.f), |
209 gesture_drag_auto_hide_state_(SHELF_AUTO_HIDE_SHOWN), | 210 gesture_drag_auto_hide_state_(SHELF_AUTO_HIDE_SHOWN), |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
264 int width = 0, height = 0; | 265 int width = 0, height = 0; |
265 GetShelfSize(&width, &height); | 266 GetShelfSize(&width, &height); |
266 return SelectValueForShelfAlignment( | 267 return SelectValueForShelfAlignment( |
267 gfx::Rect(bounds.x(), bounds.bottom() - height, bounds.width(), height), | 268 gfx::Rect(bounds.x(), bounds.bottom() - height, bounds.width(), height), |
268 gfx::Rect(bounds.x(), bounds.y(), width, bounds.height()), | 269 gfx::Rect(bounds.x(), bounds.y(), width, bounds.height()), |
269 gfx::Rect(bounds.right() - width, bounds.y(), width, bounds.height()), | 270 gfx::Rect(bounds.right() - width, bounds.y(), width, bounds.height()), |
270 gfx::Rect(bounds.x(), bounds.y(), bounds.width(), height)); | 271 gfx::Rect(bounds.x(), bounds.y(), bounds.width(), height)); |
271 } | 272 } |
272 | 273 |
273 void ShelfLayoutManager::LayoutShelf() { | 274 void ShelfLayoutManager::LayoutShelf() { |
274 base::AutoReset<bool> auto_reset_in_layout(&in_layout_, true); | |
275 StopAnimating(); | |
276 TargetBounds target_bounds; | 275 TargetBounds target_bounds; |
277 CalculateTargetBounds(state_, &target_bounds); | 276 CalculateTargetBounds(state_, &target_bounds); |
278 GetLayer(shelf_)->SetOpacity(target_bounds.opacity); | 277 UpdateBoundsAndOpacity(target_bounds, false, NULL); |
279 shelf_->SetWidgetBounds( | 278 |
280 ScreenAsh::ConvertRectToScreen( | 279 if (shelf_->launcher()) { |
281 shelf_->GetNativeView()->parent(), | 280 // This is not part of UpdateBoundsAndOpacity() because |
282 target_bounds.shelf_bounds_in_root)); | 281 // SetLauncherViewBounds() sets the bounds immediately and does not animate. |
283 if (shelf_->launcher()) | 282 // The height of the LauncherView for a horizontal shelf and the width of |
283 // the LauncherView for a vertical shelf are set when |shelf_|'s bounds | |
284 // are changed via UpdateBoundsAndOpacity(). This sets the origin and the | |
285 // dimension in the other direction. | |
284 shelf_->launcher()->SetLauncherViewBounds( | 286 shelf_->launcher()->SetLauncherViewBounds( |
285 target_bounds.launcher_bounds_in_shelf); | 287 target_bounds.launcher_bounds_in_shelf); |
286 GetLayer(shelf_->status_area_widget())->SetOpacity( | 288 } |
287 target_bounds.status_opacity); | |
288 // TODO(harrym): Once status area widget is a child view of shelf | |
289 // this can be simplified. | |
290 gfx::Rect status_bounds = target_bounds.status_bounds_in_shelf; | |
291 status_bounds.set_x(status_bounds.x() + | |
292 target_bounds.shelf_bounds_in_root.x()); | |
293 status_bounds.set_y(status_bounds.y() + | |
294 target_bounds.shelf_bounds_in_root.y()); | |
295 shelf_->status_area_widget()->SetBounds( | |
296 ScreenAsh::ConvertRectToScreen( | |
297 shelf_->status_area_widget()->GetNativeView()->parent(), | |
298 status_bounds)); | |
299 Shell::GetInstance()->SetDisplayWorkAreaInsets( | |
300 root_window_, target_bounds.work_area_insets); | |
301 UpdateHitTestBounds(); | |
302 } | 289 } |
303 | 290 |
304 ShelfVisibilityState ShelfLayoutManager::CalculateShelfVisibility() { | 291 ShelfVisibilityState ShelfLayoutManager::CalculateShelfVisibility() { |
305 switch(auto_hide_behavior_) { | 292 switch(auto_hide_behavior_) { |
306 case SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: | 293 case SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: |
307 return SHELF_AUTO_HIDE; | 294 return SHELF_AUTO_HIDE; |
308 case SHELF_AUTO_HIDE_BEHAVIOR_NEVER: | 295 case SHELF_AUTO_HIDE_BEHAVIOR_NEVER: |
309 return SHELF_VISIBLE; | 296 return SHELF_VISIBLE; |
310 case SHELF_AUTO_HIDE_ALWAYS_HIDDEN: | 297 case SHELF_AUTO_HIDE_ALWAYS_HIDDEN: |
311 return SHELF_HIDDEN; | 298 return SHELF_HIDDEN; |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
473 // In fullscreen with minimal chrome, the auto hide behavior affects neither | 460 // In fullscreen with minimal chrome, the auto hide behavior affects neither |
474 // the visibility state nor the auto hide state. Set |gesture_drag_status_| | 461 // the visibility state nor the auto hide state. Set |gesture_drag_status_| |
475 // to GESTURE_DRAG_COMPLETE_IN_PROGRESS to set the auto hide state to | 462 // to GESTURE_DRAG_COMPLETE_IN_PROGRESS to set the auto hide state to |
476 // |gesture_drag_auto_hide_state_|. | 463 // |gesture_drag_auto_hide_state_|. |
477 gesture_drag_status_ = GESTURE_DRAG_COMPLETE_IN_PROGRESS; | 464 gesture_drag_status_ = GESTURE_DRAG_COMPLETE_IN_PROGRESS; |
478 if (auto_hide_behavior_ != new_auto_hide_behavior) | 465 if (auto_hide_behavior_ != new_auto_hide_behavior) |
479 SetAutoHideBehavior(new_auto_hide_behavior); | 466 SetAutoHideBehavior(new_auto_hide_behavior); |
480 else | 467 else |
481 UpdateVisibilityState(); | 468 UpdateVisibilityState(); |
482 gesture_drag_status_ = GESTURE_DRAG_NONE; | 469 gesture_drag_status_ = GESTURE_DRAG_NONE; |
483 LayoutShelf(); | |
484 } | 470 } |
485 | 471 |
486 void ShelfLayoutManager::CancelGestureDrag() { | 472 void ShelfLayoutManager::CancelGestureDrag() { |
473 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS; | |
474 UpdateVisibilityState(); | |
487 gesture_drag_status_ = GESTURE_DRAG_NONE; | 475 gesture_drag_status_ = GESTURE_DRAG_NONE; |
488 ui::ScopedLayerAnimationSettings | |
489 launcher_settings(GetLayer(shelf_)->GetAnimator()), | |
490 status_settings(GetLayer(shelf_->status_area_widget())->GetAnimator()); | |
491 LayoutShelf(); | |
492 UpdateVisibilityState(); | |
493 UpdateShelfBackground(BackgroundAnimator::CHANGE_ANIMATE); | |
494 } | 476 } |
495 | 477 |
496 //////////////////////////////////////////////////////////////////////////////// | 478 //////////////////////////////////////////////////////////////////////////////// |
497 // ShelfLayoutManager, aura::LayoutManager implementation: | 479 // ShelfLayoutManager, aura::LayoutManager implementation: |
498 | 480 |
499 void ShelfLayoutManager::OnWindowResized() { | 481 void ShelfLayoutManager::OnWindowResized() { |
500 LayoutShelf(); | 482 LayoutShelf(); |
501 } | 483 } |
502 | 484 |
503 void ShelfLayoutManager::OnWindowAddedToLayout(aura::Window* child) { | 485 void ShelfLayoutManager::OnWindowAddedToLayout(aura::Window* child) { |
504 } | 486 } |
505 | 487 |
506 void ShelfLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) { | 488 void ShelfLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) { |
507 } | 489 } |
508 | 490 |
509 void ShelfLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) { | 491 void ShelfLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) { |
510 } | 492 } |
511 | 493 |
512 void ShelfLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child, | 494 void ShelfLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child, |
513 bool visible) { | 495 bool visible) { |
514 } | 496 } |
515 | 497 |
516 void ShelfLayoutManager::SetChildBounds(aura::Window* child, | 498 void ShelfLayoutManager::SetChildBounds(aura::Window* child, |
517 const gfx::Rect& requested_bounds) { | 499 const gfx::Rect& requested_bounds) { |
518 SetChildBoundsDirect(child, requested_bounds); | 500 SetChildBoundsDirect(child, requested_bounds); |
519 // We may contain other widgets (such as frame maximize bubble) but they don't | 501 // We may contain other widgets (such as frame maximize bubble) but they don't |
520 // effect the layout in anyway. | 502 // effect the layout in anyway. |
521 if (!in_layout_ && | 503 if (!updating_bounds_ && |
522 ((shelf_->GetNativeView() == child) || | 504 ((shelf_->GetNativeView() == child) || |
523 (shelf_->status_area_widget()->GetNativeView() == child))) { | 505 (shelf_->status_area_widget()->GetNativeView() == child))) { |
524 LayoutShelf(); | 506 LayoutShelf(); |
525 } | 507 } |
526 } | 508 } |
527 | 509 |
528 void ShelfLayoutManager::OnLockStateChanged(bool locked) { | 510 void ShelfLayoutManager::OnLockStateChanged(bool locked) { |
529 UpdateVisibilityState(); | 511 UpdateVisibilityState(); |
530 } | 512 } |
531 | 513 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
568 return; | 550 return; |
569 | 551 |
570 State state; | 552 State state; |
571 state.visibility_state = visibility_state; | 553 state.visibility_state = visibility_state; |
572 state.auto_hide_state = CalculateAutoHideState(visibility_state); | 554 state.auto_hide_state = CalculateAutoHideState(visibility_state); |
573 state.is_screen_locked = | 555 state.is_screen_locked = |
574 Shell::GetInstance()->session_state_delegate()->IsScreenLocked(); | 556 Shell::GetInstance()->session_state_delegate()->IsScreenLocked(); |
575 state.window_state = workspace_controller_ ? | 557 state.window_state = workspace_controller_ ? |
576 workspace_controller_->GetWindowState() : WORKSPACE_WINDOW_STATE_DEFAULT; | 558 workspace_controller_->GetWindowState() : WORKSPACE_WINDOW_STATE_DEFAULT; |
577 | 559 |
578 if (state_.Equals(state)) | 560 // Force an update because gesture drags affect the shelf bounds and we |
561 // should animate back to the normal bounds at the end of a gesture. | |
562 bool force_update = | |
563 (gesture_drag_status_ == GESTURE_DRAG_CANCEL_IN_PROGRESS || | |
564 gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS); | |
565 | |
566 if (!force_update && state_.Equals(state)) | |
579 return; // Nothing changed. | 567 return; // Nothing changed. |
580 | 568 |
581 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, | 569 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, |
582 WillChangeVisibilityState(visibility_state)); | 570 WillChangeVisibilityState(visibility_state)); |
583 | 571 |
584 if (state.visibility_state == SHELF_AUTO_HIDE) { | 572 if (state.visibility_state == SHELF_AUTO_HIDE) { |
585 // When state is SHELF_AUTO_HIDE we need to track when the mouse is over the | 573 // When state is SHELF_AUTO_HIDE we need to track when the mouse is over the |
586 // launcher to unhide the shelf. AutoHideEventFilter does that for us. | 574 // launcher to unhide the shelf. AutoHideEventFilter does that for us. |
587 if (!auto_hide_event_filter_) | 575 if (!auto_hide_event_filter_) |
588 auto_hide_event_filter_.reset(new AutoHideEventFilter(this)); | 576 auto_hide_event_filter_.reset(new AutoHideEventFilter(this)); |
589 } else { | 577 } else { |
590 auto_hide_event_filter_.reset(NULL); | 578 auto_hide_event_filter_.reset(NULL); |
591 } | 579 } |
592 | 580 |
593 StopAutoHideTimer(); | 581 StopAutoHideTimer(); |
594 | 582 |
595 State old_state = state_; | 583 State old_state = state_; |
596 state_ = state; | 584 state_ = state; |
597 TargetBounds target_bounds; | |
598 CalculateTargetBounds(state_, &target_bounds); | |
599 | |
600 ui::ScopedLayerAnimationSettings launcher_animation_setter( | |
601 GetLayer(shelf_)->GetAnimator()); | |
602 launcher_animation_setter.SetTransitionDuration( | |
603 base::TimeDelta::FromMilliseconds(kCrossFadeDurationMS)); | |
604 launcher_animation_setter.SetTweenType(ui::Tween::EASE_OUT); | |
605 launcher_animation_setter.SetPreemptionStrategy( | |
606 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
607 GetLayer(shelf_)->SetBounds( | |
608 target_bounds.shelf_bounds_in_root); | |
609 GetLayer(shelf_)->SetOpacity(target_bounds.opacity); | |
610 ui::ScopedLayerAnimationSettings status_animation_setter( | |
611 GetLayer(shelf_->status_area_widget())->GetAnimator()); | |
612 status_animation_setter.SetTransitionDuration( | |
613 base::TimeDelta::FromMilliseconds(kCrossFadeDurationMS)); | |
614 status_animation_setter.SetTweenType(ui::Tween::EASE_OUT); | |
615 status_animation_setter.SetPreemptionStrategy( | |
616 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
617 | 585 |
618 BackgroundAnimator::ChangeType change_type = | 586 BackgroundAnimator::ChangeType change_type = |
619 BackgroundAnimator::CHANGE_ANIMATE; | 587 BackgroundAnimator::CHANGE_ANIMATE; |
620 bool delay_background_change = false; | 588 bool delay_background_change = false; |
621 | 589 |
622 // Do not animate the background when: | 590 // Do not animate the background when: |
623 // - Going from a hidden / auto hidden shelf in fullscreen to a visible shelf | 591 // - Going from a hidden / auto hidden shelf in fullscreen to a visible shelf |
624 // in maximized mode. | 592 // in maximized mode. |
625 // - Going from an auto hidden shelf in maximized mode to a visible shelf in | 593 // - Going from an auto hidden shelf in maximized mode to a visible shelf in |
626 // maximized mode. | 594 // maximized mode. |
627 if (state.visibility_state == SHELF_VISIBLE && | 595 if (state.visibility_state == SHELF_VISIBLE && |
628 state.window_state == WORKSPACE_WINDOW_STATE_MAXIMIZED && | 596 state.window_state == WORKSPACE_WINDOW_STATE_MAXIMIZED && |
629 old_state.visibility_state != SHELF_VISIBLE) { | 597 old_state.visibility_state != SHELF_VISIBLE) { |
630 change_type = BackgroundAnimator::CHANGE_IMMEDIATE; | 598 change_type = BackgroundAnimator::CHANGE_IMMEDIATE; |
631 } else { | 599 } else { |
632 // Delay the animation when the shelf was hidden, and has just been made | 600 // Delay the animation when the shelf was hidden, and has just been made |
633 // visible (e.g. using a gesture-drag). | 601 // visible (e.g. using a gesture-drag). |
634 if (state.visibility_state == SHELF_VISIBLE && | 602 if (state.visibility_state == SHELF_VISIBLE && |
635 old_state.visibility_state == SHELF_AUTO_HIDE && | 603 old_state.visibility_state == SHELF_AUTO_HIDE && |
636 old_state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) { | 604 old_state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) { |
637 delay_background_change = true; | 605 delay_background_change = true; |
638 } | 606 } |
639 } | 607 } |
640 | 608 |
641 if (delay_background_change) { | 609 if (delay_background_change) { |
642 if (update_shelf_observer_) | 610 if (update_shelf_observer_) |
643 update_shelf_observer_->Detach(); | 611 update_shelf_observer_->Detach(); |
644 // UpdateShelfBackground deletes itself when the animation is done. | 612 // UpdateShelfBackground deletes itself when the animation is done. |
645 update_shelf_observer_ = new UpdateShelfObserver(this); | 613 update_shelf_observer_ = new UpdateShelfObserver(this); |
646 status_animation_setter.AddObserver(update_shelf_observer_); | |
647 } else { | 614 } else { |
648 UpdateShelfBackground(change_type); | 615 UpdateShelfBackground(change_type); |
649 } | 616 } |
650 | 617 |
651 shelf_->SetDimsShelf( | 618 shelf_->SetDimsShelf( |
652 state.visibility_state == SHELF_VISIBLE && | 619 state.visibility_state == SHELF_VISIBLE && |
653 state.window_state == WORKSPACE_WINDOW_STATE_MAXIMIZED); | 620 state.window_state == WORKSPACE_WINDOW_STATE_MAXIMIZED); |
654 | 621 |
655 ui::Layer* layer = GetLayer(shelf_->status_area_widget()); | 622 TargetBounds target_bounds; |
656 // TODO(harrym): Remove when status_area is view (crbug.com/180422). | 623 CalculateTargetBounds(state_, &target_bounds); |
657 gfx::Rect status_bounds = target_bounds.status_bounds_in_shelf; | 624 UpdateBoundsAndOpacity(target_bounds, true, |
658 status_bounds.set_x(status_bounds.x() + | 625 delay_background_change ? update_shelf_observer_ : NULL); |
659 target_bounds.shelf_bounds_in_root.x()); | |
660 status_bounds.set_y(status_bounds.y() + | |
661 target_bounds.shelf_bounds_in_root.y()); | |
662 layer->SetBounds(status_bounds); | |
663 layer->SetOpacity(target_bounds.status_opacity); | |
664 Shell::GetInstance()->SetDisplayWorkAreaInsets( | |
665 root_window_, target_bounds.work_area_insets); | |
666 UpdateHitTestBounds(); | |
667 | 626 |
668 // OnAutoHideStateChanged Should be emitted when: | 627 // OnAutoHideStateChanged Should be emitted when: |
669 // - firstly state changed to auto-hide from other state | 628 // - firstly state changed to auto-hide from other state |
670 // - or, auto_hide_state has changed | 629 // - or, auto_hide_state has changed |
671 if ((old_state.visibility_state != state_.visibility_state && | 630 if ((old_state.visibility_state != state_.visibility_state && |
672 state_.visibility_state == SHELF_AUTO_HIDE) || | 631 state_.visibility_state == SHELF_AUTO_HIDE) || |
673 old_state.auto_hide_state != state_.auto_hide_state) { | 632 old_state.auto_hide_state != state_.auto_hide_state) { |
674 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, | 633 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, |
675 OnAutoHideStateChanged(state_.auto_hide_state)); | 634 OnAutoHideStateChanged(state_.auto_hide_state)); |
676 } | 635 } |
677 } | 636 } |
678 | 637 |
638 void ShelfLayoutManager::UpdateBoundsAndOpacity( | |
639 const TargetBounds& target_bounds, | |
640 bool animate, | |
641 ui::ImplicitAnimationObserver* observer) { | |
642 base::AutoReset<bool> auto_reset_updating_bounds(&updating_bounds_, true); | |
643 | |
644 ui::ScopedLayerAnimationSettings launcher_animation_setter( | |
645 GetLayer(shelf_)->GetAnimator()); | |
646 ui::ScopedLayerAnimationSettings status_animation_setter( | |
647 GetLayer(shelf_->status_area_widget())->GetAnimator()); | |
648 if (animate) { | |
649 launcher_animation_setter.SetTransitionDuration( | |
650 base::TimeDelta::FromMilliseconds(kCrossFadeDurationMS)); | |
651 launcher_animation_setter.SetTweenType(ui::Tween::EASE_OUT); | |
652 launcher_animation_setter.SetPreemptionStrategy( | |
653 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
654 status_animation_setter.SetTransitionDuration( | |
655 base::TimeDelta::FromMilliseconds(kCrossFadeDurationMS)); | |
656 status_animation_setter.SetTweenType(ui::Tween::EASE_OUT); | |
657 status_animation_setter.SetPreemptionStrategy( | |
658 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); | |
659 } else { | |
660 StopAnimating(); | |
661 launcher_animation_setter.SetTransitionDuration(base::TimeDelta()); | |
662 status_animation_setter.SetTransitionDuration(base::TimeDelta()); | |
663 } | |
664 if (observer) | |
665 status_animation_setter.AddObserver(observer); | |
666 | |
667 GetLayer(shelf_)->SetOpacity(target_bounds.opacity); | |
668 shelf_->SetBounds(ScreenAsh::ConvertRectToScreen( | |
669 shelf_->GetNativeView()->parent(), | |
670 target_bounds.shelf_bounds_in_root)); | |
671 | |
672 GetLayer(shelf_->status_area_widget())->SetOpacity( | |
673 target_bounds.status_opacity); | |
674 // TODO(harrym): Once status area widget is a child view of shelf | |
675 // this can be simplified. | |
676 gfx::Rect status_bounds = target_bounds.status_bounds_in_shelf; | |
677 status_bounds.set_x(status_bounds.x() + | |
678 target_bounds.shelf_bounds_in_root.x()); | |
679 status_bounds.set_y(status_bounds.y() + | |
680 target_bounds.shelf_bounds_in_root.y()); | |
681 shelf_->status_area_widget()->SetBounds( | |
682 ScreenAsh::ConvertRectToScreen( | |
683 shelf_->status_area_widget()->GetNativeView()->parent(), | |
684 status_bounds)); | |
685 Shell::GetInstance()->SetDisplayWorkAreaInsets( | |
686 root_window_, target_bounds.work_area_insets); | |
687 UpdateHitTestBounds(); | |
688 } | |
689 | |
679 void ShelfLayoutManager::StopAnimating() { | 690 void ShelfLayoutManager::StopAnimating() { |
680 GetLayer(shelf_)->GetAnimator()->StopAnimating(); | 691 GetLayer(shelf_)->GetAnimator()->StopAnimating(); |
681 GetLayer(shelf_->status_area_widget())->GetAnimator()->StopAnimating(); | 692 GetLayer(shelf_->status_area_widget())->GetAnimator()->StopAnimating(); |
682 } | 693 } |
683 | 694 |
684 void ShelfLayoutManager::GetShelfSize(int* width, int* height) { | 695 void ShelfLayoutManager::GetShelfSize(int* width, int* height) { |
685 *width = *height = 0; | 696 *width = *height = 0; |
686 gfx::Size status_size( | 697 gfx::Size status_size( |
687 shelf_->status_area_widget()->GetWindowBoundsInScreen().size()); | 698 shelf_->status_area_widget()->GetWindowBoundsInScreen().size()); |
688 if (IsHorizontalAlignment()) | 699 if (IsHorizontalAlignment()) |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
947 // TODO: Figure out if we need any special handling when the keyboard is | 958 // TODO: Figure out if we need any special handling when the keyboard is |
948 // visible. | 959 // visible. |
949 return show_shelf_region_in_screen; | 960 return show_shelf_region_in_screen; |
950 } | 961 } |
951 | 962 |
952 ShelfAutoHideState ShelfLayoutManager::CalculateAutoHideState( | 963 ShelfAutoHideState ShelfLayoutManager::CalculateAutoHideState( |
953 ShelfVisibilityState visibility_state) const { | 964 ShelfVisibilityState visibility_state) const { |
954 if (visibility_state != SHELF_AUTO_HIDE || !shelf_) | 965 if (visibility_state != SHELF_AUTO_HIDE || !shelf_) |
955 return SHELF_AUTO_HIDE_HIDDEN; | 966 return SHELF_AUTO_HIDE_HIDDEN; |
956 | 967 |
957 if (gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS) | |
958 return gesture_drag_auto_hide_state_; | |
959 | |
960 Shell* shell = Shell::GetInstance(); | 968 Shell* shell = Shell::GetInstance(); |
961 if (shell->GetAppListTargetVisibility()) | 969 if (shell->GetAppListTargetVisibility()) |
962 return SHELF_AUTO_HIDE_SHOWN; | 970 return SHELF_AUTO_HIDE_SHOWN; |
963 | 971 |
964 if (shelf_->status_area_widget() && | 972 if (shelf_->status_area_widget() && |
965 shelf_->status_area_widget()->ShouldShowLauncher()) | 973 shelf_->status_area_widget()->ShouldShowLauncher()) |
966 return SHELF_AUTO_HIDE_SHOWN; | 974 return SHELF_AUTO_HIDE_SHOWN; |
967 | 975 |
968 if (shelf_->launcher() && shelf_->launcher()->IsShowingMenu()) | 976 if (shelf_->launcher() && shelf_->launcher()->IsShowingMenu()) |
969 return SHELF_AUTO_HIDE_SHOWN; | 977 return SHELF_AUTO_HIDE_SHOWN; |
970 | 978 |
971 if (shelf_->launcher() && shelf_->launcher()->IsShowingOverflowBubble()) | 979 if (shelf_->launcher() && shelf_->launcher()->IsShowingOverflowBubble()) |
972 return SHELF_AUTO_HIDE_SHOWN; | 980 return SHELF_AUTO_HIDE_SHOWN; |
973 | 981 |
974 if (shelf_->IsActive() || shelf_->status_area_widget()->IsActive()) | 982 if (shelf_->IsActive() || shelf_->status_area_widget()->IsActive()) |
975 return SHELF_AUTO_HIDE_SHOWN; | 983 return SHELF_AUTO_HIDE_SHOWN; |
976 | 984 |
985 const std::vector<aura::Window*> windows = | |
986 ash::MruWindowTracker::BuildWindowList(false); | |
987 | |
988 // Process the window list and check if there are any visible windows. | |
989 bool visible_window = false; | |
990 for (size_t i = 0; i < windows.size(); ++i) { | |
991 if (windows[i] && windows[i]->IsVisible() && | |
992 !ash::wm::IsWindowMinimized(windows[i]) && | |
993 root_window_ == windows[i]->GetRootWindow()) { | |
994 visible_window = true; | |
995 break; | |
996 } | |
997 } | |
998 // If there are no visible windows do not hide the shelf. | |
999 if (!visible_window) | |
1000 return SHELF_AUTO_HIDE_SHOWN; | |
1001 | |
1002 if (gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS) | |
1003 return gesture_drag_auto_hide_state_; | |
1004 | |
977 // Don't show if the user is dragging the mouse. | 1005 // Don't show if the user is dragging the mouse. |
978 if (auto_hide_event_filter_.get() && auto_hide_event_filter_->in_mouse_drag()) | 1006 if (auto_hide_event_filter_.get() && auto_hide_event_filter_->in_mouse_drag()) |
979 return SHELF_AUTO_HIDE_HIDDEN; | 1007 return SHELF_AUTO_HIDE_HIDDEN; |
980 | 1008 |
1009 // Ignore the mouse position if mouse events are disabled. | |
1010 aura::client::CursorClient* cursor_client = aura::client::GetCursorClient( | |
1011 shelf_->GetNativeWindow()->GetRootWindow()); | |
1012 if (!cursor_client->IsMouseEventsEnabled()) | |
1013 return SHELF_AUTO_HIDE_HIDDEN; | |
sadrul
2013/08/13 17:21:34
This parts are from another CL, right?
pkotwicz
2013/08/14 17:03:21
That CL has now landed, rebasing is easier :)
| |
1014 | |
981 gfx::Rect shelf_region = shelf_->GetWindowBoundsInScreen(); | 1015 gfx::Rect shelf_region = shelf_->GetWindowBoundsInScreen(); |
982 if (shelf_->status_area_widget() && | 1016 if (shelf_->status_area_widget() && |
983 shelf_->status_area_widget()->IsMessageBubbleShown() && | 1017 shelf_->status_area_widget()->IsMessageBubbleShown() && |
984 IsVisible()) { | 1018 IsVisible()) { |
985 // Increase the the hit test area to prevent the shelf from disappearing | 1019 // Increase the the hit test area to prevent the shelf from disappearing |
986 // when the mouse is over the bubble gap. | 1020 // when the mouse is over the bubble gap. |
987 shelf_region.Inset(alignment_ == SHELF_ALIGNMENT_RIGHT ? | 1021 shelf_region.Inset(alignment_ == SHELF_ALIGNMENT_RIGHT ? |
988 -kNotificationBubbleGapHeight : 0, | 1022 -kNotificationBubbleGapHeight : 0, |
989 alignment_ == SHELF_ALIGNMENT_BOTTOM ? | 1023 alignment_ == SHELF_ALIGNMENT_BOTTOM ? |
990 -kNotificationBubbleGapHeight : 0, | 1024 -kNotificationBubbleGapHeight : 0, |
(...skipping 20 matching lines...) Expand all Loading... | |
1011 // shelf slightly to make it easier to show the shelf in this situation. We | 1045 // shelf slightly to make it easier to show the shelf in this situation. We |
1012 // do not check |auto_hide_timer_|.IsRunning() because it returns false when | 1046 // do not check |auto_hide_timer_|.IsRunning() because it returns false when |
1013 // the timer's task is running. | 1047 // the timer's task is running. |
1014 if ((state_.auto_hide_state == SHELF_AUTO_HIDE_SHOWN || | 1048 if ((state_.auto_hide_state == SHELF_AUTO_HIDE_SHOWN || |
1015 mouse_over_shelf_when_auto_hide_timer_started_) && | 1049 mouse_over_shelf_when_auto_hide_timer_started_) && |
1016 GetAutoHideShowShelfRegionInScreen().Contains( | 1050 GetAutoHideShowShelfRegionInScreen().Contains( |
1017 cursor_position_in_screen)) { | 1051 cursor_position_in_screen)) { |
1018 return SHELF_AUTO_HIDE_SHOWN; | 1052 return SHELF_AUTO_HIDE_SHOWN; |
1019 } | 1053 } |
1020 | 1054 |
1021 const std::vector<aura::Window*> windows = | 1055 return SHELF_AUTO_HIDE_HIDDEN; |
1022 ash::MruWindowTracker::BuildWindowList(false); | |
1023 | |
1024 // Process the window list and check if there are any visible windows. | |
1025 for (size_t i = 0; i < windows.size(); ++i) { | |
1026 if (windows[i] && windows[i]->IsVisible() && | |
1027 !ash::wm::IsWindowMinimized(windows[i]) && | |
1028 root_window_ == windows[i]->GetRootWindow()) | |
1029 return SHELF_AUTO_HIDE_HIDDEN; | |
1030 } | |
1031 | |
1032 // If there are no visible windows do not hide the shelf. | |
1033 return SHELF_AUTO_HIDE_SHOWN; | |
1034 } | 1056 } |
1035 | 1057 |
1036 void ShelfLayoutManager::UpdateHitTestBounds() { | 1058 void ShelfLayoutManager::UpdateHitTestBounds() { |
1037 gfx::Insets mouse_insets; | 1059 gfx::Insets mouse_insets; |
1038 gfx::Insets touch_insets; | 1060 gfx::Insets touch_insets; |
1039 if (state_.visibility_state == SHELF_VISIBLE) { | 1061 if (state_.visibility_state == SHELF_VISIBLE) { |
1040 // Let clicks at the very top of the launcher through so windows can be | 1062 // Let clicks at the very top of the launcher through so windows can be |
1041 // resized with the bottom-right corner and bottom edge. | 1063 // resized with the bottom-right corner and bottom edge. |
1042 mouse_insets = GetInsetsForAlignment(kWorkspaceAreaVisibleInset); | 1064 mouse_insets = GetInsetsForAlignment(kWorkspaceAreaVisibleInset); |
1043 } else if (state_.visibility_state == SHELF_AUTO_HIDE) { | 1065 } else if (state_.visibility_state == SHELF_AUTO_HIDE) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1099 return gfx::Insets(0, distance, 0, 0); | 1121 return gfx::Insets(0, distance, 0, 0); |
1100 case SHELF_ALIGNMENT_TOP: | 1122 case SHELF_ALIGNMENT_TOP: |
1101 return gfx::Insets(0, 0, distance, 0); | 1123 return gfx::Insets(0, 0, distance, 0); |
1102 } | 1124 } |
1103 NOTREACHED(); | 1125 NOTREACHED(); |
1104 return gfx::Insets(); | 1126 return gfx::Insets(); |
1105 } | 1127 } |
1106 | 1128 |
1107 } // namespace internal | 1129 } // namespace internal |
1108 } // namespace ash | 1130 } // namespace ash |
OLD | NEW |