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
|
|
|
|
|
|
|
|
#include "libcef/browser/menu_model_impl.h"
|
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
#include "libcef/browser/menu_runner.h"
|
|
|
|
|
2015-09-09 16:05:39 +02:00
|
|
|
#include "base/memory/weak_ptr.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
|
|
|
#include "content/public/common/context_menu_params.h"
|
|
|
|
|
2014-02-05 21:35:45 +01:00
|
|
|
namespace content {
|
|
|
|
class RenderFrameHost;
|
2015-07-16 23:40:01 +02:00
|
|
|
class WebContents;
|
2014-02-05 21:35:45 +01:00
|
|
|
};
|
|
|
|
|
2012-04-19 22:31:46 +02:00
|
|
|
class CefBrowserHostImpl;
|
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:
|
2015-11-17 19:20:13 +01:00
|
|
|
CefMenuManager(CefBrowserHostImpl* browser,
|
2016-04-27 22:38:52 +02:00
|
|
|
std::unique_ptr<CefMenuRunner> runner);
|
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,
|
|
|
|
base::string16& label) override;
|
2012-04-19 22:31:46 +02:00
|
|
|
|
2015-09-09 16:05:39 +02:00
|
|
|
void ExecuteCommandCallback(int command_id,
|
|
|
|
cef_event_flags_t event_flags);
|
|
|
|
|
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);
|
|
|
|
|
2012-04-19 22:31:46 +02:00
|
|
|
// CefBrowserHostImpl pointer is guaranteed to outlive this object.
|
|
|
|
CefBrowserHostImpl* 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.
|
|
|
|
CefRunContextMenuCallback* custom_menu_callback_;
|
|
|
|
|
|
|
|
// Must be the last member.
|
2015-11-17 19:20:13 +01:00
|
|
|
base::WeakPtrFactory<CefMenuManager> weak_ptr_factory_;
|
2015-09-09 16:05:39 +02:00
|
|
|
|
2015-11-17 19:20:13 +01:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(CefMenuManager);
|
2012-04-19 22:31:46 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // CEF_LIBCEF_BROWSER_MENU_MANAGER_H_
|