Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: ui/base/clipboard/clipboard_aurax11.cc

Issue 219743002: x11: Move X event handling out of the message-pump. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tot-merge-r261267 Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/aura/window_tree_host_x11_unittest.cc ('k') | ui/base/clipboard/clipboard_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "ui/base/clipboard/clipboard.h" 5 #include "ui/base/clipboard/clipboard.h"
6 6
7 #include <X11/extensions/Xfixes.h> 7 #include <X11/extensions/Xfixes.h>
8 #include <X11/Xatom.h> 8 #include <X11/Xatom.h>
9 #include <list> 9 #include <list>
10 #include <set> 10 #include <set>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/files/file_path.h" 13 #include "base/files/file_path.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/memory/ref_counted_memory.h" 15 #include "base/memory/ref_counted_memory.h"
16 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 #include "base/memory/singleton.h" 17 #include "base/memory/singleton.h"
18 #include "base/message_loop/message_pump_observer.h" 18 #include "base/message_loop/message_pump_observer.h"
19 #include "base/message_loop/message_pump_x11.h" 19 #include "base/message_loop/message_pump_x11.h"
20 #include "base/stl_util.h" 20 #include "base/stl_util.h"
21 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
22 #include "third_party/skia/include/core/SkBitmap.h" 22 #include "third_party/skia/include/core/SkBitmap.h"
23 #include "ui/base/clipboard/custom_data_helper.h" 23 #include "ui/base/clipboard/custom_data_helper.h"
24 #include "ui/base/x/selection_owner.h" 24 #include "ui/base/x/selection_owner.h"
25 #include "ui/base/x/selection_requestor.h" 25 #include "ui/base/x/selection_requestor.h"
26 #include "ui/base/x/selection_utils.h" 26 #include "ui/base/x/selection_utils.h"
27 #include "ui/base/x/x11_util.h" 27 #include "ui/base/x/x11_util.h"
28 #include "ui/events/platform/platform_event_dispatcher.h"
29 #include "ui/events/platform/x11/x11_event_source.h"
28 #include "ui/gfx/codec/png_codec.h" 30 #include "ui/gfx/codec/png_codec.h"
29 #include "ui/gfx/size.h" 31 #include "ui/gfx/size.h"
30 #include "ui/gfx/x/x11_atom_cache.h" 32 #include "ui/gfx/x/x11_atom_cache.h"
31 33
32 namespace ui { 34 namespace ui {
33 35
34 namespace { 36 namespace {
35 37
36 const char kClipboard[] = "CLIPBOARD"; 38 const char kClipboard[] = "CLIPBOARD";
37 const char kMimeTypeFilename[] = "chromium/filename"; 39 const char kMimeTypeFilename[] = "chromium/filename";
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 219
218 bool Clipboard::FormatType::Equals(const FormatType& other) const { 220 bool Clipboard::FormatType::Equals(const FormatType& other) const {
219 return data_ == other.data_; 221 return data_ == other.data_;
220 } 222 }
221 223
222 /////////////////////////////////////////////////////////////////////////////// 224 ///////////////////////////////////////////////////////////////////////////////
223 // Clipboard::AuraX11Details 225 // Clipboard::AuraX11Details
224 226
225 // Private implementation of our X11 integration. Keeps X11 headers out of the 227 // Private implementation of our X11 integration. Keeps X11 headers out of the
226 // majority of chrome, which break badly. 228 // majority of chrome, which break badly.
227 class Clipboard::AuraX11Details : public base::MessagePumpDispatcher { 229 class Clipboard::AuraX11Details : public PlatformEventDispatcher {
228 public: 230 public:
229 AuraX11Details(); 231 AuraX11Details();
230 virtual ~AuraX11Details(); 232 virtual ~AuraX11Details();
231 233
232 X11AtomCache* atom_cache() { return &atom_cache_; } 234 X11AtomCache* atom_cache() { return &atom_cache_; }
233 235
234 // Returns the X11 type that we pass to various XSelection functions for the 236 // Returns the X11 type that we pass to various XSelection functions for the
235 // given type. 237 // given type.
236 ::Atom LookupSelectionForClipboardType(ClipboardType type) const; 238 ::Atom LookupSelectionForClipboardType(ClipboardType type) const;
237 239
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 // Returns a list of all text atoms that we handle. 277 // Returns a list of all text atoms that we handle.
276 std::vector< ::Atom> GetTextAtoms() const; 278 std::vector< ::Atom> GetTextAtoms() const;
277 279
278 // Returns a vector with a |format| converted to an X11 atom. 280 // Returns a vector with a |format| converted to an X11 atom.
279 std::vector< ::Atom> GetAtomsForFormat(const Clipboard::FormatType& format); 281 std::vector< ::Atom> GetAtomsForFormat(const Clipboard::FormatType& format);
280 282
281 // Clears a certain clipboard type, whether we own it or not. 283 // Clears a certain clipboard type, whether we own it or not.
282 void Clear(ClipboardType type); 284 void Clear(ClipboardType type);
283 285
284 private: 286 private:
285 // Overridden from base::MessagePumpDispatcher: 287 // PlatformEventDispatcher:
286 virtual uint32_t Dispatch(const base::NativeEvent& event) OVERRIDE; 288 virtual bool CanDispatchEvent(const PlatformEvent& event) OVERRIDE;
289 virtual uint32_t DispatchEvent(const PlatformEvent& event) OVERRIDE;
287 290
288 // Our X11 state. 291 // Our X11 state.
289 Display* x_display_; 292 Display* x_display_;
290 ::Window x_root_window_; 293 ::Window x_root_window_;
291 294
292 // Input-only window used as a selection owner. 295 // Input-only window used as a selection owner.
293 ::Window x_window_; 296 ::Window x_window_;
294 297
295 X11AtomCache atom_cache_; 298 X11AtomCache atom_cache_;
296 299
(...skipping 28 matching lines...) Expand all
325 atom_cache_.GetAtom(kClipboard)), 328 atom_cache_.GetAtom(kClipboard)),
326 primary_requestor_(x_display_, x_window_, XA_PRIMARY), 329 primary_requestor_(x_display_, x_window_, XA_PRIMARY),
327 clipboard_owner_(x_display_, x_window_, atom_cache_.GetAtom(kClipboard)), 330 clipboard_owner_(x_display_, x_window_, atom_cache_.GetAtom(kClipboard)),
328 primary_owner_(x_display_, x_window_, XA_PRIMARY) { 331 primary_owner_(x_display_, x_window_, XA_PRIMARY) {
329 // We don't know all possible MIME types at compile time. 332 // We don't know all possible MIME types at compile time.
330 atom_cache_.allow_uncached_atoms(); 333 atom_cache_.allow_uncached_atoms();
331 334
332 XStoreName(x_display_, x_window_, "Chromium clipboard"); 335 XStoreName(x_display_, x_window_, "Chromium clipboard");
333 XSelectInput(x_display_, x_window_, PropertyChangeMask); 336 XSelectInput(x_display_, x_window_, PropertyChangeMask);
334 337
335 base::MessagePumpX11::Current()->AddDispatcherForWindow(this, x_window_); 338 if (PlatformEventSource::GetInstance())
339 PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this);
336 } 340 }
337 341
338 Clipboard::AuraX11Details::~AuraX11Details() { 342 Clipboard::AuraX11Details::~AuraX11Details() {
339 base::MessagePumpX11::Current()->RemoveDispatcherForWindow(x_window_); 343 if (PlatformEventSource::GetInstance())
344 PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this);
340 345
341 XDestroyWindow(x_display_, x_window_); 346 XDestroyWindow(x_display_, x_window_);
342 } 347 }
343 348
344 ::Atom Clipboard::AuraX11Details::LookupSelectionForClipboardType( 349 ::Atom Clipboard::AuraX11Details::LookupSelectionForClipboardType(
345 ClipboardType type) const { 350 ClipboardType type) const {
346 if (type == CLIPBOARD_TYPE_COPY_PASTE) 351 if (type == CLIPBOARD_TYPE_COPY_PASTE)
347 return atom_cache_.GetAtom(kClipboard); 352 return atom_cache_.GetAtom(kClipboard);
348 353
349 return XA_PRIMARY; 354 return XA_PRIMARY;
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 return atoms; 483 return atoms;
479 } 484 }
480 485
481 void Clipboard::AuraX11Details::Clear(ClipboardType type) { 486 void Clipboard::AuraX11Details::Clear(ClipboardType type) {
482 if (type == CLIPBOARD_TYPE_COPY_PASTE) 487 if (type == CLIPBOARD_TYPE_COPY_PASTE)
483 clipboard_owner_.ClearSelectionOwner(); 488 clipboard_owner_.ClearSelectionOwner();
484 else 489 else
485 primary_owner_.ClearSelectionOwner(); 490 primary_owner_.ClearSelectionOwner();
486 } 491 }
487 492
488 uint32_t Clipboard::AuraX11Details::Dispatch(const base::NativeEvent& event) { 493 bool Clipboard::AuraX11Details::CanDispatchEvent(const PlatformEvent& event) {
489 XEvent* xev = event; 494 return event->xany.window == x_window_;
495 }
490 496
497 uint32_t Clipboard::AuraX11Details::DispatchEvent(const PlatformEvent& xev) {
491 switch (xev->type) { 498 switch (xev->type) {
492 case SelectionRequest: { 499 case SelectionRequest: {
493 if (xev->xselectionrequest.selection == XA_PRIMARY) 500 if (xev->xselectionrequest.selection == XA_PRIMARY)
494 primary_owner_.OnSelectionRequest(xev->xselectionrequest); 501 primary_owner_.OnSelectionRequest(xev->xselectionrequest);
495 else 502 else
496 clipboard_owner_.OnSelectionRequest(xev->xselectionrequest); 503 clipboard_owner_.OnSelectionRequest(xev->xselectionrequest);
497 break; 504 break;
498 } 505 }
499 case SelectionNotify: { 506 case SelectionNotify: {
500 if (xev->xselection.selection == XA_PRIMARY) 507 if (xev->xselection.selection == XA_PRIMARY)
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 return type; 869 return type;
863 } 870 }
864 871
865 // static 872 // static
866 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { 873 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() {
867 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData)); 874 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData));
868 return type; 875 return type;
869 } 876 }
870 877
871 } // namespace ui 878 } // namespace ui
OLDNEW
« no previous file with comments | « ui/aura/window_tree_host_x11_unittest.cc ('k') | ui/base/clipboard/clipboard_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698