Chromium Code Reviews| Index: ui/base/x/x11_window_cache.h |
| diff --git a/ui/base/x/x11_window_cache.h b/ui/base/x/x11_window_cache.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7148c0773c3039c0fae6c1875973b141f5ff9b55 |
| --- /dev/null |
| +++ b/ui/base/x/x11_window_cache.h |
| @@ -0,0 +1,133 @@ |
| +// Copyright 2016 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_BASE_X_X11_WINDOW_CACHE_H_ |
| +#define UI_BASE_X_X11_WINDOW_CACHE_H_ |
| + |
| +#include <xcb/xcb.h> |
| + |
| +#include <list> |
| +#include <map> |
| + |
| +#include "ui/base/x/ui_base_x_export.h" |
| +#include "ui/events/platform/platform_event_observer.h" |
| +#include "ui/gfx/x/x11_types.h" |
| + |
| +namespace ui { |
| + |
| +class X11EventSource; |
| + |
| +// Keep tabs on the window tree starting from a root window. |
| +class UI_BASE_X_EXPORT XWindowCache : public PlatformEventObserver { |
| + private: |
| + struct GetWindowAttributesRequest; |
| + struct GetGeometryRequest; |
| + struct ListPropertiesRequest; |
| + struct QueryTreeRequest; |
| + struct GetPropertyRequest; |
| + |
| + public: |
| + // Clients should not modify any members of Property. |
| + struct Window; |
| + struct Property { |
| + Property(xcb_atom_t name, Window* window, XWindowCache* cache); |
| + ~Property(); |
| + |
| + xcb_atom_t name; |
| + |
| + GetPropertyRequest* property_request; |
| + xcb_atom_t type; |
| + // Format can be 8, 16, or 32, indicating how |data| should be interpreted. |
| + uint8_t data_format; |
| + int data_length; |
| + union { |
| + uint8_t* bits_8; |
| + uint16_t* bits_16; |
| + uint32_t* bits_32; |
| + } data; |
| + |
| + XWindowCache* cache_; |
| + }; |
| + |
| + // Clients should not modify any members of Window. |
| + struct Window { |
| + Window(xcb_window_t id, Window* parent, XWindowCache* cache); |
| + ~Window(); |
| + |
| + xcb_window_t id; |
| + Window* parent; |
| + |
| + GetWindowAttributesRequest* attributes_request; |
|
Daniel Erat
2016/09/06 20:35:58
storing information about requests inside of the W
|
| + bool override_redirect; |
| + // |is_mapped| is different from the map_state that is returned by |
| + // XGetWindowAttributes. map_state can be one of IsUnmapped, IsUnviewable, |
| + // or IsViewable. map_state is set to IsUnviewable when the window is |
| + // mapped but some ancestor window is unmapped. If you need to check for |
| + // this case, you must do so manually. |
| + bool is_mapped; |
| + |
| + GetGeometryRequest* geometry_request; |
| + int16_t x, y; |
| + uint16_t width, height; |
| + uint16_t border_width; |
| + |
| + ListPropertiesRequest* properties_request; |
| + std::map<xcb_atom_t, std::unique_ptr<Property>> properties; |
| + |
| + QueryTreeRequest* children_request; |
| + std::list<std::unique_ptr<Window>> children; |
| + |
| + const Property* GetProperty(XID atom) const; |
|
Daniel Erat
2016/09/06 20:35:58
see the style guide's guidance on using structs vs
|
| + |
| + XWindowCache* cache_; |
| + }; |
| + |
| + XWindowCache(XDisplay* display, X11EventSource* event_source, XID root); |
| + ~XWindowCache() override; |
| + |
| + // Returns null when window |id| is not cached. |
| + const Window* GetWindow(XID id) const; |
|
Daniel Erat
2016/09/06 20:35:58
please document the lifetime of the returned objec
|
| + |
| + protected: |
| + // Overridden from PlatformEventDispatcher: |
| + void WillProcessEvent(const PlatformEvent& event) override; |
| + void DidProcessEvent(const PlatformEvent& event) override; |
| + |
| + private: |
| + friend class XWindowCacheTest; |
| + |
| + // Clears all state and rebuilds the entire cache. |
| + void ResetCache(); |
| + void ResetCacheImpl(); |
| + |
| + // Creates and adds a new property to |window|. |
| + void CacheProperty(Window* window, xcb_atom_t atom); |
| + |
| + // Allocates/Deallocates a Window. Responsible for setting up and breaking |
| + // parent/child relationships. |
| + void CreateWindow(xcb_window_t id, XWindowCache::Window* parent); |
| + void DestroyWindow(Window* window); |
| + |
| + void ProcessEvent(const XEvent* event); |
| + |
| + Window* GetWindowInternal(XID id) const; |
| + |
| + XDisplay* display_; |
| + xcb_connection_t* connection_; |
| + xcb_window_t root_id_; |
| + |
| + X11EventSource* event_source_; |
| + |
| + std::unique_ptr<Window> root_; |
| + std::map<xcb_window_t, Window*> windows_; |
| + |
| + // Don't cache icon properties because they take up too much space and we |
| + // currently never use them. |
| + xcb_intern_atom_cookie_t net_wm_icon_cookie_; |
| + xcb_atom_t net_wm_icon_; |
|
Daniel Erat
2016/09/06 20:35:58
put DISALLOW_COPY_AND_ASSIGN at the end of classes
|
| +}; |
| + |
| +} // namespace ui |
| + |
| +#endif // UI_BASE_X_X11_WINDOW_CACHE_H_ |