Revert "Remove SetCanFocus from the window server"
This reverts commit 655fc905aed0ff73f8b510ba1b4fcb9c5faaf474.
Reason for revert: It looks like I'm going to need this to fix 928939
Original change's description:
> Remove SetCanFocus from the window server
>
> I've noticed that this SetCanFocus() method has been there for
> a while but nobody is using it. I believe this is not used anymore.
>
> Bug: none
> Test: none
> Change-Id: Ifb041c696ce4c08a6fc0b45bea35ee3b6c3516f9
> Reviewed-on: https://chromium-review.googlesource.com/c/1447315
> Reviewed-by: Scott Violet <sky@chromium.org>
> Reviewed-by: Tom Sepez <tsepez@chromium.org>
> Commit-Queue: Jun Mukai <mukai@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#629072}
TBR=mukai@chromium.org,sky@chromium.org,tsepez@chromium.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Bug: none
Change-Id: I6ca42ca22d321303d1089d4d36a8e046b7c441a2
Reviewed-on: https://chromium-review.googlesource.com/c/1456682
Reviewed-by: Scott Violet <sky@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#629662}
diff --git a/services/ws/focus_handler.cc b/services/ws/focus_handler.cc
index 1b98a85e..ad9ad5d 100644
--- a/services/ws/focus_handler.cc
+++ b/services/ws/focus_handler.cc
@@ -93,6 +93,15 @@
return true;
}
+void FocusHandler::SetCanFocus(aura::Window* window, bool can_focus) {
+ if (window && (window_tree_->IsClientCreatedWindow(window) ||
+ window_tree_->IsClientRootWindow(window))) {
+ window->SetProperty(kCanFocus, can_focus);
+ } else {
+ DVLOG(1) << "SetCanFocus failed (invalid or unknown window)";
+ }
+}
+
bool FocusHandler::IsFocusableWindow(aura::Window* window) const {
if (!window)
return true; // Used to clear focus.
diff --git a/services/ws/focus_handler.h b/services/ws/focus_handler.h
index c44cbde..f53a92f 100644
--- a/services/ws/focus_handler.h
+++ b/services/ws/focus_handler.h
@@ -27,6 +27,9 @@
// Sets focus to |window| (which may be null). Returns true on success.
bool SetFocus(aura::Window* window);
+ // Sets whether |window| can be focused.
+ void SetCanFocus(aura::Window* window, bool can_focus);
+
private:
// Returns true if |window| can be focused.
bool IsFocusableWindow(aura::Window* window) const;
diff --git a/services/ws/focus_handler_unittest.cc b/services/ws/focus_handler_unittest.cc
index 6df49dd..e166fb2 100644
--- a/services/ws/focus_handler_unittest.cc
+++ b/services/ws/focus_handler_unittest.cc
@@ -11,7 +11,6 @@
#include "services/ws/event_test_utils.h"
#include "services/ws/public/mojom/window_tree_constants.mojom.h"
-#include "services/ws/window_properties.h"
#include "services/ws/window_service.h"
#include "services/ws/window_service_test_setup.h"
#include "services/ws/window_tree_test_helper.h"
@@ -79,13 +78,13 @@
top_level->AddChild(window);
// SetFocus() should still fail as |window| isn't visible.
EXPECT_FALSE(setup.window_tree_test_helper()->SetFocus(window));
- window->SetProperty(kCanFocus, false);
+ setup.window_tree_test_helper()->SetCanFocus(window, false);
window->Show();
- // SetFocus() should fail as kCanFocus is false.
+ // SetFocus() should fail as SetCanFocus(false) was called.
EXPECT_FALSE(setup.window_tree_test_helper()->SetFocus(window));
- window->ClearProperty(kCanFocus);
+ setup.window_tree_test_helper()->SetCanFocus(window, true);
EXPECT_TRUE(setup.window_tree_test_helper()->SetFocus(window));
}
diff --git a/services/ws/public/mojom/window_tree.mojom b/services/ws/public/mojom/window_tree.mojom
index 7559292..dbfe1128 100644
--- a/services/ws/public/mojom/window_tree.mojom
+++ b/services/ws/public/mojom/window_tree.mojom
@@ -290,11 +290,14 @@
// Sets focus to the specified window, use 0 to clear focus. For a window to
// get focus the following has to happen: the window is drawn, the window has
- // been marked as focusable and the window is in a container the WindowManager
- // has identified as allowing activation (see
- // WindowManagerClient::AddActivationParent()).
+ // been marked as focusable (see SetCanFocus()) and the window is in a
+ // container the WindowManager has identified as allowing activation
+ // (see WindowManagerClient::AddActivationParent()).
SetFocus(uint32 change_id, uint64 window_id);
+ // Marks the specified window as being able to receive focus.
+ SetCanFocus(uint64 window_id, bool can_focus);
+
// Sets the cursor when the pointer is inside |window_id|.
SetCursor(uint32 change_id, uint64 window_id, ui.mojom.Cursor cursor);
diff --git a/services/ws/window_tree.cc b/services/ws/window_tree.cc
index 61e7eaab..759c66b0f 100644
--- a/services/ws/window_tree.cc
+++ b/services/ws/window_tree.cc
@@ -1887,6 +1887,11 @@
change_id, SetFocusImpl(MakeClientWindowId(transport_window_id)));
}
+void WindowTree::SetCanFocus(Id transport_window_id, bool can_focus) {
+ focus_handler_.SetCanFocus(GetWindowByTransportId(transport_window_id),
+ can_focus);
+}
+
void WindowTree::SetCursor(uint32_t change_id,
Id transport_window_id,
ui::Cursor cursor) {
diff --git a/services/ws/window_tree.h b/services/ws/window_tree.h
index 3710bc0..b5366847 100644
--- a/services/ws/window_tree.h
+++ b/services/ws/window_tree.h
@@ -455,6 +455,7 @@
uint32_t embed_flags,
EmbedUsingTokenCallback callback) override;
void SetFocus(uint32_t change_id, Id transport_window_id) override;
+ void SetCanFocus(Id transport_window_id, bool can_focus) override;
void SetCursor(uint32_t change_id,
Id transport_window_id,
ui::Cursor cursor) override;
diff --git a/services/ws/window_tree_test_helper.cc b/services/ws/window_tree_test_helper.cc
index 7a066e94..4d98b99 100644
--- a/services/ws/window_tree_test_helper.cc
+++ b/services/ws/window_tree_test_helper.cc
@@ -156,6 +156,11 @@
return window_tree_->SetFocusImpl(ClientWindowIdForWindow(window));
}
+void WindowTreeTestHelper::SetCanFocus(aura::Window* window, bool can_focus) {
+ window_tree_->SetCanFocus(window_tree_->TransportIdForWindow(window),
+ can_focus);
+}
+
void WindowTreeTestHelper::SetCursor(aura::Window* window, ui::Cursor cursor) {
window_tree_->SetCursorImpl(ClientWindowIdForWindow(window), cursor);
}
diff --git a/services/ws/window_tree_test_helper.h b/services/ws/window_tree_test_helper.h
index 9c585d23..f9c4b9e 100644
--- a/services/ws/window_tree_test_helper.h
+++ b/services/ws/window_tree_test_helper.h
@@ -98,6 +98,7 @@
void SetEventTargetingPolicy(aura::Window* window,
mojom::EventTargetingPolicy policy);
bool SetFocus(aura::Window* window);
+ void SetCanFocus(aura::Window* window, bool can_focus);
void SetCursor(aura::Window* window, ui::Cursor cursor);
void OnWindowInputEventAck(uint32_t event_id, mojom::EventResult result);
bool StackAbove(aura::Window* above_window, aura::Window* below_window);
diff --git a/ui/aura/mus/window_tree_client.cc b/ui/aura/mus/window_tree_client.cc
index fc635f4..5764367 100644
--- a/ui/aura/mus/window_tree_client.cc
+++ b/ui/aura/mus/window_tree_client.cc
@@ -229,6 +229,12 @@
return it != windows_.end() ? it->second : nullptr;
}
+void WindowTreeClient::SetCanFocus(Window* window, bool can_focus) {
+ DCHECK(tree_);
+ DCHECK(window);
+ tree_->SetCanFocus(WindowMus::Get(window)->server_id(), can_focus);
+}
+
void WindowTreeClient::SetCursor(WindowMus* window,
const ui::Cursor& old_cursor,
const ui::Cursor& new_cursor) {
diff --git a/ui/aura/mus/window_tree_client.h b/ui/aura/mus/window_tree_client.h
index 6e2b375..5cb9f38 100644
--- a/ui/aura/mus/window_tree_client.h
+++ b/ui/aura/mus/window_tree_client.h
@@ -132,6 +132,7 @@
WindowMus* GetWindowByServerId(ws::Id id);
+ void SetCanFocus(Window* window, bool can_focus);
void SetCanAcceptDrops(WindowMus* window, bool can_accept_drops);
void SetEventTargetingPolicy(WindowMus* window,
ws::mojom::EventTargetingPolicy policy);
diff --git a/ui/aura/test/mus/test_window_tree.cc b/ui/aura/test/mus/test_window_tree.cc
index c789a14..98bf5a3 100644
--- a/ui/aura/test/mus/test_window_tree.cc
+++ b/ui/aura/test/mus/test_window_tree.cc
@@ -332,6 +332,8 @@
OnChangeReceived(change_id, WindowTreeChangeType::FOCUS);
}
+void TestWindowTree::SetCanFocus(ws::Id window_id, bool can_focus) {}
+
void TestWindowTree::SetEventTargetingPolicy(
ws::Id window_id,
ws::mojom::EventTargetingPolicy policy) {}
diff --git a/ui/aura/test/mus/test_window_tree.h b/ui/aura/test/mus/test_window_tree.h
index 0863c99..142c259 100644
--- a/ui/aura/test/mus/test_window_tree.h
+++ b/ui/aura/test/mus/test_window_tree.h
@@ -246,6 +246,7 @@
const viz::FrameSinkId& frame_sink_id) override;
void UnattachFrameSinkId(uint64_t window_id) override;
void SetFocus(uint32_t change_id, ws::Id window_id) override;
+ void SetCanFocus(ws::Id window_id, bool can_focus) override;
void SetEventTargetingPolicy(ws::Id window_id,
ws::mojom::EventTargetingPolicy policy) override;
void SetCursor(uint32_t change_id,