Fix WindowAndroid leak in Android WebView
[chromium-blink-merge.git] / ui / events / event_target.cc
blob9b44f9a74afa96c8fba6c883ce2acfd365a39a87
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"
7 #include <algorithm>
9 #include "base/logging.h"
10 #include "ui/events/event.h"
12 namespace ui {
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(),
37 handler);
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(),
50 handler);
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());
61 if (target_handler_)
62 target_handler_->OnEvent(event);
63 else
64 EventHandler::OnEvent(event);
67 void EventTarget::OnKeyEvent(KeyEvent* event) {
68 CHECK_EQ(this, event->target());
69 if (target_handler_)
70 target_handler_->OnKeyEvent(event);
73 void EventTarget::OnMouseEvent(MouseEvent* event) {
74 CHECK_EQ(this, event->target());
75 if (target_handler_)
76 target_handler_->OnMouseEvent(event);
79 void EventTarget::OnScrollEvent(ScrollEvent* event) {
80 CHECK_EQ(this, event->target());
81 if (target_handler_)
82 target_handler_->OnScrollEvent(event);
85 void EventTarget::OnTouchEvent(TouchEvent* event) {
86 CHECK_EQ(this, event->target());
87 if (target_handler_)
88 target_handler_->OnTouchEvent(event);
91 void EventTarget::OnGestureEvent(GestureEvent* event) {
92 CHECK_EQ(this, event->target());
93 if (target_handler_)
94 target_handler_->OnGestureEvent(event);
97 void EventTarget::GetPreTargetHandlers(EventHandlerList* list) {
98 EventTarget* target = this;
99 while (target) {
100 EventHandlerList::reverse_iterator it, rend;
101 for (it = target->pre_target_list_.rbegin(),
102 rend = target->pre_target_list_.rend();
103 it != rend;
104 ++it) {
105 list->insert(list->begin(), *it);
107 target = target->GetParentTarget();
111 void EventTarget::GetPostTargetHandlers(EventHandlerList* list) {
112 EventTarget* target = this;
113 while (target) {
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();
122 } // namespace ui