Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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. | |
| 4 | |
| 5 #ifndef CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_ | |
| 6 #define CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_ | |
| 7 | |
| 8 #include <deque> | |
| 9 #include "content/common/content_export.h" | |
| 10 #include "content/common/input/event_with_latency_info.h" | |
| 11 #include "content/common/input/input_event_ack_state.h" | |
| 12 #include "content/common/input/input_event_dispatch_type.h" | |
| 13 #include "content/common/input/web_input_event_queue.h" | |
| 14 #include "third_party/WebKit/public/web/WebInputEvent.h" | |
| 15 #include "ui/events/latency_info.h" | |
| 16 | |
| 17 namespace content { | |
| 18 | |
| 19 template <typename BaseClass, typename BaseType> | |
| 20 class EventWithDispatchType : public BaseClass { | |
| 21 public: | |
| 22 EventWithDispatchType(const BaseType& e, | |
| 23 const ui::LatencyInfo& l, | |
| 24 InputEventDispatchType t) | |
| 25 : BaseClass(e, l), type(t) {} | |
| 26 | |
| 27 InputEventDispatchType type; | |
| 28 | |
| 29 bool CanCoalesceWith(const EventWithDispatchType& other) const | |
| 30 WARN_UNUSED_RESULT { | |
| 31 return other.type == type && BaseClass::CanCoalesceWith(other); | |
| 32 } | |
| 33 | |
| 34 void CoalesceWith(const EventWithDispatchType& other) { | |
| 35 BaseClass::CoalesceWith(other); | |
| 36 } | |
| 37 }; | |
| 38 | |
| 39 using PendingMouseWheelEvent = | |
| 40 EventWithDispatchType<MouseWheelEventWithLatencyInfo, | |
| 41 blink::WebMouseWheelEvent>; | |
| 42 | |
| 43 using PendingTouchEvent = | |
| 44 EventWithDispatchType<TouchEventWithLatencyInfo, blink::WebTouchEvent>; | |
| 45 | |
| 46 class CONTENT_EXPORT MainThreadEventQueueClient { | |
| 47 public: | |
| 48 // Send an |event| that was previously queued (possibly | |
| 49 // coalesced with another event) to the |routing_id|'s | |
| 50 // channel. Implementors must implement this callback. | |
| 51 virtual void SendEventToMainThread(int routing_id, | |
| 52 const blink::WebInputEvent* event, | |
| 53 const ui::LatencyInfo& latency, | |
| 54 InputEventDispatchType dispatch_type) = 0; | |
| 55 }; | |
| 56 | |
| 57 // MainThreadEventQueue implements a series of queues (one touch | |
| 58 // and one mouse wheel) for events that need to be queued between | |
| 59 // the compositor and main threads. When an event is sent | |
| 60 // from the compositor to main it can either be sent directly if no | |
| 61 // outstanding events of that type are in flight; or it needs to | |
| 62 // wait in a queue until the main thread has finished processing | |
| 63 // the in-flight event. This class tracks the state and queues | |
| 64 // for the event types. Methods on this class should only be called | |
| 65 // from the compositor thread. | |
|
tdresser
2016/03/16 15:34:47
Let's add some class level documentation illustrat
dtapuska
2016/03/17 13:32:36
Done.
tdresser
2016/03/17 14:07:31
Awesome, thanks!
| |
| 66 class CONTENT_EXPORT MainThreadEventQueue { | |
| 67 public: | |
| 68 MainThreadEventQueue(int routing_id, MainThreadEventQueueClient* client); | |
| 69 ~MainThreadEventQueue(); | |
| 70 | |
| 71 // Called once the compositor has handled |event| and indicated that it is | |
| 72 // a non-blocking event to be queued to the main thread. | |
| 73 bool HandleEvent(const blink::WebInputEvent* event, | |
| 74 const ui::LatencyInfo& latency, | |
| 75 InputEventDispatchType dispatch_type, | |
| 76 InputEventAckState ack_result); | |
| 77 | |
| 78 // Call once the main thread has handled an outstanding |type| event | |
| 79 // in flight. | |
| 80 void EventHandled(blink::WebInputEvent::Type type); | |
| 81 | |
| 82 private: | |
| 83 friend class MainThreadEventQueueTest; | |
| 84 int routing_id_; | |
| 85 MainThreadEventQueueClient* client_; | |
| 86 WebInputEventQueue<PendingMouseWheelEvent> wheel_events_; | |
| 87 WebInputEventQueue<PendingTouchEvent> touch_events_; | |
| 88 | |
| 89 DISALLOW_COPY_AND_ASSIGN(MainThreadEventQueue); | |
| 90 }; | |
| 91 | |
| 92 } // namespace content | |
| 93 | |
| 94 #endif // CONTENT_RENDERER_INPUT_MAIN_THREAD_EVENT_QUEUE_H_ | |
| OLD | NEW |