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_source.h" | 5 #include "ui/events/event_source.h" |
| 6 | 6 |
| 7 #include <algorithm> | |
| 8 | |
| 7 #include "ui/events/event_processor.h" | 9 #include "ui/events/event_processor.h" |
| 10 #include "ui/events/event_rewriter.h" | |
| 8 | 11 |
| 9 namespace ui { | 12 namespace ui { |
| 10 | 13 |
| 14 EventSource::EventSource() {} | |
| 15 | |
| 16 EventSource::~EventSource() {} | |
| 17 | |
| 18 void EventSource::AddEventRewriter(EventRewriter* rewriter) { | |
| 19 DCHECK(rewriter); | |
|
sadrul
2014/03/26 17:26:27
Also DCHECK that |rewriter| isn't already in the l
| |
| 20 rewriter_list_.push_back(rewriter); | |
| 21 } | |
| 22 | |
| 23 void EventSource::RemoveEventRewriter(EventRewriter* rewriter) { | |
| 24 EventRewriterList::iterator find = | |
| 25 std::find(rewriter_list_.begin(), rewriter_list_.end(), rewriter); | |
| 26 if (find != rewriter_list_.end()) rewriter_list_.erase(find); | |
|
sadrul
2014/03/26 17:26:27
line-break after the conditional
kpschoedel
2014/03/26 18:43:16
Ah, I was mistakenly picking up the wrong clang-fo
| |
| 27 } | |
| 28 | |
| 11 EventDispatchDetails EventSource::SendEventToProcessor(Event* event) { | 29 EventDispatchDetails EventSource::SendEventToProcessor(Event* event) { |
| 30 scoped_ptr<Event> rewritten_event; | |
| 31 EventRewriteStatus status = EVENT_REWRITE_CONTINUE; | |
| 32 EventRewriterList::const_iterator it = rewriter_list_.begin(), | |
| 33 end = rewriter_list_.end(); | |
| 34 for (; it != end; ++it) { | |
| 35 status = (*it)->RewriteEvent(*event, rewritten_event); | |
| 36 if (status == EVENT_REWRITE_DISCARD) { | |
| 37 CHECK(!rewritten_event); | |
| 38 return EventDispatchDetails(); | |
| 39 } | |
| 40 if (status == EVENT_REWRITE_CONTINUE) { | |
| 41 CHECK(!rewritten_event); | |
| 42 continue; | |
| 43 } | |
| 44 break; | |
| 45 } | |
| 46 CHECK((it == end && !rewritten_event) || rewritten_event); | |
| 47 EventDispatchDetails details = | |
| 48 DeliverEventToProcessor(rewritten_event ? rewritten_event.get() : event); | |
| 49 if (details.dispatcher_destroyed) return details; | |
|
sadrul
2014/03/26 17:26:27
line-break
| |
| 50 | |
| 51 while (status == EVENT_REWRITE_DISPATCH_ANOTHER) { | |
| 52 scoped_ptr<Event> new_event; | |
| 53 status = (*it)->NextDispatchEvent(*rewritten_event, new_event); | |
| 54 if (status == EVENT_REWRITE_DISCARD) { | |
|
sadrul
2014/03/26 17:26:27
You don't need braces for single-line blocks
| |
| 55 return EventDispatchDetails(); | |
| 56 } | |
| 57 CHECK_NE(EVENT_REWRITE_CONTINUE, status); | |
| 58 CHECK(new_event); | |
| 59 details = DeliverEventToProcessor(new_event.get()); | |
| 60 if (details.dispatcher_destroyed) return details; | |
| 61 rewritten_event.reset(new_event.release()); | |
| 62 } | |
| 63 return EventDispatchDetails(); | |
| 64 } | |
| 65 | |
| 66 EventDispatchDetails EventSource::DeliverEventToProcessor(Event* event) { | |
| 12 EventProcessor* processor = GetEventProcessor(); | 67 EventProcessor* processor = GetEventProcessor(); |
| 13 CHECK(processor); | 68 CHECK(processor); |
| 14 return processor->OnEventFromSource(event); | 69 return processor->OnEventFromSource(event); |
| 15 } | 70 } |
| 16 | 71 |
| 17 } // namespace ui | 72 } // namespace ui |
| OLD | NEW |