| 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/common/ash_switches.h" |
| 11 #include "ash/common/material_design/material_design_controller.h" | 12 #include "ash/common/material_design/material_design_controller.h" |
| 12 #include "ash/common/session/session_state_delegate.h" | 13 #include "ash/common/session/session_state_delegate.h" |
| 13 #include "ash/common/shelf/shelf_constants.h" | 14 #include "ash/common/shelf/shelf_constants.h" |
| 14 #include "ash/common/shelf/shelf_delegate.h" | 15 #include "ash/common/shelf/shelf_delegate.h" |
| 15 #include "ash/common/shelf/wm_shelf_util.h" | 16 #include "ash/common/shelf/wm_shelf_util.h" |
| 16 #include "ash/common/shell_window_ids.h" | 17 #include "ash/common/shell_window_ids.h" |
| 17 #include "ash/common/system/status_area_widget.h" | 18 #include "ash/common/system/status_area_widget.h" |
| 18 #include "ash/common/wm/fullscreen_window_finder.h" | 19 #include "ash/common/wm/fullscreen_window_finder.h" |
| 19 #include "ash/common/wm/mru_window_tracker.h" | 20 #include "ash/common/wm/mru_window_tracker.h" |
| 20 #include "ash/common/wm/window_state.h" | 21 #include "ash/common/wm/window_state.h" |
| 21 #include "ash/common/wm/wm_screen_util.h" | 22 #include "ash/common/wm/wm_screen_util.h" |
| 22 #include "ash/common/wm_lookup.h" | 23 #include "ash/common/wm_lookup.h" |
| 23 #include "ash/common/wm_root_window_controller.h" | 24 #include "ash/common/wm_root_window_controller.h" |
| 24 #include "ash/common/wm_root_window_controller_observer.h" | 25 #include "ash/common/wm_root_window_controller_observer.h" |
| 25 #include "ash/common/wm_shell.h" | 26 #include "ash/common/wm_shell.h" |
| 26 #include "ash/common/wm_window.h" | 27 #include "ash/common/wm_window.h" |
| 27 #include "ash/shelf/shelf.h" | 28 #include "ash/shelf/shelf.h" |
| 28 #include "ash/shelf/shelf_layout_manager_observer.h" | 29 #include "ash/shelf/shelf_layout_manager_observer.h" |
| 29 #include "ash/wm/workspace_controller.h" | 30 #include "ash/wm/workspace_controller.h" |
| 30 #include "base/auto_reset.h" | 31 #include "base/auto_reset.h" |
| 32 #include "base/command_line.h" |
| 31 #include "base/i18n/rtl.h" | 33 #include "base/i18n/rtl.h" |
| 32 #include "ui/compositor/layer.h" | 34 #include "ui/compositor/layer.h" |
| 33 #include "ui/compositor/layer_animation_observer.h" | 35 #include "ui/compositor/layer_animation_observer.h" |
| 34 #include "ui/compositor/layer_animator.h" | 36 #include "ui/compositor/layer_animator.h" |
| 35 #include "ui/compositor/scoped_layer_animation_settings.h" | 37 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 36 #include "ui/display/display.h" | 38 #include "ui/display/display.h" |
| 37 #include "ui/display/screen.h" | 39 #include "ui/display/screen.h" |
| 38 #include "ui/events/event.h" | 40 #include "ui/events/event.h" |
| 41 #include "ui/events/event_handler.h" |
| 42 #include "ui/keyboard/keyboard_controller.h" |
| 39 #include "ui/keyboard/keyboard_util.h" | 43 #include "ui/keyboard/keyboard_util.h" |
| 40 #include "ui/views/border.h" | 44 #include "ui/views/border.h" |
| 41 #include "ui/views/widget/widget.h" | 45 #include "ui/views/widget/widget.h" |
| 42 | 46 |
| 43 namespace ash { | 47 namespace ash { |
| 44 namespace { | 48 namespace { |
| 45 | 49 |
| 46 // Delay before showing the shelf. This is after the mouse stops moving. | 50 // Delay before showing the shelf. This is after the mouse stops moving. |
| 47 const int kAutoHideDelayMS = 200; | 51 const int kAutoHideDelayMS = 200; |
| 48 | 52 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 gfx::Rect(rect.right() - shelf_size, rect.y(), shelf_size, | 202 gfx::Rect(rect.right() - shelf_size, rect.y(), shelf_size, |
| 199 rect.height())); | 203 rect.height())); |
| 200 } | 204 } |
| 201 | 205 |
| 202 gfx::Size ShelfLayoutManager::GetPreferredSize() { | 206 gfx::Size ShelfLayoutManager::GetPreferredSize() { |
| 203 TargetBounds target_bounds; | 207 TargetBounds target_bounds; |
| 204 CalculateTargetBounds(state_, &target_bounds); | 208 CalculateTargetBounds(state_, &target_bounds); |
| 205 return target_bounds.shelf_bounds_in_root.size(); | 209 return target_bounds.shelf_bounds_in_root.size(); |
| 206 } | 210 } |
| 207 | 211 |
| 208 void ShelfLayoutManager::LayoutShelf() { | 212 void ShelfLayoutManager::LayoutShelfAndUpdateBounds(bool change_work_area) { |
| 209 TargetBounds target_bounds; | 213 TargetBounds target_bounds; |
| 210 CalculateTargetBounds(state_, &target_bounds); | 214 CalculateTargetBounds(state_, &target_bounds); |
| 211 UpdateBoundsAndOpacity(target_bounds, false, NULL); | 215 UpdateBoundsAndOpacity(target_bounds, false, change_work_area, NULL); |
| 212 | 216 |
| 213 // Update insets in ShelfWindowTargeter when shelf bounds change. | 217 // Update insets in ShelfWindowTargeter when shelf bounds change. |
| 214 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, | 218 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, |
| 215 WillChangeVisibilityState(visibility_state())); | 219 WillChangeVisibilityState(visibility_state())); |
| 216 } | 220 } |
| 217 | 221 |
| 222 void ShelfLayoutManager::LayoutShelf() { |
| 223 LayoutShelfAndUpdateBounds(true); |
| 224 } |
| 225 |
| 218 ShelfVisibilityState ShelfLayoutManager::CalculateShelfVisibility() { | 226 ShelfVisibilityState ShelfLayoutManager::CalculateShelfVisibility() { |
| 219 switch (shelf_widget_->shelf()->auto_hide_behavior()) { | 227 switch (shelf_widget_->shelf()->auto_hide_behavior()) { |
| 220 case SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: | 228 case SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: |
| 221 return SHELF_AUTO_HIDE; | 229 return SHELF_AUTO_HIDE; |
| 222 case SHELF_AUTO_HIDE_BEHAVIOR_NEVER: | 230 case SHELF_AUTO_HIDE_BEHAVIOR_NEVER: |
| 223 return SHELF_VISIBLE; | 231 return SHELF_VISIBLE; |
| 224 case SHELF_AUTO_HIDE_ALWAYS_HIDDEN: | 232 case SHELF_AUTO_HIDE_ALWAYS_HIDDEN: |
| 225 return SHELF_HIDDEN; | 233 return SHELF_HIDDEN; |
| 226 } | 234 } |
| 227 return SHELF_VISIBLE; | 235 return SHELF_VISIBLE; |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 | 418 |
| 411 void ShelfLayoutManager::OnWindowActivated(WmWindow* gained_active, | 419 void ShelfLayoutManager::OnWindowActivated(WmWindow* gained_active, |
| 412 WmWindow* lost_active) { | 420 WmWindow* lost_active) { |
| 413 UpdateAutoHideStateNow(); | 421 UpdateAutoHideStateNow(); |
| 414 } | 422 } |
| 415 | 423 |
| 416 void ShelfLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { | 424 void ShelfLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) { |
| 417 bool keyboard_is_about_to_hide = false; | 425 bool keyboard_is_about_to_hide = false; |
| 418 if (new_bounds.IsEmpty() && !keyboard_bounds_.IsEmpty()) | 426 if (new_bounds.IsEmpty() && !keyboard_bounds_.IsEmpty()) |
| 419 keyboard_is_about_to_hide = true; | 427 keyboard_is_about_to_hide = true; |
| 428 // If new window behavior flag enabled and in non-sticky mode, do not change |
| 429 // the work area. |
| 430 bool change_work_area = |
| 431 (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 432 switches::kAshUseNewVKWindowBehavior) || |
| 433 keyboard::KeyboardController::GetInstance()->get_lock_keyboard()); |
| 420 | 434 |
| 421 keyboard_bounds_ = new_bounds; | 435 keyboard_bounds_ = new_bounds; |
| 422 OnWindowResized(); | 436 LayoutShelfAndUpdateBounds(change_work_area); |
| 423 | 437 |
| 424 // On login screen if keyboard has been just hidden, update bounds just once | 438 // On login screen if keyboard has been just hidden, update bounds just once |
| 425 // but ignore target_bounds.work_area_insets since shelf overlaps with login | 439 // but ignore target_bounds.work_area_insets since shelf overlaps with login |
| 426 // window. | 440 // window. |
| 427 if (WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked() && | 441 if (WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked() && |
| 428 keyboard_is_about_to_hide) { | 442 keyboard_is_about_to_hide) { |
| 429 WmWindow* window = WmLookup::Get()->GetWindowForWidget(shelf_widget_); | 443 WmWindow* window = WmLookup::Get()->GetWindowForWidget(shelf_widget_); |
| 430 WmShell::Get()->SetDisplayWorkAreaInsets(window, gfx::Insets()); | 444 WmShell::Get()->SetDisplayWorkAreaInsets(window, gfx::Insets()); |
| 431 } | 445 } |
| 432 } | 446 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 } else { | 539 } else { |
| 526 UpdateShelfBackground(change_type); | 540 UpdateShelfBackground(change_type); |
| 527 } | 541 } |
| 528 | 542 |
| 529 shelf_widget_->SetDimsShelf(state.visibility_state == SHELF_VISIBLE && | 543 shelf_widget_->SetDimsShelf(state.visibility_state == SHELF_VISIBLE && |
| 530 state.window_state == | 544 state.window_state == |
| 531 wm::WORKSPACE_WINDOW_STATE_MAXIMIZED); | 545 wm::WORKSPACE_WINDOW_STATE_MAXIMIZED); |
| 532 | 546 |
| 533 TargetBounds target_bounds; | 547 TargetBounds target_bounds; |
| 534 CalculateTargetBounds(state_, &target_bounds); | 548 CalculateTargetBounds(state_, &target_bounds); |
| 535 UpdateBoundsAndOpacity(target_bounds, true, delay_background_change | 549 UpdateBoundsAndOpacity( |
| 536 ? update_shelf_observer_ | 550 target_bounds, true /* animate */, true /* change_work_area */, |
| 537 : NULL); | 551 delay_background_change ? update_shelf_observer_ : NULL); |
| 538 | 552 |
| 539 // The delegate must be notified after |state_| is updated so that it can | 553 // The delegate must be notified after |state_| is updated so that it can |
| 540 // query the new target bounds. | 554 // query the new target bounds. |
| 541 ShelfDelegate* shelf_delegate = WmShell::Get()->shelf_delegate(); | 555 ShelfDelegate* shelf_delegate = WmShell::Get()->shelf_delegate(); |
| 542 DCHECK(shelf_delegate); | 556 DCHECK(shelf_delegate); |
| 543 if (old_state.visibility_state != state_.visibility_state) | 557 if (old_state.visibility_state != state_.visibility_state) |
| 544 shelf_delegate->OnShelfVisibilityStateChanged(shelf_widget_->shelf()); | 558 shelf_delegate->OnShelfVisibilityStateChanged(shelf_widget_->shelf()); |
| 545 | 559 |
| 546 // OnAutoHideStateChanged Should be emitted when: | 560 // OnAutoHideStateChanged Should be emitted when: |
| 547 // - firstly state changed to auto-hide from other state | 561 // - firstly state changed to auto-hide from other state |
| 548 // - or, auto_hide_state has changed | 562 // - or, auto_hide_state has changed |
| 549 if ((old_state.visibility_state != state_.visibility_state && | 563 if ((old_state.visibility_state != state_.visibility_state && |
| 550 state_.visibility_state == SHELF_AUTO_HIDE) || | 564 state_.visibility_state == SHELF_AUTO_HIDE) || |
| 551 old_state.auto_hide_state != state_.auto_hide_state) { | 565 old_state.auto_hide_state != state_.auto_hide_state) { |
| 552 shelf_delegate->OnShelfAutoHideStateChanged(shelf_widget_->shelf()); | 566 shelf_delegate->OnShelfAutoHideStateChanged(shelf_widget_->shelf()); |
| 553 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, | 567 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, |
| 554 OnAutoHideStateChanged(state_.auto_hide_state)); | 568 OnAutoHideStateChanged(state_.auto_hide_state)); |
| 555 } | 569 } |
| 556 } | 570 } |
| 557 | 571 |
| 558 void ShelfLayoutManager::UpdateBoundsAndOpacity( | 572 void ShelfLayoutManager::UpdateBoundsAndOpacity( |
| 559 const TargetBounds& target_bounds, | 573 const TargetBounds& target_bounds, |
| 560 bool animate, | 574 bool animate, |
| 575 bool change_work_area, |
| 561 ui::ImplicitAnimationObserver* observer) { | 576 ui::ImplicitAnimationObserver* observer) { |
| 562 base::AutoReset<bool> auto_reset_updating_bounds(&updating_bounds_, true); | 577 base::AutoReset<bool> auto_reset_updating_bounds(&updating_bounds_, true); |
| 563 { | 578 { |
| 564 ui::ScopedLayerAnimationSettings shelf_animation_setter( | 579 ui::ScopedLayerAnimationSettings shelf_animation_setter( |
| 565 GetLayer(shelf_widget_)->GetAnimator()); | 580 GetLayer(shelf_widget_)->GetAnimator()); |
| 566 ui::ScopedLayerAnimationSettings status_animation_setter( | 581 ui::ScopedLayerAnimationSettings status_animation_setter( |
| 567 GetLayer(shelf_widget_->status_area_widget())->GetAnimator()); | 582 GetLayer(shelf_widget_->status_area_widget())->GetAnimator()); |
| 568 if (animate) { | 583 if (animate) { |
| 569 int duration = duration_override_in_ms_ ? duration_override_in_ms_ | 584 int duration = duration_override_in_ms_ ? duration_override_in_ms_ |
| 570 : kAnimationDurationMS; | 585 : kAnimationDurationMS; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 607 gfx::Rect status_bounds = target_bounds.status_bounds_in_shelf; | 622 gfx::Rect status_bounds = target_bounds.status_bounds_in_shelf; |
| 608 status_bounds.Offset(target_bounds.shelf_bounds_in_root.OffsetFromOrigin()); | 623 status_bounds.Offset(target_bounds.shelf_bounds_in_root.OffsetFromOrigin()); |
| 609 WmWindow* status_window = WmLookup::Get()->GetWindowForWidget( | 624 WmWindow* status_window = WmLookup::Get()->GetWindowForWidget( |
| 610 shelf_widget_->status_area_widget()); | 625 shelf_widget_->status_area_widget()); |
| 611 shelf_widget_->status_area_widget()->SetBounds( | 626 shelf_widget_->status_area_widget()->SetBounds( |
| 612 status_window->GetParent()->ConvertRectToScreen(status_bounds)); | 627 status_window->GetParent()->ConvertRectToScreen(status_bounds)); |
| 613 | 628 |
| 614 // For crbug.com/622431, when the shelf alignment is BOTTOM_LOCKED, we | 629 // For crbug.com/622431, when the shelf alignment is BOTTOM_LOCKED, we |
| 615 // don't set display work area, as it is not real user-set alignment. | 630 // don't set display work area, as it is not real user-set alignment. |
| 616 if (!state_.is_screen_locked && | 631 if (!state_.is_screen_locked && |
| 617 shelf_widget_->GetAlignment() != SHELF_ALIGNMENT_BOTTOM_LOCKED) { | 632 shelf_widget_->GetAlignment() != SHELF_ALIGNMENT_BOTTOM_LOCKED && |
| 633 change_work_area) { |
| 618 gfx::Insets insets; | 634 gfx::Insets insets; |
| 619 // If user session is blocked (login to new user session or add user to | 635 // If user session is blocked (login to new user session or add user to |
| 620 // the existing session - multi-profile) then give 100% of work area only | 636 // the existing session - multi-profile) then give 100% of work area only |
| 621 // if keyboard is not shown. | 637 // if keyboard is not shown. |
| 622 if (!state_.is_adding_user_screen || !keyboard_bounds_.IsEmpty()) | 638 if (!state_.is_adding_user_screen || !keyboard_bounds_.IsEmpty()) |
| 623 insets = target_bounds.work_area_insets; | 639 insets = target_bounds.work_area_insets; |
| 624 WmShell::Get()->SetDisplayWorkAreaInsets(shelf_window, insets); | 640 WmShell::Get()->SetDisplayWorkAreaInsets(shelf_window, insets); |
| 625 } | 641 } |
| 626 } | 642 } |
| 627 | 643 |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 // Check transition changes to/from the add user to session and change the | 1023 // Check transition changes to/from the add user to session and change the |
| 1008 // shelf alignment accordingly | 1024 // shelf alignment accordingly |
| 1009 bool add_user = state == SessionStateDelegate::SESSION_STATE_LOGIN_SECONDARY; | 1025 bool add_user = state == SessionStateDelegate::SESSION_STATE_LOGIN_SECONDARY; |
| 1010 if (add_user != state_.is_adding_user_screen) { | 1026 if (add_user != state_.is_adding_user_screen) { |
| 1011 state_.is_adding_user_screen = add_user; | 1027 state_.is_adding_user_screen = add_user; |
| 1012 UpdateShelfVisibilityAfterLoginUIChange(); | 1028 UpdateShelfVisibilityAfterLoginUIChange(); |
| 1013 return; | 1029 return; |
| 1014 } | 1030 } |
| 1015 TargetBounds target_bounds; | 1031 TargetBounds target_bounds; |
| 1016 CalculateTargetBounds(state_, &target_bounds); | 1032 CalculateTargetBounds(state_, &target_bounds); |
| 1017 UpdateBoundsAndOpacity(target_bounds, true, NULL); | 1033 UpdateBoundsAndOpacity(target_bounds, true /* animate */, |
| 1034 true /* change_work_area */, NULL); |
| 1018 UpdateVisibilityState(); | 1035 UpdateVisibilityState(); |
| 1019 } | 1036 } |
| 1020 | 1037 |
| 1021 void ShelfLayoutManager::UpdateShelfVisibilityAfterLoginUIChange() { | 1038 void ShelfLayoutManager::UpdateShelfVisibilityAfterLoginUIChange() { |
| 1022 UpdateVisibilityState(); | 1039 UpdateVisibilityState(); |
| 1023 LayoutShelf(); | 1040 LayoutShelf(); |
| 1024 } | 1041 } |
| 1025 | 1042 |
| 1026 float ShelfLayoutManager::ComputeTargetOpacity(const State& state) { | 1043 float ShelfLayoutManager::ComputeTargetOpacity(const State& state) { |
| 1027 if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS || | 1044 if (gesture_drag_status_ == GESTURE_DRAG_IN_PROGRESS || |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1136 gesture_drag_status_ = GESTURE_DRAG_NONE; | 1153 gesture_drag_status_ = GESTURE_DRAG_NONE; |
| 1137 } | 1154 } |
| 1138 | 1155 |
| 1139 void ShelfLayoutManager::CancelGestureDrag() { | 1156 void ShelfLayoutManager::CancelGestureDrag() { |
| 1140 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS; | 1157 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS; |
| 1141 UpdateVisibilityState(); | 1158 UpdateVisibilityState(); |
| 1142 gesture_drag_status_ = GESTURE_DRAG_NONE; | 1159 gesture_drag_status_ = GESTURE_DRAG_NONE; |
| 1143 } | 1160 } |
| 1144 | 1161 |
| 1145 } // namespace ash | 1162 } // namespace ash |
| OLD | NEW |