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

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

Issue 8585035: Use scoped_ptr for memory management rather than calling delete through WindowSizer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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
« no previous file with comments | « chrome/browser/ui/window_sizer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "chrome/browser/ui/window_sizer.h" 5 #include "chrome/browser/ui/window_sizer.h"
6 6
7 #include "chrome/browser/browser_process.h" 7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/prefs/pref_service.h" 8 #include "chrome/browser/prefs/pref_service.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 std::string app_name_; 95 std::string app_name_;
96 96
97 // If set, is used as the reference browser for GetLastActiveWindowState. 97 // If set, is used as the reference browser for GetLastActiveWindowState.
98 const Browser* browser_; 98 const Browser* browser_;
99 DISALLOW_COPY_AND_ASSIGN(DefaultStateProvider); 99 DISALLOW_COPY_AND_ASSIGN(DefaultStateProvider);
100 }; 100 };
101 101
102 /////////////////////////////////////////////////////////////////////////////// 102 ///////////////////////////////////////////////////////////////////////////////
103 // WindowSizer, public: 103 // WindowSizer, public:
104 104
105 WindowSizer::WindowSizer( 105 WindowSizer::WindowSizer(StateProvider* state_provider,
106 StateProvider* state_provider, 106 MonitorInfoProvider* monitor_info_provider)
107 MonitorInfoProvider* monitor_info_provider)
108 : state_provider_(state_provider), 107 : state_provider_(state_provider),
109 monitor_info_provider_(monitor_info_provider) { 108 monitor_info_provider_(monitor_info_provider) {
110 } 109 }
111 110
112 WindowSizer::~WindowSizer() { 111 WindowSizer::~WindowSizer() {
113 if (state_provider_)
114 delete state_provider_;
115 if (monitor_info_provider_)
116 delete monitor_info_provider_;
117 } 112 }
118 113
119 // static 114 // static
120 void WindowSizer::GetBrowserWindowBounds(const std::string& app_name, 115 void WindowSizer::GetBrowserWindowBounds(const std::string& app_name,
121 const gfx::Rect& specified_bounds, 116 const gfx::Rect& specified_bounds,
122 const Browser* browser, 117 const Browser* browser,
123 gfx::Rect* window_bounds) { 118 gfx::Rect* window_bounds) {
124 const WindowSizer sizer(new DefaultStateProvider(app_name, browser), 119 const WindowSizer sizer(new DefaultStateProvider(app_name, browser),
125 CreateDefaultMonitorInfoProvider()); 120 CreateDefaultMonitorInfoProvider());
126 sizer.DetermineWindowBounds(specified_bounds, window_bounds); 121 sizer.DetermineWindowBounds(specified_bounds, window_bounds);
(...skipping 12 matching lines...) Expand all
139 // No saved placement, figure out some sensible default size based on 134 // No saved placement, figure out some sensible default size based on
140 // the user's screen size. 135 // the user's screen size.
141 GetDefaultWindowBounds(bounds); 136 GetDefaultWindowBounds(bounds);
142 } 137 }
143 } 138 }
144 } 139 }
145 } 140 }
146 141
147 bool WindowSizer::GetLastWindowBounds(gfx::Rect* bounds) const { 142 bool WindowSizer::GetLastWindowBounds(gfx::Rect* bounds) const {
148 DCHECK(bounds); 143 DCHECK(bounds);
149 if (!state_provider_ || !state_provider_->GetLastActiveWindowState(bounds)) 144 if (!state_provider_.get() ||
145 !state_provider_->GetLastActiveWindowState(bounds))
150 return false; 146 return false;
151 gfx::Rect last_window_bounds = *bounds; 147 gfx::Rect last_window_bounds = *bounds;
152 bounds->Offset(kWindowTilePixels, kWindowTilePixels); 148 bounds->Offset(kWindowTilePixels, kWindowTilePixels);
153 AdjustBoundsToBeVisibleOnMonitorContaining(last_window_bounds, 149 AdjustBoundsToBeVisibleOnMonitorContaining(last_window_bounds,
154 gfx::Rect(), 150 gfx::Rect(),
155 bounds); 151 bounds);
156 return true; 152 return true;
157 } 153 }
158 154
159 bool WindowSizer::GetSavedWindowBounds(gfx::Rect* bounds) const { 155 bool WindowSizer::GetSavedWindowBounds(gfx::Rect* bounds) const {
160 DCHECK(bounds); 156 DCHECK(bounds);
161 gfx::Rect saved_work_area; 157 gfx::Rect saved_work_area;
162 if (!state_provider_ || 158 if (!state_provider_.get() ||
163 !state_provider_->GetPersistentState(bounds, &saved_work_area)) 159 !state_provider_->GetPersistentState(bounds, &saved_work_area))
164 return false; 160 return false;
165 AdjustBoundsToBeVisibleOnMonitorContaining(*bounds, saved_work_area, bounds); 161 AdjustBoundsToBeVisibleOnMonitorContaining(*bounds, saved_work_area, bounds);
166 return true; 162 return true;
167 } 163 }
168 164
169 void WindowSizer::GetDefaultWindowBounds(gfx::Rect* default_bounds) const { 165 void WindowSizer::GetDefaultWindowBounds(gfx::Rect* default_bounds) const {
170 DCHECK(default_bounds); 166 DCHECK(default_bounds);
171 DCHECK(monitor_info_provider_); 167 DCHECK(monitor_info_provider_.get());
172 168
173 gfx::Rect work_area = monitor_info_provider_->GetPrimaryMonitorWorkArea(); 169 gfx::Rect work_area = monitor_info_provider_->GetPrimaryMonitorWorkArea();
174 170
175 // The default size is either some reasonably wide width, or if the work 171 // The default size is either some reasonably wide width, or if the work
176 // area is narrower, then the work area width less some aesthetic padding. 172 // area is narrower, then the work area width less some aesthetic padding.
177 int default_width = std::min(work_area.width() - 2 * kWindowTilePixels, 1050); 173 int default_width = std::min(work_area.width() - 2 * kWindowTilePixels, 1050);
178 int default_height = work_area.height() - 2 * kWindowTilePixels; 174 int default_height = work_area.height() - 2 * kWindowTilePixels;
179 175
180 // For wider aspect ratio displays at higher resolutions, we might size the 176 // For wider aspect ratio displays at higher resolutions, we might size the
181 // window narrower to allow two windows to easily be placed side-by-side. 177 // window narrower to allow two windows to easily be placed side-by-side.
(...skipping 12 matching lines...) Expand all
194 // kWindowTilePixels between screen edge and each other. 190 // kWindowTilePixels between screen edge and each other.
195 default_width = static_cast<int>(work_area.width() / 2. - 191 default_width = static_cast<int>(work_area.width() / 2. -
196 1.5 * kWindowTilePixels); 192 1.5 * kWindowTilePixels);
197 } 193 }
198 default_bounds->SetRect(kWindowTilePixels + work_area.x(), 194 default_bounds->SetRect(kWindowTilePixels + work_area.x(),
199 kWindowTilePixels + work_area.y(), 195 kWindowTilePixels + work_area.y(),
200 default_width, default_height); 196 default_width, default_height);
201 } 197 }
202 198
203 bool WindowSizer::PositionIsOffscreen(int position, Edge edge) const { 199 bool WindowSizer::PositionIsOffscreen(int position, Edge edge) const {
204 DCHECK(monitor_info_provider_); 200 DCHECK(monitor_info_provider_.get());
205 size_t monitor_count = monitor_info_provider_->GetMonitorCount(); 201 size_t monitor_count = monitor_info_provider_->GetMonitorCount();
206 for (size_t i = 0; i < monitor_count; ++i) { 202 for (size_t i = 0; i < monitor_count; ++i) {
207 gfx::Rect work_area = monitor_info_provider_->GetWorkAreaAt(i); 203 gfx::Rect work_area = monitor_info_provider_->GetWorkAreaAt(i);
208 switch (edge) { 204 switch (edge) {
209 case TOP: 205 case TOP:
210 if (position >= work_area.y()) 206 if (position >= work_area.y())
211 return false; 207 return false;
212 break; 208 break;
213 case LEFT: 209 case LEFT:
214 if (position >= work_area.x()) 210 if (position >= work_area.x())
(...skipping 17 matching lines...) Expand all
232 static const int kMinVisibleHeight = 30; 228 static const int kMinVisibleHeight = 30;
233 // Minimum width of the visible part of a window. 229 // Minimum width of the visible part of a window.
234 static const int kMinVisibleWidth = 30; 230 static const int kMinVisibleWidth = 30;
235 } 231 }
236 232
237 void WindowSizer::AdjustBoundsToBeVisibleOnMonitorContaining( 233 void WindowSizer::AdjustBoundsToBeVisibleOnMonitorContaining(
238 const gfx::Rect& other_bounds, 234 const gfx::Rect& other_bounds,
239 const gfx::Rect& saved_work_area, 235 const gfx::Rect& saved_work_area,
240 gfx::Rect* bounds) const { 236 gfx::Rect* bounds) const {
241 DCHECK(bounds); 237 DCHECK(bounds);
242 DCHECK(monitor_info_provider_); 238 DCHECK(monitor_info_provider_.get());
243 239
244 // Find the size of the work area of the monitor that intersects the bounds 240 // Find the size of the work area of the monitor that intersects the bounds
245 // of the anchor window. 241 // of the anchor window.
246 gfx::Rect work_area = 242 gfx::Rect work_area =
247 monitor_info_provider_->GetMonitorWorkAreaMatching(other_bounds); 243 monitor_info_provider_->GetMonitorWorkAreaMatching(other_bounds);
248 244
249 // If height or width are 0, reset to the default size. 245 // If height or width are 0, reset to the default size.
250 gfx::Rect default_bounds; 246 gfx::Rect default_bounds;
251 GetDefaultWindowBounds(&default_bounds); 247 GetDefaultWindowBounds(&default_bounds);
252 if (bounds->height() <= 0) 248 if (bounds->height() <= 0)
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 // On non-Mac platforms, we are less aggressive about repositioning. Simply 296 // On non-Mac platforms, we are less aggressive about repositioning. Simply
301 // ensure that at least kMinVisibleWidth * kMinVisibleHeight is visible. 297 // ensure that at least kMinVisibleWidth * kMinVisibleHeight is visible.
302 const int min_y = work_area.y() + kMinVisibleHeight - bounds->height(); 298 const int min_y = work_area.y() + kMinVisibleHeight - bounds->height();
303 const int min_x = work_area.x() + kMinVisibleWidth - bounds->width(); 299 const int min_x = work_area.x() + kMinVisibleWidth - bounds->width();
304 const int max_y = work_area.bottom() - kMinVisibleHeight; 300 const int max_y = work_area.bottom() - kMinVisibleHeight;
305 const int max_x = work_area.right() - kMinVisibleWidth; 301 const int max_x = work_area.right() - kMinVisibleWidth;
306 bounds->set_y(std::max(min_y, std::min(max_y, bounds->y()))); 302 bounds->set_y(std::max(min_y, std::min(max_y, bounds->y())));
307 bounds->set_x(std::max(min_x, std::min(max_x, bounds->x()))); 303 bounds->set_x(std::max(min_x, std::min(max_x, bounds->x())));
308 #endif // defined(OS_MACOSX) 304 #endif // defined(OS_MACOSX)
309 } 305 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/window_sizer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698