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 THIRD_PARTY_BLINK_PUBLIC_COMMON_INPUT_WEB_COALESCED_INPUT_EVENT_H_ 6 #define THIRD_PARTY_BLINK_PUBLIC_COMMON_INPUT_WEB_COALESCED_INPUT_EVENT_H_ 7 8 #include <memory> 9 #include <vector> 10 11 #include "third_party/blink/public/common/common_export.h" 12 #include "third_party/blink/public/common/input/web_input_event.h" 13 #include "third_party/blink/public/common/input/web_pointer_event.h" 14 #include "ui/latency/latency_info.h" 15 16 namespace blink { 17 18 // This class represents a polymorphic WebInputEvent structure with its 19 // coalesced events. The event could be any event defined in web_input_event.h, 20 // including those that cannot be coalesced. 21 class BLINK_COMMON_EXPORT WebCoalescedInputEvent { 22 public: 23 WebCoalescedInputEvent(const WebInputEvent&, const ui::LatencyInfo&); 24 WebCoalescedInputEvent(std::unique_ptr<WebInputEvent>, 25 const ui::LatencyInfo&); 26 WebCoalescedInputEvent(std::unique_ptr<WebInputEvent>, 27 std::vector<std::unique_ptr<WebInputEvent>>, 28 std::vector<std::unique_ptr<WebInputEvent>>, 29 const ui::LatencyInfo&); 30 // Copy constructor to deep copy the event. 31 WebCoalescedInputEvent(const WebCoalescedInputEvent&); 32 ~WebCoalescedInputEvent(); 33 34 WebInputEvent* EventPointer(); 35 void AddCoalescedEvent(const blink::WebInputEvent&); 36 const WebInputEvent& Event() const; 37 size_t CoalescedEventSize() const; 38 const WebInputEvent& CoalescedEvent(size_t index) const; 39 const std::vector<std::unique_ptr<WebInputEvent>>& 40 GetCoalescedEventsPointers() const; 41 42 void AddPredictedEvent(const blink::WebInputEvent&); 43 size_t PredictedEventSize() const; 44 const WebInputEvent& PredictedEvent(size_t index) const; 45 const std::vector<std::unique_ptr<WebInputEvent>>& 46 GetPredictedEventsPointers() const; 47 latency_info()48 const ui::LatencyInfo& latency_info() const { return latency_; } latency_info()49 ui::LatencyInfo& latency_info() { return latency_; } 50 51 bool CanCoalesceWith(const WebCoalescedInputEvent& other) const 52 WARN_UNUSED_RESULT; 53 54 // Coalesce with the |newer_event|. This object will be updated to take into 55 // account |newer_event|'s fields. 56 void CoalesceWith(const WebCoalescedInputEvent& newer_event); 57 58 private: 59 std::unique_ptr<WebInputEvent> event_; 60 std::vector<std::unique_ptr<WebInputEvent>> coalesced_events_; 61 std::vector<std::unique_ptr<WebInputEvent>> predicted_events_; 62 ui::LatencyInfo latency_; 63 }; 64 65 } // namespace blink 66 67 #endif 68