Commit 5c5c5e83 authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

window-service: propagates client-area-insets to ClientSurfaceEmbedder

The client area insets of a top-level need to be propagated to the
ClientSurfaceEmbedder.

BUG=869501
TEST=covered by tests

Change-Id: Id5aca98e46d596e8e43c7ea71150f59a0db638da
Reviewed-on: https://chromium-review.googlesource.com/1252145
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarFady Samuel <fsamuel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595604}
parent 304ea83e
......@@ -119,6 +119,8 @@ static_library("test_support") {
testonly = true
sources = [
"client_root_test_helper.cc",
"client_root_test_helper.h",
"event_test_utils.cc",
"event_test_utils.h",
"server_window_test_helper.cc",
......
......@@ -29,9 +29,6 @@ ClientRoot::ClientRoot(WindowTree* window_tree,
window_->AddObserver(this);
if (window_->GetHost())
window->GetHost()->AddObserver(this);
// TODO: wire up gfx::Insets() correctly below. See usage in
// aura::ClientSurfaceEmbedder for details. Insets here are used for
// guttering.
client_surface_embedder_ = std::make_unique<aura::ClientSurfaceEmbedder>(
window_, is_top_level, gfx::Insets());
// Ensure there is a valid LocalSurfaceId (if necessary).
......@@ -50,6 +47,13 @@ ClientRoot::~ClientRoot() {
server_window->frame_sink_id());
}
void ClientRoot::SetClientAreaInsets(const gfx::Insets& client_area_insets) {
if (!is_top_level_)
return;
client_surface_embedder_->SetClientAreaInsets(client_area_insets);
}
void ClientRoot::RegisterVizEmbeddingSupport() {
// This function should only be called once.
viz::HostFrameSinkManager* host_frame_sink_manager =
......
......@@ -21,6 +21,10 @@ class ClientSurfaceEmbedder;
class Window;
} // namespace aura
namespace gfx {
class Insets;
}
namespace viz {
class SurfaceInfo;
}
......@@ -43,6 +47,11 @@ class COMPONENT_EXPORT(WINDOW_SERVICE) ClientRoot
ClientRoot(WindowTree* window_tree, aura::Window* window, bool is_top_level);
~ClientRoot() override;
// Called when the client area of the window changes. If the window is a
// top-level window, then this propagates the insets to the
// ClientSurfaceEmbedder.
void SetClientAreaInsets(const gfx::Insets& client_area_insets);
// Registers the necessary state needed for embedding in viz.
void RegisterVizEmbeddingSupport();
......@@ -61,6 +70,8 @@ class COMPONENT_EXPORT(WINDOW_SERVICE) ClientRoot
void UnattachChildFrameSinkIdRecursive(ServerWindow* server_window);
private:
friend class ClientRootTestHelper;
void UpdatePrimarySurfaceId();
// Returns true if the WindowService should assign the LocalSurfaceId. A value
......
// Copyright 2018 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 "services/ws/client_root_test_helper.h"
#include "services/ws/client_root.h"
namespace ws {
ClientRootTestHelper::ClientRootTestHelper(ClientRoot* client_root)
: client_root_(client_root) {}
ClientRootTestHelper::~ClientRootTestHelper() = default;
aura::ClientSurfaceEmbedder* ClientRootTestHelper::GetClientSurfaceEmbedder() {
return client_root_->client_surface_embedder_.get();
}
} // namespace ws
// Copyright 2018 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.
#ifndef SERVICES_WS_CLIENT_ROOT_TEST_HELPER_H_
#define SERVICES_WS_CLIENT_ROOT_TEST_HELPER_H_
#include "base/macros.h"
#include "ui/events/event.h"
namespace aura {
class ClientSurfaceEmbedder;
}
namespace ws {
class ClientRoot;
// Used for accessing private members of ServerWindow in tests.
class ClientRootTestHelper {
public:
explicit ClientRootTestHelper(ClientRoot* client_root);
~ClientRootTestHelper();
aura::ClientSurfaceEmbedder* GetClientSurfaceEmbedder();
private:
ClientRoot* client_root_;
DISALLOW_COPY_AND_ASSIGN(ClientRootTestHelper);
};
} // namespace ws
#endif // SERVICES_WS_CLIENT_ROOT_TEST_HELPER_H_
......@@ -8,6 +8,7 @@
#include "base/containers/flat_map.h"
#include "components/viz/host/host_frame_sink_manager.h"
#include "services/ws/client_root.h"
#include "services/ws/drag_drop_delegate.h"
#include "services/ws/embedding.h"
#include "services/ws/public/mojom/window_tree_constants.mojom.h"
......@@ -498,6 +499,11 @@ void ServerWindow::SetClientArea(
additional_client_areas_ = additional_client_areas;
client_area_ = insets;
ClientRoot* client_root =
owning_window_tree_ ? owning_window_tree_->GetClientRootForWindow(window_)
: nullptr;
if (client_root)
client_root->SetClientAreaInsets(insets);
}
void ServerWindow::SetHitTestInsets(const gfx::Insets& mouse,
......
......@@ -7,11 +7,13 @@
#include <memory>
#include "base/run_loop.h"
#include "services/ws/client_root_test_helper.h"
#include "services/ws/window_service_test_setup.h"
#include "services/ws/window_tree.h"
#include "services/ws/window_tree_test_helper.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/mus/client_surface_embedder.h"
#include "ui/events/event.h"
#include "ui/events/event_constants.h"
#include "ui/wm/core/easy_resize_window_targeter.h"
......@@ -87,4 +89,22 @@ TEST(ServerWindow, FindTargetForWindowWithResizeInset) {
setup.root(), &mouse_event_2));
}
TEST(ServerWindow, SetClientAreaPropagatesToClientSurfaceEmbedder) {
WindowServiceTestSetup setup;
aura::Window* top_level =
setup.window_tree_test_helper()->NewTopLevelWindow();
ASSERT_TRUE(top_level);
const gfx::Rect top_level_bounds(100, 200, 200, 200);
top_level->SetBounds(top_level_bounds);
const gfx::Insets top_level_insets(1, 2, 11, 12);
setup.window_tree_test_helper()->SetClientArea(top_level, top_level_insets);
aura::ClientSurfaceEmbedder* client_surface_embedder =
ClientRootTestHelper(
setup.window_tree()->GetClientRootForWindow(top_level))
.GetClientSurfaceEmbedder();
ASSERT_TRUE(client_surface_embedder);
EXPECT_EQ(top_level_insets, client_surface_embedder->client_area_insets());
}
} // namespace ws
......@@ -307,6 +307,11 @@ ClientWindowId WindowTree::ClientWindowIdForWindow(aura::Window* window) const {
: iter->second.client_window_id;
}
ClientRoot* WindowTree::GetClientRootForWindow(aura::Window* window) {
auto iter = FindClientRootWithRoot(window);
return iter == client_roots_.end() ? nullptr : iter->get();
}
ClientRoot* WindowTree::CreateClientRoot(aura::Window* window,
bool is_top_level) {
DCHECK(window);
......
......@@ -135,6 +135,10 @@ class COMPONENT_EXPORT(WINDOW_SERVICE) WindowTree
ClientWindowId ClientWindowIdForWindow(aura::Window* window) const;
// If |window| is a client root, the ClientRoot is returned. This does not
// recurse.
ClientRoot* GetClientRootForWindow(aura::Window* window);
private:
friend class ClientRoot;
// TODO(sky): WindowTree should be refactored such that it is not
......
......@@ -50,6 +50,16 @@ void ClientSurfaceEmbedder::SetFallbackSurfaceInfo(
UpdateSizeAndGutters();
}
void ClientSurfaceEmbedder::SetClientAreaInsets(
const gfx::Insets& client_area_insets) {
if (client_area_insets_ == client_area_insets)
return;
client_area_insets_ = client_area_insets;
if (inject_gutter_)
UpdateSizeAndGutters();
}
void ClientSurfaceEmbedder::UpdateSizeAndGutters() {
surface_layer_owner_->layer()->SetBounds(gfx::Rect(window_->bounds().size()));
if (!inject_gutter_)
......
......@@ -41,6 +41,9 @@ class AURA_EXPORT ClientSurfaceEmbedder {
// updated.
void SetFallbackSurfaceInfo(const viz::SurfaceInfo& surface_info);
void SetClientAreaInsets(const gfx::Insets& client_area_insets);
const gfx::Insets& client_area_insets() const { return client_area_insets_; }
// Update the surface layer size and the right and bottom gutter layers for
// the current window size.
void UpdateSizeAndGutters();
......
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