1 // Copyright (c) 2012 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/event_target.h"
9 #include "base/logging.h"
10 #include "ui/events/event.h"
14 EventTarget::EventTarget()
15 : target_handler_(NULL
) {
18 EventTarget::~EventTarget() {
21 void EventTarget::ConvertEventToTarget(EventTarget
* target
,
22 LocatedEvent
* event
) {
25 void EventTarget::AddPreTargetHandler(EventHandler
* handler
) {
26 pre_target_list_
.push_back(handler
);
29 void EventTarget::PrependPreTargetHandler(EventHandler
* handler
) {
30 pre_target_list_
.insert(pre_target_list_
.begin(), handler
);
33 void EventTarget::RemovePreTargetHandler(EventHandler
* handler
) {
34 EventHandlerList::iterator find
=
35 std::find(pre_target_list_
.begin(),
36 pre_target_list_
.end(),
38 if (find
!= pre_target_list_
.end())
39 pre_target_list_
.erase(find
);
42 void EventTarget::AddPostTargetHandler(EventHandler
* handler
) {
43 post_target_list_
.push_back(handler
);
46 void EventTarget::RemovePostTargetHandler(EventHandler
* handler
) {
47 EventHandlerList::iterator find
=
48 std::find(post_target_list_
.begin(),
49 post_target_list_
.end(),
51 if (find
!= post_target_list_
.end())
52 post_target_list_
.erase(find
);
55 bool EventTarget::IsPreTargetListEmpty() const {
56 return pre_target_list_
.empty();
59 void EventTarget::OnEvent(Event
* event
) {
60 CHECK_EQ(this, event
->target());
62 target_handler_
->OnEvent(event
);
64 EventHandler::OnEvent(event
);
67 void EventTarget::OnKeyEvent(KeyEvent
* event
) {
68 CHECK_EQ(this, event
->target());
70 target_handler_
->OnKeyEvent(event
);
73 void EventTarget::OnMouseEvent(MouseEvent
* event
) {
74 CHECK_EQ(this, event
->target());
76 target_handler_
->OnMouseEvent(event
);
79 void EventTarget::OnScrollEvent(ScrollEvent
* event
) {
80 CHECK_EQ(this, event
->target());
82 target_handler_
->OnScrollEvent(event
);
85 void EventTarget::OnTouchEvent(TouchEvent
* event
) {
86 CHECK_EQ(this, event
->target());
88 target_handler_
->OnTouchEvent(event
);
91 void EventTarget::OnGestureEvent(GestureEvent
* event
) {
92 CHECK_EQ(this, event
->target());
94 target_handler_
->OnGestureEvent(event
);
97 void EventTarget::GetPreTargetHandlers(EventHandlerList
* list
) {
98 EventTarget
* target
= this;
100 EventHandlerList::reverse_iterator it
, rend
;
101 for (it
= target
->pre_target_list_
.rbegin(),
102 rend
= target
->pre_target_list_
.rend();
105 list
->insert(list
->begin(), *it
);
107 target
= target
->GetParentTarget();
111 void EventTarget::GetPostTargetHandlers(EventHandlerList
* list
) {
112 EventTarget
* target
= this;
114 for (EventHandlerList::iterator it
= target
->post_target_list_
.begin(),
115 end
= target
->post_target_list_
.end(); it
!= end
; ++it
) {
116 list
->push_back(*it
);
118 target
= target
->GetParentTarget();