| OLD | NEW | 
|    1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |    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 |    2 // Use of this source code is governed by a BSD-style license that can be | 
|    3 // found in the LICENSE file. |    3 // found in the LICENSE file. | 
|    4  |    4  | 
|    5 #ifndef UI_BASE_X_X11_UTIL_H_ |    5 #ifndef UI_BASE_X_X11_UTIL_H_ | 
|    6 #define UI_BASE_X_X11_UTIL_H_ |    6 #define UI_BASE_X_X11_UTIL_H_ | 
|    7  |    7  | 
|    8 // This file declares utility functions for X11 (Linux only). |    8 // This file declares utility functions for X11 (Linux only). | 
|    9 // |    9 // | 
|   10 // These functions do not require the Xlib headers to be included (which is why |   10 // These functions do not require the Xlib headers to be included (which is why | 
|   11 // we use a void* for Visual*). The Xlib headers are highly polluting so we try |   11 // we use a void* for Visual*). The Xlib headers are highly polluting so we try | 
|   12 // hard to limit their spread into the rest of the code. |   12 // hard to limit their spread into the rest of the code. | 
|   13  |   13  | 
|   14 #include <string> |   14 #include <string> | 
|   15 #include <vector> |   15 #include <vector> | 
|   16  |   16  | 
|   17 #include "base/basictypes.h" |   17 #include "base/basictypes.h" | 
|   18 #include "base/event_types.h" |   18 #include "base/event_types.h" | 
 |   19 #include "base/memory/ref_counted_memory.h" | 
|   19 #include "ui/base/events/event_constants.h" |   20 #include "ui/base/events/event_constants.h" | 
|   20 #include "ui/base/keycodes/keyboard_codes.h" |   21 #include "ui/base/keycodes/keyboard_codes.h" | 
|   21 #include "ui/base/ui_export.h" |   22 #include "ui/base/ui_export.h" | 
|   22 #include "ui/gfx/point.h" |   23 #include "ui/gfx/point.h" | 
|   23  |   24  | 
|   24 typedef unsigned long Atom; |   25 typedef unsigned long Atom; | 
|   25 typedef unsigned long XID; |   26 typedef unsigned long XID; | 
|   26 typedef unsigned long XSharedMemoryId;  // ShmSeg in the X headers. |   27 typedef unsigned long XSharedMemoryId;  // ShmSeg in the X headers. | 
|   27 typedef struct _XDisplay Display; |   28 typedef struct _XDisplay Display; | 
|   28 typedef unsigned long Cursor; |   29 typedef unsigned long Cursor; | 
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  159 UI_EXPORT bool GetWindowRect(XID window, gfx::Rect* rect); |  160 UI_EXPORT bool GetWindowRect(XID window, gfx::Rect* rect); | 
|  160  |  161  | 
|  161 // Returns true if |window| contains the point |screen_loc|. |  162 // Returns true if |window| contains the point |screen_loc|. | 
|  162 UI_EXPORT bool WindowContainsPoint(XID window, gfx::Point screen_loc); |  163 UI_EXPORT bool WindowContainsPoint(XID window, gfx::Point screen_loc); | 
|  163  |  164  | 
|  164 // Return true if |window| has any property with |property_name|. |  165 // Return true if |window| has any property with |property_name|. | 
|  165 UI_EXPORT bool PropertyExists(XID window, const std::string& property_name); |  166 UI_EXPORT bool PropertyExists(XID window, const std::string& property_name); | 
|  166  |  167  | 
|  167 // Returns the raw bytes from a property with minimal |  168 // Returns the raw bytes from a property with minimal | 
|  168 // interpretation. |out_data| should be freed by XFree() after use. |  169 // interpretation. |out_data| should be freed by XFree() after use. | 
|  169 UI_EXPORT bool GetRawBytesOfProperty(XID window, |  170 UI_EXPORT bool GetRawBytesOfProperty( | 
|  170                                      Atom property, |  171     XID window, | 
|  171                                      unsigned char** out_data, |  172     Atom property, | 
|  172                                      size_t* out_data_bytes, |  173     scoped_refptr<base::RefCountedMemory>* out_data, | 
|  173                                      size_t* out_data_items, |  174     size_t* out_data_bytes, | 
|  174                                      Atom* out_type); |  175     size_t* out_data_items, | 
 |  176     Atom* out_type); | 
|  175  |  177  | 
|  176 // Get the value of an int, int array, atom array or string property.  On |  178 // Get the value of an int, int array, atom array or string property.  On | 
|  177 // success, true is returned and the value is stored in |value|. |  179 // success, true is returned and the value is stored in |value|. | 
|  178 // |  180 // | 
|  179 // TODO(erg): Once we remove the gtk port and are 100% aura, all of these |  181 // TODO(erg): Once we remove the gtk port and are 100% aura, all of these | 
|  180 // should accept an Atom instead of a string. |  182 // should accept an Atom instead of a string. | 
|  181 UI_EXPORT bool GetIntProperty(XID window, const std::string& property_name, |  183 UI_EXPORT bool GetIntProperty(XID window, const std::string& property_name, | 
|  182                               int* value); |  184                               int* value); | 
|  183 UI_EXPORT bool GetXIDProperty(XID window, const std::string& property_name, |  185 UI_EXPORT bool GetXIDProperty(XID window, const std::string& property_name, | 
|  184                               XID* value); |  186                               XID* value); | 
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  326 // received. |  328 // received. | 
|  327 UI_EXPORT void UpdateButtonMap(); |  329 UI_EXPORT void UpdateButtonMap(); | 
|  328  |  330  | 
|  329 // Initializes a XEvent that holds XKeyEvent for testing. Note that ui::EF_ |  331 // Initializes a XEvent that holds XKeyEvent for testing. Note that ui::EF_ | 
|  330 // flags should be passed as |flags|, not the native ones in <X11/X.h>. |  332 // flags should be passed as |flags|, not the native ones in <X11/X.h>. | 
|  331 UI_EXPORT void InitXKeyEventForTesting(EventType type, |  333 UI_EXPORT void InitXKeyEventForTesting(EventType type, | 
|  332                                        KeyboardCode key_code, |  334                                        KeyboardCode key_code, | 
|  333                                        int flags, |  335                                        int flags, | 
|  334                                        XEvent* event); |  336                                        XEvent* event); | 
|  335  |  337  | 
 |  338 // Manages a piece of X11 allocated memory as a RefCountedMemory segment. This | 
 |  339 // object takes ownership over the passed in memory and will free it with the | 
 |  340 // X11 allocator when done. | 
 |  341 class UI_EXPORT XRefcountedMemory : public base::RefCountedMemory { | 
 |  342  public: | 
 |  343   XRefcountedMemory(unsigned char* x11_data, size_t length) | 
 |  344       : x11_data_(length ? x11_data : NULL), | 
 |  345         length_(length) { | 
 |  346   } | 
 |  347  | 
 |  348   // Overridden from RefCountedMemory: | 
 |  349   virtual const unsigned char* front() const OVERRIDE; | 
 |  350   virtual size_t size() const OVERRIDE; | 
 |  351  | 
 |  352  private: | 
 |  353   virtual ~XRefcountedMemory(); | 
 |  354  | 
 |  355   unsigned char* x11_data_; | 
 |  356   size_t length_; | 
 |  357  | 
 |  358   DISALLOW_COPY_AND_ASSIGN(XRefcountedMemory); | 
 |  359 }; | 
 |  360  | 
|  336 // Keeps track of a string returned by an X function (e.g. XGetAtomName) and |  361 // Keeps track of a string returned by an X function (e.g. XGetAtomName) and | 
|  337 // makes sure it's XFree'd. |  362 // makes sure it's XFree'd. | 
|  338 class UI_EXPORT XScopedString { |  363 class UI_EXPORT XScopedString { | 
|  339  public: |  364  public: | 
|  340   explicit XScopedString(char* str) : string_(str) {} |  365   explicit XScopedString(char* str) : string_(str) {} | 
|  341   ~XScopedString(); |  366   ~XScopedString(); | 
|  342  |  367  | 
|  343   const char* string() const { return string_; } |  368   const char* string() const { return string_; } | 
|  344  |  369  | 
|  345  private: |  370  private: | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  385  private: |  410  private: | 
|  386   ::Cursor cursor_; |  411   ::Cursor cursor_; | 
|  387   Display* display_; |  412   Display* display_; | 
|  388  |  413  | 
|  389   DISALLOW_COPY_AND_ASSIGN(XScopedCursor); |  414   DISALLOW_COPY_AND_ASSIGN(XScopedCursor); | 
|  390 }; |  415 }; | 
|  391  |  416  | 
|  392 }  // namespace ui |  417 }  // namespace ui | 
|  393  |  418  | 
|  394 #endif  // UI_BASE_X_X11_UTIL_H_ |  419 #endif  // UI_BASE_X_X11_UTIL_H_ | 
| OLD | NEW |