Commit 7363ebc0 authored by James Cook's avatar James Cook Committed by Commit Bot

chromeos: Use Screen::GetDisplayForNewWindows in chrome/browser

display::Screen (and ScreenMus) now has the display for new windows,
so we can use that when making new browser windows under both mash
and classic ash. Likewise, we can use display::Screen (as ScreenAsh)
for new windows inside of ash.

This lets me remove ShellStateClient, a different mechanism that
accomplishes the same goal in a less general way.

Leave ash::ShellState for now. I will clean that up in a separate CL.

TBR=tsepez@chromium.org

Bug: 764009
Test: existing browser_tests for browser frame/size
Change-Id: I5c255dc2bf8fdd48f519f148d29aca3d37e7ae73
Reviewed-on: https://chromium-review.googlesource.com/1168197Reviewed-by: default avatarJames Cook <jamescook@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582336}
parent 07f5eb56
......@@ -10,7 +10,6 @@
#include "ash/root_window_settings.h"
#include "ash/shelf/shelf_widget.h"
#include "ash/shell.h"
#include "ash/shell_state.h"
#include "ash/wm/root_window_finder.h"
#include "base/command_line.h"
#include "base/logging.h"
......@@ -39,7 +38,9 @@ class ScreenForShutdown : public display::Screen {
public:
explicit ScreenForShutdown(display::Screen* screen_ash)
: display_list_(screen_ash->GetAllDisplays()),
primary_display_(screen_ash->GetPrimaryDisplay()) {}
primary_display_(screen_ash->GetPrimaryDisplay()) {
SetDisplayForNewWindows(primary_display_.id());
}
// display::Screen overrides:
gfx::Point GetCursorScreenPoint() override { return gfx::Point(); }
......@@ -69,9 +70,6 @@ class ScreenForShutdown : public display::Screen {
display::Display GetPrimaryDisplay() const override {
return primary_display_;
}
display::Display GetDisplayForNewWindows() const override {
return primary_display_;
}
void AddObserver(display::DisplayObserver* observer) override {
NOTREACHED() << "Observer should not be added during shutdown";
}
......@@ -183,11 +181,6 @@ display::Display ScreenAsh::GetPrimaryDisplay() const {
WindowTreeHostManager::GetPrimaryDisplayId());
}
display::Display ScreenAsh::GetDisplayForNewWindows() const {
return GetDisplayNearestWindow(
Shell::Get()->shell_state()->GetRootWindowForNewWindows());
}
void ScreenAsh::AddObserver(display::DisplayObserver* observer) {
GetDisplayManager()->AddObserver(observer);
}
......
......@@ -42,7 +42,6 @@ class ASH_EXPORT ScreenAsh : public display::Screen {
display::Display GetDisplayMatching(
const gfx::Rect& match_rect) const override;
display::Display GetPrimaryDisplay() const override;
display::Display GetDisplayForNewWindows() const override;
void AddObserver(display::DisplayObserver* observer) override;
void RemoveObserver(display::DisplayObserver* observer) override;
......
......@@ -32,7 +32,6 @@
#include "ash/shelf/shelf_controller.h"
#include "ash/shell.h"
#include "ash/shell_delegate.h"
#include "ash/shell_state.h"
#include "ash/shutdown_controller.h"
#include "ash/system/locale/locale_notification_controller.h"
#include "ash/system/model/system_tray_model.h"
......@@ -178,10 +177,6 @@ void BindShelfRequestOnMainThread(mojom::ShelfControllerRequest request) {
Shell::Get()->shelf_controller()->BindRequest(std::move(request));
}
void BindShellStateOnMainThread(mojom::ShellStateRequest request) {
Shell::Get()->shell_state()->BindRequest(std::move(request));
}
void BindShutdownControllerRequestOnMainThread(
mojom::ShutdownControllerRequest request) {
Shell::Get()->shutdown_controller()->BindRequest(std::move(request));
......@@ -302,8 +297,6 @@ void RegisterInterfaces(
registry->AddInterface(
base::BindRepeating(&BindSessionControllerRequestOnMainThread),
main_thread_task_runner);
registry->AddInterface(base::BindRepeating(&BindShellStateOnMainThread),
main_thread_task_runner);
registry->AddInterface(base::BindRepeating(&BindShelfRequestOnMainThread),
main_thread_task_runner);
registry->AddInterface(
......
......@@ -46,7 +46,6 @@ mojom("interfaces_internal") {
"process_creation_time_recorder.mojom",
"session_controller.mojom",
"shelf.mojom",
"shell_state.mojom",
"shutdown.mojom",
"split_view.mojom",
"system_tray.mojom",
......
// Copyright 2018 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.
module ash.mojom;
// Allows access to ash::Shell state.
interface ShellState {
// The client is immediately notified with the initial state.
AddClient(ShellStateClient client);
};
interface ShellStateClient {
// Updates the client's cache of the display id to use for new top-level
// windows.
SetDisplayIdForNewWindows(int64 display_id);
};
......@@ -19,10 +19,6 @@ ShellState::ShellState() = default;
ShellState::~ShellState() = default;
void ShellState::BindRequest(mojom::ShellStateRequest request) {
bindings_.AddBinding(this, std::move(request));
}
aura::Window* ShellState::GetRootWindowForNewWindows() const {
if (scoped_root_window_for_new_windows_)
return scoped_root_window_for_new_windows_;
......@@ -36,21 +32,9 @@ void ShellState::SetRootWindowForNewWindows(aura::Window* root) {
NotifyAllClients();
}
void ShellState::AddClient(mojom::ShellStateClientPtr client) {
mojom::ShellStateClient* client_impl = client.get();
clients_.AddPtr(std::move(client));
client_impl->SetDisplayIdForNewWindows(GetDisplayIdForNewWindows());
}
void ShellState::FlushMojoForTest() {
clients_.FlushForTesting();
}
void ShellState::NotifyAllClients() {
const int64_t display_id = GetDisplayIdForNewWindows();
clients_.ForAllPtrs([display_id](mojom::ShellStateClient* client) {
client->SetDisplayIdForNewWindows(display_id);
});
display::Screen::GetScreen()->SetDisplayForNewWindows(display_id);
// WindowService broadcasts the display id over mojo to all remote apps.
// TODO(jamescook): Move this into Shell when ShellState is removed.
......
......@@ -7,13 +7,8 @@
#include <stdint.h>
#include <memory>
#include "ash/ash_export.h"
#include "ash/public/interfaces/shell_state.mojom.h"
#include "base/macros.h"
#include "mojo/public/cpp/bindings/binding_set.h"
#include "mojo/public/cpp/bindings/interface_ptr_set.h"
namespace aura {
class Window;
......@@ -21,17 +16,12 @@ class Window;
namespace ash {
// Provides access via mojo to ash::Shell state.
// TODO(jamescook): Move |root_window_for_new_windows_| to Shell, convert
// browser code to use display::Screen::GetDisplayForNewWindows() and delete
// TODO(jamescook): Move |root_window_for_new_windows_| to Shell and delete
// this class.
class ASH_EXPORT ShellState : public mojom::ShellState {
class ASH_EXPORT ShellState {
public:
ShellState();
~ShellState() override;
// Binds the mojom::ShellState interface to this object.
void BindRequest(mojom::ShellStateRequest request);
~ShellState();
// Returns the root window that newly created windows should be added to.
// Value can be temporarily overridden using ScopedRootWindowForNewWindows.
......@@ -43,11 +33,6 @@ class ASH_EXPORT ShellState : public mojom::ShellState {
// NOTE: Prefer ScopedRootWindowForNewWindows.
void SetRootWindowForNewWindows(aura::Window* root);
// mojom::ShellState:
void AddClient(mojom::ShellStateClientPtr client) override;
void FlushMojoForTest();
private:
friend class ScopedRootWindowForNewWindows;
......@@ -59,12 +44,6 @@ class ASH_EXPORT ShellState : public mojom::ShellState {
// Sets the value and updates clients.
void SetScopedRootWindowForNewWindows(aura::Window* root);
// Binding for mojom::ShellState interface.
mojo::BindingSet<mojom::ShellState> bindings_;
// Clients (e.g. chrome browser, other mojo apps).
mojo::InterfacePtrSet<mojom::ShellStateClient> clients_;
aura::Window* root_window_for_new_windows_ = nullptr;
// See ScopedRootWindowForNewWindows.
......
......@@ -6,61 +6,29 @@
#include <stdint.h>
#include "ash/public/interfaces/shell_state.mojom.h"
#include "ash/scoped_root_window_for_new_windows.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "base/macros.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "ui/display/display.h"
#include "ui/display/manager/display_manager.h"
#include "ui/display/screen.h"
namespace ash {
namespace {
// Simulates the client interface in chrome.
class TestShellStateClient : public mojom::ShellStateClient {
public:
TestShellStateClient() = default;
~TestShellStateClient() override = default;
mojom::ShellStateClientPtr CreateInterfacePtrAndBind() {
mojom::ShellStateClientPtr ptr;
binding_.Bind(mojo::MakeRequest(&ptr));
return ptr;
}
// mojom::ShellStateClient:
void SetDisplayIdForNewWindows(int64_t display_id) override {
last_display_id_ = display_id;
}
int64_t last_display_id_ = 0;
private:
mojo::Binding<mojom::ShellStateClient> binding_{this};
DISALLOW_COPY_AND_ASSIGN(TestShellStateClient);
};
using ShellStateTest = AshTestBase;
TEST_F(ShellStateTest, Basics) {
TEST_F(ShellStateTest, GetDisplayForNewWindows) {
UpdateDisplay("1024x768,800x600");
const int64_t primary_display_id = display_manager()->GetDisplayAt(0).id();
const int64_t secondary_display_id = display_manager()->GetDisplayAt(1).id();
ShellState* shell_state = Shell::Get()->shell_state();
TestShellStateClient client;
// Adding a client notifies it with the initial display id.
shell_state->AddClient(client.CreateInterfacePtrAndBind());
shell_state->FlushMojoForTest();
EXPECT_EQ(primary_display_id, client.last_display_id_);
display::Screen* screen = display::Screen::GetScreen();
EXPECT_EQ(primary_display_id, screen->GetDisplayForNewWindows().id());
// Setting a root window for new windows notifies the client.
ScopedRootWindowForNewWindows scoped_root(Shell::GetAllRootWindows()[1]);
shell_state->FlushMojoForTest();
EXPECT_EQ(secondary_display_id, client.last_display_id_);
EXPECT_EQ(secondary_display_id, screen->GetDisplayForNewWindows().id());
}
} // namespace
......
......@@ -1882,8 +1882,6 @@ jumbo_split_static_library("ui") {
"ash/session_controller_client.h",
"ash/session_util.cc",
"ash/session_util.h",
"ash/shell_state_client.cc",
"ash/shell_state_client.h",
"ash/system_tray_client.cc",
"ash/system_tray_client.h",
"ash/tab_scrubber.cc",
......
......@@ -34,7 +34,6 @@
#include "chrome/browser/ui/ash/network/network_connect_delegate_chromeos.h"
#include "chrome/browser/ui/ash/network/network_portal_notification_controller.h"
#include "chrome/browser/ui/ash/session_controller_client.h"
#include "chrome/browser/ui/ash/shell_state_client.h"
#include "chrome/browser/ui/ash/system_tray_client.h"
#include "chrome/browser/ui/ash/tab_scrubber.h"
#include "chrome/browser/ui/ash/tablet_mode_client.h"
......@@ -197,9 +196,6 @@ void ChromeBrowserMainExtraPartsAsh::PreProfileInit() {
session_controller_client_ = std::make_unique<SessionControllerClient>();
session_controller_client_->Init();
shell_state_client_ = std::make_unique<ShellStateClient>();
shell_state_client_->Init();
system_tray_client_ = std::make_unique<SystemTrayClient>();
// Makes mojo request to TabletModeController in ash.
......@@ -276,7 +272,6 @@ void ChromeBrowserMainExtraPartsAsh::PostMainMessageLoopRun() {
volume_controller_.reset();
system_tray_client_.reset();
shell_state_client_.reset();
session_controller_client_.reset();
chrome_new_window_client_.reset();
network_portal_notification_controller_.reset();
......
......@@ -37,7 +37,6 @@ class MediaClient;
class NetworkConnectDelegateChromeOS;
class NightLightClient;
class SessionControllerClient;
class ShellStateClient;
class SystemTrayClient;
class TabletModeClient;
class VolumeController;
......@@ -91,7 +90,6 @@ class ChromeBrowserMainExtraPartsAsh : public ChromeBrowserMainExtraParts {
std::unique_ptr<ChromeNewWindowClient> chrome_new_window_client_;
std::unique_ptr<ImeControllerClient> ime_controller_client_;
std::unique_ptr<SessionControllerClient> session_controller_client_;
std::unique_ptr<ShellStateClient> shell_state_client_;
std::unique_ptr<SystemTrayClient> system_tray_client_;
std::unique_ptr<TabletModeClient> tablet_mode_client_;
std::unique_ptr<VolumeController> volume_controller_;
......
// Copyright 2018 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.
#include "chrome/browser/ui/ash/launcher/crostini_app_display.h"
#include "chrome/browser/ui/ash/shell_state_client.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/display/types/display_constants.h"
CrostiniAppDisplay::CrostiniAppDisplay() = default;
......@@ -28,6 +30,6 @@ void CrostiniAppDisplay::Register(const std::string& app_id,
int64_t CrostiniAppDisplay::GetDisplayIdForAppId(const std::string& app_id) {
auto it = app_id_to_display_id_.find(app_id);
if (it == app_id_to_display_id_.end())
return ShellStateClient::Get()->display_id_for_new_windows();
return display::Screen::GetScreen()->GetDisplayForNewWindows().id();
return it->second;
}
......@@ -16,13 +16,13 @@
#include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controller.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h"
#include "chrome/browser/ui/ash/shell_state_client.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/grit/generated_resources.h"
#include "content/public/common/context_menu_params.h"
#include "extensions/browser/extension_prefs.h"
#include "ui/base/ui_base_features.h"
#include "ui/display/screen.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/controls/menu/menu_config.h"
......@@ -41,11 +41,11 @@ class ScopedDisplayIdForNewWindows {
public:
explicit ScopedDisplayIdForNewWindows(int64_t display_id)
: old_display_id_(display_id) {
ShellStateClient::Get()->SetDisplayIdForNewWindows(display_id);
display::Screen::GetScreen()->SetDisplayForNewWindows(display_id);
}
~ScopedDisplayIdForNewWindows() {
ShellStateClient::Get()->SetDisplayIdForNewWindows(old_display_id_);
display::Screen::GetScreen()->SetDisplayForNewWindows(old_display_id_);
}
private:
......
// Copyright 2018 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.
#include "chrome/browser/ui/ash/shell_state_client.h"
#include <utility>
#include "ash/public/interfaces/constants.mojom.h"
#include "chrome/browser/ui/window_sizer/window_sizer.h"
#include "content/public/common/service_manager_connection.h"
#include "services/service_manager/public/cpp/connector.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/display/types/display_constants.h"
namespace {
ShellStateClient* g_shell_state_client = nullptr;
} // namespace
ShellStateClient::ShellStateClient()
: binding_(this), display_id_for_new_windows_(display::kInvalidDisplayId) {
DCHECK(!g_shell_state_client);
g_shell_state_client = this;
}
ShellStateClient::~ShellStateClient() {
DCHECK_EQ(this, g_shell_state_client);
g_shell_state_client = nullptr;
}
void ShellStateClient::Init() {
content::ServiceManagerConnection::GetForProcess()
->GetConnector()
->BindInterface(ash::mojom::kServiceName, &shell_state_ptr_);
BindAndAddClient();
}
void ShellStateClient::InitForTesting(ash::mojom::ShellStatePtr shell_state) {
shell_state_ptr_ = std::move(shell_state);
BindAndAddClient();
}
// static
ShellStateClient* ShellStateClient::Get() {
return g_shell_state_client;
}
void ShellStateClient::SetDisplayIdForNewWindows(int64_t display_id) {
display_id_for_new_windows_ = display_id;
}
void ShellStateClient::FlushForTesting() {
shell_state_ptr_.FlushForTesting();
}
void ShellStateClient::BindAndAddClient() {
ash::mojom::ShellStateClientPtr client_ptr;
binding_.Bind(mojo::MakeRequest(&client_ptr));
shell_state_ptr_->AddClient(std::move(client_ptr));
}
// static
display::Display WindowSizer::GetDisplayForNewWindow(const gfx::Rect& bounds) {
display::Screen* screen = display::Screen::GetScreen();
// May be null in unit tests.
if (g_shell_state_client) {
// Prefer the display where the user last activated any window.
const int64_t id = g_shell_state_client->display_id_for_new_windows();
display::Display display;
if (screen->GetDisplayWithDisplayId(id, &display))
return display;
}
// Otherwise find the display that best matches the bounds.
return screen->GetDisplayMatching(bounds);
}
// Copyright 2018 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_ASH_SHELL_STATE_CLIENT_H_
#define CHROME_BROWSER_UI_ASH_SHELL_STATE_CLIENT_H_
#include <memory>
#include "ash/public/interfaces/shell_state.mojom.h"
#include "base/macros.h"
#include "mojo/public/cpp/bindings/binding.h"
// Caches ash::Shell state. The initial values are loaded asynchronously at
// startup because we don't want Chrome to block on startup waiting for Ash.
class ShellStateClient : public ash::mojom::ShellStateClient {
public:
ShellStateClient();
~ShellStateClient() override;
// Initializes and connects to ash.
void Init();
// Tests can provide a mock mojo interface for the ash interface.
void InitForTesting(ash::mojom::ShellStatePtr shell_state_ptr);
static ShellStateClient* Get();
int64_t display_id_for_new_windows() const {
return display_id_for_new_windows_;
}
// ash::mojom::ShellStateClient:
void SetDisplayIdForNewWindows(int64_t display_id) override;
// Flushes the mojo pipe to ash.
void FlushForTesting();
private:
friend class ScopedDisplayIdForNewWindows;
// Binds this object to its mojo interface and registers it as an ash client.
void BindAndAddClient();
// The mojo interface in ash.
ash::mojom::ShellStatePtr shell_state_ptr_;
// Binds to the observer interface from ash.
mojo::Binding<ash::mojom::ShellStateClient> binding_;
int64_t display_id_for_new_windows_;
DISALLOW_COPY_AND_ASSIGN(ShellStateClient);
};
#endif // CHROME_BROWSER_UI_ASH_SHELL_STATE_CLIENT_H_
// Copyright 2018 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.
#include "chrome/browser/ui/ash/shell_state_client.h"
#include "ash/public/interfaces/shell_state.mojom.h"
#include "base/macros.h"
#include "base/test/scoped_task_environment.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
class TestShellState : ash::mojom::ShellState {
public:
TestShellState() : binding_(this) {}
~TestShellState() override = default;
ash::mojom::ShellStatePtr CreateInterfacePtr() {
ash::mojom::ShellStatePtr ptr;
binding_.Bind(mojo::MakeRequest(&ptr));
return ptr;
}
// ash::mojom::ShellState:
void AddClient(ash::mojom::ShellStateClientPtr client) override {
++add_client_count_;
}
int add_client_count() const { return add_client_count_; }
private:
mojo::Binding<ash::mojom::ShellState> binding_;
int add_client_count_ = 0;
DISALLOW_COPY_AND_ASSIGN(TestShellState);
};
TEST(ShellStateClientTest, Basics) {
base::test::ScopedTaskEnvironment scoped_task_enviroment;
ShellStateClient client;
TestShellState ash_shell_state;
client.InitForTesting(ash_shell_state.CreateInterfacePtr());
client.FlushForTesting();
// Client was added to ash.
EXPECT_TRUE(ash_shell_state.add_client_count());
client.SetDisplayIdForNewWindows(123);
EXPECT_EQ(123, client.display_id_for_new_windows());
}
} // namespace
......@@ -366,10 +366,12 @@ ui::WindowShowState WindowSizer::GetWindowDefaultShowState() const {
return browser_->initial_show_state();
}
#if !defined(OS_CHROMEOS)
// Chrome OS has an implementation in //chrome/browser/ui/ash.
// static
display::Display WindowSizer::GetDisplayForNewWindow(const gfx::Rect& bounds) {
#if defined(OS_CHROMEOS)
// Prefer the display where the user last activated a window.
return display::Screen::GetScreen()->GetDisplayForNewWindows();
#else
return display::Screen::GetScreen()->GetDisplayMatching(bounds);
}
#endif // defined(OS_CHROMEOS)
}
......@@ -6,7 +6,6 @@
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "base/memory/ptr_util.h"
#include "chrome/browser/ui/ash/shell_state_client.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/window_sizer/window_sizer_common_unittest.h"
#include "chrome/common/chrome_switches.h"
......@@ -44,7 +43,7 @@ class WindowSizerAshTest : public ash::AshTestBase {
auto state_provider = std::make_unique<TestStateProvider>();
state_provider->SetPersistentState(gfx::Rect(), gfx::Rect(),
ui::SHOW_STATE_DEFAULT);
shell_state_client_.SetDisplayIdForNewWindows(display_id);
display::Screen::GetScreen()->SetDisplayForNewWindows(display_id);
ui::WindowShowState ignored;
WindowSizer sizer(std::move(state_provider), browser);
......@@ -94,7 +93,6 @@ class WindowSizerAshTest : public ash::AshTestBase {
protected:
TestingProfile profile_;
ShellStateClient shell_state_client_;
private:
DISALLOW_COPY_AND_ASSIGN(WindowSizerAshTest);
......@@ -733,7 +731,7 @@ TEST_F(WindowSizerAshTest, DefaultBoundsInTargetDisplay) {
// When the second display is active new windows are placed there.
aura::Window* second_root = ash::Shell::GetAllRootWindows()[1];
int64_t second_display_id = display_manager()->GetSecondaryDisplay().id();
shell_state_client_.SetDisplayIdForNewWindows(second_display_id);
display::Screen::GetScreen()->SetDisplayForNewWindows(second_display_id);
gfx::Rect bounds;
ui::WindowShowState show_state;
WindowSizer::GetBrowserWindowBoundsAndShowState(
......
......@@ -3405,7 +3405,6 @@ test("unit_tests") {
"../browser/ui/ash/network/network_state_notifier_unittest.cc",
"../browser/ui/ash/network/tether_notification_presenter_unittest.cc",
"../browser/ui/ash/session_controller_client_unittest.cc",
"../browser/ui/ash/shell_state_client_unittest.cc",
"../browser/ui/ash/tablet_mode_client_unittest.cc",
"../browser/ui/ash/wallpaper_controller_client_unittest.cc",
"../browser/ui/window_sizer/window_sizer_ash_unittest.cc",
......
......@@ -5,6 +5,7 @@
#include "ui/display/screen.h"
#include "ui/display/display.h"
#include "ui/display/types/display_constants.h"
#include "ui/gfx/geometry/rect.h"
namespace display {
......@@ -15,9 +16,9 @@ Screen* g_screen;
} // namespace
Screen::Screen() {}
Screen::Screen() : display_id_for_new_windows_(kInvalidDisplayId) {}
Screen::~Screen() {}
Screen::~Screen() = default;
// static
Screen* Screen::GetScreen() {
......@@ -38,10 +39,20 @@ Display Screen::GetDisplayNearestView(gfx::NativeView view) const {
return GetDisplayNearestWindow(GetWindowForView(view));
}
Display Screen::GetDisplayForNewWindows() const {
display::Display Screen::GetDisplayForNewWindows() const {
display::Display display;
if (GetDisplayWithDisplayId(display_id_for_new_windows_, &display))
return display;
// Fallback to primary display.
return GetPrimaryDisplay();
}
void Screen::SetDisplayForNewWindows(int64_t display_id) {
// GetDisplayForNewWindows() handles invalid display ids.
display_id_for_new_windows_ = display_id;
}
gfx::Rect Screen::ScreenToDIPRectInWindow(gfx::NativeView view,
const gfx::Rect& screen_rect) const {
float scale = GetDisplayNearestView(view).device_scale_factor();
......
......@@ -78,7 +78,10 @@ class DISPLAY_EXPORT Screen {
// Returns a suggested display to use when creating a new window. On most
// platforms just returns the primary display.
virtual Display GetDisplayForNewWindows() const;
Display GetDisplayForNewWindows() const;
// Sets the suggested display to use when creating a new window.
void SetDisplayForNewWindows(int64_t display_id);
// Adds/Removes display observers.
virtual void AddObserver(DisplayObserver* observer) = 0;
......@@ -104,6 +107,8 @@ class DISPLAY_EXPORT Screen {
private:
static gfx::NativeWindow GetWindowForView(gfx::NativeView view);
int64_t display_id_for_new_windows_;
DISALLOW_COPY_AND_ASSIGN(Screen);
};
......
......@@ -104,8 +104,7 @@ void ScreenMus::OnDisplaysChanged(
delegate_->OnWindowManagerFrameValuesChanged();
}
// GetDisplayForNewWindows() can handle ids that are not in the list.
display_id_for_new_windows_ = display_id_for_new_windows;
SetDisplayForNewWindows(display_id_for_new_windows);
}
display::Display ScreenMus::GetDisplayNearestWindow(
......@@ -130,13 +129,4 @@ aura::Window* ScreenMus::GetWindowAtScreenPoint(const gfx::Point& point) {
return delegate_->GetWindowAtScreenPoint(point);
}
display::Display ScreenMus::GetDisplayForNewWindows() const {
display::Display display;
if (GetDisplayWithDisplayId(display_id_for_new_windows_, &display))
return display;
// Fallback to primary display.
return GetPrimaryDisplay();
}
} // namespace views
......@@ -33,11 +33,9 @@ class VIEWS_MUS_EXPORT ScreenMus : public display::ScreenBase,
gfx::Point GetCursorScreenPoint() override;
bool IsWindowUnderCursor(gfx::NativeWindow window) override;
aura::Window* GetWindowAtScreenPoint(const gfx::Point& point) override;
display::Display GetDisplayForNewWindows() const override;
private:
ScreenMusDelegate* delegate_;
int64_t display_id_for_new_windows_ = display::kInvalidDisplayId;
DISALLOW_COPY_AND_ASSIGN(ScreenMus);
};
......
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