Commit 21f7061b authored by Ahmed Fakhry's avatar Ahmed Fakhry Committed by Commit Bot

Updates embedded surface layer visibility when window is reparented

When the window is reparented from a hidden parent to a visible one,
the embedded surface layer visibility should be updated accordingly.

BUG=956822, 866622
TEST=Manually (see bug), and added a test.

Change-Id: Ib92ddf80f9889d2e001962ca4e3773b88c29f4aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1585235
Commit-Queue: Ahmed Fakhry <afakhry@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#654606}
parent 2d563d11
......@@ -395,6 +395,7 @@ test("aura_unittests") {
"gestures/gesture_recognizer_unittest.cc",
"mouse_location_manager_unittest.cc",
"mus/client_side_window_move_handler_unittest.cc",
"mus/client_surface_embedder_unittest.cc",
"mus/drag_drop_controller_mus_unittest.cc",
"mus/focus_synchronizer_unittest.cc",
"mus/gesture_synchronizer_unittest.cc",
......
......@@ -67,10 +67,22 @@ viz::SurfaceId ClientSurfaceEmbedder::GetSurfaceId() const {
return id ? *id : viz::SurfaceId();
}
ui::Layer* ClientSurfaceEmbedder::GetSurfaceLayerForTesting() const {
return surface_layer_owner_->layer();
}
void ClientSurfaceEmbedder::OnWindowVisibilityChanged(Window* window,
bool visible) {
if (window->Contains(window_))
surface_layer_owner_->layer()->SetVisible(GetTargetVisibility(window_));
}
void ClientSurfaceEmbedder::OnWindowHierarchyChanged(
const HierarchyChangeParams& params) {
// Window may change visibility as a result of being reparented to a different
// parent window with different visibility.
if (params.target == window_)
surface_layer_owner_->layer()->SetVisible(GetTargetVisibility(window_));
}
} // namespace aura
......@@ -13,6 +13,7 @@
namespace ui {
class LayerOwner;
class Layer;
}
namespace viz {
......@@ -38,9 +39,12 @@ class AURA_EXPORT ClientSurfaceEmbedder : public WindowObserver {
// Returns the SurfaceId, empty if SetSurfaceId() has not been called yet.
viz::SurfaceId GetSurfaceId() const;
ui::Layer* GetSurfaceLayerForTesting() const;
private:
// aura::WindowObserver:
void OnWindowVisibilityChanged(Window* window, bool visible) override;
void OnWindowHierarchyChanged(const HierarchyChangeParams& params) override;
// The window which embeds the client.
Window* window_;
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/aura/mus/client_surface_embedder.h"
#include "ui/aura/test/aura_mus_test_base.h"
#include "ui/aura/test/mus/window_port_mus_test_helper.h"
namespace aura {
namespace {
using ClientSurfaceEmbedderTest = test::AuraMusClientTestBase;
// Test that reparenting a window from a hidden parent to a visible one updates
// the embedded surface layer visibility. https://crbug.com/956822.
TEST_F(ClientSurfaceEmbedderTest, SurfaceVisibility) {
std::unique_ptr<Window> parent1(
CreateNormalWindow(100, root_window(), nullptr));
parent1->Show();
std::unique_ptr<Window> parent2(
CreateNormalWindow(200, root_window(), nullptr));
parent2->Show();
std::unique_ptr<Window> window(
CreateNormalWindow(10, parent1.get(), nullptr));
window->Show();
WindowPortMusTestHelper(window.get()).SimulateEmbedding();
ClientSurfaceEmbedder* client_surface_embedder =
WindowPortMusTestHelper(window.get()).GetClientSurfaceEmbedder();
EXPECT_TRUE(window->IsVisible());
EXPECT_TRUE(client_surface_embedder->GetSurfaceLayerForTesting()
->GetTargetVisibility());
// Hide the current parent and expect the visibility will be updated.
parent1->Hide();
EXPECT_FALSE(window->IsVisible());
EXPECT_FALSE(client_surface_embedder->GetSurfaceLayerForTesting()
->GetTargetVisibility());
// Reparent the window from the hidden parent to the visible one.
parent2->AddChild(window.get());
EXPECT_TRUE(window->IsVisible());
EXPECT_TRUE(client_surface_embedder->GetSurfaceLayerForTesting()
->GetTargetVisibility());
}
} // namespace
} // namespace aura
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