Views Omnibox: tolerate minor click-to-select-all dragging.
[chromium-blink-merge.git] / ui / gfx / x / x11_atom_cache.h
blobfefa64205d06e404b75675cabe32b3f603f4e4bb
1 // Copyright (c) 2012 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.
5 #ifndef UI_GFX_X_X11_ATOM_CACHE_H_
6 #define UI_GFX_X_X11_ATOM_CACHE_H_
8 #include "base/basictypes.h"
9 #include "ui/gfx/gfx_export.h"
11 #include <map>
12 #include <string>
14 #include <X11/Xlib.h>
16 // Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class.
17 #undef RootWindow
19 namespace ui {
21 // Pre-caches all Atoms on first use to minimize roundtrips to the X11
22 // server. By default, GetAtom() will CHECK() that atoms accessed through
23 // GetAtom() were passed to the constructor, but this behaviour can be changed
24 // with allow_uncached_atoms().
25 class GFX_EXPORT X11AtomCache {
26 public:
27 // Preinterns the NULL terminated list of string |to_cache_ on |xdisplay|.
28 X11AtomCache(Display* xdisplay, const char** to_cache);
29 ~X11AtomCache();
31 // Returns the pre-interned Atom without having to go to the x server.
32 ::Atom GetAtom(const char*) const;
34 // When an Atom isn't in the list of items we've cached, we should look it
35 // up, cache it locally, and then return the result.
36 void allow_uncached_atoms() { uncached_atoms_allowed_ = true; }
38 private:
39 Display* xdisplay_;
41 bool uncached_atoms_allowed_;
43 mutable std::map<std::string, ::Atom> cached_atoms_;
45 DISALLOW_COPY_AND_ASSIGN(X11AtomCache);
48 } // namespace ui
50 #endif // UI_GFX_X_X11_ATOM_CACHE_H_