Chromium Code Reviews| OLD | NEW |
|---|---|
| 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(); | |
| 14 CHECK(root); | |
| 15 EventTargeter* targeter = root->GetEventTargeter(); | |
| 16 CHECK(targeter); | |
| 17 | |
| 18 // If |event| is in the process of being dispatched or has already been | 13 // If |event| is in the process of being dispatched or has already been |
| 19 // dispatched, then dispatch a copy of the event instead. | 14 // dispatched, then dispatch a copy of the event instead. |
| 20 bool dispatch_original_event = event->phase() == EP_PREDISPATCH; | 15 bool dispatch_original_event = event->phase() == EP_PREDISPATCH; |
| 21 Event* event_to_dispatch = event; | 16 Event* event_to_dispatch = event; |
| 22 std::unique_ptr<Event> event_copy; | 17 std::unique_ptr<Event> event_copy; |
| 23 if (!dispatch_original_event) { | 18 if (!dispatch_original_event) { |
| 24 event_copy = Event::Clone(*event); | 19 event_copy = Event::Clone(*event); |
| 25 event_to_dispatch = event_copy.get(); | 20 event_to_dispatch = event_copy.get(); |
| 26 } | 21 } |
| 27 | 22 |
| 28 OnEventProcessingStarted(event_to_dispatch); | 23 OnEventProcessingStarted(event_to_dispatch); |
| 29 EventTarget* target = NULL; | 24 EventTarget* target = nullptr; |
| 30 if (!event_to_dispatch->handled()) | 25 EventTargeter* targeter = nullptr; |
| 26 if (!event_to_dispatch->handled()) { | |
| 27 EventTarget* root = GetRootForEvent(event_to_dispatch); | |
| 28 DCHECK(root); | |
| 29 targeter = root->GetEventTargeter(); | |
| 30 if (!targeter) | |
| 31 targeter = GetDefaultEventTargeter(); | |
|
sadrul
2017/02/13 17:05:42
Can you add a test in event_processor_unittest.cc
riajiang
2017/02/13 23:30:34
Added tests for this part of the code in WindowTre
| |
| 32 DCHECK(targeter); | |
| 31 target = targeter->FindTargetForEvent(root, event_to_dispatch); | 33 target = targeter->FindTargetForEvent(root, event_to_dispatch); |
| 34 } | |
| 32 | 35 |
| 33 EventDispatchDetails details; | 36 EventDispatchDetails details; |
| 34 while (target) { | 37 while (target) { |
| 35 details = DispatchEvent(target, event_to_dispatch); | 38 details = DispatchEvent(target, event_to_dispatch); |
| 36 | 39 |
| 37 if (!dispatch_original_event) { | 40 if (!dispatch_original_event) { |
| 38 if (event_to_dispatch->stopped_propagation()) | 41 if (event_to_dispatch->stopped_propagation()) |
| 39 event->StopPropagation(); | 42 event->StopPropagation(); |
| 40 else if (event_to_dispatch->handled()) | 43 else if (event_to_dispatch->handled()) |
| 41 event->SetHandled(); | 44 event->SetHandled(); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 54 return details; | 57 return details; |
| 55 } | 58 } |
| 56 | 59 |
| 57 void EventProcessor::OnEventProcessingStarted(Event* event) { | 60 void EventProcessor::OnEventProcessingStarted(Event* event) { |
| 58 } | 61 } |
| 59 | 62 |
| 60 void EventProcessor::OnEventProcessingFinished(Event* event) { | 63 void EventProcessor::OnEventProcessingFinished(Event* event) { |
| 61 } | 64 } |
| 62 | 65 |
| 63 } // namespace ui | 66 } // namespace ui |
| OLD | NEW |