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

Unified Diff: ui/aura/mus/mus_mouse_location_updater.cc

Issue 2657283003: mash: make Env::last_mouse_location() accurate for Mus (Closed)
Patch Set: merge Created 3 years, 11 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/aura/mus/mus_mouse_location_updater.h ('k') | ui/aura/test/aura_test_base.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/aura/mus/mus_mouse_location_updater.cc
diff --git a/ui/aura/mus/mus_mouse_location_updater.cc b/ui/aura/mus/mus_mouse_location_updater.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cbf89bd620a7980583599cc32916739fda36b711
--- /dev/null
+++ b/ui/aura/mus/mus_mouse_location_updater.cc
@@ -0,0 +1,67 @@
+// Copyright 2017 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.
+
+#include "ui/aura/mus/mus_mouse_location_updater.h"
+
+#include "ui/aura/env.h"
+#include "ui/events/event.h"
+
+namespace aura {
+namespace {
+
+bool IsMouseEventWithLocation(const ui::Event& event) {
+ // All mouse events except exited, capture, and wheel which mus doesn't
+ // include locations for.
+ switch (event.type()) {
+ case ui::ET_MOUSE_PRESSED:
+ case ui::ET_MOUSE_DRAGGED:
+ case ui::ET_MOUSE_RELEASED:
+ case ui::ET_MOUSE_MOVED:
+ case ui::ET_MOUSE_ENTERED:
+ return true;
+ default:
+ break;
+ }
+ return false;
+}
+
+} // namespace
+
+MusMouseLocationUpdater::MusMouseLocationUpdater() {
+ base::MessageLoop::current()->AddNestingObserver(this);
+}
+
+MusMouseLocationUpdater::~MusMouseLocationUpdater() {
+ base::MessageLoop::current()->RemoveNestingObserver(this);
+}
+
+void MusMouseLocationUpdater::OnEventProcessingStarted(const ui::Event& event) {
+ if (!IsMouseEventWithLocation(event) ||
+ Env::GetInstance()->always_use_last_mouse_location_) {
+ return;
+ }
+
+ is_processing_trigger_event_ = true;
+ Env::GetInstance()->set_last_mouse_location(
+ event.AsMouseEvent()->root_location());
+ Env::GetInstance()->get_last_mouse_location_from_mus_ = false;
+}
+
+void MusMouseLocationUpdater::OnEventProcessingFinished() {
+ UseCursorScreenPoint();
+}
+
+void MusMouseLocationUpdater::UseCursorScreenPoint() {
+ if (!is_processing_trigger_event_)
+ return;
+
+ is_processing_trigger_event_ = false;
+ Env::GetInstance()->get_last_mouse_location_from_mus_ = true;
+}
+
+void MusMouseLocationUpdater::OnBeginNestedMessageLoop() {
+ UseCursorScreenPoint();
+}
+
+} // namespace aura
« no previous file with comments | « ui/aura/mus/mus_mouse_location_updater.h ('k') | ui/aura/test/aura_test_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698