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_
12 #include "base/memory/scoped_vector.h"
13 #include "ui/events/event_target.h"
15 typedef std::vector
<std::string
> HandlerSequenceRecorder
;
24 class TestEventTarget
: public EventTarget
{
27 ~TestEventTarget() override
;
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
) {
49 void set_target_name(const std::string
& target_name
) {
50 target_name_
= target_name
;
54 EventTargeter
* GetEventTargeter() override
;
57 bool Contains(TestEventTarget
* target
) const;
60 bool CanAcceptEvent(const ui::Event
& event
) override
;
61 EventTarget
* GetParentTarget() override
;
62 scoped_ptr
<EventTargetIterator
> GetChildIterator() const override
;
65 void OnEvent(Event
* event
) override
;
68 void set_parent(TestEventTarget
* parent
) { parent_
= parent
; }
70 TestEventTarget
* parent_
;
71 ScopedVector
<TestEventTarget
> children_
;
72 scoped_ptr
<EventTargeter
> targeter_
;
73 bool mark_events_as_handled_
;
75 std::set
<ui::EventType
> received_
;
77 HandlerSequenceRecorder
* recorder_
;
78 std::string target_name_
;
80 DISALLOW_COPY_AND_ASSIGN(TestEventTarget
);
86 #endif // UI_EVENTS_TEST_TEST_EVENT_TARGET_H_