feat: add support for share menu on macOS (#25629)
This commit is contained in:
parent
89c04b3c6c
commit
6b6ffbdd10
17 changed files with 316 additions and 6 deletions
|
@ -6,16 +6,34 @@
|
|||
#define SHELL_BROWSER_UI_ELECTRON_MENU_MODEL_H_
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/memory/weak_ptr.h"
|
||||
#include "base/observer_list.h"
|
||||
#include "base/observer_list_types.h"
|
||||
#include "base/optional.h"
|
||||
#include "ui/base/models/simple_menu_model.h"
|
||||
#include "url/gurl.h"
|
||||
|
||||
namespace electron {
|
||||
|
||||
class ElectronMenuModel : public ui::SimpleMenuModel {
|
||||
public:
|
||||
#if defined(OS_MAC)
|
||||
struct SharingItem {
|
||||
SharingItem();
|
||||
SharingItem(SharingItem&&);
|
||||
SharingItem(const SharingItem&) = delete;
|
||||
~SharingItem();
|
||||
|
||||
base::Optional<std::vector<std::string>> texts;
|
||||
base::Optional<std::vector<GURL>> urls;
|
||||
base::Optional<std::vector<base::FilePath>> file_paths;
|
||||
};
|
||||
#endif
|
||||
|
||||
class Delegate : public ui::SimpleMenuModel::Delegate {
|
||||
public:
|
||||
~Delegate() override {}
|
||||
|
@ -30,6 +48,11 @@ class ElectronMenuModel : public ui::SimpleMenuModel {
|
|||
|
||||
virtual bool ShouldCommandIdWorkWhenHidden(int command_id) const = 0;
|
||||
|
||||
#if defined(OS_MAC)
|
||||
virtual bool GetSharingItemForCommandId(int command_id,
|
||||
SharingItem* item) const = 0;
|
||||
#endif
|
||||
|
||||
private:
|
||||
// ui::SimpleMenuModel::Delegate:
|
||||
bool GetAcceleratorForCommandId(
|
||||
|
@ -65,6 +88,13 @@ class ElectronMenuModel : public ui::SimpleMenuModel {
|
|||
ui::Accelerator* accelerator) const;
|
||||
bool ShouldRegisterAcceleratorAt(int index) const;
|
||||
bool WorksWhenHiddenAt(int index) const;
|
||||
#if defined(OS_MAC)
|
||||
// Return the SharingItem of menu item.
|
||||
bool GetSharingItemAt(int index, SharingItem* item) const;
|
||||
// Set/Get the SharingItem of this menu.
|
||||
void SetSharingItem(SharingItem item);
|
||||
const base::Optional<SharingItem>& GetSharingItem() const;
|
||||
#endif
|
||||
|
||||
// ui::SimpleMenuModel:
|
||||
void MenuWillClose() override;
|
||||
|
@ -80,6 +110,10 @@ class ElectronMenuModel : public ui::SimpleMenuModel {
|
|||
private:
|
||||
Delegate* delegate_; // weak ref.
|
||||
|
||||
#if defined(OS_MAC)
|
||||
base::Optional<SharingItem> sharing_item_;
|
||||
#endif
|
||||
|
||||
std::map<int, base::string16> toolTips_; // command id -> tooltip
|
||||
std::map<int, base::string16> roles_; // command id -> role
|
||||
std::map<int, base::string16> sublabels_; // command id -> sublabel
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue