Commit dd3a8f54 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Misc. cleanup.

* Make SetScreenInstance() return the previous screen instance.  This
  will easily let callers save/restore screen instances.
* Use ProcessDisplayChanged() in an applicable spot.
* Stop overriding GetDisplayMatching() in DesktopScreenWin.  The parent
  class definition is more accurate, and this looks to be an ancient
  artifact.
* Replace some DISALLOW_COPY_AND_ASSIGN.
* Various other stuff

Bug: none
Change-Id: Ic6d545c828e5ec68f015cc7677b6ce74cc14e286
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2145631
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Reviewed-by: default avatarStéphane Marchesin <marcheu@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759950}
parent 858b3481
...@@ -35,12 +35,10 @@ class TestScreen : public display::ScreenBase { ...@@ -35,12 +35,10 @@ class TestScreen : public display::ScreenBase {
void AddDisplay(const gfx::Rect& bounds, void AddDisplay(const gfx::Rect& bounds,
const gfx::Rect& work_area) { const gfx::Rect& work_area) {
display::Display display(display_list().displays().size(), bounds); const int num_displays = GetNumDisplays();
display::Display display(num_displays, bounds);
display.set_work_area(work_area); display.set_work_area(work_area);
display_list().AddDisplay(display, ProcessDisplayChanged(display, num_displays == 0);
display_list().displays().empty()
? display::DisplayList::Type::PRIMARY
: display::DisplayList::Type::NOT_PRIMARY);
} }
private: private:
......
...@@ -119,8 +119,10 @@ ShellPlatformDataAura::ShellPlatformDataAura(const gfx::Size& initial_size) { ...@@ -119,8 +119,10 @@ ShellPlatformDataAura::ShellPlatformDataAura(const gfx::Size& initial_size) {
} }
ShellPlatformDataAura::~ShellPlatformDataAura() { ShellPlatformDataAura::~ShellPlatformDataAura() {
#if defined(USE_OZONE)
if (screen_) if (screen_)
display::Screen::SetScreenInstance(nullptr); display::Screen::SetScreenInstance(nullptr);
#endif
} }
void ShellPlatformDataAura::ShowWindow() { void ShellPlatformDataAura::ShowWindow() {
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <memory> #include <memory>
#include "base/macros.h" #include "base/macros.h"
#include "build/build_config.h"
#include "ui/aura/window_tree_host.h" #include "ui/aura/window_tree_host.h"
namespace aura { namespace aura {
...@@ -18,9 +19,11 @@ class WindowParentingClient; ...@@ -18,9 +19,11 @@ class WindowParentingClient;
} }
} }
#if defined(USE_OZONE)
namespace display { namespace display {
class Screen; class Screen;
} }
#endif
namespace gfx { namespace gfx {
class Size; class Size;
...@@ -39,7 +42,9 @@ class ShellPlatformDataAura { ...@@ -39,7 +42,9 @@ class ShellPlatformDataAura {
aura::WindowTreeHost* host() { return host_.get(); } aura::WindowTreeHost* host() { return host_.get(); }
private: private:
#if defined(USE_OZONE)
std::unique_ptr<display::Screen> screen_; std::unique_ptr<display::Screen> screen_;
#endif
std::unique_ptr<aura::WindowTreeHost> host_; std::unique_ptr<aura::WindowTreeHost> host_;
std::unique_ptr<aura::client::FocusClient> focus_client_; std::unique_ptr<aura::client::FocusClient> focus_client_;
......
...@@ -363,7 +363,7 @@ ShellDesktopControllerAura::CreateRootWindowControllerForDisplay( ...@@ -363,7 +363,7 @@ ShellDesktopControllerAura::CreateRootWindowControllerForDisplay(
gfx::Rect bounds(gfx::ScaleToFlooredPoint(display.bounds().origin(), gfx::Rect bounds(gfx::ScaleToFlooredPoint(display.bounds().origin(),
display.device_scale_factor()), display.device_scale_factor()),
display.GetSizeInPixel()); display.GetSizeInPixel());
std::unique_ptr<RootWindowController> root_window_controller = auto root_window_controller =
std::make_unique<RootWindowController>(this, bounds, browser_context_); std::make_unique<RootWindowController>(this, bounds, browser_context_);
// Initialize the root window with our clients. // Initialize the root window with our clients.
...@@ -392,13 +392,9 @@ void ShellDesktopControllerAura::TearDownRootWindowController( ...@@ -392,13 +392,9 @@ void ShellDesktopControllerAura::TearDownRootWindowController(
} }
void ShellDesktopControllerAura::MaybeQuit() { void ShellDesktopControllerAura::MaybeQuit() {
// run_loop_ may be null in tests.
if (!run_loop_)
return;
// Quit if there are no app windows open and no keep-alives waiting for apps // Quit if there are no app windows open and no keep-alives waiting for apps
// to relaunch. // to relaunch. |run_loop_| may be null in tests.
if (root_window_controllers_.empty() && if (run_loop_ && root_window_controllers_.empty() &&
!KeepAliveRegistry::GetInstance()->IsKeepingAlive()) { !KeepAliveRegistry::GetInstance()->IsKeepingAlive()) {
run_loop_->QuitWhenIdle(); run_loop_->QuitWhenIdle();
} }
...@@ -406,7 +402,7 @@ void ShellDesktopControllerAura::MaybeQuit() { ...@@ -406,7 +402,7 @@ void ShellDesktopControllerAura::MaybeQuit() {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
gfx::Size ShellDesktopControllerAura::GetStartingWindowSize() { gfx::Size ShellDesktopControllerAura::GetStartingWindowSize() {
gfx::Size size; gfx::Size size = GetPrimaryDisplaySize();
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kAppShellHostWindowSize)) { if (command_line->HasSwitch(switches::kAppShellHostWindowSize)) {
const std::string size_str = const std::string size_str =
...@@ -414,22 +410,16 @@ gfx::Size ShellDesktopControllerAura::GetStartingWindowSize() { ...@@ -414,22 +410,16 @@ gfx::Size ShellDesktopControllerAura::GetStartingWindowSize() {
int width, height; int width, height;
CHECK_EQ(2, sscanf(size_str.c_str(), "%dx%d", &width, &height)); CHECK_EQ(2, sscanf(size_str.c_str(), "%dx%d", &width, &height));
size = gfx::Size(width, height); size = gfx::Size(width, height);
} else {
size = GetPrimaryDisplaySize();
} }
if (size.IsEmpty()) return size.IsEmpty() ? gfx::Size(1920, 1080) : size;
size = gfx::Size(1920, 1080);
return size;
} }
gfx::Size ShellDesktopControllerAura::GetPrimaryDisplaySize() { gfx::Size ShellDesktopControllerAura::GetPrimaryDisplaySize() {
const display::DisplayConfigurator::DisplayStateList& displays = const display::DisplayConfigurator::DisplayStateList& displays =
display_configurator_->cached_displays(); display_configurator_->cached_displays();
if (displays.empty()) const display::DisplayMode* mode =
return gfx::Size(); displays.empty() ? nullptr : displays[0]->current_mode();
const display::DisplayMode* mode = displays[0]->current_mode();
return mode ? mode->size() : gfx::Size(); return mode ? mode->size() : gfx::Size();
return gfx::Size();
} }
#endif #endif
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "ui/display/screen.h" #include "ui/display/screen.h"
#include <utility>
#include "ui/display/display.h" #include "ui/display/display.h"
#include "ui/display/types/display_constants.h" #include "ui/display/types/display_constants.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
...@@ -31,8 +33,8 @@ Screen* Screen::GetScreen() { ...@@ -31,8 +33,8 @@ Screen* Screen::GetScreen() {
} }
// static // static
void Screen::SetScreenInstance(Screen* instance) { Screen* Screen::SetScreenInstance(Screen* instance) {
g_screen = instance; return std::exchange(g_screen, instance);
} }
Display Screen::GetDisplayNearestView(gfx::NativeView view) const { Display Screen::GetDisplayNearestView(gfx::NativeView view) const {
......
...@@ -37,9 +37,10 @@ class DISPLAY_EXPORT Screen { ...@@ -37,9 +37,10 @@ class DISPLAY_EXPORT Screen {
// Retrieves the single Screen object. // Retrieves the single Screen object.
static Screen* GetScreen(); static Screen* GetScreen();
// Sets the global screen. NOTE: this does not take ownership of |screen|. // Sets the global screen. Returns the previously installed screen, if any.
// Tests must be sure to reset any state they install. // NOTE: this does not take ownership of |screen|. Tests must be sure to reset
static void SetScreenInstance(Screen* instance); // any state they install.
static Screen* SetScreenInstance(Screen* instance);
// Returns the current absolute position of the mouse pointer. // Returns the current absolute position of the mouse pointer.
virtual gfx::Point GetCursorScreenPoint() = 0; virtual gfx::Point GetCursorScreenPoint() = 0;
......
...@@ -11,21 +11,16 @@ namespace win { ...@@ -11,21 +11,16 @@ namespace win {
namespace test { namespace test {
ScopedScreenWin::ScopedScreenWin() : ScreenWin(false) { ScopedScreenWin::ScopedScreenWin() : ScreenWin(false) {
const gfx::Rect pixel_bounds = gfx::Rect(0, 0, 1920, 1200); constexpr gfx::Rect kPixelBounds(0, 0, 1920, 1200);
const gfx::Rect pixel_work = gfx::Rect(0, 0, 1920, 1100); constexpr gfx::Rect kPixelWork(0, 0, 1920, 1100);
MONITORINFOEX monitor_info = const MONITORINFOEX monitor_info =
CreateMonitorInfo(pixel_bounds, pixel_work, L"primary"); CreateMonitorInfo(kPixelBounds, kPixelWork, L"primary");
std::vector<DisplayInfo> display_infos; UpdateFromDisplayInfos({{monitor_info, 1.0f /* device_scale_factor*/, 1.0f,
display_infos.push_back( Display::ROTATE_0, 60, gfx::Vector2dF(96.0, 96.0)}});
DisplayInfo(monitor_info, 1.0f /* device_scale_factor*/, 1.0f,
Display::ROTATE_0, 60, gfx::Vector2dF(96.0, 96.0)));
UpdateFromDisplayInfos(display_infos);
previous_screen_ = Screen::GetScreen();
Screen::SetScreenInstance(this);
} }
ScopedScreenWin::~ScopedScreenWin() { ScopedScreenWin::~ScopedScreenWin() {
Screen::SetScreenInstance(previous_screen_); Screen::SetScreenInstance(old_screen_);
} }
} // namespace test } // namespace test
......
...@@ -22,7 +22,8 @@ class ScopedScreenWin : public ScreenWin { ...@@ -22,7 +22,8 @@ class ScopedScreenWin : public ScreenWin {
~ScopedScreenWin() override; ~ScopedScreenWin() override;
private: private:
Screen* previous_screen_; Screen* old_screen_ = Screen::SetScreenInstance(this);
DISALLOW_COPY_AND_ASSIGN(ScopedScreenWin); DISALLOW_COPY_AND_ASSIGN(ScopedScreenWin);
}; };
......
...@@ -4,40 +4,26 @@ ...@@ -4,40 +4,26 @@
#include "ui/views/widget/desktop_aura/desktop_screen_win.h" #include "ui/views/widget/desktop_aura/desktop_screen_win.h"
#include "base/logging.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/aura/window_tree_host.h" #include "ui/aura/window_tree_host.h"
#include "ui/display/display.h"
#include "ui/views/widget/desktop_aura/desktop_screen.h" #include "ui/views/widget/desktop_aura/desktop_screen.h"
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h" #include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h"
namespace views { namespace views {
////////////////////////////////////////////////////////////////////////////////
// DesktopScreenWin, public:
DesktopScreenWin::DesktopScreenWin() = default; DesktopScreenWin::DesktopScreenWin() = default;
DesktopScreenWin::~DesktopScreenWin() = default; DesktopScreenWin::~DesktopScreenWin() = default;
////////////////////////////////////////////////////////////////////////////////
// DesktopScreenWin, display::win::ScreenWin implementation:
display::Display DesktopScreenWin::GetDisplayMatching(
const gfx::Rect& match_rect) const {
return GetDisplayNearestPoint(match_rect.CenterPoint());
}
HWND DesktopScreenWin::GetHWNDFromNativeWindow(gfx::NativeWindow window) const { HWND DesktopScreenWin::GetHWNDFromNativeWindow(gfx::NativeWindow window) const {
aura::WindowTreeHost* host = window->GetHost(); aura::WindowTreeHost* host = window->GetHost();
return host ? host->GetAcceleratedWidget() : nullptr; return host ? host->GetAcceleratedWidget() : nullptr;
} }
gfx::NativeWindow DesktopScreenWin::GetNativeWindowFromHWND(HWND hwnd) const { gfx::NativeWindow DesktopScreenWin::GetNativeWindowFromHWND(HWND hwnd) const {
return (::IsWindow(hwnd)) return ::IsWindow(hwnd)
? DesktopWindowTreeHostWin::GetContentWindowForHWND(hwnd) ? DesktopWindowTreeHostWin::GetContentWindowForHWND(hwnd)
: nullptr; : gfx::kNullNativeWindow;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#ifndef UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_SCREEN_WIN_H_ #ifndef UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_SCREEN_WIN_H_
#define UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_SCREEN_WIN_H_ #define UI_VIEWS_WIDGET_DESKTOP_AURA_DESKTOP_SCREEN_WIN_H_
#include "base/macros.h"
#include "ui/display/win/screen_win.h" #include "ui/display/win/screen_win.h"
#include "ui/views/views_export.h" #include "ui/views/views_export.h"
...@@ -14,16 +13,14 @@ namespace views { ...@@ -14,16 +13,14 @@ namespace views {
class VIEWS_EXPORT DesktopScreenWin : public display::win::ScreenWin { class VIEWS_EXPORT DesktopScreenWin : public display::win::ScreenWin {
public: public:
DesktopScreenWin(); DesktopScreenWin();
DesktopScreenWin(const DesktopScreenWin&) = delete;
DesktopScreenWin& operator=(const DesktopScreenWin&) = delete;
~DesktopScreenWin() override; ~DesktopScreenWin() override;
private: private:
// Overridden from display::win::ScreenWin: // display::win::ScreenWin:
display::Display GetDisplayMatching(
const gfx::Rect& match_rect) const override;
HWND GetHWNDFromNativeWindow(gfx::NativeWindow window) const override; HWND GetHWNDFromNativeWindow(gfx::NativeWindow window) const override;
gfx::NativeWindow GetNativeWindowFromHWND(HWND hwnd) const override; gfx::NativeWindow GetNativeWindowFromHWND(HWND hwnd) const override;
DISALLOW_COPY_AND_ASSIGN(DesktopScreenWin);
}; };
} // namespace views } // namespace views
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "base/macros.h"
#include "content/shell/browser/shell_browser_context.h" #include "content/shell/browser/shell_browser_context.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
#include "ui/views/widget/desktop_aura/desktop_screen.h" #include "ui/views/widget/desktop_aura/desktop_screen.h"
...@@ -19,13 +18,14 @@ class ViewsContentClientMainPartsDesktopAura ...@@ -19,13 +18,14 @@ class ViewsContentClientMainPartsDesktopAura
ViewsContentClientMainPartsDesktopAura( ViewsContentClientMainPartsDesktopAura(
const content::MainFunctionParams& content_params, const content::MainFunctionParams& content_params,
ViewsContentClient* views_content_client); ViewsContentClient* views_content_client);
~ViewsContentClientMainPartsDesktopAura() override {} ViewsContentClientMainPartsDesktopAura(
const ViewsContentClientMainPartsDesktopAura&) = delete;
ViewsContentClientMainPartsDesktopAura& operator=(
const ViewsContentClientMainPartsDesktopAura&) = delete;
~ViewsContentClientMainPartsDesktopAura() override = default;
// content::BrowserMainParts: // ViewsContentClientMainPartsAura:
void PreMainMessageLoopRun() override; void PreMainMessageLoopRun() override;
private:
DISALLOW_COPY_AND_ASSIGN(ViewsContentClientMainPartsDesktopAura);
}; };
ViewsContentClientMainPartsDesktopAura::ViewsContentClientMainPartsDesktopAura( ViewsContentClientMainPartsDesktopAura::ViewsContentClientMainPartsDesktopAura(
......
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