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

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

Issue 1877543002: Revise the shelf alignment locking mechanism. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update and cleanup tests. Created 4 years, 8 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
« no previous file with comments | « ash/shelf/shelf_layout_manager.h ('k') | ash/shelf/shelf_layout_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <cstring> 9 #include <cstring>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "ash/accelerators/accelerator_commands.h" 13 #include "ash/accelerators/accelerator_commands.h"
14 #include "ash/ash_switches.h" 14 #include "ash/ash_switches.h"
15 #include "ash/root_window_controller.h" 15 #include "ash/root_window_controller.h"
16 #include "ash/screen_util.h" 16 #include "ash/screen_util.h"
17 #include "ash/session/session_state_delegate.h" 17 #include "ash/session/session_state_delegate.h"
18 #include "ash/shelf/shelf.h" 18 #include "ash/shelf/shelf.h"
19 #include "ash/shelf/shelf_bezel_event_filter.h" 19 #include "ash/shelf/shelf_bezel_event_filter.h"
20 #include "ash/shelf/shelf_constants.h" 20 #include "ash/shelf/shelf_constants.h"
21 #include "ash/shelf/shelf_layout_manager_observer.h" 21 #include "ash/shelf/shelf_layout_manager_observer.h"
22 #include "ash/shelf/shelf_util.h"
22 #include "ash/shelf/shelf_widget.h" 23 #include "ash/shelf/shelf_widget.h"
23 #include "ash/shell.h" 24 #include "ash/shell.h"
24 #include "ash/shell_window_ids.h" 25 #include "ash/shell_window_ids.h"
25 #include "ash/system/status_area_widget.h" 26 #include "ash/system/status_area_widget.h"
26 #include "ash/wm/gestures/shelf_gesture_handler.h" 27 #include "ash/wm/gestures/shelf_gesture_handler.h"
27 #include "ash/wm/lock_state_controller.h" 28 #include "ash/wm/lock_state_controller.h"
28 #include "ash/wm/mru_window_tracker.h" 29 #include "ash/wm/mru_window_tracker.h"
29 #include "ash/wm/window_animations.h" 30 #include "ash/wm/window_animations.h"
30 #include "ash/wm/window_state.h" 31 #include "ash/wm/window_state.h"
31 #include "ash/wm/window_state_aura.h" 32 #include "ash/wm/window_state_aura.h"
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 const float kDragHideThreshold = 0.4f; 381 const float kDragHideThreshold = 0.4f;
381 gfx::Rect bounds = GetIdealBounds(); 382 gfx::Rect bounds = GetIdealBounds();
382 float drag_ratio = fabs(gesture_drag_amount_) / 383 float drag_ratio = fabs(gesture_drag_amount_) /
383 (horizontal ? bounds.height() : bounds.width()); 384 (horizontal ? bounds.height() : bounds.width());
384 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN) { 385 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_SHOWN) {
385 should_change = drag_ratio > kDragHideThreshold; 386 should_change = drag_ratio > kDragHideThreshold;
386 } else { 387 } else {
387 bool correct_direction = false; 388 bool correct_direction = false;
388 switch (GetAlignment()) { 389 switch (GetAlignment()) {
389 case SHELF_ALIGNMENT_BOTTOM: 390 case SHELF_ALIGNMENT_BOTTOM:
391 case SHELF_ALIGNMENT_BOTTOM_LOCKED:
390 case SHELF_ALIGNMENT_RIGHT: 392 case SHELF_ALIGNMENT_RIGHT:
391 correct_direction = gesture_drag_amount_ < 0; 393 correct_direction = gesture_drag_amount_ < 0;
392 break; 394 break;
393 case SHELF_ALIGNMENT_LEFT: 395 case SHELF_ALIGNMENT_LEFT:
394 correct_direction = gesture_drag_amount_ > 0; 396 correct_direction = gesture_drag_amount_ > 0;
395 break; 397 break;
396 } 398 }
397 should_change = correct_direction && drag_ratio > kDragHideThreshold; 399 should_change = correct_direction && drag_ratio > kDragHideThreshold;
398 } 400 }
399 } else if (gesture.type() == ui::ET_SCROLL_FLING_START) { 401 } else if (gesture.type() == ui::ET_SCROLL_FLING_START) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 } 486 }
485 487
486 void ShelfLayoutManager::OnWindowActivated( 488 void ShelfLayoutManager::OnWindowActivated(
487 aura::client::ActivationChangeObserver::ActivationReason reason, 489 aura::client::ActivationChangeObserver::ActivationReason reason,
488 aura::Window* gained_active, 490 aura::Window* gained_active,
489 aura::Window* lost_active) { 491 aura::Window* lost_active) {
490 UpdateAutoHideStateNow(); 492 UpdateAutoHideStateNow();
491 } 493 }
492 494
493 bool ShelfLayoutManager::IsHorizontalAlignment() const { 495 bool ShelfLayoutManager::IsHorizontalAlignment() const {
494 return GetAlignment() == SHELF_ALIGNMENT_BOTTOM; 496 return ash::IsHorizontalAlignment(GetAlignment());
495 }
496
497 bool ShelfLayoutManager::IsAlignmentLocked() const {
498 if (state_.is_screen_locked)
499 return true;
500 // The session state becomes active at the start of transitioning to a user
501 // session, however the session is considered blocked until the full UI is
502 // ready. Exit early to allow for proper layout.
503 SessionStateDelegate* session_state_delegate =
504 Shell::GetInstance()->session_state_delegate();
505 if (session_state_delegate->GetSessionState() ==
506 SessionStateDelegate::SESSION_STATE_ACTIVE) {
507 return false;
508 }
509 if (session_state_delegate->IsUserSessionBlocked() ||
510 state_.is_adding_user_screen) {
511 return true;
512 }
513 return false;
514 } 497 }
515 498
516 void ShelfLayoutManager::SetChromeVoxPanelHeight(int height) { 499 void ShelfLayoutManager::SetChromeVoxPanelHeight(int height) {
517 chromevox_panel_height_ = height; 500 chromevox_panel_height_ = height;
518 LayoutShelf(); 501 LayoutShelf();
519 } 502 }
520 503
521 //////////////////////////////////////////////////////////////////////////////// 504 ////////////////////////////////////////////////////////////////////////////////
522 // ShelfLayoutManager, private: 505 // ShelfLayoutManager, private:
523 506
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 translate = resistance_free_region + diff; 828 translate = resistance_free_region + diff;
846 } else { 829 } else {
847 translate = gesture_drag_amount_; 830 translate = gesture_drag_amount_;
848 } 831 }
849 832
850 if (horizontal) { 833 if (horizontal) {
851 // Move and size the shelf with the gesture. 834 // Move and size the shelf with the gesture.
852 int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate; 835 int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate;
853 shelf_height = std::max(shelf_height, kAutoHideSize); 836 shelf_height = std::max(shelf_height, kAutoHideSize);
854 target_bounds->shelf_bounds_in_root.set_height(shelf_height); 837 target_bounds->shelf_bounds_in_root.set_height(shelf_height);
855 if (GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { 838 if (IsHorizontalAlignment()) {
856 target_bounds->shelf_bounds_in_root.set_y( 839 target_bounds->shelf_bounds_in_root.set_y(
857 available_bounds.bottom() - shelf_height); 840 available_bounds.bottom() - shelf_height);
858 } 841 }
859 842
860 target_bounds->status_bounds_in_shelf.set_y(0); 843 target_bounds->status_bounds_in_shelf.set_y(0);
861 } else { 844 } else {
862 // Move and size the shelf with the gesture. 845 // Move and size the shelf with the gesture.
863 int shelf_width = target_bounds->shelf_bounds_in_root.width(); 846 int shelf_width = target_bounds->shelf_bounds_in_root.width();
864 bool right_aligned = GetAlignment() == SHELF_ALIGNMENT_RIGHT; 847 bool right_aligned = GetAlignment() == SHELF_ALIGNMENT_RIGHT;
865 if (right_aligned) 848 if (right_aligned)
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 984
1002 gfx::Rect shelf_region = shelf_->GetWindowBoundsInScreen(); 985 gfx::Rect shelf_region = shelf_->GetWindowBoundsInScreen();
1003 if (shelf_->status_area_widget() && 986 if (shelf_->status_area_widget() &&
1004 shelf_->status_area_widget()->IsMessageBubbleShown() && 987 shelf_->status_area_widget()->IsMessageBubbleShown() &&
1005 IsVisible()) { 988 IsVisible()) {
1006 // Increase the the hit test area to prevent the shelf from disappearing 989 // Increase the the hit test area to prevent the shelf from disappearing
1007 // when the mouse is over the bubble gap. 990 // when the mouse is over the bubble gap.
1008 ShelfAlignment alignment = GetAlignment(); 991 ShelfAlignment alignment = GetAlignment();
1009 shelf_region.Inset( 992 shelf_region.Inset(
1010 alignment == SHELF_ALIGNMENT_RIGHT ? -kNotificationBubbleGapHeight : 0, 993 alignment == SHELF_ALIGNMENT_RIGHT ? -kNotificationBubbleGapHeight : 0,
1011 alignment == SHELF_ALIGNMENT_BOTTOM ? -kNotificationBubbleGapHeight : 0, 994 IsHorizontalAlignment() ? -kNotificationBubbleGapHeight : 0,
1012 alignment == SHELF_ALIGNMENT_LEFT ? -kNotificationBubbleGapHeight : 0, 995 alignment == SHELF_ALIGNMENT_LEFT ? -kNotificationBubbleGapHeight : 0,
1013 0); 996 0);
1014 } 997 }
1015 998
1016 gfx::Point cursor_position_in_screen = 999 gfx::Point cursor_position_in_screen =
1017 gfx::Screen::GetScreen()->GetCursorScreenPoint(); 1000 gfx::Screen::GetScreen()->GetCursorScreenPoint();
1018 if (shelf_region.Contains(cursor_position_in_screen)) 1001 if (shelf_region.Contains(cursor_position_in_screen))
1019 return SHELF_AUTO_HIDE_SHOWN; 1002 return SHELF_AUTO_HIDE_SHOWN;
1020 1003
1021 // When the shelf is auto hidden and the shelf is on the boundary between two 1004 // When the shelf is auto hidden and the shelf is on the boundary between two
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 } 1094 }
1112 TargetBounds target_bounds; 1095 TargetBounds target_bounds;
1113 CalculateTargetBounds(state_, &target_bounds); 1096 CalculateTargetBounds(state_, &target_bounds);
1114 UpdateBoundsAndOpacity(target_bounds, true, NULL); 1097 UpdateBoundsAndOpacity(target_bounds, true, NULL);
1115 UpdateVisibilityState(); 1098 UpdateVisibilityState();
1116 } 1099 }
1117 1100
1118 void ShelfLayoutManager::UpdateShelfVisibilityAfterLoginUIChange() { 1101 void ShelfLayoutManager::UpdateShelfVisibilityAfterLoginUIChange() {
1119 UpdateVisibilityState(); 1102 UpdateVisibilityState();
1120 LayoutShelf(); 1103 LayoutShelf();
1121 // The shelf alignment may have changed when it was unlocked.
1122 Shell::GetInstance()->OnShelfAlignmentChanged(
1123 shelf_->GetNativeWindow()->GetRootWindow());
1124 } 1104 }
1125 1105
1126 } // namespace ash 1106 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_layout_manager.h ('k') | ash/shelf/shelf_layout_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698