OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_H_ | 5 #ifndef CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_H_ |
6 #define CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_H_ | 6 #define CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "ui/base/ui_base_types.h" | 11 #include "ui/base/ui_base_types.h" |
12 #include "ui/gfx/geometry/rect.h" | 12 #include "ui/gfx/geometry/rect.h" |
13 | 13 |
14 class Browser; | 14 class Browser; |
15 | 15 |
16 namespace gfx { | 16 namespace gfx { |
17 class Display; | 17 class Display; |
18 class Screen; | 18 class Screen; |
19 } | 19 } |
20 | 20 |
| 21 namespace display { |
| 22 using Display = gfx::Display; |
| 23 using Screen = gfx::Screen; |
| 24 } |
| 25 |
21 /////////////////////////////////////////////////////////////////////////////// | 26 /////////////////////////////////////////////////////////////////////////////// |
22 // WindowSizer | 27 // WindowSizer |
23 // | 28 // |
24 // A class that determines the best new size and position for a window to be | 29 // A class that determines the best new size and position for a window to be |
25 // shown at based several factors, including the position and size of the last | 30 // shown at based several factors, including the position and size of the last |
26 // window of the same type, the last saved bounds of the window from the | 31 // window of the same type, the last saved bounds of the window from the |
27 // previous session, and default system metrics if neither of the above two | 32 // previous session, and default system metrics if neither of the above two |
28 // conditions exist. The system has built-in providers for monitor metrics | 33 // conditions exist. The system has built-in providers for monitor metrics |
29 // and persistent storage (using preferences) but can be overrided with mocks | 34 // and persistent storage (using preferences) but can be overrided with mocks |
30 // for testing. | 35 // for testing. |
31 // | 36 // |
32 class WindowSizer { | 37 class WindowSizer { |
33 public: | 38 public: |
34 class StateProvider; | 39 class StateProvider; |
35 class TargetDisplayProvider; | 40 class TargetDisplayProvider; |
36 | 41 |
37 // WindowSizer owns |state_provider| and |target_display_provider|, | 42 // WindowSizer owns |state_provider| and |target_display_provider|, |
38 // and will use the platforms's gfx::Screen. | 43 // and will use the platforms's display::Screen. |
39 WindowSizer(std::unique_ptr<StateProvider> state_provider, | 44 WindowSizer(std::unique_ptr<StateProvider> state_provider, |
40 std::unique_ptr<TargetDisplayProvider> target_display_provider, | 45 std::unique_ptr<TargetDisplayProvider> target_display_provider, |
41 const Browser* browser); | 46 const Browser* browser); |
42 | 47 |
43 // WindowSizer owns |state_provider| and |target_display_provider|, | 48 // WindowSizer owns |state_provider| and |target_display_provider|, |
44 // and will use the supplied |screen|. Used only for testing. | 49 // and will use the supplied |screen|. Used only for testing. |
45 WindowSizer(std::unique_ptr<StateProvider> state_provider, | 50 WindowSizer(std::unique_ptr<StateProvider> state_provider, |
46 std::unique_ptr<TargetDisplayProvider> target_display_provider, | 51 std::unique_ptr<TargetDisplayProvider> target_display_provider, |
47 gfx::Screen* screen, | 52 display::Screen* screen, |
48 const Browser* browser); | 53 const Browser* browser); |
49 | 54 |
50 virtual ~WindowSizer(); | 55 virtual ~WindowSizer(); |
51 | 56 |
52 // An interface implemented by an object that can retrieve state from either a | 57 // An interface implemented by an object that can retrieve state from either a |
53 // persistent store or an existing window. | 58 // persistent store or an existing window. |
54 class StateProvider { | 59 class StateProvider { |
55 public: | 60 public: |
56 virtual ~StateProvider() {} | 61 virtual ~StateProvider() {} |
57 | 62 |
(...skipping 13 matching lines...) Expand all Loading... |
71 virtual bool GetLastActiveWindowState( | 76 virtual bool GetLastActiveWindowState( |
72 gfx::Rect* bounds, | 77 gfx::Rect* bounds, |
73 ui::WindowShowState* show_state) const = 0; | 78 ui::WindowShowState* show_state) const = 0; |
74 }; | 79 }; |
75 | 80 |
76 // An interface implemented by an object to identify on which | 81 // An interface implemented by an object to identify on which |
77 // display a new window should be located. | 82 // display a new window should be located. |
78 class TargetDisplayProvider { | 83 class TargetDisplayProvider { |
79 public: | 84 public: |
80 virtual ~TargetDisplayProvider() {} | 85 virtual ~TargetDisplayProvider() {} |
81 virtual gfx::Display GetTargetDisplay(const gfx::Screen* screen, | 86 virtual display::Display GetTargetDisplay( |
82 const gfx::Rect& bounds) const = 0; | 87 const display::Screen* screen, |
| 88 const gfx::Rect& bounds) const = 0; |
83 }; | 89 }; |
84 | 90 |
85 // Determines the position and size for a window as it is created as well | 91 // Determines the position and size for a window as it is created as well |
86 // as the initial state. This function uses several strategies to figure out | 92 // as the initial state. This function uses several strategies to figure out |
87 // optimal size and placement, first looking for an existing active window, | 93 // optimal size and placement, first looking for an existing active window, |
88 // then falling back to persisted data from a previous session, finally | 94 // then falling back to persisted data from a previous session, finally |
89 // utilizing a default algorithm. If |specified_bounds| are non-empty, this | 95 // utilizing a default algorithm. If |specified_bounds| are non-empty, this |
90 // value is returned instead. For use only in testing. | 96 // value is returned instead. For use only in testing. |
91 // |show_state| will be overwritten and return the initial visual state of | 97 // |show_state| will be overwritten and return the initial visual state of |
92 // the window to use. | 98 // the window to use. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 // this information, false if this information does not exist and a default | 136 // this information, false if this information does not exist and a default |
131 // size should be used. | 137 // size should be used. |
132 // |show_state| will only be changed if it was set to SHOW_STATE_DEFAULT. | 138 // |show_state| will only be changed if it was set to SHOW_STATE_DEFAULT. |
133 bool GetSavedWindowBounds(gfx::Rect* bounds, | 139 bool GetSavedWindowBounds(gfx::Rect* bounds, |
134 ui::WindowShowState* show_state) const; | 140 ui::WindowShowState* show_state) const; |
135 | 141 |
136 // Gets the default window position and size to be shown on | 142 // Gets the default window position and size to be shown on |
137 // |display| if there is no last window and no saved window | 143 // |display| if there is no last window and no saved window |
138 // placement in prefs. This function determines the default size | 144 // placement in prefs. This function determines the default size |
139 // based on monitor size, etc. | 145 // based on monitor size, etc. |
140 void GetDefaultWindowBounds(const gfx::Display& display, | 146 void GetDefaultWindowBounds(const display::Display& display, |
141 gfx::Rect* default_bounds) const; | 147 gfx::Rect* default_bounds) const; |
142 | 148 |
143 // Adjusts |bounds| to be visible on-screen, biased toward the work area of | 149 // Adjusts |bounds| to be visible on-screen, biased toward the work area of |
144 // the |display|. Despite the name, this doesn't | 150 // the |display|. Despite the name, this doesn't |
145 // guarantee the bounds are fully contained within this display's work rect; | 151 // guarantee the bounds are fully contained within this display's work rect; |
146 // it just tried to ensure the edges are visible on _some_ work rect. | 152 // it just tried to ensure the edges are visible on _some_ work rect. |
147 // If |saved_work_area| is non-empty, it is used to determine whether the | 153 // If |saved_work_area| is non-empty, it is used to determine whether the |
148 // monitor configuration has changed. If it has, bounds are repositioned and | 154 // monitor configuration has changed. If it has, bounds are repositioned and |
149 // resized if necessary to make them completely contained in the current work | 155 // resized if necessary to make them completely contained in the current work |
150 // area. | 156 // area. |
151 void AdjustBoundsToBeVisibleOnDisplay( | 157 void AdjustBoundsToBeVisibleOnDisplay(const display::Display& display, |
152 const gfx::Display& display, | 158 const gfx::Rect& saved_work_area, |
153 const gfx::Rect& saved_work_area, | 159 gfx::Rect* bounds) const; |
154 gfx::Rect* bounds) const; | |
155 | 160 |
156 // Determine the target display for a new window based on | 161 // Determine the target display for a new window based on |
157 // |bounds|. On ash environment, this returns the display containing | 162 // |bounds|. On ash environment, this returns the display containing |
158 // ash's the target root window. | 163 // ash's the target root window. |
159 gfx::Display GetTargetDisplay(const gfx::Rect& bounds) const; | 164 display::Display GetTargetDisplay(const gfx::Rect& bounds) const; |
160 | 165 |
161 #if defined(USE_ASH) | 166 #if defined(USE_ASH) |
162 // Ash specific logic for window placement. Returns true if |bounds| and | 167 // Ash specific logic for window placement. Returns true if |bounds| and |
163 // |show_state| have been fully determined, otherwise returns false (but | 168 // |show_state| have been fully determined, otherwise returns false (but |
164 // may still affect |show_state|). | 169 // may still affect |show_state|). |
165 // If the window is too big to fit in the display work area then the |bounds| | 170 // If the window is too big to fit in the display work area then the |bounds| |
166 // are adjusted to default bounds and the |show_state| is adjusted to | 171 // are adjusted to default bounds and the |show_state| is adjusted to |
167 // SHOW_STATE_MAXIMIZED. | 172 // SHOW_STATE_MAXIMIZED. |
168 bool GetBrowserBoundsAsh(gfx::Rect* bounds, | 173 bool GetBrowserBoundsAsh(gfx::Rect* bounds, |
169 ui::WindowShowState* show_state) const; | 174 ui::WindowShowState* show_state) const; |
170 | 175 |
171 // Determines the position and size for a tabbed browser window in | 176 // Determines the position and size for a tabbed browser window in |
172 // ash as it gets created. This will be called before other standard | 177 // ash as it gets created. This will be called before other standard |
173 // placement logic. |show_state| will only be changed | 178 // placement logic. |show_state| will only be changed |
174 // if it was set to SHOW_STATE_DEFAULT. | 179 // if it was set to SHOW_STATE_DEFAULT. |
175 void GetTabbedBrowserBoundsAsh(gfx::Rect* bounds, | 180 void GetTabbedBrowserBoundsAsh(gfx::Rect* bounds, |
176 ui::WindowShowState* show_state) const; | 181 ui::WindowShowState* show_state) const; |
177 #endif | 182 #endif |
178 | 183 |
179 // Determine the default show state for the window - not looking at other | 184 // Determine the default show state for the window - not looking at other |
180 // windows or at persistent information. | 185 // windows or at persistent information. |
181 ui::WindowShowState GetWindowDefaultShowState() const; | 186 ui::WindowShowState GetWindowDefaultShowState() const; |
182 | 187 |
183 // Providers for persistent storage and monitor metrics. | 188 // Providers for persistent storage and monitor metrics. |
184 std::unique_ptr<StateProvider> state_provider_; | 189 std::unique_ptr<StateProvider> state_provider_; |
185 std::unique_ptr<TargetDisplayProvider> target_display_provider_; | 190 std::unique_ptr<TargetDisplayProvider> target_display_provider_; |
186 gfx::Screen* screen_; // not owned. | 191 display::Screen* screen_; // not owned. |
187 | 192 |
188 // Note that this browser handle might be NULL. | 193 // Note that this browser handle might be NULL. |
189 const Browser* browser_; | 194 const Browser* browser_; |
190 | 195 |
191 DISALLOW_COPY_AND_ASSIGN(WindowSizer); | 196 DISALLOW_COPY_AND_ASSIGN(WindowSizer); |
192 }; | 197 }; |
193 | 198 |
194 #endif // CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_H_ | 199 #endif // CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_H_ |
OLD | NEW |