Commit e32cba92 authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

window-service: makes WindowTree::AddTransientChild use WindowParentingClient

This gives similar behavior to NativeWidgetAura, where it calls to the
WindowParentingClient from init. This is necessary to ensure the right parent
is picked up for transients created from the lock screen. In such a scenario
the transient needs to be placed in the lock screen container. That was
previously done by way of NativeWidgetAura calling to ParentWindowWithContext().
This gives similar behavior.

BUG=945281
TEST=covered by test

Change-Id: Id4ad2c5485988be05c256e8a38358790aff89948
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1540278Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#644526}
parent 2abe2821
......@@ -33,6 +33,7 @@
#include "services/ws/window_service_observer.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/transient_window_client.h"
#include "ui/aura/client/window_parenting_client.h"
#include "ui/aura/env.h"
#include "ui/aura/mus/os_exchange_data_provider_mus.h"
#include "ui/aura/mus/property_converter.h"
......@@ -1003,6 +1004,19 @@ bool WindowTree::AddTransientWindowImpl(const ClientWindowId& parent_id,
}
::wm::AddTransientChild(parent, transient);
// Transients are placed in a container by way of the WindowParentingClient.
// This code is simular to NativeWidgetAura, where it calls to
// ParentWindowWithContext().
if (IsTopLevel(parent) && parent->GetRootWindow() && IsTopLevel(transient) &&
transient->GetRootWindow()) {
aura::client::WindowParentingClient* client =
aura::client::GetWindowParentingClient(parent);
aura::Window* default_parent =
client->GetDefaultParent(transient, transient->GetBoundsInScreen());
if (default_parent && transient->parent() != default_parent)
default_parent->AddChild(transient);
}
return true;
}
......
......@@ -34,6 +34,7 @@
#include "ui/aura/test/aura_test_helper.h"
#include "ui/aura/test/test_screen.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/test/test_window_parenting_client.h"
#include "ui/aura/test/window_occlusion_tracker_test_api.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tracker.h"
......@@ -2597,5 +2598,31 @@ TEST(WindowTreeTest, SetWindowTransform) {
EXPECT_EQ(scaled, child_window->transform());
}
TEST(WindowTreeTest, AddingTransientGoesThroughParentingClient) {
WindowServiceTestSetup setup;
aura::test::TestWindowParentingClient test_window_parenting_client(
setup.aura_test_helper()->root_window());
WindowTreeTestHelper* helper = setup.window_tree_test_helper();
aura::Window* top_level = helper->NewTopLevelWindow();
ASSERT_TRUE(top_level);
aura::Window* transient = helper->NewTopLevelWindow();
ASSERT_TRUE(transient);
// Put |top_level| in |container|.
aura::Window container(nullptr);
container.Init(ui::LAYER_NOT_DRAWN);
top_level->parent()->AddChild(&container);
container.AddChild(top_level);
test_window_parenting_client.set_default_parent(&container);
EXPECT_NE(&container, transient->parent());
// AddTransientWindow() should trigger calling into the WindowParentingClient,
// which will result in adding |transient| as a child of |container|.
helper->window_tree()->AddTransientWindow(
10, helper->TransportIdForWindow(top_level),
helper->TransportIdForWindow(transient));
EXPECT_EQ(&container, transient->parent());
}
} // namespace
} // namespace ws
......@@ -33,7 +33,8 @@ class AURA_EXPORT WindowParentingClient {
AURA_EXPORT void SetWindowParentingClient(
Window* window,
WindowParentingClient* window_tree_client);
WindowParentingClient* GetWindowParentingClient(Window* window);
AURA_EXPORT WindowParentingClient* GetWindowParentingClient(Window* window);
// Adds |window| to an appropriate parent by consulting an implementation of
// WindowParentingClient attached at the root Window containing |context|. The
......
......@@ -20,7 +20,7 @@ TestWindowParentingClient::~TestWindowParentingClient() {
Window* TestWindowParentingClient::GetDefaultParent(Window* window,
const gfx::Rect& bounds) {
return root_window_;
return default_parent_ ? default_parent_ : root_window_;
}
} // namespace test
......
......@@ -17,12 +17,17 @@ class TestWindowParentingClient : public client::WindowParentingClient {
explicit TestWindowParentingClient(Window* root_window);
~TestWindowParentingClient() override;
void set_default_parent(Window* parent) { default_parent_ = parent; }
// Overridden from client::WindowParentingClient:
Window* GetDefaultParent(Window* window, const gfx::Rect& bounds) override;
private:
Window* root_window_;
// If non-null this is returned from GetDefaultParent().
Window* default_parent_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(TestWindowParentingClient);
};
......
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