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 <cstring> | 9 #include <cstring> |
10 #include <string> | 10 #include <string> |
(...skipping 28 matching lines...) Expand all Loading... |
39 #include "ui/aura/client/cursor_client.h" | 39 #include "ui/aura/client/cursor_client.h" |
40 #include "ui/aura/window_event_dispatcher.h" | 40 #include "ui/aura/window_event_dispatcher.h" |
41 #include "ui/base/ui_base_switches.h" | 41 #include "ui/base/ui_base_switches.h" |
42 #include "ui/compositor/layer.h" | 42 #include "ui/compositor/layer.h" |
43 #include "ui/compositor/layer_animation_observer.h" | 43 #include "ui/compositor/layer_animation_observer.h" |
44 #include "ui/compositor/layer_animator.h" | 44 #include "ui/compositor/layer_animator.h" |
45 #include "ui/compositor/scoped_layer_animation_settings.h" | 45 #include "ui/compositor/scoped_layer_animation_settings.h" |
46 #include "ui/events/event.h" | 46 #include "ui/events/event.h" |
47 #include "ui/events/event_handler.h" | 47 #include "ui/events/event_handler.h" |
48 #include "ui/gfx/screen.h" | 48 #include "ui/gfx/screen.h" |
| 49 #include "ui/keyboard/keyboard_util.h" |
49 #include "ui/views/widget/widget.h" | 50 #include "ui/views/widget/widget.h" |
50 #include "ui/wm/public/activation_client.h" | 51 #include "ui/wm/public/activation_client.h" |
51 | 52 |
52 namespace ash { | 53 namespace ash { |
53 namespace { | 54 namespace { |
54 | 55 |
55 // Delay before showing the shelf. This is after the mouse stops moving. | 56 // Delay before showing the shelf. This is after the mouse stops moving. |
56 const int kAutoHideDelayMS = 200; | 57 const int kAutoHideDelayMS = 200; |
57 | 58 |
58 // To avoid hiding the shelf when the mouse transitions from a message bubble | 59 // To avoid hiding the shelf when the mouse transitions from a message bubble |
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 bounds->Inset(SelectValueForShelfAlignment( | 769 bounds->Inset(SelectValueForShelfAlignment( |
769 gfx::Insets(0, 0, inset, 0), | 770 gfx::Insets(0, 0, inset, 0), |
770 gfx::Insets(0, inset, 0, 0), | 771 gfx::Insets(0, inset, 0, 0), |
771 gfx::Insets(0, 0, 0, inset), | 772 gfx::Insets(0, 0, 0, inset), |
772 gfx::Insets(inset, 0, 0, 0))); | 773 gfx::Insets(inset, 0, 0, 0))); |
773 } | 774 } |
774 | 775 |
775 void ShelfLayoutManager::CalculateTargetBounds( | 776 void ShelfLayoutManager::CalculateTargetBounds( |
776 const State& state, | 777 const State& state, |
777 TargetBounds* target_bounds) { | 778 TargetBounds* target_bounds) { |
778 const gfx::Rect available_bounds(GetAvailableBounds()); | 779 const gfx::Rect available_bounds(root_window_->bounds()); |
779 gfx::Rect status_size( | 780 gfx::Rect status_size( |
780 shelf_->status_area_widget()->GetWindowBoundsInScreen().size()); | 781 shelf_->status_area_widget()->GetWindowBoundsInScreen().size()); |
781 int shelf_width = 0, shelf_height = 0; | 782 int shelf_width = 0, shelf_height = 0; |
782 GetShelfSize(&shelf_width, &shelf_height); | 783 GetShelfSize(&shelf_width, &shelf_height); |
783 if (IsHorizontalAlignment()) | 784 if (IsHorizontalAlignment()) |
784 shelf_width = available_bounds.width(); | 785 shelf_width = available_bounds.width(); |
785 else | 786 else |
786 shelf_height = available_bounds.height(); | 787 shelf_height = available_bounds.height(); |
787 | 788 |
788 if (state.visibility_state == SHELF_AUTO_HIDE && | 789 if (state.visibility_state == SHELF_AUTO_HIDE && |
789 state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) { | 790 state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) { |
790 // Auto-hidden shelf always starts with the default size. If a gesture-drag | 791 // Auto-hidden shelf always starts with the default size. If a gesture-drag |
791 // is in progress, then the call to UpdateTargetBoundsForGesture() below | 792 // is in progress, then the call to UpdateTargetBoundsForGesture() below |
792 // takes care of setting the height properly. | 793 // takes care of setting the height properly. |
793 if (IsHorizontalAlignment()) | 794 if (IsHorizontalAlignment()) |
794 shelf_height = kAutoHideSize; | 795 shelf_height = kAutoHideSize; |
795 else | 796 else |
796 shelf_width = kAutoHideSize; | 797 shelf_width = kAutoHideSize; |
797 } else if (state.visibility_state == SHELF_HIDDEN || | 798 } else if (state.visibility_state == SHELF_HIDDEN) { |
798 !keyboard_bounds_.IsEmpty()) { | |
799 if (IsHorizontalAlignment()) | 799 if (IsHorizontalAlignment()) |
800 shelf_height = 0; | 800 shelf_height = 0; |
801 else | 801 else |
802 shelf_width = 0; | 802 shelf_width = 0; |
803 } | 803 } |
804 | 804 |
| 805 int bottom_shelf_vertical_offset = available_bounds.bottom(); |
| 806 if (keyboard_bounds_.IsEmpty()) |
| 807 bottom_shelf_vertical_offset -= shelf_height; |
| 808 else |
| 809 bottom_shelf_vertical_offset -= keyboard_bounds_.height(); |
| 810 |
805 target_bounds->shelf_bounds_in_root = SelectValueForShelfAlignment( | 811 target_bounds->shelf_bounds_in_root = SelectValueForShelfAlignment( |
806 gfx::Rect(available_bounds.x(), available_bounds.bottom() - shelf_height, | 812 gfx::Rect(available_bounds.x(), bottom_shelf_vertical_offset, |
807 available_bounds.width(), shelf_height), | 813 available_bounds.width(), shelf_height), |
808 gfx::Rect(available_bounds.x(), available_bounds.y(), | 814 gfx::Rect(available_bounds.x(), available_bounds.y(), |
809 shelf_width, available_bounds.height()), | 815 shelf_width, available_bounds.height()), |
810 gfx::Rect(available_bounds.right() - shelf_width, available_bounds.y(), | 816 gfx::Rect(available_bounds.right() - shelf_width, available_bounds.y(), |
811 shelf_width, available_bounds.height()), | 817 shelf_width, available_bounds.height()), |
812 gfx::Rect(available_bounds.x(), available_bounds.y(), | 818 gfx::Rect(available_bounds.x(), available_bounds.y(), |
813 available_bounds.width(), shelf_height)); | 819 available_bounds.width(), shelf_height)); |
814 | 820 |
815 if (IsHorizontalAlignment()) | 821 if (IsHorizontalAlignment()) |
816 status_size.set_height(kShelfSize); | 822 status_size.set_height(kShelfSize); |
(...skipping 15 matching lines...) Expand all Loading... |
832 target_bounds->work_area_insets = SelectValueForShelfAlignment( | 838 target_bounds->work_area_insets = SelectValueForShelfAlignment( |
833 gfx::Insets(0, 0, GetWorkAreaSize(state, shelf_height), 0), | 839 gfx::Insets(0, 0, GetWorkAreaSize(state, shelf_height), 0), |
834 gfx::Insets(0, GetWorkAreaSize(state, shelf_width), 0, 0), | 840 gfx::Insets(0, GetWorkAreaSize(state, shelf_width), 0, 0), |
835 gfx::Insets(0, 0, 0, GetWorkAreaSize(state, shelf_width)), | 841 gfx::Insets(0, 0, 0, GetWorkAreaSize(state, shelf_width)), |
836 gfx::Insets(GetWorkAreaSize(state, shelf_height), 0, 0, 0)); | 842 gfx::Insets(GetWorkAreaSize(state, shelf_height), 0, 0, 0)); |
837 | 843 |
838 // TODO(varkha): The functionality of managing insets for display areas | 844 // TODO(varkha): The functionality of managing insets for display areas |
839 // should probably be pushed to a separate component. This would simplify or | 845 // should probably be pushed to a separate component. This would simplify or |
840 // remove entirely the dependency on keyboard and dock. | 846 // remove entirely the dependency on keyboard and dock. |
841 | 847 |
842 // Also push in the work area inset for the keyboard if it is visible. | 848 if (!keyboard_bounds_.IsEmpty() && !keyboard::IsKeyboardOverscrollEnabled()) { |
843 if (!keyboard_bounds_.IsEmpty()) { | 849 // Also push in the work area inset for the keyboard if it is visible. |
844 gfx::Insets keyboard_insets(0, 0, keyboard_bounds_.height(), 0); | 850 gfx::Insets keyboard_insets(0, 0, keyboard_bounds_.height(), 0); |
845 target_bounds->work_area_insets += keyboard_insets; | 851 target_bounds->work_area_insets += keyboard_insets; |
846 } | 852 } |
847 | 853 |
848 // Also push in the work area inset for the dock if it is visible. | 854 // Also push in the work area inset for the dock if it is visible. |
849 if (!dock_bounds_.IsEmpty()) { | 855 if (!dock_bounds_.IsEmpty()) { |
850 gfx::Insets dock_insets( | 856 gfx::Insets dock_insets( |
851 0, (dock_bounds_.x() > 0 ? 0 : dock_bounds_.width()), | 857 0, (dock_bounds_.x() > 0 ? 0 : dock_bounds_.width()), |
852 0, (dock_bounds_.x() > 0 ? dock_bounds_.width() : 0)); | 858 0, (dock_bounds_.x() > 0 ? dock_bounds_.width() : 0)); |
853 target_bounds->work_area_insets += dock_insets; | 859 target_bounds->work_area_insets += dock_insets; |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 } | 1120 } |
1115 | 1121 |
1116 int ShelfLayoutManager::GetWorkAreaSize(const State& state, int size) const { | 1122 int ShelfLayoutManager::GetWorkAreaSize(const State& state, int size) const { |
1117 if (state.visibility_state == SHELF_VISIBLE) | 1123 if (state.visibility_state == SHELF_VISIBLE) |
1118 return size; | 1124 return size; |
1119 if (state.visibility_state == SHELF_AUTO_HIDE) | 1125 if (state.visibility_state == SHELF_AUTO_HIDE) |
1120 return kAutoHideSize; | 1126 return kAutoHideSize; |
1121 return 0; | 1127 return 0; |
1122 } | 1128 } |
1123 | 1129 |
1124 gfx::Rect ShelfLayoutManager::GetAvailableBounds() const { | |
1125 gfx::Rect bounds(root_window_->bounds()); | |
1126 bounds.set_height(bounds.height() - keyboard_bounds_.height()); | |
1127 return bounds; | |
1128 } | |
1129 | |
1130 void ShelfLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { | 1130 void ShelfLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { |
1131 bool keyboard_is_about_to_hide = false; | 1131 bool keyboard_is_about_to_hide = false; |
1132 if (new_bounds.IsEmpty() && !keyboard_bounds_.IsEmpty()) | 1132 if (new_bounds.IsEmpty() && !keyboard_bounds_.IsEmpty()) |
1133 keyboard_is_about_to_hide = true; | 1133 keyboard_is_about_to_hide = true; |
1134 | 1134 |
1135 keyboard_bounds_ = new_bounds; | 1135 keyboard_bounds_ = new_bounds; |
1136 OnWindowResized(); | 1136 OnWindowResized(); |
1137 | 1137 |
1138 SessionStateDelegate* session_state_delegate = | 1138 SessionStateDelegate* session_state_delegate = |
1139 Shell::GetInstance()->session_state_delegate(); | 1139 Shell::GetInstance()->session_state_delegate(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1178 | 1178 |
1179 void ShelfLayoutManager::SessionStateChanged( | 1179 void ShelfLayoutManager::SessionStateChanged( |
1180 SessionStateDelegate::SessionState state) { | 1180 SessionStateDelegate::SessionState state) { |
1181 TargetBounds target_bounds; | 1181 TargetBounds target_bounds; |
1182 CalculateTargetBounds(state_, &target_bounds); | 1182 CalculateTargetBounds(state_, &target_bounds); |
1183 UpdateBoundsAndOpacity(target_bounds, true, NULL); | 1183 UpdateBoundsAndOpacity(target_bounds, true, NULL); |
1184 UpdateVisibilityState(); | 1184 UpdateVisibilityState(); |
1185 } | 1185 } |
1186 | 1186 |
1187 } // namespace ash | 1187 } // namespace ash |
OLD | NEW |