window_positioning_utils.h 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright 2016 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_WINDOW_POSITIONING_UTILS_H_
  5. #define ASH_WM_WINDOW_POSITIONING_UTILS_H_
  6. #include "ash/ash_export.h"
  7. #include "ash/display/screen_orientation_controller.h"
  8. namespace aura {
  9. class Window;
  10. }
  11. namespace display {
  12. class Display;
  13. }
  14. namespace gfx {
  15. class Rect;
  16. class Size;
  17. }
  18. namespace ash {
  19. // We force at least this many DIPs for any window on the screen.
  20. const int kMinimumOnScreenArea = 25;
  21. const float kDefaultSnapRatio = 0.5f;
  22. // In clamshell mode, users can snap left/right for horizontal display and
  23. // top/bottom for vertical display. For primary-landscape-oriented display,
  24. // |kPrimary| and |kSecondary| are left snap and right snap.
  25. // For other orientation see the table of description for
  26. // `SplitViewController::IsLayoutHorizontal()`.
  27. enum class SnapViewType { kPrimary, kSecondary };
  28. // Adjusts |bounds| so that the size does not exceed |max_size|.
  29. ASH_EXPORT void AdjustBoundsSmallerThan(const gfx::Size& max_size,
  30. gfx::Rect* bounds);
  31. // Move the given bounds inside the given |visible_area| in parent coordinates,
  32. // including a safety margin given by |min_width| and |min_height|.
  33. // This also ensures that the top of the bounds is visible.
  34. ASH_EXPORT void AdjustBoundsToEnsureWindowVisibility(
  35. const gfx::Rect& visible_area,
  36. int min_width,
  37. int min_height,
  38. gfx::Rect* bounds);
  39. // Move the given bounds inside the given |visible_area| in parent coordinates,
  40. // including a safety margin given by |kMinimumOnScreenArea|.
  41. // This also ensures that the top of the bounds is visible.
  42. ASH_EXPORT void AdjustBoundsToEnsureMinimumWindowVisibility(
  43. const gfx::Rect& visible_area,
  44. gfx::Rect* bounds);
  45. // Returns the bounds of a snapped window for a given snap |type| and
  46. // |snap_ratio| in clamshell mode.
  47. ASH_EXPORT gfx::Rect GetSnappedWindowBoundsInParent(aura::Window* window,
  48. SnapViewType type,
  49. float snap_ratio);
  50. // Returns the bounds of a snapped window with default snapped ratio
  51. // |kDefaultSnapRatio|, in parent coordinates.
  52. ASH_EXPORT gfx::Rect GetDefaultSnappedWindowBoundsInParent(aura::Window* window,
  53. SnapViewType type);
  54. // Returns the bounds of a snapped window for |display| with |type| and
  55. // |snap_ratio| in clamshell mode whatever coordinates are used for
  56. // |work_area|. Typically, |display| should be the target display window is
  57. // being dragged into.
  58. ASH_EXPORT gfx::Rect GetSnappedWindowBounds(const gfx::Rect& work_area,
  59. const display::Display display,
  60. aura::Window* window,
  61. SnapViewType type,
  62. float snap_ratio);
  63. // Returns the display orientation used for snapping windows in clamshell mode.
  64. // If vertical snap state is not enabled, returns primary-landscape
  65. // orientation. Otherwise, returns the current orientation relative to natural
  66. // orientation of this |display|.
  67. chromeos::OrientationType GetSnapDisplayOrientation(
  68. const display::Display& display);
  69. // Moves the window to the center of the display.
  70. ASH_EXPORT void CenterWindow(aura::Window* window);
  71. // Sets the bounds of |window| to |bounds_in_screen|. This may move |window|
  72. // to |display| if necessary.
  73. ASH_EXPORT void SetBoundsInScreen(aura::Window* window,
  74. const gfx::Rect& bounds_in_screen,
  75. const display::Display& display);
  76. } // namespace ash
  77. #endif // ASH_WM_WINDOW_POSITIONING_UTILS_H_