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> |
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_widget.h" | 22 #include "ash/shelf/shelf_widget.h" |
23 #include "ash/shell.h" | 23 #include "ash/shell.h" |
24 #include "ash/shell_window_ids.h" | 24 #include "ash/shell_window_ids.h" |
25 #include "ash/system/status_area_widget.h" | 25 #include "ash/system/status_area_widget.h" |
26 #include "ash/wm/gestures/shelf_gesture_handler.h" | 26 #include "ash/wm/gestures/shelf_gesture_handler.h" |
27 #include "ash/wm/lock_state_controller.h" | 27 #include "ash/wm/lock_state_controller.h" |
28 #include "ash/wm/maximize_mode/maximize_mode_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_util.h" | 32 #include "ash/wm/window_util.h" |
32 #include "ash/wm/workspace_controller.h" | 33 #include "ash/wm/workspace_controller.h" |
33 #include "base/auto_reset.h" | 34 #include "base/auto_reset.h" |
34 #include "base/command_line.h" | 35 #include "base/command_line.h" |
35 #include "base/command_line.h" | |
36 #include "base/i18n/rtl.h" | 36 #include "base/i18n/rtl.h" |
37 #include "base/strings/string_number_conversions.h" | 37 #include "base/strings/string_number_conversions.h" |
38 #include "base/strings/string_util.h" | 38 #include "base/strings/string_util.h" |
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" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 ShelfLayoutManager* shelf_; | 182 ShelfLayoutManager* shelf_; |
183 | 183 |
184 DISALLOW_COPY_AND_ASSIGN(UpdateShelfObserver); | 184 DISALLOW_COPY_AND_ASSIGN(UpdateShelfObserver); |
185 }; | 185 }; |
186 | 186 |
187 // ShelfLayoutManager ---------------------------------------------------------- | 187 // ShelfLayoutManager ---------------------------------------------------------- |
188 | 188 |
189 ShelfLayoutManager::ShelfLayoutManager(ShelfWidget* shelf) | 189 ShelfLayoutManager::ShelfLayoutManager(ShelfWidget* shelf) |
190 : root_window_(shelf->GetNativeView()->GetRootWindow()), | 190 : root_window_(shelf->GetNativeView()->GetRootWindow()), |
191 updating_bounds_(false), | 191 updating_bounds_(false), |
192 force_shelf_always_visibile_( | |
193 Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled()), | |
194 auto_hide_behavior_(SHELF_AUTO_HIDE_BEHAVIOR_NEVER), | 192 auto_hide_behavior_(SHELF_AUTO_HIDE_BEHAVIOR_NEVER), |
195 alignment_(SHELF_ALIGNMENT_BOTTOM), | 193 alignment_(SHELF_ALIGNMENT_BOTTOM), |
196 shelf_(shelf), | 194 shelf_(shelf), |
197 workspace_controller_(NULL), | 195 workspace_controller_(NULL), |
198 window_overlaps_shelf_(false), | 196 window_overlaps_shelf_(false), |
199 mouse_over_shelf_when_auto_hide_timer_started_(false), | 197 mouse_over_shelf_when_auto_hide_timer_started_(false), |
200 bezel_event_filter_(new ShelfBezelEventFilter(this)), | 198 bezel_event_filter_(new ShelfBezelEventFilter(this)), |
201 gesture_drag_status_(GESTURE_DRAG_NONE), | 199 gesture_drag_status_(GESTURE_DRAG_NONE), |
202 gesture_drag_amount_(0.f), | 200 gesture_drag_amount_(0.f), |
203 gesture_drag_auto_hide_state_(SHELF_AUTO_HIDE_SHOWN), | 201 gesture_drag_auto_hide_state_(SHELF_AUTO_HIDE_SHOWN), |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
290 // The height of the ShelfView for a horizontal shelf and the width of | 288 // The height of the ShelfView for a horizontal shelf and the width of |
291 // the ShelfView for a vertical shelf are set when |shelf_|'s bounds | 289 // the ShelfView for a vertical shelf are set when |shelf_|'s bounds |
292 // are changed via UpdateBoundsAndOpacity(). This sets the origin and the | 290 // are changed via UpdateBoundsAndOpacity(). This sets the origin and the |
293 // dimension in the other direction. | 291 // dimension in the other direction. |
294 shelf_->shelf()->SetShelfViewBounds( | 292 shelf_->shelf()->SetShelfViewBounds( |
295 target_bounds.shelf_bounds_in_shelf); | 293 target_bounds.shelf_bounds_in_shelf); |
296 } | 294 } |
297 } | 295 } |
298 | 296 |
299 ShelfVisibilityState ShelfLayoutManager::CalculateShelfVisibility() { | 297 ShelfVisibilityState ShelfLayoutManager::CalculateShelfVisibility() { |
300 switch(auto_hide_behavior_) { | 298 switch (auto_hide_behavior_) { |
jonross
2014/05/29 15:24:42
cpplint
| |
301 case SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: | 299 case SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: |
302 return SHELF_AUTO_HIDE; | 300 return SHELF_AUTO_HIDE; |
303 case SHELF_AUTO_HIDE_BEHAVIOR_NEVER: | 301 case SHELF_AUTO_HIDE_BEHAVIOR_NEVER: |
304 return SHELF_VISIBLE; | 302 return SHELF_VISIBLE; |
305 case SHELF_AUTO_HIDE_ALWAYS_HIDDEN: | 303 case SHELF_AUTO_HIDE_ALWAYS_HIDDEN: |
306 return SHELF_HIDDEN; | 304 return SHELF_HIDDEN; |
307 } | 305 } |
308 return SHELF_VISIBLE; | 306 return SHELF_VISIBLE; |
309 } | 307 } |
310 | 308 |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
555 void ShelfLayoutManager::OnLockStateChanged(bool locked) { | 553 void ShelfLayoutManager::OnLockStateChanged(bool locked) { |
556 // Force the shelf to layout for alignment (bottom if locked, restore | 554 // Force the shelf to layout for alignment (bottom if locked, restore |
557 // the previous alignment otherwise). | 555 // the previous alignment otherwise). |
558 state_.is_screen_locked = locked; | 556 state_.is_screen_locked = locked; |
559 shelf_->SetAlignment(locked ? SHELF_ALIGNMENT_BOTTOM : alignment_); | 557 shelf_->SetAlignment(locked ? SHELF_ALIGNMENT_BOTTOM : alignment_); |
560 UpdateVisibilityState(); | 558 UpdateVisibilityState(); |
561 LayoutShelf(); | 559 LayoutShelf(); |
562 } | 560 } |
563 | 561 |
564 void ShelfLayoutManager::OnMaximizeModeStarted() { | 562 void ShelfLayoutManager::OnMaximizeModeStarted() { |
565 DCHECK(!force_shelf_always_visibile_); | |
566 force_shelf_always_visibile_ = true; | |
567 UpdateVisibilityState(); | 563 UpdateVisibilityState(); |
568 } | 564 } |
569 | 565 |
570 void ShelfLayoutManager::OnMaximizeModeEnded() { | 566 void ShelfLayoutManager::OnMaximizeModeEnded() { |
571 DCHECK(force_shelf_always_visibile_); | |
572 // Note: At this time Ash::Shell::IsMaximizeModeWindowManagerEnabled() will | |
573 // report true, even though it is in progress of shut down. To address this | |
574 // |force_shelf_always_visibile_| will be read. | |
575 force_shelf_always_visibile_ = false; | |
576 UpdateVisibilityState(); | 567 UpdateVisibilityState(); |
577 } | 568 } |
578 | 569 |
579 void ShelfLayoutManager::OnWindowActivated(aura::Window* gained_active, | 570 void ShelfLayoutManager::OnWindowActivated(aura::Window* gained_active, |
580 aura::Window* lost_active) { | 571 aura::Window* lost_active) { |
581 UpdateAutoHideStateNow(); | 572 UpdateAutoHideStateNow(); |
582 } | 573 } |
583 | 574 |
584 bool ShelfLayoutManager::IsHorizontalAlignment() const { | 575 bool ShelfLayoutManager::IsHorizontalAlignment() const { |
585 return GetAlignment() == SHELF_ALIGNMENT_BOTTOM || | 576 return GetAlignment() == SHELF_ALIGNMENT_BOTTOM || |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
797 if (state.visibility_state == SHELF_AUTO_HIDE && | 788 if (state.visibility_state == SHELF_AUTO_HIDE && |
798 state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) { | 789 state.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN) { |
799 // Auto-hidden shelf always starts with the default size. If a gesture-drag | 790 // Auto-hidden shelf always starts with the default size. If a gesture-drag |
800 // is in progress, then the call to UpdateTargetBoundsForGesture() below | 791 // is in progress, then the call to UpdateTargetBoundsForGesture() below |
801 // takes care of setting the height properly. | 792 // takes care of setting the height properly. |
802 if (IsHorizontalAlignment()) | 793 if (IsHorizontalAlignment()) |
803 shelf_height = kAutoHideSize; | 794 shelf_height = kAutoHideSize; |
804 else | 795 else |
805 shelf_width = kAutoHideSize; | 796 shelf_width = kAutoHideSize; |
806 } else if (state.visibility_state == SHELF_HIDDEN || | 797 } else if (state.visibility_state == SHELF_HIDDEN || |
807 (!keyboard_bounds_.IsEmpty() && !keyboard::IsKeyboardOverscrollEnabled())) | 798 (!keyboard_bounds_.IsEmpty() && |
808 { | 799 !keyboard::IsKeyboardOverscrollEnabled())) { |
jonross
2014/05/29 15:24:42
cpplint
flackr
2014/05/29 16:10:06
nit: This can be aligned with the above line (i.e.
jonross
2014/05/29 17:40:00
Done.
| |
809 if (IsHorizontalAlignment()) | 800 if (IsHorizontalAlignment()) |
810 shelf_height = 0; | 801 shelf_height = 0; |
811 else | 802 else |
812 shelf_width = 0; | 803 shelf_width = 0; |
813 } | 804 } |
814 | 805 |
815 int bottom_shelf_vertical_offset = available_bounds.bottom(); | 806 int bottom_shelf_vertical_offset = available_bounds.bottom(); |
816 if (keyboard_bounds_.IsEmpty()) | 807 if (keyboard_bounds_.IsEmpty()) |
817 bottom_shelf_vertical_offset -= shelf_height; | 808 bottom_shelf_vertical_offset -= shelf_height; |
818 else | 809 else |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1133 | 1124 |
1134 int ShelfLayoutManager::GetWorkAreaSize(const State& state, int size) const { | 1125 int ShelfLayoutManager::GetWorkAreaSize(const State& state, int size) const { |
1135 if (state.visibility_state == SHELF_VISIBLE) | 1126 if (state.visibility_state == SHELF_VISIBLE) |
1136 return size; | 1127 return size; |
1137 if (state.visibility_state == SHELF_AUTO_HIDE) | 1128 if (state.visibility_state == SHELF_AUTO_HIDE) |
1138 return kAutoHideSize; | 1129 return kAutoHideSize; |
1139 return 0; | 1130 return 0; |
1140 } | 1131 } |
1141 | 1132 |
1142 bool ShelfLayoutManager::IsShelfForcedToBeVisible() const { | 1133 bool ShelfLayoutManager::IsShelfForcedToBeVisible() const { |
1134 bool force_shelf_always_visibile = Shell::GetInstance()-> | |
1135 maximize_mode_controller()->IsMaximizeModeWindowManagerEnabled(); | |
1143 // Bail out early when there is no |workspace_controller_|, which happens | 1136 // Bail out early when there is no |workspace_controller_|, which happens |
1144 // during shutdown after PrepareForShutdown. | 1137 // during shutdown after PrepareForShutdown. |
1145 if (!workspace_controller_) | 1138 if (!workspace_controller_) |
1146 return force_shelf_always_visibile_; | 1139 return force_shelf_always_visibile; |
1147 | 1140 |
1148 return force_shelf_always_visibile_ && | 1141 return force_shelf_always_visibile && |
1149 workspace_controller_->GetWindowState() != | 1142 workspace_controller_->GetWindowState() != |
1150 WORKSPACE_WINDOW_STATE_FULL_SCREEN; | 1143 WORKSPACE_WINDOW_STATE_FULL_SCREEN; |
1151 } | 1144 } |
1152 | 1145 |
1153 void ShelfLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { | 1146 void ShelfLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { |
1154 bool keyboard_is_about_to_hide = false; | 1147 bool keyboard_is_about_to_hide = false; |
1155 if (new_bounds.IsEmpty() && !keyboard_bounds_.IsEmpty()) | 1148 if (new_bounds.IsEmpty() && !keyboard_bounds_.IsEmpty()) |
1156 keyboard_is_about_to_hide = true; | 1149 keyboard_is_about_to_hide = true; |
1157 | 1150 |
1158 keyboard_bounds_ = new_bounds; | 1151 keyboard_bounds_ = new_bounds; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1193 | 1186 |
1194 void ShelfLayoutManager::SessionStateChanged( | 1187 void ShelfLayoutManager::SessionStateChanged( |
1195 SessionStateDelegate::SessionState state) { | 1188 SessionStateDelegate::SessionState state) { |
1196 TargetBounds target_bounds; | 1189 TargetBounds target_bounds; |
1197 CalculateTargetBounds(state_, &target_bounds); | 1190 CalculateTargetBounds(state_, &target_bounds); |
1198 UpdateBoundsAndOpacity(target_bounds, true, NULL); | 1191 UpdateBoundsAndOpacity(target_bounds, true, NULL); |
1199 UpdateVisibilityState(); | 1192 UpdateVisibilityState(); |
1200 } | 1193 } |
1201 | 1194 |
1202 } // namespace ash | 1195 } // namespace ash |
OLD | NEW |