Remove ExtensionPrefs::SetDidExtensionEscalatePermissions.
[chromium-blink-merge.git] / ui / events / event_target.h
blobe8b14a6445851b3a5b2e00a9c5dae39c0a79da2e
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 #ifndef UI_EVENTS_EVENT_TARGET_H_
6 #define UI_EVENTS_EVENT_TARGET_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "ui/events/event_handler.h"
14 #include "ui/events/events_export.h"
16 namespace ui {
18 class EventDispatcher;
19 class EventTargeter;
20 class EventTargetIterator;
21 class LocatedEvent;
23 class EVENTS_EXPORT EventTarget : public EventHandler {
24 public:
25 class DispatcherApi {
26 public:
27 explicit DispatcherApi(EventTarget* target) : target_(target) {}
29 const EventHandlerList& pre_target_list() const {
30 return target_->pre_target_list_;
33 private:
34 DispatcherApi();
35 EventTarget* target_;
37 DISALLOW_COPY_AND_ASSIGN(DispatcherApi);
40 EventTarget();
41 ~EventTarget() override;
43 virtual bool CanAcceptEvent(const Event& event) = 0;
45 // Returns the parent EventTarget in the event-target tree.
46 virtual EventTarget* GetParentTarget() = 0;
48 // Returns an iterator an EventTargeter can use to iterate over the list of
49 // child EventTargets.
50 virtual scoped_ptr<EventTargetIterator> GetChildIterator() const = 0;
52 // Returns the EventTargeter that should be used to find the target for an
53 // event in the subtree rooted at this EventTarget.
54 virtual EventTargeter* GetEventTargeter() = 0;
56 // Updates the states in |event| (e.g. location) to be suitable for |target|,
57 // so that |event| can be dispatched to |target|.
58 virtual void ConvertEventToTarget(EventTarget* target,
59 LocatedEvent* event);
61 // Adds a handler to receive events before the target. The handler must be
62 // explicitly removed from the target before the handler is destroyed. The
63 // EventTarget does not take ownership of the handler.
64 void AddPreTargetHandler(EventHandler* handler);
66 // Same as AddPreTargetHandler except that the |handler| is added to the front
67 // of the list so it is the first one to receive events.
68 void PrependPreTargetHandler(EventHandler* handler);
69 void RemovePreTargetHandler(EventHandler* handler);
71 // Adds a handler to receive events after the target. The handler must be
72 // explicitly removed from the target before the handler is destroyed. The
73 // EventTarget does not take ownership of the handler.
74 void AddPostTargetHandler(EventHandler* handler);
75 void RemovePostTargetHandler(EventHandler* handler);
77 // Returns true if the event pre target list is empty.
78 bool IsPreTargetListEmpty() const;
80 void set_target_handler(EventHandler* handler) {
81 target_handler_ = handler;
84 protected:
85 EventHandler* target_handler() { return target_handler_; }
87 // Overridden from EventHandler:
88 void OnEvent(Event* event) override;
89 void OnKeyEvent(KeyEvent* event) override;
90 void OnMouseEvent(MouseEvent* event) override;
91 void OnScrollEvent(ScrollEvent* event) override;
92 void OnTouchEvent(TouchEvent* event) override;
93 void OnGestureEvent(GestureEvent* event) override;
95 private:
96 friend class EventDispatcher;
97 friend class EventTargetTestApi;
99 // Returns the list of handlers that should receive the event before the
100 // target. The handlers from the outermost target are first in the list, and
101 // the handlers on |this| are the last in the list.
102 void GetPreTargetHandlers(EventHandlerList* list);
104 // Returns the list of handlers that should receive the event after the
105 // target. The handlers from the outermost target are last in the list, and
106 // the handlers on |this| are the first in the list.
107 void GetPostTargetHandlers(EventHandlerList* list);
109 EventHandlerList pre_target_list_;
110 EventHandlerList post_target_list_;
111 EventHandler* target_handler_;
113 DISALLOW_COPY_AND_ASSIGN(EventTarget);
116 } // namespace ui
118 #endif // UI_EVENTS_EVENT_TARGET_H_