ui: Remove some unnecessary functions from the API.
[chromium-blink-merge.git] / ui / events / event_target_iterator.h
blob3083c830778ac365777f1cbc69a7af46296e5af4
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.
5 #ifndef UI_EVENTS_EVENT_TARGET_ITERATOR_H_
6 #define UI_EVENTS_EVENT_TARGET_ITERATOR_H_
8 #include <vector>
10 namespace ui {
12 class EventTarget;
14 // An interface that allows iterating over a set of EventTargets.
15 class EventTargetIterator {
16 public:
17 virtual ~EventTargetIterator() {}
18 virtual EventTarget* GetNextTarget() = 0;
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()) {
31 virtual ~EventTargetIteratorImpl() {}
33 virtual EventTarget* GetNextTarget() OVERRIDE {
34 if (begin_ == end_)
35 return NULL;
36 EventTarget* target = *(begin_);
37 ++begin_;
38 return target;
41 private:
42 typename std::vector<T*>::const_reverse_iterator begin_;
43 typename std::vector<T*>::const_reverse_iterator end_;
46 } // namespace ui
48 #endif // UI_EVENTS_EVENT_TARGET_ITERATOR_H_