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 (!keyboard_bounds_.IsEmpty() && !keyboard::IsKeyboardOverscrollEnabled())) |
| 800 { |
799 if (IsHorizontalAlignment()) | 801 if (IsHorizontalAlignment()) |
800 shelf_height = 0; | 802 shelf_height = 0; |
801 else | 803 else |
802 shelf_width = 0; | 804 shelf_width = 0; |
803 } | 805 } |
804 | 806 |
| 807 int bottom_shelf_vertical_offset = available_bounds.bottom(); |
| 808 if (keyboard_bounds_.IsEmpty()) |
| 809 bottom_shelf_vertical_offset -= shelf_height; |
| 810 else |
| 811 bottom_shelf_vertical_offset -= keyboard_bounds_.height(); |
| 812 |
805 target_bounds->shelf_bounds_in_root = SelectValueForShelfAlignment( | 813 target_bounds->shelf_bounds_in_root = SelectValueForShelfAlignment( |
806 gfx::Rect(available_bounds.x(), available_bounds.bottom() - shelf_height, | 814 gfx::Rect(available_bounds.x(), bottom_shelf_vertical_offset, |
807 available_bounds.width(), shelf_height), | 815 available_bounds.width(), shelf_height), |
808 gfx::Rect(available_bounds.x(), available_bounds.y(), | 816 gfx::Rect(available_bounds.x(), available_bounds.y(), |
809 shelf_width, available_bounds.height()), | 817 shelf_width, available_bounds.height()), |
810 gfx::Rect(available_bounds.right() - shelf_width, available_bounds.y(), | 818 gfx::Rect(available_bounds.right() - shelf_width, available_bounds.y(), |
811 shelf_width, available_bounds.height()), | 819 shelf_width, available_bounds.height()), |
812 gfx::Rect(available_bounds.x(), available_bounds.y(), | 820 gfx::Rect(available_bounds.x(), available_bounds.y(), |
813 available_bounds.width(), shelf_height)); | 821 available_bounds.width(), shelf_height)); |
814 | 822 |
815 if (IsHorizontalAlignment()) | 823 if (IsHorizontalAlignment()) |
816 status_size.set_height(kShelfSize); | 824 status_size.set_height(kShelfSize); |
(...skipping 15 matching lines...) Expand all Loading... |
832 target_bounds->work_area_insets = SelectValueForShelfAlignment( | 840 target_bounds->work_area_insets = SelectValueForShelfAlignment( |
833 gfx::Insets(0, 0, GetWorkAreaSize(state, shelf_height), 0), | 841 gfx::Insets(0, 0, GetWorkAreaSize(state, shelf_height), 0), |
834 gfx::Insets(0, GetWorkAreaSize(state, shelf_width), 0, 0), | 842 gfx::Insets(0, GetWorkAreaSize(state, shelf_width), 0, 0), |
835 gfx::Insets(0, 0, 0, GetWorkAreaSize(state, shelf_width)), | 843 gfx::Insets(0, 0, 0, GetWorkAreaSize(state, shelf_width)), |
836 gfx::Insets(GetWorkAreaSize(state, shelf_height), 0, 0, 0)); | 844 gfx::Insets(GetWorkAreaSize(state, shelf_height), 0, 0, 0)); |
837 | 845 |
838 // TODO(varkha): The functionality of managing insets for display areas | 846 // TODO(varkha): The functionality of managing insets for display areas |
839 // should probably be pushed to a separate component. This would simplify or | 847 // should probably be pushed to a separate component. This would simplify or |
840 // remove entirely the dependency on keyboard and dock. | 848 // remove entirely the dependency on keyboard and dock. |
841 | 849 |
842 // Also push in the work area inset for the keyboard if it is visible. | 850 if (!keyboard_bounds_.IsEmpty() && !keyboard::IsKeyboardOverscrollEnabled()) { |
843 if (!keyboard_bounds_.IsEmpty()) { | 851 // 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); | 852 gfx::Insets keyboard_insets(0, 0, keyboard_bounds_.height(), 0); |
845 target_bounds->work_area_insets += keyboard_insets; | 853 target_bounds->work_area_insets += keyboard_insets; |
846 } | 854 } |
847 | 855 |
848 // Also push in the work area inset for the dock if it is visible. | 856 // Also push in the work area inset for the dock if it is visible. |
849 if (!dock_bounds_.IsEmpty()) { | 857 if (!dock_bounds_.IsEmpty()) { |
850 gfx::Insets dock_insets( | 858 gfx::Insets dock_insets( |
851 0, (dock_bounds_.x() > 0 ? 0 : dock_bounds_.width()), | 859 0, (dock_bounds_.x() > 0 ? 0 : dock_bounds_.width()), |
852 0, (dock_bounds_.x() > 0 ? dock_bounds_.width() : 0)); | 860 0, (dock_bounds_.x() > 0 ? dock_bounds_.width() : 0)); |
853 target_bounds->work_area_insets += dock_insets; | 861 target_bounds->work_area_insets += dock_insets; |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1127 // Bail out early when there is no |workspace_controller_|, which happens | 1135 // Bail out early when there is no |workspace_controller_|, which happens |
1128 // during shutdown after PrepareForShutdown. | 1136 // during shutdown after PrepareForShutdown. |
1129 if (!workspace_controller_) | 1137 if (!workspace_controller_) |
1130 return force_shelf_always_visibile_; | 1138 return force_shelf_always_visibile_; |
1131 | 1139 |
1132 return force_shelf_always_visibile_ && | 1140 return force_shelf_always_visibile_ && |
1133 workspace_controller_->GetWindowState() != | 1141 workspace_controller_->GetWindowState() != |
1134 WORKSPACE_WINDOW_STATE_FULL_SCREEN; | 1142 WORKSPACE_WINDOW_STATE_FULL_SCREEN; |
1135 } | 1143 } |
1136 | 1144 |
1137 gfx::Rect ShelfLayoutManager::GetAvailableBounds() const { | |
1138 gfx::Rect bounds(root_window_->bounds()); | |
1139 bounds.set_height(bounds.height() - keyboard_bounds_.height()); | |
1140 return bounds; | |
1141 } | |
1142 | |
1143 void ShelfLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { | 1145 void ShelfLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { |
1144 bool keyboard_is_about_to_hide = false; | 1146 bool keyboard_is_about_to_hide = false; |
1145 if (new_bounds.IsEmpty() && !keyboard_bounds_.IsEmpty()) | 1147 if (new_bounds.IsEmpty() && !keyboard_bounds_.IsEmpty()) |
1146 keyboard_is_about_to_hide = true; | 1148 keyboard_is_about_to_hide = true; |
1147 | 1149 |
1148 keyboard_bounds_ = new_bounds; | 1150 keyboard_bounds_ = new_bounds; |
1149 OnWindowResized(); | 1151 OnWindowResized(); |
1150 | 1152 |
1151 SessionStateDelegate* session_state_delegate = | 1153 SessionStateDelegate* session_state_delegate = |
1152 Shell::GetInstance()->session_state_delegate(); | 1154 Shell::GetInstance()->session_state_delegate(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1191 | 1193 |
1192 void ShelfLayoutManager::SessionStateChanged( | 1194 void ShelfLayoutManager::SessionStateChanged( |
1193 SessionStateDelegate::SessionState state) { | 1195 SessionStateDelegate::SessionState state) { |
1194 TargetBounds target_bounds; | 1196 TargetBounds target_bounds; |
1195 CalculateTargetBounds(state_, &target_bounds); | 1197 CalculateTargetBounds(state_, &target_bounds); |
1196 UpdateBoundsAndOpacity(target_bounds, true, NULL); | 1198 UpdateBoundsAndOpacity(target_bounds, true, NULL); |
1197 UpdateVisibilityState(); | 1199 UpdateVisibilityState(); |
1198 } | 1200 } |
1199 | 1201 |
1200 } // namespace ash | 1202 } // namespace ash |
OLD | NEW |