summaryrefslogtreecommitdiff
path: root/chromium/ui/events/event_target.cc
blob: bbd1422ba287e77eee85b287a733213b267e369d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/events/event_target.h"

#include <algorithm>

#include "base/logging.h"
#include "ui/events/event.h"

namespace ui {

EventTarget::EventTarget()
    : target_handler_(NULL) {
}

EventTarget::~EventTarget() {
}

void EventTarget::ConvertEventToTarget(EventTarget* target,
                                       LocatedEvent* event) {
}

void EventTarget::AddPreTargetHandler(EventHandler* handler,
                                      Priority priority) {
  DCHECK(handler);
  PrioritizedHandler prioritized = PrioritizedHandler();
  prioritized.handler = handler;
  prioritized.priority = priority;
  EventHandlerPriorityList::iterator it;
  switch (priority) {
    case Priority::kDefault:
      pre_target_list_.push_back(prioritized);
      return;
    case Priority::kSystem:
      // Find the beginning of the kSystem part of the list and prepend
      // this new handler to that section.
      // TODO(katie): We are adding this to the front of the list because
      // previously the function PrependPreTargetHandler added items to the
      // front in this way. See if we can simply put each item in the list and
      // sort, or insert each item the same way, in a later change.
      it = std::lower_bound(pre_target_list_.begin(), pre_target_list_.end(),
                            prioritized);
      pre_target_list_.insert(it, prioritized);
      return;
    case Priority::kAccessibility:
      pre_target_list_.insert(pre_target_list_.begin(), prioritized);
      return;
  }
}

void EventTarget::RemovePreTargetHandler(EventHandler* handler) {
  EventHandlerPriorityList::iterator it, end;
  for (it = pre_target_list_.begin(), end = pre_target_list_.end(); it != end;
       ++it) {
    if (it->handler == handler) {
      pre_target_list_.erase(it);
      return;
    }
  }
}

void EventTarget::AddPostTargetHandler(EventHandler* handler) {
  DCHECK(handler);
  post_target_list_.push_back(handler);
}

void EventTarget::RemovePostTargetHandler(EventHandler* handler) {
  EventHandlerList::iterator find =
      std::find(post_target_list_.begin(),
                post_target_list_.end(),
                handler);
  if (find != post_target_list_.end())
    post_target_list_.erase(find);
}

bool EventTarget::IsPreTargetListEmpty() const {
  return pre_target_list_.empty();
}

EventHandler* EventTarget::SetTargetHandler(EventHandler* target_handler) {
  EventHandler* original_target_handler = target_handler_;
  target_handler_ = target_handler;
  return original_target_handler;
}

// TODO(katie): trigger all kAccessibility handlers in the tree first,
// then kSystem and finally kDefault, rather than doing each set per
// parent level.
void EventTarget::GetPreTargetHandlers(EventHandlerList* list) {
  EventTarget* target = this;
  while (target) {
    EventHandlerPriorityList::reverse_iterator it, rend;
    for (it = target->pre_target_list_.rbegin(),
            rend = target->pre_target_list_.rend();
        it != rend;
        ++it) {
      list->insert(list->begin(), it->handler);
    }
    target = target->GetParentTarget();
  }
}

void EventTarget::GetPostTargetHandlers(EventHandlerList* list) {
  EventTarget* target = this;
  while (target) {
    for (EventHandlerList::iterator it = target->post_target_list_.begin(),
        end = target->post_target_list_.end(); it != end; ++it) {
      list->push_back(*it);
    }
    target = target->GetParentTarget();
  }
}

}  // namespace ui