phantom_window_controller.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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
  3. // found in the LICENSE file.
  4. #ifndef ASH_WM_WORKSPACE_PHANTOM_WINDOW_CONTROLLER_H_
  5. #define ASH_WM_WORKSPACE_PHANTOM_WINDOW_CONTROLLER_H_
  6. #include <memory>
  7. #include "ash/ash_export.h"
  8. #include "ui/gfx/geometry/rect.h"
  9. namespace aura {
  10. class Window;
  11. }
  12. namespace views {
  13. class Widget;
  14. }
  15. namespace ash {
  16. // PhantomWindowController is responsible for showing a phantom representation
  17. // of a window. It's used to show a preview of how snapping or docking a window
  18. // will affect the window's bounds.
  19. class ASH_EXPORT PhantomWindowController {
  20. public:
  21. explicit PhantomWindowController(aura::Window* window);
  22. PhantomWindowController(const PhantomWindowController&) = delete;
  23. PhantomWindowController& operator=(const PhantomWindowController&) = delete;
  24. // Hides the phantom window without any animation.
  25. ~PhantomWindowController();
  26. // Shows the phantom window and animates expanding from
  27. // |kScrimStartBoundsRatio| of the full size to the full size which is
  28. // `snap_window_bounds_in_screen.Insets(kPhantomWindowInsets)`.
  29. void Show(const gfx::Rect& window_bounds_in_screen);
  30. void HideMaximizeCue();
  31. void ShowMaximizeCue();
  32. // Transforms the phantom widget from top-snapped to maximized phantom for
  33. // the target maximized window bounds |window_bounds_in_screen|.
  34. void TransformPhantomWidgetFromSnapTopToMaximize(
  35. const gfx::Rect& window_bounds_in_screen);
  36. // Returns the target snapped or maximized window bounds which is the phantom
  37. // bounds |target_bounds_in_screen_| with offsets |kPhantomWindowInsets|.
  38. gfx::Rect GetTargetWindowBounds() const;
  39. aura::Window* window() { return window_; }
  40. // Returns |maximize_cue_widget_|.
  41. views::Widget* GetMaximizeCueForTesting() const;
  42. private:
  43. // Creates, shows and returns a phantom widget at |bounds|
  44. // with kShellWindowId_ShelfContainer in |root_window| as a parent.
  45. std::unique_ptr<views::Widget> CreatePhantomWidget(
  46. aura::Window* root_window,
  47. const gfx::Rect& bounds_in_screen);
  48. // Creates and returns a maximize cue widget in
  49. // |kShellWindowId_OverlayContainer| in a given |root_window|.
  50. std::unique_ptr<views::Widget> CreateMaximizeCue(aura::Window* root_window);
  51. // Show phantom widget animating from the current widget size to
  52. // |target_bounds_in_screen| and animating to full opacity.
  53. void ShowPhantomWidget();
  54. // Window that the phantom window is stacked above.
  55. aura::Window* window_;
  56. // Target bounds of |phantom_widget_| in screen coordinates for animation.
  57. gfx::Rect target_bounds_in_screen_;
  58. // Phantom representation of the window.
  59. std::unique_ptr<views::Widget> phantom_widget_;
  60. // Maximize cue on top-snap phantom to inform users to hold longer if they
  61. // want to maximize instead of snap top.
  62. std::unique_ptr<views::Widget> maximize_cue_widget_;
  63. };
  64. } // namespace ash
  65. #endif // ASH_WM_WORKSPACE_PHANTOM_WINDOW_CONTROLLER_H_