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/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_state.h" | 20 #include "ash/common/wm/window_state.h" |
| 21 #include "ash/common/wm/wm_screen_util.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/shelf/shelf.h" | 27 #include "ash/shelf/shelf.h" |
| 28 #include "ash/shelf/shelf_bezel_event_filter.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" | 30 #include "ash/shell.h" |
| 31 #include "ash/wm/gestures/shelf_gesture_handler.h" | 31 #include "ash/wm/gestures/shelf_gesture_handler.h" |
| 32 #include "ash/wm/window_animations.h" | 32 #include "ash/wm/window_animations.h" |
| 33 #include "ash/wm/workspace_controller.h" | 33 #include "ash/wm/workspace_controller.h" |
| 34 #include "base/auto_reset.h" | 34 #include "base/auto_reset.h" |
| 35 #include "base/i18n/rtl.h" | 35 #include "base/i18n/rtl.h" |
| 36 #include "ui/compositor/layer.h" | 36 #include "ui/compositor/layer.h" |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 // status_area_widget() may be NULL during the shutdown. | 241 // status_area_widget() may be NULL during the shutdown. |
| 242 return shelf_widget_->status_area_widget() && | 242 return shelf_widget_->status_area_widget() && |
| 243 shelf_widget_->status_area_widget()->IsVisible() && | 243 shelf_widget_->status_area_widget()->IsVisible() && |
| 244 (state_.visibility_state == SHELF_VISIBLE || | 244 (state_.visibility_state == SHELF_VISIBLE || |
| 245 (state_.visibility_state == SHELF_AUTO_HIDE && | 245 (state_.visibility_state == SHELF_AUTO_HIDE && |
| 246 state_.auto_hide_state == SHELF_AUTO_HIDE_SHOWN)); | 246 state_.auto_hide_state == SHELF_AUTO_HIDE_SHOWN)); |
| 247 } | 247 } |
| 248 | 248 |
| 249 gfx::Rect ShelfLayoutManager::GetIdealBounds() { | 249 gfx::Rect ShelfLayoutManager::GetIdealBounds() { |
| 250 const int shelf_size = GetShelfConstant(SHELF_SIZE); | 250 const int shelf_size = GetShelfConstant(SHELF_SIZE); |
| 251 gfx::Rect rect( | 251 WmWindow* shelf_window = WmLookup::Get()->GetWindowForWidget(shelf_widget_); |
|
James Cook
2016/08/05 23:51:25
optional thought: I wonder if we should cache the
msw
2016/08/06 00:08:13
Yeah, that might make sense, but I'd punt on cachi
| |
| 252 ScreenUtil::GetDisplayBoundsInParent(shelf_widget_->GetNativeView())); | 252 gfx::Rect rect(wm::GetDisplayBoundsInParent(shelf_window)); |
| 253 return SelectValueForShelfAlignment( | 253 return SelectValueForShelfAlignment( |
| 254 gfx::Rect(rect.x(), rect.bottom() - shelf_size, rect.width(), shelf_size), | 254 gfx::Rect(rect.x(), rect.bottom() - shelf_size, rect.width(), shelf_size), |
| 255 gfx::Rect(rect.x(), rect.y(), shelf_size, rect.height()), | 255 gfx::Rect(rect.x(), rect.y(), shelf_size, rect.height()), |
| 256 gfx::Rect(rect.right() - shelf_size, rect.y(), shelf_size, | 256 gfx::Rect(rect.right() - shelf_size, rect.y(), shelf_size, |
| 257 rect.height())); | 257 rect.height())); |
| 258 } | 258 } |
| 259 | 259 |
| 260 gfx::Size ShelfLayoutManager::GetPreferredSize() { | 260 gfx::Size ShelfLayoutManager::GetPreferredSize() { |
| 261 TargetBounds target_bounds; | 261 TargetBounds target_bounds; |
| 262 CalculateTargetBounds(state_, &target_bounds); | 262 CalculateTargetBounds(state_, &target_bounds); |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 726 StopAnimating(); | 726 StopAnimating(); |
| 727 shelf_animation_setter.SetTransitionDuration(base::TimeDelta()); | 727 shelf_animation_setter.SetTransitionDuration(base::TimeDelta()); |
| 728 status_animation_setter.SetTransitionDuration(base::TimeDelta()); | 728 status_animation_setter.SetTransitionDuration(base::TimeDelta()); |
| 729 } | 729 } |
| 730 if (observer) | 730 if (observer) |
| 731 status_animation_setter.AddObserver(observer); | 731 status_animation_setter.AddObserver(observer); |
| 732 | 732 |
| 733 GetLayer(shelf_widget_)->SetOpacity(target_bounds.opacity); | 733 GetLayer(shelf_widget_)->SetOpacity(target_bounds.opacity); |
| 734 // mash::wm::ShelfLayout manages window bounds when running in mash. | 734 // mash::wm::ShelfLayout manages window bounds when running in mash. |
| 735 if (!Shell::GetInstance()->in_mus()) { | 735 if (!Shell::GetInstance()->in_mus()) { |
| 736 shelf_widget_->SetBounds(ScreenUtil::ConvertRectToScreen( | 736 WmWindow* window = WmLookup::Get()->GetWindowForWidget(shelf_widget_); |
| 737 shelf_widget_->GetNativeView()->parent(), | 737 shelf_widget_->SetBounds(window->GetParent()->ConvertRectToScreen( |
| 738 target_bounds.shelf_bounds_in_root)); | 738 target_bounds.shelf_bounds_in_root)); |
| 739 } | 739 } |
| 740 | 740 |
| 741 GetLayer(shelf_widget_->status_area_widget()) | 741 GetLayer(shelf_widget_->status_area_widget()) |
| 742 ->SetOpacity(target_bounds.status_opacity); | 742 ->SetOpacity(target_bounds.status_opacity); |
| 743 | 743 |
| 744 // Having a window which is visible but does not have an opacity is an | 744 // Having a window which is visible but does not have an opacity is an |
| 745 // illegal state. We therefore hide the shelf here if required. | 745 // illegal state. We therefore hide the shelf here if required. |
| 746 if (!target_bounds.status_opacity) | 746 if (!target_bounds.status_opacity) |
| 747 shelf_widget_->status_area_widget()->Hide(); | 747 shelf_widget_->status_area_widget()->Hide(); |
| 748 // Setting visibility during an animation causes the visibility property to | 748 // Setting visibility during an animation causes the visibility property to |
| 749 // animate. Override the animation settings to immediately set the | 749 // animate. Override the animation settings to immediately set the |
| 750 // visibility property. Opacity will still animate. | 750 // visibility property. Opacity will still animate. |
| 751 | 751 |
| 752 // TODO(harrym): Once status area widget is a child view of shelf | 752 // TODO(harrym): Once status area widget is a child view of shelf |
| 753 // this can be simplified. | 753 // this can be simplified. |
| 754 gfx::Rect status_bounds = target_bounds.status_bounds_in_shelf; | 754 gfx::Rect status_bounds = target_bounds.status_bounds_in_shelf; |
| 755 status_bounds.Offset(target_bounds.shelf_bounds_in_root.OffsetFromOrigin()); | 755 status_bounds.Offset(target_bounds.shelf_bounds_in_root.OffsetFromOrigin()); |
| 756 // mash::wm::ShelfLayout manages window bounds when running mash. | 756 // mash::wm::ShelfLayout manages window bounds when running mash. |
| 757 if (!Shell::GetInstance()->in_mus()) { | 757 if (!Shell::GetInstance()->in_mus()) { |
| 758 WmWindow* window = WmLookup::Get()->GetWindowForWidget( | |
| 759 shelf_widget_->status_area_widget()); | |
| 758 shelf_widget_->status_area_widget()->SetBounds( | 760 shelf_widget_->status_area_widget()->SetBounds( |
| 759 ScreenUtil::ConvertRectToScreen( | 761 window->GetParent()->ConvertRectToScreen(status_bounds)); |
| 760 shelf_widget_->status_area_widget()->GetNativeView()->parent(), | |
| 761 status_bounds)); | |
| 762 } | 762 } |
| 763 // 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 |
| 764 // 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. |
| 765 if (!state_.is_screen_locked && | 765 if (!state_.is_screen_locked && |
| 766 shelf_widget_->GetAlignment() != SHELF_ALIGNMENT_BOTTOM_LOCKED) { | 766 shelf_widget_->GetAlignment() != SHELF_ALIGNMENT_BOTTOM_LOCKED) { |
| 767 gfx::Insets insets; | 767 gfx::Insets insets; |
| 768 // If user session is blocked (login to new user session or add user to | 768 // If user session is blocked (login to new user session or add user to |
| 769 // the existing session - multi-profile) then give 100% of work area only | 769 // the existing session - multi-profile) then give 100% of work area only |
| 770 // if keyboard is not shown. | 770 // if keyboard is not shown. |
| 771 if (!state_.is_adding_user_screen || !keyboard_bounds_.IsEmpty()) | 771 if (!state_.is_adding_user_screen || !keyboard_bounds_.IsEmpty()) |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 800 // Auto-hidden shelf always starts with the default size. If a gesture-drag | 800 // Auto-hidden shelf always starts with the default size. If a gesture-drag |
| 801 // is in progress, then the call to UpdateTargetBoundsForGesture() below | 801 // is in progress, then the call to UpdateTargetBoundsForGesture() below |
| 802 // takes care of setting the height properly. | 802 // takes care of setting the height properly. |
| 803 shelf_size = kShelfAutoHideSize; | 803 shelf_size = kShelfAutoHideSize; |
| 804 } else if (state.visibility_state == SHELF_HIDDEN || | 804 } else if (state.visibility_state == SHELF_HIDDEN || |
| 805 (!keyboard_bounds_.IsEmpty() && | 805 (!keyboard_bounds_.IsEmpty() && |
| 806 !keyboard::IsKeyboardOverscrollEnabled())) { | 806 !keyboard::IsKeyboardOverscrollEnabled())) { |
| 807 shelf_size = 0; | 807 shelf_size = 0; |
| 808 } | 808 } |
| 809 | 809 |
| 810 gfx::Rect available_bounds = | 810 WmWindow* shelf_window = WmLookup::Get()->GetWindowForWidget(shelf_widget_); |
| 811 ScreenUtil::GetShelfDisplayBoundsInRoot(root_window_); | 811 gfx::Rect available_bounds = wm::GetShelfDisplayBoundsForWindow(shelf_window); |
| 812 available_bounds.Inset(0, chromevox_panel_height_, 0, 0); | 812 available_bounds.Inset(0, chromevox_panel_height_, 0, 0); |
| 813 int shelf_width = PrimaryAxisValue(available_bounds.width(), shelf_size); | 813 int shelf_width = PrimaryAxisValue(available_bounds.width(), shelf_size); |
| 814 int shelf_height = PrimaryAxisValue(shelf_size, available_bounds.height()); | 814 int shelf_height = PrimaryAxisValue(shelf_size, available_bounds.height()); |
| 815 int bottom_shelf_vertical_offset = available_bounds.bottom(); | 815 int bottom_shelf_vertical_offset = available_bounds.bottom(); |
| 816 if (keyboard_bounds_.IsEmpty()) | 816 if (keyboard_bounds_.IsEmpty()) |
| 817 bottom_shelf_vertical_offset -= shelf_height; | 817 bottom_shelf_vertical_offset -= shelf_height; |
| 818 else | 818 else |
| 819 bottom_shelf_vertical_offset -= keyboard_bounds_.height(); | 819 bottom_shelf_vertical_offset -= keyboard_bounds_.height(); |
| 820 | 820 |
| 821 gfx::Point shelf_origin = SelectValueForShelfAlignment( | 821 gfx::Point shelf_origin = SelectValueForShelfAlignment( |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 885 target_bounds->shelf_bounds_in_shelf = SelectValueForShelfAlignment( | 885 target_bounds->shelf_bounds_in_shelf = SelectValueForShelfAlignment( |
| 886 gfx::Rect(0, 0, shelf_width - status_size.width(), | 886 gfx::Rect(0, 0, shelf_width - status_size.width(), |
| 887 target_bounds->shelf_bounds_in_root.height()), | 887 target_bounds->shelf_bounds_in_root.height()), |
| 888 gfx::Rect(0, 0, target_bounds->shelf_bounds_in_root.width(), | 888 gfx::Rect(0, 0, target_bounds->shelf_bounds_in_root.width(), |
| 889 shelf_height - status_size.height()), | 889 shelf_height - status_size.height()), |
| 890 gfx::Rect(0, 0, target_bounds->shelf_bounds_in_root.width(), | 890 gfx::Rect(0, 0, target_bounds->shelf_bounds_in_root.width(), |
| 891 shelf_height - status_size.height())); | 891 shelf_height - status_size.height())); |
| 892 | 892 |
| 893 available_bounds.Subtract(target_bounds->shelf_bounds_in_root); | 893 available_bounds.Subtract(target_bounds->shelf_bounds_in_root); |
| 894 available_bounds.Subtract(keyboard_bounds_); | 894 available_bounds.Subtract(keyboard_bounds_); |
| 895 user_work_area_bounds_ = | 895 |
| 896 ScreenUtil::ConvertRectToScreen(root_window_, available_bounds); | 896 WmWindow* root = shelf_window->GetRootWindow(); |
| 897 user_work_area_bounds_ = root->ConvertRectToScreen(available_bounds); | |
| 897 } | 898 } |
| 898 | 899 |
| 899 void ShelfLayoutManager::UpdateTargetBoundsForGesture( | 900 void ShelfLayoutManager::UpdateTargetBoundsForGesture( |
| 900 TargetBounds* target_bounds) const { | 901 TargetBounds* target_bounds) const { |
| 901 CHECK_EQ(GESTURE_DRAG_IN_PROGRESS, gesture_drag_status_); | 902 CHECK_EQ(GESTURE_DRAG_IN_PROGRESS, gesture_drag_status_); |
| 902 bool horizontal = IsHorizontalAlignment(); | 903 bool horizontal = IsHorizontalAlignment(); |
| 903 gfx::Rect available_bounds = | 904 WmWindow* window = WmLookup::Get()->GetWindowForWidget(shelf_widget_); |
| 904 ScreenUtil::GetShelfDisplayBoundsInRoot(root_window_); | 905 gfx::Rect available_bounds = wm::GetShelfDisplayBoundsForWindow(window); |
| 905 int resistance_free_region = 0; | 906 int resistance_free_region = 0; |
| 906 | 907 |
| 907 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && | 908 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && |
| 908 visibility_state() == SHELF_AUTO_HIDE && | 909 visibility_state() == SHELF_AUTO_HIDE && |
| 909 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) { | 910 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) { |
| 910 // If the shelf was hidden when the drag started (and the state hasn't | 911 // If the shelf was hidden when the drag started (and the state hasn't |
| 911 // changed since then, e.g. because the tray-menu was shown because of the | 912 // changed since then, e.g. because the tray-menu was shown because of the |
| 912 // drag), then allow the drag some resistance-free region at first to make | 913 // drag), then allow the drag some resistance-free region at first to make |
| 913 // sure the shelf sticks with the finger until the shelf is visible. | 914 // sure the shelf sticks with the finger until the shelf is visible. |
| 914 resistance_free_region = GetShelfConstant(SHELF_SIZE) - kShelfAutoHideSize; | 915 resistance_free_region = GetShelfConstant(SHELF_SIZE) - kShelfAutoHideSize; |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1185 if (ash::MaterialDesignController::IsShelfMaterial()) { | 1186 if (ash::MaterialDesignController::IsShelfMaterial()) { |
| 1186 return (state.visibility_state == SHELF_AUTO_HIDE && | 1187 return (state.visibility_state == SHELF_AUTO_HIDE && |
| 1187 state.auto_hide_state == SHELF_AUTO_HIDE_SHOWN) | 1188 state.auto_hide_state == SHELF_AUTO_HIDE_SHOWN) |
| 1188 ? 1.0f | 1189 ? 1.0f |
| 1189 : 0.0f; | 1190 : 0.0f; |
| 1190 } | 1191 } |
| 1191 return (state.visibility_state == SHELF_AUTO_HIDE) ? 1.0f : 0.0f; | 1192 return (state.visibility_state == SHELF_AUTO_HIDE) ? 1.0f : 0.0f; |
| 1192 } | 1193 } |
| 1193 | 1194 |
| 1194 } // namespace ash | 1195 } // namespace ash |
| OLD | NEW |