blob: 9200fab48103dfc1f76844a3c4ab9a5b7435cce6 [file] [log] [blame]
// 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 "ash/shell_state.h"
#include <memory>
#include <utility>
#include "ash/shell.h"
#include "ash/ws/window_service_owner.h"
#include "services/ws/window_service.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
namespace ash {
ShellState::ShellState() = default;
ShellState::~ShellState() = default;
aura::Window* ShellState::GetRootWindowForNewWindows() const {
if (scoped_root_window_for_new_windows_)
return scoped_root_window_for_new_windows_;
return root_window_for_new_windows_;
void ShellState::SetRootWindowForNewWindows(aura::Window* root) {
if (root == root_window_for_new_windows_)
root_window_for_new_windows_ = root;
void ShellState::NotifyAllClients() {
const int64_t display_id = GetDisplayIdForNewWindows();
// WindowService broadcasts the display id over mojo to all remote apps.
// TODO(jamescook): Move this into Shell when ShellState is removed.
WindowServiceOwner* ws_owner = Shell::Get()->window_service_owner();
// |ws_owner| is null during shutdown and tests. |window_service()| is null
// during early startup.
if (ws_owner && ws_owner->window_service())
int64_t ShellState::GetDisplayIdForNewWindows() const {
// GetDisplayNearestWindow() handles null.
return display::Screen::GetScreen()
void ShellState::SetScopedRootWindowForNewWindows(aura::Window* root) {
if (root == scoped_root_window_for_new_windows_)
// Only allow set and clear, not switch.
DCHECK(!scoped_root_window_for_new_windows_ || !root);
scoped_root_window_for_new_windows_ = root;
} // namespace ash