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

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: add docs 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
« no previous file with comments | « chrome/browser/ui/window_sizer.h ('k') | chrome/browser/ui/window_sizer_aura.cc » ('j') | 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 "base/compiler_specific.h"
7 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/prefs/pref_service.h" 9 #include "chrome/browser/prefs/pref_service.h"
9 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_list.h" 12 #include "chrome/browser/ui/browser_list.h"
12 #include "chrome/browser/ui/browser_window.h" 13 #include "chrome/browser/ui/browser_window.h"
13 #include "chrome/common/pref_names.h" 14 #include "chrome/common/pref_names.h"
15 #include "ui/gfx/screen.h"
16
17 // Minimum height of the visible part of a window.
18 const int kMinVisibleHeight = 30;
19 // Minimum width of the visible part of a window.
20 const int kMinVisibleWidth = 30;
21
22 class DefaultMonitorInfoProvider : public MonitorInfoProvider {
23 public:
24 // Overridden from MonitorInfoProvider:
25 virtual gfx::Rect GetPrimaryMonitorWorkArea() const OVERRIDE {
26 return gfx::Screen::GetPrimaryMonitorWorkArea();
27 }
28 virtual gfx::Rect GetPrimaryMonitorBounds() const OVERRIDE {
29 return gfx::Screen::GetPrimaryMonitorBounds();
30 }
31 virtual gfx::Rect GetMonitorWorkAreaMatching(
32 const gfx::Rect& match_rect) const OVERRIDE {
33 return gfx::Screen::GetMonitorWorkAreaMatching(match_rect);
34 }
35 };
14 36
15 /////////////////////////////////////////////////////////////////////////////// 37 ///////////////////////////////////////////////////////////////////////////////
16 // An implementation of WindowSizer::StateProvider that gets the last active 38 // An implementation of WindowSizer::StateProvider that gets the last active
17 // and persistent state from the browser window and the user's profile. 39 // and persistent state from the browser window and the user's profile.
18 class DefaultStateProvider : public WindowSizer::StateProvider { 40 class DefaultStateProvider : public WindowSizer::StateProvider {
19 public: 41 public:
20 DefaultStateProvider(const std::string& app_name, const Browser* browser) 42 DefaultStateProvider(const std::string& app_name, const Browser* browser)
21 : app_name_(app_name), browser_(browser) { 43 : app_name_(app_name), browser_(browser) {
22 } 44 }
23 45
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 std::string app_name_; 117 std::string app_name_;
96 118
97 // If set, is used as the reference browser for GetLastActiveWindowState. 119 // If set, is used as the reference browser for GetLastActiveWindowState.
98 const Browser* browser_; 120 const Browser* browser_;
99 DISALLOW_COPY_AND_ASSIGN(DefaultStateProvider); 121 DISALLOW_COPY_AND_ASSIGN(DefaultStateProvider);
100 }; 122 };
101 123
102 /////////////////////////////////////////////////////////////////////////////// 124 ///////////////////////////////////////////////////////////////////////////////
103 // WindowSizer, public: 125 // WindowSizer, public:
104 126
127 WindowSizer::WindowSizer(StateProvider* state_provider)
128 : state_provider_(state_provider),
129 monitor_info_provider_(new DefaultMonitorInfoProvider) {
130 }
131
105 WindowSizer::WindowSizer(StateProvider* state_provider, 132 WindowSizer::WindowSizer(StateProvider* state_provider,
106 MonitorInfoProvider* monitor_info_provider) 133 MonitorInfoProvider* monitor_info_provider)
107 : state_provider_(state_provider), 134 : state_provider_(state_provider),
108 monitor_info_provider_(monitor_info_provider) { 135 monitor_info_provider_(monitor_info_provider) {
109 } 136 }
110 137
111 WindowSizer::~WindowSizer() { 138 WindowSizer::~WindowSizer() {
112 } 139 }
113 140
114 // static 141 // static
115 void WindowSizer::GetBrowserWindowBounds(const std::string& app_name, 142 void WindowSizer::GetBrowserWindowBounds(const std::string& app_name,
116 const gfx::Rect& specified_bounds, 143 const gfx::Rect& specified_bounds,
117 const Browser* browser, 144 const Browser* browser,
118 gfx::Rect* window_bounds) { 145 gfx::Rect* window_bounds) {
119 const WindowSizer sizer(new DefaultStateProvider(app_name, browser), 146 const WindowSizer sizer(new DefaultStateProvider(app_name, browser));
120 CreateDefaultMonitorInfoProvider());
121 sizer.DetermineWindowBounds(specified_bounds, window_bounds); 147 sizer.DetermineWindowBounds(specified_bounds, window_bounds);
122 } 148 }
123 149
124 /////////////////////////////////////////////////////////////////////////////// 150 ///////////////////////////////////////////////////////////////////////////////
125 // WindowSizer, private: 151 // WindowSizer, private:
126 152
127 void WindowSizer::DetermineWindowBounds(const gfx::Rect& specified_bounds, 153 void WindowSizer::DetermineWindowBounds(const gfx::Rect& specified_bounds,
128 gfx::Rect* bounds) const { 154 gfx::Rect* bounds) const {
129 *bounds = specified_bounds; 155 *bounds = specified_bounds;
130 if (bounds->IsEmpty()) { 156 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 215 // The padding is set so that two windows, side by side have
190 // kWindowTilePixels between screen edge and each other. 216 // kWindowTilePixels between screen edge and each other.
191 default_width = static_cast<int>(work_area.width() / 2. - 217 default_width = static_cast<int>(work_area.width() / 2. -
192 1.5 * kWindowTilePixels); 218 1.5 * kWindowTilePixels);
193 } 219 }
194 default_bounds->SetRect(kWindowTilePixels + work_area.x(), 220 default_bounds->SetRect(kWindowTilePixels + work_area.x(),
195 kWindowTilePixels + work_area.y(), 221 kWindowTilePixels + work_area.y(),
196 default_width, default_height); 222 default_width, default_height);
197 } 223 }
198 224
199 bool WindowSizer::PositionIsOffscreen(int position, Edge edge) const {
200 DCHECK(monitor_info_provider_.get());
201 size_t monitor_count = monitor_info_provider_->GetMonitorCount();
202 for (size_t i = 0; i < monitor_count; ++i) {
203 gfx::Rect work_area = monitor_info_provider_->GetWorkAreaAt(i);
204 switch (edge) {
205 case TOP:
206 if (position >= work_area.y())
207 return false;
208 break;
209 case LEFT:
210 if (position >= work_area.x())
211 return false;
212 break;
213 case BOTTOM:
214 if (position <= work_area.bottom())
215 return false;
216 break;
217 case RIGHT:
218 if (position <= work_area.right())
219 return false;
220 break;
221 }
222 }
223 return true;
224 }
225
226 namespace {
227 // Minimum height of the visible part of a window.
228 static const int kMinVisibleHeight = 30;
229 // Minimum width of the visible part of a window.
230 static const int kMinVisibleWidth = 30;
231 }
232
233 void WindowSizer::AdjustBoundsToBeVisibleOnMonitorContaining( 225 void WindowSizer::AdjustBoundsToBeVisibleOnMonitorContaining(
234 const gfx::Rect& other_bounds, 226 const gfx::Rect& other_bounds,
235 const gfx::Rect& saved_work_area, 227 const gfx::Rect& saved_work_area,
236 gfx::Rect* bounds) const { 228 gfx::Rect* bounds) const {
237 DCHECK(bounds); 229 DCHECK(bounds);
238 DCHECK(monitor_info_provider_.get()); 230 DCHECK(monitor_info_provider_.get());
239 231
240 // Find the size of the work area of the monitor that intersects the bounds 232 // Find the size of the work area of the monitor that intersects the bounds
241 // of the anchor window. 233 // of the anchor window.
242 gfx::Rect work_area = 234 gfx::Rect work_area =
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 // On non-Mac platforms, we are less aggressive about repositioning. Simply 288 // On non-Mac platforms, we are less aggressive about repositioning. Simply
297 // ensure that at least kMinVisibleWidth * kMinVisibleHeight is visible. 289 // ensure that at least kMinVisibleWidth * kMinVisibleHeight is visible.
298 const int min_y = work_area.y() + kMinVisibleHeight - bounds->height(); 290 const int min_y = work_area.y() + kMinVisibleHeight - bounds->height();
299 const int min_x = work_area.x() + kMinVisibleWidth - bounds->width(); 291 const int min_x = work_area.x() + kMinVisibleWidth - bounds->width();
300 const int max_y = work_area.bottom() - kMinVisibleHeight; 292 const int max_y = work_area.bottom() - kMinVisibleHeight;
301 const int max_x = work_area.right() - kMinVisibleWidth; 293 const int max_x = work_area.right() - kMinVisibleWidth;
302 bounds->set_y(std::max(min_y, std::min(max_y, bounds->y()))); 294 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()))); 295 bounds->set_x(std::max(min_x, std::min(max_x, bounds->x())));
304 #endif // defined(OS_MACOSX) 296 #endif // defined(OS_MACOSX)
305 } 297 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/window_sizer.h ('k') | chrome/browser/ui/window_sizer_aura.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698