3083c830778ac365777f1cbc69a7af46296e5af4
[platform/framework/web/crosswalk.git] / src / ui / events / event_target_iterator.h
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
3 // found in the LICENSE file.
4
5 #ifndef UI_EVENTS_EVENT_TARGET_ITERATOR_H_
6 #define UI_EVENTS_EVENT_TARGET_ITERATOR_H_
7
8 #include <vector>
9
10 namespace ui {
11
12 class EventTarget;
13
14 // An interface that allows iterating over a set of EventTargets.
15 class EventTargetIterator {
16  public:
17   virtual ~EventTargetIterator() {}
18   virtual EventTarget* GetNextTarget() = 0;
19 };
20
21 // Provides an EventTargetIterator implementation for iterating over a list of
22 // EventTargets. The list is iterated in the reverse order, since typically the
23 // EventTargets are maintained in increasing z-order in the lists.
24 template<typename T>
25 class EventTargetIteratorImpl : public EventTargetIterator {
26  public:
27   explicit EventTargetIteratorImpl(const std::vector<T*>& children)
28       : begin_(children.rbegin()),
29         end_(children.rend()) {
30   }
31   virtual ~EventTargetIteratorImpl() {}
32
33   virtual EventTarget* GetNextTarget() OVERRIDE {
34     if (begin_ == end_)
35       return NULL;
36     EventTarget* target = *(begin_);
37     ++begin_;
38     return target;
39   }
40
41  private:
42   typename std::vector<T*>::const_reverse_iterator begin_;
43   typename std::vector<T*>::const_reverse_iterator end_;
44 };
45
46 }  // namespace ui
47
48 #endif  // UI_EVENTS_EVENT_TARGET_ITERATOR_H_