summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorjonross <jonross@chromium.org>2016-03-08 06:03:26 -0800
committerCommit bot <commit-bot@chromium.org>2016-03-08 14:04:36 +0000
commitc3385cc179280dd4b09733b2954be7e9ae3b5112 (patch)
treefcb8a119477033e1e18f3b8ca5b4bd0b0445b7ea /components
parent1d3dd7dbbeea929087e089ae1e8acdaa4fae80aa (diff)
downloadchromium_src-c3385cc179280dd4b09733b2954be7e9ae3b5112.zip
chromium_src-c3385cc179280dd4b09733b2954be7e9ae3b5112.tar.gz
chromium_src-c3385cc179280dd4b09733b2954be7e9ae3b5112.tar.bz2
Update WindowTree::OnWindowInputEventAck to include handled
To support post-target accelerators we plan to have the client application report whether an input event was handled or not, when ack-ing the event. This change updates WindowTree::OnWindowInputEventAck to include a boolean parameter |handled|. PlatformWindowMus will always mark events as handled. CompositorMusConnection will base the handled state on the ack state of the renderer. TEST=WindowTreeClientImplTest, WindowTreeApptest, WindowTreeTest, CompositorMusConnectionTest BUG=560478 Review URL: https://codereview.chromium.org/1749323002 Cr-Commit-Position: refs/heads/master@{#379821}
Diffstat (limited to 'components')
-rw-r--r--components/mus/public/cpp/input_event_handler.h13
-rw-r--r--components/mus/public/cpp/lib/window_tree_client_impl.cc14
-rw-r--r--components/mus/public/cpp/tests/test_window_tree.cc2
-rw-r--r--components/mus/public/cpp/tests/test_window_tree.h2
-rw-r--r--components/mus/public/cpp/tests/window_tree_client_impl_unittest.cc21
-rw-r--r--components/mus/public/interfaces/window_tree.mojom7
-rw-r--r--components/mus/ws/window_tree.cc2
-rw-r--r--components/mus/ws/window_tree.h2
-rw-r--r--components/mus/ws/window_tree_apptest.cc2
-rw-r--r--components/mus/ws/window_tree_unittest.cc2
10 files changed, 41 insertions, 26 deletions
diff --git a/components/mus/public/cpp/input_event_handler.h b/components/mus/public/cpp/input_event_handler.h
index ebd1597..597653b 100644
--- a/components/mus/public/cpp/input_event_handler.h
+++ b/components/mus/public/cpp/input_event_handler.h
@@ -16,11 +16,14 @@ class Window;
class InputEventHandler {
public:
// The event handler can asynchronously ack the event by taking ownership of
- // the |ack_callback|. If the handler does not take ownership of the callback,
- // then WindowTreeClientImpl will ack the event.
- virtual void OnWindowInputEvent(Window* target,
- mojom::EventPtr event,
- scoped_ptr<base::Closure>* ack_callback) = 0;
+ // the |ack_callback|. The callback takes a bool representing whether the
+ // handler has consumed the event. If the handler does not take ownership of
+ // the callback, then WindowTreeClientImpl will ack the event as not consumed.
+ virtual void OnWindowInputEvent(
+ Window* target,
+ mojom::EventPtr event,
+ scoped_ptr<base::Callback<void(bool)>>* ack_callback) = 0;
+
protected:
virtual ~InputEventHandler() {}
};
diff --git a/components/mus/public/cpp/lib/window_tree_client_impl.cc b/components/mus/public/cpp/lib/window_tree_client_impl.cc
index cdcd7b6..7c0a477 100644
--- a/components/mus/public/cpp/lib/window_tree_client_impl.cc
+++ b/components/mus/public/cpp/lib/window_tree_client_impl.cc
@@ -820,17 +820,21 @@ void WindowTreeClientImpl::OnWindowInputEvent(uint32_t event_id,
mojom::EventPtr event) {
Window* window = GetWindowById(window_id);
if (!window || !window->input_event_handler_) {
- tree_->OnWindowInputEventAck(event_id);
+ tree_->OnWindowInputEventAck(event_id, false);
return;
}
- scoped_ptr<base::Closure> ack_callback(
- new base::Closure(base::Bind(&mojom::WindowTree::OnWindowInputEventAck,
- base::Unretained(tree_), event_id)));
+ scoped_ptr<base::Callback<void(bool)>> ack_callback(
+ new base::Callback<void(bool)>(
+ base::Bind(&mojom::WindowTree::OnWindowInputEventAck,
+ base::Unretained(tree_), event_id)));
window->input_event_handler_->OnWindowInputEvent(window, std::move(event),
&ack_callback);
+
+ // The handler did not take ownership of the callback, so we send the ack,
+ // marking the event as not consumed.
if (ack_callback)
- ack_callback->Run();
+ ack_callback->Run(false);
}
void WindowTreeClientImpl::OnWindowFocused(Id focused_window_id) {
diff --git a/components/mus/public/cpp/tests/test_window_tree.cc b/components/mus/public/cpp/tests/test_window_tree.cc
index 398a661..7301bd9 100644
--- a/components/mus/public/cpp/tests/test_window_tree.cc
+++ b/components/mus/public/cpp/tests/test_window_tree.cc
@@ -132,7 +132,7 @@ void TestWindowTree::SetImeVisibility(uint32_t window_id,
bool visible,
mojo::TextInputStatePtr state) {}
-void TestWindowTree::OnWindowInputEventAck(uint32_t event_id) {
+void TestWindowTree::OnWindowInputEventAck(uint32_t event_id, bool handled) {
EXPECT_FALSE(acked_events_.count(event_id));
acked_events_.insert(event_id);
}
diff --git a/components/mus/public/cpp/tests/test_window_tree.h b/components/mus/public/cpp/tests/test_window_tree.h
index d392341..daaebb30 100644
--- a/components/mus/public/cpp/tests/test_window_tree.h
+++ b/components/mus/public/cpp/tests/test_window_tree.h
@@ -87,7 +87,7 @@ class TestWindowTree : public mojom::WindowTree {
void SetImeVisibility(uint32_t window_id,
bool visible,
mojo::TextInputStatePtr state) override;
- void OnWindowInputEventAck(uint32_t event_id) override;
+ void OnWindowInputEventAck(uint32_t event_id, bool handled) override;
void GetWindowManagerClient(
mojo::AssociatedInterfaceRequest<mojom::WindowManagerClient> internal)
override;
diff --git a/components/mus/public/cpp/tests/window_tree_client_impl_unittest.cc b/components/mus/public/cpp/tests/window_tree_client_impl_unittest.cc
index 69c498b..b822257 100644
--- a/components/mus/public/cpp/tests/window_tree_client_impl_unittest.cc
+++ b/components/mus/public/cpp/tests/window_tree_client_impl_unittest.cc
@@ -27,6 +27,12 @@
#include "ui/events/event_utils.h"
#include "ui/gfx/geometry/rect.h"
+namespace {
+
+void DoNothingBool(bool result) {}
+
+} // namespace
+
namespace mus {
mojo::Array<uint8_t> Int32ToPropertyTransportValue(int32_t value) {
@@ -122,21 +128,22 @@ class TestInputEventHandler : public InputEventHandler {
void AckEvent() {
DCHECK(should_manually_ack_);
DCHECK(!ack_callback_.is_null());
- ack_callback_.Run();
- ack_callback_ = base::Closure();
+ ack_callback_.Run(true);
+ ack_callback_ = base::Bind(&::DoNothingBool);
}
void Reset() {
received_event_ = false;
- ack_callback_ = base::Closure();
+ ack_callback_ = base::Bind(&::DoNothingBool);
}
bool received_event() const { return received_event_; }
private:
// InputEventHandler:
- void OnWindowInputEvent(Window* target,
- mojom::EventPtr event,
- scoped_ptr<base::Closure>* ack_callback) override {
+ void OnWindowInputEvent(
+ Window* target,
+ mojom::EventPtr event,
+ scoped_ptr<base::Callback<void(bool)>>* ack_callback) override {
EXPECT_FALSE(received_event_)
<< "Observer was not reset after receiving event.";
received_event_ = true;
@@ -148,7 +155,7 @@ class TestInputEventHandler : public InputEventHandler {
bool received_event_;
bool should_manually_ack_;
- base::Closure ack_callback_;
+ base::Callback<void(bool)> ack_callback_;
DISALLOW_COPY_AND_ASSIGN(TestInputEventHandler);
};
diff --git a/components/mus/public/interfaces/window_tree.mojom b/components/mus/public/interfaces/window_tree.mojom
index 5114297..09d2972 100644
--- a/components/mus/public/interfaces/window_tree.mojom
+++ b/components/mus/public/interfaces/window_tree.mojom
@@ -246,7 +246,7 @@ interface WindowTree {
SetImeVisibility(uint32 window_id, bool visible, mojo.TextInputState? state);
// See documentation for WindowTreeClient::OnWindowInputEvent().
- OnWindowInputEventAck(uint32 event_id);
+ OnWindowInputEventAck(uint32 event_id, bool handled);
// See description of WindowManager for details.
GetWindowManagerClient(associated WindowManagerClient& internal);
@@ -350,8 +350,9 @@ interface WindowTreeClient {
// Invoked when an event is targeted at the specified window. The client must
// call WindowTree::OnWindowInputEventAck() with the same |event_id| to notify
- // that the event has been processed. The client will not receive farther
- // events until the event is ack'ed.
+ // that the event has been processed, and with a boolean |handled| to notify
+ // if the event was consumed. The client will not receive farther events until
+ // the event is ack'ed.
OnWindowInputEvent(uint32 event_id, uint32 window, Event event);
OnWindowFocused(uint32 focused_window_id);
diff --git a/components/mus/ws/window_tree.cc b/components/mus/ws/window_tree.cc
index 7782e8b..0356a8e 100644
--- a/components/mus/ws/window_tree.cc
+++ b/components/mus/ws/window_tree.cc
@@ -1145,7 +1145,7 @@ void WindowTree::SetImeVisibility(Id transport_window_id,
}
}
-void WindowTree::OnWindowInputEventAck(uint32_t event_id) {
+void WindowTree::OnWindowInputEventAck(uint32_t event_id, bool handled) {
if (event_ack_id_ == 0 || event_id != event_ack_id_) {
// TODO(sad): Something bad happened. Kill the client?
NOTIMPLEMENTED() << "Wrong event acked.";
diff --git a/components/mus/ws/window_tree.h b/components/mus/ws/window_tree.h
index 378186d..0c103e7 100644
--- a/components/mus/ws/window_tree.h
+++ b/components/mus/ws/window_tree.h
@@ -344,7 +344,7 @@ class WindowTree : public mojom::WindowTree,
void SetImeVisibility(Id transport_window_id,
bool visible,
mojo::TextInputStatePtr state) override;
- void OnWindowInputEventAck(uint32_t event_id) override;
+ void OnWindowInputEventAck(uint32_t event_id, bool handled) override;
void SetClientArea(
Id transport_window_id,
mojo::InsetsPtr insets,
diff --git a/components/mus/ws/window_tree_apptest.cc b/components/mus/ws/window_tree_apptest.cc
index 8970435..b143ab0 100644
--- a/components/mus/ws/window_tree_apptest.cc
+++ b/components/mus/ws/window_tree_apptest.cc
@@ -355,7 +355,7 @@ class TestWindowTreeClientImpl : public mojom::WindowTreeClient,
// Ack input events to clear the state on the server. These can be received
// during test startup. X11Window::DispatchEvent sends a synthetic move
// event to notify of entry.
- tree()->OnWindowInputEventAck(event_id);
+ tree()->OnWindowInputEventAck(event_id, true);
// Don't log input events as none of the tests care about them and they
// may come in at random points.
}
diff --git a/components/mus/ws/window_tree_unittest.cc b/components/mus/ws/window_tree_unittest.cc
index 17f59eb..99d88fe 100644
--- a/components/mus/ws/window_tree_unittest.cc
+++ b/components/mus/ws/window_tree_unittest.cc
@@ -198,7 +198,7 @@ class WindowTreeTest : public testing::Test {
void AckPreviousEvent() {
DisplayTestApi test_api(display_);
while (test_api.tree_awaiting_input_ack())
- test_api.tree_awaiting_input_ack()->OnWindowInputEventAck(0);
+ test_api.tree_awaiting_input_ack()->OnWindowInputEventAck(0, true);
}
void DispatchEventAndAckImmediately(const ui::Event& event) {