wm_shadow_controller_delegate.cc 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ash/wm/wm_shadow_controller_delegate.h"
  5. #include "ash/root_window_controller.h"
  6. #include "ash/shell.h"
  7. #include "ash/wm/desks/desks_util.h"
  8. #include "ash/wm/overview/overview_controller.h"
  9. #include "ash/wm/overview/overview_item.h"
  10. #include "ash/wm/overview/overview_session.h"
  11. #include "ash/wm/splitview/split_view_controller.h"
  12. #include "ash/wm/window_state.h"
  13. #include "ui/aura/client/aura_constants.h"
  14. #include "ui/aura/window.h"
  15. #include "ui/wm/core/shadow_types.h"
  16. namespace ash {
  17. WmShadowControllerDelegate::WmShadowControllerDelegate() = default;
  18. WmShadowControllerDelegate::~WmShadowControllerDelegate() = default;
  19. bool WmShadowControllerDelegate::ShouldShowShadowForWindow(
  20. const aura::Window* window) {
  21. // Hide the shadow if it is one of the splitscreen snapped windows.
  22. if (window->GetRootWindow() && RootWindowController::ForWindow(window)) {
  23. SplitViewController* split_view_controller =
  24. SplitViewController::Get(window);
  25. if (split_view_controller &&
  26. split_view_controller->IsWindowInSplitView(window)) {
  27. return false;
  28. }
  29. }
  30. // Hide the shadow while we are in overview mode.
  31. OverviewController* overview_controller = Shell::Get()->overview_controller();
  32. if (overview_controller && overview_controller->InOverviewSession()) {
  33. OverviewSession* overview_session = overview_controller->overview_session();
  34. // InOverviewSession() being true implies |overview_session| exists.
  35. DCHECK(overview_session);
  36. // Windows in overview that are not moving out of the active desk should not
  37. // have shadows.
  38. auto* overview_item = overview_session->GetOverviewItemForWindow(window);
  39. if (desks_util::BelongsToActiveDesk(const_cast<aura::Window*>(window)) &&
  40. overview_item && !overview_item->is_moving_to_another_desk()) {
  41. return false;
  42. }
  43. }
  44. // The shadow state will be updated when the window is added to a parent.
  45. if (!window->parent())
  46. return false;
  47. // Show the shadow if it's currently being dragged no matter of the window's
  48. // show state.
  49. auto* window_state = WindowState::Get(window);
  50. if (window_state && window_state->is_dragged())
  51. return ::wm::GetShadowElevationConvertDefault(window) > 0;
  52. // Hide the shadow if it's not being dragged and it's a maximized/fullscreen
  53. // window.
  54. ui::WindowShowState show_state =
  55. window->GetProperty(aura::client::kShowStateKey);
  56. if (show_state == ui::SHOW_STATE_FULLSCREEN ||
  57. show_state == ui::SHOW_STATE_MAXIMIZED) {
  58. return false;
  59. }
  60. return ::wm::GetShadowElevationConvertDefault(window) > 0;
  61. }
  62. } // namespace ash