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

Side by Side Diff: ui/aura/mus/mus_mouse_location_updater.cc

Issue 2657283003: mash: make Env::last_mouse_location() accurate for Mus (Closed)
Patch Set: cleanup Created 3 years, 10 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 unified diff | Download patch
« no previous file with comments | « ui/aura/mus/mus_mouse_location_updater.h ('k') | ui/aura/window_event_dispatcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/aura/mus/mus_mouse_location_updater.h"
6
7 #include "ui/aura/env.h"
8 #include "ui/events/event.h"
9
10 namespace aura {
11 namespace {
12
13 bool IsMouseEventWithLocation(const ui::Event& event) {
14 // All mouse events except exited, capture, and wheel which mus doesn't
15 // include locations for.
16 switch (event.type()) {
17 case ui::ET_MOUSE_PRESSED:
18 case ui::ET_MOUSE_DRAGGED:
19 case ui::ET_MOUSE_RELEASED:
20 case ui::ET_MOUSE_MOVED:
21 case ui::ET_MOUSE_ENTERED:
22 return true;
23 default:
24 break;
25 }
26 return false;
27 }
28
29 } // namespace
30
31 MusMouseLocationUpdater::MusMouseLocationUpdater() {}
32
33 MusMouseLocationUpdater::~MusMouseLocationUpdater() {
34 // Should never be destroyed while in the middle of processing an event.
35 DCHECK(!observing_message_loop_);
36 }
37
38 void MusMouseLocationUpdater::OnEventProcessingStarted(const ui::Event& event) {
39 // Should never process an event while processing another event, unless
40 // a nested message loop is spun, which sets |observing_message_loop_| to
41 // false.
42 DCHECK(!observing_message_loop_);
43
44 if (!IsMouseEventWithLocation(event))
45 return;
46
47 Env::GetInstance()->set_last_mouse_location(
48 event.AsMouseEvent()->root_location());
49 Env::GetInstance()->get_last_mouse_location_from_mus_ = false;
sadrul 2017/01/27 21:08:36 Maybe call this |last_mouse_location_is_valid_| (a
50 observing_message_loop_ = true;
51 base::MessageLoop::current()->AddNestingObserver(this);
sadrul 2017/01/27 21:08:36 Is it better to just leave it always added as a ne
52 }
53
54 void MusMouseLocationUpdater::OnEventProcessingFinished() {
55 if (!observing_message_loop_)
56 return;
57
58 StopObserving();
59 }
60
61 void MusMouseLocationUpdater::StopObserving() {
62 DCHECK(observing_message_loop_);
63 observing_message_loop_ = false;
64 base::MessageLoop::current()->RemoveNestingObserver(this);
65 Env::GetInstance()->get_last_mouse_location_from_mus_ = true;
66 }
67
68 void MusMouseLocationUpdater::OnBeginNestedMessageLoop() {
69 StopObserving();
70 }
71
72 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/mus/mus_mouse_location_updater.h ('k') | ui/aura/window_event_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698