#include "ui/display/screen.h"
#include <optional>
#include <utility>
#include "base/check.h"
#include "base/containers/contains.h"
#include "base/memory/ptr_util.h"
#include "base/notreached.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "ui/display/display.h"
#include "ui/display/display_util.h"
#include "ui/display/tablet_state.h"
#include "ui/display/types/display_constants.h"
#include "ui/gfx/geometry/rect.h"
namespace display {
namespace {
Screen* g_screen;
}
Screen::Screen() : … { … }
Screen::~Screen() = default;
Screen* Screen::GetScreen() { … }
Screen* Screen::SetScreenInstance(Screen* instance,
const base::Location& location) { … }
bool Screen::HasScreen() { … }
void Screen::SetCursorScreenPointForTesting(const gfx::Point& point) { … }
Display Screen::GetDisplayNearestView(gfx::NativeView view) const { … }
Display Screen::GetDisplayForNewWindows() const { … }
void Screen::SetDisplayForNewWindows(int64_t display_id) { … }
#if BUILDFLAG(IS_CHROMEOS_LACROS) || BUILDFLAG(IS_LINUX)
Screen::ScreenSaverSuspender::~ScreenSaverSuspender() = default;
std::unique_ptr<Screen::ScreenSaverSuspender> Screen::SuspendScreenSaver() { … }
#endif
bool Screen::IsScreenSaverActive() const { … }
base::TimeDelta Screen::CalculateIdleTime() const { … }
gfx::Rect Screen::ScreenToDIPRectInWindow(gfx::NativeWindow window,
const gfx::Rect& screen_rect) const { … }
gfx::Rect Screen::DIPToScreenRectInWindow(gfx::NativeWindow window,
const gfx::Rect& dip_rect) const { … }
bool Screen::GetDisplayWithDisplayId(int64_t display_id,
Display* display) const { … }
void Screen::SetPanelRotationForTesting(int64_t display_id,
Display::Rotation rotation) { … }
std::string Screen::GetCurrentWorkspace() { … }
base::Value::List Screen::GetGpuExtraInfo(
const gfx::GpuExtraInfo& gpu_extra_info) { … }
std::optional<float> Screen::GetPreferredScaleFactorForWindow(
gfx::NativeWindow window) const { … }
std::optional<float> Screen::GetPreferredScaleFactorForView(
gfx::NativeView view) const { … }
#if BUILDFLAG(IS_CHROMEOS)
TabletState Screen::GetTabletState() const {
return TabletState::kInClamshellMode;
}
bool Screen::InTabletMode() const {
TabletState state = GetTabletState();
return state == TabletState::kInTabletMode ||
state == TabletState::kEnteringTabletMode;
}
#endif
void Screen::SetScopedDisplayForNewWindows(int64_t display_id) { … }
ScreenInfos Screen::GetScreenInfosNearestDisplay(int64_t nearest_id) const { … }
#if BUILDFLAG(IS_APPLE)
ScopedNativeScreen::ScopedNativeScreen(const base::Location& location) {
if (!Screen::HasScreen()) {
#if BUILDFLAG(IS_IOS)
Screen::GetScreen();
#else
screen_ = base::WrapUnique(CreateNativeScreen());
Screen::SetScreenInstance(screen_.get(), location);
#endif
}
}
ScopedNativeScreen::~ScopedNativeScreen() {
if (screen_) {
DCHECK_EQ(screen_.get(), Screen::GetScreen());
Screen::SetScreenInstance(nullptr);
screen_.reset();
}
}
#endif
}