Skip to content

Commit

Permalink
Move ash::ScopedRootWindowForNewWindows to display::ScopedDisplay...
Browse files Browse the repository at this point in the history
This object is needed outside of ash.

Bug: 1083825
Change-Id: Id3ab099925ac6cee0810815eb377aa745b44e060
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2208883
Reviewed-by: Mitsuru Oshima <oshima@chromium.org>
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Joel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#770772}
  • Loading branch information
Joel Hockey authored and Commit Bot committed May 20, 2020
1 parent 5cc2f76 commit 784a832
Show file tree
Hide file tree
Showing 30 changed files with 172 additions and 278 deletions.
5 changes: 0 additions & 5 deletions ash/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,6 @@ component("ash") {
"rotator/window_rotation.h",
"scoped_animation_disabler.cc",
"scoped_animation_disabler.h",
"scoped_root_window_for_new_windows.cc",
"scoped_root_window_for_new_windows.h",
"screen_util.cc",
"screen_util.h",
"screenshot_delegate.h",
Expand Down Expand Up @@ -732,8 +730,6 @@ component("ash") {
"shell.cc",
"shell_delegate.cc",
"shell_init_params.cc",
"shell_state.cc",
"shell_state.h",
"shutdown_controller_impl.cc",
"shutdown_controller_impl.h",
"shutdown_reason.cc",
Expand Down Expand Up @@ -2004,7 +2000,6 @@ test("ash_unittests") {
"shelf/test/shelf_layout_manager_test_base.h",
"shelf/test/widget_animation_smoothness_inspector.cc",
"shelf/test/widget_animation_smoothness_inspector.h",
"shell_state_unittest.cc",
"shell_unittest.cc",
"sticky_keys/sticky_keys_overlay_unittest.cc",
"sticky_keys/sticky_keys_unittest.cc",
Expand Down
7 changes: 2 additions & 5 deletions ash/display/display_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "ash/screen_util.h"
#include "ash/shelf/shelf.h"
#include "ash/shell.h"
#include "ash/shell_state.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/test/ash_test_base.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
Expand Down Expand Up @@ -4598,8 +4597,7 @@ TEST_F(DisplayManagerTest, UpdateRootWindowForNewWindows) {
const auto test_removing_secondary = [this](size_t before, size_t after) {
UpdateDisplay("800x600,800x600,800x600");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
Shell::Get()->shell_state()->SetRootWindowForNewWindows(
root_windows[before]);
Shell::SetRootWindowForNewWindows(root_windows[before]);
UpdateDisplay("800x600,800x600");
EXPECT_EQ(root_windows[after], Shell::GetRootWindowForNewWindows());
};
Expand All @@ -4613,8 +4611,7 @@ TEST_F(DisplayManagerTest, UpdateRootWindowForNewWindows) {
// primary one.
for (size_t before = 0u; before < 3u; ++before) {
UpdateDisplay("800x600,800x600,800x600");
Shell::Get()->shell_state()->SetRootWindowForNewWindows(
Shell::GetAllRootWindows()[before]);
Shell::SetRootWindowForNewWindows(Shell::GetAllRootWindows()[before]);
display_manager()->SetUnifiedDesktopEnabled(true);
EXPECT_EQ(Shell::GetPrimaryRootWindow(),
Shell::GetRootWindowForNewWindows());
Expand Down
5 changes: 3 additions & 2 deletions ash/display/screen_ash_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/scoped_root_window_for_new_windows.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/window.h"
#include "ui/display/manager/display_manager.h"
#include "ui/display/scoped_display_for_new_windows.h"

namespace ash {

Expand Down Expand Up @@ -44,7 +44,8 @@ TEST_F(ScreenAshTest, GetDisplayForNewWindows) {

// The display for new windows is updated when the root window for new windows
// changes.
ScopedRootWindowForNewWindows scoped_root(Shell::GetAllRootWindows()[1]);
display::ScopedDisplayForNewWindows scoped_display(
Shell::GetAllRootWindows()[1]);
EXPECT_EQ(displays[1].id(), screen->GetDisplayForNewWindows().id());
}

Expand Down
6 changes: 2 additions & 4 deletions ash/display/window_tree_host_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include "ash/root_window_controller.h"
#include "ash/root_window_settings.h"
#include "ash/shell.h"
#include "ash/shell_state.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/unified/unified_system_tray.h"
#include "ash/wm/window_util.h"
Expand Down Expand Up @@ -229,7 +228,7 @@ void WindowTreeHostManager::Shutdown() {
}
CHECK(primary_rwc);

Shell::Get()->shell_state()->SetRootWindowForNewWindows(nullptr);
Shell::SetRootWindowForNewWindows(nullptr);
for (auto* rwc : to_delete)
delete rwc;
delete primary_rwc;
Expand Down Expand Up @@ -551,8 +550,7 @@ void WindowTreeHostManager::DeleteHost(AshWindowTreeHost* host_to_delete) {
primary_tree_host_for_replace_ = nullptr;
DCHECK_EQ(primary_root_after_host_deletion, Shell::GetPrimaryRootWindow());
if (Shell::GetRootWindowForNewWindows() == root_being_deleted) {
Shell::Get()->shell_state()->SetRootWindowForNewWindows(
primary_root_after_host_deletion);
Shell::SetRootWindowForNewWindows(primary_root_after_host_deletion);
}
// NOTE: ShelfWidget is gone, but Shelf still exists until this task runs.
base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, controller);
Expand Down
6 changes: 3 additions & 3 deletions ash/drag_drop/drag_drop_tracker_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
#include <memory>

#include "ash/public/cpp/shell_window_ids.h"
#include "ash/scoped_root_window_for_new_windows.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ui/aura/test/test_windows.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/display/scoped_display_for_new_windows.h"
#include "ui/events/event_utils.h"

namespace ash {
Expand Down Expand Up @@ -83,7 +83,7 @@ TEST_F(DragDropTrackerTest, GetTarget) {
EXPECT_NE(window1.get(), GetTarget(gfx::Point(50, 250)));

// Make RootWindow1 active so that capture window is parented to it.
ScopedRootWindowForNewWindows root_for_new_windows(root_windows[1]);
display::ScopedDisplayForNewWindows display_for_new_windows(root_windows[1]);

// Start tracking from the RootWindow1 and check the point on RootWindow0 that
// |window0| covers.
Expand Down Expand Up @@ -145,7 +145,7 @@ TEST_F(DragDropTrackerTest, ConvertEvent) {
EXPECT_EQ(original01.flags(), converted01->flags());

// Make RootWindow1 active so that capture window is parented to it.
ScopedRootWindowForNewWindows root_for_new_windows(root_windows[1]);
display::ScopedDisplayForNewWindows display_for_new_windows(root_windows[1]);

// Start tracking from the RootWindow1 and converts the mouse event into
// |window0|'s coodinates.
Expand Down
4 changes: 1 addition & 3 deletions ash/highlighter/highlighter_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "ash/highlighter/highlighter_view.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/shell.h"
#include "ash/shell_state.h"
#include "ash/system/palette/palette_utils.h"
#include "base/bind.h"
#include "base/metrics/histogram_macros.h"
Expand Down Expand Up @@ -191,8 +190,7 @@ void HighlighterController::RecognizeGesture() {
if (!box.IsEmpty() &&
gesture_type != HighlighterGestureType::kNotRecognized) {
// The window for selection should be the root window to show assistant.
Shell::Get()->shell_state()->SetRootWindowForNewWindows(
current_window->GetRootWindow());
Shell::SetRootWindowForNewWindows(current_window->GetRootWindow());

const gfx::Rect selection_rect = gfx::ToEnclosingRect(box);
for (auto& observer : observers_)
Expand Down
23 changes: 0 additions & 23 deletions ash/scoped_root_window_for_new_windows.cc

This file was deleted.

36 changes: 0 additions & 36 deletions ash/scoped_root_window_for_new_windows.h

This file was deleted.

3 changes: 1 addition & 2 deletions ash/shelf/home_button_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include "ash/shelf/home_button.h"
#include "ash/shelf/shelf_button.h"
#include "ash/shell.h"
#include "ash/shell_state.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "base/bind.h"
#include "base/check_op.h"
Expand Down Expand Up @@ -105,7 +104,7 @@ bool HomeButtonController::MaybeHandleGestureEvent(ui::GestureEvent* event) {
"VoiceInteraction.Started.HomeButtonLongPress"));
assistant_overlay_->BurstAnimation();
event->SetHandled();
Shell::Get()->shell_state()->SetRootWindowForNewWindows(
Shell::SetRootWindowForNewWindows(
button_->GetWidget()->GetNativeWindow()->GetRootWindow());
AssistantUiController::Get()->ShowUi(
AssistantEntryPoint::kLongPressLauncher);
Expand Down
4 changes: 1 addition & 3 deletions ash/shelf/shelf_layout_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
#include "ash/shelf/test/shelf_layout_manager_test_base.h"
#include "ash/shelf/test/widget_animation_waiter.h"
#include "ash/shell.h"
#include "ash/shell_state.h"
#include "ash/system/status_area_widget.h"
#include "ash/system/status_area_widget_test_helper.h"
#include "ash/system/unified/unified_system_tray.h"
Expand Down Expand Up @@ -3556,8 +3555,7 @@ TEST_F(ShelfLayoutManagerTest, VerifyAutoHideBehaviorOnMultipleDisplays) {
// Set focus on the secondary display.
aura::Window* secondary_root_window =
Shell::GetRootWindowForDisplayId(GetSecondaryDisplay().id());
Shell::Get()->shell_state()->SetRootWindowForNewWindows(
secondary_root_window);
Shell::SetRootWindowForNewWindows(secondary_root_window);

// Show the system tray on the secondary display.
Shell::Get()->accelerator_controller()->PerformActionIfEnabled(
Expand Down
15 changes: 8 additions & 7 deletions ash/shelf/shelf_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "ash/public/cpp/shelf_model.h"
#include "ash/public/cpp/shelf_types.h"
#include "ash/public/cpp/window_properties.h"
#include "ash/scoped_root_window_for_new_windows.h"
#include "ash/screen_util.h"
#include "ash/shelf/hotseat_widget.h"
#include "ash/shelf/scrollable_shelf_view.h"
Expand Down Expand Up @@ -56,6 +55,7 @@
#include "ui/compositor/layer_animation_observer.h"
#include "ui/compositor/layer_animator.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/display/scoped_display_for_new_windows.h"
#include "ui/events/event_utils.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/point.h"
Expand Down Expand Up @@ -678,11 +678,12 @@ void ShelfView::ButtonPressed(views::Button* sender,
// to destroy the scoped object just in case the window activation event does
// not get fired.
aura::Window* window = sender->GetWidget()->GetNativeWindow();
scoped_root_window_for_new_windows_ =
std::make_unique<ScopedRootWindowForNewWindows>(window->GetRootWindow());
scoped_display_for_new_windows_ =
std::make_unique<display::ScopedDisplayForNewWindows>(
window->GetRootWindow());
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE,
base::BindOnce(&ShelfView::DestroyScopedRootWindow,
base::BindOnce(&ShelfView::DestroyScopedDisplay,
weak_factory_.GetWeakPtr()),
base::TimeDelta::FromMilliseconds(100));

Expand Down Expand Up @@ -1929,7 +1930,7 @@ void ShelfView::ShelfItemDelegateChanged(const ShelfID& id,
}

void ShelfView::ShelfItemStatusChanged(const ShelfID& id) {
scoped_root_window_for_new_windows_.reset();
scoped_display_for_new_windows_.reset();

int index = model_->ItemIndexByID(id);
if (index < 0)
Expand Down Expand Up @@ -2198,8 +2199,8 @@ void ShelfView::UpdateVisibleIndices() {
last_visible_index_ = model_->item_count() - 1;
}

void ShelfView::DestroyScopedRootWindow() {
scoped_root_window_for_new_windows_.reset();
void ShelfView::DestroyScopedDisplay() {
scoped_display_for_new_windows_.reset();
}

} // namespace ash
13 changes: 8 additions & 5 deletions ash/shelf/shelf_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ namespace ui {
class SimpleMenuModel;
}

namespace display {
class ScopedDisplayForNewWindows;
}

namespace views {
class BoundsAnimator;
class MenuRunner;
Expand All @@ -48,7 +52,6 @@ class Separator;

namespace ash {
class DragImageView;
class ScopedRootWindowForNewWindows;
class ShelfAppButton;
class ShelfButton;
class ShelfModel;
Expand Down Expand Up @@ -492,7 +495,7 @@ class ASH_EXPORT ShelfView : public views::AccessiblePaneView,

bool ShouldHandleGestures(const ui::GestureEvent& event) const;

void DestroyScopedRootWindow();
void DestroyScopedDisplay();

// Different from GetTitleForView, |view| here must be a child view.
base::string16 GetTitleForChildView(const views::View* view) const;
Expand Down Expand Up @@ -551,9 +554,9 @@ class ASH_EXPORT ShelfView : public views::AccessiblePaneView,
std::unique_ptr<ShelfMenuModelAdapter> shelf_menu_model_adapter_;

// Created when a shelf icon is pressed, so that new windows will be on the
// same root window as the press event.
std::unique_ptr<ScopedRootWindowForNewWindows>
scoped_root_window_for_new_windows_;
// same display as the press event.
std::unique_ptr<display::ScopedDisplayForNewWindows>
scoped_display_for_new_windows_;

// True when an item being inserted or removed in the model cancels a drag.
bool cancelling_drag_model_changed_ = false;
Expand Down
15 changes: 10 additions & 5 deletions ash/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
#include "ash/shell_delegate.h"
#include "ash/shell_init_params.h"
#include "ash/shell_observer.h"
#include "ash/shell_state.h"
#include "ash/shutdown_controller_impl.h"
#include "ash/sticky_keys/sticky_keys_controller.h"
#include "ash/style/ash_color_provider.h"
Expand Down Expand Up @@ -309,9 +308,16 @@ aura::Window* Shell::GetPrimaryRootWindow() {
return instance_->window_tree_host_manager_->GetPrimaryRootWindow();
}

// static
void Shell::SetRootWindowForNewWindows(aura::Window* root) {
display::Screen::GetScreen()->SetDisplayForNewWindows(
display::Screen::GetScreen()->GetDisplayNearestWindow(root).id());
}

// static
aura::Window* Shell::GetRootWindowForNewWindows() {
return Shell::Get()->shell_state_->GetRootWindowForNewWindows();
return GetRootWindowForDisplayId(
display::Screen::GetScreen()->GetDisplayForNewWindows().id());
}

// static
Expand Down Expand Up @@ -544,7 +550,6 @@ Shell::Shell(std::unique_ptr<ShellDelegate> shell_delegate)
ash_color_provider_(std::make_unique<AshColorProvider>()),
session_controller_(std::make_unique<SessionControllerImpl>()),
shell_delegate_(std::move(shell_delegate)),
shell_state_(std::make_unique<ShellState>()),
shutdown_controller_(std::make_unique<ShutdownControllerImpl>()),
system_tray_notifier_(std::make_unique<SystemTrayNotifier>()),
window_cycle_controller_(std::make_unique<WindowCycleController>()),
Expand Down Expand Up @@ -981,7 +986,7 @@ void Shell::Init(
// controller.
desks_controller_ = std::make_unique<DesksController>();

shell_state_->SetRootWindowForNewWindows(GetPrimaryRootWindow());
Shell::SetRootWindowForNewWindows(GetPrimaryRootWindow());

resolution_notification_controller_ =
std::make_unique<ResolutionNotificationController>();
Expand Down Expand Up @@ -1321,7 +1326,7 @@ void Shell::OnWindowActivated(
if (!gained_active)
return;

shell_state_->SetRootWindowForNewWindows(gained_active->GetRootWindow());
Shell::SetRootWindowForNewWindows(gained_active->GetRootWindow());
}

void Shell::OnFirstSessionStarted() {
Expand Down
Loading

0 comments on commit 784a832

Please sign in to comment.