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 #include "ui/events/test/test_event_target.h"
7 #include "ui/events/event.h"
8 #include "ui/events/event_target_iterator.h"
9 #include "ui/events/event_targeter.h"
14 TestEventTarget::TestEventTarget()
16 mark_events_as_handled_(false),
18 target_name_("unknown") {}
19 TestEventTarget::~TestEventTarget() {}
21 void TestEventTarget::AddChild(scoped_ptr
<TestEventTarget
> child
) {
22 TestEventTarget
* child_r
= child
.get();
23 if (child
->parent()) {
24 AddChild(child
->parent()->RemoveChild(child
.release()));
26 children_
.push_back(child
.release());
28 child_r
->set_parent(this);
31 scoped_ptr
<TestEventTarget
> TestEventTarget::RemoveChild(TestEventTarget
*c
) {
32 ScopedVector
<TestEventTarget
>::iterator iter
= std::find(children_
.begin(),
35 if (iter
!= children_
.end()) {
36 children_
.weak_erase(iter
);
38 return make_scoped_ptr(c
);
43 void TestEventTarget::SetEventTargeter(scoped_ptr
<EventTargeter
> targeter
) {
44 targeter_
= targeter
.Pass();
47 bool TestEventTarget::DidReceiveEvent(ui::EventType type
) const {
48 return received_
.count(type
) > 0;
51 void TestEventTarget::ResetReceivedEvents() {
55 ////////////////////////////////////////////////////////////////////////////////
56 // TestEventTarget, protected
58 bool TestEventTarget::CanAcceptEvent(const ui::Event
& event
) {
62 EventTarget
* TestEventTarget::GetParentTarget() {
66 scoped_ptr
<EventTargetIterator
> TestEventTarget::GetChildIterator() const {
67 return make_scoped_ptr(
68 new EventTargetIteratorImpl
<TestEventTarget
>(children_
.get()));
71 EventTargeter
* TestEventTarget::GetEventTargeter() {
72 return targeter_
.get();
75 void TestEventTarget::OnEvent(Event
* event
) {
77 recorder_
->push_back(target_name_
);
78 received_
.insert(event
->type());
79 EventTarget::OnEvent(event
);
80 if (!event
->handled() && mark_events_as_handled_
)
84 ////////////////////////////////////////////////////////////////////////////////
85 // TestEventTarget, private
87 bool TestEventTarget::Contains(TestEventTarget
* target
) const {
88 while (target
&& target
!= this)
89 target
= target
->parent();
90 return target
== this;