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

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

Issue 1920263003: Rename gfx::Display/Screen to display::Display/Screen in chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
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 #include "chrome/browser/ui/window_sizer/window_sizer.h" 5 #include "chrome/browser/ui/window_sizer/window_sizer.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_list.h" 16 #include "chrome/browser/ui/browser_list.h"
17 #include "chrome/browser/ui/browser_window.h" 17 #include "chrome/browser/ui/browser_window.h"
18 #include "chrome/browser/ui/browser_window_state.h" 18 #include "chrome/browser/ui/browser_window_state.h"
19 #include "chrome/common/chrome_switches.h" 19 #include "chrome/common/chrome_switches.h"
20 #include "components/prefs/pref_service.h" 20 #include "components/prefs/pref_service.h"
21 #include "ui/base/ui_base_switches.h" 21 #include "ui/base/ui_base_switches.h"
22 #include "ui/gfx/screen.h" 22 #include "ui/display/screen.h"
23 23
24 #if defined(USE_ASH) 24 #if defined(USE_ASH)
25 #include "ash/shell.h" 25 #include "ash/shell.h"
26 #include "ash/wm/common/window_positioner.h" 26 #include "ash/wm/common/window_positioner.h"
27 #include "chrome/browser/ui/ash/ash_util.h" 27 #include "chrome/browser/ui/ash/ash_util.h"
28 #endif 28 #endif
29 29
30 namespace { 30 namespace {
31 31
32 // Minimum height of the visible part of a window. 32 // Minimum height of the visible part of a window.
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 // If set, is used as the reference browser for GetLastActiveWindowState. 144 // If set, is used as the reference browser for GetLastActiveWindowState.
145 const Browser* browser_; 145 const Browser* browser_;
146 DISALLOW_COPY_AND_ASSIGN(DefaultStateProvider); 146 DISALLOW_COPY_AND_ASSIGN(DefaultStateProvider);
147 }; 147 };
148 148
149 class DefaultTargetDisplayProvider : public WindowSizer::TargetDisplayProvider { 149 class DefaultTargetDisplayProvider : public WindowSizer::TargetDisplayProvider {
150 public: 150 public:
151 DefaultTargetDisplayProvider() {} 151 DefaultTargetDisplayProvider() {}
152 ~DefaultTargetDisplayProvider() override {} 152 ~DefaultTargetDisplayProvider() override {}
153 153
154 gfx::Display GetTargetDisplay(const gfx::Screen* screen, 154 display::Display GetTargetDisplay(const display::Screen* screen,
155 const gfx::Rect& bounds) const override { 155 const gfx::Rect& bounds) const override {
156 #if defined(USE_ASH) 156 #if defined(USE_ASH)
157 // Use the target display on ash. 157 // Use the target display on ash.
158 if (chrome::ShouldOpenAshOnStartup()) { 158 if (chrome::ShouldOpenAshOnStartup()) {
159 aura::Window* target = ash::Shell::GetTargetRootWindow(); 159 aura::Window* target = ash::Shell::GetTargetRootWindow();
160 return screen->GetDisplayNearestWindow(target); 160 return screen->GetDisplayNearestWindow(target);
161 } 161 }
162 #endif 162 #endif
163 // Find the size of the work area of the monitor that intersects the bounds 163 // Find the size of the work area of the monitor that intersects the bounds
164 // of the anchor window. 164 // of the anchor window.
165 return screen->GetDisplayMatching(bounds); 165 return screen->GetDisplayMatching(bounds);
166 } 166 }
167 167
168 private: 168 private:
169 DISALLOW_COPY_AND_ASSIGN(DefaultTargetDisplayProvider); 169 DISALLOW_COPY_AND_ASSIGN(DefaultTargetDisplayProvider);
170 }; 170 };
171 171
172 } // namespace 172 } // namespace
173 173
174 /////////////////////////////////////////////////////////////////////////////// 174 ///////////////////////////////////////////////////////////////////////////////
175 // WindowSizer, public: 175 // WindowSizer, public:
176 176
177 WindowSizer::WindowSizer( 177 WindowSizer::WindowSizer(
178 std::unique_ptr<StateProvider> state_provider, 178 std::unique_ptr<StateProvider> state_provider,
179 std::unique_ptr<TargetDisplayProvider> target_display_provider, 179 std::unique_ptr<TargetDisplayProvider> target_display_provider,
180 const Browser* browser) 180 const Browser* browser)
181 : state_provider_(std::move(state_provider)), 181 : state_provider_(std::move(state_provider)),
182 target_display_provider_(std::move(target_display_provider)), 182 target_display_provider_(std::move(target_display_provider)),
183 screen_(gfx::Screen::GetScreen()), 183 screen_(display::Screen::GetScreen()),
184 browser_(browser) {} 184 browser_(browser) {}
185 185
186 WindowSizer::WindowSizer( 186 WindowSizer::WindowSizer(
187 std::unique_ptr<StateProvider> state_provider, 187 std::unique_ptr<StateProvider> state_provider,
188 std::unique_ptr<TargetDisplayProvider> target_display_provider, 188 std::unique_ptr<TargetDisplayProvider> target_display_provider,
189 gfx::Screen* screen, 189 display::Screen* screen,
190 const Browser* browser) 190 const Browser* browser)
191 : state_provider_(std::move(state_provider)), 191 : state_provider_(std::move(state_provider)),
192 target_display_provider_(std::move(target_display_provider)), 192 target_display_provider_(std::move(target_display_provider)),
193 screen_(screen), 193 screen_(screen),
194 browser_(browser) { 194 browser_(browser) {
195 DCHECK(screen_); 195 DCHECK(screen_);
196 } 196 }
197 197
198 WindowSizer::~WindowSizer() { 198 WindowSizer::~WindowSizer() {
199 } 199 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 !state_provider_->GetPersistentState(bounds, 285 !state_provider_->GetPersistentState(bounds,
286 &saved_work_area, 286 &saved_work_area,
287 show_state)) 287 show_state))
288 return false; 288 return false;
289 AdjustBoundsToBeVisibleOnDisplay(GetTargetDisplay(*bounds), 289 AdjustBoundsToBeVisibleOnDisplay(GetTargetDisplay(*bounds),
290 saved_work_area, 290 saved_work_area,
291 bounds); 291 bounds);
292 return true; 292 return true;
293 } 293 }
294 294
295 void WindowSizer::GetDefaultWindowBounds(const gfx::Display& display, 295 void WindowSizer::GetDefaultWindowBounds(const display::Display& display,
296 gfx::Rect* default_bounds) const { 296 gfx::Rect* default_bounds) const {
297 DCHECK(default_bounds); 297 DCHECK(default_bounds);
298 #if defined(USE_ASH) 298 #if defined(USE_ASH)
299 // TODO(beng): insufficient but currently necessary. http://crbug.com/133312 299 // TODO(beng): insufficient but currently necessary. http://crbug.com/133312
300 if (chrome::ShouldOpenAshOnStartup()) { 300 if (chrome::ShouldOpenAshOnStartup()) {
301 *default_bounds = ash::WindowPositioner::GetDefaultWindowBounds(display); 301 *default_bounds = ash::WindowPositioner::GetDefaultWindowBounds(display);
302 return; 302 return;
303 } 303 }
304 #endif 304 #endif
305 gfx::Rect work_area = display.work_area(); 305 gfx::Rect work_area = display.work_area();
(...skipping 20 matching lines...) Expand all
326 // kWindowTilePixels between screen edge and each other. 326 // kWindowTilePixels between screen edge and each other.
327 default_width = static_cast<int>(work_area.width() / 2. - 327 default_width = static_cast<int>(work_area.width() / 2. -
328 1.5 * kWindowTilePixels); 328 1.5 * kWindowTilePixels);
329 } 329 }
330 default_bounds->SetRect(kWindowTilePixels + work_area.x(), 330 default_bounds->SetRect(kWindowTilePixels + work_area.x(),
331 kWindowTilePixels + work_area.y(), 331 kWindowTilePixels + work_area.y(),
332 default_width, default_height); 332 default_width, default_height);
333 } 333 }
334 334
335 void WindowSizer::AdjustBoundsToBeVisibleOnDisplay( 335 void WindowSizer::AdjustBoundsToBeVisibleOnDisplay(
336 const gfx::Display& display, 336 const display::Display& display,
337 const gfx::Rect& saved_work_area, 337 const gfx::Rect& saved_work_area,
338 gfx::Rect* bounds) const { 338 gfx::Rect* bounds) const {
339 DCHECK(bounds); 339 DCHECK(bounds);
340 340
341 // If |bounds| is empty, reset to the default size. 341 // If |bounds| is empty, reset to the default size.
342 if (bounds->IsEmpty()) { 342 if (bounds->IsEmpty()) {
343 gfx::Rect default_bounds; 343 gfx::Rect default_bounds;
344 GetDefaultWindowBounds(display, &default_bounds); 344 GetDefaultWindowBounds(display, &default_bounds);
345 if (bounds->height() <= 0) 345 if (bounds->height() <= 0)
346 bounds->set_height(default_bounds.height()); 346 bounds->set_height(default_bounds.height());
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 // ensure that at least kMinVisibleWidth * kMinVisibleHeight is visible. 396 // ensure that at least kMinVisibleWidth * kMinVisibleHeight is visible.
397 const int min_y = work_area.y() + kMinVisibleHeight - bounds->height(); 397 const int min_y = work_area.y() + kMinVisibleHeight - bounds->height();
398 const int min_x = work_area.x() + kMinVisibleWidth - bounds->width(); 398 const int min_x = work_area.x() + kMinVisibleWidth - bounds->width();
399 const int max_y = work_area.bottom() - kMinVisibleHeight; 399 const int max_y = work_area.bottom() - kMinVisibleHeight;
400 const int max_x = work_area.right() - kMinVisibleWidth; 400 const int max_x = work_area.right() - kMinVisibleWidth;
401 bounds->set_y(std::max(min_y, std::min(max_y, bounds->y()))); 401 bounds->set_y(std::max(min_y, std::min(max_y, bounds->y())));
402 bounds->set_x(std::max(min_x, std::min(max_x, bounds->x()))); 402 bounds->set_x(std::max(min_x, std::min(max_x, bounds->x())));
403 #endif // defined(OS_MACOSX) 403 #endif // defined(OS_MACOSX)
404 } 404 }
405 405
406 gfx::Display WindowSizer::GetTargetDisplay(const gfx::Rect& bounds) const { 406 display::Display WindowSizer::GetTargetDisplay(const gfx::Rect& bounds) const {
407 return target_display_provider_->GetTargetDisplay(screen_, bounds); 407 return target_display_provider_->GetTargetDisplay(screen_, bounds);
408 } 408 }
409 409
410 ui::WindowShowState WindowSizer::GetWindowDefaultShowState() const { 410 ui::WindowShowState WindowSizer::GetWindowDefaultShowState() const {
411 if (!browser_) 411 if (!browser_)
412 return ui::SHOW_STATE_DEFAULT; 412 return ui::SHOW_STATE_DEFAULT;
413 413
414 // Only tabbed browsers use the command line or preference state, with the 414 // Only tabbed browsers use the command line or preference state, with the
415 // exception of devtools. 415 // exception of devtools.
416 bool show_state = !browser_->is_type_tabbed() && !browser_->is_devtools(); 416 bool show_state = !browser_->is_type_tabbed() && !browser_->is_devtools();
417 417
418 #if defined(USE_AURA) 418 #if defined(USE_AURA)
419 // We use the apps save state on aura. 419 // We use the apps save state on aura.
420 show_state &= !browser_->is_app(); 420 show_state &= !browser_->is_app();
421 #endif 421 #endif
422 422
423 if (show_state) 423 if (show_state)
424 return browser_->initial_show_state(); 424 return browser_->initial_show_state();
425 425
426 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 426 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
427 switches::kStartMaximized)) 427 switches::kStartMaximized))
428 return ui::SHOW_STATE_MAXIMIZED; 428 return ui::SHOW_STATE_MAXIMIZED;
429 429
430 if (browser_->initial_show_state() != ui::SHOW_STATE_DEFAULT) 430 if (browser_->initial_show_state() != ui::SHOW_STATE_DEFAULT)
431 return browser_->initial_show_state(); 431 return browser_->initial_show_state();
432 432
433 // Otherwise we use the default which can be overridden later on. 433 // Otherwise we use the default which can be overridden later on.
434 return ui::SHOW_STATE_DEFAULT; 434 return ui::SHOW_STATE_DEFAULT;
435 } 435 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/window_sizer/window_sizer.h ('k') | chrome/browser/ui/window_sizer/window_sizer_ash.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698