Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(478)

Unified Diff: ui/views/mus/native_widget_mus.cc

Issue 1979573002: Move mus::InputEventHandler implementation and tests from PlatformWindowMus to NativeWidgetMus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@native_widget_mus5
Patch Set: Drop multiple copies of unittests (AGAIN) Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/mus/native_widget_mus.h ('k') | ui/views/mus/native_widget_mus_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/mus/native_widget_mus.cc
diff --git a/ui/views/mus/native_widget_mus.cc b/ui/views/mus/native_widget_mus.cc
index 2210ebdc99c0ee3ec4dbe78b42aae0bd4fbea179..d90116ac4f0a4c82fa2ea8bddfa4e1c28cb291c3 100644
--- a/ui/views/mus/native_widget_mus.cc
+++ b/ui/views/mus/native_widget_mus.cc
@@ -4,7 +4,9 @@
#include "ui/views/mus/native_widget_mus.h"
+#include "base/callback.h"
#include "base/macros.h"
+#include "base/message_loop/message_loop.h"
#include "base/threading/thread_task_runner_handle.h"
#include "components/mus/public/cpp/property_type_converters.h"
#include "components/mus/public/cpp/window.h"
@@ -14,6 +16,7 @@
#include "components/mus/public/interfaces/cursor.mojom.h"
#include "components/mus/public/interfaces/window_manager.mojom.h"
#include "components/mus/public/interfaces/window_manager_constants.mojom.h"
+#include "components/mus/public/interfaces/window_tree.mojom.h"
#include "mojo/converters/geometry/geometry_type_converters.h"
#include "ui/aura/client/default_capture_client.h"
#include "ui/aura/client/window_tree_client.h"
@@ -23,6 +26,7 @@
#include "ui/aura/window.h"
#include "ui/aura/window_property.h"
#include "ui/base/hit_test.h"
+#include "ui/events/event.h"
#include "ui/gfx/canvas.h"
#include "ui/native_theme/native_theme_aura.h"
#include "ui/platform_window/platform_window_delegate.h"
@@ -43,6 +47,8 @@
DECLARE_WINDOW_PROPERTY_TYPE(mus::Window*);
+using mus::mojom::EventResult;
+
namespace views {
namespace {
@@ -297,6 +303,44 @@ SkBitmap AppIconFromDelegate(WidgetDelegate* delegate) {
return app_icon.GetRepresentation(1.f).sk_bitmap();
}
+// Handles acknowledgement of an input event, either immediately when a nested
+// message loop starts, or upon destruction.
+class EventAckHandler : public base::MessageLoop::NestingObserver {
+ public:
+ explicit EventAckHandler(
+ std::unique_ptr<base::Callback<void(EventResult)>> ack_callback)
+ : ack_callback_(std::move(ack_callback)) {
+ DCHECK(ack_callback_);
+ base::MessageLoop::current()->AddNestingObserver(this);
+ }
+
+ ~EventAckHandler() override {
+ base::MessageLoop::current()->RemoveNestingObserver(this);
+ if (ack_callback_) {
+ ack_callback_->Run(handled_ ? EventResult::HANDLED
+ : EventResult::UNHANDLED);
+ }
+ }
+
+ void set_handled(bool handled) { handled_ = handled; }
+
+ // base::MessageLoop::NestingObserver:
+ void OnBeginNestedMessageLoop() override {
+ // Acknowledge the event immediately if a nested message loop starts.
+ // Otherwise we appear unresponsive for the life of the nested message loop.
+ if (ack_callback_) {
+ ack_callback_->Run(EventResult::HANDLED);
+ ack_callback_.reset();
+ }
+ }
+
+ private:
+ std::unique_ptr<base::Callback<void(EventResult)>> ack_callback_;
+ bool handled_ = false;
+
+ DISALLOW_COPY_AND_ASSIGN(EventAckHandler);
+};
+
} // namespace
class NativeWidgetMus::MusWindowObserver : public mus::WindowObserver {
@@ -1219,6 +1263,23 @@ void NativeWidgetMus::OnHostCloseRequested(const aura::WindowTreeHost* host) {
GetWidget()->Close();
}
+void NativeWidgetMus::OnWindowInputEvent(
+ mus::Window* view,
+ const ui::Event& event_in,
+ std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) {
+ // Take ownership of the callback, indicating that we will handle it.
+ EventAckHandler ack_handler(std::move(*ack_callback));
+
+ std::unique_ptr<ui::Event> event = ui::Event::Clone(event_in);
+ // TODO(markdittmer): This should be this->OnEvent(event.get()), but that
+ // can't happen until IME is refactored out of in WindowTreeHostMus.
+ platform_window_delegate()->DispatchEvent(event.get());
+ // NOTE: |this| may be deleted.
+
+ ack_handler.set_handled(event->handled());
+ // |ack_handler| acks the event on destruction if necessary.
+}
+
void NativeWidgetMus::OnMusWindowVisibilityChanging(mus::Window* window) {
native_widget_delegate_->OnNativeWidgetVisibilityChanging(!window->visible());
}
« no previous file with comments | « ui/views/mus/native_widget_mus.h ('k') | ui/views/mus/native_widget_mus_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698