Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / events / test / test_event_target.cc
blob8ea7438d738841b97acb56fcfdceb857f0458fd7
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"
11 namespace ui {
12 namespace test {
14 TestEventTarget::TestEventTarget()
15 : parent_(NULL),
16 mark_events_as_handled_(false),
17 recorder_(NULL),
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()));
25 } else {
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(),
33 children_.end(),
34 c);
35 if (iter != children_.end()) {
36 children_.weak_erase(iter);
37 c->set_parent(NULL);
38 return make_scoped_ptr(c);
40 return nullptr;
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() {
52 received_.clear();
55 ////////////////////////////////////////////////////////////////////////////////
56 // TestEventTarget, protected
58 bool TestEventTarget::CanAcceptEvent(const ui::Event& event) {
59 return true;
62 EventTarget* TestEventTarget::GetParentTarget() {
63 return parent_;
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) {
76 if (recorder_)
77 recorder_->push_back(target_name_);
78 received_.insert(event->type());
79 EventTarget::OnEvent(event);
80 if (!event->handled() && mark_events_as_handled_)
81 event->SetHandled();
84 ////////////////////////////////////////////////////////////////////////////////
85 // TestEventTarget, private
87 bool TestEventTarget::Contains(TestEventTarget* target) const {
88 while (target && target != this)
89 target = target->parent();
90 return target == this;
93 } // namespace test
94 } // namespace ui