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 <algorithm> | 7 #include <algorithm> |
8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
9 | 9 |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "ui/base/x/selection_utils.h" | 12 #include "ui/base/x/selection_utils.h" |
13 #include "ui/base/x/x11_util.h" | 13 #include "ui/base/x/x11_util.h" |
14 #include "ui/events/platform/platform_event_dispatcher.h" | 14 #include "ui/events/platform/platform_event_dispatcher.h" |
15 #include "ui/events/platform/platform_event_source.h" | 15 #include "ui/events/platform/platform_event_source.h" |
16 #include "ui/gfx/x/x11_types.h" | 16 #include "ui/gfx/x/x11_types.h" |
17 | 17 |
18 namespace ui { | 18 namespace ui { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 const char kChromeSelection[] = "CHROME_SELECTION"; | 22 const char kChromeSelection[] = "CHROME_SELECTION"; |
23 const char kIncr[] = "INCR"; | 23 const char kIncr[] = "INCR"; |
24 | 24 |
25 const char* kAtomsToCache[] = { | |
26 kChromeSelection, | |
27 kIncr, | |
28 NULL | |
29 }; | |
30 | |
31 // The period of |abort_timer_|. Arbitrary but must be <= than | 25 // The period of |abort_timer_|. Arbitrary but must be <= than |
32 // kRequestTimeoutMs. | 26 // kRequestTimeoutMs. |
33 const int kTimerPeriodMs = 100; | 27 const int kTimerPeriodMs = 100; |
34 | 28 |
35 // The amount of time to wait for a request to complete before aborting it. | 29 // The amount of time to wait for a request to complete before aborting it. |
36 const int kRequestTimeoutMs = 10000; | 30 const int kRequestTimeoutMs = 10000; |
37 | 31 |
38 static_assert(kTimerPeriodMs <= kRequestTimeoutMs, | 32 static_assert(kTimerPeriodMs <= kRequestTimeoutMs, |
39 "timer period must be <= request timeout"); | 33 "timer period must be <= request timeout"); |
40 | 34 |
(...skipping 19 matching lines...) Expand all Loading... |
60 | 54 |
61 } // namespace | 55 } // namespace |
62 | 56 |
63 SelectionRequestor::SelectionRequestor(XDisplay* x_display, | 57 SelectionRequestor::SelectionRequestor(XDisplay* x_display, |
64 XID x_window, | 58 XID x_window, |
65 PlatformEventDispatcher* dispatcher) | 59 PlatformEventDispatcher* dispatcher) |
66 : x_display_(x_display), | 60 : x_display_(x_display), |
67 x_window_(x_window), | 61 x_window_(x_window), |
68 x_property_(None), | 62 x_property_(None), |
69 dispatcher_(dispatcher), | 63 dispatcher_(dispatcher), |
70 current_request_index_(0u), | 64 current_request_index_(0u) { |
71 atom_cache_(x_display_, kAtomsToCache) { | 65 x_property_ = GetAtom(kChromeSelection); |
72 x_property_ = atom_cache_.GetAtom(kChromeSelection); | |
73 } | 66 } |
74 | 67 |
75 SelectionRequestor::~SelectionRequestor() {} | 68 SelectionRequestor::~SelectionRequestor() {} |
76 | 69 |
77 bool SelectionRequestor::PerformBlockingConvertSelection( | 70 bool SelectionRequestor::PerformBlockingConvertSelection( |
78 XAtom selection, | 71 XAtom selection, |
79 XAtom target, | 72 XAtom target, |
80 scoped_refptr<base::RefCountedMemory>* out_data, | 73 scoped_refptr<base::RefCountedMemory>* out_data, |
81 size_t* out_data_items, | 74 size_t* out_data_items, |
82 XAtom* out_type) { | 75 XAtom* out_type) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 &request->out_data_items, | 155 &request->out_data_items, |
163 &request->out_type); | 156 &request->out_type); |
164 if (success) { | 157 if (success) { |
165 request->out_data.clear(); | 158 request->out_data.clear(); |
166 request->out_data.push_back(out_data); | 159 request->out_data.push_back(out_data); |
167 } | 160 } |
168 } | 161 } |
169 if (event_property != None) | 162 if (event_property != None) |
170 XDeleteProperty(x_display_, x_window_, event_property); | 163 XDeleteProperty(x_display_, x_window_, event_property); |
171 | 164 |
172 if (request->out_type == atom_cache_.GetAtom(kIncr)) { | 165 if (request->out_type == GetAtom(kIncr)) { |
173 request->data_sent_incrementally = true; | 166 request->data_sent_incrementally = true; |
174 request->out_data.clear(); | 167 request->out_data.clear(); |
175 request->out_data_items = 0u; | 168 request->out_data_items = 0u; |
176 request->out_type = None; | 169 request->out_type = None; |
177 request->timeout = base::TimeTicks::Now() + | 170 request->timeout = base::TimeTicks::Now() + |
178 base::TimeDelta::FromMilliseconds(kRequestTimeoutMs); | 171 base::TimeDelta::FromMilliseconds(kRequestTimeoutMs); |
179 } else { | 172 } else { |
180 CompleteRequest(current_request_index_, success); | 173 CompleteRequest(current_request_index_, success); |
181 } | 174 } |
182 } | 175 } |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 out_type(None), | 305 out_type(None), |
313 success(false), | 306 success(false), |
314 timeout(timeout), | 307 timeout(timeout), |
315 completed(false) { | 308 completed(false) { |
316 } | 309 } |
317 | 310 |
318 SelectionRequestor::Request::~Request() { | 311 SelectionRequestor::Request::~Request() { |
319 } | 312 } |
320 | 313 |
321 } // namespace ui | 314 } // namespace ui |
OLD | NEW |