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 
5 #ifndef UI_VIEWS_WINDOW_WINDOW_RESIZE_UTILS_H_
6 #define UI_VIEWS_WINDOW_WINDOW_RESIZE_UTILS_H_
7 
8 #include "base/macros.h"
9 #include "ui/views/views_export.h"
10 
11 namespace gfx {
12 class Size;
13 class Rect;
14 }  // namespace gfx
15 
16 namespace views {
17 
18 enum class HitTest {
19   kBottom,
20   kBottomLeft,
21   kBottomRight,
22   kLeft,
23   kRight,
24   kTop,
25   kTopLeft,
26   kTopRight
27 };
28 
29 class VIEWS_EXPORT WindowResizeUtils {
30  public:
31   // Force the min and max window sizes to adhere to the aspect ratio.
32   // |aspect_ratio| must be valid and is found using width / height.
33   static void SizeMinMaxToAspectRatio(float aspect_ratio,
34                                       gfx::Size* min_window_size,
35                                       gfx::Size* max_window_size);
36 
37   // Updates |rect| to adhere to the |aspect_ratio| of the window, if it has
38   // been set. |param| refers to the edge of the window being sized.
39   // |min_window_size| and |max_window_size| are expected to adhere to the
40   // given aspect ratio.
41   // |aspect_ratio| must be valid and is found using width / height.
42   // TODO(apacible): |max_window_size| is expected to be non-empty. Handle
43   // unconstrained max sizes and sizing when windows are maximized.
44   static void SizeRectToAspectRatio(HitTest param,
45                                     float aspect_ratio,
46                                     const gfx::Size& min_window_size,
47                                     const gfx::Size& max_window_size,
48                                     gfx::Rect* rect);
49 
50  private:
51   DISALLOW_IMPLICIT_CONSTRUCTORS(WindowResizeUtils);
52 };
53 
54 }  // namespace views
55 
56 #endif  // UI_VIEWS_WINDOW_WINDOW_RESIZE_UTILS_H_
57