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

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: comments addressed, test modified 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 scoped_ptr<Event> event_copy(Event::Clone(*event));
sadrul 2014/09/03 16:23:53 I was thinking of something more like this: scop
tdanderson 2014/09/03 20:20:02 Done.
20 21
21 while (target) { 22 while (target) {
22 EventDispatchDetails details = DispatchEvent(target, event); 23 EventDispatchDetails details;
24 if (event->phase() != EP_PREDISPATCH) {
25 // |event| is currently being processed by another EventProcessor, which
26 // expects the event's state (e.g., target, phase, etc.) to remain
27 // unchanged once |this| has finished its nested processing (with the
28 // exception of whether or not the event was handled). Thus dispatch
29 // a copy of the event instead.
30 details = DispatchEvent(target, event_copy.get());
31
32 if (event_copy->stopped_propagation())
33 event->StopPropagation();
34 else if (event_copy->handled())
35 event->SetHandled();
36 } else {
37 // |this| is the only EventProcessor currently processing |event|, so
38 // copying the event prior to dispatch is unnecessary.
39 details = DispatchEvent(target, event);
sadrul 2014/09/03 16:23:53 DispatchEvent() would set the event-phase to POSTD
tdanderson 2014/09/03 20:20:02 Thanks for catching this! In the next patch set I
40 }
41
23 if (details.dispatcher_destroyed || 42 if (details.dispatcher_destroyed ||
24 details.target_destroyed || 43 details.target_destroyed ||
25 event->handled()) { 44 event->handled()) {
26 return details; 45 return details;
27 } 46 }
28 47
29 target = targeter->FindNextBestTarget(target, event); 48 target = targeter->FindNextBestTarget(target, event);
30 } 49 }
31 50
32 return EventDispatchDetails(); 51 return EventDispatchDetails();
33 } 52 }
34 53
35 void EventProcessor::PrepareEventForDispatch(Event* event) { 54 void EventProcessor::PrepareEventForDispatch(Event* event) {
36 } 55 }
37 56
38 } // namespace ui 57 } // 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