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

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

Issue 1891233006: mus: Fix handled status in UI event ack, add MessageLoop::NestingObserver (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@eventresult
Patch Set: Created 4 years, 8 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/platform_window_mus.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/mus/platform_window_mus.cc
diff --git a/ui/views/mus/platform_window_mus.cc b/ui/views/mus/platform_window_mus.cc
index 4b72979b40ce92857c8d88346fcdc320a7a2eb10..b8f99fb53fa5b0d5daea11081824f838bca8215e 100644
--- a/ui/views/mus/platform_window_mus.cc
+++ b/ui/views/mus/platform_window_mus.cc
@@ -4,6 +4,7 @@
#include "ui/views/mus/platform_window_mus.h"
+#include "base/message_loop/message_loop.h"
#include "build/build_config.h"
#include "components/bitmap_uploader/bitmap_uploader.h"
#include "components/mus/public/cpp/property_type_converters.h"
@@ -14,9 +15,12 @@
#include "ui/platform_window/platform_window_delegate.h"
#include "ui/views/mus/window_manager_connection.h"
+using mus::mojom::EventResult;
+
namespace views {
namespace {
+
static uint32_t accelerated_widget_count = 1;
} // namespace
@@ -33,6 +37,7 @@ PlatformWindowMus::PlatformWindowMus(ui::PlatformWindowDelegate* delegate,
DCHECK(mus_window_);
mus_window_->AddObserver(this);
mus_window_->set_input_event_handler(this);
+ base::MessageLoop::current()->AddNestingObserver(this);
// We need accelerated widget numbers to be different for each
// window and fit in the smallest sizeof(AcceleratedWidget) uint32_t
@@ -55,6 +60,7 @@ PlatformWindowMus::PlatformWindowMus(ui::PlatformWindowDelegate* delegate,
}
PlatformWindowMus::~PlatformWindowMus() {
+ base::MessageLoop::current()->RemoveNestingObserver(this);
if (!mus_window_)
return;
mus_window_->RemoveObserver(this);
@@ -222,17 +228,31 @@ void PlatformWindowMus::OnRequestClose(mus::Window* window) {
void PlatformWindowMus::OnWindowInputEvent(
mus::Window* view,
- const ui::Event& event,
- std::unique_ptr<base::Callback<void(mus::mojom::EventResult)>>*
- ack_callback) {
- // It's possible dispatching the event will spin a nested message loop. Ack
- // the callback now, otherwise we appear unresponsive for the life of the
- // nested message loop.
- (*ack_callback)->Run(mus::mojom::EventResult::HANDLED);
- ack_callback->reset();
- // TODO(moshayedi): Avoid cloning after updating PlatformWindowDelegate to
- // accept constant pointers.
- delegate_->DispatchEvent(ui::Event::Clone(event).get());
+ const ui::Event& event_in,
+ std::unique_ptr<base::Callback<void(EventResult)>>* ack_callback) {
+ event_ack_callback_ = std::move(*ack_callback);
sky 2016/04/16 16:28:33 I have a feeling you need to deal with multiple ne
+
+ // DispatchEvent requires a mutable event so flags like handled can be set.
+ scoped_ptr<ui::Event> event = ui::Event::Clone(event_in);
sky 2016/04/16 16:28:33 std::unique_ptr
+ delegate_->DispatchEvent(event.get());
+
+ // If the event wasn't already handled by a nested message loop then ack it
+ // with the handled state.
+ if (event_ack_callback_) {
sky 2016/04/16 16:28:33 In addition to multiple nestings you should deal w
+ event_ack_callback_->Run(
+ event->handled() ? EventResult::HANDLED : EventResult::UNHANDLED);
+ event_ack_callback_.reset();
+ }
+}
+
+void PlatformWindowMus::OnBeginNestedMessageLoop() {
+ // It's possible dispatching an event will spin a nested message loop. If we
+ // are processing an event then ack the callback now, otherwise we appear
+ // unresponsive for the life of the nested message loop.
+ if (event_ack_callback_) {
+ event_ack_callback_->Run(EventResult::HANDLED);
+ event_ack_callback_.reset();
+ }
}
} // namespace views
« no previous file with comments | « ui/views/mus/platform_window_mus.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698