diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-12 14:27:29 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-13 09:35:20 +0000 |
commit | c30a6232df03e1efbd9f3b226777b07e087a1122 (patch) | |
tree | e992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/ui/gfx/x/event.h | |
parent | 7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff) | |
download | qtwebengine-chromium-85-based.tar.gz |
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/ui/gfx/x/event.h')
-rw-r--r-- | chromium/ui/gfx/x/event.h | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/chromium/ui/gfx/x/event.h b/chromium/ui/gfx/x/event.h new file mode 100644 index 00000000000..37073dbd584 --- /dev/null +++ b/chromium/ui/gfx/x/event.h @@ -0,0 +1,92 @@ +// Copyright 2020 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef UI_GFX_X_EVENT_H_ +#define UI_GFX_X_EVENT_H_ + +#include <X11/Xlib.h> +#include <xcb/xcb.h> + +#include <cstdint> +#include <utility> + +#include "base/component_export.h" + +namespace x11 { + +class Connection; +class Event; + +COMPONENT_EXPORT(X11) +void ReadEvent(Event* event, Connection* connection, const uint8_t* buffer); + +class COMPONENT_EXPORT(X11) Event { + public: + // Used to create events for testing. + template <typename T> + Event(XEvent* xlib_event, T&& xproto_event) { + sequence_valid_ = true; + sequence_ = xlib_event_.xany.serial; + custom_allocated_xlib_event_ = true; + xlib_event_ = *xlib_event; + type_id_ = T::type_id; + deleter_ = [](void* event) { delete reinterpret_cast<T*>(event); }; + event_ = new T(std::forward<T>(xproto_event)); + } + + Event(); + Event(xcb_generic_event_t* xcb_event, + Connection* connection, + bool sequence_valid = true); + + Event(const Event&) = delete; + Event& operator=(const Event&) = delete; + + Event(Event&& event); + Event& operator=(Event&& event); + + ~Event(); + + template <typename T> + T* As() { + if (type_id_ == T::type_id) + return reinterpret_cast<T*>(event_); + return nullptr; + } + + template <typename T> + const T* As() const { + return const_cast<Event*>(this)->As<T>(); + } + + bool sequence_valid() const { return sequence_valid_; } + uint32_t sequence() const { return sequence_; } + + const XEvent& xlib_event() const { return xlib_event_; } + XEvent& xlib_event() { return xlib_event_; } + + private: + friend void ReadEvent(Event* event, + Connection* connection, + const uint8_t* buffer); + + void Dealloc(); + + bool sequence_valid_ = false; + uint32_t sequence_ = 0; + + // Indicates if |xlib_event_| was allocated manually and therefore + // needs to be freed manually. + bool custom_allocated_xlib_event_ = false; + XEvent xlib_event_{}; + + // XProto event state. + int type_id_ = 0; + void (*deleter_)(void*) = nullptr; + void* event_ = nullptr; +}; + +} // namespace x11 + +#endif // UI_GFX_X_EVENT_H_ |