Commit 6a02e97a authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

chromeos: implements StackAbove for ws2

BUG=837700
TEST=covered by tests
TBR=tsepez@chromium.org

Change-Id: I9d2fc168a33e9daf00ca9ca9f8b03989122cb848
Reviewed-on: https://chromium-review.googlesource.com/1089201Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#565004}
parent a6f9732f
...@@ -319,7 +319,9 @@ interface WindowTree { ...@@ -319,7 +319,9 @@ interface WindowTree {
DeactivateWindow(uint64 window_id); DeactivateWindow(uint64 window_id);
// Stacks the window |above_id| above |below_id|. These two windows must // Stacks the window |above_id| above |below_id|. These two windows must
// share the same parent. // share the same parent. This function is intended for use with top-levels
// only. For non-top-levels, use ReorderWindow().
// TODO(sky): unify this and ReorderWindow(). https://crbug.com/850133.
StackAbove(uint32 change_id, uint64 above_id, uint64 below_id); StackAbove(uint32 change_id, uint64 above_id, uint64 below_id);
// Stacks the window above all sibling windows. // Stacks the window above all sibling windows.
......
...@@ -843,6 +843,25 @@ bool WindowServiceClient::SetFocusImpl(const ClientWindowId& window_id) { ...@@ -843,6 +843,25 @@ bool WindowServiceClient::SetFocusImpl(const ClientWindowId& window_id) {
return focus_handler_.SetFocus(GetWindowByClientId(window_id)); return focus_handler_.SetFocus(GetWindowByClientId(window_id));
} }
bool WindowServiceClient::StackAboveImpl(
const ClientWindowId& above_window_id,
const ClientWindowId& below_window_id) {
DVLOG(3) << "StackAbove above_window_id=" << above_window_id
<< " below_window_id=" << below_window_id;
aura::Window* above_window = GetWindowByClientId(above_window_id);
aura::Window* below_window = GetWindowByClientId(below_window_id);
// This function only applies to top-levels.
if (!IsClientCreatedWindow(above_window) ||
!IsClientCreatedWindow(below_window) || !IsTopLevel(above_window) ||
!IsTopLevel(below_window) || !above_window->parent() ||
above_window->parent() != below_window->parent()) {
DVLOG(1) << "StackAbove failed (invalid windows)";
return false;
}
above_window->parent()->StackChildAbove(above_window, below_window);
return true;
}
bool WindowServiceClient::StackAtTopImpl(const ClientWindowId& window_id) { bool WindowServiceClient::StackAtTopImpl(const ClientWindowId& window_id) {
DVLOG(3) << "StackAtTop window_id= " << window_id; DVLOG(3) << "StackAtTop window_id= " << window_id;
...@@ -1265,7 +1284,9 @@ void WindowServiceClient::DeactivateWindow(Id window_id) { ...@@ -1265,7 +1284,9 @@ void WindowServiceClient::DeactivateWindow(Id window_id) {
void WindowServiceClient::StackAbove(uint32_t change_id, void WindowServiceClient::StackAbove(uint32_t change_id,
Id above_id, Id above_id,
Id below_id) { Id below_id) {
NOTIMPLEMENTED_LOG_ONCE(); const bool result = StackAboveImpl(MakeClientWindowId(above_id),
MakeClientWindowId(below_id));
window_tree_client_->OnChangeCompleted(change_id, result);
} }
void WindowServiceClient::StackAtTop(uint32_t change_id, Id window_id) { void WindowServiceClient::StackAtTop(uint32_t change_id, Id window_id) {
......
...@@ -235,6 +235,8 @@ class COMPONENT_EXPORT(WINDOW_SERVICE) WindowServiceClient ...@@ -235,6 +235,8 @@ class COMPONENT_EXPORT(WINDOW_SERVICE) WindowServiceClient
mojom::OrderDirection direction); mojom::OrderDirection direction);
std::vector<aura::Window*> GetWindowTreeImpl(const ClientWindowId& window_id); std::vector<aura::Window*> GetWindowTreeImpl(const ClientWindowId& window_id);
bool SetFocusImpl(const ClientWindowId& window_id); bool SetFocusImpl(const ClientWindowId& window_id);
bool StackAboveImpl(const ClientWindowId& above_window_id,
const ClientWindowId& below_window_id);
bool StackAtTopImpl(const ClientWindowId& window_id); bool StackAtTopImpl(const ClientWindowId& window_id);
void GetWindowTreeRecursive(aura::Window* window, void GetWindowTreeRecursive(aura::Window* window,
......
...@@ -117,10 +117,9 @@ Embedding* WindowServiceClientTestHelper::Embed( ...@@ -117,10 +117,9 @@ Embedding* WindowServiceClientTestHelper::Embed(
mojom::WindowTreeClientPtr client_ptr, mojom::WindowTreeClientPtr client_ptr,
mojom::WindowTreeClient* client, mojom::WindowTreeClient* client,
uint32_t embed_flags) { uint32_t embed_flags) {
if (!window_service_client_->EmbedImpl( if (!window_service_client_->EmbedImpl(ClientWindowIdForWindow(window),
window_service_client_->MakeClientWindowId( std::move(client_ptr), client,
TransportIdForWindow(window)), embed_flags)) {
std::move(client_ptr), client, embed_flags)) {
return nullptr; return nullptr;
} }
return ClientWindow::GetMayBeNull(window)->embedding(); return ClientWindow::GetMayBeNull(window)->embedding();
...@@ -139,9 +138,16 @@ void WindowServiceClientTestHelper::OnWindowInputEventAck( ...@@ -139,9 +138,16 @@ void WindowServiceClientTestHelper::OnWindowInputEventAck(
window_service_client_->OnWindowInputEventAck(event_id, result); window_service_client_->OnWindowInputEventAck(event_id, result);
} }
bool WindowServiceClientTestHelper::StackAbove(aura::Window* above_window,
aura::Window* below_window) {
return window_service_client_->StackAboveImpl(
ClientWindowIdForWindow(above_window),
ClientWindowIdForWindow(below_window));
}
bool WindowServiceClientTestHelper::StackAtTop(aura::Window* window) { bool WindowServiceClientTestHelper::StackAtTop(aura::Window* window) {
return window_service_client_->StackAtTopImpl( return window_service_client_->StackAtTopImpl(
window_service_client_->MakeClientWindowId(TransportIdForWindow(window))); ClientWindowIdForWindow(window));
} }
Id WindowServiceClientTestHelper::TransportIdForWindow(aura::Window* window) { Id WindowServiceClientTestHelper::TransportIdForWindow(aura::Window* window) {
...@@ -150,8 +156,7 @@ Id WindowServiceClientTestHelper::TransportIdForWindow(aura::Window* window) { ...@@ -150,8 +156,7 @@ Id WindowServiceClientTestHelper::TransportIdForWindow(aura::Window* window) {
} }
bool WindowServiceClientTestHelper::SetFocus(aura::Window* window) { bool WindowServiceClientTestHelper::SetFocus(aura::Window* window) {
return window_service_client_->SetFocusImpl( return window_service_client_->SetFocusImpl(ClientWindowIdForWindow(window));
window_service_client_->MakeClientWindowId(TransportIdForWindow(window)));
} }
void WindowServiceClientTestHelper::SetCanFocus(aura::Window* window, void WindowServiceClientTestHelper::SetCanFocus(aura::Window* window,
......
...@@ -93,6 +93,7 @@ class WindowServiceClientTestHelper { ...@@ -93,6 +93,7 @@ class WindowServiceClientTestHelper {
bool SetFocus(aura::Window* window); bool SetFocus(aura::Window* window);
void SetCanFocus(aura::Window* window, bool can_focus); void SetCanFocus(aura::Window* window, bool can_focus);
void OnWindowInputEventAck(uint32_t event_id, mojom::EventResult result); void OnWindowInputEventAck(uint32_t event_id, mojom::EventResult result);
bool StackAbove(aura::Window* above_window, aura::Window* below_window);
bool StackAtTop(aura::Window* window); bool StackAtTop(aura::Window* window);
Id TransportIdForWindow(aura::Window* window); Id TransportIdForWindow(aura::Window* window);
......
...@@ -1069,6 +1069,57 @@ TEST(WindowServiceClientTest, ReorderWindow) { ...@@ -1069,6 +1069,57 @@ TEST(WindowServiceClientTest, ReorderWindow) {
top_level, window2, mojom::OrderDirection::ABOVE)); top_level, window2, mojom::OrderDirection::ABOVE));
} }
TEST(WindowServiceClientTest, StackAbove) {
// Create two top-levels.
WindowServiceTestSetup setup;
aura::Window* top_level1 = setup.client_test_helper()->NewTopLevelWindow();
ASSERT_TRUE(top_level1);
aura::Window* top_level2 = setup.client_test_helper()->NewTopLevelWindow();
ASSERT_TRUE(top_level2);
ASSERT_TRUE(top_level1->parent());
ASSERT_EQ(top_level1->parent(), top_level2->parent());
ASSERT_EQ(2u, top_level2->parent()->children().size());
// 1 on top of 2.
EXPECT_TRUE(setup.client_test_helper()->StackAbove(top_level1, top_level2));
EXPECT_EQ(top_level2, top_level2->parent()->children()[0]);
EXPECT_EQ(top_level1, top_level2->parent()->children()[1]);
// Repeat, should still succeed and nothing should change.
EXPECT_TRUE(setup.client_test_helper()->StackAbove(top_level1, top_level2));
EXPECT_EQ(top_level2, top_level2->parent()->children()[0]);
EXPECT_EQ(top_level1, top_level2->parent()->children()[1]);
// 2 on top of 1.
EXPECT_TRUE(setup.client_test_helper()->StackAbove(top_level2, top_level1));
EXPECT_EQ(top_level1, top_level2->parent()->children()[0]);
EXPECT_EQ(top_level2, top_level2->parent()->children()[1]);
// 1 on top of 2, using WindowTree interface, which should result in an ack.
setup.changes()->clear();
uint32_t change_id = 102;
setup.client_test_helper()->window_tree()->StackAbove(
change_id, setup.client_test_helper()->TransportIdForWindow(top_level1),
setup.client_test_helper()->TransportIdForWindow(top_level2));
EXPECT_EQ("ChangeCompleted id=102 success=true",
SingleChangeToDescription(*setup.changes()));
setup.changes()->clear();
EXPECT_EQ(top_level2, top_level2->parent()->children()[0]);
EXPECT_EQ(top_level1, top_level2->parent()->children()[1]);
// Using invalid id should fail.
setup.client_test_helper()->window_tree()->StackAbove(
change_id, setup.client_test_helper()->TransportIdForWindow(top_level1),
kInvalidTransportId);
EXPECT_EQ("ChangeCompleted id=102 success=false",
SingleChangeToDescription(*setup.changes()));
// Using non-top-level should fail.
aura::Window* non_top_level_window = setup.client_test_helper()->NewWindow();
EXPECT_FALSE(
setup.client_test_helper()->StackAbove(top_level1, non_top_level_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