Commit 0f1a2fab authored by kylechar's avatar kylechar Committed by Commit bot

Unify mustash display closing code paths.

There are currently two ways a display can be closed in mustash. First,
the NDD can update and indicated the display is gone. Second, when
running off device the user can close the platform window. This CL
unifies the two code paths.

When running off device and the platform window calls
PlatformWindowDelegate::OnRequestClose() the request is forwarded to
PlatformScreen. PlatformScreen then tells the NDD to remove the fake
display. The display configuration will update and the display will be
gone. This allows the same display removed code path to get used in all
cases.

This also fixes PlatformScreen not knowing about the user closing a
display.

BUG=641012

Review-Url: https://codereview.chromium.org/2345043003
Cr-Commit-Position: refs/heads/master@{#419563}
parent 591e68b1
......@@ -37,6 +37,9 @@ class PlatformScreen {
// removed or modified.
virtual void Init(PlatformScreenDelegate* delegate) = 0;
// Handle requests from the platform to close a display.
virtual void RequestCloseDisplay(int64_t display_id) = 0;
virtual int64_t GetPrimaryDisplayId() const = 0;
private:
......
......@@ -64,6 +64,19 @@ void PlatformScreenOzone::Init(PlatformScreenDelegate* delegate) {
display_configurator_.ForceInitialConfigure(kChromeOsBootColor);
}
void PlatformScreenOzone::RequestCloseDisplay(int64_t display_id) {
if (!fake_display_controller_ || wait_for_display_config_update_)
return;
CachedDisplayIterator iter = GetCachedDisplayIterator(display_id);
if (iter != cached_displays_.end()) {
// Tell the NDD to remove the display. PlatformScreen will get an update
// that the display configuration has changed and the display will be gone.
wait_for_display_config_update_ =
fake_display_controller_->RemoveDisplay(iter->id);
}
}
int64_t PlatformScreenOzone::GetPrimaryDisplayId() const {
return primary_display_id_;
}
......
......@@ -37,6 +37,7 @@ class PlatformScreenOzone
// PlatformScreen:
void AddInterfaces(shell::InterfaceRegistry* registry) override;
void Init(PlatformScreenDelegate* delegate) override;
void RequestCloseDisplay(int64_t display_id) override;
int64_t GetPrimaryDisplayId() const override;
// mojom::DisplayController:
......
......@@ -43,6 +43,14 @@ void PlatformScreenStub::Init(PlatformScreenDelegate* delegate) {
weak_ptr_factory_.GetWeakPtr()));
}
void PlatformScreenStub::RequestCloseDisplay(int64_t display_id) {
if (display_id == kDisplayId) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(&PlatformScreenDelegate::OnDisplayRemoved,
base::Unretained(delegate_), display_id));
}
}
int64_t PlatformScreenStub::GetPrimaryDisplayId() const {
return kDisplayId;
}
......
......@@ -27,6 +27,7 @@ class PlatformScreenStub : public PlatformScreen {
// PlatformScreen.
void AddInterfaces(shell::InterfaceRegistry* registry) override;
void Init(PlatformScreenDelegate* delegate) override;
void RequestCloseDisplay(int64_t display_id) override;
int64_t GetPrimaryDisplayId() const override;
PlatformScreenDelegate* delegate_ = nullptr;
......
......@@ -302,10 +302,6 @@ void Display::OnNativeCaptureLost() {
display_root->window_manager_state()->SetCapture(nullptr, kInvalidClientId);
}
void Display::OnDisplayClosed() {
display_manager()->DestroyDisplay(this);
}
void Display::OnViewportMetricsChanged(const ViewportMetrics& old_metrics,
const ViewportMetrics& new_metrics) {
gfx::Rect new_bounds(new_metrics.bounds.size());
......
......@@ -172,7 +172,6 @@ class Display : public PlatformDisplayDelegate,
bool IsInHighContrastMode() override;
void OnEvent(const ui::Event& event) override;
void OnNativeCaptureLost() override;
void OnDisplayClosed() override;
void OnViewportMetricsChanged(const ViewportMetrics& old_metrics,
const ViewportMetrics& new_metrics) override;
void OnCompositorFrameDrawn() override;
......
......@@ -182,7 +182,6 @@ void DisplayManager::OnDisplayRemoved(int64_t id) {
Display* display = GetDisplayById(id);
if (display)
DestroyDisplay(display);
// TODO(kylechar): What if the display is still pending?
}
void DisplayManager::OnDisplayModified(int64_t id, const gfx::Rect& bounds) {
......
......@@ -255,13 +255,10 @@ void DefaultPlatformDisplay::DispatchEvent(ui::Event* event) {
}
void DefaultPlatformDisplay::OnCloseRequest() {
platform_window_->Close();
display::PlatformScreen::GetInstance()->RequestCloseDisplay(GetId());
}
void DefaultPlatformDisplay::OnClosed() {
if (delegate_)
delegate_->OnDisplayClosed();
}
void DefaultPlatformDisplay::OnClosed() {}
void DefaultPlatformDisplay::OnWindowStateChanged(
ui::PlatformWindowState new_state) {}
......
......@@ -28,9 +28,6 @@ class PlatformDisplayDelegate {
virtual bool IsInHighContrastMode() = 0;
// Called when the window managed by the PlatformDisplay is closed.
virtual void OnDisplayClosed() = 0;
// Called when an event arrives.
virtual void OnEvent(const ui::Event& event) = 0;
......
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