Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(486)

Side by Side Diff: chrome/browser/ui/window_sizer/window_sizer.h

Issue 11072002: Combined window positioning and show state determiniation in the WindowSizer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/ui/host_desktop.h" 10 #include "chrome/browser/ui/host_desktop.h"
11 #include "ui/base/ui_base_types.h"
11 #include "ui/gfx/rect.h" 12 #include "ui/gfx/rect.h"
12 13
13 class Browser; 14 class Browser;
14 15
15 // An interface implemented by an object that can retrieve information about 16 // An interface implemented by an object that can retrieve information about
16 // the monitors on the system. 17 // the monitors on the system.
17 class MonitorInfoProvider { 18 class MonitorInfoProvider {
18 public: 19 public:
19 virtual ~MonitorInfoProvider() {} 20 virtual ~MonitorInfoProvider() {}
20 21
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 virtual ~WindowSizer(); 59 virtual ~WindowSizer();
59 60
60 // An interface implemented by an object that can retrieve state from either a 61 // An interface implemented by an object that can retrieve state from either a
61 // persistent store or an existing window. 62 // persistent store or an existing window.
62 class StateProvider { 63 class StateProvider {
63 public: 64 public:
64 virtual ~StateProvider() {} 65 virtual ~StateProvider() {}
65 66
66 // Retrieve the persisted bounds of the window. Returns true if there was 67 // Retrieve the persisted bounds of the window. Returns true if there was
67 // persisted data to retrieve state information, false otherwise. 68 // persisted data to retrieve state information, false otherwise.
69 // The |show_state| variable will only be touched if there was persisted
sky 2012/10/05 22:54:03 Why constrain based on default? Shouldn't it alway
Mr4D (OOO till 08-26) 2012/10/06 01:10:10 This is part of the process. The default can enfor
sky 2012/10/08 15:25:17 Again, that should be up to the call site, right?
sky 2012/10/08 15:30:09 One more comment on this. I'm fine with internal m
Mr4D (OOO till 08-26) 2012/10/08 17:39:18 As discussed - there are no 'public' functions whi
70 // data and the |show_state| variable is SHOW_STATE_DEFAULT.
68 virtual bool GetPersistentState(gfx::Rect* bounds, 71 virtual bool GetPersistentState(gfx::Rect* bounds,
69 gfx::Rect* work_area) const = 0; 72 gfx::Rect* work_area,
73 ui::WindowShowState& show_state) const = 0;
sky 2012/10/05 22:54:03 Style guide says no references like this, you want
Mr4D (OOO till 08-26) 2012/10/06 01:10:10 Okay. I thought I have seen it being used somewher
sky 2012/10/08 15:25:17 Yes. A function can take references, but only if i
Mr4D (OOO till 08-26) 2012/10/08 17:39:18 I figured that after your first comment (somehow I
70 74
71 // Retrieve the bounds of the most recent window of the matching type. 75 // Retrieve the bounds of the most recent window of the matching type.
72 // Returns true if there was a last active window to retrieve state 76 // Returns true if there was a last active window to retrieve state
73 // information from, false otherwise. 77 // information from, false otherwise.
74 virtual bool GetLastActiveWindowState(gfx::Rect* bounds) const = 0; 78 // The |show_state| variable will only be touched if we have found a
79 // suitable window and the |show_state| variable is SHOW_STATE_DEFAULT.
80 virtual bool GetLastActiveWindowState(gfx::Rect* bounds,
sky 2012/10/05 22:54:03 wrap gfx::Rect* bounds to the next line so things
Mr4D (OOO till 08-26) 2012/10/06 01:10:10 Done.
81 ui::WindowShowState& show_state) const = 0;
75 }; 82 };
76 83
77 // Determines the position and size for a window as it is created. This 84 // Determines the position and size for a window as it is created as well
78 // function uses several strategies to figure out optimal size and placement, 85 // as the initial state. This function uses several strategies to figure out
79 // first looking for an existing active window, then falling back to persisted 86 // optimal size and placement, first looking for an existing active window,
80 // data from a previous session, finally utilizing a default 87 // then falling back to persisted data from a previous session, finally
81 // algorithm. If |specified_bounds| are non-empty, this value is returned 88 // utilizing a default algorithm. If |specified_bounds| are non-empty, this
82 // instead. For use only in testing. 89 // value is returned instead. For use only in testing.
83 void DetermineWindowBounds(const gfx::Rect& specified_bounds, 90 // |show_state| will be overwritten and return the initial visual state of
84 gfx::Rect* bounds) const; 91 // the window to use.
92 void DetermineWindowBoundsAndShowState(
93 const gfx::Rect& specified_bounds,
94 gfx::Rect* bounds,
95 ui::WindowShowState& show_state) const;
85 96
86 // Determines the size, position and maximized state for the browser window. 97 // Determines the size, position and maximized state for the browser window.
87 // See documentation for DetermineWindowBounds above. Normally, 98 // See documentation for DetermineWindowBounds above. Normally,
88 // |window_bounds| is calculated by calling GetLastActiveWindowState(). To 99 // |window_bounds| is calculated by calling GetLastActiveWindowState(). To
89 // explicitly specify a particular window to base the bounds on, pass in a 100 // explicitly specify a particular window to base the bounds on, pass in a
90 // non-NULL value for |browser|. 101 // non-NULL value for |browser|.
102 static void GetBrowserWindowBoundsAndShowState(
103 const std::string& app_name,
104 const gfx::Rect& specified_bounds,
105 const Browser* browser,
106 gfx::Rect* window_bounds,
107 ui::WindowShowState& show_state);
91 static void GetBrowserWindowBounds(const std::string& app_name, 108 static void GetBrowserWindowBounds(const std::string& app_name,
sky 2012/10/05 22:54:03 Can't we nuke this?
Mr4D (OOO till 08-26) 2012/10/06 01:10:10 Well - I thought that it is nicer to not have to p
92 const gfx::Rect& specified_bounds, 109 const gfx::Rect& specified_bounds,
93 const Browser* browser, 110 const Browser* browser,
94 gfx::Rect* window_bounds); 111 gfx::Rect* window_bounds);
95 112
96 // Returns the default origin for popups of the given size. 113 // Returns the default origin for popups of the given size.
97 static gfx::Point GetDefaultPopupOrigin(const gfx::Size& size, 114 static gfx::Point GetDefaultPopupOrigin(const gfx::Size& size,
98 chrome::HostDesktopType type); 115 chrome::HostDesktopType type);
99 116
100 // The number of pixels which are kept free top, left and right when a window 117 // The number of pixels which are kept free top, left and right when a window
101 // gets positioned to its default location. 118 // gets positioned to its default location.
102 static const int kDesktopBorderSize; 119 static const int kDesktopBorderSize;
103 120
104 // Maximum width of a window even if there is more room on the desktop. 121 // Maximum width of a window even if there is more room on the desktop.
105 static const int kMaximumWindowWidth; 122 static const int kMaximumWindowWidth;
106 123
107 // How much horizontal and vertical offset there is between newly 124 // How much horizontal and vertical offset there is between newly
108 // opened windows. This value may be different on each platform. 125 // opened windows. This value may be different on each platform.
109 static const int kWindowTilePixels; 126 static const int kWindowTilePixels;
110 127
111 private: 128 private:
112 // The edge of the screen to check for out-of-bounds. 129 // The edge of the screen to check for out-of-bounds.
113 enum Edge { TOP, LEFT, BOTTOM, RIGHT }; 130 enum Edge { TOP, LEFT, BOTTOM, RIGHT };
114 131
115 // Gets the size and placement of the last window. Returns true if this data 132 // Gets the size and placement of the last window. Returns true if this data
116 // is valid, false if there is no last window and the application should 133 // is valid, false if there is no last window and the application should
117 // restore saved state from preferences using RestoreWindowPosition. 134 // restore saved state from preferences using RestoreWindowPosition.
118 bool GetLastWindowBounds(gfx::Rect* bounds) const; 135 // |show_state| will only be changed if it was set to SHOW_STATE_DEFAULT.
136 bool GetLastWindowBounds(gfx::Rect* bounds,
137 ui::WindowShowState& show_state) const;
119 138
120 // Gets the size and placement of the last window in the last session, saved 139 // Gets the size and placement of the last window in the last session, saved
121 // in local state preferences. Returns true if local state exists containing 140 // in local state preferences. Returns true if local state exists containing
122 // this information, false if this information does not exist and a default 141 // this information, false if this information does not exist and a default
123 // size should be used. 142 // size should be used.
124 bool GetSavedWindowBounds(gfx::Rect* bounds) const; 143 // |show_state| will only be changed if it was set to SHOW_STATE_DEFAULT.
144 bool GetSavedWindowBounds(gfx::Rect* bounds,
145 ui::WindowShowState& show_state) const;
125 146
126 // Gets the default window position and size if there is no last window and 147 // Gets the default window position and size if there is no last window and
127 // no saved window placement in prefs. This function determines the default 148 // no saved window placement in prefs. This function determines the default
128 // size based on monitor size, etc. 149 // size based on monitor size, etc.
129 void GetDefaultWindowBounds(gfx::Rect* default_bounds) const; 150 void GetDefaultWindowBounds(gfx::Rect* default_bounds) const;
130 #if defined(USE_ASH) 151 #if defined(USE_ASH)
131 void GetDefaultWindowBoundsAsh(gfx::Rect* default_bounds) const; 152 void GetDefaultWindowBoundsAsh(gfx::Rect* default_bounds) const;
132 #endif 153 #endif
133 154
134 // Adjusts |bounds| to be visible on-screen, biased toward the work area of 155 // Adjusts |bounds| to be visible on-screen, biased toward the work area of
135 // the monitor containing |other_bounds|. Despite the name, this doesn't 156 // the monitor containing |other_bounds|. Despite the name, this doesn't
136 // guarantee the bounds are fully contained within this monitor's work rect; 157 // guarantee the bounds are fully contained within this monitor's work rect;
137 // it just tried to ensure the edges are visible on _some_ work rect. 158 // it just tried to ensure the edges are visible on _some_ work rect.
138 // If |saved_work_area| is non-empty, it is used to determine whether the 159 // If |saved_work_area| is non-empty, it is used to determine whether the
139 // monitor configuration has changed. If it has, bounds are repositioned and 160 // monitor configuration has changed. If it has, bounds are repositioned and
140 // resized if necessary to make them completely contained in the current work 161 // resized if necessary to make them completely contained in the current work
141 // area. 162 // area.
142 void AdjustBoundsToBeVisibleOnMonitorContaining( 163 void AdjustBoundsToBeVisibleOnMonitorContaining(
143 const gfx::Rect& other_bounds, 164 const gfx::Rect& other_bounds,
144 const gfx::Rect& saved_work_area, 165 const gfx::Rect& saved_work_area,
145 gfx::Rect* bounds) const; 166 gfx::Rect* bounds) const;
146 167
147 // Determines the position and size for a window as it gets created. This 168 // Determines the position and size for a window as it gets created. This
148 // will be called before DetermineWindowBounds. It will return true when the 169 // will be called before DetermineWindowBounds. It will return true when the
149 // function was setting the bounds structure to the desired size. Otherwise 170 // function was setting the bounds structure to the desired size. Otherwise
150 // another algorithm should get used to determine the correct bounds. 171 // another algorithm should get used to determine the correct bounds.
172 // |show_state| will only be changed if it was set to SHOW_STATE_DEFAULT.
151 bool GetBoundsOverride(const gfx::Rect& specified_bounds, 173 bool GetBoundsOverride(const gfx::Rect& specified_bounds,
152 gfx::Rect* bounds) const; 174 gfx::Rect* bounds,
175 ui::WindowShowState& show_state) const;
153 #if defined(USE_ASH) 176 #if defined(USE_ASH)
154 bool GetBoundsOverrideAsh(const gfx::Rect& specified_bounds, 177 bool GetBoundsOverrideAsh(const gfx::Rect& specified_bounds,
155 gfx::Rect* bounds_in_screen) const; 178 gfx::Rect* bounds_in_screen,
179 ui::WindowShowState& show_state) const;
156 #endif 180 #endif
157 181
182 // Determine the default show state for the window - not looking at other
183 // windows or at persistent information.
184 ui::WindowShowState GetWindowDefaultShowState() const;
185
158 // Providers for persistent storage and monitor metrics. 186 // Providers for persistent storage and monitor metrics.
159 scoped_ptr<StateProvider> state_provider_; 187 scoped_ptr<StateProvider> state_provider_;
160 scoped_ptr<MonitorInfoProvider> monitor_info_provider_; 188 scoped_ptr<MonitorInfoProvider> monitor_info_provider_;
161 189
162 // Note that this browser handle might be NULL. 190 // Note that this browser handle might be NULL.
163 const Browser* browser_; 191 const Browser* browser_;
164 192
165 DISALLOW_COPY_AND_ASSIGN(WindowSizer); 193 DISALLOW_COPY_AND_ASSIGN(WindowSizer);
166 }; 194 };
167 195
168 #endif // CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_H_ 196 #endif // CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698