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