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