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

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

Issue 8549008: Extract MonitorInfoProvider from WindowSizer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase 2 Created 9 years 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) 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"
11 #include "chrome/browser/ui/browser_list.h" 11 #include "chrome/browser/ui/browser_list.h"
12 #include "chrome/browser/ui/browser_window.h" 12 #include "chrome/browser/ui/browser_window.h"
13 #include "chrome/browser/ui/monitor_info_provider.h"
13 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
14 15
15 /////////////////////////////////////////////////////////////////////////////// 16 ///////////////////////////////////////////////////////////////////////////////
16 // An implementation of WindowSizer::StateProvider that gets the last active 17 // An implementation of WindowSizer::StateProvider that gets the last active
17 // and persistent state from the browser window and the user's profile. 18 // and persistent state from the browser window and the user's profile.
18 class DefaultStateProvider : public WindowSizer::StateProvider { 19 class DefaultStateProvider : public WindowSizer::StateProvider {
19 public: 20 public:
20 DefaultStateProvider(const std::string& app_name, const Browser* browser) 21 DefaultStateProvider(const std::string& app_name, const Browser* browser)
21 : app_name_(app_name), browser_(browser) { 22 : app_name_(app_name), browser_(browser) {
22 } 23 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 111
111 WindowSizer::~WindowSizer() { 112 WindowSizer::~WindowSizer() {
112 } 113 }
113 114
114 // static 115 // static
115 void WindowSizer::GetBrowserWindowBounds(const std::string& app_name, 116 void WindowSizer::GetBrowserWindowBounds(const std::string& app_name,
116 const gfx::Rect& specified_bounds, 117 const gfx::Rect& specified_bounds,
117 const Browser* browser, 118 const Browser* browser,
118 gfx::Rect* window_bounds) { 119 gfx::Rect* window_bounds) {
119 const WindowSizer sizer(new DefaultStateProvider(app_name, browser), 120 const WindowSizer sizer(new DefaultStateProvider(app_name, browser),
120 CreateDefaultMonitorInfoProvider()); 121 MonitorInfoProvider::Create());
121 sizer.DetermineWindowBounds(specified_bounds, window_bounds); 122 sizer.DetermineWindowBounds(specified_bounds, window_bounds);
122 } 123 }
123 124
124 /////////////////////////////////////////////////////////////////////////////// 125 ///////////////////////////////////////////////////////////////////////////////
125 // WindowSizer, private: 126 // WindowSizer, private:
126 127
127 void WindowSizer::DetermineWindowBounds(const gfx::Rect& specified_bounds, 128 void WindowSizer::DetermineWindowBounds(const gfx::Rect& specified_bounds,
128 gfx::Rect* bounds) const { 129 gfx::Rect* bounds) const {
129 *bounds = specified_bounds; 130 *bounds = specified_bounds;
130 if (bounds->IsEmpty()) { 131 if (bounds->IsEmpty()) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 // The padding is set so that two windows, side by side have 190 // The padding is set so that two windows, side by side have
190 // kWindowTilePixels between screen edge and each other. 191 // kWindowTilePixels between screen edge and each other.
191 default_width = static_cast<int>(work_area.width() / 2. - 192 default_width = static_cast<int>(work_area.width() / 2. -
192 1.5 * kWindowTilePixels); 193 1.5 * kWindowTilePixels);
193 } 194 }
194 default_bounds->SetRect(kWindowTilePixels + work_area.x(), 195 default_bounds->SetRect(kWindowTilePixels + work_area.x(),
195 kWindowTilePixels + work_area.y(), 196 kWindowTilePixels + work_area.y(),
196 default_width, default_height); 197 default_width, default_height);
197 } 198 }
198 199
199 bool WindowSizer::PositionIsOffscreen(int position, Edge edge) const { 200 bool WindowSizer::PositionIsOffscreen(int position, Edge edge) const {
Ben Goodger (Google) 2011/12/02 17:10:32 No one calls this function in Chrome. It can just
tfarina 2011/12/02 17:24:43 Removed.
200 DCHECK(monitor_info_provider_.get()); 201 DCHECK(monitor_info_provider_.get());
201 size_t monitor_count = monitor_info_provider_->GetMonitorCount(); 202 size_t monitor_count = monitor_info_provider_->GetMonitorCount();
202 for (size_t i = 0; i < monitor_count; ++i) { 203 for (size_t i = 0; i < monitor_count; ++i) {
203 gfx::Rect work_area = monitor_info_provider_->GetWorkAreaAt(i); 204 gfx::Rect work_area = monitor_info_provider_->GetWorkAreaAt(i);
204 switch (edge) { 205 switch (edge) {
205 case TOP: 206 case TOP:
206 if (position >= work_area.y()) 207 if (position >= work_area.y())
207 return false; 208 return false;
208 break; 209 break;
209 case LEFT: 210 case LEFT:
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 // On non-Mac platforms, we are less aggressive about repositioning. Simply 297 // On non-Mac platforms, we are less aggressive about repositioning. Simply
297 // ensure that at least kMinVisibleWidth * kMinVisibleHeight is visible. 298 // ensure that at least kMinVisibleWidth * kMinVisibleHeight is visible.
298 const int min_y = work_area.y() + kMinVisibleHeight - bounds->height(); 299 const int min_y = work_area.y() + kMinVisibleHeight - bounds->height();
299 const int min_x = work_area.x() + kMinVisibleWidth - bounds->width(); 300 const int min_x = work_area.x() + kMinVisibleWidth - bounds->width();
300 const int max_y = work_area.bottom() - kMinVisibleHeight; 301 const int max_y = work_area.bottom() - kMinVisibleHeight;
301 const int max_x = work_area.right() - kMinVisibleWidth; 302 const int max_x = work_area.right() - kMinVisibleWidth;
302 bounds->set_y(std::max(min_y, std::min(max_y, bounds->y()))); 303 bounds->set_y(std::max(min_y, std::min(max_y, bounds->y())));
303 bounds->set_x(std::max(min_x, std::min(max_x, bounds->x()))); 304 bounds->set_x(std::max(min_x, std::min(max_x, bounds->x())));
304 #endif // defined(OS_MACOSX) 305 #endif // defined(OS_MACOSX)
305 } 306 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698