Chromium Code Reviews| 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 <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "ash/common/ash_switches.h" | |
| 11 #include "ash/common/material_design/material_design_controller.h" | 12 #include "ash/common/material_design/material_design_controller.h" |
| 12 #include "ash/common/session/session_state_delegate.h" | 13 #include "ash/common/session/session_state_delegate.h" |
| 13 #include "ash/common/shelf/shelf_constants.h" | 14 #include "ash/common/shelf/shelf_constants.h" |
| 14 #include "ash/common/shelf/shelf_delegate.h" | 15 #include "ash/common/shelf/shelf_delegate.h" |
| 15 #include "ash/common/shelf/wm_shelf_util.h" | 16 #include "ash/common/shelf/wm_shelf_util.h" |
| 16 #include "ash/common/shell_window_ids.h" | 17 #include "ash/common/shell_window_ids.h" |
| 17 #include "ash/common/system/status_area_widget.h" | 18 #include "ash/common/system/status_area_widget.h" |
| 18 #include "ash/common/wm/fullscreen_window_finder.h" | 19 #include "ash/common/wm/fullscreen_window_finder.h" |
| 19 #include "ash/common/wm/mru_window_tracker.h" | 20 #include "ash/common/wm/mru_window_tracker.h" |
| 20 #include "ash/common/wm/window_state.h" | 21 #include "ash/common/wm/window_state.h" |
| 21 #include "ash/common/wm_lookup.h" | 22 #include "ash/common/wm_lookup.h" |
| 22 #include "ash/common/wm_root_window_controller.h" | 23 #include "ash/common/wm_root_window_controller.h" |
| 23 #include "ash/common/wm_root_window_controller_observer.h" | 24 #include "ash/common/wm_root_window_controller_observer.h" |
| 24 #include "ash/common/wm_shell.h" | 25 #include "ash/common/wm_shell.h" |
| 25 #include "ash/common/wm_window.h" | 26 #include "ash/common/wm_window.h" |
| 26 #include "ash/screen_util.h" | 27 #include "ash/screen_util.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_bezel_event_filter.h" |
| 29 #include "ash/shelf/shelf_layout_manager_observer.h" | 30 #include "ash/shelf/shelf_layout_manager_observer.h" |
| 30 #include "ash/shell.h" | 31 #include "ash/shell.h" |
| 31 #include "ash/wm/gestures/shelf_gesture_handler.h" | 32 #include "ash/wm/gestures/shelf_gesture_handler.h" |
| 32 #include "ash/wm/window_animations.h" | 33 #include "ash/wm/window_animations.h" |
| 33 #include "ash/wm/workspace_controller.h" | 34 #include "ash/wm/workspace_controller.h" |
| 34 #include "base/auto_reset.h" | 35 #include "base/auto_reset.h" |
| 36 #include "base/command_line.h" | |
| 35 #include "base/i18n/rtl.h" | 37 #include "base/i18n/rtl.h" |
| 36 #include "ui/compositor/layer.h" | 38 #include "ui/compositor/layer.h" |
| 37 #include "ui/compositor/layer_animation_observer.h" | 39 #include "ui/compositor/layer_animation_observer.h" |
| 38 #include "ui/compositor/layer_animator.h" | 40 #include "ui/compositor/layer_animator.h" |
| 39 #include "ui/compositor/scoped_layer_animation_settings.h" | 41 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 40 #include "ui/display/display.h" | 42 #include "ui/display/display.h" |
| 41 #include "ui/display/screen.h" | 43 #include "ui/display/screen.h" |
| 42 #include "ui/events/event.h" | 44 #include "ui/events/event.h" |
| 43 #include "ui/events/event_handler.h" | 45 #include "ui/events/event_handler.h" |
| 46 #include "ui/keyboard/keyboard_controller.h" | |
| 44 #include "ui/keyboard/keyboard_util.h" | 47 #include "ui/keyboard/keyboard_util.h" |
| 45 #include "ui/views/border.h" | 48 #include "ui/views/border.h" |
| 46 #include "ui/views/widget/widget.h" | 49 #include "ui/views/widget/widget.h" |
| 47 | 50 |
| 48 namespace ash { | 51 namespace ash { |
| 49 namespace { | 52 namespace { |
| 50 | 53 |
| 51 // Delay before showing the shelf. This is after the mouse stops moving. | 54 // Delay before showing the shelf. This is after the mouse stops moving. |
| 52 const int kAutoHideDelayMS = 200; | 55 const int kAutoHideDelayMS = 200; |
| 53 | 56 |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 | 263 |
| 261 gfx::Size ShelfLayoutManager::GetPreferredSize() { | 264 gfx::Size ShelfLayoutManager::GetPreferredSize() { |
| 262 TargetBounds target_bounds; | 265 TargetBounds target_bounds; |
| 263 CalculateTargetBounds(state_, &target_bounds); | 266 CalculateTargetBounds(state_, &target_bounds); |
| 264 return target_bounds.shelf_bounds_in_root.size(); | 267 return target_bounds.shelf_bounds_in_root.size(); |
| 265 } | 268 } |
| 266 | 269 |
| 267 void ShelfLayoutManager::LayoutShelf() { | 270 void ShelfLayoutManager::LayoutShelf() { |
| 268 TargetBounds target_bounds; | 271 TargetBounds target_bounds; |
| 269 CalculateTargetBounds(state_, &target_bounds); | 272 CalculateTargetBounds(state_, &target_bounds); |
| 270 UpdateBoundsAndOpacity(target_bounds, false, NULL); | 273 UpdateBoundsAndOpacity(target_bounds, false, true, NULL); |
| 271 | 274 |
| 272 // Update insets in ShelfWindowTargeter when shelf bounds change. | 275 // Update insets in ShelfWindowTargeter when shelf bounds change. |
| 273 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, | 276 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, |
| 274 WillChangeVisibilityState(visibility_state())); | 277 WillChangeVisibilityState(visibility_state())); |
| 275 } | 278 } |
| 276 | 279 |
| 277 ShelfVisibilityState ShelfLayoutManager::CalculateShelfVisibility() { | 280 ShelfVisibilityState ShelfLayoutManager::CalculateShelfVisibility() { |
| 278 switch (shelf_widget_->shelf()->auto_hide_behavior()) { | 281 switch (shelf_widget_->shelf()->auto_hide_behavior()) { |
| 279 case SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: | 282 case SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: |
| 280 return SHELF_AUTO_HIDE; | 283 return SHELF_AUTO_HIDE; |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 543 void ShelfLayoutManager::OnWindowActivated(WmWindow* gained_active, | 546 void ShelfLayoutManager::OnWindowActivated(WmWindow* gained_active, |
| 544 WmWindow* lost_active) { | 547 WmWindow* lost_active) { |
| 545 UpdateAutoHideStateNow(); | 548 UpdateAutoHideStateNow(); |
| 546 } | 549 } |
| 547 | 550 |
| 548 void ShelfLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { | 551 void ShelfLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { |
| 549 bool keyboard_is_about_to_hide = false; | 552 bool keyboard_is_about_to_hide = false; |
| 550 if (new_bounds.IsEmpty() && !keyboard_bounds_.IsEmpty()) | 553 if (new_bounds.IsEmpty() && !keyboard_bounds_.IsEmpty()) |
| 551 keyboard_is_about_to_hide = true; | 554 keyboard_is_about_to_hide = true; |
| 552 | 555 |
| 556 // If new window behavior flag enabled and in non-sticky mode, do not change | |
| 557 // the work area. | |
| 558 bool change_work_area = | |
| 559 (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 560 switches::kAshUseNewVKWindowBehavior) || | |
| 561 keyboard::KeyboardController::GetInstance()->get_lock_keyboard()); | |
| 562 | |
| 553 keyboard_bounds_ = new_bounds; | 563 keyboard_bounds_ = new_bounds; |
| 554 OnWindowResized(); | 564 TargetBounds target_bounds; |
| 565 CalculateTargetBounds(state_, &target_bounds); | |
| 566 UpdateBoundsAndOpacity(target_bounds, false, change_work_area, NULL); | |
| 567 | |
| 568 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, | |
| 569 WillChangeVisibilityState(visibility_state())); | |
|
oshima
2016/08/02 16:33:53
Instead of coyping, can you add change_work_area p
hariank
2016/08/03 18:09:39
Done.
| |
| 555 | 570 |
| 556 // On login screen if keyboard has been just hidden, update bounds just once | 571 // On login screen if keyboard has been just hidden, update bounds just once |
| 557 // but ignore target_bounds.work_area_insets since shelf overlaps with login | 572 // but ignore target_bounds.work_area_insets since shelf overlaps with login |
| 558 // window. | 573 // window. |
| 559 if (WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked() && | 574 if (WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked() && |
| 560 keyboard_is_about_to_hide) { | 575 keyboard_is_about_to_hide) { |
| 561 Shell::GetInstance()->SetDisplayWorkAreaInsets(root_window_, gfx::Insets()); | 576 Shell::GetInstance()->SetDisplayWorkAreaInsets(root_window_, gfx::Insets()); |
| 562 } | 577 } |
| 563 } | 578 } |
| 564 | 579 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 653 } else { | 668 } else { |
| 654 UpdateShelfBackground(change_type); | 669 UpdateShelfBackground(change_type); |
| 655 } | 670 } |
| 656 | 671 |
| 657 shelf_widget_->SetDimsShelf(state.visibility_state == SHELF_VISIBLE && | 672 shelf_widget_->SetDimsShelf(state.visibility_state == SHELF_VISIBLE && |
| 658 state.window_state == | 673 state.window_state == |
| 659 wm::WORKSPACE_WINDOW_STATE_MAXIMIZED); | 674 wm::WORKSPACE_WINDOW_STATE_MAXIMIZED); |
| 660 | 675 |
| 661 TargetBounds target_bounds; | 676 TargetBounds target_bounds; |
| 662 CalculateTargetBounds(state_, &target_bounds); | 677 CalculateTargetBounds(state_, &target_bounds); |
| 663 UpdateBoundsAndOpacity(target_bounds, true, delay_background_change | 678 UpdateBoundsAndOpacity(target_bounds, true, true, delay_background_change |
| 664 ? update_shelf_observer_ | 679 ? update_shelf_observer_ |
| 665 : NULL); | 680 : NULL); |
| 666 | 681 |
| 667 // The delegate must be notified after |state_| is updated so that it can | 682 // The delegate must be notified after |state_| is updated so that it can |
| 668 // query the new target bounds. | 683 // query the new target bounds. |
| 669 ShelfDelegate* shelf_delegate = WmShell::Get()->shelf_delegate(); | 684 ShelfDelegate* shelf_delegate = WmShell::Get()->shelf_delegate(); |
| 670 DCHECK(shelf_delegate); | 685 DCHECK(shelf_delegate); |
| 671 if (old_state.visibility_state != state_.visibility_state) | 686 if (old_state.visibility_state != state_.visibility_state) |
| 672 shelf_delegate->OnShelfVisibilityStateChanged(shelf_widget_->shelf()); | 687 shelf_delegate->OnShelfVisibilityStateChanged(shelf_widget_->shelf()); |
| 673 | 688 |
| 674 // OnAutoHideStateChanged Should be emitted when: | 689 // OnAutoHideStateChanged Should be emitted when: |
| 675 // - firstly state changed to auto-hide from other state | 690 // - firstly state changed to auto-hide from other state |
| 676 // - or, auto_hide_state has changed | 691 // - or, auto_hide_state has changed |
| 677 if ((old_state.visibility_state != state_.visibility_state && | 692 if ((old_state.visibility_state != state_.visibility_state && |
| 678 state_.visibility_state == SHELF_AUTO_HIDE) || | 693 state_.visibility_state == SHELF_AUTO_HIDE) || |
| 679 old_state.auto_hide_state != state_.auto_hide_state) { | 694 old_state.auto_hide_state != state_.auto_hide_state) { |
| 680 shelf_delegate->OnShelfAutoHideStateChanged(shelf_widget_->shelf()); | 695 shelf_delegate->OnShelfAutoHideStateChanged(shelf_widget_->shelf()); |
| 681 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, | 696 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, |
| 682 OnAutoHideStateChanged(state_.auto_hide_state)); | 697 OnAutoHideStateChanged(state_.auto_hide_state)); |
| 683 } | 698 } |
| 684 } | 699 } |
| 685 | 700 |
| 686 void ShelfLayoutManager::UpdateBoundsAndOpacity( | 701 void ShelfLayoutManager::UpdateBoundsAndOpacity( |
| 687 const TargetBounds& target_bounds, | 702 const TargetBounds& target_bounds, |
| 688 bool animate, | 703 bool animate, |
| 704 bool change_work_area, | |
| 689 ui::ImplicitAnimationObserver* observer) { | 705 ui::ImplicitAnimationObserver* observer) { |
| 690 base::AutoReset<bool> auto_reset_updating_bounds(&updating_bounds_, true); | 706 base::AutoReset<bool> auto_reset_updating_bounds(&updating_bounds_, true); |
| 691 { | 707 { |
| 692 ui::ScopedLayerAnimationSettings shelf_animation_setter( | 708 ui::ScopedLayerAnimationSettings shelf_animation_setter( |
| 693 GetLayer(shelf_widget_)->GetAnimator()); | 709 GetLayer(shelf_widget_)->GetAnimator()); |
| 694 ui::ScopedLayerAnimationSettings status_animation_setter( | 710 ui::ScopedLayerAnimationSettings status_animation_setter( |
| 695 GetLayer(shelf_widget_->status_area_widget())->GetAnimator()); | 711 GetLayer(shelf_widget_->status_area_widget())->GetAnimator()); |
| 696 if (animate) { | 712 if (animate) { |
| 697 int duration = duration_override_in_ms_ ? duration_override_in_ms_ | 713 int duration = duration_override_in_ms_ ? duration_override_in_ms_ |
| 698 : kCrossFadeDurationMS; | 714 : kCrossFadeDurationMS; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 740 // mash::wm::ShelfLayout manages window bounds when running mash. | 756 // mash::wm::ShelfLayout manages window bounds when running mash. |
| 741 if (!Shell::GetInstance()->in_mus()) { | 757 if (!Shell::GetInstance()->in_mus()) { |
| 742 shelf_widget_->status_area_widget()->SetBounds( | 758 shelf_widget_->status_area_widget()->SetBounds( |
| 743 ScreenUtil::ConvertRectToScreen( | 759 ScreenUtil::ConvertRectToScreen( |
| 744 shelf_widget_->status_area_widget()->GetNativeView()->parent(), | 760 shelf_widget_->status_area_widget()->GetNativeView()->parent(), |
| 745 status_bounds)); | 761 status_bounds)); |
| 746 } | 762 } |
| 747 // For crbug.com/622431, when the shelf alignment is BOTTOM_LOCKED, we | 763 // For crbug.com/622431, when the shelf alignment is BOTTOM_LOCKED, we |
| 748 // don't set display work area, as it is not real user-set alignment. | 764 // don't set display work area, as it is not real user-set alignment. |
| 749 if (!state_.is_screen_locked && | 765 if (!state_.is_screen_locked && |
| 750 shelf_widget_->GetAlignment() != SHELF_ALIGNMENT_BOTTOM_LOCKED) { | 766 shelf_widget_->GetAlignment() != SHELF_ALIGNMENT_BOTTOM_LOCKED && |
| 767 change_work_area) { | |
| 751 gfx::Insets insets; | 768 gfx::Insets insets; |
| 752 // If user session is blocked (login to new user session or add user to | 769 // If user session is blocked (login to new user session or add user to |
| 753 // the existing session - multi-profile) then give 100% of work area only | 770 // the existing session - multi-profile) then give 100% of work area only |
| 754 // if keyboard is not shown. | 771 // if keyboard is not shown. |
|
oshima
2016/08/02 16:33:53
can you test if this works in lock screen?
hariank
2016/08/03 18:09:39
Done.
| |
| 755 if (!state_.is_adding_user_screen || !keyboard_bounds_.IsEmpty()) | 772 if (!state_.is_adding_user_screen || !keyboard_bounds_.IsEmpty()) |
| 756 insets = target_bounds.work_area_insets; | 773 insets = target_bounds.work_area_insets; |
| 757 Shell::GetInstance()->SetDisplayWorkAreaInsets(root_window_, insets); | 774 Shell::GetInstance()->SetDisplayWorkAreaInsets(root_window_, insets); |
| 758 } | 775 } |
| 759 } | 776 } |
| 760 | 777 |
| 761 // Set an empty border to avoid the shelf view and status area overlapping. | 778 // Set an empty border to avoid the shelf view and status area overlapping. |
| 762 // TODO(msw): Avoid setting bounds of views within the shelf widget here. | 779 // TODO(msw): Avoid setting bounds of views within the shelf widget here. |
| 763 gfx::Rect shelf_bounds = gfx::Rect(target_bounds.shelf_bounds_in_root.size()); | 780 gfx::Rect shelf_bounds = gfx::Rect(target_bounds.shelf_bounds_in_root.size()); |
| 764 shelf_widget_->GetContentsView()->SetBorder(views::Border::CreateEmptyBorder( | 781 shelf_widget_->GetContentsView()->SetBorder(views::Border::CreateEmptyBorder( |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1158 // Check transition changes to/from the add user to session and change the | 1175 // Check transition changes to/from the add user to session and change the |
| 1159 // shelf alignment accordingly | 1176 // shelf alignment accordingly |
| 1160 bool add_user = state == SessionStateDelegate::SESSION_STATE_LOGIN_SECONDARY; | 1177 bool add_user = state == SessionStateDelegate::SESSION_STATE_LOGIN_SECONDARY; |
| 1161 if (add_user != state_.is_adding_user_screen) { | 1178 if (add_user != state_.is_adding_user_screen) { |
| 1162 state_.is_adding_user_screen = add_user; | 1179 state_.is_adding_user_screen = add_user; |
| 1163 UpdateShelfVisibilityAfterLoginUIChange(); | 1180 UpdateShelfVisibilityAfterLoginUIChange(); |
| 1164 return; | 1181 return; |
| 1165 } | 1182 } |
| 1166 TargetBounds target_bounds; | 1183 TargetBounds target_bounds; |
| 1167 CalculateTargetBounds(state_, &target_bounds); | 1184 CalculateTargetBounds(state_, &target_bounds); |
| 1168 UpdateBoundsAndOpacity(target_bounds, true, NULL); | 1185 UpdateBoundsAndOpacity(target_bounds, true, true, NULL); |
| 1169 UpdateVisibilityState(); | 1186 UpdateVisibilityState(); |
| 1170 } | 1187 } |
| 1171 | 1188 |
| 1172 void ShelfLayoutManager::UpdateShelfVisibilityAfterLoginUIChange() { | 1189 void ShelfLayoutManager::UpdateShelfVisibilityAfterLoginUIChange() { |
| 1173 UpdateVisibilityState(); | 1190 UpdateVisibilityState(); |
| 1174 LayoutShelf(); | 1191 LayoutShelf(); |
| 1175 } | 1192 } |
| 1176 | 1193 |
| 1177 float ShelfLayoutManager::ComputeTargetOpacity(const State& state) { | 1194 float ShelfLayoutManager::ComputeTargetOpacity(const State& state) { |
| 1178 if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS || | 1195 if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS || |
| 1179 state.visibility_state == SHELF_VISIBLE) { | 1196 state.visibility_state == SHELF_VISIBLE) { |
| 1180 return 1.0f; | 1197 return 1.0f; |
| 1181 } | 1198 } |
| 1182 // In Chrome OS Material Design, when shelf is hidden during auto hide state, | 1199 // In Chrome OS Material Design, when shelf is hidden during auto hide state, |
| 1183 // target bounds are also hidden. So the window can extend to the edge of | 1200 // target bounds are also hidden. So the window can extend to the edge of |
| 1184 // screen. | 1201 // screen. |
| 1185 if (ash::MaterialDesignController::IsShelfMaterial()) { | 1202 if (ash::MaterialDesignController::IsShelfMaterial()) { |
| 1186 return (state.visibility_state == SHELF_AUTO_HIDE && | 1203 return (state.visibility_state == SHELF_AUTO_HIDE && |
| 1187 state.auto_hide_state == SHELF_AUTO_HIDE_SHOWN) | 1204 state.auto_hide_state == SHELF_AUTO_HIDE_SHOWN) |
| 1188 ? 1.0f | 1205 ? 1.0f |
| 1189 : 0.0f; | 1206 : 0.0f; |
| 1190 } | 1207 } |
| 1191 return (state.visibility_state == SHELF_AUTO_HIDE) ? 1.0f : 0.0f; | 1208 return (state.visibility_state == SHELF_AUTO_HIDE) ? 1.0f : 0.0f; |
| 1192 } | 1209 } |
| 1193 | 1210 |
| 1194 } // namespace ash | 1211 } // namespace ash |
| OLD | NEW |