#include "chrome/browser/ui/window_sizer/window_sizer.h"
#include <algorithm>
#include <utility>
#include "base/command_line.h"
#include "base/functional/function_ref.h"
#include "base/memory/raw_ptr.h"
#include "base/not_fatal_until.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/browser_window_state.h"
#include "chrome/browser/ui/web_applications/app_browser_controller.h"
#include "chrome/common/chrome_switches.h"
#include "components/prefs/pref_service.h"
#include "ui/base/ui_base_switches.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/ui/window_sizer/window_sizer_chromeos.h"
#endif
namespace {
const int kMinVisibleHeight = …;
const int kMinVisibleWidth = …;
#if BUILDFLAG(IS_CHROMEOS_ASH)
constexpr float kMinVisibleRatio = 0.3f;
#endif
BrowserWindow* FindMostRecentBrowserWindow(
base::FunctionRef<bool(Browser*)> matcher) { … }
class DefaultStateProvider : public WindowSizer::StateProvider { … };
}
WindowSizer::WindowSizer(std::unique_ptr<StateProvider> state_provider,
const Browser* browser)
: … { … }
WindowSizer::~WindowSizer() = default;
void WindowSizer::GetBrowserWindowBoundsAndShowState(
const gfx::Rect& specified_bounds,
const Browser* browser,
gfx::Rect* window_bounds,
ui::WindowShowState* show_state) { … }
#if !BUILDFLAG(IS_LINUX)
void WindowSizer::GetBrowserWindowBoundsAndShowState(
std::unique_ptr<StateProvider> state_provider,
const gfx::Rect& specified_bounds,
const Browser* browser,
gfx::Rect* bounds,
ui::WindowShowState* show_state) {
DCHECK(bounds);
DCHECK(show_state);
#if BUILDFLAG(IS_CHROMEOS)
WindowSizerChromeOS sizer(std::move(state_provider), browser);
#else
WindowSizer sizer(std::move(state_provider), browser);
#endif
*show_state = GetWindowDefaultShowState(browser);
*bounds = specified_bounds;
sizer.DetermineWindowBoundsAndShowState(specified_bounds, bounds, show_state);
}
#endif
void WindowSizer::DetermineWindowBoundsAndShowState(
const gfx::Rect& specified_bounds,
gfx::Rect* bounds,
ui::WindowShowState* show_state) { … }
void WindowSizer::AdjustWorkAreaForPlatform(gfx::Rect& work_area) { … }
bool WindowSizer::GetLastActiveWindowBounds(
gfx::Rect* bounds,
ui::WindowShowState* show_state) const { … }
bool WindowSizer::GetSavedWindowBounds(gfx::Rect* bounds,
ui::WindowShowState* show_state) const { … }
gfx::Rect WindowSizer::GetDefaultWindowBounds(
const display::Display& display) const { … }
void WindowSizer::AdjustBoundsToBeVisibleOnDisplay(
const display::Display& display,
const gfx::Rect& saved_work_area,
gfx::Rect* bounds) const { … }
ui::WindowShowState WindowSizer::GetWindowDefaultShowState(
const Browser* browser) { … }
display::Display WindowSizer::GetDisplayForNewWindow(const gfx::Rect& bounds) { … }