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/animation/animation_change_type.h" | 11 #include "ash/animation/animation_change_type.h" |
12 #include "ash/keyboard/keyboard_observer_register.h" | 12 #include "ash/keyboard/keyboard_observer_register.h" |
13 #include "ash/public/cpp/shell_window_ids.h" | 13 #include "ash/public/cpp/shell_window_ids.h" |
14 #include "ash/root_window_controller.h" | 14 #include "ash/root_window_controller.h" |
15 #include "ash/screen_util.h" | 15 #include "ash/screen_util.h" |
16 #include "ash/session/session_controller.h" | 16 #include "ash/session/session_controller.h" |
| 17 #include "ash/shelf/shelf.h" |
17 #include "ash/shelf/shelf_constants.h" | 18 #include "ash/shelf/shelf_constants.h" |
18 #include "ash/shelf/shelf_layout_manager_observer.h" | 19 #include "ash/shelf/shelf_layout_manager_observer.h" |
19 #include "ash/shelf/shelf_widget.h" | 20 #include "ash/shelf/shelf_widget.h" |
20 #include "ash/shelf/wm_shelf.h" | |
21 #include "ash/shell.h" | 21 #include "ash/shell.h" |
22 #include "ash/shell_port.h" | 22 #include "ash/shell_port.h" |
23 #include "ash/system/status_area_widget.h" | 23 #include "ash/system/status_area_widget.h" |
24 #include "ash/wm/fullscreen_window_finder.h" | 24 #include "ash/wm/fullscreen_window_finder.h" |
25 #include "ash/wm/mru_window_tracker.h" | 25 #include "ash/wm/mru_window_tracker.h" |
26 #include "ash/wm/screen_pinning_controller.h" | 26 #include "ash/wm/screen_pinning_controller.h" |
27 #include "ash/wm/window_state.h" | 27 #include "ash/wm/window_state.h" |
28 #include "ash/wm_window.h" | 28 #include "ash/wm_window.h" |
29 #include "base/auto_reset.h" | 29 #include "base/auto_reset.h" |
30 #include "base/command_line.h" | 30 #include "base/command_line.h" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 (visibility_state != SHELF_AUTO_HIDE || | 134 (visibility_state != SHELF_AUTO_HIDE || |
135 other.auto_hide_state == auto_hide_state) && | 135 other.auto_hide_state == auto_hide_state) && |
136 other.window_state == window_state && | 136 other.window_state == window_state && |
137 other.pre_lock_screen_animation_active == | 137 other.pre_lock_screen_animation_active == |
138 pre_lock_screen_animation_active && | 138 pre_lock_screen_animation_active && |
139 other.session_state == session_state; | 139 other.session_state == session_state; |
140 } | 140 } |
141 | 141 |
142 // ShelfLayoutManager ---------------------------------------------------------- | 142 // ShelfLayoutManager ---------------------------------------------------------- |
143 | 143 |
144 ShelfLayoutManager::ShelfLayoutManager(ShelfWidget* shelf_widget, | 144 ShelfLayoutManager::ShelfLayoutManager(ShelfWidget* shelf_widget, Shelf* shelf) |
145 WmShelf* wm_shelf) | |
146 : updating_bounds_(false), | 145 : updating_bounds_(false), |
147 shelf_widget_(shelf_widget), | 146 shelf_widget_(shelf_widget), |
148 wm_shelf_(wm_shelf), | 147 shelf_(shelf), |
149 window_overlaps_shelf_(false), | 148 window_overlaps_shelf_(false), |
150 mouse_over_shelf_when_auto_hide_timer_started_(false), | 149 mouse_over_shelf_when_auto_hide_timer_started_(false), |
151 gesture_drag_status_(GESTURE_DRAG_NONE), | 150 gesture_drag_status_(GESTURE_DRAG_NONE), |
152 gesture_drag_amount_(0.f), | 151 gesture_drag_amount_(0.f), |
153 gesture_drag_auto_hide_state_(SHELF_AUTO_HIDE_SHOWN), | 152 gesture_drag_auto_hide_state_(SHELF_AUTO_HIDE_SHOWN), |
154 update_shelf_observer_(nullptr), | 153 update_shelf_observer_(nullptr), |
155 chromevox_panel_height_(0), | 154 chromevox_panel_height_(0), |
156 duration_override_in_ms_(0), | 155 duration_override_in_ms_(0), |
157 shelf_background_type_(SHELF_BACKGROUND_OVERLAP), | 156 shelf_background_type_(SHELF_BACKGROUND_OVERLAP), |
158 keyboard_observer_(this), | 157 keyboard_observer_(this), |
159 scoped_session_observer_(this) { | 158 scoped_session_observer_(this) { |
160 DCHECK(shelf_widget_); | 159 DCHECK(shelf_widget_); |
161 DCHECK(wm_shelf_); | 160 DCHECK(shelf_); |
162 Shell::Get()->AddShellObserver(this); | 161 Shell::Get()->AddShellObserver(this); |
163 ShellPort::Get()->AddLockStateObserver(this); | 162 ShellPort::Get()->AddLockStateObserver(this); |
164 Shell::Get()->activation_client()->AddObserver(this); | 163 Shell::Get()->activation_client()->AddObserver(this); |
165 state_.session_state = Shell::Get()->session_controller()->GetSessionState(); | 164 state_.session_state = Shell::Get()->session_controller()->GetSessionState(); |
166 } | 165 } |
167 | 166 |
168 ShelfLayoutManager::~ShelfLayoutManager() { | 167 ShelfLayoutManager::~ShelfLayoutManager() { |
169 if (update_shelf_observer_) | 168 if (update_shelf_observer_) |
170 update_shelf_observer_->Detach(); | 169 update_shelf_observer_->Detach(); |
171 | 170 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 // Update insets in ShelfWindowTargeter when shelf bounds change. | 213 // Update insets in ShelfWindowTargeter when shelf bounds change. |
215 for (auto& observer : observers_) | 214 for (auto& observer : observers_) |
216 observer.WillChangeVisibilityState(visibility_state()); | 215 observer.WillChangeVisibilityState(visibility_state()); |
217 } | 216 } |
218 | 217 |
219 void ShelfLayoutManager::LayoutShelf() { | 218 void ShelfLayoutManager::LayoutShelf() { |
220 LayoutShelfAndUpdateBounds(true); | 219 LayoutShelfAndUpdateBounds(true); |
221 } | 220 } |
222 | 221 |
223 ShelfVisibilityState ShelfLayoutManager::CalculateShelfVisibility() { | 222 ShelfVisibilityState ShelfLayoutManager::CalculateShelfVisibility() { |
224 switch (wm_shelf_->auto_hide_behavior()) { | 223 switch (shelf_->auto_hide_behavior()) { |
225 case SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: | 224 case SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: |
226 return SHELF_AUTO_HIDE; | 225 return SHELF_AUTO_HIDE; |
227 case SHELF_AUTO_HIDE_BEHAVIOR_NEVER: | 226 case SHELF_AUTO_HIDE_BEHAVIOR_NEVER: |
228 return SHELF_VISIBLE; | 227 return SHELF_VISIBLE; |
229 case SHELF_AUTO_HIDE_ALWAYS_HIDDEN: | 228 case SHELF_AUTO_HIDE_ALWAYS_HIDDEN: |
230 return SHELF_HIDDEN; | 229 return SHELF_HIDDEN; |
231 } | 230 } |
232 return SHELF_VISIBLE; | 231 return SHELF_VISIBLE; |
233 } | 232 } |
234 | 233 |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 // this can be simplified. | 626 // this can be simplified. |
628 gfx::Rect status_bounds = target_bounds.status_bounds_in_shelf; | 627 gfx::Rect status_bounds = target_bounds.status_bounds_in_shelf; |
629 status_bounds.Offset(target_bounds.shelf_bounds_in_root.OffsetFromOrigin()); | 628 status_bounds.Offset(target_bounds.shelf_bounds_in_root.OffsetFromOrigin()); |
630 ::wm::ConvertRectToScreen(status_widget->GetNativeWindow()->parent(), | 629 ::wm::ConvertRectToScreen(status_widget->GetNativeWindow()->parent(), |
631 &status_bounds); | 630 &status_bounds); |
632 status_widget->SetBounds(status_bounds); | 631 status_widget->SetBounds(status_bounds); |
633 | 632 |
634 // For crbug.com/622431, when the shelf alignment is BOTTOM_LOCKED, we | 633 // For crbug.com/622431, when the shelf alignment is BOTTOM_LOCKED, we |
635 // don't set display work area, as it is not real user-set alignment. | 634 // don't set display work area, as it is not real user-set alignment. |
636 if (!state_.IsScreenLocked() && | 635 if (!state_.IsScreenLocked() && |
637 wm_shelf_->GetAlignment() != SHELF_ALIGNMENT_BOTTOM_LOCKED && | 636 shelf_->alignment() != SHELF_ALIGNMENT_BOTTOM_LOCKED && |
638 change_work_area) { | 637 change_work_area) { |
639 gfx::Insets insets; | 638 gfx::Insets insets; |
640 // If user session is blocked (login to new user session or add user to | 639 // If user session is blocked (login to new user session or add user to |
641 // the existing session - multi-profile) then give 100% of work area only | 640 // the existing session - multi-profile) then give 100% of work area only |
642 // if keyboard is not shown. | 641 // if keyboard is not shown. |
643 if (!state_.IsAddingSecondaryUser() || !keyboard_bounds_.IsEmpty()) | 642 if (!state_.IsAddingSecondaryUser() || !keyboard_bounds_.IsEmpty()) |
644 insets = target_bounds.work_area_insets; | 643 insets = target_bounds.work_area_insets; |
645 WmWindow* shelf_window = WmWindow::Get(shelf_widget_->GetNativeWindow()); | 644 WmWindow* shelf_window = WmWindow::Get(shelf_widget_->GetNativeWindow()); |
646 ShellPort::Get()->SetDisplayWorkAreaInsets(shelf_window, insets); | 645 ShellPort::Get()->SetDisplayWorkAreaInsets(shelf_window, insets); |
647 } | 646 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 | 693 |
695 gfx::Point shelf_origin = SelectValueForShelfAlignment( | 694 gfx::Point shelf_origin = SelectValueForShelfAlignment( |
696 gfx::Point(available_bounds.x(), bottom_shelf_vertical_offset), | 695 gfx::Point(available_bounds.x(), bottom_shelf_vertical_offset), |
697 gfx::Point(available_bounds.x(), available_bounds.y()), | 696 gfx::Point(available_bounds.x(), available_bounds.y()), |
698 gfx::Point(available_bounds.right() - shelf_width, available_bounds.y())); | 697 gfx::Point(available_bounds.right() - shelf_width, available_bounds.y())); |
699 target_bounds->shelf_bounds_in_root = | 698 target_bounds->shelf_bounds_in_root = |
700 gfx::Rect(shelf_origin.x(), shelf_origin.y(), shelf_width, shelf_height); | 699 gfx::Rect(shelf_origin.x(), shelf_origin.y(), shelf_width, shelf_height); |
701 | 700 |
702 gfx::Size status_size( | 701 gfx::Size status_size( |
703 shelf_widget_->status_area_widget()->GetWindowBoundsInScreen().size()); | 702 shelf_widget_->status_area_widget()->GetWindowBoundsInScreen().size()); |
704 if (wm_shelf_->IsHorizontalAlignment()) | 703 if (shelf_->IsHorizontalAlignment()) |
705 status_size.set_height(kShelfSize); | 704 status_size.set_height(kShelfSize); |
706 else | 705 else |
707 status_size.set_width(kShelfSize); | 706 status_size.set_width(kShelfSize); |
708 | 707 |
709 gfx::Point status_origin = SelectValueForShelfAlignment( | 708 gfx::Point status_origin = SelectValueForShelfAlignment( |
710 gfx::Point(0, 0), gfx::Point(shelf_width - status_size.width(), | 709 gfx::Point(0, 0), gfx::Point(shelf_width - status_size.width(), |
711 shelf_height - status_size.height()), | 710 shelf_height - status_size.height()), |
712 gfx::Point(0, shelf_height - status_size.height())); | 711 gfx::Point(0, shelf_height - status_size.height())); |
713 if (wm_shelf_->IsHorizontalAlignment() && !base::i18n::IsRTL()) | 712 if (shelf_->IsHorizontalAlignment() && !base::i18n::IsRTL()) |
714 status_origin.set_x(shelf_width - status_size.width()); | 713 status_origin.set_x(shelf_width - status_size.width()); |
715 target_bounds->status_bounds_in_shelf = gfx::Rect(status_origin, status_size); | 714 target_bounds->status_bounds_in_shelf = gfx::Rect(status_origin, status_size); |
716 | 715 |
717 target_bounds->work_area_insets = SelectValueForShelfAlignment( | 716 target_bounds->work_area_insets = SelectValueForShelfAlignment( |
718 gfx::Insets(0, 0, GetWorkAreaInsets(state, shelf_height), 0), | 717 gfx::Insets(0, 0, GetWorkAreaInsets(state, shelf_height), 0), |
719 gfx::Insets(0, GetWorkAreaInsets(state, shelf_width), 0, 0), | 718 gfx::Insets(0, GetWorkAreaInsets(state, shelf_width), 0, 0), |
720 gfx::Insets(0, 0, 0, GetWorkAreaInsets(state, shelf_width))); | 719 gfx::Insets(0, 0, 0, GetWorkAreaInsets(state, shelf_width))); |
721 | 720 |
722 // TODO(varkha): The functionality of managing insets for display areas | 721 // TODO(varkha): The functionality of managing insets for display areas |
723 // should probably be pushed to a separate component. This would simplify or | 722 // should probably be pushed to a separate component. This would simplify or |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 available_bounds.Subtract(keyboard_bounds_); | 759 available_bounds.Subtract(keyboard_bounds_); |
761 | 760 |
762 aura::Window* root = shelf_window->GetRootWindow(); | 761 aura::Window* root = shelf_window->GetRootWindow(); |
763 ::wm::ConvertRectToScreen(root, &available_bounds); | 762 ::wm::ConvertRectToScreen(root, &available_bounds); |
764 user_work_area_bounds_ = available_bounds; | 763 user_work_area_bounds_ = available_bounds; |
765 } | 764 } |
766 | 765 |
767 void ShelfLayoutManager::UpdateTargetBoundsForGesture( | 766 void ShelfLayoutManager::UpdateTargetBoundsForGesture( |
768 TargetBounds* target_bounds) const { | 767 TargetBounds* target_bounds) const { |
769 CHECK_EQ(GESTURE_DRAG_IN_PROGRESS, gesture_drag_status_); | 768 CHECK_EQ(GESTURE_DRAG_IN_PROGRESS, gesture_drag_status_); |
770 bool horizontal = wm_shelf_->IsHorizontalAlignment(); | 769 bool horizontal = shelf_->IsHorizontalAlignment(); |
771 aura::Window* window = shelf_widget_->GetNativeWindow(); | 770 aura::Window* window = shelf_widget_->GetNativeWindow(); |
772 gfx::Rect available_bounds = ScreenUtil::GetDisplayBoundsWithShelf(window); | 771 gfx::Rect available_bounds = ScreenUtil::GetDisplayBoundsWithShelf(window); |
773 int resistance_free_region = 0; | 772 int resistance_free_region = 0; |
774 | 773 |
775 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && | 774 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && |
776 visibility_state() == SHELF_AUTO_HIDE && | 775 visibility_state() == SHELF_AUTO_HIDE && |
777 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) { | 776 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) { |
778 // If the shelf was hidden when the drag started (and the state hasn't | 777 // If the shelf was hidden when the drag started (and the state hasn't |
779 // changed since then, e.g. because the tray-menu was shown because of the | 778 // changed since then, e.g. because the tray-menu was shown because of the |
780 // drag), then allow the drag some resistance-free region at first to make | 779 // drag), then allow the drag some resistance-free region at first to make |
(...skipping 15 matching lines...) Expand all Loading... |
796 else | 795 else |
797 translate = resistance_free_region + diff; | 796 translate = resistance_free_region + diff; |
798 } else { | 797 } else { |
799 translate = gesture_drag_amount_; | 798 translate = gesture_drag_amount_; |
800 } | 799 } |
801 if (horizontal) { | 800 if (horizontal) { |
802 // Move and size the shelf with the gesture. | 801 // Move and size the shelf with the gesture. |
803 int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate; | 802 int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate; |
804 shelf_height = std::max(shelf_height, 0); | 803 shelf_height = std::max(shelf_height, 0); |
805 target_bounds->shelf_bounds_in_root.set_height(shelf_height); | 804 target_bounds->shelf_bounds_in_root.set_height(shelf_height); |
806 if (wm_shelf_->IsHorizontalAlignment()) { | 805 if (shelf_->IsHorizontalAlignment()) { |
807 target_bounds->shelf_bounds_in_root.set_y(available_bounds.bottom() - | 806 target_bounds->shelf_bounds_in_root.set_y(available_bounds.bottom() - |
808 shelf_height); | 807 shelf_height); |
809 } | 808 } |
810 | 809 |
811 target_bounds->status_bounds_in_shelf.set_y(0); | 810 target_bounds->status_bounds_in_shelf.set_y(0); |
812 } else { | 811 } else { |
813 // Move and size the shelf with the gesture. | 812 // Move and size the shelf with the gesture. |
814 int shelf_width = target_bounds->shelf_bounds_in_root.width(); | 813 int shelf_width = target_bounds->shelf_bounds_in_root.width(); |
815 bool right_aligned = wm_shelf_->GetAlignment() == SHELF_ALIGNMENT_RIGHT; | 814 bool right_aligned = shelf_->alignment() == SHELF_ALIGNMENT_RIGHT; |
816 if (right_aligned) | 815 if (right_aligned) |
817 shelf_width -= translate; | 816 shelf_width -= translate; |
818 else | 817 else |
819 shelf_width += translate; | 818 shelf_width += translate; |
820 shelf_width = std::max(shelf_width, 0); | 819 shelf_width = std::max(shelf_width, 0); |
821 target_bounds->shelf_bounds_in_root.set_width(shelf_width); | 820 target_bounds->shelf_bounds_in_root.set_width(shelf_width); |
822 if (right_aligned) { | 821 if (right_aligned) { |
823 target_bounds->shelf_bounds_in_root.set_x(available_bounds.right() - | 822 target_bounds->shelf_bounds_in_root.set_x(available_bounds.right() - |
824 shelf_width); | 823 shelf_width); |
825 } | 824 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 | 857 |
859 gfx::Rect ShelfLayoutManager::GetAutoHideShowShelfRegionInScreen() const { | 858 gfx::Rect ShelfLayoutManager::GetAutoHideShowShelfRegionInScreen() const { |
860 gfx::Rect shelf_bounds_in_screen = shelf_widget_->GetWindowBoundsInScreen(); | 859 gfx::Rect shelf_bounds_in_screen = shelf_widget_->GetWindowBoundsInScreen(); |
861 gfx::Vector2d offset = SelectValueForShelfAlignment( | 860 gfx::Vector2d offset = SelectValueForShelfAlignment( |
862 gfx::Vector2d(0, shelf_bounds_in_screen.height()), | 861 gfx::Vector2d(0, shelf_bounds_in_screen.height()), |
863 gfx::Vector2d(-kMaxAutoHideShowShelfRegionSize, 0), | 862 gfx::Vector2d(-kMaxAutoHideShowShelfRegionSize, 0), |
864 gfx::Vector2d(shelf_bounds_in_screen.width(), 0)); | 863 gfx::Vector2d(shelf_bounds_in_screen.width(), 0)); |
865 | 864 |
866 gfx::Rect show_shelf_region_in_screen = shelf_bounds_in_screen; | 865 gfx::Rect show_shelf_region_in_screen = shelf_bounds_in_screen; |
867 show_shelf_region_in_screen += offset; | 866 show_shelf_region_in_screen += offset; |
868 if (wm_shelf_->IsHorizontalAlignment()) | 867 if (shelf_->IsHorizontalAlignment()) |
869 show_shelf_region_in_screen.set_height(kMaxAutoHideShowShelfRegionSize); | 868 show_shelf_region_in_screen.set_height(kMaxAutoHideShowShelfRegionSize); |
870 else | 869 else |
871 show_shelf_region_in_screen.set_width(kMaxAutoHideShowShelfRegionSize); | 870 show_shelf_region_in_screen.set_width(kMaxAutoHideShowShelfRegionSize); |
872 | 871 |
873 // TODO: Figure out if we need any special handling when the keyboard is | 872 // TODO: Figure out if we need any special handling when the keyboard is |
874 // visible. | 873 // visible. |
875 return show_shelf_region_in_screen; | 874 return show_shelf_region_in_screen; |
876 } | 875 } |
877 | 876 |
878 bool ShelfLayoutManager::HasVisibleWindow() const { | 877 bool ShelfLayoutManager::HasVisibleWindow() const { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
933 // Ignore the mouse position if mouse events are disabled. | 932 // Ignore the mouse position if mouse events are disabled. |
934 if (!shelf_widget_->IsMouseEventsEnabled()) | 933 if (!shelf_widget_->IsMouseEventsEnabled()) |
935 return SHELF_AUTO_HIDE_HIDDEN; | 934 return SHELF_AUTO_HIDE_HIDDEN; |
936 | 935 |
937 gfx::Rect shelf_region = shelf_widget_->GetWindowBoundsInScreen(); | 936 gfx::Rect shelf_region = shelf_widget_->GetWindowBoundsInScreen(); |
938 if (shelf_widget_->status_area_widget() && | 937 if (shelf_widget_->status_area_widget() && |
939 shelf_widget_->status_area_widget()->IsMessageBubbleShown() && | 938 shelf_widget_->status_area_widget()->IsMessageBubbleShown() && |
940 IsVisible()) { | 939 IsVisible()) { |
941 // Increase the the hit test area to prevent the shelf from disappearing | 940 // Increase the the hit test area to prevent the shelf from disappearing |
942 // when the mouse is over the bubble gap. | 941 // when the mouse is over the bubble gap. |
943 ShelfAlignment alignment = wm_shelf_->GetAlignment(); | 942 ShelfAlignment alignment = shelf_->alignment(); |
944 shelf_region.Inset( | 943 shelf_region.Inset( |
945 alignment == SHELF_ALIGNMENT_RIGHT ? -kNotificationBubbleGapHeight : 0, | 944 alignment == SHELF_ALIGNMENT_RIGHT ? -kNotificationBubbleGapHeight : 0, |
946 wm_shelf_->IsHorizontalAlignment() ? -kNotificationBubbleGapHeight : 0, | 945 shelf_->IsHorizontalAlignment() ? -kNotificationBubbleGapHeight : 0, |
947 alignment == SHELF_ALIGNMENT_LEFT ? -kNotificationBubbleGapHeight : 0, | 946 alignment == SHELF_ALIGNMENT_LEFT ? -kNotificationBubbleGapHeight : 0, |
948 0); | 947 0); |
949 } | 948 } |
950 | 949 |
951 gfx::Point cursor_position_in_screen = | 950 gfx::Point cursor_position_in_screen = |
952 display::Screen::GetScreen()->GetCursorScreenPoint(); | 951 display::Screen::GetScreen()->GetCursorScreenPoint(); |
953 if (shelf_region.Contains(cursor_position_in_screen)) | 952 if (shelf_region.Contains(cursor_position_in_screen)) |
954 return SHELF_AUTO_HIDE_SHOWN; | 953 return SHELF_AUTO_HIDE_SHOWN; |
955 | 954 |
956 // When the shelf is auto hidden and the shelf is on the boundary between two | 955 // When the shelf is auto hidden and the shelf is on the boundary between two |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1076 MaybeUpdateShelfBackground(AnimationChangeType::ANIMATE); | 1075 MaybeUpdateShelfBackground(AnimationChangeType::ANIMATE); |
1077 } | 1076 } |
1078 | 1077 |
1079 void ShelfLayoutManager::UpdateGestureDrag(const ui::GestureEvent& gesture) { | 1078 void ShelfLayoutManager::UpdateGestureDrag(const ui::GestureEvent& gesture) { |
1080 gesture_drag_amount_ += PrimaryAxisValue(gesture.details().scroll_y(), | 1079 gesture_drag_amount_ += PrimaryAxisValue(gesture.details().scroll_y(), |
1081 gesture.details().scroll_x()); | 1080 gesture.details().scroll_x()); |
1082 LayoutShelf(); | 1081 LayoutShelf(); |
1083 } | 1082 } |
1084 | 1083 |
1085 void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) { | 1084 void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) { |
1086 bool horizontal = wm_shelf_->IsHorizontalAlignment(); | 1085 bool horizontal = shelf_->IsHorizontalAlignment(); |
1087 bool should_change = false; | 1086 bool should_change = false; |
1088 if (gesture.type() == ui::ET_GESTURE_SCROLL_END) { | 1087 if (gesture.type() == ui::ET_GESTURE_SCROLL_END) { |
1089 // The visibility of the shelf changes only if the shelf was dragged X% | 1088 // The visibility of the shelf changes only if the shelf was dragged X% |
1090 // along the correct axis. If the shelf was already visible, then the | 1089 // along the correct axis. If the shelf was already visible, then the |
1091 // direction of the drag does not matter. | 1090 // direction of the drag does not matter. |
1092 const float kDragHideThreshold = 0.4f; | 1091 const float kDragHideThreshold = 0.4f; |
1093 gfx::Rect bounds = GetIdealBounds(); | 1092 gfx::Rect bounds = GetIdealBounds(); |
1094 float drag_ratio = fabs(gesture_drag_amount_) / | 1093 float drag_ratio = fabs(gesture_drag_amount_) / |
1095 (horizontal ? bounds.height() : bounds.width()); | 1094 (horizontal ? bounds.height() : bounds.width()); |
1096 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN) { | 1095 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN) { |
1097 should_change = drag_ratio > kDragHideThreshold; | 1096 should_change = drag_ratio > kDragHideThreshold; |
1098 } else { | 1097 } else { |
1099 bool correct_direction = false; | 1098 bool correct_direction = false; |
1100 switch (wm_shelf_->GetAlignment()) { | 1099 switch (shelf_->alignment()) { |
1101 case SHELF_ALIGNMENT_BOTTOM: | 1100 case SHELF_ALIGNMENT_BOTTOM: |
1102 case SHELF_ALIGNMENT_BOTTOM_LOCKED: | 1101 case SHELF_ALIGNMENT_BOTTOM_LOCKED: |
1103 case SHELF_ALIGNMENT_RIGHT: | 1102 case SHELF_ALIGNMENT_RIGHT: |
1104 correct_direction = gesture_drag_amount_ < 0; | 1103 correct_direction = gesture_drag_amount_ < 0; |
1105 break; | 1104 break; |
1106 case SHELF_ALIGNMENT_LEFT: | 1105 case SHELF_ALIGNMENT_LEFT: |
1107 correct_direction = gesture_drag_amount_ > 0; | 1106 correct_direction = gesture_drag_amount_ > 0; |
1108 break; | 1107 break; |
1109 } | 1108 } |
1110 should_change = correct_direction && drag_ratio > kDragHideThreshold; | 1109 should_change = correct_direction && drag_ratio > kDragHideThreshold; |
(...skipping 28 matching lines...) Expand all Loading... |
1139 gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN | 1138 gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN |
1140 ? SHELF_AUTO_HIDE_BEHAVIOR_NEVER | 1139 ? SHELF_AUTO_HIDE_BEHAVIOR_NEVER |
1141 : SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; | 1140 : SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; |
1142 | 1141 |
1143 // When in fullscreen and the shelf is forced to be auto hidden, the auto hide | 1142 // When in fullscreen and the shelf is forced to be auto hidden, the auto hide |
1144 // behavior affects neither the visibility state nor the auto hide state. Set | 1143 // behavior affects neither the visibility state nor the auto hide state. Set |
1145 // |gesture_drag_status_| to GESTURE_DRAG_COMPLETE_IN_PROGRESS to set the auto | 1144 // |gesture_drag_status_| to GESTURE_DRAG_COMPLETE_IN_PROGRESS to set the auto |
1146 // hide state to |gesture_drag_auto_hide_state_|. Only change the auto-hide | 1145 // hide state to |gesture_drag_auto_hide_state_|. Only change the auto-hide |
1147 // behavior if there is at least one window visible. | 1146 // behavior if there is at least one window visible. |
1148 gesture_drag_status_ = GESTURE_DRAG_COMPLETE_IN_PROGRESS; | 1147 gesture_drag_status_ = GESTURE_DRAG_COMPLETE_IN_PROGRESS; |
1149 if (wm_shelf_->auto_hide_behavior() != new_auto_hide_behavior && | 1148 if (shelf_->auto_hide_behavior() != new_auto_hide_behavior && |
1150 HasVisibleWindow()) { | 1149 HasVisibleWindow()) { |
1151 wm_shelf_->SetAutoHideBehavior(new_auto_hide_behavior); | 1150 shelf_->SetAutoHideBehavior(new_auto_hide_behavior); |
1152 } else { | 1151 } else { |
1153 UpdateVisibilityState(); | 1152 UpdateVisibilityState(); |
1154 } | 1153 } |
1155 gesture_drag_status_ = GESTURE_DRAG_NONE; | 1154 gesture_drag_status_ = GESTURE_DRAG_NONE; |
1156 } | 1155 } |
1157 | 1156 |
1158 void ShelfLayoutManager::CancelGestureDrag() { | 1157 void ShelfLayoutManager::CancelGestureDrag() { |
1159 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS; | 1158 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS; |
1160 UpdateVisibilityState(); | 1159 UpdateVisibilityState(); |
1161 gesture_drag_status_ = GESTURE_DRAG_NONE; | 1160 gesture_drag_status_ = GESTURE_DRAG_NONE; |
1162 } | 1161 } |
1163 | 1162 |
1164 } // namespace ash | 1163 } // namespace ash |
OLD | NEW |