mirror of
https://github.com/cefsharp/CefSharp.git
synced 2026-12-05 03:32:37 +00:00
Add IMenuModel
Refactor to reflect actual underlying Cef Model (Remove return bool)
This commit is contained in:
@@ -261,6 +261,7 @@
|
||||
<ClInclude Include="Internals\CefFileDialogCallbackWrapper.h" />
|
||||
<ClInclude Include="Internals\CefFrameWrapper.h" />
|
||||
<ClInclude Include="Internals\CefGeolocationCallbackWrapper.h" />
|
||||
<ClInclude Include="Internals\CefMenuModelWrapper.h" />
|
||||
<ClInclude Include="Internals\CefPostDataElementWrapper.h" />
|
||||
<ClInclude Include="Internals\CefPostDataWrapper.h" />
|
||||
<ClInclude Include="Internals\CefResponseWrapper.h" />
|
||||
|
||||
@@ -238,6 +238,9 @@
|
||||
<ClInclude Include="WindowInfo.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Internals\CefMenuModelWrapper.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Internals\CefSharpBrowserWrapper.h">
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
// Copyright © 2010-2015 The CefSharp Authors. All rights reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Stdafx.h"
|
||||
|
||||
#include "include\cef_menu_model.h"
|
||||
|
||||
namespace CefSharp
|
||||
{
|
||||
public ref class CefMenuModelWrapper : public IMenuModel
|
||||
{
|
||||
private:
|
||||
MCefRefPtr<CefMenuModel> _menu;
|
||||
|
||||
public:
|
||||
CefMenuModelWrapper(CefRefPtr<CefMenuModel> &menu) : _menu(menu)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
!CefMenuModelWrapper()
|
||||
{
|
||||
_menu = NULL;
|
||||
}
|
||||
|
||||
~CefMenuModelWrapper()
|
||||
{
|
||||
this->!CefMenuModelWrapper();
|
||||
}
|
||||
|
||||
virtual bool Clear()
|
||||
{
|
||||
return _menu->Clear();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "ClientAdapter.h"
|
||||
#include "CefRequestWrapper.h"
|
||||
#include "CefContextMenuParamsWrapper.h"
|
||||
#include "CefMenuModelWrapper.h"
|
||||
#include "CefDragDataWrapper.h"
|
||||
#include "TypeConversion.h"
|
||||
#include "CefSharpBrowserWrapper.h"
|
||||
@@ -623,19 +624,15 @@ namespace CefSharp
|
||||
{
|
||||
auto handler = _browserControl->MenuHandler;
|
||||
|
||||
if (handler == nullptr)
|
||||
if (handler != nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CefFrameWrapper frameWrapper(frame);
|
||||
CefContextMenuParamsWrapper contextMenuParamsWrapper(params);
|
||||
|
||||
auto result = handler->OnBeforeContextMenu(_browserControl, %frameWrapper, %contextMenuParamsWrapper);
|
||||
if (!result)
|
||||
{
|
||||
model->Clear();
|
||||
}
|
||||
auto browserWrapper = GetBrowserWrapper(browser->GetIdentifier(), browser->IsPopup());
|
||||
CefFrameWrapper frameWrapper(frame);
|
||||
CefContextMenuParamsWrapper contextMenuParamsWrapper(params);
|
||||
CefMenuModelWrapper menuModelWrapper(model);
|
||||
|
||||
handler->OnBeforeContextMenu(_browserControl, browserWrapper, %frameWrapper, %contextMenuParamsWrapper, %menuModelWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
void ClientAdapter::OnGotFocus(CefRefPtr<CefBrowser> browser)
|
||||
|
||||
@@ -6,10 +6,20 @@ namespace CefSharp.WinForms.Example.Handlers
|
||||
{
|
||||
internal class MenuHandler : IMenuHandler
|
||||
{
|
||||
public bool OnBeforeContextMenu(IWebBrowser browser, IFrame frame, IContextMenuParams parameters)
|
||||
void IMenuHandler.OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model)
|
||||
{
|
||||
// Return false if you want to disable the context menu.
|
||||
return true;
|
||||
//To disable the menu then call clear
|
||||
// model.Clear();
|
||||
}
|
||||
|
||||
bool IMenuHandler.OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, int commandId, CefEventFlags eventFlags)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void IMenuHandler.OnContextMenuDismissed(IWebBrowser browserControl, IBrowser browser, IFrame frame)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,12 +8,23 @@ namespace CefSharp.Wpf.Example.Handlers
|
||||
{
|
||||
public class MenuHandler : IMenuHandler
|
||||
{
|
||||
public bool OnBeforeContextMenu(IWebBrowser browser, IFrame frame, IContextMenuParams parameters)
|
||||
void IMenuHandler.OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model)
|
||||
{
|
||||
Console.WriteLine("Context menu opened");
|
||||
Console.WriteLine(parameters.MisspelledWord);
|
||||
|
||||
return true;
|
||||
//To disable context mode then clear
|
||||
// model.Clear();
|
||||
}
|
||||
|
||||
bool IMenuHandler.OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, int commandId, CefEventFlags eventFlags)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void IMenuHandler.OnContextMenuDismissed(IWebBrowser browserControl, IBrowser browser, IFrame frame)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,6 +94,7 @@
|
||||
<Compile Include="CefJsDialogType.cs" />
|
||||
<Compile Include="ICookieManager.cs" />
|
||||
<Compile Include="ILoadHandler.cs" />
|
||||
<Compile Include="IMenuModel.cs" />
|
||||
<Compile Include="KeyEvent.cs" />
|
||||
<Compile Include="KeyEventType.cs" />
|
||||
<Compile Include="IPostData.cs" />
|
||||
|
||||
@@ -6,6 +6,48 @@ namespace CefSharp
|
||||
{
|
||||
public interface IMenuHandler
|
||||
{
|
||||
bool OnBeforeContextMenu(IWebBrowser browser, IFrame frame, IContextMenuParams parameters);
|
||||
/// <summary>
|
||||
/// Called before a context menu is displayed. |params| provides information
|
||||
/// about the context menu state. |model| initially contains the default
|
||||
/// context menu. The |model| can be cleared to show no context menu or
|
||||
/// modified to show a custom menu. Do not keep references to |params| or
|
||||
/// |model| outside of this callback.
|
||||
/// </summary>
|
||||
/// <param name="browserControl">the ChromiumWebBrowser control</param>
|
||||
/// <param name="browser">the browser object</param>
|
||||
/// <param name="frame">The frame the request is coming from</param>
|
||||
/// <param name="parameters"></param>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters,
|
||||
IMenuModel model);
|
||||
|
||||
/// <summary>
|
||||
/// Called to execute a command selected from the context menu. Return true if
|
||||
/// the command was handled or false for the default implementation. See
|
||||
/// cef_menu_id_t for the command ids that have default implementations. All
|
||||
/// user-defined command ids should be between MENU_ID_USER_FIRST and
|
||||
/// MENU_ID_USER_LAST. |params| will have the same values as what was passed to
|
||||
/// OnBeforeContextMenu(). Do not keep a reference to |params| outside of this
|
||||
/// callback.
|
||||
/// </summary>
|
||||
/// <param name="browserControl">the ChromiumWebBrowser control</param>
|
||||
/// <param name="browser">the browser object</param>
|
||||
/// <param name="frame">The frame the request is coming from</param>
|
||||
/// <param name="parameters"></param>
|
||||
/// <param name="commandId"></param>
|
||||
/// <param name="eventFlags"></param>
|
||||
/// <returns></returns>
|
||||
bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters,
|
||||
int commandId, CefEventFlags eventFlags);
|
||||
|
||||
/// <summary>
|
||||
/// Called when the context menu is dismissed irregardless of whether the menu
|
||||
/// was empty or a command was selected.
|
||||
/// </summary>
|
||||
/// <param name="browserControl">the ChromiumWebBrowser control</param>
|
||||
/// <param name="browser">the browser object</param>
|
||||
/// <param name="frame">The frame the request is coming from</param>
|
||||
void OnContextMenuDismissed(IWebBrowser browserControl, IBrowser browser, IFrame frame);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
// Copyright © 2010-2015 The CefSharp Authors. All rights reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
namespace CefSharp
|
||||
{
|
||||
public interface IMenuModel
|
||||
{
|
||||
bool Clear();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user