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