Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CefSharp.Wpf.HwndHost support added to sample app and master solution #4964

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "CefSharp.Wpf.HwndHost"]
path = CefSharp.Wpf.HwndHost
url = https://github.com/cefsharp/CefSharp.Wpf.HwndHost.git
4 changes: 3 additions & 1 deletion CefSharp.Wpf.Example/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
using CefSharp.Example;
using CefSharp.Example.Handlers;
using CefSharp.Wpf.Example.Handlers;

#if CEFSHARP_WPF_HWNDHOST
using CefSharp.Wpf.HwndHost;
#endif
namespace CefSharp.Wpf.Example
{
public partial class App : Application
Expand Down
16 changes: 15 additions & 1 deletion CefSharp.Wpf.Example/CefSharp.Wpf.Example.netcore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@
<SelfContained Condition="'$(Configuration)' == 'Debug'">false</SelfContained>
</PropertyGroup>

<PropertyGroup Condition="'False'">
<DefineConstants>$(DefineConstants);CEFSHARP_WPF_HWNDHOST</DefineConstants>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\CefSharp.Core\CefSharp.Core.netcore.csproj" />
<ProjectReference Include="..\CefSharp.Example\CefSharp.Example.netcore.csproj" />
<ProjectReference Include="..\CefSharp.Wpf\CefSharp.Wpf.netcore.csproj" />
<ProjectReference Include="..\CefSharp\CefSharp.netcore.csproj" />
<PackageReference Include="chromiumembeddedframework.runtime" Version="129.0.11" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
Expand All @@ -49,6 +51,18 @@
<PackageReference Include="MaterialDesignThemes" Version="4.8.0" />
</ItemGroup>

<Choose>
<When Condition="$(DefineConstants.Contains(CEFSHARP_WPF_HWNDHOST))">
<ItemGroup>
<ProjectReference Include="..\CefSharp.Wpf.HwndHost\CefSharp.Wpf.HwndHost\CefSharp.Wpf.HwndHost.csproj" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<ProjectReference Include="..\CefSharp.Wpf\CefSharp.Wpf.netcore.csproj" />
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<None Include="crash_reporter.cfg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down
1 change: 1 addition & 0 deletions CefSharp.Wpf.Example/ChangeParentWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

using System.Windows;
using CefSharp.Wpf.Example.Controls;

namespace CefSharp.Wpf.Example
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public Task<InteropBitmap> TakeScreenshot(Size screenshotSize, int? frameRate =

return screenshotTaskCompletionSource.Task;
}

#if ! CEFSHARP_WPF_HWNDHOST
protected override CefSharp.Structs.Rect GetViewRect()
{
if (isTakingScreenshot)
Expand Down Expand Up @@ -161,7 +161,7 @@ protected override void OnPaint(bool isPopup, Structs.Rect dirtyRect, IntPtr buf
base.OnPaint(isPopup, dirtyRect, buffer, width, height);
}
}

#endif
private void TakeScreenshot()
{
var uiThreadTaskScheduler = TaskScheduler.FromCurrentSynchronizationContext();
Expand Down
2 changes: 2 additions & 0 deletions CefSharp.Wpf.Example/Controls/NonReloadingTabControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
using System.Windows.Automation.Peers;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
#if ! CEFSHARP_WPF_HWNDHOST
using TabControlAutomationPeer = CefSharp.Wpf.Experimental.Accessibility.TabControlAutomationPeer;
#endif

namespace CefSharp.Wpf.Example.Controls
{
Expand Down
21 changes: 21 additions & 0 deletions CefSharp.Wpf.Example/Controls/SampleChromiumWebBrowser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
#if CEFSHARP_WPF_HWNDHOST
using CefSharp.Wpf.HwndHost;
#endif
namespace CefSharp.Wpf.Example.Controls
{
public class ChromiumWebBrowser :
#if CEFSHARP_WPF_HWNDHOST
CefSharp.Wpf.HwndHost.ChromiumWebBrowser
#else
CefSharp.Wpf.ChromiumWebBrowser
#endif
{
public ChromiumWebBrowser(string initialAddress) : base(initialAddress){ }
public ChromiumWebBrowser() { }
}
}
1 change: 1 addition & 0 deletions CefSharp.Wpf.Example/Handlers/DisplayHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

using CefSharp.Wpf.Example.Controls;
using CefSharp.Wpf.Example.Views;
using System;
using System.Windows;
Expand Down
1 change: 1 addition & 0 deletions CefSharp.Wpf.Example/Handlers/JsDialogHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

using System.Windows;
using CefSharp.Wpf.Example.Controls;

namespace CefSharp.Wpf.Example.Handlers
{
Expand Down
3 changes: 3 additions & 0 deletions CefSharp.Wpf.Example/Handlers/MenuHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

using System;
#if ! CEFSHARP_WPF_HWNDHOST
using CefSharp.Wpf.Handler;

namespace CefSharp.Wpf.Example.Handlers
Expand Down Expand Up @@ -46,3 +47,5 @@ protected override void ExecuteCommand(IBrowser browser, ContextMenuExecuteModel
}
}
}

#endif
6 changes: 3 additions & 3 deletions CefSharp.Wpf.Example/JavascriptCallbackMainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Window x:Class="CefSharp.Wpf.Example.JavascriptCallbackMainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wpf="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
xmlns:wpf="clr-namespace:CefSharp.Wpf.Example.Controls"
Title="JavascriptCallbackMainWindow" WindowState="Maximized">
<Grid>
<Grid.RowDefinitions>
Expand All @@ -12,10 +12,10 @@
</Grid.RowDefinitions>
<wpf:ChromiumWebBrowser Grid.Row="0"
x:Name="BrowserOne"
Address="custom://cefsharp/JavascriptCallbackTest.html" BorderBrush="Red" BorderThickness="1"/>
Address="custom://cefsharp/JavascriptCallbackTest.html" />
<wpf:ChromiumWebBrowser Grid.Row="1"
x:Name="BrowserTwo"
Address="test://cefsharp/JavascriptCallbackTest.html" BorderBrush="Red" BorderThickness="1"/>
Address="test://cefsharp/JavascriptCallbackTest.html"/>
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Center">
<Button Content="Execute Callback Immediately" Click="ExecuteCallbackImmediatelyClick" Margin="0, 0, 10, 0"/>
<Button Content="Execute Callback In 3 Seconds" Click="ExecuteCallbackInThreeSeconds"/>
Expand Down
5 changes: 4 additions & 1 deletion CefSharp.Wpf.Example/JavascriptCallbackMainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ public partial class JavascriptCallbackMainWindow : Window
public JavascriptCallbackMainWindow()
{
InitializeComponent();

#if ! CEFSHARP_WPF_HWNDHOST
BrowserTwo.BorderBrush = BrowserOne.BorderBrush = System.Windows.Media.Brushes.Red;
BrowserTwo.BorderThickness = BrowserOne.BorderThickness = new Thickness(1);
#endif
boundObjectOne = new JavascriptCallbackBoundObject(BrowserOne);
boundObjectTwo = new JavascriptCallbackBoundObject(BrowserTwo);

Expand Down
4 changes: 4 additions & 0 deletions CefSharp.Wpf.Example/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,12 @@ private void CustomCommandBinding(object sender, ExecutedRoutedEventArgs e)
}
else if (param == "ToggleAudioMute")
{
#if CEFSHARP_WPF_HWNDHOST
throw new NotImplementedException();
#else
var cmd = browserViewModel.WebBrowser.ToggleAudioMuteCommand;
cmd.Execute(null);
#endif
}
else if (param == "ClearHttpAuthCredentials")
{
Expand Down
2 changes: 1 addition & 1 deletion CefSharp.Wpf.Example/SimpleMainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Window x:Class="CefSharp.Wpf.Example.SimpleMainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wpf="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
xmlns:wpf="clr-namespace:CefSharp.Wpf.Example.Controls"
Title="SimpleMainWindow" WindowState="Maximized">
<Grid>
<Grid.RowDefinitions>
Expand Down
1 change: 1 addition & 0 deletions CefSharp.Wpf.Example/SpawnBrowsersWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using CefSharp.Wpf.Example.Controls;

namespace CefSharp.Wpf.Example
{
Expand Down
2 changes: 1 addition & 1 deletion CefSharp.Wpf.Example/StandardTabControlWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="CefSharp.Wpf.Example.StandardTabControlWindow"
xmlns:cefSharp="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
xmlns:cefSharp="clr-namespace:CefSharp.Wpf.Example.Controls"
Title="TabControl Test Window" Height="594" Width="651">
<Grid>
<TabControl ItemsSource="{Binding Tabs}">
Expand Down
1 change: 1 addition & 0 deletions CefSharp.Wpf.Example/StandardTabControlWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using CefSharp.Wpf.Example.Controls;

namespace CefSharp.Wpf.Example
{
Expand Down
2 changes: 1 addition & 1 deletion CefSharp.Wpf.Example/TouchKeyboardWin10MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Window x:Class="CefSharp.Wpf.Example.TouchKeyboardWin10MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wpf="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
xmlns:wpf="clr-namespace:CefSharp.Wpf.Example.Controls"
Title="SimpleMainWindow" WindowState="Maximized">
<Grid>
<Grid.RowDefinitions>
Expand Down
4 changes: 3 additions & 1 deletion CefSharp.Wpf.Example/TouchKeyboardWin10MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Windows;
using CefSharp.Enums;
using Microsoft.Windows.Input.TouchKeyboard;

#if ! CEFSHARP_WPF_HWNDHOST
namespace CefSharp.Wpf.Example
{
/// <summary>
Expand Down Expand Up @@ -56,3 +56,5 @@ private void BrowserVirtualKeyboardRequested(object sender, VirtualKeyboardReque
}
}
}

#endif
3 changes: 3 additions & 0 deletions CefSharp.Wpf.Example/ViewModels/BrowserTabViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
using System.Windows;
using System.Windows.Input;
using CefSharp.Example;
#if CEFSHARP_WPF_HWNDHOST
using CefSharp.Wpf.HwndHost;
#endif

namespace CefSharp.Wpf.Example.ViewModels
{
Expand Down
2 changes: 1 addition & 1 deletion CefSharp.Wpf.Example/Views/BrowserTabView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:cefSharp="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
xmlns:cefSharp="clr-namespace:CefSharp.Wpf.Example.Controls"
xmlns:local="clr-namespace:CefSharp.Wpf.Example.ViewModels"
xmlns:system="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
Expand Down
10 changes: 6 additions & 4 deletions CefSharp.Wpf.Example/Views/BrowserTabView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
using CefSharp.Fluent;
using CefSharp.Wpf.Example.Handlers;
using CefSharp.Wpf.Example.ViewModels;
#if ! CEFSHARP_WPF_HWNDHOST
using CefSharp.Wpf.Experimental;
using CefSharp.Wpf.Experimental.Accessibility;
#endif

namespace CefSharp.Wpf.Example.Views
{
Expand All @@ -31,9 +33,9 @@ public BrowserTabView()
InitializeComponent();

DataContextChanged += OnDataContextChanged;

#if ! CEFSHARP_WPF_HWNDHOST
browser.UsePopupMouseTransform();

#endif
//browser.BrowserSettings.BackgroundColor = Cef.ColorSetARGB(0, 255, 255, 255);

//Please remove the comments below to use the Experimental WpfImeKeyboardHandler.
Expand Down Expand Up @@ -182,7 +184,7 @@ public BrowserTabView()
}
}).Build();
*/

#if ! CEFSHARP_WPF_HWNDHOST
browser.MenuHandler = new MenuHandler(addDevtoolsMenuItems:true);

//Enable experimental Accessibility support
Expand All @@ -195,7 +197,7 @@ public BrowserTabView()
//browser.GetBrowserHost().SetAccessibilityState(CefState.Enabled);
}
};

#endif
browser.DownloadHandler = DownloadHandler
.Create()
.CanDownload((chromiumWebBrowser, browser, url, requestMethod) =>
Expand Down
1 change: 1 addition & 0 deletions CefSharp.Wpf.HwndHost
Submodule CefSharp.Wpf.HwndHost added at 2a0305
14 changes: 14 additions & 0 deletions CefSharp3.netcore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CefSharp.Core.netcore", "Ce
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CefSharp.Core.Runtime.RefAssembly.netcore", "CefSharp.Core.Runtime.RefAssembly\CefSharp.Core.Runtime.RefAssembly.netcore.csproj", "{A4AFD158-0B6F-4579-AE79-EC386C8BEA58}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CefSharp.Wpf.HwndHost", "..\CefSharp.Wpf.HwndHost\CefSharp.Wpf.HwndHost\CefSharp.Wpf.HwndHost.csproj", "{94AF2E6A-6508-451F-BF4A-56B9C0AB1993}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|arm64 = Debug|arm64
Expand Down Expand Up @@ -243,6 +245,18 @@ Global
{A4AFD158-0B6F-4579-AE79-EC386C8BEA58}.Release|x64.Build.0 = Release|Any CPU
{A4AFD158-0B6F-4579-AE79-EC386C8BEA58}.Release|x86.ActiveCfg = Release|Any CPU
{A4AFD158-0B6F-4579-AE79-EC386C8BEA58}.Release|x86.Build.0 = Release|Any CPU
{94AF2E6A-6508-451F-BF4A-56B9C0AB1993}.Debug|arm64.ActiveCfg = Debug|x64
{94AF2E6A-6508-451F-BF4A-56B9C0AB1993}.Debug|arm64.Build.0 = Debug|x64
{94AF2E6A-6508-451F-BF4A-56B9C0AB1993}.Debug|x64.ActiveCfg = Debug|x64
{94AF2E6A-6508-451F-BF4A-56B9C0AB1993}.Debug|x64.Build.0 = Debug|x64
{94AF2E6A-6508-451F-BF4A-56B9C0AB1993}.Debug|x86.ActiveCfg = Debug|x64
{94AF2E6A-6508-451F-BF4A-56B9C0AB1993}.Debug|x86.Build.0 = Debug|x64
{94AF2E6A-6508-451F-BF4A-56B9C0AB1993}.Release|arm64.ActiveCfg = Release|x64
{94AF2E6A-6508-451F-BF4A-56B9C0AB1993}.Release|arm64.Build.0 = Release|x64
{94AF2E6A-6508-451F-BF4A-56B9C0AB1993}.Release|x64.ActiveCfg = Release|x64
{94AF2E6A-6508-451F-BF4A-56B9C0AB1993}.Release|x64.Build.0 = Release|x64
{94AF2E6A-6508-451F-BF4A-56B9C0AB1993}.Release|x86.ActiveCfg = Release|x64
{94AF2E6A-6508-451F-BF4A-56B9C0AB1993}.Release|x86.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down