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

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

Issue 1883263002: mash: Repost mouse pressed event when closing Ash system tray (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup 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 1ae09d182c134d3542b9eb0dfdeafe0a1f96e234..1323f307eb0631f4b92dc3671c9c46f4747cc547 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"
@@ -17,6 +18,7 @@
namespace views {
namespace {
+
static uint32_t accelerated_widget_count = 1;
} // namespace
@@ -33,6 +35,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 +58,7 @@ PlatformWindowMus::PlatformWindowMus(ui::PlatformWindowDelegate* delegate,
}
PlatformWindowMus::~PlatformWindowMus() {
+ base::MessageLoop::current()->RemoveNestingObserver(this);
if (!mus_window_)
return;
mus_window_->RemoveObserver(this);
@@ -223,18 +227,49 @@ void PlatformWindowMus::OnRequestClose(mus::Window* window) {
void PlatformWindowMus::OnWindowInputEvent(
mus::Window* view,
const ui::Event& event,
- std::unique_ptr<base::Callback<void(bool)>>* 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.
- // TODO(jamescook): Only ack the event as handled if a nested message loop
- // actually starts, perhaps through an observer on MessageLoop. Otherwise
- // ack the event with the actual handled state below DispatchEvent().
- (*ack_callback)->Run(true);
- ack_callback->reset();
- // TODO(moshayedi): Avoid cloning after updating PlatformWindowDelegate to
- // accept constant pointers.
- delegate_->DispatchEvent(ui::Event::Clone(event).get());
+ std::unique_ptr<base::Callback<void(mus::mojom::EventResult)>>*
+ ack_callback) {
+ event_ack_callback_ = std::move(*ack_callback);
+
+ bool had_capture = mus_window_->HasCapture();
+
+ // DispatchEvent requires a mutable event so flags like handled can be set.
+ scoped_ptr<ui::Event> mutable_event = ui::Event::Clone(event);
+ delegate_->DispatchEvent(mutable_event.get());
+
+ mus::mojom::EventResult result;
+ if (mutable_event->handled())
+ result = mus::mojom::EventResult::HANDLED;
+ else if (ShouldRepostEvent(*mutable_event.get(), had_capture))
+ result = mus::mojom::EventResult::REPOST;
+ else
+ result = mus::mojom::EventResult::UNHANDLED;
+
+ // If the event wasn't already handled by a nested message loop then ack it
+ // with the handled state.
+ if (event_ack_callback_) {
+ event_ack_callback_->Run(result);
+ 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(mus::mojom::EventResult::HANDLED);
+ event_ack_callback_.reset();
+ }
+}
+
+bool PlatformWindowMus::ShouldRepostEvent(const ui::Event& event,
+ bool had_capture) {
+ // Repost mouse events that cause capture loss (e.g. a mouse press that closes
+ // a menu that had capture).
+ return had_capture && !mus_window_->HasCapture() &&
+ (event.type() == ui::ET_MOUSE_PRESSED ||
+ event.type() == ui::ET_MOUSE_RELEASED);
}
} // 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