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 #ifndef UI_BASE_X_SELECTION_OWNER_H_ | 5 #ifndef UI_BASE_X_SELECTION_OWNER_H_ |
6 #define UI_BASE_X_SELECTION_OWNER_H_ | 6 #define UI_BASE_X_SELECTION_OWNER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/memory/ref_counted_memory.h" | |
13 #include "base/time/time.h" | |
14 #include "base/timer/timer.h" | |
12 #include "ui/base/ui_base_export.h" | 15 #include "ui/base/ui_base_export.h" |
13 #include "ui/base/x/selection_utils.h" | 16 #include "ui/base/x/selection_utils.h" |
14 #include "ui/gfx/x/x11_atom_cache.h" | 17 #include "ui/gfx/x/x11_atom_cache.h" |
15 #include "ui/gfx/x/x11_types.h" | 18 #include "ui/gfx/x/x11_types.h" |
16 | 19 |
17 namespace ui { | 20 namespace ui { |
18 | 21 |
19 // Owns a specific X11 selection on an X window. | 22 // Owns a specific X11 selection on an X window. |
20 // | 23 // |
21 // The selection owner object keeps track of which xwindow is the current | 24 // The selection owner object keeps track of which xwindow is the current |
(...skipping 16 matching lines...) Expand all Loading... | |
38 // |data| to other windows. | 41 // |data| to other windows. |
39 void TakeOwnershipOfSelection(const SelectionFormatMap& data); | 42 void TakeOwnershipOfSelection(const SelectionFormatMap& data); |
40 | 43 |
41 // Clears our internal format map and clears the selection owner, whether we | 44 // Clears our internal format map and clears the selection owner, whether we |
42 // own the selection or not. | 45 // own the selection or not. |
43 void ClearSelectionOwner(); | 46 void ClearSelectionOwner(); |
44 | 47 |
45 // It is our owner's responsibility to plumb X11 events on |xwindow_| to us. | 48 // It is our owner's responsibility to plumb X11 events on |xwindow_| to us. |
46 void OnSelectionRequest(const XEvent& event); | 49 void OnSelectionRequest(const XEvent& event); |
47 void OnSelectionClear(const XEvent& event); | 50 void OnSelectionClear(const XEvent& event); |
48 // TODO(erg): Do we also need to follow PropertyNotify events? We currently | 51 |
49 // don't, but there were open todos in the previous implementation. | 52 // Returns true if SelectionOwner can process the XChangeProperty event, |
53 // |event|. | |
54 bool CanDispatchPropertyEvent(const XEvent& event); | |
55 | |
56 void OnPropertyEvent(const XEvent& event); | |
50 | 57 |
51 private: | 58 private: |
59 // Holds state related to an incremental data transfer. | |
60 struct IncrTransfer { | |
Daniel Erat
2014/07/25 19:38:44
nit: rename to IncrementalTransfer
| |
61 IncrTransfer(XID window, | |
62 XAtom target, | |
63 XAtom property, | |
64 const scoped_refptr<base::RefCountedMemory>& incr_data, | |
65 int incr_offset, | |
66 base::TimeTicks incr_timeout, | |
67 int incr_foreign_window_manager_id); | |
68 ~IncrTransfer(); | |
69 | |
70 // Parameters from the XSelectionRequest. The data is transferred over | |
71 // |property| on |window|. | |
72 XID window; | |
73 XAtom target; | |
74 XAtom property; | |
75 | |
76 // The data to be transferred. | |
77 scoped_refptr<base::RefCountedMemory> data; | |
78 | |
79 // The offset from the beginning of |data| of the first byte to be | |
80 // transferred in the next chunk. | |
81 size_t offset; | |
82 | |
83 // Time when the transfer should be aborted because the selection requestor | |
84 // is taking too long to notify us that we can send the next chunk. | |
85 base::TimeTicks timeout; | |
86 | |
87 // Used to unselect PropertyChangeMask on |window| when we are done with | |
88 // the data transfer. | |
89 int foreign_window_manager_id; | |
90 }; | |
91 | |
52 // Attempts to convert the selection to |target|. If the conversion is | 92 // Attempts to convert the selection to |target|. If the conversion is |
53 // successful, true is returned and the result is stored in the |property| | 93 // successful, true is returned and the result is stored in the |property| |
54 // of |requestor|. | 94 // of |requestor|. |
55 bool ProcessTarget(XAtom target, XID requestor, XAtom property); | 95 bool ProcessTarget(XAtom target, XID requestor, XAtom property); |
56 | 96 |
97 // Sends the next chunk of data for given the incremental data transfer. | |
98 void ProcessIncr(IncrTransfer* transfer); | |
Daniel Erat
2014/07/25 19:38:44
nit: ProcessIncrementalTransfer
| |
99 | |
100 // Aborts any incremental data transfers which have timed out. | |
101 void AbortStaleIncrTransfers(); | |
Daniel Erat
2014/07/25 19:38:44
AbortStaleIncrementalTransfers
| |
102 | |
103 // Called when the transfer at |it| has completed to do cleanup. | |
104 void CompleteIncrTransfer(std::vector<IncrTransfer>::iterator it); | |
Daniel Erat
2014/07/25 19:38:44
CompleteIncrementalTransfer
| |
105 | |
106 // Returns the incremental data transfer, if any, which was waiting for | |
107 // |event|. | |
108 std::vector<IncrTransfer>::iterator FindIncrTransferForEvent( | |
Daniel Erat
2014/07/25 19:38:44
etc.
| |
109 const XEvent& event); | |
110 | |
57 // Our X11 state. | 111 // Our X11 state. |
58 XDisplay* x_display_; | 112 XDisplay* x_display_; |
59 XID x_window_; | 113 XID x_window_; |
60 | 114 |
61 // The X11 selection that this instance communicates on. | 115 // The X11 selection that this instance communicates on. |
62 XAtom selection_name_; | 116 XAtom selection_name_; |
63 | 117 |
118 // The maximum size of data we can put in XChangeProperty(). | |
119 size_t max_request_size_; | |
120 | |
64 // The data we are currently serving. | 121 // The data we are currently serving. |
65 SelectionFormatMap format_map_; | 122 SelectionFormatMap format_map_; |
66 | 123 |
124 std::vector<IncrTransfer> incrs_; | |
Daniel Erat
2014/07/25 19:38:44
incremental_transfers_
| |
125 | |
126 // Used to abort stale incremental data transfers. | |
127 base::RepeatingTimer<SelectionOwner> incr_timer_; | |
Daniel Erat
2014/07/25 19:38:44
incremental_timer_
| |
128 | |
67 X11AtomCache atom_cache_; | 129 X11AtomCache atom_cache_; |
68 | 130 |
69 DISALLOW_COPY_AND_ASSIGN(SelectionOwner); | 131 DISALLOW_COPY_AND_ASSIGN(SelectionOwner); |
70 }; | 132 }; |
71 | 133 |
72 } // namespace ui | 134 } // namespace ui |
73 | 135 |
74 #endif // UI_BASE_X_SELECTION_OWNER_H_ | 136 #endif // UI_BASE_X_SELECTION_OWNER_H_ |
OLD | NEW |