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

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

Issue 2237613002: mash: Migrate some misc ShelfLayoutManager deps to ash common. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move ShelfBezelEventHandler to WmShelfAura. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/shelf/shelf_layout_manager.h" 5 #include "ash/shelf/shelf_layout_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <vector> 9 #include <vector>
10 10
11 #include "ash/common/material_design/material_design_controller.h" 11 #include "ash/common/material_design/material_design_controller.h"
12 #include "ash/common/session/session_state_delegate.h" 12 #include "ash/common/session/session_state_delegate.h"
13 #include "ash/common/shelf/shelf_constants.h" 13 #include "ash/common/shelf/shelf_constants.h"
14 #include "ash/common/shelf/shelf_delegate.h" 14 #include "ash/common/shelf/shelf_delegate.h"
15 #include "ash/common/shelf/wm_shelf_util.h" 15 #include "ash/common/shelf/wm_shelf_util.h"
16 #include "ash/common/shell_window_ids.h" 16 #include "ash/common/shell_window_ids.h"
17 #include "ash/common/system/status_area_widget.h" 17 #include "ash/common/system/status_area_widget.h"
18 #include "ash/common/wm/fullscreen_window_finder.h" 18 #include "ash/common/wm/fullscreen_window_finder.h"
19 #include "ash/common/wm/mru_window_tracker.h" 19 #include "ash/common/wm/mru_window_tracker.h"
20 #include "ash/common/wm/window_animation_types.h"
20 #include "ash/common/wm/window_state.h" 21 #include "ash/common/wm/window_state.h"
21 #include "ash/common/wm/wm_screen_util.h" 22 #include "ash/common/wm/wm_screen_util.h"
22 #include "ash/common/wm_lookup.h" 23 #include "ash/common/wm_lookup.h"
23 #include "ash/common/wm_root_window_controller.h" 24 #include "ash/common/wm_root_window_controller.h"
24 #include "ash/common/wm_root_window_controller_observer.h" 25 #include "ash/common/wm_root_window_controller_observer.h"
25 #include "ash/common/wm_shell.h" 26 #include "ash/common/wm_shell.h"
26 #include "ash/common/wm_window.h" 27 #include "ash/common/wm_window.h"
27 #include "ash/shelf/shelf.h" 28 #include "ash/shelf/shelf.h"
28 #include "ash/shelf/shelf_bezel_event_filter.h"
29 #include "ash/shelf/shelf_layout_manager_observer.h" 29 #include "ash/shelf/shelf_layout_manager_observer.h"
30 #include "ash/shell.h"
James Cook 2016/08/11 00:50:06 hooray!
msw 2016/08/11 02:08:51 Acknowledged.
31 #include "ash/wm/window_animations.h"
32 #include "ash/wm/workspace_controller.h" 30 #include "ash/wm/workspace_controller.h"
33 #include "base/auto_reset.h" 31 #include "base/auto_reset.h"
34 #include "base/i18n/rtl.h" 32 #include "base/i18n/rtl.h"
35 #include "ui/compositor/layer.h" 33 #include "ui/compositor/layer.h"
36 #include "ui/compositor/layer_animation_observer.h" 34 #include "ui/compositor/layer_animation_observer.h"
37 #include "ui/compositor/layer_animator.h" 35 #include "ui/compositor/layer_animator.h"
38 #include "ui/compositor/scoped_layer_animation_settings.h" 36 #include "ui/compositor/scoped_layer_animation_settings.h"
39 #include "ui/display/display.h" 37 #include "ui/display/display.h"
40 #include "ui/display/screen.h" 38 #include "ui/display/screen.h"
41 #include "ui/events/event.h" 39 #include "ui/events/event.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 }; 138 };
141 139
142 // ShelfLayoutManager ---------------------------------------------------------- 140 // ShelfLayoutManager ----------------------------------------------------------
143 141
144 ShelfLayoutManager::ShelfLayoutManager(ShelfWidget* shelf_widget) 142 ShelfLayoutManager::ShelfLayoutManager(ShelfWidget* shelf_widget)
145 : updating_bounds_(false), 143 : updating_bounds_(false),
146 shelf_widget_(shelf_widget), 144 shelf_widget_(shelf_widget),
147 workspace_controller_(NULL), 145 workspace_controller_(NULL),
148 window_overlaps_shelf_(false), 146 window_overlaps_shelf_(false),
149 mouse_over_shelf_when_auto_hide_timer_started_(false), 147 mouse_over_shelf_when_auto_hide_timer_started_(false),
150 bezel_event_filter_(new ShelfBezelEventFilter(this)),
151 gesture_drag_status_(GESTURE_DRAG_NONE), 148 gesture_drag_status_(GESTURE_DRAG_NONE),
152 gesture_drag_amount_(0.f), 149 gesture_drag_amount_(0.f),
153 gesture_drag_auto_hide_state_(SHELF_AUTO_HIDE_SHOWN), 150 gesture_drag_auto_hide_state_(SHELF_AUTO_HIDE_SHOWN),
154 update_shelf_observer_(NULL), 151 update_shelf_observer_(NULL),
155 chromevox_panel_height_(0), 152 chromevox_panel_height_(0),
156 duration_override_in_ms_(0), 153 duration_override_in_ms_(0),
157 root_window_controller_observer_( 154 root_window_controller_observer_(
158 new RootWindowControllerObserverImpl(this)) { 155 new RootWindowControllerObserverImpl(this)) {
159 WmShell::Get()->AddShellObserver(this); 156 WmShell::Get()->AddShellObserver(this);
160 WmShell::Get()->AddLockStateObserver(this); 157 WmShell::Get()->AddLockStateObserver(this);
161 WmShell::Get()->AddActivationObserver(this); 158 WmShell::Get()->AddActivationObserver(this);
162 WmShell::Get()->GetSessionStateDelegate()->AddSessionStateObserver(this); 159 WmShell::Get()->GetSessionStateDelegate()->AddSessionStateObserver(this);
163 } 160 }
164 161
165 ShelfLayoutManager::~ShelfLayoutManager() { 162 ShelfLayoutManager::~ShelfLayoutManager() {
166 if (update_shelf_observer_) 163 if (update_shelf_observer_)
167 update_shelf_observer_->Detach(); 164 update_shelf_observer_->Detach();
168 165
169 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, 166 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_,
170 WillDeleteShelfLayoutManager()); 167 WillDeleteShelfLayoutManager());
171 WmShell::Get()->RemoveShellObserver(this); 168 WmShell::Get()->RemoveShellObserver(this);
172 WmShell::Get()->RemoveLockStateObserver(this); 169 WmShell::Get()->RemoveLockStateObserver(this);
173 WmShell::Get()->GetSessionStateDelegate()->RemoveSessionStateObserver(this); 170 WmShell::Get()->GetSessionStateDelegate()->RemoveSessionStateObserver(this);
174 } 171 }
175 172
176 void ShelfLayoutManager::PrepareForShutdown() { 173 void ShelfLayoutManager::PrepareForShutdown() {
177 in_shutdown_ = true; 174 in_shutdown_ = true;
178 // Clear all event filters, otherwise sometimes those filters may catch 175 set_workspace_controller(nullptr);
179 // synthesized mouse event and cause crashes during the shutdown.
180 set_workspace_controller(NULL);
181 bezel_event_filter_.reset();
182 // Stop observing changes to avoid updating a partially destructed shelf. 176 // Stop observing changes to avoid updating a partially destructed shelf.
183 WmShell::Get()->RemoveActivationObserver(this); 177 WmShell::Get()->RemoveActivationObserver(this);
184 } 178 }
185 179
186 bool ShelfLayoutManager::IsVisible() const { 180 bool ShelfLayoutManager::IsVisible() const {
187 // status_area_widget() may be NULL during the shutdown. 181 // status_area_widget() may be NULL during the shutdown.
188 return shelf_widget_->status_area_widget() && 182 return shelf_widget_->status_area_widget() &&
189 shelf_widget_->status_area_widget()->IsVisible() && 183 shelf_widget_->status_area_widget()->IsVisible() &&
190 (state_.visibility_state == SHELF_VISIBLE || 184 (state_.visibility_state == SHELF_VISIBLE ||
191 (state_.visibility_state == SHELF_AUTO_HIDE && 185 (state_.visibility_state == SHELF_AUTO_HIDE &&
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 } 389 }
396 } 390 }
397 391
398 void ShelfLayoutManager::OnLockStateChanged(bool locked) { 392 void ShelfLayoutManager::OnLockStateChanged(bool locked) {
399 // Force the shelf to layout for alignment (bottom if locked, restore 393 // Force the shelf to layout for alignment (bottom if locked, restore
400 // the previous alignment otherwise). 394 // the previous alignment otherwise).
401 state_.is_screen_locked = locked; 395 state_.is_screen_locked = locked;
402 UpdateShelfVisibilityAfterLoginUIChange(); 396 UpdateShelfVisibilityAfterLoginUIChange();
403 } 397 }
404 398
405 void ShelfLayoutManager::OnShelfAlignmentChanged(WmWindow* root_window) {
406 if (Shell::GetInstance()->in_mus())
407 LayoutShelf();
408 }
409
410 void ShelfLayoutManager::OnShelfAutoHideBehaviorChanged(WmWindow* root_window) { 399 void ShelfLayoutManager::OnShelfAutoHideBehaviorChanged(WmWindow* root_window) {
411 UpdateVisibilityState(); 400 UpdateVisibilityState();
412 } 401 }
413 402
414 void ShelfLayoutManager::OnPinnedStateChanged(WmWindow* pinned_window) { 403 void ShelfLayoutManager::OnPinnedStateChanged(WmWindow* pinned_window) {
415 // Shelf needs to be hidden on entering to pinned mode, or restored 404 // Shelf needs to be hidden on entering to pinned mode, or restored
416 // on exiting from pinned mode. 405 // on exiting from pinned mode.
417 UpdateVisibilityState(); 406 UpdateVisibilityState();
418 } 407 }
419 408
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 bool animate, 558 bool animate,
570 ui::ImplicitAnimationObserver* observer) { 559 ui::ImplicitAnimationObserver* observer) {
571 base::AutoReset<bool> auto_reset_updating_bounds(&updating_bounds_, true); 560 base::AutoReset<bool> auto_reset_updating_bounds(&updating_bounds_, true);
572 { 561 {
573 ui::ScopedLayerAnimationSettings shelf_animation_setter( 562 ui::ScopedLayerAnimationSettings shelf_animation_setter(
574 GetLayer(shelf_widget_)->GetAnimator()); 563 GetLayer(shelf_widget_)->GetAnimator());
575 ui::ScopedLayerAnimationSettings status_animation_setter( 564 ui::ScopedLayerAnimationSettings status_animation_setter(
576 GetLayer(shelf_widget_->status_area_widget())->GetAnimator()); 565 GetLayer(shelf_widget_->status_area_widget())->GetAnimator());
577 if (animate) { 566 if (animate) {
578 int duration = duration_override_in_ms_ ? duration_override_in_ms_ 567 int duration = duration_override_in_ms_ ? duration_override_in_ms_
579 : kCrossFadeDurationMS; 568 : wm::kCrossFadeDurationMS;
580 shelf_animation_setter.SetTransitionDuration( 569 shelf_animation_setter.SetTransitionDuration(
581 base::TimeDelta::FromMilliseconds(duration)); 570 base::TimeDelta::FromMilliseconds(duration));
582 shelf_animation_setter.SetTweenType(gfx::Tween::EASE_OUT); 571 shelf_animation_setter.SetTweenType(gfx::Tween::EASE_OUT);
583 shelf_animation_setter.SetPreemptionStrategy( 572 shelf_animation_setter.SetPreemptionStrategy(
584 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 573 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
585 status_animation_setter.SetTransitionDuration( 574 status_animation_setter.SetTransitionDuration(
586 base::TimeDelta::FromMilliseconds(duration)); 575 base::TimeDelta::FromMilliseconds(duration));
587 status_animation_setter.SetTweenType(gfx::Tween::EASE_OUT); 576 status_animation_setter.SetTweenType(gfx::Tween::EASE_OUT);
588 status_animation_setter.SetPreemptionStrategy( 577 status_animation_setter.SetPreemptionStrategy(
589 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 578 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
590 } else { 579 } else {
591 StopAnimating(); 580 StopAnimating();
592 shelf_animation_setter.SetTransitionDuration(base::TimeDelta()); 581 shelf_animation_setter.SetTransitionDuration(base::TimeDelta());
593 status_animation_setter.SetTransitionDuration(base::TimeDelta()); 582 status_animation_setter.SetTransitionDuration(base::TimeDelta());
594 } 583 }
595 if (observer) 584 if (observer)
596 status_animation_setter.AddObserver(observer); 585 status_animation_setter.AddObserver(observer);
597 586
598 GetLayer(shelf_widget_)->SetOpacity(target_bounds.opacity); 587 GetLayer(shelf_widget_)->SetOpacity(target_bounds.opacity);
599 // mash::wm::ShelfLayout manages window bounds when running in mash. 588 WmWindow* shelf_window = WmLookup::Get()->GetWindowForWidget(shelf_widget_);
600 if (!Shell::GetInstance()->in_mus()) { 589 shelf_widget_->SetBounds(shelf_window->GetParent()->ConvertRectToScreen(
601 WmWindow* window = WmLookup::Get()->GetWindowForWidget(shelf_widget_); 590 target_bounds.shelf_bounds_in_root));
602 shelf_widget_->SetBounds(window->GetParent()->ConvertRectToScreen(
603 target_bounds.shelf_bounds_in_root));
604 }
605 591
606 GetLayer(shelf_widget_->status_area_widget()) 592 GetLayer(shelf_widget_->status_area_widget())
607 ->SetOpacity(target_bounds.status_opacity); 593 ->SetOpacity(target_bounds.status_opacity);
608 594
609 // Having a window which is visible but does not have an opacity is an 595 // Having a window which is visible but does not have an opacity is an
610 // illegal state. We therefore hide the shelf here if required. 596 // illegal state. We therefore hide the shelf here if required.
611 if (!target_bounds.status_opacity) 597 if (!target_bounds.status_opacity)
612 shelf_widget_->status_area_widget()->Hide(); 598 shelf_widget_->status_area_widget()->Hide();
613 // Setting visibility during an animation causes the visibility property to 599 // Setting visibility during an animation causes the visibility property to
614 // animate. Override the animation settings to immediately set the 600 // animate. Override the animation settings to immediately set the
615 // visibility property. Opacity will still animate. 601 // visibility property. Opacity will still animate.
616 602
617 // TODO(harrym): Once status area widget is a child view of shelf 603 // TODO(harrym): Once status area widget is a child view of shelf
618 // this can be simplified. 604 // this can be simplified.
619 gfx::Rect status_bounds = target_bounds.status_bounds_in_shelf; 605 gfx::Rect status_bounds = target_bounds.status_bounds_in_shelf;
620 status_bounds.Offset(target_bounds.shelf_bounds_in_root.OffsetFromOrigin()); 606 status_bounds.Offset(target_bounds.shelf_bounds_in_root.OffsetFromOrigin());
621 // mash::wm::ShelfLayout manages window bounds when running mash. 607 WmWindow* status_window = WmLookup::Get()->GetWindowForWidget(
622 if (!Shell::GetInstance()->in_mus()) { 608 shelf_widget_->status_area_widget());
623 WmWindow* window = WmLookup::Get()->GetWindowForWidget( 609 shelf_widget_->status_area_widget()->SetBounds(
624 shelf_widget_->status_area_widget()); 610 status_window->GetParent()->ConvertRectToScreen(status_bounds));
625 shelf_widget_->status_area_widget()->SetBounds( 611
626 window->GetParent()->ConvertRectToScreen(status_bounds));
627 }
628 // For crbug.com/622431, when the shelf alignment is BOTTOM_LOCKED, we 612 // For crbug.com/622431, when the shelf alignment is BOTTOM_LOCKED, we
629 // don't set display work area, as it is not real user-set alignment. 613 // don't set display work area, as it is not real user-set alignment.
630 if (!state_.is_screen_locked && 614 if (!state_.is_screen_locked &&
631 shelf_widget_->GetAlignment() != SHELF_ALIGNMENT_BOTTOM_LOCKED) { 615 shelf_widget_->GetAlignment() != SHELF_ALIGNMENT_BOTTOM_LOCKED) {
632 gfx::Insets insets; 616 gfx::Insets insets;
633 // If user session is blocked (login to new user session or add user to 617 // If user session is blocked (login to new user session or add user to
634 // the existing session - multi-profile) then give 100% of work area only 618 // the existing session - multi-profile) then give 100% of work area only
635 // if keyboard is not shown. 619 // if keyboard is not shown.
636 if (!state_.is_adding_user_screen || !keyboard_bounds_.IsEmpty()) 620 if (!state_.is_adding_user_screen || !keyboard_bounds_.IsEmpty())
637 insets = target_bounds.work_area_insets; 621 insets = target_bounds.work_area_insets;
638 WmWindow* window = WmLookup::Get()->GetWindowForWidget(shelf_widget_); 622 WmShell::Get()->SetDisplayWorkAreaInsets(shelf_window, insets);
639 WmShell::Get()->SetDisplayWorkAreaInsets(window, insets);
640 } 623 }
641 } 624 }
642 625
643 // Set an empty border to avoid the shelf view and status area overlapping. 626 // Set an empty border to avoid the shelf view and status area overlapping.
644 // TODO(msw): Avoid setting bounds of views within the shelf widget here. 627 // TODO(msw): Avoid setting bounds of views within the shelf widget here.
645 gfx::Rect shelf_bounds = gfx::Rect(target_bounds.shelf_bounds_in_root.size()); 628 gfx::Rect shelf_bounds = gfx::Rect(target_bounds.shelf_bounds_in_root.size());
646 shelf_widget_->GetContentsView()->SetBorder(views::Border::CreateEmptyBorder( 629 shelf_widget_->GetContentsView()->SetBorder(views::Border::CreateEmptyBorder(
647 shelf_bounds.InsetsFrom(target_bounds.shelf_bounds_in_shelf))); 630 shelf_bounds.InsetsFrom(target_bounds.shelf_bounds_in_shelf)));
648 shelf_widget_->GetContentsView()->Layout(); 631 shelf_widget_->GetContentsView()->Layout();
649 632
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 883
901 if (shelf_widget_->shelf() && 884 if (shelf_widget_->shelf() &&
902 shelf_widget_->shelf()->IsShowingOverflowBubble()) 885 shelf_widget_->shelf()->IsShowingOverflowBubble())
903 return SHELF_AUTO_HIDE_SHOWN; 886 return SHELF_AUTO_HIDE_SHOWN;
904 887
905 if (shelf_widget_->IsActive() || 888 if (shelf_widget_->IsActive() ||
906 (shelf_widget_->status_area_widget() && 889 (shelf_widget_->status_area_widget() &&
907 shelf_widget_->status_area_widget()->IsActive())) 890 shelf_widget_->status_area_widget()->IsActive()))
908 return SHELF_AUTO_HIDE_SHOWN; 891 return SHELF_AUTO_HIDE_SHOWN;
909 892
910 // TODO(jamescook): Track visible windows on mash via ShelfDelegate. 893 const std::vector<WmWindow*> windows =
911 if (!Shell::GetInstance()->in_mus()) { 894 WmShell::Get()->mru_window_tracker()->BuildWindowListIgnoreModal();
912 const std::vector<WmWindow*> windows =
913 WmShell::Get()->mru_window_tracker()->BuildWindowListIgnoreModal();
914 895
915 // Process the window list and check if there are any visible windows. 896 // Process the window list and check if there are any visible windows.
916 bool visible_window = false; 897 bool visible_window = false;
917 for (size_t i = 0; i < windows.size(); ++i) { 898 for (size_t i = 0; i < windows.size(); ++i) {
918 if (windows[i] && windows[i]->IsVisible() && 899 if (windows[i] && windows[i]->IsVisible() &&
919 !windows[i]->GetWindowState()->IsMinimized() && 900 !windows[i]->GetWindowState()->IsMinimized() &&
920 windows[i]->GetDisplayNearestWindow().id() == shelf_display_id) { 901 windows[i]->GetDisplayNearestWindow().id() == shelf_display_id) {
921 visible_window = true; 902 visible_window = true;
922 break; 903 break;
923 }
924 } 904 }
925 // If there are no visible windows do not hide the shelf.
926 if (!visible_window)
927 return SHELF_AUTO_HIDE_SHOWN;
928 } 905 }
906 // If there are no visible windows do not hide the shelf.
907 if (!visible_window)
908 return SHELF_AUTO_HIDE_SHOWN;
929 909
930 if (gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS) 910 if (gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS)
931 return gesture_drag_auto_hide_state_; 911 return gesture_drag_auto_hide_state_;
932 912
933 // Don't show if the user is dragging the mouse. 913 // Don't show if the user is dragging the mouse.
934 if (in_mouse_drag_) 914 if (in_mouse_drag_)
935 return SHELF_AUTO_HIDE_HIDDEN; 915 return SHELF_AUTO_HIDE_HIDDEN;
936 916
937 // Ignore the mouse position if mouse events are disabled. 917 // Ignore the mouse position if mouse events are disabled.
938 if (!shelf_widget_->IsMouseEventsEnabled()) 918 if (!shelf_widget_->IsMouseEventsEnabled())
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 gesture_drag_status_ = GESTURE_DRAG_NONE; 1134 gesture_drag_status_ = GESTURE_DRAG_NONE;
1155 } 1135 }
1156 1136
1157 void ShelfLayoutManager::CancelGestureDrag() { 1137 void ShelfLayoutManager::CancelGestureDrag() {
1158 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS; 1138 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS;
1159 UpdateVisibilityState(); 1139 UpdateVisibilityState();
1160 gesture_drag_status_ = GESTURE_DRAG_NONE; 1140 gesture_drag_status_ = GESTURE_DRAG_NONE;
1161 } 1141 }
1162 1142
1163 } // namespace ash 1143 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698