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 UI_EVENTS_BLINK_EVENT_WITH_CALLBACK_H_
6 #define UI_EVENTS_BLINK_EVENT_WITH_CALLBACK_H_
7 
8 #include <list>
9 
10 #include "ui/events/blink/input_handler_proxy.h"
11 #include "ui/latency/latency_info.h"
12 
13 namespace ui {
14 
15 namespace test {
16 class InputHandlerProxyEventQueueTest;
17 }
18 
19 class EventWithCallback {
20  public:
21   struct OriginalEventWithCallback {
22     OriginalEventWithCallback(
23         WebScopedInputEvent event,
24         const LatencyInfo& latency,
25         InputHandlerProxy::EventDispositionCallback callback);
26     ~OriginalEventWithCallback();
27     WebScopedInputEvent event_;
28     LatencyInfo latency_;
29     InputHandlerProxy::EventDispositionCallback callback_;
30   };
31   using OriginalEventList = std::list<OriginalEventWithCallback>;
32 
33   EventWithCallback(WebScopedInputEvent event,
34                     const LatencyInfo& latency,
35                     base::TimeTicks timestamp_now,
36                     InputHandlerProxy::EventDispositionCallback callback);
37   EventWithCallback(WebScopedInputEvent event,
38                     const LatencyInfo& latency,
39                     base::TimeTicks creation_timestamp,
40                     base::TimeTicks last_coalesced_timestamp,
41                     std::unique_ptr<OriginalEventList> original_events);
42   ~EventWithCallback();
43 
44   bool CanCoalesceWith(const EventWithCallback& other) const WARN_UNUSED_RESULT;
45   void CoalesceWith(EventWithCallback* other, base::TimeTicks timestamp_now);
46 
47   void RunCallbacks(InputHandlerProxy::EventDisposition,
48                     const LatencyInfo& latency,
49                     std::unique_ptr<DidOverscrollParams>,
50                     const blink::WebInputEventAttribution&);
51 
event()52   const blink::WebInputEvent& event() const { return *event_; }
event_pointer()53   blink::WebInputEvent* event_pointer() { return event_.get(); }
latency_info()54   const LatencyInfo& latency_info() const { return latency_; }
mutable_latency_info()55   LatencyInfo* mutable_latency_info() { return &latency_; }
creation_timestamp()56   base::TimeTicks creation_timestamp() const { return creation_timestamp_; }
last_coalesced_timestamp()57   base::TimeTicks last_coalesced_timestamp() const {
58     return last_coalesced_timestamp_;
59   }
coalesced_count()60   size_t coalesced_count() const { return original_events_.size(); }
original_events()61   OriginalEventList& original_events() { return original_events_; }
62   // |first_original_event()| is used as ID for tracing.
first_original_event()63   blink::WebInputEvent* first_original_event() {
64     return original_events_.empty() ? nullptr
65                                     : original_events_.front().event_.get();
66   }
67   void SetScrollbarManipulationHandledOnCompositorThread();
68 
69  private:
70   friend class test::InputHandlerProxyEventQueueTest;
71 
72   void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock);
73 
74   WebScopedInputEvent event_;
75   LatencyInfo latency_;
76   OriginalEventList original_events_;
77 
78   base::TimeTicks creation_timestamp_;
79   base::TimeTicks last_coalesced_timestamp_;
80 };
81 
82 }  // namespace ui
83 
84 #endif  // UI_EVENTS_BLINK_EVENT_WITH_CALLBACK_H_
85