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

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

Issue 2899253002: chromeos: Rename ash::WmShelf to Shelf (Closed)
Patch Set: cleanup Created 3 years, 7 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/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
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
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
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) {
msw 2017/05/24 18:42:58 optional nit: reorder this to be the second condit
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 }
648 } 647 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
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
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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 // Ignore the mouse position if mouse events are disabled. 933 // Ignore the mouse position if mouse events are disabled.
935 if (!shelf_widget_->IsMouseEventsEnabled()) 934 if (!shelf_widget_->IsMouseEventsEnabled())
936 return SHELF_AUTO_HIDE_HIDDEN; 935 return SHELF_AUTO_HIDE_HIDDEN;
937 936
938 gfx::Rect shelf_region = shelf_widget_->GetWindowBoundsInScreen(); 937 gfx::Rect shelf_region = shelf_widget_->GetWindowBoundsInScreen();
939 if (shelf_widget_->status_area_widget() && 938 if (shelf_widget_->status_area_widget() &&
940 shelf_widget_->status_area_widget()->IsMessageBubbleShown() && 939 shelf_widget_->status_area_widget()->IsMessageBubbleShown() &&
941 IsVisible()) { 940 IsVisible()) {
942 // Increase the the hit test area to prevent the shelf from disappearing 941 // Increase the the hit test area to prevent the shelf from disappearing
943 // when the mouse is over the bubble gap. 942 // when the mouse is over the bubble gap.
944 ShelfAlignment alignment = wm_shelf_->GetAlignment(); 943 ShelfAlignment alignment = shelf_->alignment();
945 shelf_region.Inset( 944 shelf_region.Inset(
946 alignment == SHELF_ALIGNMENT_RIGHT ? -kNotificationBubbleGapHeight : 0, 945 alignment == SHELF_ALIGNMENT_RIGHT ? -kNotificationBubbleGapHeight : 0,
947 wm_shelf_->IsHorizontalAlignment() ? -kNotificationBubbleGapHeight : 0, 946 shelf_->IsHorizontalAlignment() ? -kNotificationBubbleGapHeight : 0,
948 alignment == SHELF_ALIGNMENT_LEFT ? -kNotificationBubbleGapHeight : 0, 947 alignment == SHELF_ALIGNMENT_LEFT ? -kNotificationBubbleGapHeight : 0,
949 0); 948 0);
950 } 949 }
951 950
952 gfx::Point cursor_position_in_screen = 951 gfx::Point cursor_position_in_screen =
953 display::Screen::GetScreen()->GetCursorScreenPoint(); 952 display::Screen::GetScreen()->GetCursorScreenPoint();
954 if (shelf_region.Contains(cursor_position_in_screen)) 953 if (shelf_region.Contains(cursor_position_in_screen))
955 return SHELF_AUTO_HIDE_SHOWN; 954 return SHELF_AUTO_HIDE_SHOWN;
956 955
957 // When the shelf is auto hidden and the shelf is on the boundary between two 956 // 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
1077 MaybeUpdateShelfBackground(AnimationChangeType::ANIMATE); 1076 MaybeUpdateShelfBackground(AnimationChangeType::ANIMATE);
1078 } 1077 }
1079 1078
1080 void ShelfLayoutManager::UpdateGestureDrag(const ui::GestureEvent& gesture) { 1079 void ShelfLayoutManager::UpdateGestureDrag(const ui::GestureEvent& gesture) {
1081 gesture_drag_amount_ += PrimaryAxisValue(gesture.details().scroll_y(), 1080 gesture_drag_amount_ += PrimaryAxisValue(gesture.details().scroll_y(),
1082 gesture.details().scroll_x()); 1081 gesture.details().scroll_x());
1083 LayoutShelf(); 1082 LayoutShelf();
1084 } 1083 }
1085 1084
1086 void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) { 1085 void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) {
1087 bool horizontal = wm_shelf_->IsHorizontalAlignment(); 1086 bool horizontal = shelf_->IsHorizontalAlignment();
1088 bool should_change = false; 1087 bool should_change = false;
1089 if (gesture.type() == ui::ET_GESTURE_SCROLL_END) { 1088 if (gesture.type() == ui::ET_GESTURE_SCROLL_END) {
1090 // The visibility of the shelf changes only if the shelf was dragged X% 1089 // The visibility of the shelf changes only if the shelf was dragged X%
1091 // along the correct axis. If the shelf was already visible, then the 1090 // along the correct axis. If the shelf was already visible, then the
1092 // direction of the drag does not matter. 1091 // direction of the drag does not matter.
1093 const float kDragHideThreshold = 0.4f; 1092 const float kDragHideThreshold = 0.4f;
1094 gfx::Rect bounds = GetIdealBounds(); 1093 gfx::Rect bounds = GetIdealBounds();
1095 float drag_ratio = fabs(gesture_drag_amount_) / 1094 float drag_ratio = fabs(gesture_drag_amount_) /
1096 (horizontal ? bounds.height() : bounds.width()); 1095 (horizontal ? bounds.height() : bounds.width());
1097 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN) { 1096 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN) {
1098 should_change = drag_ratio > kDragHideThreshold; 1097 should_change = drag_ratio > kDragHideThreshold;
1099 } else { 1098 } else {
1100 bool correct_direction = false; 1099 bool correct_direction = false;
1101 switch (wm_shelf_->GetAlignment()) { 1100 switch (shelf_->alignment()) {
1102 case SHELF_ALIGNMENT_BOTTOM: 1101 case SHELF_ALIGNMENT_BOTTOM:
1103 case SHELF_ALIGNMENT_BOTTOM_LOCKED: 1102 case SHELF_ALIGNMENT_BOTTOM_LOCKED:
1104 case SHELF_ALIGNMENT_RIGHT: 1103 case SHELF_ALIGNMENT_RIGHT:
1105 correct_direction = gesture_drag_amount_ < 0; 1104 correct_direction = gesture_drag_amount_ < 0;
1106 break; 1105 break;
1107 case SHELF_ALIGNMENT_LEFT: 1106 case SHELF_ALIGNMENT_LEFT:
1108 correct_direction = gesture_drag_amount_ > 0; 1107 correct_direction = gesture_drag_amount_ > 0;
1109 break; 1108 break;
1110 } 1109 }
1111 should_change = correct_direction && drag_ratio > kDragHideThreshold; 1110 should_change = correct_direction && drag_ratio > kDragHideThreshold;
(...skipping 28 matching lines...) Expand all
1140 gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN 1139 gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN
1141 ? SHELF_AUTO_HIDE_BEHAVIOR_NEVER 1140 ? SHELF_AUTO_HIDE_BEHAVIOR_NEVER
1142 : SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS; 1141 : SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS;
1143 1142
1144 // When in fullscreen and the shelf is forced to be auto hidden, the auto hide 1143 // When in fullscreen and the shelf is forced to be auto hidden, the auto hide
1145 // behavior affects neither the visibility state nor the auto hide state. Set 1144 // behavior affects neither the visibility state nor the auto hide state. Set
1146 // |gesture_drag_status_| to GESTURE_DRAG_COMPLETE_IN_PROGRESS to set the auto 1145 // |gesture_drag_status_| to GESTURE_DRAG_COMPLETE_IN_PROGRESS to set the auto
1147 // hide state to |gesture_drag_auto_hide_state_|. Only change the auto-hide 1146 // hide state to |gesture_drag_auto_hide_state_|. Only change the auto-hide
1148 // behavior if there is at least one window visible. 1147 // behavior if there is at least one window visible.
1149 gesture_drag_status_ = GESTURE_DRAG_COMPLETE_IN_PROGRESS; 1148 gesture_drag_status_ = GESTURE_DRAG_COMPLETE_IN_PROGRESS;
1150 if (wm_shelf_->auto_hide_behavior() != new_auto_hide_behavior && 1149 if (shelf_->auto_hide_behavior() != new_auto_hide_behavior &&
1151 HasVisibleWindow()) { 1150 HasVisibleWindow()) {
1152 wm_shelf_->SetAutoHideBehavior(new_auto_hide_behavior); 1151 shelf_->SetAutoHideBehavior(new_auto_hide_behavior);
1153 } else { 1152 } else {
1154 UpdateVisibilityState(); 1153 UpdateVisibilityState();
1155 } 1154 }
1156 gesture_drag_status_ = GESTURE_DRAG_NONE; 1155 gesture_drag_status_ = GESTURE_DRAG_NONE;
1157 } 1156 }
1158 1157
1159 void ShelfLayoutManager::CancelGestureDrag() { 1158 void ShelfLayoutManager::CancelGestureDrag() {
1160 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS; 1159 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS;
1161 UpdateVisibilityState(); 1160 UpdateVisibilityState();
1162 gesture_drag_status_ = GESTURE_DRAG_NONE; 1161 gesture_drag_status_ = GESTURE_DRAG_NONE;
1163 } 1162 }
1164 1163
1165 } // namespace ash 1164 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698