Commit 3fdecebf authored by pkotwicz@chromium.org's avatar pkotwicz@chromium.org

Remove X11/Xlib.h include from selection_requestor.h

Removing the include of Xlib.h makes selection_requestor.h more easily
testable. In particular, the definition of None in X.h conflicts with
that in gtest-type-util.h

This CL also adds XAtom to x11_types.h so that it does not need to be forward declared everywhere.

BUG=None
TEST=None
R=derat,danakj
TBR=dcheng (for trivial change to clipboard_aurax11.cc)

Review URL: https://codereview.chromium.org/392153002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@283740 0039d316-1c4b-4281-b951-d872f2087c98
parent 2a9e56a2
......@@ -546,11 +546,11 @@ uint32_t Clipboard::AuraX11Details::DispatchEvent(const PlatformEvent& xev) {
case SelectionNotify: {
::Atom selection = xev->xselection.selection;
if (selection == XA_PRIMARY)
primary_requestor_.OnSelectionNotify(xev->xselection);
primary_requestor_.OnSelectionNotify(*xev);
else if (selection == GetCopyPasteSelection())
clipboard_requestor_.OnSelectionNotify(xev->xselection);
clipboard_requestor_.OnSelectionNotify(*xev);
else if (selection == atom_cache_.GetAtom(kClipboardManager))
clipboard_manager_requestor_.OnSelectionNotify(xev->xselection);
clipboard_manager_requestor_.OnSelectionNotify(*xev);
break;
}
case SelectionClear: {
......
......@@ -4,6 +4,8 @@
#include "ui/base/x/selection_requestor.h"
#include <X11/Xlib.h>
#include "base/run_loop.h"
#include "ui/base/x/selection_utils.h"
#include "ui/base/x/x11_util.h"
......@@ -24,9 +26,9 @@ const char* kAtomsToCache[] = {
} // namespace
SelectionRequestor::SelectionRequestor(Display* x_display,
Window x_window,
Atom selection_name,
SelectionRequestor::SelectionRequestor(XDisplay* x_display,
XID x_window,
XAtom selection_name,
PlatformEventDispatcher* dispatcher)
: x_display_(x_display),
x_window_(x_window),
......@@ -38,15 +40,15 @@ SelectionRequestor::SelectionRequestor(Display* x_display,
SelectionRequestor::~SelectionRequestor() {}
bool SelectionRequestor::PerformBlockingConvertSelection(
Atom target,
XAtom target,
scoped_refptr<base::RefCountedMemory>* out_data,
size_t* out_data_items,
Atom* out_type) {
XAtom* out_type) {
// The name of the property that we are either:
// - Passing as a parameter with the XConvertSelection() request.
// OR
// - Asking the selection owner to set on |x_window_|.
Atom property = atom_cache_.GetAtom(kChromeSelection);
XAtom property = atom_cache_.GetAtom(kChromeSelection);
XConvertSelection(x_display_,
selection_name_,
......@@ -72,18 +74,18 @@ bool SelectionRequestor::PerformBlockingConvertSelection(
}
void SelectionRequestor::PerformBlockingConvertSelectionWithParameter(
Atom target,
const std::vector< ::Atom>& parameter) {
XAtom target,
const std::vector<XAtom>& parameter) {
SetAtomArrayProperty(x_window_, kChromeSelection, "ATOM", parameter);
PerformBlockingConvertSelection(target, NULL, NULL, NULL);
}
SelectionData SelectionRequestor::RequestAndWaitForTypes(
const std::vector< ::Atom>& types) {
for (std::vector< ::Atom>::const_iterator it = types.begin();
const std::vector<XAtom>& types) {
for (std::vector<XAtom>::const_iterator it = types.begin();
it != types.end(); ++it) {
scoped_refptr<base::RefCountedMemory> data;
::Atom type = None;
XAtom type = None;
if (PerformBlockingConvertSelection(*it,
&data,
NULL,
......@@ -96,18 +98,18 @@ SelectionData SelectionRequestor::RequestAndWaitForTypes(
return SelectionData();
}
void SelectionRequestor::OnSelectionNotify(const XSelectionEvent& event) {
void SelectionRequestor::OnSelectionNotify(const XEvent& event) {
// Find the PendingRequest for the corresponding XConvertSelection call. If
// there are multiple pending requests on the same target, satisfy them in
// FIFO order.
PendingRequest* request_notified = NULL;
if (selection_name_ == event.selection) {
if (selection_name_ == event.xselection.selection) {
for (std::list<PendingRequest*>::iterator iter = pending_requests_.begin();
iter != pending_requests_.end(); ++iter) {
PendingRequest* request = *iter;
if (request->returned)
continue;
if (request->target != event.target)
if (request->target != event.xselection.target)
continue;
request_notified = request;
break;
......@@ -117,16 +119,17 @@ void SelectionRequestor::OnSelectionNotify(const XSelectionEvent& event) {
// This event doesn't correspond to any XConvertSelection calls that we
// issued in PerformBlockingConvertSelection. This shouldn't happen, but any
// client can send any message, so it can happen.
XAtom returned_property = event.xselection.property;
if (!request_notified) {
// ICCCM requires us to delete the property passed into SelectionNotify. If
// |request_notified| is true, the property will be deleted when the run
// loop has quit.
if (event.property != None)
XDeleteProperty(x_display_, x_window_, event.property);
if (returned_property != None)
XDeleteProperty(x_display_, x_window_, returned_property);
return;
}
request_notified->returned_property = event.property;
request_notified->returned_property = returned_property;
request_notified->returned = true;
if (!request_notified->quit_closure.is_null())
......@@ -171,7 +174,7 @@ void SelectionRequestor::BlockTillSelectionNotifyForRequest(
pending_requests_.pop_back();
}
SelectionRequestor::PendingRequest::PendingRequest(Atom target)
SelectionRequestor::PendingRequest::PendingRequest(XAtom target)
: target(target),
returned_property(None),
returned(false) {
......
......@@ -15,9 +15,11 @@
#include "base/basictypes.h"
#include "base/callback.h"
#include "base/event_types.h"
#include "base/memory/ref_counted_memory.h"
#include "ui/base/ui_base_export.h"
#include "ui/gfx/x/x11_atom_cache.h"
#include "ui/gfx/x/x11_types.h"
namespace ui {
class PlatformEventDispatcher;
......@@ -32,9 +34,9 @@ class SelectionData;
// implement per-component fast-paths.
class UI_BASE_EXPORT SelectionRequestor {
public:
SelectionRequestor(Display* xdisplay,
::Window xwindow,
::Atom selection_name,
SelectionRequestor(XDisplay* xdisplay,
XID xwindow,
XAtom selection_name,
PlatformEventDispatcher* dispatcher);
~SelectionRequestor();
......@@ -43,34 +45,34 @@ class UI_BASE_EXPORT SelectionRequestor {
// back. The result is stored in |out_data|.
// |out_data_items| is the length of |out_data| in |out_type| items.
bool PerformBlockingConvertSelection(
::Atom target,
XAtom target,
scoped_refptr<base::RefCountedMemory>* out_data,
size_t* out_data_items,
::Atom* out_type);
XAtom* out_type);
// Requests |target| from the selection that we handle, passing |parameter|
// as a parameter to XConvertSelection().
void PerformBlockingConvertSelectionWithParameter(
::Atom target,
const std::vector< ::Atom>& parameter);
XAtom target,
const std::vector<XAtom>& parameter);
// Returns the first of |types| offered by the current selection holder, or
// returns NULL if none of those types are available.
SelectionData RequestAndWaitForTypes(const std::vector< ::Atom>& types);
SelectionData RequestAndWaitForTypes(const std::vector<XAtom>& types);
// It is our owner's responsibility to plumb X11 SelectionNotify events on
// |xwindow_| to us.
void OnSelectionNotify(const XSelectionEvent& event);
void OnSelectionNotify(const XEvent& event);
private:
// A request that has been issued and we are waiting for a response to.
struct PendingRequest {
explicit PendingRequest(Atom target);
explicit PendingRequest(XAtom target);
~PendingRequest();
// Data to the current XConvertSelection request. Used for error detection;
// we verify it on the return message.
::Atom target;
XAtom target;
// Called to terminate the nested message loop.
base::Closure quit_closure;
......@@ -79,7 +81,7 @@ class UI_BASE_EXPORT SelectionRequestor {
// success. If None, our request failed somehow. If equal to the property
// atom that we sent in the XConvertSelection call, we can read that
// property on |x_window_| for the requested data.
::Atom returned_property;
XAtom returned_property;
// Set to true when return_property is populated.
bool returned;
......@@ -90,11 +92,11 @@ class UI_BASE_EXPORT SelectionRequestor {
void BlockTillSelectionNotifyForRequest(PendingRequest* request);
// Our X11 state.
Display* x_display_;
::Window x_window_;
XDisplay* x_display_;
XID x_window_;
// The X11 selection that this instance communicates on.
::Atom selection_name_;
XAtom selection_name_;
// Dispatcher which handles SelectionNotify and SelectionRequest for
// |selection_name_|. PerformBlockingConvertSelection() calls the
......
......@@ -25,7 +25,7 @@ XMenuList::~XMenuList() {
void XMenuList::MaybeRegisterMenu(XID menu) {
int value = 0;
if (!GetIntProperty(menu, "_NET_WM_WINDOW_TYPE", &value) ||
static_cast<Atom>(value) != menu_type_atom_) {
static_cast<XAtom>(value) != menu_type_atom_) {
return;
}
menus_.push_back(menu);
......
......@@ -11,8 +11,6 @@
#include "ui/base/ui_base_export.h"
#include "ui/gfx/x/x11_types.h"
typedef unsigned long Atom;
// A process wide singleton cache for X menus.
template <typename T> struct DefaultSingletonTraits;
......@@ -39,7 +37,7 @@ class UI_BASE_EXPORT XMenuList {
~XMenuList();
std::vector<XID> menus_;
::Atom menu_type_atom_;
XAtom menu_type_atom_;
DISALLOW_COPY_AND_ASSIGN(XMenuList);
};
......
......@@ -84,9 +84,9 @@ int DefaultX11IOErrorHandler(XDisplay* d) {
// Note: The caller should free the resulting value data.
bool GetProperty(XID window, const std::string& property_name, long max_length,
Atom* type, int* format, unsigned long* num_items,
XAtom* type, int* format, unsigned long* num_items,
unsigned char** property) {
Atom property_atom = GetAtom(property_name.c_str());
XAtom property_atom = GetAtom(property_name.c_str());
unsigned long remaining_bytes = 0;
return XGetWindowProperty(gfx::GetXDisplay(),
window,
......@@ -483,7 +483,7 @@ void SetUseOSWindowFrame(XID window, bool use_os_window_frame) {
motif_hints.flags = (1L << 1);
motif_hints.decorations = use_os_window_frame ? 1 : 0;
::Atom hint_atom = GetAtom("_MOTIF_WM_HINTS");
XAtom hint_atom = GetAtom("_MOTIF_WM_HINTS");
XChangeProperty(gfx::GetXDisplay(),
window,
hint_atom,
......@@ -553,9 +553,9 @@ bool IsWindowVisible(XID window) {
return false;
// Minimized windows are not visible.
std::vector<Atom> wm_states;
std::vector<XAtom> wm_states;
if (GetAtomArrayProperty(window, "_NET_WM_STATE", &wm_states)) {
Atom hidden_atom = GetAtom("_NET_WM_STATE_HIDDEN");
XAtom hidden_atom = GetAtom("_NET_WM_STATE_HIDDEN");
if (std::find(wm_states.begin(), wm_states.end(), hidden_atom) !=
wm_states.end()) {
return false;
......@@ -663,7 +663,7 @@ bool WindowContainsPoint(XID window, gfx::Point screen_loc) {
bool PropertyExists(XID window, const std::string& property_name) {
Atom type = None;
XAtom type = None;
int format = 0; // size in bits of each item in 'property'
unsigned long num_items = 0;
unsigned char* property = NULL;
......@@ -678,14 +678,14 @@ bool PropertyExists(XID window, const std::string& property_name) {
}
bool GetRawBytesOfProperty(XID window,
Atom property,
XAtom property,
scoped_refptr<base::RefCountedMemory>* out_data,
size_t* out_data_items,
Atom* out_type) {
XAtom* out_type) {
// Retrieve the data from our window.
unsigned long nitems = 0;
unsigned long nbytes = 0;
Atom prop_type = None;
XAtom prop_type = None;
int prop_format = 0;
unsigned char* property_data = NULL;
if (XGetWindowProperty(gfx::GetXDisplay(), window, property,
......@@ -732,7 +732,7 @@ bool GetRawBytesOfProperty(XID window,
}
bool GetIntProperty(XID window, const std::string& property_name, int* value) {
Atom type = None;
XAtom type = None;
int format = 0; // size in bits of each item in 'property'
unsigned long num_items = 0;
unsigned char* property = NULL;
......@@ -753,7 +753,7 @@ bool GetIntProperty(XID window, const std::string& property_name, int* value) {
}
bool GetXIDProperty(XID window, const std::string& property_name, XID* value) {
Atom type = None;
XAtom type = None;
int format = 0; // size in bits of each item in 'property'
unsigned long num_items = 0;
unsigned char* property = NULL;
......@@ -776,7 +776,7 @@ bool GetXIDProperty(XID window, const std::string& property_name, XID* value) {
bool GetIntArrayProperty(XID window,
const std::string& property_name,
std::vector<int>* value) {
Atom type = None;
XAtom type = None;
int format = 0; // size in bits of each item in 'property'
unsigned long num_items = 0;
unsigned char* properties = NULL;
......@@ -803,8 +803,8 @@ bool GetIntArrayProperty(XID window,
bool GetAtomArrayProperty(XID window,
const std::string& property_name,
std::vector<Atom>* value) {
Atom type = None;
std::vector<XAtom>* value) {
XAtom type = None;
int format = 0; // size in bits of each item in 'property'
unsigned long num_items = 0;
unsigned char* properties = NULL;
......@@ -820,7 +820,7 @@ bool GetAtomArrayProperty(XID window,
return false;
}
Atom* atom_properties = reinterpret_cast<Atom*>(properties);
XAtom* atom_properties = reinterpret_cast<XAtom*>(properties);
value->clear();
value->insert(value->begin(), atom_properties, atom_properties + num_items);
XFree(properties);
......@@ -829,7 +829,7 @@ bool GetAtomArrayProperty(XID window,
bool GetStringProperty(
XID window, const std::string& property_name, std::string* value) {
Atom type = None;
XAtom type = None;
int format = 0; // size in bits of each item in 'property'
unsigned long num_items = 0;
unsigned char* property = NULL;
......@@ -862,8 +862,8 @@ bool SetIntArrayProperty(XID window,
const std::string& type,
const std::vector<int>& value) {
DCHECK(!value.empty());
Atom name_atom = GetAtom(name.c_str());
Atom type_atom = GetAtom(type.c_str());
XAtom name_atom = GetAtom(name.c_str());
XAtom type_atom = GetAtom(type.c_str());
// XChangeProperty() expects values of type 32 to be longs.
scoped_ptr<long[]> data(new long[value.size()]);
......@@ -885,21 +885,21 @@ bool SetIntArrayProperty(XID window,
bool SetAtomProperty(XID window,
const std::string& name,
const std::string& type,
Atom value) {
std::vector<Atom> values(1, value);
XAtom value) {
std::vector<XAtom> values(1, value);
return SetAtomArrayProperty(window, name, type, values);
}
bool SetAtomArrayProperty(XID window,
const std::string& name,
const std::string& type,
const std::vector<Atom>& value) {
const std::vector<XAtom>& value) {
DCHECK(!value.empty());
Atom name_atom = GetAtom(name.c_str());
Atom type_atom = GetAtom(type.c_str());
XAtom name_atom = GetAtom(name.c_str());
XAtom type_atom = GetAtom(type.c_str());
// XChangeProperty() expects values of type 32 to be longs.
scoped_ptr<Atom[]> data(new Atom[value.size()]);
scoped_ptr<XAtom[]> data(new XAtom[value.size()]);
for (size_t i = 0; i < value.size(); ++i)
data[i] = value[i];
......@@ -916,8 +916,8 @@ bool SetAtomArrayProperty(XID window,
}
bool SetStringProperty(XID window,
Atom property,
Atom type,
XAtom property,
XAtom type,
const std::string& value) {
gfx::X11ErrorTracker err_tracker;
XChangeProperty(gfx::GetXDisplay(),
......@@ -931,7 +931,7 @@ bool SetStringProperty(XID window,
return !err_tracker.FoundNewError();
}
Atom GetAtom(const char* name) {
XAtom GetAtom(const char* name) {
// TODO(derat): Cache atoms to avoid round-trips to the server.
return XInternAtom(gfx::GetXDisplay(), name, false);
}
......@@ -1227,9 +1227,9 @@ bool IsX11WindowFullScreen(XID window) {
// If _NET_WM_STATE_FULLSCREEN is in _NET_SUPPORTED, use the presence or
// absence of _NET_WM_STATE_FULLSCREEN in _NET_WM_STATE to determine
// whether we're fullscreen.
Atom fullscreen_atom = GetAtom("_NET_WM_STATE_FULLSCREEN");
XAtom fullscreen_atom = GetAtom("_NET_WM_STATE_FULLSCREEN");
if (WmSupportsHint(fullscreen_atom)) {
std::vector<Atom> atom_properties;
std::vector<XAtom> atom_properties;
if (GetAtomArrayProperty(window,
"_NET_WM_STATE",
&atom_properties)) {
......@@ -1256,8 +1256,8 @@ bool IsX11WindowFullScreen(XID window) {
return window_rect.size() == gfx::Size(width, height);
}
bool WmSupportsHint(Atom atom) {
std::vector<Atom> supported_atoms;
bool WmSupportsHint(XAtom atom) {
std::vector<XAtom> supported_atoms;
if (!GetAtomArrayProperty(GetX11RootWindow(),
"_NET_SUPPORTED",
&supported_atoms)) {
......
......@@ -23,7 +23,6 @@
#include "ui/gfx/point.h"
#include "ui/gfx/x/x11_types.h"
typedef unsigned long Atom;
typedef unsigned long XSharedMemoryId; // ShmSeg in the X headers.
typedef unsigned long Cursor;
typedef struct _XcursorImage XcursorImage;
......@@ -136,16 +135,16 @@ UI_BASE_EXPORT bool PropertyExists(XID window,
// interpretation. |out_data| should be freed by XFree() after use.
UI_BASE_EXPORT bool GetRawBytesOfProperty(
XID window,
Atom property,
XAtom property,
scoped_refptr<base::RefCountedMemory>* out_data,
size_t* out_data_items,
Atom* out_type);
XAtom* out_type);
// Get the value of an int, int array, atom array or string property. On
// success, true is returned and the value is stored in |value|.
//
// TODO(erg): Once we remove the gtk port and are 100% aura, all of these
// should accept an Atom instead of a string.
// should accept an XAtom instead of a string.
UI_BASE_EXPORT bool GetIntProperty(XID window,
const std::string& property_name,
int* value);
......@@ -157,7 +156,7 @@ UI_BASE_EXPORT bool GetIntArrayProperty(XID window,
std::vector<int>* value);
UI_BASE_EXPORT bool GetAtomArrayProperty(XID window,
const std::string& property_name,
std::vector<Atom>* value);
std::vector<XAtom>* value);
UI_BASE_EXPORT bool GetStringProperty(XID window,
const std::string& property_name,
std::string* value);
......@@ -174,18 +173,18 @@ UI_BASE_EXPORT bool SetIntArrayProperty(XID window,
UI_BASE_EXPORT bool SetAtomProperty(XID window,
const std::string& name,
const std::string& type,
Atom value);
XAtom value);
UI_BASE_EXPORT bool SetAtomArrayProperty(XID window,
const std::string& name,
const std::string& type,
const std::vector<Atom>& value);
const std::vector<XAtom>& value);
UI_BASE_EXPORT bool SetStringProperty(XID window,
Atom property,
Atom type,
XAtom property,
XAtom type,
const std::string& value);
// Gets the X atom for default display corresponding to atom_name.
UI_BASE_EXPORT Atom GetAtom(const char* atom_name);
UI_BASE_EXPORT XAtom GetAtom(const char* atom_name);
// Sets the WM_CLASS attribute for a given X11 window.
UI_BASE_EXPORT void SetWindowClassHint(XDisplay* display,
......@@ -272,7 +271,7 @@ UI_BASE_EXPORT void SetDefaultX11ErrorHandlers();
UI_BASE_EXPORT bool IsX11WindowFullScreen(XID window);
// Returns true if the window manager supports the given hint.
UI_BASE_EXPORT bool WmSupportsHint(Atom atom);
UI_BASE_EXPORT bool WmSupportsHint(XAtom atom);
// Manages a piece of X11 allocated memory as a RefCountedMemory segment. This
// object takes ownership over the passed in memory and will free it with the
......
......@@ -19,7 +19,7 @@ X11AtomCache::X11AtomCache(XDisplay* xdisplay, const char** to_cache)
for (const char** i = to_cache; *i != NULL; i++)
cache_count++;
scoped_ptr<Atom[]> cached_atoms(new Atom[cache_count]);
scoped_ptr<XAtom[]> cached_atoms(new XAtom[cache_count]);
// Grab all the atoms we need now to minimize roundtrips to the X11 server.
XInternAtoms(xdisplay_,
......@@ -32,11 +32,11 @@ X11AtomCache::X11AtomCache(XDisplay* xdisplay, const char** to_cache)
X11AtomCache::~X11AtomCache() {}
Atom X11AtomCache::GetAtom(const char* name) const {
XAtom X11AtomCache::GetAtom(const char* name) const {
std::map<std::string, Atom>::const_iterator it = cached_atoms_.find(name);
if (uncached_atoms_allowed_ && it == cached_atoms_.end()) {
Atom atom = XInternAtom(xdisplay_, name, false);
XAtom atom = XInternAtom(xdisplay_, name, false);
cached_atoms_.insert(std::make_pair(name, atom));
return atom;
}
......
......@@ -10,9 +10,7 @@
#include "base/basictypes.h"
#include "ui/gfx/gfx_export.h"
typedef unsigned long Atom;
typedef struct _XDisplay XDisplay;
#include "ui/gfx/x/x11_types.h"
namespace ui {
......@@ -27,7 +25,7 @@ class GFX_EXPORT X11AtomCache {
~X11AtomCache();
// Returns the pre-interned Atom without having to go to the x server.
Atom GetAtom(const char*) const;
XAtom GetAtom(const char*) const;
// When an Atom isn't in the list of items we've cached, we should look it
// up, cache it locally, and then return the result.
......@@ -38,7 +36,7 @@ class GFX_EXPORT X11AtomCache {
bool uncached_atoms_allowed_;
mutable std::map<std::string, Atom> cached_atoms_;
mutable std::map<std::string, XAtom> cached_atoms_;
DISALLOW_COPY_AND_ASSIGN(X11AtomCache);
};
......
......@@ -8,6 +8,7 @@
#include "base/basictypes.h"
#include "ui/gfx/gfx_export.h"
typedef unsigned long XAtom;
typedef unsigned long XID;
typedef struct _XImage XImage;
typedef struct _XGC *GC;
......
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