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

Side by Side Diff: ui/events/event_processor.cc

Issue 519113002: Do not mutate ui::Event properties during nested event processing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: only Clone() when needed Created 6 years, 3 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/events/event.cc ('k') | ui/events/event_processor_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/events/event_processor.h" 5 #include "ui/events/event_processor.h"
6 6
7 #include "ui/events/event_target.h" 7 #include "ui/events/event_target.h"
8 #include "ui/events/event_targeter.h" 8 #include "ui/events/event_targeter.h"
9 9
10 namespace ui { 10 namespace ui {
11 11
12 EventDispatchDetails EventProcessor::OnEventFromSource(Event* event) { 12 EventDispatchDetails EventProcessor::OnEventFromSource(Event* event) {
13 EventTarget* root = GetRootTarget(); 13 EventTarget* root = GetRootTarget();
14 CHECK(root); 14 CHECK(root);
15 EventTargeter* targeter = root->GetEventTargeter(); 15 EventTargeter* targeter = root->GetEventTargeter();
16 CHECK(targeter); 16 CHECK(targeter);
17 17
18 PrepareEventForDispatch(event); 18 PrepareEventForDispatch(event);
19 EventTarget* target = targeter->FindTargetForEvent(root, event); 19 EventTarget* target = targeter->FindTargetForEvent(root, event);
20 20
21 // Create a copy of |event| if it is currently being processed by another
22 // EventProcessor.
sadrul 2014/09/04 15:45:06 If the event is in the process of being dispatched
tdanderson 2014/09/04 17:19:03 Done.
23 scoped_ptr<Event> event_copy;
24 if (event->phase() != EP_PREDISPATCH)
25 event_copy = Event::Clone(*event);
26
21 while (target) { 27 while (target) {
22 EventDispatchDetails details = DispatchEvent(target, event); 28 EventDispatchDetails details;
29 if (event_copy) {
30 // The state of |event| (such as its target and phase) should remain
31 // unchanged once we have finished our nested processing, with the
32 // exception of whether or not the event was handled. Thus dispatch
33 // |event_copy| instead of |event|.
sadrul 2014/09/04 15:45:06 You don't need this comment. The comment above in
tdanderson 2014/09/04 17:19:03 Done.
34 details = DispatchEvent(target, event_copy.get());
35
36 if (event_copy->stopped_propagation())
37 event->StopPropagation();
38 else if (event_copy->handled())
39 event->SetHandled();
40 } else {
41 // |this| is the only EventProcessor currently processing |event|, so
42 // copying the event prior to dispatch is unnecessary.
43 details = DispatchEvent(target, event);
44 }
45
23 if (details.dispatcher_destroyed || 46 if (details.dispatcher_destroyed ||
24 details.target_destroyed || 47 details.target_destroyed ||
25 event->handled()) { 48 event->handled()) {
26 return details; 49 return details;
27 } 50 }
28 51
29 target = targeter->FindNextBestTarget(target, event); 52 target = targeter->FindNextBestTarget(target, event);
30 } 53 }
31 54
32 return EventDispatchDetails(); 55 return EventDispatchDetails();
33 } 56 }
34 57
35 void EventProcessor::PrepareEventForDispatch(Event* event) { 58 void EventProcessor::PrepareEventForDispatch(Event* event) {
36 } 59 }
37 60
38 } // namespace ui 61 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/event.cc ('k') | ui/events/event_processor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698