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

Side by Side Diff: ui/events/event_target_iterator.h

Issue 724973003: Get event targetting working for mouse events. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: sky comments Created 6 years, 1 month 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
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 #ifndef UI_EVENTS_EVENT_TARGET_ITERATOR_H_ 5 #ifndef UI_EVENTS_EVENT_TARGET_ITERATOR_H_
6 #define UI_EVENTS_EVENT_TARGET_ITERATOR_H_ 6 #define UI_EVENTS_EVENT_TARGET_ITERATOR_H_
7 7
8 #include <vector> 8 #include <vector>
9 9
10 namespace ui { 10 namespace ui {
(...skipping 10 matching lines...) Expand all
21 // Provides an EventTargetIterator implementation for iterating over a list of 21 // Provides an EventTargetIterator implementation for iterating over a list of
22 // EventTargets. The list is iterated in the reverse order, since typically the 22 // EventTargets. The list is iterated in the reverse order, since typically the
23 // EventTargets are maintained in increasing z-order in the lists. 23 // EventTargets are maintained in increasing z-order in the lists.
24 template<typename T> 24 template<typename T>
25 class EventTargetIteratorImpl : public EventTargetIterator { 25 class EventTargetIteratorImpl : public EventTargetIterator {
26 public: 26 public:
27 explicit EventTargetIteratorImpl(const std::vector<T*>& children) 27 explicit EventTargetIteratorImpl(const std::vector<T*>& children)
28 : begin_(children.rbegin()), 28 : begin_(children.rbegin()),
29 end_(children.rend()) { 29 end_(children.rend()) {
30 } 30 }
31 virtual ~EventTargetIteratorImpl() {} 31 ~EventTargetIteratorImpl() override {}
32 32
33 virtual EventTarget* GetNextTarget() override { 33 EventTarget* GetNextTarget() override {
34 if (begin_ == end_) 34 if (begin_ == end_)
35 return NULL; 35 return NULL;
36 EventTarget* target = *(begin_); 36 EventTarget* target = *(begin_);
37 ++begin_; 37 ++begin_;
38 return target; 38 return target;
39 } 39 }
40 40
41 private: 41 private:
42 typename std::vector<T*>::const_reverse_iterator begin_; 42 typename std::vector<T*>::const_reverse_iterator begin_;
43 typename std::vector<T*>::const_reverse_iterator end_; 43 typename std::vector<T*>::const_reverse_iterator end_;
44 }; 44 };
45 45
46 // Provides a version which keeps a copy of the data (for when it has to be
47 // derived instead of pointed at).
48 template<typename T>
49 class CopyingEventTargetIteratorImpl : public EventTargetIterator {
50 public:
51 explicit CopyingEventTargetIteratorImpl(const std::vector<T*>& children)
52 : children_(children),
53 begin_(children_.rbegin()),
54 end_(children_.rend()) {
55 }
56 ~CopyingEventTargetIteratorImpl() override {}
57
58 EventTarget* GetNextTarget() override {
59 if (begin_ == end_)
60 return NULL;
61 EventTarget* target = *(begin_);
62 ++begin_;
63 return target;
64 }
65
66 private:
67 typename std::vector<T*> children_;
68 typename std::vector<T*>::const_reverse_iterator begin_;
69 typename std::vector<T*>::const_reverse_iterator end_;
70 };
71
46 } // namespace ui 72 } // namespace ui
47 73
48 #endif // UI_EVENTS_EVENT_TARGET_ITERATOR_H_ 74 #endif // UI_EVENTS_EVENT_TARGET_ITERATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698