Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ui / events / test / test_event_target.h
blob368e29567e466fe88515a35305458741174e7c9c
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_TEST_TEST_EVENT_TARGET_H_
6 #define UI_EVENTS_TEST_TEST_EVENT_TARGET_H_
8 #include <set>
9 #include <string>
10 #include <vector>
12 #include "base/memory/scoped_vector.h"
13 #include "ui/events/event_target.h"
15 typedef std::vector<std::string> HandlerSequenceRecorder;
17 namespace gfx {
18 class Point;
21 namespace ui {
22 namespace test {
24 class TestEventTarget : public EventTarget {
25 public:
26 TestEventTarget();
27 virtual ~TestEventTarget();
29 void AddChild(scoped_ptr<TestEventTarget> child);
30 scoped_ptr<TestEventTarget> RemoveChild(TestEventTarget* child);
32 TestEventTarget* parent() { return parent_; }
34 void set_mark_events_as_handled(bool handle) {
35 mark_events_as_handled_ = handle;
38 TestEventTarget* child_at(int index) { return children_[index]; }
39 size_t child_count() const { return children_.size(); }
41 void SetEventTargeter(scoped_ptr<EventTargeter> targeter);
43 bool DidReceiveEvent(ui::EventType type) const;
44 void ResetReceivedEvents();
46 void set_recorder(HandlerSequenceRecorder* recorder) {
47 recorder_ = recorder;
49 void set_target_name(const std::string& target_name) {
50 target_name_ = target_name;
53 protected:
54 bool Contains(TestEventTarget* target) const;
56 // EventTarget:
57 virtual bool CanAcceptEvent(const ui::Event& event) OVERRIDE;
58 virtual EventTarget* GetParentTarget() OVERRIDE;
59 virtual scoped_ptr<EventTargetIterator> GetChildIterator() const OVERRIDE;
60 virtual EventTargeter* GetEventTargeter() OVERRIDE;
62 // EventHandler:
63 virtual void OnEvent(Event* event) OVERRIDE;
65 private:
66 void set_parent(TestEventTarget* parent) { parent_ = parent; }
68 TestEventTarget* parent_;
69 ScopedVector<TestEventTarget> children_;
70 scoped_ptr<EventTargeter> targeter_;
71 bool mark_events_as_handled_;
73 std::set<ui::EventType> received_;
75 HandlerSequenceRecorder* recorder_;
76 std::string target_name_;
78 DISALLOW_COPY_AND_ASSIGN(TestEventTarget);
81 } // namespace test
82 } // namespace ui
84 #endif // UI_EVENTS_TEST_TEST_EVENT_TARGET_H_