| 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 // This file defines utility functions for X11 (Linux only). This code has been |     5 // This file defines utility functions for X11 (Linux only). This code has been | 
|     6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support |     6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support | 
|     7 // remains woefully incomplete. |     7 // remains woefully incomplete. | 
|     8  |     8  | 
|     9 #include "ui/base/x/x11_util.h" |     9 #include "ui/base/x/x11_util.h" | 
|    10  |    10  | 
| (...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   756                            &type, &format, &num_items, &property); |   756                            &type, &format, &num_items, &property); | 
|   757   if (result != Success) |   757   if (result != Success) | 
|   758     return false; |   758     return false; | 
|   759  |   759  | 
|   760   XFree(property); |   760   XFree(property); | 
|   761   return num_items > 0; |   761   return num_items > 0; | 
|   762 } |   762 } | 
|   763  |   763  | 
|   764 bool GetRawBytesOfProperty(XID window, |   764 bool GetRawBytesOfProperty(XID window, | 
|   765                            Atom property, |   765                            Atom property, | 
|   766                            unsigned char** out_data, |   766                            scoped_refptr<base::RefCountedMemory>* out_data, | 
|   767                            size_t* out_data_bytes, |   767                            size_t* out_data_bytes, | 
|   768                            size_t* out_data_items, |   768                            size_t* out_data_items, | 
|   769                            Atom* out_type) { |   769                            Atom* out_type) { | 
|   770   // Retrieve the data from our window. |   770   // Retrieve the data from our window. | 
|   771   unsigned long nitems = 0; |   771   unsigned long nitems = 0; | 
|   772   unsigned long nbytes = 0; |   772   unsigned long nbytes = 0; | 
|   773   Atom prop_type = None; |   773   Atom prop_type = None; | 
|   774   int prop_format = 0; |   774   int prop_format = 0; | 
|   775   unsigned char* property_data = NULL; |   775   unsigned char* property_data = NULL; | 
|   776   if (XGetWindowProperty(GetXDisplay(), window, property, |   776   if (XGetWindowProperty(GetXDisplay(), window, property, | 
|   777                          0, 0x1FFFFFFF /* MAXINT32 / 4 */, False, |   777                          0, 0x1FFFFFFF /* MAXINT32 / 4 */, False, | 
|   778                          AnyPropertyType, &prop_type, &prop_format, |   778                          AnyPropertyType, &prop_type, &prop_format, | 
|   779                          &nitems, &nbytes, &property_data) != Success) { |   779                          &nitems, &nbytes, &property_data) != Success) { | 
|   780     return false; |   780     return false; | 
|   781   } |   781   } | 
|   782  |   782  | 
|   783   if (prop_type == None) |   783   if (prop_type == None) | 
|   784     return false; |   784     return false; | 
|   785  |   785  | 
 |   786   size_t bytes = 0; | 
 |   787   // So even though we should theoretically have nbytes (and we can't | 
 |   788   // pass NULL there), we need to manually calculate the byte length here | 
 |   789   // because nbytes always returns zero. | 
 |   790   switch (prop_format) { | 
 |   791     case 8: | 
 |   792       bytes = nitems; | 
 |   793       break; | 
 |   794     case 16: | 
 |   795       bytes = sizeof(short) * nitems; | 
 |   796       break; | 
 |   797     case 32: | 
 |   798       bytes = sizeof(long) * nitems; | 
 |   799       break; | 
 |   800     default: | 
 |   801       NOTREACHED(); | 
 |   802       break; | 
 |   803   } | 
 |   804  | 
 |   805   if (out_data_bytes) | 
 |   806     *out_data_bytes = bytes; | 
 |   807  | 
|   786   if (out_data) |   808   if (out_data) | 
|   787     *out_data = property_data; |   809     *out_data = new XRefcountedMemory(property_data, bytes); | 
|   788   else |   810   else | 
|   789     XFree(property_data); |   811     XFree(property_data); | 
|   790  |   812  | 
|   791   if (out_data_bytes) { |  | 
|   792     // So even though we should theoretically have nbytes (and we can't |  | 
|   793     // pass NULL there), we need to manually calculate the byte length here |  | 
|   794     // because nbytes always returns zero. |  | 
|   795     switch (prop_format) { |  | 
|   796       case 8: |  | 
|   797         *out_data_bytes = nitems; |  | 
|   798         break; |  | 
|   799       case 16: |  | 
|   800         *out_data_bytes = sizeof(short) * nitems; |  | 
|   801         break; |  | 
|   802       case 32: |  | 
|   803         *out_data_bytes = sizeof(long) * nitems; |  | 
|   804         break; |  | 
|   805       default: |  | 
|   806         NOTREACHED(); |  | 
|   807         break; |  | 
|   808     } |  | 
|   809   } |  | 
|   810  |  | 
|   811   if (out_data_items) |   813   if (out_data_items) | 
|   812     *out_data_items = nitems; |   814     *out_data_items = nitems; | 
|   813  |   815  | 
|   814   if (out_type) |   816   if (out_type) | 
|   815     *out_type = prop_type; |   817     *out_type = prop_type; | 
|   816  |   818  | 
|   817   return true; |   819   return true; | 
|   818 } |   820 } | 
|   819  |   821  | 
|   820 bool GetIntProperty(XID window, const std::string& property_name, int* value) { |   822 bool GetIntProperty(XID window, const std::string& property_name, int* value) { | 
| (...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1494   key_event.y = 0; |  1496   key_event.y = 0; | 
|  1495   key_event.x_root = 0; |  1497   key_event.x_root = 0; | 
|  1496   key_event.y_root = 0; |  1498   key_event.y_root = 0; | 
|  1497   key_event.state = XKeyEventState(flags); |  1499   key_event.state = XKeyEventState(flags); | 
|  1498   key_event.keycode = XKeyEventKeyCode(key_code, flags, display); |  1500   key_event.keycode = XKeyEventKeyCode(key_code, flags, display); | 
|  1499   key_event.same_screen = 1; |  1501   key_event.same_screen = 1; | 
|  1500   event->type = key_event.type; |  1502   event->type = key_event.type; | 
|  1501   event->xkey = key_event; |  1503   event->xkey = key_event; | 
|  1502 } |  1504 } | 
|  1503  |  1505  | 
 |  1506 const unsigned char* XRefcountedMemory::front() const { | 
 |  1507   return x11_data_; | 
 |  1508 } | 
 |  1509  | 
 |  1510 size_t XRefcountedMemory::size() const { | 
 |  1511   return length_; | 
 |  1512 } | 
 |  1513  | 
 |  1514 XRefcountedMemory::~XRefcountedMemory() { | 
 |  1515   XFree(x11_data_); | 
 |  1516 } | 
 |  1517  | 
|  1504 XScopedString::~XScopedString() { |  1518 XScopedString::~XScopedString() { | 
|  1505   XFree(string_); |  1519   XFree(string_); | 
|  1506 } |  1520 } | 
|  1507  |  1521  | 
|  1508 XScopedImage::~XScopedImage() { |  1522 XScopedImage::~XScopedImage() { | 
|  1509   reset(NULL); |  1523   reset(NULL); | 
|  1510 } |  1524 } | 
|  1511  |  1525  | 
|  1512 void XScopedImage::reset(XImage* image) { |  1526 void XScopedImage::reset(XImage* image) { | 
|  1513   if (image_ == image) |  1527   if (image_ == image) | 
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1659       << "request_code " << static_cast<int>(error_event.request_code) << ", " |  1673       << "request_code " << static_cast<int>(error_event.request_code) << ", " | 
|  1660       << "minor_code " << static_cast<int>(error_event.minor_code) |  1674       << "minor_code " << static_cast<int>(error_event.minor_code) | 
|  1661       << " (" << request_str << ")"; |  1675       << " (" << request_str << ")"; | 
|  1662 } |  1676 } | 
|  1663  |  1677  | 
|  1664 // ---------------------------------------------------------------------------- |  1678 // ---------------------------------------------------------------------------- | 
|  1665 // End of x11_util_internal.h |  1679 // End of x11_util_internal.h | 
|  1666  |  1680  | 
|  1667  |  1681  | 
|  1668 }  // namespace ui |  1682 }  // namespace ui | 
| OLD | NEW |