1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
ash / clipboard / clipboard_history_util.h [blame]
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_CLIPBOARD_CLIPBOARD_HISTORY_UTIL_H_
#define ASH_CLIPBOARD_CLIPBOARD_HISTORY_UTIL_H_
#include <list>
#include <optional>
#include <string>
#include <string_view>
#include <vector>
#include "ash/ash_export.h"
#include "chromeos/crosapi/mojom/clipboard_history.mojom.h"
#include "ui/base/models/image_model.h"
namespace ui {
class ClipboardData;
enum class ClipboardInternalFormat;
} // namespace ui
namespace ash {
class ClipboardHistoryItem;
namespace clipboard_history_util {
// The first available command id for clipboard history menu items.
constexpr int kFirstItemCommandId = 1;
// The maximum available command id for clipboard history menu items.
constexpr int kMaxItemCommandId = 5;
// The max number of items stored in ClipboardHistory.
constexpr int kMaxClipboardItems = kMaxItemCommandId - kFirstItemCommandId + 1;
// A value greater than the maximum command ID, used to record histograms.
constexpr int kCommandIdBoundary = kMaxItemCommandId + 1;
// The type of the action to take when the clipboard history menu item is
// activated.
enum class Action {
kEmpty,
// Pastes the activated item's corresponding clipboard data.
kPaste,
// Deletes the activated item.
kDelete,
// Selects the activated item.
kSelect,
// Selects the item hovered by mouse if any.
kSelectItemHoveredByMouse
};
// IDs for the views used by the clipboard history menu.
enum MenuViewID {
// We start at 1 because 0 is not a valid view ID.
kBitmapItemView = 1,
kContentsViewID,
kCtrlVLabelID,
kDeleteButtonViewID,
kDisplayTextLabelID,
kFooterContentViewID,
kFooterContentV2LabelID,
kFooterContentV2ViewID,
kSecondaryDisplayTextLabelID,
};
// Modes for specifying a clipboard history pause's semantics.
enum class PauseBehavior {
// Clipboard history should be truly paused, i.e., any data change or read
// should be ignored.
kDefault = 0,
// The operation guarded by this pause is a paste-based reorder, which is
// allowed to change the clipboard history list.
kAllowReorderOnPaste = 1,
};
// The different operations clipboard history sees. These values are written to
// logs. New enum values can be added, but existing enums must never be
// renumbered, deleted, or reused. Keep this up to date with the
// `ClipboardHistoryOperation` enum in enums.xml.
enum class Operation {
// Emitted when the user initiates a clipboard write.
kCopy = 0,
// Emitted when the user initiates a clipboard read.
kPaste = 1,
// Insert new types above this line.
kMaxValue = kPaste
};
// The different ways a clipboard history list reorder can occur. These values
// are written to logs. New enum values can be added, but existing enums must
// never be renumbered, deleted, or reused. Keep this up to date with the
// `ClipboardHistoryReorderType` enum in enums.xml.
enum class ReorderType {
// Emitted when the user copies an existing clipboard history item other than
// the top item, causing the copied item to move to the top.
kOnCopy = 0,
// Emitted when the user pastes an existing clipboard history item other than
// the top item, causing the pasted item to move to the top. This behavior is
// gated by the `kClipboardHistoryReorder` flag.
kOnPaste = 1,
// Insert new types above this line.
kMaxValue = kOnPaste
};
// Returns the main format of the specified clipboard `data`.
// NOTE: One `ui::ClipboardData` instance may contain multiple formats.
ASH_EXPORT std::optional<ui::ClipboardInternalFormat> CalculateMainFormat(
const ui::ClipboardData& data);
// Returns true if `data` contains the specified `format`.
ASH_EXPORT bool ContainsFormat(const ui::ClipboardData& data,
ui::ClipboardInternalFormat format);
// Records the histogram for deleting clipboard history items.
ASH_EXPORT void RecordClipboardHistoryItemDeleted(
const ClipboardHistoryItem& item);
// Records the histogram for pasting clipboard history items.
ASH_EXPORT void RecordClipboardHistoryItemPasted(
const ClipboardHistoryItem& item);
// Returns true if `data` contains file system data.
ASH_EXPORT bool ContainsFileSystemData(const ui::ClipboardData& data);
// Updates `sources` with the file system sources contained in `data`; updates
// `source_list` by splitting `sources` into pieces each of which corresponds to
// a file. Note that multiple files can be copied simultaneously. `sources` is
// referenced by `source_list` to reduce memory copies.
ASH_EXPORT void GetSplitFileSystemData(
const ui::ClipboardData& data,
std::vector<std::u16string_view>* source_list,
std::u16string* sources);
// Returns the count of copied files contained by the clipboard data.
ASH_EXPORT size_t GetCountOfCopiedFiles(const ui::ClipboardData& data);
// Returns file system sources contained in `data`. If `data` does not contain
// file system sources, an empty string is returned.
ASH_EXPORT std::u16string GetFileSystemSources(const ui::ClipboardData& data);
// Returns the icon representation of the shortcut modifier key based on
// keyboard layout and whether the Assistant feature is enabled.
ASH_EXPORT const gfx::VectorIcon& GetShortcutKeyIcon();
// Returns the name of the shortcut modifier key based on keyboard layout.
ASH_EXPORT std::u16string GetShortcutKeyName();
// Returns true if `data` is supported by clipboard history.
ASH_EXPORT bool IsSupported(const ui::ClipboardData& data);
// Returns whether the clipboard history is enabled for the current user mode.
ASH_EXPORT bool IsEnabledInCurrentMode();
// Returns an image icon for the file clipboard item.
ASH_EXPORT ui::ImageModel GetIconForFileClipboardItem(
const ClipboardHistoryItem& item);
// Returns a placeholder image to display for HTML items while their previews
// render.
ASH_EXPORT ui::ImageModel GetHtmlPreviewPlaceholder();
// Returns an item descriptor based on `item`.
crosapi::mojom::ClipboardHistoryItemDescriptor ItemToDescriptor(
const ClipboardHistoryItem& item);
// Calculates the preferred width for clipboard history menu item views.
int GetPreferredItemViewWidth();
} // namespace clipboard_history_util
} // namespace ash
#endif // ASH_CLIPBOARD_CLIPBOARD_HISTORY_UTIL_H_