Commit 82abbf60 authored by James Cook's avatar James Cook Committed by Commit Bot

Refactor Chrome OS code out of cross-platform WindowSizer

The class had methods like GetDefaultWindowBoundsChromeOS() wrapped in
ifdef checks, with implementations in a different file.

Introduce a real subclass WindowSizerChromeOS. Move helper functions
there.

Bug: 846736, 1109050
Test: existing unit_tests
Change-Id: Ibf38eafe7955d086edcec653db4d2d17d5cfbc5c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2321946
Commit-Queue: James Cook <jamescook@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792446}
parent 60c1196a
...@@ -2419,6 +2419,7 @@ static_library("ui") { ...@@ -2419,6 +2419,7 @@ static_library("ui") {
"webui/version_handler_chromeos.cc", "webui/version_handler_chromeos.cc",
"webui/version_handler_chromeos.h", "webui/version_handler_chromeos.h",
"window_sizer/window_sizer_chromeos.cc", "window_sizer/window_sizer_chromeos.cc",
"window_sizer/window_sizer_chromeos.h",
] ]
deps += [ deps += [
......
...@@ -23,6 +23,10 @@ ...@@ -23,6 +23,10 @@
#include "ui/display/display.h" #include "ui/display/display.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/ui/window_sizer/window_sizer_chromeos.h"
#endif
namespace { namespace {
// Minimum height of the visible part of a window. // Minimum height of the visible part of a window.
...@@ -133,9 +137,6 @@ class DefaultStateProvider : public WindowSizer::StateProvider { ...@@ -133,9 +137,6 @@ class DefaultStateProvider : public WindowSizer::StateProvider {
} // namespace } // namespace
///////////////////////////////////////////////////////////////////////////////
// WindowSizer, public:
WindowSizer::WindowSizer(std::unique_ptr<StateProvider> state_provider, WindowSizer::WindowSizer(std::unique_ptr<StateProvider> state_provider,
const Browser* browser) const Browser* browser)
: state_provider_(std::move(state_provider)), browser_(browser) {} : state_provider_(std::move(state_provider)), browser_(browser) {}
...@@ -148,32 +149,35 @@ void WindowSizer::GetBrowserWindowBoundsAndShowState( ...@@ -148,32 +149,35 @@ void WindowSizer::GetBrowserWindowBoundsAndShowState(
const Browser* browser, const Browser* browser,
gfx::Rect* window_bounds, gfx::Rect* window_bounds,
ui::WindowShowState* show_state) { ui::WindowShowState* show_state) {
auto state_provider = std::make_unique<DefaultStateProvider>(browser); return GetBrowserWindowBoundsAndShowState(
const WindowSizer sizer(std::move(state_provider), browser); std::make_unique<DefaultStateProvider>(browser), specified_bounds,
sizer.DetermineWindowBoundsAndShowState(specified_bounds, browser, window_bounds, show_state);
window_bounds,
show_state);
} }
/////////////////////////////////////////////////////////////////////////////// // static
// WindowSizer, private: void WindowSizer::GetBrowserWindowBoundsAndShowState(
std::unique_ptr<StateProvider> state_provider,
void WindowSizer::DetermineWindowBoundsAndShowState(
const gfx::Rect& specified_bounds, const gfx::Rect& specified_bounds,
const Browser* browser,
gfx::Rect* bounds, gfx::Rect* bounds,
ui::WindowShowState* show_state) const { ui::WindowShowState* show_state) {
DCHECK(bounds); DCHECK(bounds);
DCHECK(show_state); DCHECK(show_state);
// Pre-populate the window state with our default.
*show_state = GetWindowDefaultShowState();
*bounds = specified_bounds;
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
// Check for custom window placement for Chrome OS. WindowSizerChromeOS sizer(std::move(state_provider), browser);
if (GetBrowserBoundsChromeOS(bounds, show_state)) #else
return; WindowSizer sizer(std::move(state_provider), browser);
#endif #endif
// Pre-populate the window state with our default.
*show_state = GetWindowDefaultShowState(browser);
*bounds = specified_bounds;
sizer.DetermineWindowBoundsAndShowState(specified_bounds, bounds, show_state);
}
void WindowSizer::DetermineWindowBoundsAndShowState(
const gfx::Rect& specified_bounds,
gfx::Rect* bounds,
ui::WindowShowState* show_state) {
if (bounds->IsEmpty()) { if (bounds->IsEmpty()) {
// See if there's last active window's placement information. // See if there's last active window's placement information.
if (GetLastActiveWindowBounds(bounds, show_state)) if (GetLastActiveWindowBounds(bounds, show_state))
...@@ -184,7 +188,7 @@ void WindowSizer::DetermineWindowBoundsAndShowState( ...@@ -184,7 +188,7 @@ void WindowSizer::DetermineWindowBoundsAndShowState(
// No saved placement, figure out some sensible default size based on // No saved placement, figure out some sensible default size based on
// the user's screen size. // the user's screen size.
GetDefaultWindowBounds(GetDisplayForNewWindow(), bounds); *bounds = GetDefaultWindowBounds(GetDisplayForNewWindow());
return; return;
} }
...@@ -230,12 +234,8 @@ bool WindowSizer::GetSavedWindowBounds(gfx::Rect* bounds, ...@@ -230,12 +234,8 @@ bool WindowSizer::GetSavedWindowBounds(gfx::Rect* bounds,
return true; return true;
} }
void WindowSizer::GetDefaultWindowBounds(const display::Display& display, gfx::Rect WindowSizer::GetDefaultWindowBounds(
gfx::Rect* default_bounds) const { const display::Display& display) const {
DCHECK(default_bounds);
#if defined(OS_CHROMEOS)
*default_bounds = GetDefaultWindowBoundsChromeOS(browser_, display);
#else
gfx::Rect work_area = display.work_area(); gfx::Rect work_area = display.work_area();
// The default size is either some reasonably wide width, or if the work // The default size is either some reasonably wide width, or if the work
...@@ -265,10 +265,9 @@ void WindowSizer::GetDefaultWindowBounds(const display::Display& display, ...@@ -265,10 +265,9 @@ void WindowSizer::GetDefaultWindowBounds(const display::Display& display,
1.5 * kWindowTilePixels); 1.5 * kWindowTilePixels);
} }
#endif // !defined(OS_MACOSX) #endif // !defined(OS_MACOSX)
default_bounds->SetRect(kWindowTilePixels + work_area.x(), return gfx::Rect(kWindowTilePixels + work_area.x(),
kWindowTilePixels + work_area.y(), kWindowTilePixels + work_area.y(), default_width,
default_width, default_height); default_height);
#endif
} }
void WindowSizer::AdjustBoundsToBeVisibleOnDisplay( void WindowSizer::AdjustBoundsToBeVisibleOnDisplay(
...@@ -279,8 +278,7 @@ void WindowSizer::AdjustBoundsToBeVisibleOnDisplay( ...@@ -279,8 +278,7 @@ void WindowSizer::AdjustBoundsToBeVisibleOnDisplay(
// If |bounds| is empty, reset to the default size. // If |bounds| is empty, reset to the default size.
if (bounds->IsEmpty()) { if (bounds->IsEmpty()) {
gfx::Rect default_bounds; gfx::Rect default_bounds = GetDefaultWindowBounds(display);
GetDefaultWindowBounds(display, &default_bounds);
if (bounds->height() <= 0) if (bounds->height() <= 0)
bounds->set_height(default_bounds.height()); bounds->set_height(default_bounds.height());
if (bounds->width() <= 0) if (bounds->width() <= 0)
...@@ -340,17 +338,19 @@ void WindowSizer::AdjustBoundsToBeVisibleOnDisplay( ...@@ -340,17 +338,19 @@ void WindowSizer::AdjustBoundsToBeVisibleOnDisplay(
#endif // defined(OS_MACOSX) #endif // defined(OS_MACOSX)
} }
ui::WindowShowState WindowSizer::GetWindowDefaultShowState() const { // static
if (!browser_) ui::WindowShowState WindowSizer::GetWindowDefaultShowState(
const Browser* browser) {
if (!browser)
return ui::SHOW_STATE_DEFAULT; return ui::SHOW_STATE_DEFAULT;
// Only tabbed browsers and dev tools use the command line. // Only tabbed browsers and dev tools use the command line.
bool use_command_line = bool use_command_line =
browser_->is_type_normal() || browser_->is_type_devtools(); browser->is_type_normal() || browser->is_type_devtools();
#if defined(USE_AURA) #if defined(USE_AURA)
// We use the apps save state as well on aura. // We use the apps save state as well on aura.
use_command_line = use_command_line || browser_->deprecated_is_app(); use_command_line = use_command_line || browser->deprecated_is_app();
#endif #endif
if (use_command_line && base::CommandLine::ForCurrentProcess()->HasSwitch( if (use_command_line && base::CommandLine::ForCurrentProcess()->HasSwitch(
...@@ -358,7 +358,7 @@ ui::WindowShowState WindowSizer::GetWindowDefaultShowState() const { ...@@ -358,7 +358,7 @@ ui::WindowShowState WindowSizer::GetWindowDefaultShowState() const {
return ui::SHOW_STATE_MAXIMIZED; return ui::SHOW_STATE_MAXIMIZED;
} }
return browser_->initial_show_state(); return browser->initial_show_state();
} }
// static // static
......
...@@ -61,20 +61,20 @@ class WindowSizer { ...@@ -61,20 +61,20 @@ class WindowSizer {
// optimal size and placement, first looking for an existing active window, // optimal size and placement, first looking for an existing active window,
// then falling back to persisted data from a previous session, finally // then falling back to persisted data from a previous session, finally
// utilizing a default algorithm. If |specified_bounds| are non-empty, this // utilizing a default algorithm. If |specified_bounds| are non-empty, this
// value is returned instead. For use only in testing. // value is returned instead. To explicitly specify a particular window to
// base the bounds on, pass in a non-null value for |browser|.
//
// |show_state| will be overwritten and return the initial visual state of // |show_state| will be overwritten and return the initial visual state of
// the window to use. // the window to use.
void DetermineWindowBoundsAndShowState( static void GetBrowserWindowBoundsAndShowState(
const gfx::Rect& specified_bounds, const gfx::Rect& specified_bounds,
gfx::Rect* bounds, const Browser* browser,
ui::WindowShowState* show_state) const; gfx::Rect* window_bounds,
ui::WindowShowState* show_state);
// Determines the size, position and maximized state for the browser window. // As above, but takes a state provider for testing.
// See documentation for DetermineWindowBoundsAndShowState above. Normally,
// |window_bounds| is calculated by calling GetLastActiveWindowState(). To
// explicitly specify a particular window to base the bounds on, pass in a
// non-NULL value for |browser|.
static void GetBrowserWindowBoundsAndShowState( static void GetBrowserWindowBoundsAndShowState(
std::unique_ptr<StateProvider> state_provider,
const gfx::Rect& specified_bounds, const gfx::Rect& specified_bounds,
const Browser* browser, const Browser* browser,
gfx::Rect* window_bounds, gfx::Rect* window_bounds,
...@@ -90,28 +90,21 @@ class WindowSizer { ...@@ -90,28 +90,21 @@ class WindowSizer {
// The maximum default window width. This value may differ between platforms. // The maximum default window width. This value may differ between platforms.
static const int kWindowMaxDefaultWidth; static const int kWindowMaxDefaultWidth;
#if defined(OS_CHROMEOS)
// The number of pixels which are kept free top, left and right when a window
// gets positioned to its default location.
static const int kDesktopBorderSize = 16;
// Maximum width of a window even if there is more room on the desktop.
static const int kMaximumWindowWidth = 1100;
#endif
protected: protected:
const StateProvider* state_provider() const { return state_provider_.get(); } const StateProvider* state_provider() const { return state_provider_.get(); }
const Browser* browser() const { return browser_; }
private: // WindowSizer will use the platform's display::Screen.
friend class WindowSizerChromeOSTest;
friend class WindowSizerTestUtil;
// WindowSizer will use the platforms's display::Screen.
WindowSizer(std::unique_ptr<StateProvider> state_provider, WindowSizer(std::unique_ptr<StateProvider> state_provider,
const Browser* browser); const Browser* browser);
virtual ~WindowSizer(); virtual ~WindowSizer();
// See GetBrowserWindowBoundsAndShowState() above.
virtual void DetermineWindowBoundsAndShowState(
const gfx::Rect& specified_bounds,
gfx::Rect* bounds,
ui::WindowShowState* show_state);
// Gets the size and placement of the last active window. Returns true if this // Gets the size and placement of the last active window. Returns true if this
// data is valid, false if there is no last window and the application should // data is valid, false if there is no last window and the application should
// restore saved state from preferences using RestoreWindowPosition. // restore saved state from preferences using RestoreWindowPosition.
...@@ -131,8 +124,8 @@ class WindowSizer { ...@@ -131,8 +124,8 @@ class WindowSizer {
// |display| if there is no last window and no saved window // |display| if there is no last window and no saved window
// placement in prefs. This function determines the default size // placement in prefs. This function determines the default size
// based on monitor size, etc. // based on monitor size, etc.
void GetDefaultWindowBounds(const display::Display& display, virtual gfx::Rect GetDefaultWindowBounds(
gfx::Rect* default_bounds) const; const display::Display& display) const;
// Adjusts |bounds| to be visible on-screen, biased toward the work area of // Adjusts |bounds| to be visible on-screen, biased toward the work area of
// the |display|. Despite the name, this doesn't // the |display|. Despite the name, this doesn't
...@@ -146,38 +139,18 @@ class WindowSizer { ...@@ -146,38 +139,18 @@ class WindowSizer {
const gfx::Rect& saved_work_area, const gfx::Rect& saved_work_area,
gfx::Rect* bounds) const; gfx::Rect* bounds) const;
#if defined(OS_CHROMEOS)
// Chrome OS specific logic for window placement. Returns true if |bounds| and
// |show_state| have been fully determined, otherwise returns false (but
// may still affect |show_state|).
// If the window is too big to fit in the display work area then the |bounds|
// are adjusted to default bounds and the |show_state| is adjusted to
// SHOW_STATE_MAXIMIZED.
bool GetBrowserBoundsChromeOS(gfx::Rect* bounds,
ui::WindowShowState* show_state) const;
// Determines the position and size for a tabbed browser window in
// ash as it gets created. This will be called before other standard
// placement logic. |show_state| will only be changed
// if it was set to SHOW_STATE_DEFAULT.
void GetTabbedBrowserBoundsChromeOS(gfx::Rect* bounds,
ui::WindowShowState* show_state) const;
// Returns the default bounds for a |browser| window on |display|.
static gfx::Rect GetDefaultWindowBoundsChromeOS(
const Browser* browser,
const display::Display& display);
#endif
// Determine the default show state for the window - not looking at other // Determine the default show state for the window - not looking at other
// windows or at persistent information. // windows or at persistent information.
ui::WindowShowState GetWindowDefaultShowState() const; static ui::WindowShowState GetWindowDefaultShowState(const Browser* browser);
// Returns the target display for a new window with |bounds| in screen // Returns the target display for a new window with |bounds| in screen
// coordinates. // coordinates.
static display::Display GetDisplayForNewWindow( static display::Display GetDisplayForNewWindow(
const gfx::Rect& bounds = gfx::Rect()); const gfx::Rect& bounds = gfx::Rect());
private:
friend class WindowSizerTestUtil;
// Providers for persistent storage and monitor metrics. // Providers for persistent storage and monitor metrics.
std::unique_ptr<StateProvider> state_provider_; std::unique_ptr<StateProvider> state_provider_;
......
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/ui/window_sizer/window_sizer.h" #include "chrome/browser/ui/window_sizer/window_sizer_chromeos.h"
#include <utility>
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -37,61 +39,108 @@ bool ShouldForceMaximizeOnFirstRun() { ...@@ -37,61 +39,108 @@ bool ShouldForceMaximizeOnFirstRun() {
} // namespace } // namespace
bool WindowSizer::GetBrowserBoundsChromeOS( WindowSizerChromeOS::WindowSizerChromeOS(
std::unique_ptr<StateProvider> state_provider,
const Browser* browser)
: WindowSizer(std::move(state_provider), browser) {}
WindowSizerChromeOS::~WindowSizerChromeOS() = default;
void WindowSizerChromeOS::DetermineWindowBoundsAndShowState(
const gfx::Rect& specified_bounds,
gfx::Rect* bounds,
ui::WindowShowState* show_state) {
// If we got *both* the bounds and show state, we're done.
if (GetBrowserBounds(bounds, show_state))
return;
// Fall back to cross-platform behavior. Note that |show_state| may have been
// changed by the function above.
WindowSizer::DetermineWindowBoundsAndShowState(specified_bounds, bounds,
show_state);
}
gfx::Rect WindowSizerChromeOS::GetDefaultWindowBounds(
const display::Display& display) const {
// Let apps set their own default.
if (browser() && browser()->app_controller()) {
gfx::Rect bounds = browser()->app_controller()->GetDefaultBounds();
if (!bounds.IsEmpty())
return bounds;
}
const gfx::Rect work_area = display.work_area();
// There should be a 'desktop' border around the window at the left and right
// side.
int default_width = work_area.width() - 2 * kDesktopBorderSize;
// There should also be a 'desktop' border around the window at the top.
// Since the workspace excludes the tray area we only need one border size.
int default_height = work_area.height() - kDesktopBorderSize;
int offset_x = kDesktopBorderSize;
if (default_width > kMaximumWindowWidth) {
// The window should get centered on the screen and not follow the grid.
offset_x = (work_area.width() - kMaximumWindowWidth) / 2;
default_width = kMaximumWindowWidth;
}
return gfx::Rect(work_area.x() + offset_x, work_area.y() + kDesktopBorderSize,
default_width, default_height);
}
bool WindowSizerChromeOS::GetBrowserBounds(
gfx::Rect* bounds, gfx::Rect* bounds,
ui::WindowShowState* show_state) const { ui::WindowShowState* show_state) const {
if (!browser_) if (!browser())
return false; return false;
// This should not be called on a Browser that already has a window. // This should not be called on a Browser that already has a window.
DCHECK(!browser_->window()); DCHECK(!browser()->window());
bool determined = false; bool determined = false;
if (bounds->IsEmpty()) { if (bounds->IsEmpty()) {
if (browser_->is_type_normal()) { if (browser()->is_type_normal()) {
GetTabbedBrowserBoundsChromeOS(bounds, show_state); GetTabbedBrowserBounds(bounds, show_state);
determined = true; determined = true;
} else if (browser_->is_trusted_source()) { } else if (browser()->is_trusted_source()) {
// For trusted popups (v1 apps and system windows), do not use the last // For trusted popups (v1 apps and system windows), do not use the last
// active window bounds, only use saved or default bounds. // active window bounds, only use saved or default bounds.
if (!GetSavedWindowBounds(bounds, show_state)) { if (!GetSavedWindowBounds(bounds, show_state))
*bounds = *bounds = GetDefaultWindowBounds(GetDisplayForNewWindow());
GetDefaultWindowBoundsChromeOS(browser_, GetDisplayForNewWindow());
}
determined = true; determined = true;
} else if (state_provider_) { } else if (state_provider()) {
// Finally, prioritize the last saved |show_state|. If you have questions // Finally, prioritize the last saved |show_state|. If you have questions
// or comments about this behavior please contact oshima@chromium.org. // or comments about this behavior please contact oshima@chromium.org.
gfx::Rect ignored_bounds, ignored_work_area; gfx::Rect ignored_bounds, ignored_work_area;
state_provider_->GetPersistentState(&ignored_bounds, &ignored_work_area, state_provider()->GetPersistentState(&ignored_bounds, &ignored_work_area,
show_state); show_state);
// |determined| is not set here, so we fall back to cross-platform window
// bounds computation.
} }
} }
if (browser_->is_type_normal() && *show_state == ui::SHOW_STATE_DEFAULT) { if (browser()->is_type_normal() && *show_state == ui::SHOW_STATE_DEFAULT) {
display::Display display = display::Display display =
display::Screen::GetScreen()->GetDisplayMatching(*bounds); display::Screen::GetScreen()->GetDisplayMatching(*bounds);
gfx::Rect work_area = display.work_area(); gfx::Rect work_area = display.work_area();
bounds->AdjustToFit(work_area); bounds->AdjustToFit(work_area);
if (*bounds == work_area) { if (*bounds == work_area) {
// A |browser_| that occupies the whole work area gets maximized. // A browser that occupies the whole work area gets maximized. The
// |bounds| returned here become the restore bounds once the window // |bounds| returned here become the restore bounds once the window
// gets maximized after this method returns. Return a sensible default // gets maximized after this method returns. Return a sensible default
// in order to make restored state visibly different from maximized. // in order to make restored state visibly different from maximized.
*show_state = ui::SHOW_STATE_MAXIMIZED; *show_state = ui::SHOW_STATE_MAXIMIZED;
*bounds = GetDefaultWindowBoundsChromeOS(browser_, display); *bounds = GetDefaultWindowBounds(display);
determined = true; determined = true;
} }
} }
return determined; return determined;
} }
void WindowSizer::GetTabbedBrowserBoundsChromeOS( void WindowSizerChromeOS::GetTabbedBrowserBounds(
gfx::Rect* bounds_in_screen, gfx::Rect* bounds_in_screen,
ui::WindowShowState* show_state) const { ui::WindowShowState* show_state) const {
DCHECK(show_state); DCHECK(show_state);
DCHECK(bounds_in_screen); DCHECK(bounds_in_screen);
DCHECK(browser_->is_type_normal()); DCHECK(browser()->is_type_normal());
DCHECK(bounds_in_screen->IsEmpty()); DCHECK(bounds_in_screen->IsEmpty());
const ui::WindowShowState passed_show_state = *show_state; const ui::WindowShowState passed_show_state = *show_state;
...@@ -99,9 +148,9 @@ void WindowSizer::GetTabbedBrowserBoundsChromeOS( ...@@ -99,9 +148,9 @@ void WindowSizer::GetTabbedBrowserBoundsChromeOS(
bool is_saved_bounds = GetSavedWindowBounds(bounds_in_screen, show_state); bool is_saved_bounds = GetSavedWindowBounds(bounds_in_screen, show_state);
display::Display display = GetDisplayForNewWindow(*bounds_in_screen); display::Display display = GetDisplayForNewWindow(*bounds_in_screen);
if (!is_saved_bounds) if (!is_saved_bounds)
*bounds_in_screen = GetDefaultWindowBoundsChromeOS(browser_, display); *bounds_in_screen = GetDefaultWindowBounds(display);
if (browser_->is_session_restore()) { if (browser()->is_session_restore()) {
// Respect display for saved bounds during session restore. // Respect display for saved bounds during session restore.
display = display =
display::Screen::GetScreen()->GetDisplayMatching(*bounds_in_screen); display::Screen::GetScreen()->GetDisplayMatching(*bounds_in_screen);
...@@ -128,31 +177,3 @@ void WindowSizer::GetTabbedBrowserBoundsChromeOS( ...@@ -128,31 +177,3 @@ void WindowSizer::GetTabbedBrowserBoundsChromeOS(
bounds_in_screen->AdjustToFit(display.work_area()); bounds_in_screen->AdjustToFit(display.work_area());
} }
// static
gfx::Rect WindowSizer::GetDefaultWindowBoundsChromeOS(
const Browser* browser,
const display::Display& display) {
// Let apps set their own default.
if (browser && browser->app_controller()) {
gfx::Rect bounds = browser->app_controller()->GetDefaultBounds();
if (!bounds.IsEmpty())
return bounds;
}
const gfx::Rect work_area = display.work_area();
// There should be a 'desktop' border around the window at the left and right
// side.
int default_width = work_area.width() - 2 * kDesktopBorderSize;
// There should also be a 'desktop' border around the window at the top.
// Since the workspace excludes the tray area we only need one border size.
int default_height = work_area.height() - kDesktopBorderSize;
int offset_x = kDesktopBorderSize;
if (default_width > kMaximumWindowWidth) {
// The window should get centered on the screen and not follow the grid.
offset_x = (work_area.width() - kMaximumWindowWidth) / 2;
default_width = kMaximumWindowWidth;
}
return gfx::Rect(work_area.x() + offset_x, work_area.y() + kDesktopBorderSize,
default_width, default_height);
}
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_CHROMEOS_H_
#define CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_CHROMEOS_H_
#include <memory>
#include "chrome/browser/ui/window_sizer/window_sizer.h"
#include "ui/base/ui_base_types.h"
namespace gfx {
class Rect;
}
// Support Chrome OS platform specific window sizing and positioning.
class WindowSizerChromeOS : public WindowSizer {
public:
// The number of pixels which are kept free top, left and right when a window
// gets positioned to its default location. Visible for testing.
static const int kDesktopBorderSize = 16;
// Maximum width of a window even if there is more room on the desktop.
// Visible for testing.
static const int kMaximumWindowWidth = 1100;
WindowSizerChromeOS(std::unique_ptr<StateProvider> state_provider,
const Browser* browser);
WindowSizerChromeOS(const WindowSizerChromeOS&) = delete;
WindowSizerChromeOS& operator=(const WindowSizerChromeOS&) = delete;
~WindowSizerChromeOS() override;
// WindowSizer:
void DetermineWindowBoundsAndShowState(
const gfx::Rect& specified_bounds,
gfx::Rect* bounds,
ui::WindowShowState* show_state) override;
gfx::Rect GetDefaultWindowBounds(
const display::Display& display) const override;
private:
// Returns true if |bounds| and |show_state| have been fully determined,
// otherwise returns false (but may still affect |show_state|). If the window
// is too big to fit in the display work area then the |bounds| are adjusted
// to default bounds and the |show_state| is adjusted to SHOW_STATE_MAXIMIZED.
bool GetBrowserBounds(gfx::Rect* bounds,
ui::WindowShowState* show_state) const;
// Determines the position and size for a tabbed browser window as it gets
// created. This will be called before other standard placement logic.
// |show_state| will only be changed if it was set to SHOW_STATE_DEFAULT.
void GetTabbedBrowserBounds(gfx::Rect* bounds,
ui::WindowShowState* show_state) const;
};
#endif // CHROME_BROWSER_UI_WINDOW_SIZER_WINDOW_SIZER_CHROMEOS_H_
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/ui/window_sizer/window_sizer_chromeos.h"
#include "ash/public/cpp/window_properties.h" #include "ash/public/cpp/window_properties.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
...@@ -49,8 +51,8 @@ class WindowSizerChromeOSTest : public ChromeAshTestBase { ...@@ -49,8 +51,8 @@ class WindowSizerChromeOSTest : public ChromeAshTestBase {
display::Screen::GetScreen()->SetDisplayForNewWindows(display_id); display::Screen::GetScreen()->SetDisplayForNewWindows(display_id);
ui::WindowShowState ignored; ui::WindowShowState ignored;
WindowSizer sizer(std::move(state_provider), browser); WindowSizer::GetBrowserWindowBoundsAndShowState(
sizer.DetermineWindowBoundsAndShowState(passed_in, out_bounds, &ignored); std::move(state_provider), passed_in, browser, out_bounds, &ignored);
} }
// Returns browser window |out_bounds| and |out_show_state| for simulated // Returns browser window |out_bounds| and |out_show_state| for simulated
...@@ -72,9 +74,8 @@ class WindowSizerChromeOSTest : public ChromeAshTestBase { ...@@ -72,9 +74,8 @@ class WindowSizerChromeOSTest : public ChromeAshTestBase {
if (source == LAST_ACTIVE || source == BOTH) if (source == LAST_ACTIVE || source == BOTH)
provider->SetLastActiveState(bounds, show_state_last); provider->SetLastActiveState(bounds, show_state_last);
WindowSizer sizer(std::move(provider), browser); WindowSizer::GetBrowserWindowBoundsAndShowState(
sizer.DetermineWindowBoundsAndShowState(passed_in, out_bounds, std::move(provider), passed_in, browser, out_bounds, out_show_state);
out_show_state);
} }
// Returns browser window show state for simulated persisted and last-active // Returns browser window show state for simulated persisted and last-active
...@@ -101,8 +102,8 @@ class WindowSizerChromeOSTest : public ChromeAshTestBase { ...@@ -101,8 +102,8 @@ class WindowSizerChromeOSTest : public ChromeAshTestBase {
namespace { namespace {
// Shorten identifiers to improve line wrapping. // Shorten identifiers to improve line wrapping.
const int kDesktopBorderSize = WindowSizer::kDesktopBorderSize; const int kDesktopBorderSize = WindowSizerChromeOS::kDesktopBorderSize;
const int kMaximumWindowWidth = WindowSizer::kMaximumWindowWidth; const int kMaximumWindowWidth = WindowSizerChromeOS::kMaximumWindowWidth;
const int kWindowTilePixels = WindowSizer::kWindowTilePixels; const int kWindowTilePixels = WindowSizer::kWindowTilePixels;
std::unique_ptr<Browser> CreateTestBrowser(aura::Window* window, std::unique_ptr<Browser> CreateTestBrowser(aura::Window* window,
......
...@@ -115,8 +115,8 @@ void WindowSizerTestUtil::GetWindowBounds(const gfx::Rect& monitor1_bounds, ...@@ -115,8 +115,8 @@ void WindowSizerTestUtil::GetWindowBounds(const gfx::Rect& monitor1_bounds,
provider->SetLastActiveState(bounds, ui::SHOW_STATE_DEFAULT); provider->SetLastActiveState(bounds, ui::SHOW_STATE_DEFAULT);
ui::WindowShowState ignored; ui::WindowShowState ignored;
WindowSizer sizer(std::move(provider), browser); WindowSizer::GetBrowserWindowBoundsAndShowState(
sizer.DetermineWindowBoundsAndShowState(passed_in, out_bounds, &ignored); std::move(provider), passed_in, browser, out_bounds, &ignored);
} }
#if !defined(OS_MACOSX) #if !defined(OS_MACOSX)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment