summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
Diffstat (limited to 'components')
-rw-r--r--components/html_viewer/html_frame.cc21
-rw-r--r--components/html_viewer/html_frame.h11
-rw-r--r--components/mus/public/cpp/input_event_handler.h30
-rw-r--r--components/mus/public/cpp/lib/window.cc1
-rw-r--r--components/mus/public/cpp/lib/window_tree_client_impl.cc16
-rw-r--r--components/mus/public/cpp/tests/BUILD.gn2
-rw-r--r--components/mus/public/cpp/tests/test_window_tree.cc11
-rw-r--r--components/mus/public/cpp/tests/test_window_tree.h5
-rw-r--r--components/mus/public/cpp/tests/window_tree_client_impl_unittest.cc75
-rw-r--r--components/mus/public/cpp/window.h6
-rw-r--r--components/mus/public/cpp/window_observer.h5
-rw-r--r--components/pdf_viewer/pdf_viewer.cc19
12 files changed, 174 insertions, 28 deletions
diff --git a/components/html_viewer/html_frame.cc b/components/html_viewer/html_frame.cc
index 1ddb997..50a183d 100644
--- a/components/html_viewer/html_frame.cc
+++ b/components/html_viewer/html_frame.cc
@@ -584,11 +584,15 @@ web_view::mojom::Frame* HTMLFrame::GetServerFrame() {
}
void HTMLFrame::SetWindow(mus::Window* window) {
- if (window_)
+ if (window_) {
+ window_->set_input_event_handler(nullptr);
window_->RemoveObserver(this);
+ }
window_ = window;
- if (window_)
+ if (window_) {
window_->AddObserver(this);
+ window_->set_input_event_handler(this);
+ }
}
void HTMLFrame::CreateRootWebWidget() {
@@ -757,8 +761,14 @@ void HTMLFrame::OnWindowDestroyed(mus::Window* window) {
Close();
}
+void HTMLFrame::OnWindowFocusChanged(mus::Window* gained_focus,
+ mus::Window* lost_focus) {
+ UpdateFocus();
+}
+
void HTMLFrame::OnWindowInputEvent(mus::Window* window,
- const mus::mojom::EventPtr& event) {
+ mus::mojom::EventPtr event,
+ scoped_ptr<base::Closure>* ack_callback) {
if (event->pointer_data && event->pointer_data->location) {
// Blink expects coordintes to be in DIPs.
event->pointer_data->location->x /= global_state()->device_pixel_ratio();
@@ -794,11 +804,6 @@ void HTMLFrame::OnWindowInputEvent(mus::Window* window,
web_widget->handleInputEvent(*web_event);
}
-void HTMLFrame::OnWindowFocusChanged(mus::Window* gained_focus,
- mus::Window* lost_focus) {
- UpdateFocus();
-}
-
void HTMLFrame::OnConnect(
web_view::mojom::FramePtr frame,
uint32_t change_id,
diff --git a/components/html_viewer/html_frame.h b/components/html_viewer/html_frame.h
index 9f108ac..1439c6a2 100644
--- a/components/html_viewer/html_frame.h
+++ b/components/html_viewer/html_frame.h
@@ -13,6 +13,7 @@
#include "cc/layers/surface_layer.h"
#include "components/html_viewer/html_frame_tree_manager.h"
#include "components/html_viewer/replicated_frame_state.h"
+#include "components/mus/public/cpp/input_event_handler.h"
#include "components/mus/public/cpp/window_observer.h"
#include "components/web_view/public/interfaces/frame.mojom.h"
#include "mojo/public/cpp/bindings/binding.h"
@@ -70,7 +71,8 @@ class WebLayerTreeViewImpl;
class HTMLFrame : public blink::WebFrameClient,
public blink::WebRemoteFrameClient,
public web_view::mojom::FrameClient,
- public mus::WindowObserver {
+ public mus::WindowObserver,
+ public mus::InputEventHandler {
public:
struct CreateParams {
CreateParams(
@@ -270,11 +272,14 @@ class HTMLFrame : public blink::WebFrameClient,
const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) override;
void OnWindowDestroyed(mus::Window* window) override;
- void OnWindowInputEvent(mus::Window* window,
- const mus::mojom::EventPtr& event) override;
void OnWindowFocusChanged(mus::Window* gained_focus,
mus::Window* lost_focus) override;
+ // mus::InputEventHandler:
+ void OnWindowInputEvent(mus::Window* window,
+ mus::mojom::EventPtr event,
+ scoped_ptr<base::Closure>* ack_callback) override;
+
// web_view::mojom::FrameClient:
void OnConnect(web_view::mojom::FramePtr server,
uint32_t change_id,
diff --git a/components/mus/public/cpp/input_event_handler.h b/components/mus/public/cpp/input_event_handler.h
new file mode 100644
index 0000000..ebd1597
--- /dev/null
+++ b/components/mus/public/cpp/input_event_handler.h
@@ -0,0 +1,30 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_MUS_PUBLIC_CPP_INPUT_EVENT_HANDLER_H_
+#define COMPONENTS_MUS_PUBLIC_CPP_INPUT_EVENT_HANDLER_H_
+
+#include "base/callback_forward.h"
+#include "components/mus/public/interfaces/input_events.mojom.h"
+
+namespace mus {
+
+class Window;
+
+// Responsible for processing input events for mus::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;
+ protected:
+ virtual ~InputEventHandler() {}
+};
+
+} // namespace mus
+
+#endif // COMPONENTS_MUS_PUBLIC_CPP_INPUT_EVENT_HANDLER_H_
diff --git a/components/mus/public/cpp/lib/window.cc b/components/mus/public/cpp/lib/window.cc
index 084bac5..c09438c 100644
--- a/components/mus/public/cpp/lib/window.cc
+++ b/components/mus/public/cpp/lib/window.cc
@@ -408,6 +408,7 @@ Window::Window()
parent_(nullptr),
stacking_target_(nullptr),
transient_parent_(nullptr),
+ input_event_handler_(nullptr),
viewport_metrics_(CreateEmptyViewportMetrics()),
visible_(true),
drawn_(false) {}
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 570c9b5..4e0d946 100644
--- a/components/mus/public/cpp/lib/window_tree_client_impl.cc
+++ b/components/mus/public/cpp/lib/window_tree_client_impl.cc
@@ -6,6 +6,7 @@
#include "base/bind.h"
#include "components/mus/common/util.h"
+#include "components/mus/public/cpp/input_event_handler.h"
#include "components/mus/public/cpp/lib/in_flight_change.h"
#include "components/mus/public/cpp/lib/window_private.h"
#include "components/mus/public/cpp/window_manager_delegate.h"
@@ -640,11 +641,18 @@ void WindowTreeClientImpl::OnWindowInputEvent(uint32_t event_id,
Id window_id,
mojom::EventPtr event) {
Window* window = GetWindowById(window_id);
- if (window) {
- FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(window).observers(),
- OnWindowInputEvent(window, event));
+ if (!window || !window->input_event_handler_) {
+ tree_->OnWindowInputEventAck(event_id);
+ return;
}
- tree_->OnWindowInputEventAck(event_id);
+
+ scoped_ptr<base::Closure> ack_callback(
+ new base::Closure(base::Bind(&mojom::WindowTree::OnWindowInputEventAck,
+ base::Unretained(tree_), event_id)));
+ window->input_event_handler_->OnWindowInputEvent(window, std::move(event),
+ &ack_callback);
+ if (ack_callback)
+ ack_callback->Run();
}
void WindowTreeClientImpl::OnWindowFocused(Id focused_window_id) {
diff --git a/components/mus/public/cpp/tests/BUILD.gn b/components/mus/public/cpp/tests/BUILD.gn
index b9cf72b..a8492a0 100644
--- a/components/mus/public/cpp/tests/BUILD.gn
+++ b/components/mus/public/cpp/tests/BUILD.gn
@@ -53,11 +53,13 @@ test("mojo_view_manager_lib_unittests") {
"//components/mus/public/cpp",
"//mojo/application/public/cpp",
"//mojo/converters/geometry",
+ "//mojo/converters/input_events",
"//mojo/gles2",
"//mojo/platform_handle:platform_handle_impl",
"//mojo/public/cpp/system",
"//testing/gtest",
"//third_party/mojo/src/mojo/edk/system",
+ "//ui/events",
"//ui/gfx:test_support",
"//ui/gfx/geometry",
"//ui/mojo/geometry:interfaces",
diff --git a/components/mus/public/cpp/tests/test_window_tree.cc b/components/mus/public/cpp/tests/test_window_tree.cc
index 1d70f32..d1f7945 100644
--- a/components/mus/public/cpp/tests/test_window_tree.cc
+++ b/components/mus/public/cpp/tests/test_window_tree.cc
@@ -4,6 +4,8 @@
#include "components/mus/public/cpp/tests/test_window_tree.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
namespace mus {
TestWindowTree::TestWindowTree() : got_change_(false), change_id_(0) {}
@@ -20,6 +22,10 @@ bool TestWindowTree::GetAndClearChangeId(uint32_t* change_id) {
return true;
}
+bool TestWindowTree::WasEventAcked(uint32_t event_id) const {
+ return acked_events_.count(event_id);
+}
+
void TestWindowTree::NewWindow(
uint32_t change_id,
uint32_t window_id,
@@ -106,7 +112,10 @@ 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) {
+ EXPECT_FALSE(acked_events_.count(event_id));
+ acked_events_.insert(event_id);
+}
void TestWindowTree::WmResponse(uint32_t change_id, bool response) {}
} // namespace mus
diff --git a/components/mus/public/cpp/tests/test_window_tree.h b/components/mus/public/cpp/tests/test_window_tree.h
index 8a35699..a61c8c9 100644
--- a/components/mus/public/cpp/tests/test_window_tree.h
+++ b/components/mus/public/cpp/tests/test_window_tree.h
@@ -5,6 +5,8 @@
#ifndef COMPONENTS_MUS_PUBLIC_CPP_TESTS_TEST_WINDOW_TREE_H_
#define COMPONENTS_MUS_PUBLIC_CPP_TESTS_TEST_WINDOW_TREE_H_
+#include <set>
+
#include "base/macros.h"
#include "components/mus/public/interfaces/window_tree.mojom.h"
@@ -21,6 +23,8 @@ class TestWindowTree : public mojom::WindowTree {
// invoked since the last GetAndClearChangeId().
bool GetAndClearChangeId(uint32_t* change_id);
+ bool WasEventAcked(uint32_t event_id) const;
+
private:
// mojom::WindowTree:
void NewWindow(
@@ -78,6 +82,7 @@ class TestWindowTree : public mojom::WindowTree {
bool got_change_;
uint32_t change_id_;
+ std::set<uint32_t> acked_events_;
DISALLOW_COPY_AND_ASSIGN(TestWindowTree);
};
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 5c61a40..14542b8 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
@@ -6,6 +6,7 @@
#include "base/logging.h"
#include "components/mus/common/util.h"
+#include "components/mus/public/cpp/input_event_handler.h"
#include "components/mus/public/cpp/lib/window_private.h"
#include "components/mus/public/cpp/property_type_converters.h"
#include "components/mus/public/cpp/tests/test_window.h"
@@ -15,7 +16,10 @@
#include "components/mus/public/cpp/window_property.h"
#include "components/mus/public/cpp/window_tree_delegate.h"
#include "mojo/converters/geometry/geometry_type_converters.h"
+#include "mojo/converters/input_events/input_events_type_converters.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "ui/events/event.h"
+#include "ui/events/event_utils.h"
#include "ui/gfx/geometry/rect.h"
namespace mus {
@@ -96,6 +100,48 @@ class WindowTreeSetup {
DISALLOW_COPY_AND_ASSIGN(WindowTreeSetup);
};
+class TestInputEventHandler : public InputEventHandler {
+ public:
+ TestInputEventHandler()
+ : received_event_(false), should_manually_ack_(false) {}
+ ~TestInputEventHandler() override {}
+
+ void set_should_manually_ack() { should_manually_ack_ = true; }
+
+ void AckEvent() {
+ DCHECK(should_manually_ack_);
+ DCHECK(!ack_callback_.is_null());
+ ack_callback_.Run();
+ ack_callback_ = base::Closure();
+ }
+
+ void Reset() {
+ received_event_ = false;
+ ack_callback_ = base::Closure();
+ }
+ bool received_event() const { return received_event_; }
+
+ private:
+ // InputEventHandler:
+ void OnWindowInputEvent(Window* target,
+ mojom::EventPtr event,
+ scoped_ptr<base::Closure>* ack_callback) override {
+ EXPECT_FALSE(received_event_)
+ << "Observer was not reset after receiving event.";
+ received_event_ = true;
+ if (should_manually_ack_) {
+ ack_callback_ = *ack_callback->get();
+ ack_callback->reset();
+ }
+ }
+
+ bool received_event_;
+ bool should_manually_ack_;
+ base::Closure ack_callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestInputEventHandler);
+};
+
using WindowTreeClientImplTest = testing::Test;
// Verifies bounds are reverted if the server replied that the change failed.
@@ -276,6 +322,35 @@ TEST_F(WindowTreeClientImplTest, SetVisibleFailedWithPendingChange) {
EXPECT_EQ(original_visible, root->visible());
}
+TEST_F(WindowTreeClientImplTest, InputEventBasic) {
+ WindowTreeSetup setup;
+ Window* root = setup.window_tree_connection()->GetRoot();
+ ASSERT_TRUE(root);
+
+ TestInputEventHandler event_handler;
+ root->set_input_event_handler(&event_handler);
+
+ scoped_ptr<ui::Event> ui_event(
+ new ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(),
+ ui::EventTimeForNow(), ui::EF_NONE, 0));
+ mojom::EventPtr mus_event = mojom::Event::From(*ui_event);
+ setup.window_tree_client()->OnWindowInputEvent(1, root->id(),
+ std::move(mus_event));
+ EXPECT_TRUE(event_handler.received_event());
+ EXPECT_TRUE(setup.window_tree()->WasEventAcked(1));
+ event_handler.Reset();
+
+ event_handler.set_should_manually_ack();
+ mus_event = mojom::Event::From(*ui_event);
+ setup.window_tree_client()->OnWindowInputEvent(33, root->id(),
+ std::move(mus_event));
+ EXPECT_TRUE(event_handler.received_event());
+ EXPECT_FALSE(setup.window_tree()->WasEventAcked(33));
+
+ event_handler.AckEvent();
+ EXPECT_TRUE(setup.window_tree()->WasEventAcked(33));
+}
+
// Verifies focus is reverted if the server replied that the change failed.
TEST_F(WindowTreeClientImplTest, SetFocusFailed) {
WindowTreeSetup setup;
diff --git a/components/mus/public/cpp/window.h b/components/mus/public/cpp/window.h
index 8005cf4..6ed39dd 100644
--- a/components/mus/public/cpp/window.h
+++ b/components/mus/public/cpp/window.h
@@ -26,6 +26,7 @@ class Size;
namespace mus {
+class InputEventHandler;
class ServiceProviderImpl;
class WindowObserver;
class WindowSurface;
@@ -143,6 +144,10 @@ class Window {
template <typename T>
void ClearLocalProperty(const WindowProperty<T>* property);
+ void set_input_event_handler(InputEventHandler* input_event_handler) {
+ input_event_handler_ = input_event_handler;
+ }
+
// Observation.
void AddObserver(WindowObserver* observer);
void RemoveObserver(WindowObserver* observer);
@@ -282,6 +287,7 @@ class Window {
Children transient_children_;
base::ObserverList<WindowObserver> observers_;
+ InputEventHandler* input_event_handler_;
gfx::Rect bounds_;
gfx::Insets client_area_;
diff --git a/components/mus/public/cpp/window_observer.h b/components/mus/public/cpp/window_observer.h
index b0b3597..52cc179 100644
--- a/components/mus/public/cpp/window_observer.h
+++ b/components/mus/public/cpp/window_observer.h
@@ -8,7 +8,6 @@
#include <vector>
#include "components/mus/public/cpp/window.h"
-#include "components/mus/public/interfaces/input_events.mojom.h"
namespace mus {
@@ -67,10 +66,6 @@ class WindowObserver {
virtual void OnWindowPredefinedCursorChanged(Window* window,
mojom::Cursor cursor) {}
-
- virtual void OnWindowInputEvent(Window* window,
- const mojom::EventPtr& event) {}
-
virtual void OnWindowVisibilityChanging(Window* window) {}
virtual void OnWindowVisibilityChanged(Window* window) {}
diff --git a/components/pdf_viewer/pdf_viewer.cc b/components/pdf_viewer/pdf_viewer.cc
index 5dc9097..870be0c 100644
--- a/components/pdf_viewer/pdf_viewer.cc
+++ b/components/pdf_viewer/pdf_viewer.cc
@@ -8,6 +8,7 @@
#include "base/memory/scoped_ptr.h"
#include "components/bitmap_uploader/bitmap_uploader.h"
#include "components/mus/common/types.h"
+#include "components/mus/public/cpp/input_event_handler.h"
#include "components/mus/public/cpp/scoped_window_ptr.h"
#include "components/mus/public/cpp/window.h"
#include "components/mus/public/cpp/window_observer.h"
@@ -42,6 +43,7 @@ namespace {
// Responsible for managing a particlar view displaying a PDF document.
class PDFView : public mus::WindowTreeDelegate,
public mus::WindowObserver,
+ public mus::InputEventHandler,
public web_view::mojom::FrameClient,
public mojo::InterfaceFactory<web_view::mojom::FrameClient> {
public:
@@ -105,6 +107,7 @@ class PDFView : public mus::WindowTreeDelegate,
DCHECK(!root_);
root_ = root;
root_->AddObserver(this);
+ root_->set_input_event_handler(this);
bitmap_uploader_.reset(new bitmap_uploader::BitmapUploader(root_));
bitmap_uploader_->Init(shell_);
bitmap_uploader_->SetColor(g_background_color);
@@ -123,8 +126,16 @@ class PDFView : public mus::WindowTreeDelegate,
DrawBitmap();
}
+ void OnWindowDestroyed(mus::Window* view) override {
+ DCHECK_EQ(root_, view);
+ root_ = nullptr;
+ bitmap_uploader_.reset();
+ }
+
+ // mus::InputEventHandler:
void OnWindowInputEvent(mus::Window* view,
- const mus::mojom::EventPtr& event) override {
+ mus::mojom::EventPtr event,
+ scoped_ptr<base::Closure>* ack_callback) override {
if (event->key_data &&
(event->action != mus::mojom::EVENT_TYPE_KEY_PRESSED ||
event->key_data->is_char)) {
@@ -153,12 +164,6 @@ class PDFView : public mus::WindowTreeDelegate,
}
}
- void OnWindowDestroyed(mus::Window* view) override {
- DCHECK_EQ(root_, view);
- root_ = nullptr;
- bitmap_uploader_.reset();
- }
-
// web_view::mojom::FrameClient:
void OnConnect(web_view::mojom::FramePtr frame,
uint32_t change_id,