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 |
(...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
857 if (wm_shelf_->IsHorizontalAlignment()) | 857 if (wm_shelf_->IsHorizontalAlignment()) |
858 show_shelf_region_in_screen.set_height(kMaxAutoHideShowShelfRegionSize); | 858 show_shelf_region_in_screen.set_height(kMaxAutoHideShowShelfRegionSize); |
859 else | 859 else |
860 show_shelf_region_in_screen.set_width(kMaxAutoHideShowShelfRegionSize); | 860 show_shelf_region_in_screen.set_width(kMaxAutoHideShowShelfRegionSize); |
861 | 861 |
862 // TODO: Figure out if we need any special handling when the keyboard is | 862 // TODO: Figure out if we need any special handling when the keyboard is |
863 // visible. | 863 // visible. |
864 return show_shelf_region_in_screen; | 864 return show_shelf_region_in_screen; |
865 } | 865 } |
866 | 866 |
867 bool ShelfLayoutManager::HasVisibleWindow() const { | |
868 const int64_t shelf_display_id = | |
869 WmWindow::Get(shelf_widget_->GetNativeWindow()) | |
870 ->GetDisplayNearestWindow() | |
871 .id(); | |
oshima
2017/04/27 16:55:06
Sorry I missed this suggestion. It's simpler and f
| |
872 const std::vector<WmWindow*> windows = | |
873 Shell::Get()->mru_window_tracker()->BuildWindowListIgnoreModal(); | |
874 // Process the window list and check if there are any visible windows. | |
875 // Ignore app list windows that may be animating to hide after dismissal. | |
876 for (auto* window : windows) { | |
877 if (window->IsVisible() && !IsAppListWindow(window) && | |
878 window->GetDisplayNearestWindow().id() == shelf_display_id) { | |
879 return true; | |
880 } | |
881 } | |
882 return false; | |
883 } | |
884 | |
867 ShelfAutoHideState ShelfLayoutManager::CalculateAutoHideState( | 885 ShelfAutoHideState ShelfLayoutManager::CalculateAutoHideState( |
868 ShelfVisibilityState visibility_state) const { | 886 ShelfVisibilityState visibility_state) const { |
869 if (visibility_state != SHELF_AUTO_HIDE || !wm_shelf_->IsShelfInitialized()) | 887 if (visibility_state != SHELF_AUTO_HIDE || !wm_shelf_->IsShelfInitialized()) |
870 return SHELF_AUTO_HIDE_HIDDEN; | 888 return SHELF_AUTO_HIDE_HIDDEN; |
871 | 889 |
872 if (shelf_widget_->IsShowingAppList()) | 890 if (shelf_widget_->IsShowingAppList()) |
873 return SHELF_AUTO_HIDE_SHOWN; | 891 return SHELF_AUTO_HIDE_SHOWN; |
874 | 892 |
875 if (shelf_widget_->status_area_widget() && | 893 if (shelf_widget_->status_area_widget() && |
876 shelf_widget_->status_area_widget()->ShouldShowShelf()) | 894 shelf_widget_->status_area_widget()->ShouldShowShelf()) |
877 return SHELF_AUTO_HIDE_SHOWN; | 895 return SHELF_AUTO_HIDE_SHOWN; |
878 | 896 |
879 if (shelf_widget_->IsShowingContextMenu()) | 897 if (shelf_widget_->IsShowingContextMenu()) |
880 return SHELF_AUTO_HIDE_SHOWN; | 898 return SHELF_AUTO_HIDE_SHOWN; |
881 | 899 |
882 if (shelf_widget_->IsShowingOverflowBubble()) | 900 if (shelf_widget_->IsShowingOverflowBubble()) |
883 return SHELF_AUTO_HIDE_SHOWN; | 901 return SHELF_AUTO_HIDE_SHOWN; |
884 | 902 |
885 if (shelf_widget_->IsActive() || | 903 if (shelf_widget_->IsActive() || |
886 (shelf_widget_->status_area_widget() && | 904 (shelf_widget_->status_area_widget() && |
887 shelf_widget_->status_area_widget()->IsActive())) | 905 shelf_widget_->status_area_widget()->IsActive())) |
888 return SHELF_AUTO_HIDE_SHOWN; | 906 return SHELF_AUTO_HIDE_SHOWN; |
889 | 907 |
890 const int64_t shelf_display_id = | |
891 WmWindow::Get(shelf_widget_->GetNativeWindow()) | |
892 ->GetDisplayNearestWindow() | |
893 .id(); | |
894 const std::vector<WmWindow*> windows = | |
895 Shell::Get()->mru_window_tracker()->BuildWindowListIgnoreModal(); | |
896 // Process the window list and check if there are any visible windows. | |
897 // Ignore app list windows that may be animating to hide after dismissal. | |
898 bool visible_window = false; | |
899 for (size_t i = 0; i < windows.size(); ++i) { | |
900 if (windows[i] && windows[i]->IsVisible() && !IsAppListWindow(windows[i]) && | |
901 !windows[i]->GetWindowState()->IsMinimized() && | |
902 windows[i]->GetDisplayNearestWindow().id() == shelf_display_id) { | |
903 visible_window = true; | |
904 break; | |
905 } | |
906 } | |
907 // If there are no visible windows do not hide the shelf. | 908 // If there are no visible windows do not hide the shelf. |
908 if (!visible_window) | 909 if (!HasVisibleWindow()) |
909 return SHELF_AUTO_HIDE_SHOWN; | 910 return SHELF_AUTO_HIDE_SHOWN; |
910 | 911 |
911 if (gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS) | 912 if (gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS) |
912 return gesture_drag_auto_hide_state_; | 913 return gesture_drag_auto_hide_state_; |
913 | 914 |
914 // Don't show if the user is dragging the mouse. | 915 // Don't show if the user is dragging the mouse. |
915 if (in_mouse_drag_) | 916 if (in_mouse_drag_) |
916 return SHELF_AUTO_HIDE_HIDDEN; | 917 return SHELF_AUTO_HIDE_HIDDEN; |
917 | 918 |
918 // Ignore the mouse position if mouse events are disabled. | 919 // Ignore the mouse position if mouse events are disabled. |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1121 ? SHELF_AUTO_HIDE_HIDDEN | 1122 ? SHELF_AUTO_HIDE_HIDDEN |
1122 : SHELF_AUTO_HIDE_SHOWN; | 1123 : SHELF_AUTO_HIDE_SHOWN; |
1123 ShelfAutoHideBehavior new_auto_hide_behavior = | 1124 ShelfAutoHideBehavior new_auto_hide_behavior = |
1124 gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN | 1125 gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN |
1125 ? SHELF_AUTO_HIDE_BEHAVIOR_NEVER | 1126 ? SHELF_AUTO_HIDE_BEHAVIOR_NEVER |
1126 : SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; | 1127 : SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; |
1127 | 1128 |
1128 // When in fullscreen and the shelf is forced to be auto hidden, the auto hide | 1129 // When in fullscreen and the shelf is forced to be auto hidden, the auto hide |
1129 // behavior affects neither the visibility state nor the auto hide state. Set | 1130 // behavior affects neither the visibility state nor the auto hide state. Set |
1130 // |gesture_drag_status_| to GESTURE_DRAG_COMPLETE_IN_PROGRESS to set the auto | 1131 // |gesture_drag_status_| to GESTURE_DRAG_COMPLETE_IN_PROGRESS to set the auto |
1131 // hide state to |gesture_drag_auto_hide_state_|. | 1132 // hide state to |gesture_drag_auto_hide_state_|. Only change the auto-hide |
1133 // behavior if there is at least one window visible. | |
1132 gesture_drag_status_ = GESTURE_DRAG_COMPLETE_IN_PROGRESS; | 1134 gesture_drag_status_ = GESTURE_DRAG_COMPLETE_IN_PROGRESS; |
1133 if (wm_shelf_->auto_hide_behavior() != new_auto_hide_behavior) | 1135 if (wm_shelf_->auto_hide_behavior() != new_auto_hide_behavior && |
1136 HasVisibleWindow()) { | |
1134 wm_shelf_->SetAutoHideBehavior(new_auto_hide_behavior); | 1137 wm_shelf_->SetAutoHideBehavior(new_auto_hide_behavior); |
1135 else | 1138 } else { |
1136 UpdateVisibilityState(); | 1139 UpdateVisibilityState(); |
1140 } | |
1137 gesture_drag_status_ = GESTURE_DRAG_NONE; | 1141 gesture_drag_status_ = GESTURE_DRAG_NONE; |
1138 } | 1142 } |
1139 | 1143 |
1140 void ShelfLayoutManager::CancelGestureDrag() { | 1144 void ShelfLayoutManager::CancelGestureDrag() { |
1141 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS; | 1145 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS; |
1142 UpdateVisibilityState(); | 1146 UpdateVisibilityState(); |
1143 gesture_drag_status_ = GESTURE_DRAG_NONE; | 1147 gesture_drag_status_ = GESTURE_DRAG_NONE; |
1144 } | 1148 } |
1145 | 1149 |
1146 } // namespace ash | 1150 } // namespace ash |
OLD | NEW |