| 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 #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" | |
| 19 #include "base/message_loop/message_pump_x11.h" | |
| 20 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
| 22 #include "third_party/skia/include/core/SkBitmap.h" | 20 #include "third_party/skia/include/core/SkBitmap.h" |
| 23 #include "ui/base/clipboard/custom_data_helper.h" | 21 #include "ui/base/clipboard/custom_data_helper.h" |
| 24 #include "ui/base/x/selection_owner.h" | 22 #include "ui/base/x/selection_owner.h" |
| 25 #include "ui/base/x/selection_requestor.h" | 23 #include "ui/base/x/selection_requestor.h" |
| 26 #include "ui/base/x/selection_utils.h" | 24 #include "ui/base/x/selection_utils.h" |
| 27 #include "ui/base/x/x11_util.h" | 25 #include "ui/base/x/x11_util.h" |
| 28 #include "ui/events/platform/platform_event_dispatcher.h" | 26 #include "ui/events/platform/platform_event_dispatcher.h" |
| 29 #include "ui/events/platform/x11/x11_event_source.h" | 27 #include "ui/events/platform/platform_event_observer.h" |
| 28 #include "ui/events/platform/platform_event_source.h" |
| 30 #include "ui/gfx/codec/png_codec.h" | 29 #include "ui/gfx/codec/png_codec.h" |
| 31 #include "ui/gfx/size.h" | 30 #include "ui/gfx/size.h" |
| 32 #include "ui/gfx/x/x11_atom_cache.h" | 31 #include "ui/gfx/x/x11_atom_cache.h" |
| 33 | 32 |
| 34 namespace ui { | 33 namespace ui { |
| 35 | 34 |
| 36 namespace { | 35 namespace { |
| 37 | 36 |
| 38 const char kClipboard[] = "CLIPBOARD"; | 37 const char kClipboard[] = "CLIPBOARD"; |
| 39 const char kMimeTypeFilename[] = "chromium/filename"; | 38 const char kMimeTypeFilename[] = "chromium/filename"; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 50 kString, | 49 kString, |
| 51 kTargets, | 50 kTargets, |
| 52 kText, | 51 kText, |
| 53 kUtf8String, | 52 kUtf8String, |
| 54 NULL | 53 NULL |
| 55 }; | 54 }; |
| 56 | 55 |
| 57 /////////////////////////////////////////////////////////////////////////////// | 56 /////////////////////////////////////////////////////////////////////////////// |
| 58 | 57 |
| 59 // Uses the XFixes API to provide sequence numbers for GetSequenceNumber(). | 58 // Uses the XFixes API to provide sequence numbers for GetSequenceNumber(). |
| 60 class SelectionChangeObserver : public base::MessagePumpObserver { | 59 class SelectionChangeObserver : public ui::PlatformEventObserver { |
| 61 public: | 60 public: |
| 62 static SelectionChangeObserver* GetInstance(); | 61 static SelectionChangeObserver* GetInstance(); |
| 63 | 62 |
| 64 uint64 clipboard_sequence_number() const { | 63 uint64 clipboard_sequence_number() const { |
| 65 return clipboard_sequence_number_; | 64 return clipboard_sequence_number_; |
| 66 } | 65 } |
| 67 uint64 primary_sequence_number() const { return primary_sequence_number_; } | 66 uint64 primary_sequence_number() const { return primary_sequence_number_; } |
| 68 | 67 |
| 69 private: | 68 private: |
| 70 friend struct DefaultSingletonTraits<SelectionChangeObserver>; | 69 friend struct DefaultSingletonTraits<SelectionChangeObserver>; |
| 71 | 70 |
| 72 SelectionChangeObserver(); | 71 SelectionChangeObserver(); |
| 73 virtual ~SelectionChangeObserver(); | 72 virtual ~SelectionChangeObserver(); |
| 74 | 73 |
| 75 // Overridden from base::MessagePumpObserver: | 74 // ui::PlatformEventObserver: |
| 76 virtual void WillProcessEvent(const base::NativeEvent& event) OVERRIDE; | 75 virtual void WillProcessEvent(const ui::PlatformEvent& event) OVERRIDE; |
| 77 virtual void DidProcessEvent( | 76 virtual void DidProcessEvent(const ui::PlatformEvent& event) OVERRIDE {} |
| 78 const base::NativeEvent& event) OVERRIDE {} | |
| 79 | 77 |
| 80 int event_base_; | 78 int event_base_; |
| 81 Atom clipboard_atom_; | 79 Atom clipboard_atom_; |
| 82 uint64 clipboard_sequence_number_; | 80 uint64 clipboard_sequence_number_; |
| 83 uint64 primary_sequence_number_; | 81 uint64 primary_sequence_number_; |
| 84 | 82 |
| 85 DISALLOW_COPY_AND_ASSIGN(SelectionChangeObserver); | 83 DISALLOW_COPY_AND_ASSIGN(SelectionChangeObserver); |
| 86 }; | 84 }; |
| 87 | 85 |
| 88 SelectionChangeObserver::SelectionChangeObserver() | 86 SelectionChangeObserver::SelectionChangeObserver() |
| (...skipping 11 matching lines...) Expand all Loading... |
| 100 XFixesSelectionClientCloseNotifyMask); | 98 XFixesSelectionClientCloseNotifyMask); |
| 101 // This seems to be semi-optional. For some reason, registering for any | 99 // This seems to be semi-optional. For some reason, registering for any |
| 102 // selection notify events seems to subscribe us to events for both the | 100 // selection notify events seems to subscribe us to events for both the |
| 103 // primary and the clipboard buffers. Register anyway just to be safe. | 101 // primary and the clipboard buffers. Register anyway just to be safe. |
| 104 XFixesSelectSelectionInput(gfx::GetXDisplay(), GetX11RootWindow(), | 102 XFixesSelectSelectionInput(gfx::GetXDisplay(), GetX11RootWindow(), |
| 105 XA_PRIMARY, | 103 XA_PRIMARY, |
| 106 XFixesSetSelectionOwnerNotifyMask | | 104 XFixesSetSelectionOwnerNotifyMask | |
| 107 XFixesSelectionWindowDestroyNotifyMask | | 105 XFixesSelectionWindowDestroyNotifyMask | |
| 108 XFixesSelectionClientCloseNotifyMask); | 106 XFixesSelectionClientCloseNotifyMask); |
| 109 | 107 |
| 110 base::MessagePumpX11::Current()->AddObserver(this); | 108 ui::PlatformEventSource::GetInstance()->AddPlatformEventObserver(this); |
| 111 } | 109 } |
| 112 } | 110 } |
| 113 | 111 |
| 114 SelectionChangeObserver::~SelectionChangeObserver() { | 112 SelectionChangeObserver::~SelectionChangeObserver() { |
| 115 // We are a singleton; we will outlive our message pump. | 113 // We are a singleton; we will outlive the event source. |
| 116 } | 114 } |
| 117 | 115 |
| 118 SelectionChangeObserver* SelectionChangeObserver::GetInstance() { | 116 SelectionChangeObserver* SelectionChangeObserver::GetInstance() { |
| 119 return Singleton<SelectionChangeObserver>::get(); | 117 return Singleton<SelectionChangeObserver>::get(); |
| 120 } | 118 } |
| 121 | 119 |
| 122 void SelectionChangeObserver::WillProcessEvent(const base::NativeEvent& event) { | 120 void SelectionChangeObserver::WillProcessEvent(const ui::PlatformEvent& event) { |
| 123 if (event->type == event_base_ + XFixesSelectionNotify) { | 121 if (event->type == event_base_ + XFixesSelectionNotify) { |
| 124 XFixesSelectionNotifyEvent* ev = | 122 XFixesSelectionNotifyEvent* ev = |
| 125 reinterpret_cast<XFixesSelectionNotifyEvent*>(event); | 123 reinterpret_cast<XFixesSelectionNotifyEvent*>(event); |
| 126 if (ev->selection == clipboard_atom_) { | 124 if (ev->selection == clipboard_atom_) { |
| 127 clipboard_sequence_number_++; | 125 clipboard_sequence_number_++; |
| 128 } else if (ev->selection == XA_PRIMARY) { | 126 } else if (ev->selection == XA_PRIMARY) { |
| 129 primary_sequence_number_++; | 127 primary_sequence_number_++; |
| 130 } else { | 128 } else { |
| 131 DLOG(ERROR) << "Unexpected selection atom: " << ev->selection; | 129 DLOG(ERROR) << "Unexpected selection atom: " << ev->selection; |
| 132 } | 130 } |
| (...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 return type; | 864 return type; |
| 867 } | 865 } |
| 868 | 866 |
| 869 // static | 867 // static |
| 870 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { | 868 const Clipboard::FormatType& Clipboard::GetPepperCustomDataFormatType() { |
| 871 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData)); | 869 CR_DEFINE_STATIC_LOCAL(FormatType, type, (kMimeTypePepperCustomData)); |
| 872 return type; | 870 return type; |
| 873 } | 871 } |
| 874 | 872 |
| 875 } // namespace ui | 873 } // namespace ui |
| OLD | NEW |