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

Unified Diff: services/ui/ws/display.cc

Issue 2712963003: mustash: Use ui::chromeos::EventRewriter in mus (Closed)
Patch Set: Update tests Created 3 years, 9 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
Index: services/ui/ws/display.cc
diff --git a/services/ui/ws/display.cc b/services/ui/ws/display.cc
index 7fc5771a689b12454b47d45b124b35f174ac2284..977e8baf3ba2a6097d0aa7d36f9e7ae024a2df6f 100644
--- a/services/ui/ws/display.cc
+++ b/services/ui/ws/display.cc
@@ -8,6 +8,7 @@
#include <utility>
#include <vector>
+#include "base/callback_helpers.h"
#include "base/memory/ptr_util.h"
#include "base/strings/utf_string_conversions.h"
#include "services/service_manager/public/interfaces/connector.mojom.h"
@@ -28,6 +29,7 @@
#include "services/ui/ws/window_tree_binding.h"
#include "ui/base/cursor/cursor.h"
#include "ui/display/screen.h"
+#include "ui/events/event_rewriter.h"
namespace ui {
namespace ws {
@@ -270,13 +272,54 @@ bool Display::IsInHighContrastMode() {
}
void Display::OnEvent(const ui::Event& event) {
+ // Run UserActivityMonitor::OnUserActivity() for active user before exiting
+ // this function.
+ auto* activity_monitor = window_server_->GetUserActivityMonitorForUser(
+ window_server_->user_id_tracker()->active_id());
+ base::ScopedClosureRunner scoped_runner(
sky 2017/03/15 19:48:11 Do we really need a ScopedClosureRunner? Can you c
Peng 2017/03/16 17:28:57 This function has several return statements, using
sky 2017/03/16 20:23:07 Sorry for not being clear. I wasn't suggesting you
+ base::Bind(&UserActivityMonitor::OnUserActivity,
+ base::Unretained(activity_monitor)));
+
WindowManagerDisplayRoot* display_root = GetActiveWindowManagerDisplayRoot();
- if (display_root)
- display_root->window_manager_state()->ProcessEvent(event, GetId());
- window_server_
- ->GetUserActivityMonitorForUser(
- window_server_->user_id_tracker()->active_id())
- ->OnUserActivity();
+ if (!display_root)
+ return;
+
+ std::unique_ptr<ui::Event> rewritten_event;
+ auto status = ui::EVENT_REWRITE_CONTINUE;
sky 2017/03/15 19:48:11 Please don't overuse auto, it's make the code hard
Peng 2017/03/16 17:28:57 Done.
+ auto* event_rewriter = display_manager()->event_rewriter();
+
+ // |event_rewriter| is null for non-ChromeOS build.
+ if (event_rewriter)
+ status = event_rewriter->RewriteEvent(event, &rewritten_event);
+
+ if (status == ui::EVENT_REWRITE_DISCARD) {
+ DCHECK(!rewritten_event);
+ return;
+ }
+
+ auto* wm_state = display_root->window_manager_state();
+ if (status == ui::EVENT_REWRITE_CONTINUE) {
+ DCHECK(!rewritten_event);
+ wm_state->ProcessEvent(event, GetId());
+ return;
+ }
+
+ DCHECK(status == ui::EVENT_REWRITE_REWRITTEN ||
+ status == ui::EVENT_REWRITE_DISPATCH_ANOTHER);
+ DCHECK(rewritten_event);
+ wm_state->ProcessEvent(*rewritten_event, GetId());
+
+ while (status == ui::EVENT_REWRITE_DISPATCH_ANOTHER) {
+ std::unique_ptr<Event> new_event;
+ status = event_rewriter->NextDispatchEvent(*rewritten_event, &new_event);
+ if (status == ui::EVENT_REWRITE_DISCARD)
+ break;
+ DCHECK_NE(EVENT_REWRITE_CONTINUE, status);
+
+ DCHECK(new_event);
+ wm_state->ProcessEvent(*new_event, GetId());
+ rewritten_event = std::move(new_event);
+ }
}
void Display::OnNativeCaptureLost() {

Powered by Google App Engine
This is Rietveld 408576698