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 UI_BASE_X_X11_WINDOW_CACHE_H_ | |
| 6 #define UI_BASE_X_X11_WINDOW_CACHE_H_ | |
| 7 | |
| 8 #include <xcb/xcb.h> | |
| 9 | |
| 10 #include <list> | |
| 11 #include <map> | |
| 12 | |
| 13 #include "ui/base/x/ui_base_x_export.h" | |
| 14 #include "ui/events/platform/platform_event_observer.h" | |
| 15 #include "ui/gfx/x/x11_types.h" | |
| 16 | |
| 17 namespace ui { | |
| 18 | |
| 19 class X11EventSource; | |
| 20 | |
| 21 // Keep tabs on the window tree starting from a root window. | |
| 22 class UI_BASE_X_EXPORT XWindowCache : public PlatformEventObserver { | |
| 23 private: | |
| 24 struct GetWindowAttributesRequest; | |
| 25 struct GetGeometryRequest; | |
| 26 struct ListPropertiesRequest; | |
| 27 struct QueryTreeRequest; | |
| 28 struct GetPropertyRequest; | |
| 29 | |
| 30 public: | |
| 31 // Clients should not modify any members of Property. | |
| 32 struct Window; | |
| 33 struct Property { | |
| 34 Property(xcb_atom_t name, Window* window, XWindowCache* cache); | |
| 35 ~Property(); | |
| 36 | |
| 37 xcb_atom_t name; | |
| 38 | |
| 39 GetPropertyRequest* property_request; | |
| 40 xcb_atom_t type; | |
| 41 // Format can be 8, 16, or 32, indicating how |data| should be interpreted. | |
| 42 uint8_t data_format; | |
| 43 int data_length; | |
| 44 union { | |
| 45 uint8_t* bits_8; | |
| 46 uint16_t* bits_16; | |
| 47 uint32_t* bits_32; | |
| 48 } data; | |
| 49 | |
| 50 XWindowCache* cache_; | |
| 51 }; | |
| 52 | |
| 53 // Clients should not modify any members of Window. | |
| 54 struct Window { | |
| 55 Window(xcb_window_t id, Window* parent, XWindowCache* cache); | |
| 56 ~Window(); | |
| 57 | |
| 58 xcb_window_t id; | |
| 59 Window* parent; | |
| 60 | |
| 61 GetWindowAttributesRequest* attributes_request; | |
|
Daniel Erat
2016/09/06 20:35:58
storing information about requests inside of the W
| |
| 62 bool override_redirect; | |
| 63 // |is_mapped| is different from the map_state that is returned by | |
| 64 // XGetWindowAttributes. map_state can be one of IsUnmapped, IsUnviewable, | |
| 65 // or IsViewable. map_state is set to IsUnviewable when the window is | |
| 66 // mapped but some ancestor window is unmapped. If you need to check for | |
| 67 // this case, you must do so manually. | |
| 68 bool is_mapped; | |
| 69 | |
| 70 GetGeometryRequest* geometry_request; | |
| 71 int16_t x, y; | |
| 72 uint16_t width, height; | |
| 73 uint16_t border_width; | |
| 74 | |
| 75 ListPropertiesRequest* properties_request; | |
| 76 std::map<xcb_atom_t, std::unique_ptr<Property>> properties; | |
| 77 | |
| 78 QueryTreeRequest* children_request; | |
| 79 std::list<std::unique_ptr<Window>> children; | |
| 80 | |
| 81 const Property* GetProperty(XID atom) const; | |
|
Daniel Erat
2016/09/06 20:35:58
see the style guide's guidance on using structs vs
| |
| 82 | |
| 83 XWindowCache* cache_; | |
| 84 }; | |
| 85 | |
| 86 XWindowCache(XDisplay* display, X11EventSource* event_source, XID root); | |
| 87 ~XWindowCache() override; | |
| 88 | |
| 89 // Returns null when window |id| is not cached. | |
| 90 const Window* GetWindow(XID id) const; | |
|
Daniel Erat
2016/09/06 20:35:58
please document the lifetime of the returned objec
| |
| 91 | |
| 92 protected: | |
| 93 // Overridden from PlatformEventDispatcher: | |
| 94 void WillProcessEvent(const PlatformEvent& event) override; | |
| 95 void DidProcessEvent(const PlatformEvent& event) override; | |
| 96 | |
| 97 private: | |
| 98 friend class XWindowCacheTest; | |
| 99 | |
| 100 // Clears all state and rebuilds the entire cache. | |
| 101 void ResetCache(); | |
| 102 void ResetCacheImpl(); | |
| 103 | |
| 104 // Creates and adds a new property to |window|. | |
| 105 void CacheProperty(Window* window, xcb_atom_t atom); | |
| 106 | |
| 107 // Allocates/Deallocates a Window. Responsible for setting up and breaking | |
| 108 // parent/child relationships. | |
| 109 void CreateWindow(xcb_window_t id, XWindowCache::Window* parent); | |
| 110 void DestroyWindow(Window* window); | |
| 111 | |
| 112 void ProcessEvent(const XEvent* event); | |
| 113 | |
| 114 Window* GetWindowInternal(XID id) const; | |
| 115 | |
| 116 XDisplay* display_; | |
| 117 xcb_connection_t* connection_; | |
| 118 xcb_window_t root_id_; | |
| 119 | |
| 120 X11EventSource* event_source_; | |
| 121 | |
| 122 std::unique_ptr<Window> root_; | |
| 123 std::map<xcb_window_t, Window*> windows_; | |
| 124 | |
| 125 // Don't cache icon properties because they take up too much space and we | |
| 126 // currently never use them. | |
| 127 xcb_intern_atom_cookie_t net_wm_icon_cookie_; | |
| 128 xcb_atom_t net_wm_icon_; | |
|
Daniel Erat
2016/09/06 20:35:58
put DISALLOW_COPY_AND_ASSIGN at the end of classes
| |
| 129 }; | |
| 130 | |
| 131 } // namespace ui | |
| 132 | |
| 133 #endif // UI_BASE_X_X11_WINDOW_CACHE_H_ | |
| OLD | NEW |