default_state.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // Copyright 2014 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. #ifndef ASH_WM_DEFAULT_STATE_H_
  5. #define ASH_WM_DEFAULT_STATE_H_
  6. #include "ash/wm/base_state.h"
  7. #include "ash/wm/window_state.h"
  8. #include "ui/display/display.h"
  9. #include "ui/gfx/geometry/rect.h"
  10. namespace ash {
  11. class SetBoundsWMEvent;
  12. namespace mojom {
  13. enum class WindowStateType;
  14. }
  15. // DefaultState implements Ash behavior without state machine.
  16. class DefaultState : public BaseState {
  17. public:
  18. explicit DefaultState(chromeos::WindowStateType initial_state_type);
  19. DefaultState(const DefaultState&) = delete;
  20. DefaultState& operator=(const DefaultState&) = delete;
  21. ~DefaultState() override;
  22. // WindowState::State overrides:
  23. void AttachState(WindowState* window_state,
  24. WindowState::State* previous_state) override;
  25. void DetachState(WindowState* window_state) override;
  26. // BaseState:
  27. void HandleWorkspaceEvents(WindowState* window_state,
  28. const WMEvent* event) override;
  29. void HandleCompoundEvents(WindowState* window_state,
  30. const WMEvent* event) override;
  31. void HandleBoundsEvents(WindowState* window_state,
  32. const WMEvent* event) override;
  33. void HandleTransitionEvents(WindowState* window_state,
  34. const WMEvent* event) override;
  35. private:
  36. // Set the fullscreen/maximized bounds without animation.
  37. static bool SetMaximizedOrFullscreenBounds(WindowState* window_state);
  38. static void SetBounds(WindowState* window_state,
  39. const SetBoundsWMEvent* bounds_event);
  40. // Enters next state. This is used when the state moves from one to another
  41. // within the same desktop mode. Uses `snap_ratio` for the next state type if
  42. // provided.
  43. void EnterToNextState(WindowState* window_state,
  44. chromeos::WindowStateType next_state_type,
  45. absl::optional<float> snap_ratio);
  46. // Reenters the current state. This is called when migrating from
  47. // previous desktop mode, and the window's state needs to re-construct the
  48. // state/bounds for this state.
  49. void ReenterToCurrentState(WindowState* window_state,
  50. WindowState::State* state_in_previous_mode);
  51. // Animates to new window bounds, using `snap_ratio` if provided, based on the
  52. // current and previous state type.
  53. void UpdateBoundsFromState(WindowState* window_state,
  54. chromeos::WindowStateType old_state_type,
  55. absl::optional<float> snap_ratio);
  56. // Updates the window bounds for display bounds, or display work area bounds
  57. // changes.
  58. // |ensure_full_window_visibility| - Whether the window bounds should be
  59. // adjusted so they fully fit within the display work area. If false, the
  60. // method will ensure minimum window visibility.
  61. void UpdateBoundsForDisplayOrWorkAreaBoundsChange(
  62. WindowState* window_state,
  63. bool ensure_full_window_visibility);
  64. // The saved window state for the case that the state gets de-/activated.
  65. gfx::Rect stored_bounds_;
  66. gfx::Rect stored_restore_bounds_;
  67. // The display state in which the mode got started.
  68. display::Display stored_display_state_;
  69. // The window state only gets remembered for DCHECK reasons.
  70. WindowState* stored_window_state_;
  71. };
  72. } // namespace ash
  73. #endif // ASH_WM_DEFAULT_STATE_H_