Commit a4f0d394 authored by Jun Mukai's avatar Jun Mukai Committed by Commit Bot

Synchronize ClientSurfaceEmbedder visibility with its window

Bug: 936603
Test: manually
Change-Id: I2b83069342dc094c097a5d26b6a63cd9ac5364ce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1506662
Commit-Queue: Jun Mukai <mukai@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#638401}
parent 6eced5f2
......@@ -10,6 +10,21 @@
#include "ui/gfx/geometry/dip_util.h"
namespace aura {
namespace {
// Returns the target visibility respecting the window hierarchy. It returns
// true only when the target visibility of the window and all its ancestors are
// true. This can check if the window is going to be drawn without the effect
// of LayerAnimator.
bool GetTargetVisibility(aura::Window* window) {
if (!window)
return false;
while (window && window->TargetVisibility())
window = window->parent();
return window == nullptr;
}
} // namespace
ClientSurfaceEmbedder::ClientSurfaceEmbedder(Window* window)
: window_(window),
......@@ -20,6 +35,7 @@ ClientSurfaceEmbedder::ClientSurfaceEmbedder(Window* window)
// The frame provided by the parent window->layer() needs to show through
// the surface layer.
surface_layer_owner_->layer()->SetFillsBoundsOpaquely(false);
surface_layer_owner_->layer()->SetVisible(GetTargetVisibility(window_));
window_->layer()->Add(surface_layer_owner_->layer());
......@@ -27,9 +43,12 @@ ClientSurfaceEmbedder::ClientSurfaceEmbedder(Window* window)
// this is the case with window decorations provided by Window Manager.
// This content should appear underneath the content of the embedded client.
window_->layer()->StackAtTop(surface_layer_owner_->layer());
window_->AddObserver(this);
}
ClientSurfaceEmbedder::~ClientSurfaceEmbedder() = default;
ClientSurfaceEmbedder::~ClientSurfaceEmbedder() {
window_->RemoveObserver(this);
}
void ClientSurfaceEmbedder::SetSurfaceId(const viz::SurfaceId& surface_id) {
// Set the background to transparent to avoid a flash of color before the
......@@ -48,4 +67,10 @@ viz::SurfaceId ClientSurfaceEmbedder::GetSurfaceId() const {
return id ? *id : viz::SurfaceId();
}
void ClientSurfaceEmbedder::OnWindowVisibilityChanged(Window* window,
bool visible) {
if (window->Contains(window_))
surface_layer_owner_->layer()->SetVisible(GetTargetVisibility(window_));
}
} // namespace aura
......@@ -9,6 +9,7 @@
#include "base/macros.h"
#include "ui/aura/aura_export.h"
#include "ui/aura/window_observer.h"
namespace ui {
class LayerOwner;
......@@ -23,11 +24,12 @@ namespace aura {
class Window;
// Used to display content from another client. The other client is rendering
// to viz using the SurfaceId supplied to SetSurfaceId().
class AURA_EXPORT ClientSurfaceEmbedder {
// to viz using the SurfaceId supplied to SetSurfaceId(). This class can't
// outlive the window.
class AURA_EXPORT ClientSurfaceEmbedder : public WindowObserver {
public:
explicit ClientSurfaceEmbedder(Window* window);
~ClientSurfaceEmbedder();
~ClientSurfaceEmbedder() override;
// Sets the current SurfaceId *and* updates the size of the layer to match
// that of the window.
......@@ -37,6 +39,9 @@ class AURA_EXPORT ClientSurfaceEmbedder {
viz::SurfaceId GetSurfaceId() const;
private:
// aura::WindowObserver:
void OnWindowVisibilityChanged(Window* window, bool visible) override;
// The window which embeds the client.
Window* window_;
......
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