Commit 9df5e553 authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

chromeos: wires up capture for ws2

This doesn't include client notification, but it's a good point to
send out for review.

BUG=837696
TEST=covered by tests

Change-Id: I38450a98efa24ee96a3273d3cebe1ea6bc87a5da
Reviewed-on: https://chromium-review.googlesource.com/1060420
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#558902}
parent 06a3103d
...@@ -48,6 +48,7 @@ component("lib") { ...@@ -48,6 +48,7 @@ component("lib") {
"//services/ui/common:mus_common", "//services/ui/common:mus_common",
"//services/ui/public/interfaces", "//services/ui/public/interfaces",
"//ui/aura", "//ui/aura",
"//ui/wm",
] ]
defines = [ "IS_WINDOW_SERVICE_IMPL" ] defines = [ "IS_WINDOW_SERVICE_IMPL" ]
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "ui/compositor/layer_type.h" #include "ui/compositor/layer_type.h"
#include "ui/display/display.h" #include "ui/display/display.h"
#include "ui/display/screen.h" #include "ui/display/screen.h"
#include "ui/wm/core/capture_controller.h"
namespace ui { namespace ui {
namespace ws2 { namespace ws2 {
...@@ -430,6 +431,58 @@ bool WindowServiceClient::DeleteWindowImpl(const ClientWindowId& window_id) { ...@@ -430,6 +431,58 @@ bool WindowServiceClient::DeleteWindowImpl(const ClientWindowId& window_id) {
return true; return true;
} }
bool WindowServiceClient::SetCaptureImpl(const ClientWindowId& window_id) {
DVLOG(3) << "SetCapture window_id=" << window_id;
aura::Window* window = GetWindowByClientId(window_id);
if (!window) {
DVLOG(1) << "SetCapture failed (no window)";
return false;
}
if ((!IsClientCreatedWindow(window) && !IsClientRootWindow(window)) ||
!window->IsVisible() || !window->GetRootWindow()) {
DVLOG(1) << "SetCapture failed (access denied or invalid window)";
return false;
}
wm::CaptureController* capture_controller = wm::CaptureController::Get();
DCHECK(capture_controller);
if (capture_controller->GetCaptureWindow() == window)
return true;
capture_controller->SetCapture(window);
return capture_controller->GetCaptureWindow() == window;
}
bool WindowServiceClient::ReleaseCaptureImpl(const ClientWindowId& window_id) {
DVLOG(3) << "ReleaseCapture window_id=" << window_id;
aura::Window* window = GetWindowByClientId(window_id);
if (!window) {
DVLOG(1) << "ReleaseCapture failed (no window)";
return false;
}
if (!IsClientCreatedWindow(window) && !IsClientRootWindow(window)) {
DVLOG(1) << "ReleaseCapture failed (access denied)";
return false;
}
wm::CaptureController* capture_controller = wm::CaptureController::Get();
DCHECK(capture_controller);
if (!capture_controller->GetCaptureWindow())
return true; // Capture window is already null.
if (capture_controller->GetCaptureWindow() != window) {
DVLOG(1) << "ReleaseCapture failed (supplied window does not have capture)";
return false;
}
capture_controller->ReleaseCapture(window);
return capture_controller->GetCaptureWindow() != window;
}
bool WindowServiceClient::AddWindowImpl(const ClientWindowId& parent_id, bool WindowServiceClient::AddWindowImpl(const ClientWindowId& parent_id,
const ClientWindowId& child_id) { const ClientWindowId& child_id) {
aura::Window* parent = GetWindowByClientId(parent_id); aura::Window* parent = GetWindowByClientId(parent_id);
...@@ -751,12 +804,16 @@ void WindowServiceClient::DeleteWindow(uint32_t change_id, ...@@ -751,12 +804,16 @@ void WindowServiceClient::DeleteWindow(uint32_t change_id,
change_id, DeleteWindowImpl(MakeClientWindowId(transport_window_id))); change_id, DeleteWindowImpl(MakeClientWindowId(transport_window_id)));
} }
void WindowServiceClient::SetCapture(uint32_t change_id, Id window_id) { void WindowServiceClient::SetCapture(uint32_t change_id,
NOTIMPLEMENTED(); Id transport_window_id) {
window_tree_client_->OnChangeCompleted(
change_id, SetCaptureImpl(MakeClientWindowId(transport_window_id)));
} }
void WindowServiceClient::ReleaseCapture(uint32_t change_id, Id window_id) { void WindowServiceClient::ReleaseCapture(uint32_t change_id,
NOTIMPLEMENTED(); Id transport_window_id) {
window_tree_client_->OnChangeCompleted(
change_id, ReleaseCaptureImpl(MakeClientWindowId(transport_window_id)));
} }
void WindowServiceClient::StartPointerWatcher(bool want_moves) { void WindowServiceClient::StartPointerWatcher(bool want_moves) {
......
...@@ -186,6 +186,8 @@ class COMPONENT_EXPORT(WINDOW_SERVICE) WindowServiceClient ...@@ -186,6 +186,8 @@ class COMPONENT_EXPORT(WINDOW_SERVICE) WindowServiceClient
const ClientWindowId& client_window_id, const ClientWindowId& client_window_id,
const std::map<std::string, std::vector<uint8_t>>& properties); const std::map<std::string, std::vector<uint8_t>>& properties);
bool DeleteWindowImpl(const ClientWindowId& window_id); bool DeleteWindowImpl(const ClientWindowId& window_id);
bool SetCaptureImpl(const ClientWindowId& window_id);
bool ReleaseCaptureImpl(const ClientWindowId& window_id);
bool AddWindowImpl(const ClientWindowId& parent_id, bool AddWindowImpl(const ClientWindowId& parent_id,
const ClientWindowId& child_id); const ClientWindowId& child_id);
bool RemoveWindowFromParentImpl(const ClientWindowId& client_window_id); bool RemoveWindowFromParentImpl(const ClientWindowId& client_window_id);
...@@ -225,8 +227,8 @@ class COMPONENT_EXPORT(WINDOW_SERVICE) WindowServiceClient ...@@ -225,8 +227,8 @@ class COMPONENT_EXPORT(WINDOW_SERVICE) WindowServiceClient
const base::flat_map<std::string, std::vector<uint8_t>>& properties) const base::flat_map<std::string, std::vector<uint8_t>>& properties)
override; override;
void DeleteWindow(uint32_t change_id, Id transport_window_id) override; void DeleteWindow(uint32_t change_id, Id transport_window_id) override;
void SetCapture(uint32_t change_id, Id window_id) override; void SetCapture(uint32_t change_id, Id transport_window_id) override;
void ReleaseCapture(uint32_t change_id, Id window_id) override; void ReleaseCapture(uint32_t change_id, Id transport_window_id) override;
void StartPointerWatcher(bool want_moves) override; void StartPointerWatcher(bool want_moves) override;
void StopPointerWatcher() override; void StopPointerWatcher() override;
void SetWindowBounds( void SetWindowBounds(
......
...@@ -43,6 +43,18 @@ aura::Window* WindowServiceClientTestHelper::NewTopLevelWindow( ...@@ -43,6 +43,18 @@ aura::Window* WindowServiceClientTestHelper::NewTopLevelWindow(
window_service_client_->MakeClientWindowId(transport_window_id)); window_service_client_->MakeClientWindowId(transport_window_id));
} }
bool WindowServiceClientTestHelper::SetCapture(aura::Window* window) {
return window_service_client_->SetCaptureImpl(
window_service_client_->MakeClientWindowId(
window_service_client_->TransportIdForWindow(window)));
}
bool WindowServiceClientTestHelper::ReleaseCapture(aura::Window* window) {
return window_service_client_->ReleaseCaptureImpl(
window_service_client_->MakeClientWindowId(
window_service_client_->TransportIdForWindow(window)));
}
void WindowServiceClientTestHelper::SetWindowBounds(aura::Window* window, void WindowServiceClientTestHelper::SetWindowBounds(aura::Window* window,
const gfx::Rect& bounds, const gfx::Rect& bounds,
uint32_t change_id) { uint32_t change_id) {
......
...@@ -52,6 +52,8 @@ class WindowServiceClientTestHelper { ...@@ -52,6 +52,8 @@ class WindowServiceClientTestHelper {
aura::Window* NewTopLevelWindow( aura::Window* NewTopLevelWindow(
Id transport_window_id, Id transport_window_id,
base::flat_map<std::string, std::vector<uint8_t>> properties = {}); base::flat_map<std::string, std::vector<uint8_t>> properties = {});
bool SetCapture(aura::Window* window);
bool ReleaseCapture(aura::Window* window);
void SetWindowBounds(aura::Window* window, void SetWindowBounds(aura::Window* window,
const gfx::Rect& bounds, const gfx::Rect& bounds,
uint32_t change_id = 1); uint32_t change_id = 1);
......
...@@ -502,6 +502,28 @@ TEST(WindowServiceClientTest, PointerWatcher) { ...@@ -502,6 +502,28 @@ TEST(WindowServiceClientTest, PointerWatcher) {
} }
} }
TEST(WindowServiceClientTest, Capture) {
WindowServiceTestHelper helper;
aura::Window* window = helper.helper()->NewWindow(1);
// Setting capture on |window| should fail as it's not visible.
EXPECT_FALSE(helper.helper()->SetCapture(window));
aura::Window* top_level = helper.helper()->NewTopLevelWindow(2);
ASSERT_TRUE(top_level);
EXPECT_FALSE(helper.helper()->SetCapture(top_level));
top_level->Show();
EXPECT_TRUE(helper.helper()->SetCapture(top_level));
EXPECT_FALSE(helper.helper()->ReleaseCapture(window));
EXPECT_TRUE(helper.helper()->ReleaseCapture(top_level));
top_level->AddChild(window);
window->Show();
EXPECT_TRUE(helper.helper()->SetCapture(window));
EXPECT_TRUE(helper.helper()->ReleaseCapture(window));
}
} // namespace } // namespace
} // namespace ws2 } // namespace ws2
} // namespace ui } // namespace ui
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