forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclipboard_history_controller_impl.h
139 lines (107 loc) · 4.64 KB
/
clipboard_history_controller_impl.h
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
// Copyright 2020 The Chromium Authors. All rights reserved.
// 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_CONTROLLER_IMPL_H_
#define ASH_CLIPBOARD_CLIPBOARD_HISTORY_CONTROLLER_IMPL_H_
#include <memory>
#include <vector>
#include "ash/ash_export.h"
#include "ash/clipboard/clipboard_history.h"
#include "ash/clipboard/clipboard_history_item.h"
#include "ash/public/cpp/clipboard_history_controller.h"
#include "base/memory/weak_ptr.h"
#include "base/observer_list.h"
namespace views {
enum class MenuAnchorPosition;
} // namespace views
namespace gfx {
class Rect;
} // namespace gfx
namespace ash {
class ClipboardHistoryMenuModelAdapter;
class ClipboardHistoryResourceManager;
class ClipboardNudgeController;
// Shows a menu with the last few things saved in the clipboard when the
// keyboard shortcut is pressed.
class ASH_EXPORT ClipboardHistoryControllerImpl
: public ClipboardHistoryController,
public ClipboardHistory::Observer {
public:
class Observer : public base::CheckedObserver {
public:
// Called when the clipboard history menu is shown.
virtual void OnClipboardHistoryMenuShown() = 0;
// Called when the user pastes from the clipboard history menu.
virtual void OnClipboardHistoryPasted() = 0;
};
ClipboardHistoryControllerImpl();
ClipboardHistoryControllerImpl(const ClipboardHistoryControllerImpl&) =
delete;
ClipboardHistoryControllerImpl& operator=(
const ClipboardHistoryControllerImpl&) = delete;
~ClipboardHistoryControllerImpl() override;
void AddObserver(Observer* observer) const;
void RemoveObserver(Observer* observer) const;
// Returns if the contextual menu is currently showing.
bool IsMenuShowing() const;
// Shows the clipboard history menu through the keyboard accelerator.
void ShowMenuByAccelerator();
// Returns bounds for the contextual menu in screen coordinates.
gfx::Rect GetMenuBoundsInScreenForTest() const;
// Returns the history which tracks what is being copied to the clipboard.
const ClipboardHistory* history() const { return clipboard_history_.get(); }
// Returns the resource manager which gets labels and images for items copied
// to the clipboard.
const ClipboardHistoryResourceManager* resource_manager() const {
return resource_manager_.get();
}
ClipboardNudgeController* nudge_controller() const {
return nudge_controller_.get();
}
ClipboardHistoryMenuModelAdapter* context_menu_for_test() {
return context_menu_.get();
}
private:
class AcceleratorTarget;
class MenuDelegate;
// ClipboardHistoryController:
void ShowMenu(const gfx::Rect& anchor_rect,
views::MenuAnchorPosition menu_anchor_position,
ui::MenuSourceType source_type) override;
bool CanShowMenu() const override;
// ClipboardHistory::Observer:
void OnClipboardHistoryCleared() override;
void ExecuteSelectedMenuItem(int event_flags);
// Executes the command specified by `command_id` with the given event flags.
void ExecuteCommand(int command_id, int event_flags);
// Paste the clipboard data of the menu item specified by `command_id`.
// `paste_plain_text` indicates whether the plain text instead of the
// clipboard data should be pasted.
void PasteMenuItemData(int command_id, bool paste_plain_text);
// Delete the menu item being selected and its corresponding data. If no item
// is selected, do nothing.
void DeleteSelectedMenuItemIfAny();
// Advances the pseudo focus (backward if `reverse` is true).
void AdvancePseudoFocus(bool reverse);
gfx::Rect CalculateAnchorRect() const;
// Called when the contextual menu is closed.
void OnMenuClosed();
// Mutable to allow adding/removing from |observers_| through a const
// ClipboardHistoryControllerImpl.
mutable base::ObserverList<Observer> observers_;
// The menu being shown.
std::unique_ptr<ClipboardHistoryMenuModelAdapter> context_menu_;
// Used to keep track of what is being copied to the clipboard.
std::unique_ptr<ClipboardHistory> clipboard_history_;
// Manages resources for clipboard history.
std::unique_ptr<ClipboardHistoryResourceManager> resource_manager_;
// Detects the search+v key combo.
std::unique_ptr<AcceleratorTarget> accelerator_target_;
// Handles events on the contextual menu.
std::unique_ptr<MenuDelegate> menu_delegate_;
// Controller that shows contextual nudges for multipaste.
std::unique_ptr<ClipboardNudgeController> nudge_controller_;
base::WeakPtrFactory<ClipboardHistoryControllerImpl> weak_ptr_factory_{this};
};
} // namespace ash
#endif // ASH_CLIPBOARD_CLIPBOARD_HISTORY_CONTROLLER_IMPL_H_