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

window-service: wire up DeactivateWindow()

BUG=837684
TEST=covered by tests

Change-Id: I209d2722d8cf5acc09ff51112f69253b9ca0a79c
Reviewed-on: https://chromium-review.googlesource.com/1164417
Commit-Queue: Scott Violet <sky@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#581125}
parent 38894f66
...@@ -78,6 +78,7 @@ component("lib") { ...@@ -78,6 +78,7 @@ component("lib") {
"//ui/aura", "//ui/aura",
"//ui/base/mojo:lib", "//ui/base/mojo:lib",
"//ui/wm", "//ui/wm",
"//ui/wm/public",
] ]
defines = [ "IS_WINDOW_SERVICE_IMPL" ] defines = [ "IS_WINDOW_SERVICE_IMPL" ]
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "ui/gl/test/gl_surface_test_support.h" #include "ui/gl/test/gl_surface_test_support.h"
#include "ui/wm/core/base_focus_rules.h" #include "ui/wm/core/base_focus_rules.h"
#include "ui/wm/core/capture_controller.h" #include "ui/wm/core/capture_controller.h"
#include "ui/wm/public/activation_client.h"
namespace ui { namespace ui {
namespace ws2 { namespace ws2 {
...@@ -50,6 +51,7 @@ WindowServiceTestSetup::WindowServiceTestSetup() ...@@ -50,6 +51,7 @@ WindowServiceTestSetup::WindowServiceTestSetup()
service_ = service_ =
std::make_unique<WindowService>(&delegate_, nullptr, focus_controller()); std::make_unique<WindowService>(&delegate_, nullptr, focus_controller());
aura::client::SetFocusClient(root(), focus_controller()); aura::client::SetFocusClient(root(), focus_controller());
wm::SetActivationClient(root(), focus_controller());
delegate_.set_top_level_parent(aura_test_helper_.root_window()); delegate_.set_top_level_parent(aura_test_helper_.root_window());
window_tree_ = service_->CreateWindowTree(&window_tree_client_); window_tree_ = service_->CreateWindowTree(&window_tree_client_);
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include "ui/wm/core/capture_controller.h" #include "ui/wm/core/capture_controller.h"
#include "ui/wm/core/window_modality_controller.h" #include "ui/wm/core/window_modality_controller.h"
#include "ui/wm/core/window_util.h" #include "ui/wm/core/window_util.h"
#include "ui/wm/public/activation_client.h"
namespace ui { namespace ui {
namespace ws2 { namespace ws2 {
...@@ -1663,8 +1664,34 @@ void WindowTree::OnWindowInputEventAck(uint32_t event_id, ...@@ -1663,8 +1664,34 @@ void WindowTree::OnWindowInputEventAck(uint32_t event_id,
} }
} }
void WindowTree::DeactivateWindow(Id window_id) { void WindowTree::DeactivateWindow(Id transport_window_id) {
NOTIMPLEMENTED_LOG_ONCE(); DVLOG(3) << "DeactivateWindow id="
<< MakeClientWindowId(transport_window_id).ToString();
aura::Window* window = GetWindowByTransportId(transport_window_id);
if (!window) {
DVLOG(1) << "DeactivateWindow failed (no window)";
return;
}
if (!IsClientCreatedWindow(window) || !IsTopLevel(window)) {
DVLOG(1) << "DeactivateWindow failed (access denied)";
return;
}
wm::ActivationClient* activation_client =
wm::GetActivationClient(window->GetRootWindow());
if (!activation_client) {
DVLOG(1) << "DeactivateWindow failed (no activation client)";
return;
}
// Only allow deactivation if |window| is the active window.
if (activation_client->GetActiveWindow() != window) {
DVLOG(1) << "DeactivateWindow failed (window is not active)";
return;
}
activation_client->DeactivateWindow(window);
} }
void WindowTree::StackAbove(uint32_t change_id, Id above_id, Id below_id) { void WindowTree::StackAbove(uint32_t change_id, Id above_id, Id below_id) {
......
...@@ -401,7 +401,7 @@ class COMPONENT_EXPORT(WINDOW_SERVICE) WindowTree ...@@ -401,7 +401,7 @@ class COMPONENT_EXPORT(WINDOW_SERVICE) WindowTree
ui::mojom::EventTargetingPolicy policy) override; ui::mojom::EventTargetingPolicy policy) override;
void OnWindowInputEventAck(uint32_t event_id, void OnWindowInputEventAck(uint32_t event_id,
mojom::EventResult result) override; mojom::EventResult result) override;
void DeactivateWindow(Id window_id) override; void DeactivateWindow(Id transport_window_id) override;
void StackAbove(uint32_t change_id, Id above_id, Id below_id) override; void StackAbove(uint32_t change_id, Id above_id, Id below_id) override;
void StackAtTop(uint32_t change_id, Id window_id) override; void StackAtTop(uint32_t change_id, Id window_id) override;
void PerformWmAction(Id window_id, const std::string& action) override; void PerformWmAction(Id window_id, const std::string& action) override;
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "ui/events/test/event_generator.h" #include "ui/events/test/event_generator.h"
#include "ui/wm/core/capture_controller.h" #include "ui/wm/core/capture_controller.h"
#include "ui/wm/core/focus_controller.h" #include "ui/wm/core/focus_controller.h"
#include "ui/wm/core/window_util.h"
namespace ui { namespace ui {
namespace ws2 { namespace ws2 {
...@@ -1739,6 +1740,36 @@ TEST(WindowTreeTest, DontSendGestures) { ...@@ -1739,6 +1740,36 @@ TEST(WindowTreeTest, DontSendGestures) {
EXPECT_TRUE(setup.window_tree_client()->input_events().empty()); EXPECT_TRUE(setup.window_tree_client()->input_events().empty());
} }
TEST(WindowTreeTest, DeactivateWindow) {
// Create two top-levels and focuses (activates) the second.
WindowServiceTestSetup setup;
aura::Window* top_level1 =
setup.window_tree_test_helper()->NewTopLevelWindow();
ASSERT_TRUE(top_level1);
top_level1->Show();
aura::Window* top_level2 =
setup.window_tree_test_helper()->NewTopLevelWindow();
ASSERT_TRUE(top_level2);
top_level2->Show();
EXPECT_TRUE(setup.window_tree_test_helper()->SetFocus(top_level2));
EXPECT_TRUE(wm::IsActiveWindow(top_level2));
// Attempting to deactivate |top_level1| should do nothing.
setup.window_tree_test_helper()->window_tree()->DeactivateWindow(
setup.window_tree_test_helper()->TransportIdForWindow(top_level1));
EXPECT_TRUE(wm::IsActiveWindow(top_level2));
// Similarly, calling Deactivate() with an invalid id should do nothing.
setup.window_tree_test_helper()->window_tree()->DeactivateWindow(
kInvalidTransportId);
EXPECT_TRUE(wm::IsActiveWindow(top_level2));
// Deactivate() with |top_level2| should activate |top_level1|.
setup.window_tree_test_helper()->window_tree()->DeactivateWindow(
setup.window_tree_test_helper()->TransportIdForWindow(top_level2));
EXPECT_TRUE(wm::IsActiveWindow(top_level1));
}
} // 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