client_controlled_state.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // Copyright 2017 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_CLIENT_CONTROLLED_STATE_H_
  5. #define ASH_WM_CLIENT_CONTROLLED_STATE_H_
  6. #include <memory>
  7. #include "ash/ash_export.h"
  8. #include "ash/wm/base_state.h"
  9. #include "ash/wm/wm_event.h"
  10. #include "base/time/time.h"
  11. #include "ui/display/display.h"
  12. #include "ui/gfx/geometry/rect.h"
  13. namespace ash {
  14. // ClientControlledState delegates the window state transition and
  15. // bounds control to the client. Its window state and bounds are
  16. // determined by the delegate. ARC++ window's state is controlled by
  17. // Android framework, for example.
  18. class ASH_EXPORT ClientControlledState : public BaseState {
  19. public:
  20. class Delegate {
  21. public:
  22. virtual ~Delegate() = default;
  23. // Handles the state change of |window_state| to |requested_state|.
  24. // Delegate may decide to ignore the state change, proceed with the state
  25. // change, or can move to a different state.
  26. virtual void HandleWindowStateRequest(
  27. WindowState* window_state,
  28. chromeos::WindowStateType requested_state) = 0;
  29. // Handles the bounds change request for |window_state|. The bounds change
  30. // might come from a state change request |requested_state| (currently it
  31. // should only be a snapped window state). Delegate may choose to ignore the
  32. // request, set the given bounds, or set the different bounds.
  33. virtual void HandleBoundsRequest(
  34. WindowState* window_state,
  35. chromeos::WindowStateType requested_state,
  36. const gfx::Rect& requested_bounds_in_display,
  37. int64_t display_id) = 0;
  38. };
  39. // Adjust bounds to ensure window visibility, which is used for window added
  40. // to a new workspace.
  41. static void AdjustBoundsForMinimumWindowVisibility(
  42. const gfx::Rect& display_bounds,
  43. gfx::Rect* bounds);
  44. explicit ClientControlledState(std::unique_ptr<Delegate> delegate);
  45. ClientControlledState(const ClientControlledState&) = delete;
  46. ClientControlledState& operator=(const ClientControlledState&) = delete;
  47. ~ClientControlledState() override;
  48. // Resets |delegate_|.
  49. void ResetDelegate();
  50. // A flag used to update the window's bounds directly, instead of
  51. // delegating to |Delegate|. The Delegate should use this to
  52. // apply the bounds change to the window.
  53. void set_bounds_locally(bool set) { set_bounds_locally_ = set; }
  54. bool set_bounds_locally() const { return set_bounds_locally_; }
  55. // Sets the type of animation for the next bounds change
  56. // applied locally.
  57. void set_next_bounds_change_animation_type(
  58. WindowState::BoundsChangeAnimationType animation_type) {
  59. next_bounds_change_animation_type_ = animation_type;
  60. }
  61. // WindowState::State:
  62. void AttachState(WindowState* window_state,
  63. WindowState::State* previous_state) override;
  64. void DetachState(WindowState* window_state) override;
  65. #if DCHECK_IS_ON()
  66. void CheckMaximizableCondition(
  67. const WindowState* window_state) const override;
  68. #endif // DCHECK_IS_ON()
  69. // BaseState:
  70. void HandleWorkspaceEvents(WindowState* window_state,
  71. const WMEvent* event) override;
  72. void HandleCompoundEvents(WindowState* window_state,
  73. const WMEvent* event) override;
  74. void HandleBoundsEvents(WindowState* window_state,
  75. const WMEvent* event) override;
  76. void HandleTransitionEvents(WindowState* window_state,
  77. const WMEvent* event) override;
  78. void OnWindowDestroying(WindowState* window_state) override;
  79. // Enters next state. This is used when the state moves from one to another
  80. // within the same desktop mode. Returns true if the state has changed, or
  81. // false otherwise.
  82. bool EnterNextState(WindowState* window_state,
  83. chromeos::WindowStateType next_state_type);
  84. private:
  85. chromeos::WindowStateType GetResolvedNextWindowStateType(
  86. WindowState* window_state,
  87. const WMEvent* event);
  88. void UpdateWindowForTransitionEvents(
  89. WindowState* window_state,
  90. chromeos::WindowStateType next_state_type,
  91. WMEventType event_type);
  92. std::unique_ptr<Delegate> delegate_;
  93. bool set_bounds_locally_ = false;
  94. base::TimeDelta bounds_change_animation_duration_ =
  95. WindowState::kBoundsChangeSlideDuration;
  96. WindowState::BoundsChangeAnimationType next_bounds_change_animation_type_ =
  97. WindowState::BoundsChangeAnimationType::kNone;
  98. };
  99. } // namespace ash
  100. #endif // ASH_WM_CLIENT_CONTROLLED_STATE_H_