2012-04-19 22:31:46 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework 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 CEF_LIBCEF_BROWSER_MENU_MANAGER_H_
|
|
|
|
#define CEF_LIBCEF_BROWSER_MENU_MANAGER_H_
|
|
|
|
#pragma once
|
|
|
|
|
2024-05-11 17:48:38 +02:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2015-09-09 16:05:39 +02:00
|
|
|
#include "base/memory/weak_ptr.h"
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/menu_model_impl.h"
|
|
|
|
#include "cef/libcef/browser/menu_runner.h"
|
2020-03-30 22:13:42 +02:00
|
|
|
#include "content/public/browser/context_menu_params.h"
|
2015-07-16 23:40:01 +02:00
|
|
|
#include "content/public/browser/web_contents_observer.h"
|
2012-04-19 22:31:46 +02:00
|
|
|
|
2014-02-05 21:35:45 +01:00
|
|
|
namespace content {
|
|
|
|
class RenderFrameHost;
|
2015-07-16 23:40:01 +02:00
|
|
|
class WebContents;
|
2019-03-13 22:27:37 +01:00
|
|
|
} // namespace content
|
2014-02-05 21:35:45 +01:00
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
class AlloyBrowserHostImpl;
|
2015-11-17 19:20:13 +01:00
|
|
|
class CefRunContextMenuCallback;
|
2012-04-19 22:31:46 +02:00
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
class CefMenuManager : public CefMenuModelImpl::Delegate,
|
2015-07-16 23:40:01 +02:00
|
|
|
public content::WebContentsObserver {
|
2012-04-19 22:31:46 +02:00
|
|
|
public:
|
2020-09-22 21:54:02 +02:00
|
|
|
CefMenuManager(AlloyBrowserHostImpl* browser,
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<CefMenuRunner> runner);
|
2021-12-06 21:40:25 +01:00
|
|
|
|
|
|
|
CefMenuManager(const CefMenuManager&) = delete;
|
|
|
|
CefMenuManager& operator=(const CefMenuManager&) = delete;
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
~CefMenuManager() override;
|
|
|
|
|
|
|
|
// Delete the runner to free any platform constructs.
|
|
|
|
void Destroy();
|
2012-04-19 22:31:46 +02:00
|
|
|
|
|
|
|
// Returns true if the context menu is currently showing.
|
|
|
|
bool IsShowingContextMenu();
|
|
|
|
|
|
|
|
// Create the context menu.
|
|
|
|
bool CreateContextMenu(const content::ContextMenuParams& params);
|
2014-07-01 00:30:29 +02:00
|
|
|
void CancelContextMenu();
|
2012-04-19 22:31:46 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
// CefMenuModelImpl::Delegate methods.
|
2014-11-12 20:25:15 +01:00
|
|
|
void ExecuteCommand(CefRefPtr<CefMenuModelImpl> source,
|
|
|
|
int command_id,
|
|
|
|
cef_event_flags_t event_flags) override;
|
|
|
|
void MenuWillShow(CefRefPtr<CefMenuModelImpl> source) override;
|
|
|
|
void MenuClosed(CefRefPtr<CefMenuModelImpl> source) override;
|
2017-02-22 19:05:27 +01:00
|
|
|
bool FormatLabel(CefRefPtr<CefMenuModelImpl> source,
|
2021-04-21 00:52:34 +02:00
|
|
|
std::u16string& label) override;
|
2012-04-19 22:31:46 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void ExecuteCommandCallback(int command_id, cef_event_flags_t event_flags);
|
2015-09-09 16:05:39 +02:00
|
|
|
|
2012-04-19 22:31:46 +02:00
|
|
|
// Create the default menu model.
|
|
|
|
void CreateDefaultModel();
|
|
|
|
// Execute the default command handling.
|
|
|
|
void ExecuteDefaultCommand(int command_id);
|
|
|
|
|
2015-09-09 16:05:39 +02:00
|
|
|
// Returns true if the specified id is a custom context menu command.
|
|
|
|
bool IsCustomContextMenuCommand(int command_id);
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
// AlloyBrowserHostImpl pointer is guaranteed to outlive this object.
|
2024-05-11 17:48:38 +02:00
|
|
|
raw_ptr<AlloyBrowserHostImpl> browser_;
|
2014-02-05 21:35:45 +01:00
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<CefMenuRunner> runner_;
|
2015-11-17 19:20:13 +01:00
|
|
|
|
2012-04-19 22:31:46 +02:00
|
|
|
CefRefPtr<CefMenuModelImpl> model_;
|
|
|
|
content::ContextMenuParams params_;
|
|
|
|
|
2015-09-09 16:05:39 +02:00
|
|
|
// Not owned by this class.
|
2024-05-11 17:48:38 +02:00
|
|
|
raw_ptr<CefRunContextMenuCallback> custom_menu_callback_ = nullptr;
|
2015-09-09 16:05:39 +02:00
|
|
|
|
|
|
|
// Must be the last member.
|
2015-11-17 19:20:13 +01:00
|
|
|
base::WeakPtrFactory<CefMenuManager> weak_ptr_factory_;
|
2012-04-19 22:31:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_MENU_MANAGER_H_
|