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_owner.h" | 5 #include "ui/base/x/selection_owner.h" |
6 | 6 |
7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
8 #include <X11/Xatom.h> | 8 #include <X11/Xatom.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 21 matching lines...) Expand all Loading... | |
32 x_window_(x_window), | 32 x_window_(x_window), |
33 selection_name_(selection_name), | 33 selection_name_(selection_name), |
34 atom_cache_(x_display_, kAtomsToCache) { | 34 atom_cache_(x_display_, kAtomsToCache) { |
35 } | 35 } |
36 | 36 |
37 SelectionOwner::~SelectionOwner() { | 37 SelectionOwner::~SelectionOwner() { |
38 Clear(); | 38 Clear(); |
39 } | 39 } |
40 | 40 |
41 void SelectionOwner::RetrieveTargets(std::vector<Atom>* targets) { | 41 void SelectionOwner::RetrieveTargets(std::vector<Atom>* targets) { |
42 targets->clear(); | |
43 for (SelectionFormatMap::const_iterator it = format_map_.begin(); | 42 for (SelectionFormatMap::const_iterator it = format_map_.begin(); |
44 it != format_map_.end(); ++it) { | 43 it != format_map_.end(); ++it) { |
45 targets->push_back(it->first); | 44 targets->push_back(it->first); |
46 } | 45 } |
47 } | 46 } |
48 | 47 |
49 void SelectionOwner::TakeOwnershipOfSelection( | 48 void SelectionOwner::TakeOwnershipOfSelection( |
50 const SelectionFormatMap& data) { | 49 const SelectionFormatMap& data) { |
51 XSetSelectionOwner(x_display_, selection_name_, x_window_, CurrentTime); | 50 XSetSelectionOwner(x_display_, selection_name_, x_window_, CurrentTime); |
52 | 51 |
(...skipping 21 matching lines...) Expand all Loading... | |
74 reply.xselection.property = None; // Indicates failure | 73 reply.xselection.property = None; // Indicates failure |
75 reply.xselection.time = event.time; | 74 reply.xselection.time = event.time; |
76 | 75 |
77 // Get the proper selection. | 76 // Get the proper selection. |
78 Atom targets_atom = atom_cache_.GetAtom(kTargets); | 77 Atom targets_atom = atom_cache_.GetAtom(kTargets); |
79 if (event.target == targets_atom) { | 78 if (event.target == targets_atom) { |
80 // We have been asked for TARGETS. Send an atom array back with the data | 79 // We have been asked for TARGETS. Send an atom array back with the data |
81 // types we support. | 80 // types we support. |
82 std::vector<Atom> targets; | 81 std::vector<Atom> targets; |
83 targets.push_back(targets_atom); | 82 targets.push_back(targets_atom); |
84 RetrieveTargets(&targets); | 83 RetrieveTargets(&targets); |
sadrul
2014/01/09 13:07:55
An alternate solution could be to targets.push_bac
| |
85 | 84 |
86 XChangeProperty(x_display_, event.requestor, event.property, XA_ATOM, 32, | 85 XChangeProperty(x_display_, event.requestor, event.property, XA_ATOM, 32, |
87 PropModeReplace, | 86 PropModeReplace, |
88 reinterpret_cast<unsigned char*>(&targets.front()), | 87 reinterpret_cast<unsigned char*>(&targets.front()), |
89 targets.size()); | 88 targets.size()); |
90 reply.xselection.property = event.property; | 89 reply.xselection.property = event.property; |
91 } else if (event.target == atom_cache_.GetAtom(kMultiple)) { | 90 } else if (event.target == atom_cache_.GetAtom(kMultiple)) { |
92 // TODO(erg): Theoretically, the spec claims I'm supposed to handle the | 91 // TODO(erg): Theoretically, the spec claims I'm supposed to handle the |
93 // MULTIPLE case, but I haven't seen it in the wild yet. | 92 // MULTIPLE case, but I haven't seen it in the wild yet. |
94 NOTIMPLEMENTED(); | 93 NOTIMPLEMENTED(); |
(...skipping 21 matching lines...) Expand all Loading... | |
116 | 115 |
117 void SelectionOwner::OnSelectionClear(const XSelectionClearEvent& event) { | 116 void SelectionOwner::OnSelectionClear(const XSelectionClearEvent& event) { |
118 DLOG(ERROR) << "SelectionClear"; | 117 DLOG(ERROR) << "SelectionClear"; |
119 | 118 |
120 // TODO(erg): If we receive a SelectionClear event while we're handling data, | 119 // TODO(erg): If we receive a SelectionClear event while we're handling data, |
121 // we need to delay clearing. | 120 // we need to delay clearing. |
122 } | 121 } |
123 | 122 |
124 } // namespace ui | 123 } // namespace ui |
125 | 124 |
OLD | NEW |