OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_EVENTS_EVENT_REWRITER_H_ | 5 #ifndef UI_EVENTS_EVENT_REWRITER_H_ |
6 #define UI_EVENTS_EVENT_REWRITER_H_ | 6 #define UI_EVENTS_EVENT_REWRITER_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "ui/events/events_export.h" | 9 #include "ui/events/events_export.h" |
10 | 10 |
11 namespace ui { | 11 namespace ui { |
12 | 12 |
13 class Event; | 13 class Event; |
14 | 14 |
15 // Return status of EventRewriter operations; see that class below. | 15 // Return status of EventRewriter operations; see that class below. |
16 enum EventRewriteStatus { | 16 enum EventRewriteStatus { |
17 // Nothing was done; no rewritten event returned. Pass the original | 17 // Nothing was done; no rewritten event returned. Pass the original |
18 // event to later rewriters, or send it to the EventProcessor if this | 18 // event to later rewriters, or send it to the EventProcessor if this |
19 // was the final rewriter. | 19 // was the final rewriter. |
20 EVENT_REWRITE_CONTINUE, | 20 EVENT_REWRITE_CONTINUE, |
21 | 21 |
22 // The event has been rewritten. Send the rewritten event to the | 22 // The event has been rewritten. Send the rewritten event (which may |
23 // EventProcessor instead of the original event (without sending | 23 // be either the modified original event, or a newly allocated event) |
24 // either to any later rewriters). | 24 // to the EventProcessor, without sending it to any later rewriters. |
25 EVENT_REWRITE_REWRITTEN, | 25 EVENT_REWRITE_REWRITTEN, |
26 | 26 |
27 // The event should be discarded, neither passing it to any later | 27 // The event should be discarded, neither passing it to any later |
28 // rewriters nor sending it to the EventProcessor. | 28 // rewriters nor sending it to the EventProcessor. |
29 EVENT_REWRITE_DISCARD, | 29 EVENT_REWRITE_DISCARD, |
30 | 30 |
31 // The event has been rewritten. As for EVENT_REWRITE_REWRITTEN, | 31 // The event has been rewritten. As for EVENT_REWRITE_REWRITTEN, |
32 // send the rewritten event to the EventProcessor instead of the | 32 // send the rewritten event to the EventProcessor without invoking |
33 // original event (without sending either to any later rewriters). | 33 // any later rewriters. In addition the rewriter has one or more |
34 // In addition the rewriter has one or more additional new events | 34 // additional new events to be retrieved using |NextDispatchEvent()| |
35 // to be retrieved using |NextDispatchEvent()| and sent to the | 35 // and sent to the EventProcessor. |
36 // EventProcessor. | |
37 EVENT_REWRITE_DISPATCH_ANOTHER, | 36 EVENT_REWRITE_DISPATCH_ANOTHER, |
38 }; | 37 }; |
39 | 38 |
40 // EventRewriter provides a mechanism for Events to be rewritten | 39 // EventRewriter provides a mechanism for Events to be rewritten |
41 // before being dispatched from EventSource to EventProcessor. | 40 // before being dispatched from EventSource to EventProcessor. |
42 class EVENTS_EXPORT EventRewriter { | 41 class EVENTS_EXPORT EventRewriter { |
43 public: | 42 public: |
44 virtual ~EventRewriter() {} | 43 virtual ~EventRewriter() {} |
45 | 44 |
46 // Potentially rewrites (replaces) an event, or requests it be discarded. | 45 // Potentially rewrites or replaces an event, or requests it be discarded. |
47 // or discards an event. If the rewriter wants to rewrite an event, and | 46 // A rewritten event may either be the modified original |event|, or a |
48 // dispatch another event once the rewritten event is dispatched, it should | 47 // newly allocated event returned through |rewritten_event| (but not both). |
49 // return EVENT_REWRITE_DISPATCH_ANOTHER, and return the next event to | 48 // If the rewriter wants to rewrite an event, and dispatch another |
| 49 // event once the rewritten event is dispatched, it should return |
| 50 // EVENT_REWRITE_DISPATCH_ANOTHER, and return the next event to |
50 // dispatch from |NextDispatchEvent()|. | 51 // dispatch from |NextDispatchEvent()|. |
51 virtual EventRewriteStatus RewriteEvent( | 52 virtual EventRewriteStatus RewriteEvent( |
52 const Event& event, | 53 Event* event, |
53 scoped_ptr<Event>* rewritten_event) = 0; | 54 scoped_ptr<Event>* rewritten_event) = 0; |
54 | 55 |
55 // Supplies an additional event to be dispatched. It is only valid to | 56 // Supplies an additional event to be dispatched. It is only valid to |
56 // call this after the immediately previous call to |RewriteEvent()| | 57 // call this after the immediately previous call to |RewriteEvent()| |
57 // or |NextDispatchEvent()| has returned EVENT_REWRITE_DISPATCH_ANOTHER. | 58 // or |NextDispatchEvent()| has returned EVENT_REWRITE_DISPATCH_ANOTHER. |
58 // Should only return either EVENT_REWRITE_REWRITTEN or | 59 // Should only return either EVENT_REWRITE_REWRITTEN or |
59 // EVENT_REWRITE_DISPATCH_ANOTHER; otherwise the previous call should not | 60 // EVENT_REWRITE_DISPATCH_ANOTHER; otherwise the previous call should not |
60 // have returned EVENT_REWRITE_DISPATCH_ANOTHER. | 61 // have returned EVENT_REWRITE_DISPATCH_ANOTHER. |last_event| must be |
| 62 // the previous rewritten event, and the additional event is returned |
| 63 // through |new_event|. |
61 virtual EventRewriteStatus NextDispatchEvent( | 64 virtual EventRewriteStatus NextDispatchEvent( |
62 const Event& last_event, | 65 const Event& last_event, |
63 scoped_ptr<Event>* new_event) = 0; | 66 scoped_ptr<Event>* new_event) = 0; |
64 }; | 67 }; |
65 | 68 |
66 } // namespace ui | 69 } // namespace ui |
67 | 70 |
68 #endif // UI_EVENTS_EVENT_REWRITER_H_ | 71 #endif // UI_EVENTS_EVENT_REWRITER_H_ |
OLD | NEW |