| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #include "ui/base/x/selection_requestor.h" | 5 #include "ui/base/x/selection_requestor.h" |
| 6 | 6 |
| 7 #include "base/message_pump_aurax11.h" | 7 #include "base/message_pump_aurax11.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "ui/base/x/selection_utils.h" |
| 9 | 10 |
| 10 namespace ui { | 11 namespace ui { |
| 11 | 12 |
| 12 namespace { | 13 namespace { |
| 13 | 14 |
| 14 const char kChromeSelection[] = "CHROME_SELECTION"; | 15 const char kChromeSelection[] = "CHROME_SELECTION"; |
| 15 | 16 |
| 16 const char* kAtomsToCache[] = { | 17 const char* kAtomsToCache[] = { |
| 17 kChromeSelection, | 18 kChromeSelection, |
| 18 NULL | 19 NULL |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 110 |
| 110 if (out_data_items) | 111 if (out_data_items) |
| 111 *out_data_items = nitems; | 112 *out_data_items = nitems; |
| 112 | 113 |
| 113 if (out_type) | 114 if (out_type) |
| 114 *out_type = prop_type; | 115 *out_type = prop_type; |
| 115 | 116 |
| 116 return true; | 117 return true; |
| 117 } | 118 } |
| 118 | 119 |
| 120 scoped_ptr<SelectionData> SelectionRequestor::RequestAndWaitForTypes( |
| 121 const std::vector< ::Atom>& types) { |
| 122 for (std::vector< ::Atom>::const_iterator it = types.begin(); |
| 123 it != types.end(); ++it) { |
| 124 unsigned char* data = NULL; |
| 125 size_t data_bytes = 0; |
| 126 ::Atom type = None; |
| 127 if (PerformBlockingConvertSelection(*it, |
| 128 &data, |
| 129 &data_bytes, |
| 130 NULL, |
| 131 &type) && |
| 132 type == *it) { |
| 133 scoped_ptr<SelectionData> data_out(new SelectionData(x_display_)); |
| 134 data_out->Set(type, (char*)data, data_bytes, true); |
| 135 return data_out.Pass(); |
| 136 } |
| 137 } |
| 138 |
| 139 return scoped_ptr<SelectionData>(); |
| 140 } |
| 141 |
| 119 void SelectionRequestor::OnSelectionNotify(const XSelectionEvent& event) { | 142 void SelectionRequestor::OnSelectionNotify(const XSelectionEvent& event) { |
| 120 if (!in_nested_loop_) { | 143 if (!in_nested_loop_) { |
| 121 // This shouldn't happen; we're not waiting on the X server for data, but | 144 // This shouldn't happen; we're not waiting on the X server for data, but |
| 122 // any client can send any message... | 145 // any client can send any message... |
| 123 return; | 146 return; |
| 124 } | 147 } |
| 125 | 148 |
| 126 if (selection_name_ == event.selection && | 149 if (selection_name_ == event.selection && |
| 127 current_target_ == event.target) { | 150 current_target_ == event.target) { |
| 128 returned_property_ = event.property; | 151 returned_property_ = event.property; |
| 129 } else { | 152 } else { |
| 130 // I am assuming that if some other client sent us a message after we've | 153 // I am assuming that if some other client sent us a message after we've |
| 131 // asked for data, but it's malformed, we should just treat as if they sent | 154 // asked for data, but it's malformed, we should just treat as if they sent |
| 132 // us an error message. | 155 // us an error message. |
| 133 returned_property_ = None; | 156 returned_property_ = None; |
| 134 } | 157 } |
| 135 | 158 |
| 136 quit_closure_.Run(); | 159 quit_closure_.Run(); |
| 137 } | 160 } |
| 138 | 161 |
| 139 } // namespace ui | 162 } // namespace ui |
| OLD | NEW |