1a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 2a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// found in the LICENSE file. 4a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 5a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#ifndef UI_EVENTS_EVENT_TARGET_ITERATOR_H_ 6a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#define UI_EVENTS_EVENT_TARGET_ITERATOR_H_ 7a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 8a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include <vector> 9a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 10a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)namespace ui { 11a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 12a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class EventTarget; 13a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 14a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// An interface that allows iterating over a set of EventTargets. 15a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class EventTargetIterator { 16a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) public: 17a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual ~EventTargetIterator() {} 18a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual EventTarget* GetNextTarget() = 0; 19a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}; 20a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 21a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Provides an EventTargetIterator implementation for iterating over a list of 22a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// EventTargets. The list is iterated in the reverse order, since typically the 23a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// EventTargets are maintained in increasing z-order in the lists. 24a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)template<typename T> 25a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class EventTargetIteratorImpl : public EventTargetIterator { 26a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) public: 27a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) explicit EventTargetIteratorImpl(const std::vector<T*>& children) 28a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) : begin_(children.rbegin()), 29a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) end_(children.rend()) { 30a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 31a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual ~EventTargetIteratorImpl() {} 32a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 33a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) virtual EventTarget* GetNextTarget() OVERRIDE { 34a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) if (begin_ == end_) 35a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return NULL; 36a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EventTarget* target = *(begin_); 37a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) ++begin_; 38a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) return target; 39a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) } 40a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 41a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) private: 42a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) typename std::vector<T*>::const_reverse_iterator begin_; 43a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) typename std::vector<T*>::const_reverse_iterator end_; 44a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}; 45a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 46a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)} // namespace ui 47a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 48a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif // UI_EVENTS_EVENT_TARGET_ITERATOR_H_ 49