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/session/session_controller.h" | 16 #include "ash/session/session_controller.h" |
16 #include "ash/shelf/shelf_constants.h" | 17 #include "ash/shelf/shelf_constants.h" |
17 #include "ash/shelf/shelf_layout_manager_observer.h" | 18 #include "ash/shelf/shelf_layout_manager_observer.h" |
18 #include "ash/shelf/shelf_widget.h" | 19 #include "ash/shelf/shelf_widget.h" |
19 #include "ash/shelf/wm_shelf.h" | 20 #include "ash/shelf/wm_shelf.h" |
20 #include "ash/shell.h" | 21 #include "ash/shell.h" |
21 #include "ash/shell_port.h" | 22 #include "ash/shell_port.h" |
22 #include "ash/system/status_area_widget.h" | 23 #include "ash/system/status_area_widget.h" |
23 #include "ash/wm/fullscreen_window_finder.h" | 24 #include "ash/wm/fullscreen_window_finder.h" |
24 #include "ash/wm/mru_window_tracker.h" | 25 #include "ash/wm/mru_window_tracker.h" |
25 #include "ash/wm/screen_pinning_controller.h" | 26 #include "ash/wm/screen_pinning_controller.h" |
26 #include "ash/wm/window_state.h" | 27 #include "ash/wm/window_state.h" |
27 #include "ash/wm/window_state_aura.h" | 28 #include "ash/wm/window_state_aura.h" |
28 #include "ash/wm/wm_screen_util.h" | |
29 #include "ash/wm_window.h" | 29 #include "ash/wm_window.h" |
30 #include "base/auto_reset.h" | 30 #include "base/auto_reset.h" |
31 #include "base/command_line.h" | 31 #include "base/command_line.h" |
32 #include "base/i18n/rtl.h" | 32 #include "base/i18n/rtl.h" |
33 #include "ui/base/ui_base_switches.h" | 33 #include "ui/base/ui_base_switches.h" |
34 #include "ui/compositor/layer.h" | 34 #include "ui/compositor/layer.h" |
35 #include "ui/compositor/layer_animation_observer.h" | 35 #include "ui/compositor/layer_animation_observer.h" |
36 #include "ui/compositor/layer_animator.h" | 36 #include "ui/compositor/layer_animator.h" |
37 #include "ui/compositor/scoped_layer_animation_settings.h" | 37 #include "ui/compositor/scoped_layer_animation_settings.h" |
38 #include "ui/display/display.h" | 38 #include "ui/display/display.h" |
39 #include "ui/display/screen.h" | 39 #include "ui/display/screen.h" |
40 #include "ui/events/event.h" | 40 #include "ui/events/event.h" |
41 #include "ui/events/event_handler.h" | 41 #include "ui/events/event_handler.h" |
42 #include "ui/keyboard/keyboard_controller.h" | 42 #include "ui/keyboard/keyboard_controller.h" |
43 #include "ui/keyboard/keyboard_util.h" | 43 #include "ui/keyboard/keyboard_util.h" |
44 #include "ui/views/border.h" | 44 #include "ui/views/border.h" |
45 #include "ui/views/widget/widget.h" | 45 #include "ui/views/widget/widget.h" |
| 46 #include "ui/wm/core/coordinate_conversion.h" |
46 #include "ui/wm/public/activation_client.h" | 47 #include "ui/wm/public/activation_client.h" |
47 | 48 |
48 namespace ash { | 49 namespace ash { |
49 namespace { | 50 namespace { |
50 | 51 |
51 // Delay before showing the shelf. This is after the mouse stops moving. | 52 // Delay before showing the shelf. This is after the mouse stops moving. |
52 const int kAutoHideDelayMS = 200; | 53 const int kAutoHideDelayMS = 200; |
53 | 54 |
54 // Duration of the animation to show or hide the shelf. | 55 // Duration of the animation to show or hide the shelf. |
55 const int kAnimationDurationMS = 200; | 56 const int kAnimationDurationMS = 200; |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 bool ShelfLayoutManager::IsVisible() const { | 185 bool ShelfLayoutManager::IsVisible() const { |
185 // status_area_widget() may be nullptr during the shutdown. | 186 // status_area_widget() may be nullptr during the shutdown. |
186 return shelf_widget_->status_area_widget() && | 187 return shelf_widget_->status_area_widget() && |
187 shelf_widget_->status_area_widget()->IsVisible() && | 188 shelf_widget_->status_area_widget()->IsVisible() && |
188 (state_.visibility_state == SHELF_VISIBLE || | 189 (state_.visibility_state == SHELF_VISIBLE || |
189 (state_.visibility_state == SHELF_AUTO_HIDE && | 190 (state_.visibility_state == SHELF_AUTO_HIDE && |
190 state_.auto_hide_state == SHELF_AUTO_HIDE_SHOWN)); | 191 state_.auto_hide_state == SHELF_AUTO_HIDE_SHOWN)); |
191 } | 192 } |
192 | 193 |
193 gfx::Rect ShelfLayoutManager::GetIdealBounds() { | 194 gfx::Rect ShelfLayoutManager::GetIdealBounds() { |
194 WmWindow* shelf_window = WmWindow::Get(shelf_widget_->GetNativeWindow()); | 195 aura::Window* shelf_window = shelf_widget_->GetNativeWindow(); |
195 gfx::Rect rect(wm::GetDisplayBoundsInParent(shelf_window)); | 196 gfx::Rect rect(ScreenUtil::GetDisplayBoundsInParent(shelf_window)); |
196 return SelectValueForShelfAlignment( | 197 return SelectValueForShelfAlignment( |
197 gfx::Rect(rect.x(), rect.bottom() - kShelfSize, rect.width(), kShelfSize), | 198 gfx::Rect(rect.x(), rect.bottom() - kShelfSize, rect.width(), kShelfSize), |
198 gfx::Rect(rect.x(), rect.y(), kShelfSize, rect.height()), | 199 gfx::Rect(rect.x(), rect.y(), kShelfSize, rect.height()), |
199 gfx::Rect(rect.right() - kShelfSize, rect.y(), kShelfSize, | 200 gfx::Rect(rect.right() - kShelfSize, rect.y(), kShelfSize, |
200 rect.height())); | 201 rect.height())); |
201 } | 202 } |
202 | 203 |
203 gfx::Size ShelfLayoutManager::GetPreferredSize() { | 204 gfx::Size ShelfLayoutManager::GetPreferredSize() { |
204 TargetBounds target_bounds; | 205 TargetBounds target_bounds; |
205 CalculateTargetBounds(state_, &target_bounds); | 206 CalculateTargetBounds(state_, &target_bounds); |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 // Auto-hidden shelf always starts with the default size. If a gesture-drag | 665 // Auto-hidden shelf always starts with the default size. If a gesture-drag |
665 // is in progress, then the call to UpdateTargetBoundsForGesture() below | 666 // is in progress, then the call to UpdateTargetBoundsForGesture() below |
666 // takes care of setting the height properly. | 667 // takes care of setting the height properly. |
667 shelf_size = kShelfAutoHideSize; | 668 shelf_size = kShelfAutoHideSize; |
668 } else if (state.visibility_state == SHELF_HIDDEN || | 669 } else if (state.visibility_state == SHELF_HIDDEN || |
669 (!keyboard_bounds_.IsEmpty() && | 670 (!keyboard_bounds_.IsEmpty() && |
670 !keyboard::IsKeyboardOverscrollEnabled())) { | 671 !keyboard::IsKeyboardOverscrollEnabled())) { |
671 shelf_size = 0; | 672 shelf_size = 0; |
672 } | 673 } |
673 | 674 |
674 WmWindow* shelf_window = WmWindow::Get(shelf_widget_->GetNativeWindow()); | 675 aura::Window* shelf_window = shelf_widget_->GetNativeWindow(); |
675 gfx::Rect available_bounds = wm::GetDisplayBoundsWithShelf(shelf_window); | 676 gfx::Rect available_bounds = |
| 677 ScreenUtil::GetDisplayBoundsWithShelf(shelf_window); |
676 available_bounds.Inset(0, chromevox_panel_height_, 0, 0); | 678 available_bounds.Inset(0, chromevox_panel_height_, 0, 0); |
677 int shelf_width = PrimaryAxisValue(available_bounds.width(), shelf_size); | 679 int shelf_width = PrimaryAxisValue(available_bounds.width(), shelf_size); |
678 int shelf_height = PrimaryAxisValue(shelf_size, available_bounds.height()); | 680 int shelf_height = PrimaryAxisValue(shelf_size, available_bounds.height()); |
679 int bottom_shelf_vertical_offset = available_bounds.bottom(); | 681 int bottom_shelf_vertical_offset = available_bounds.bottom(); |
680 if (keyboard_bounds_.IsEmpty()) | 682 if (keyboard_bounds_.IsEmpty()) |
681 bottom_shelf_vertical_offset -= shelf_height; | 683 bottom_shelf_vertical_offset -= shelf_height; |
682 else | 684 else |
683 bottom_shelf_vertical_offset -= keyboard_bounds_.height(); | 685 bottom_shelf_vertical_offset -= keyboard_bounds_.height(); |
684 | 686 |
685 gfx::Point shelf_origin = SelectValueForShelfAlignment( | 687 gfx::Point shelf_origin = SelectValueForShelfAlignment( |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 gfx::Rect(0, 0, shelf_width - status_size.width(), | 744 gfx::Rect(0, 0, shelf_width - status_size.width(), |
743 target_bounds->shelf_bounds_in_root.height()), | 745 target_bounds->shelf_bounds_in_root.height()), |
744 gfx::Rect(0, 0, target_bounds->shelf_bounds_in_root.width(), | 746 gfx::Rect(0, 0, target_bounds->shelf_bounds_in_root.width(), |
745 shelf_height - status_size.height()), | 747 shelf_height - status_size.height()), |
746 gfx::Rect(0, 0, target_bounds->shelf_bounds_in_root.width(), | 748 gfx::Rect(0, 0, target_bounds->shelf_bounds_in_root.width(), |
747 shelf_height - status_size.height())); | 749 shelf_height - status_size.height())); |
748 | 750 |
749 available_bounds.Subtract(target_bounds->shelf_bounds_in_root); | 751 available_bounds.Subtract(target_bounds->shelf_bounds_in_root); |
750 available_bounds.Subtract(keyboard_bounds_); | 752 available_bounds.Subtract(keyboard_bounds_); |
751 | 753 |
752 WmWindow* root = shelf_window->GetRootWindow(); | 754 aura::Window* root = shelf_window->GetRootWindow(); |
753 user_work_area_bounds_ = root->ConvertRectToScreen(available_bounds); | 755 ::wm::ConvertRectToScreen(root, &available_bounds); |
| 756 user_work_area_bounds_ = available_bounds; |
754 } | 757 } |
755 | 758 |
756 void ShelfLayoutManager::UpdateTargetBoundsForGesture( | 759 void ShelfLayoutManager::UpdateTargetBoundsForGesture( |
757 TargetBounds* target_bounds) const { | 760 TargetBounds* target_bounds) const { |
758 CHECK_EQ(GESTURE_DRAG_IN_PROGRESS, gesture_drag_status_); | 761 CHECK_EQ(GESTURE_DRAG_IN_PROGRESS, gesture_drag_status_); |
759 bool horizontal = wm_shelf_->IsHorizontalAlignment(); | 762 bool horizontal = wm_shelf_->IsHorizontalAlignment(); |
760 WmWindow* window = WmWindow::Get(shelf_widget_->GetNativeWindow()); | 763 aura::Window* window = shelf_widget_->GetNativeWindow(); |
761 gfx::Rect available_bounds = wm::GetDisplayBoundsWithShelf(window); | 764 gfx::Rect available_bounds = ScreenUtil::GetDisplayBoundsWithShelf(window); |
762 int resistance_free_region = 0; | 765 int resistance_free_region = 0; |
763 | 766 |
764 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && | 767 if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && |
765 visibility_state() == SHELF_AUTO_HIDE && | 768 visibility_state() == SHELF_AUTO_HIDE && |
766 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) { | 769 auto_hide_state() != SHELF_AUTO_HIDE_SHOWN) { |
767 // If the shelf was hidden when the drag started (and the state hasn't | 770 // If the shelf was hidden when the drag started (and the state hasn't |
768 // changed since then, e.g. because the tray-menu was shown because of the | 771 // changed since then, e.g. because the tray-menu was shown because of the |
769 // drag), then allow the drag some resistance-free region at first to make | 772 // drag), then allow the drag some resistance-free region at first to make |
770 // sure the shelf sticks with the finger until the shelf is visible. | 773 // sure the shelf sticks with the finger until the shelf is visible. |
771 resistance_free_region = kShelfSize - kShelfAutoHideSize; | 774 resistance_free_region = kShelfSize - kShelfAutoHideSize; |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1139 gesture_drag_status_ = GESTURE_DRAG_NONE; | 1142 gesture_drag_status_ = GESTURE_DRAG_NONE; |
1140 } | 1143 } |
1141 | 1144 |
1142 void ShelfLayoutManager::CancelGestureDrag() { | 1145 void ShelfLayoutManager::CancelGestureDrag() { |
1143 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS; | 1146 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS; |
1144 UpdateVisibilityState(); | 1147 UpdateVisibilityState(); |
1145 gesture_drag_status_ = GESTURE_DRAG_NONE; | 1148 gesture_drag_status_ = GESTURE_DRAG_NONE; |
1146 } | 1149 } |
1147 | 1150 |
1148 } // namespace ash | 1151 } // namespace ash |
OLD | NEW |