1a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved.
2a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// found in the LICENSE file.
4a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
5a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#ifndef UI_EVENTS_EVENT_TARGETER_H_
6a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#define UI_EVENTS_EVENT_TARGETER_H_
7a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
8a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "base/compiler_specific.h"
9a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "ui/events/event.h"
10a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "ui/events/events_export.h"
11a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
12a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)namespace ui {
13a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
14a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class Event;
15a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class EventTarget;
16a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class LocatedEvent;
17a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
18a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class EVENTS_EXPORT EventTargeter {
19a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) public:
20a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual ~EventTargeter();
21a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
22a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Returns the target |event| should be dispatched to. If there is no such
231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // target, return NULL. If |event| is a located event, the location of |event|
241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // is in the coordinate space of |root|. Furthermore, the targeter can mutate
251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // the event (e.g., by changing the location of the event to be in the
261320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // returned target's coordinate space) so that it can be dispatched to the
271320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // target without any further modification.
28a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual EventTarget* FindTargetForEvent(EventTarget* root,
29a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                          Event* event);
30a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
31a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Same as FindTargetForEvent(), but used for positional events. The location
32a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // etc. of |event| are in |root|'s coordinate system. When finding the target
33effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // for the event, the targeter can mutate the |event| (e.g. change the
34effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // coordinate to be in the returned target's coordinate system) so that it can
351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // be dispatched to the target without any further modification.
361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // TODO(tdanderson|sadrul): This should not be in the public API of
371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  //                          EventTargeter.
38a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual EventTarget* FindTargetForLocatedEvent(EventTarget* root,
39a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                                 LocatedEvent* event);
40a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
41010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Returns true if |target| or one of its descendants can be a target of
42010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // |event|. This requires that |target| and its descendants are not
43010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // prohibited from accepting the event, and that the event is within an
44010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // actionable region of the target's bounds. Note that the location etc. of
45010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // |event| is in |target|'s parent's coordinate system.
46010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // TODO(tdanderson|sadrul): This function should be made non-virtual and
47010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  //                          non-public.
48a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual bool SubtreeShouldBeExploredForEvent(EventTarget* target,
49a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                               const LocatedEvent& event);
50effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
51effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // Returns the next best target for |event| as compared to |previous_target|.
521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // |event| is in the local coordinate space of |previous_target|.
53effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // Also mutates |event| so that it can be dispatched to the returned target
54effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // (e.g., by changing |event|'s location to be in the returned target's
55effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  // coordinate space).
56effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  virtual EventTarget* FindNextBestTarget(EventTarget* previous_target,
57effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch                                          Event* event);
58010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
59010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) protected:
60010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Returns false if neither |target| nor any of its descendants are allowed
61010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // to accept |event| for reasons unrelated to the event's location or the
62010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // target's bounds. For example, overrides of this function may consider
63010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // attributes such as the visibility or enabledness of |target|. Note that
64010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // the location etc. of |event| is in |target|'s parent's coordinate system.
65010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual bool SubtreeCanAcceptEvent(EventTarget* target,
66010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                                     const LocatedEvent& event) const;
67010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
68010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Returns whether the location of the event is in an actionable region of the
69010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // target. Note that the location etc. of |event| is in the |target|'s
70010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // parent's coordinate system.
71010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual bool EventLocationInsideBounds(EventTarget* target,
72010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)                                         const LocatedEvent& event) const;
73a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)};
74a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
75a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}  // namespace ui
76a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
77a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#endif  // UI_EVENTS_EVENT_TARGETER_H_
78