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 17 matching lines...) Expand all Loading... | |
28 SelectionOwner::SelectionOwner(Display* x_display, | 28 SelectionOwner::SelectionOwner(Display* x_display, |
29 Window x_window, | 29 Window x_window, |
30 Atom selection_name) | 30 Atom selection_name) |
31 : x_display_(x_display), | 31 : x_display_(x_display), |
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(); | |
39 } | |
40 | |
41 void SelectionOwner::RetrieveTargets(std::vector<Atom>* targets) { | |
Daniel Erat
2013/06/17 22:09:57
nit: either clear |targets| first here or document
| |
42 for (SelectionFormatMap::const_iterator it = selection_data_->begin(); | |
43 it != selection_data_->end(); ++it) { | |
44 targets->push_back(it->first); | |
45 } | |
38 } | 46 } |
39 | 47 |
40 void SelectionOwner::TakeOwnershipOfSelection( | 48 void SelectionOwner::TakeOwnershipOfSelection( |
41 scoped_ptr<SelectionFormatMap> data) { | 49 scoped_ptr<SelectionFormatMap> data) { |
42 XSetSelectionOwner(x_display_, selection_name_, x_window_, CurrentTime); | 50 XSetSelectionOwner(x_display_, selection_name_, x_window_, CurrentTime); |
43 | 51 |
44 if (XGetSelectionOwner(x_display_, selection_name_) == x_window_) { | 52 if (XGetSelectionOwner(x_display_, selection_name_) == x_window_) { |
45 // The X server agrees that we are the selection owner. Commit our data. | 53 // The X server agrees that we are the selection owner. Commit our data. |
46 selection_data_ = data.Pass(); | 54 selection_data_ = data.Pass(); |
47 } | 55 } |
(...skipping 18 matching lines...) Expand all Loading... | |
66 reply.xselection.time = event.time; | 74 reply.xselection.time = event.time; |
67 | 75 |
68 // Get the proper selection. | 76 // Get the proper selection. |
69 if (selection_data_.get()) { | 77 if (selection_data_.get()) { |
70 Atom targets_atom = atom_cache_.GetAtom(kTargets); | 78 Atom targets_atom = atom_cache_.GetAtom(kTargets); |
71 if (event.target == targets_atom) { | 79 if (event.target == targets_atom) { |
72 // We have been asked for TARGETS. Send an atom array back with the data | 80 // We have been asked for TARGETS. Send an atom array back with the data |
73 // types we support. | 81 // types we support. |
74 std::vector<Atom> targets; | 82 std::vector<Atom> targets; |
75 targets.push_back(targets_atom); | 83 targets.push_back(targets_atom); |
76 for (SelectionFormatMap::const_iterator it = selection_data_->begin(); | 84 RetrieveTargets(&targets); |
77 it != selection_data_->end(); ++it) { | |
78 targets.push_back(it->first); | |
79 } | |
80 | 85 |
81 XChangeProperty(x_display_, event.requestor, event.property, XA_ATOM, 32, | 86 XChangeProperty(x_display_, event.requestor, event.property, XA_ATOM, 32, |
82 PropModeReplace, | 87 PropModeReplace, |
83 reinterpret_cast<unsigned char*>(&targets.front()), | 88 reinterpret_cast<unsigned char*>(&targets.front()), |
84 targets.size()); | 89 targets.size()); |
85 reply.xselection.property = event.property; | 90 reply.xselection.property = event.property; |
86 } else if (event.target == atom_cache_.GetAtom(kMultiple)) { | 91 } else if (event.target == atom_cache_.GetAtom(kMultiple)) { |
87 // TODO(erg): Theoretically, the spec claims I'm supposed to handle the | 92 // TODO(erg): Theoretically, the spec claims I'm supposed to handle the |
88 // MULTIPLE case, but I haven't seen it in the wild yet. | 93 // MULTIPLE case, but I haven't seen it in the wild yet. |
89 NOTIMPLEMENTED(); | 94 NOTIMPLEMENTED(); |
(...skipping 23 matching lines...) Expand all Loading... | |
113 | 118 |
114 void SelectionOwner::OnSelectionClear(const XSelectionClearEvent& event) { | 119 void SelectionOwner::OnSelectionClear(const XSelectionClearEvent& event) { |
115 DLOG(ERROR) << "SelectionClear"; | 120 DLOG(ERROR) << "SelectionClear"; |
116 | 121 |
117 // TODO(erg): If we receive a SelectionClear event while we're handling data, | 122 // TODO(erg): If we receive a SelectionClear event while we're handling data, |
118 // we need to delay clearing. | 123 // we need to delay clearing. |
119 } | 124 } |
120 | 125 |
121 } // namespace ui | 126 } // namespace ui |
122 | 127 |
OLD | NEW |