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_TEST_TEST_EVENT_TARGET_H_ 6 #define UI_EVENTS_TEST_TEST_EVENT_TARGET_H_ 7 8 #include <set> 9 10 #include "base/memory/scoped_vector.h" 11 #include "ui/events/event_target.h" 12 13 namespace gfx { 14 class Point; 15 } 16 17 namespace ui { 18 namespace test { 19 20 class TestEventTarget : public EventTarget { 21 public: 22 TestEventTarget(); 23 virtual ~TestEventTarget(); 24 25 void AddChild(scoped_ptr<TestEventTarget> child); 26 scoped_ptr<TestEventTarget> RemoveChild(TestEventTarget* child); 27 28 TestEventTarget* parent() { return parent_; } 29 30 TestEventTarget* child_at(int index) { return children_[index]; } 31 size_t child_count() const { return children_.size(); } 32 33 void SetEventTargeter(scoped_ptr<EventTargeter> targeter); 34 35 bool DidReceiveEvent(ui::EventType type) const; 36 void ResetReceivedEvents(); 37 38 protected: 39 bool Contains(TestEventTarget* target) const; 40 41 // EventTarget: 42 virtual bool CanAcceptEvent(const ui::Event& event) OVERRIDE; 43 virtual EventTarget* GetParentTarget() OVERRIDE; 44 virtual scoped_ptr<EventTargetIterator> GetChildIterator() const OVERRIDE; 45 virtual EventTargeter* GetEventTargeter() OVERRIDE; 46 47 // EventHandler: 48 virtual void OnEvent(Event* event) OVERRIDE; 49 50 private: 51 void set_parent(TestEventTarget* parent) { parent_ = parent; } 52 53 TestEventTarget* parent_; 54 ScopedVector<TestEventTarget> children_; 55 scoped_ptr<EventTargeter> targeter_; 56 57 std::set<ui::EventType> received_; 58 59 DISALLOW_COPY_AND_ASSIGN(TestEventTarget); 60 }; 61 62 } // namespace test 63 } // namespace ui 64 65 #endif // UI_EVENTS_TEST_TEST_EVENT_TARGET_H_ 66