Commit d610b37d authored by erg@google.com's avatar erg@google.com

Desktop aura: Put x11 cache in aura, instead of ui/base/x/.

This should solve the pyauto compile error because MessagePumpX is actually an aura component, not a general x11 component.

Instead of being a Singleton, X11AtomCache should tie its lifetime to an aura::Env, which are reset in the unit tests whenever an X server is switched out.

BUG=128584, 129075
TEST=none

Review URL: https://chromiumcodereview.appspot.com/10416020

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138290 0039d316-1c4b-4281-b951-d872f2087c98
parent 1cbfc987
......@@ -110,6 +110,8 @@
'window.h',
'window_delegate.h',
'window_observer.h',
'x11_atom_cache.cc',
'x11_atom_cache.h',
],
'conditions': [
['OS=="mac"', {
......
......@@ -12,6 +12,10 @@
#include "ui/aura/aura_export.h"
#include "ui/aura/client/stacking_client.h"
#if defined(USE_X11)
#include "ui/aura/x11_atom_cache.h"
#endif
namespace aura {
class EnvObserver;
......@@ -55,6 +59,12 @@ class AURA_EXPORT Env {
MonitorManager* monitor_manager() { return monitor_manager_.get(); }
void SetMonitorManager(MonitorManager* monitor_manager);
#if defined(USE_X11)
// Gets the X11 atom cache. This must not persist the cache across
// Env::DeleteInstance() calls.
X11AtomCache* atom_cache() { return &atom_cache_; }
#endif
// Returns the native event dispatcher. The result should only be passed to
// MessageLoopForUI::RunWithDispatcher() or
// MessageLoopForUI::RunAllPendingWithDispatcher(), or used to dispatch
......@@ -83,6 +93,7 @@ class AURA_EXPORT Env {
#if defined(USE_X11)
scoped_ptr<internal::MonitorChangeObserverX11> monitor_change_observer_;
X11AtomCache atom_cache_;
#endif
DISALLOW_COPY_AND_ASSIGN(Env);
......
......@@ -23,18 +23,17 @@
#include "ui/aura/env.h"
#include "ui/aura/event.h"
#include "ui/aura/root_window.h"
#include "ui/aura/x11_atom_cache.h"
#include "ui/base/cursor/cursor.h"
#include "ui/base/keycodes/keyboard_codes.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/touch/touch_factory.h"
#include "ui/base/view_prop.h"
#include "ui/base/x/x11_atom_cache.h"
#include "ui/base/x/x11_util.h"
#include "ui/compositor/layer.h"
#include "ui/gfx/codec/png_codec.h"
#include "ui/gfx/image/image.h"
using ui::X11AtomCache;
using std::max;
using std::min;
......@@ -393,10 +392,10 @@ RootWindowHostLinux::RootWindowHostLinux(const gfx::Rect& bounds)
// TODO(erg): We currently only request window deletion events. We also
// should listen for activation events and anything else that GTK+ listens
// for, and do something useful.
X11AtomCache* cache = X11AtomCache::GetInstance();
X11AtomCache* cache = aura::Env::GetInstance()->atom_cache();
::Atom protocols[2];
protocols[0] = cache->GetAtom(ui::ATOM_WM_DELETE_WINDOW);
protocols[1] = cache->GetAtom(ui::ATOM__NET_WM_PING);
protocols[0] = cache->GetAtom(ATOM_WM_DELETE_WINDOW);
protocols[1] = cache->GetAtom(ATOM__NET_WM_PING);
XSetWMProtocols(xdisplay_, xwindow_, protocols, 2);
// We need a WM_CLIENT_MACHINE and WM_LOCALE_NAME value so we integrate with
......@@ -408,7 +407,7 @@ RootWindowHostLinux::RootWindowHostLinux(const gfx::Rect& bounds)
pid_t pid = getpid();
XChangeProperty(xdisplay_,
xwindow_,
cache->GetAtom(ui::ATOM__NET_WM_PID),
cache->GetAtom(ATOM__NET_WM_PID),
XA_CARDINAL,
32,
PropModeReplace,
......@@ -580,11 +579,11 @@ bool RootWindowHostLinux::Dispatch(const base::NativeEvent& event) {
}
case ClientMessage: {
Atom message_type = static_cast<Atom>(xev->xclient.data.l[0]);
X11AtomCache* cache = X11AtomCache::GetInstance();
if (message_type == cache->GetAtom(ui::ATOM_WM_DELETE_WINDOW)) {
X11AtomCache* cache = aura::Env::GetInstance()->atom_cache();
if (message_type == cache->GetAtom(ATOM_WM_DELETE_WINDOW)) {
// We have received a close message from the window manager.
root_window_->OnRootWindowHostClosed();
} else if (message_type == cache->GetAtom(ui::ATOM__NET_WM_PING)) {
} else if (message_type == cache->GetAtom(ATOM__NET_WM_PING)) {
XEvent reply_event = *xev;
reply_event.xclient.window = x_root_window_;
......@@ -877,7 +876,7 @@ bool RootWindowHostLinux::IsWindowManagerPresent() {
// of WM_Sn selections (where n is a screen number).
return XGetSelectionOwner(
xdisplay_,
X11AtomCache::GetInstance()->GetAtom(ui::ATOM_WM_S0)) != None;
aura::Env::GetInstance()->atom_cache()->GetAtom(ATOM_WM_S0)) != None;
}
void RootWindowHostLinux::SetCursorInternal(gfx::NativeCursor cursor) {
......
......@@ -2,20 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/base/x/x11_atom_cache.h"
#include "ui/aura/x11_atom_cache.h"
#include <X11/Xatom.h>
#include "base/message_pump_x.h"
namespace ui {
namespace aura {
namespace {
// A list of atoms that we'll intern on host creation to save roundtrips to the
// X11 server. Must be kept in sync with AtomCache::AtomName
struct AtomInfo {
ui::AtomName id;
AtomName id;
const char* name;
} const kAtomList[] = {
{ ATOM_WM_DELETE_WINDOW, "WM_DELETE_WINDOW" },
......@@ -27,15 +27,10 @@ struct AtomInfo {
};
// Our lists need to stay in sync here.
COMPILE_ASSERT(arraysize(kAtomList) == ui::ATOM_COUNT,
atom_lists_are_same_size);
COMPILE_ASSERT(arraysize(kAtomList) == ATOM_COUNT, atom_lists_are_same_size);
} // namespace
X11AtomCache* X11AtomCache::GetInstance() {
return Singleton<X11AtomCache>::get();
}
::Atom X11AtomCache::GetAtom(AtomName name) const {
std::map<AtomName, ::Atom>::const_iterator it = cached_atoms_.find(name);
DCHECK(it != cached_atoms_.end());
......@@ -60,6 +55,4 @@ X11AtomCache::X11AtomCache() {
X11AtomCache::~X11AtomCache() {}
} // namespace ui
} // namespace aura
......@@ -2,12 +2,11 @@
// 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_ATOM_CACHE_H_
#define UI_BASE_X_X11_ATOM_CACHE_H_
#ifndef UI_AURA_X11_ATOM_CACHE_H_
#define UI_AURA_X11_ATOM_CACHE_H_
#include "base/basictypes.h"
#include "base/memory/singleton.h"
#include "ui/base/ui_export.h"
#include "ui/aura/aura_export.h"
#include <X11/Xlib.h>
......@@ -16,7 +15,8 @@
// Get rid of a macro from Xlib.h that conflicts with Aura's RootWindow class.
#undef RootWindow
namespace ui {
namespace aura {
class Env;
// Names of cached atoms that we fetch from X11AtomCache. Adding an entry here
// also requires adding an entry in the cc file.
......@@ -34,15 +34,13 @@ enum AtomName {
// Pre-caches all Atoms on first use to minimize roundtrips to the X11
// server. Assumes that we only have a single X11 display,
// base::MessagePumpX::GetDefaultXDisplay().
class UI_EXPORT X11AtomCache {
class AURA_EXPORT X11AtomCache {
public:
static X11AtomCache* GetInstance();
// Returns the pre-interned Atom by enum instead of string.
::Atom GetAtom(AtomName name) const;
private:
friend struct DefaultSingletonTraits<X11AtomCache>;
friend class aura::Env;
// Constructor performs all interning
X11AtomCache();
......@@ -53,6 +51,6 @@ class UI_EXPORT X11AtomCache {
DISALLOW_COPY_AND_ASSIGN(X11AtomCache);
};
} // namespace ui
} // namespace aura
#endif // UI_BASE_X_ATOM_CACHE_H_
#endif // UI_AURA_ATOM_CACHE_H_
......@@ -297,8 +297,6 @@
'base/x/root_window_property_watcher_x.h',
'base/x/work_area_watcher_x.cc',
'base/x/work_area_watcher_x.h',
'base/x/x11_atom_cache.cc',
'base/x/x11_atom_cache.h',
'base/x/x11_util.cc',
'base/x/x11_util.h',
'base/x/x11_util_internal.h',
......
......@@ -208,7 +208,7 @@ class MenuController::MenuScrollTask {
base::RepeatingTimer<MenuScrollTask> scrolling_timer_;
// Time we started scrolling at.
Time start_scroll_time_;
base::Time start_scroll_time_;
// How many pixels to scroll per second.
int pixels_per_second_;
......
......@@ -8,11 +8,11 @@
#include <X11/extensions/XInput2.h>
#include "base/message_pump_x.h"
#include "ui/aura/env.h"
#include "ui/aura/root_window.h"
#include "ui/aura/window_delegate.h"
#include "ui/aura/x11_atom_cache.h"
#include "ui/base/hit_test.h"
#include "ui/base/x/x11_atom_cache.h"
#include "ui/base/x/x11_atom_cache.h"
namespace {
......@@ -58,13 +58,13 @@ X11WindowEventFilter::X11WindowEventFilter(aura::RootWindow* root_window)
X11WindowEventFilter::~X11WindowEventFilter() {}
void X11WindowEventFilter::SetUseHostWindowBorders(bool use_os_border) {
ui::X11AtomCache* cache = ui::X11AtomCache::GetInstance();
aura::X11AtomCache* cache = aura::Env::GetInstance()->atom_cache();
MotifWmHints motif_hints;
memset(&motif_hints, 0, sizeof(motif_hints));
motif_hints.flags = kHintsDecorations;
motif_hints.decorations = use_os_border ? 1 : 0;
::Atom hint_atom = cache->GetAtom(ui::ATOM__MOTIF_WM_HINTS);
::Atom hint_atom = cache->GetAtom(aura::ATOM__MOTIF_WM_HINTS);
XChangeProperty(base::MessagePumpX::GetDefaultXDisplay(),
xwindow_,
hint_atom,
......@@ -173,8 +173,8 @@ bool X11WindowEventFilter::DispatchHostWindowDragMovement(
event.xclient.type = ClientMessage;
event.xclient.display = xdisplay_;
event.xclient.window = xwindow_;
event.xclient.message_type = ui::X11AtomCache::GetInstance()->GetAtom(
ui::ATOM__NET_WM_MOVERESIZE);
event.xclient.message_type = aura::Env::GetInstance()->atom_cache()->GetAtom(
aura::ATOM__NET_WM_MOVERESIZE);
event.xclient.format = 32;
event.xclient.data.l[0] = screen_location.x();
event.xclient.data.l[1] = screen_location.y();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment