Skip to content

Commit 0d3016a

Browse files
authored
Merge pull request #266 from MicrosoftEdge/smoketest/1.0.3116-testing
WebView2Samples update for 1.0.3116-prerelease
2 parents 366dc06 + eff6bca commit 0d3016a

File tree

7 files changed

+286
-5
lines changed

7 files changed

+286
-5
lines changed

SampleApps/WebView2APISample/WebView2APISample.vcxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -496,13 +496,13 @@
496496
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
497497
<ImportGroup Label="ExtensionTargets">
498498
<Import Project="..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
499-
<Import Project="..\packages\Microsoft.Web.WebView2.1.0.3079-prerelease\build\native\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.3079-prerelease\build\native\Microsoft.Web.WebView2.targets')" />
499+
<Import Project="..\packages\Microsoft.Web.WebView2.1.0.3116-prerelease\build\native\Microsoft.Web.WebView2.targets" Condition="Exists('..\packages\Microsoft.Web.WebView2.1.0.3116-prerelease\build\native\Microsoft.Web.WebView2.targets')" />
500500
</ImportGroup>
501501
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
502502
<PropertyGroup>
503503
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
504504
</PropertyGroup>
505505
<Error Condition="!Exists('..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Windows.ImplementationLibrary.1.0.220201.1\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
506-
<Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.3079-prerelease\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.3079-prerelease\build\native\Microsoft.Web.WebView2.targets'))" />
506+
<Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.3116-prerelease\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.3116-prerelease\build\native\Microsoft.Web.WebView2.targets'))" />
507507
</Target>
508508
</Project>
Loading
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Microsoft.Web.WebView2" version="1.0.3079-prerelease" targetFramework="native" />
3+
<package id="Microsoft.Web.WebView2" version="1.0.3116-prerelease" targetFramework="native" />
44
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.220201.1" targetFramework="native" />
55
</packages>

SampleApps/WebView2WindowsFormsBrowser/WebView2WindowsFormsBrowser.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<PlatformTarget>AnyCPU</PlatformTarget>
2626
</PropertyGroup>
2727
<ItemGroup>
28-
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3079-prerelease" />
28+
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3116-prerelease" />
2929
</ItemGroup>
3030
<ItemGroup>
3131
<Folder Include="assets\" />

SampleApps/WebView2WpfBrowser/MainWindow.xaml

+24
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,17 @@ found in the LICENSE file.
112112
<CommandBinding Command="{x:Static local:MainWindow.FileExplorerCommand}" Executed="FileExplorerExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
113113
<CommandBinding Command="{x:Static local:MainWindow.ToggleScreenCaptureEnableCommand}" Executed="TogglScreenCaptureEnabledCmdExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
114114
<CommandBinding Command="{x:Static local:MainWindow.FileTypePolicyCommand}" Executed="FileTypePolicyExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
115+
<CommandBinding Command="{x:Static local:MainWindow.StartCommand}" Executed="StartExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
116+
<CommandBinding Command="{x:Static local:MainWindow.FindNextCommand}" Executed="FindNextExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
117+
<CommandBinding Command="{x:Static local:MainWindow.FindPreviousCommand}" Executed="FindPreviousExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
118+
<CommandBinding Command="{x:Static local:MainWindow.StopFindCommand}" Executed="StopFindExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
119+
<CommandBinding Command="{x:Static local:MainWindow.FindTermCommand}" Executed="ChangeFindTermExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
120+
<CommandBinding Command="{x:Static local:MainWindow.GetMatchCountCommand}" Executed="GetMatchCountExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
121+
<CommandBinding Command="{x:Static local:MainWindow.GetActiveMatchIndexCommand}" Executed="GetActiveMatchIndexExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
122+
<CommandBinding Command="{x:Static local:MainWindow.ToggleCaseSensitiveCommand}" Executed="ToggleCaseSensitiveExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
123+
<CommandBinding Command="{x:Static local:MainWindow.ToggleShouldHighlightAllMatchesCommand}" Executed="ToggleShouldHighlightAllMatchesExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
124+
<CommandBinding Command="{x:Static local:MainWindow.ToggleShouldMatchWordCommand}" Executed="ToggleShouldMatchWordExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
125+
<CommandBinding Command="{x:Static local:MainWindow.ToggleSuppressDefaultFindDialogCommand}" Executed="ToggleSuppressDefaultFindDialogExecuted" CanExecute="CoreWebView2RequiringCmdsCanExecute"/>
115126
</Window.CommandBindings>
116127
<DockPanel>
117128
<Menu DockPanel.Dock="Top">
@@ -251,6 +262,19 @@ found in the LICENSE file.
251262
<MenuItem Header="File-system explorer" Command="{x:Static local:MainWindow.FileExplorerCommand}"/>
252263
<MenuItem Header="Toggle Screen Capture" Command="{x:Static local:MainWindow.ToggleScreenCaptureEnableCommand}"/>
253264
<MenuItem Header="File Type Policy" Command="{x:Static local:MainWindow.FileTypePolicyCommand}"/>
265+
<MenuItem Header="Find on Page">
266+
<MenuItem Header="Start Find" Command="{x:Static local:MainWindow.StartCommand}"/>
267+
<MenuItem Header="Find Next" Command="{x:Static local:MainWindow.FindNextCommand}"/>
268+
<MenuItem Header="Find Previous" Command="{x:Static local:MainWindow.FindPreviousCommand}"/>
269+
<MenuItem Header="Stop Find" Command="{x:Static local:MainWindow.StopFindCommand}"/>
270+
<MenuItem Header="Find Term" Command="{x:Static local:MainWindow.FindTermCommand}"/>
271+
<MenuItem Header="Show Match Count" Command="{x:Static local:MainWindow.GetMatchCountCommand}"/>
272+
<MenuItem Header="Show Active Match Index" Command="{x:Static local:MainWindow.GetActiveMatchIndexCommand}"/>
273+
<MenuItem Header="Toggle Case Sensitive" Command="{x:Static local:MainWindow.ToggleCaseSensitiveCommand}"/>
274+
<MenuItem Header="Toggle Highlight All" Command="{x:Static local:MainWindow.ToggleShouldHighlightAllMatchesCommand}"/>
275+
<MenuItem Header="Toggle Match Word" Command="{x:Static local:MainWindow.ToggleShouldMatchWordCommand}"/>
276+
<MenuItem Header="Toggle Default Find Dialog" Command="{x:Static local:MainWindow.ToggleSuppressDefaultFindDialogCommand}"/>
277+
</MenuItem>
254278
</MenuItem>
255279
<MenuItem Header="_Audio">
256280
<MenuItem Header="Toggle Mute State" IsCheckable="True" IsChecked="False" Command="{x:Static local:MainWindow.ToggleMuteStateCommand}"/>

SampleApps/WebView2WpfBrowser/MainWindow.xaml.cs

+257
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,27 @@ public partial class MainWindow : Window
140140
public static RoutedCommand ChildFrameEventsCommand = new RoutedCommand();
141141
public static RoutedCommand RemoveChildFrameEventsCommand = new RoutedCommand();
142142

143+
public static RoutedCommand StartCommand = new RoutedCommand();
144+
145+
public static RoutedCommand FindNextCommand = new RoutedCommand();
146+
147+
public static RoutedCommand FindPreviousCommand = new RoutedCommand();
148+
149+
public static RoutedCommand StopFindCommand = new RoutedCommand();
150+
public static RoutedCommand FindTermCommand = new RoutedCommand();
151+
152+
public static RoutedCommand GetMatchCountCommand = new RoutedCommand();
153+
154+
public static RoutedCommand GetActiveMatchIndexCommand = new RoutedCommand();
155+
156+
public static RoutedCommand ToggleCaseSensitiveCommand = new RoutedCommand();
157+
158+
public static RoutedCommand ToggleShouldHighlightAllMatchesCommand = new RoutedCommand();
159+
160+
public static RoutedCommand ToggleShouldMatchWordCommand = new RoutedCommand();
161+
162+
public static RoutedCommand ToggleSuppressDefaultFindDialogCommand = new RoutedCommand();
163+
143164
#endregion commands
144165

145166
bool _isNavigating = false;
@@ -3931,5 +3952,241 @@ void HandleChildFrameNavigationCompleted(object sender, CoreWebView2NavigationCo
39313952
MessageBox.Show(this, "Id: " + Frame.FrameId + " NavigationCompleted", "Child frame Navigation Completed", MessageBoxButton.OK);
39323953
}
39333954
#endif
3955+
#if USE_WEBVIEW2_EXPERIMENTAL
3956+
3957+
private CoreWebView2FindOptions _findOptions;
3958+
private bool _findEventHandlersSet = false;
3959+
private string _lastSearchTerm = string.Empty;
3960+
#endif
3961+
void StartExecuted(object target, ExecutedRoutedEventArgs e)
3962+
{
3963+
#if USE_WEBVIEW2_EXPERIMENTAL
3964+
3965+
if (_iWebView2?.CoreWebView2 == null || _iWebView2.CoreWebView2.Find == null)
3966+
{
3967+
MessageBox.Show("Find API is unavailable.");
3968+
return;
3969+
}
3970+
3971+
var dialog = new TextInputDialog(
3972+
title: "Find on Page Term",
3973+
description: "Enter find term:",
3974+
defaultInput: "WebView2");
3975+
3976+
if (dialog.ShowDialog() == true)
3977+
{
3978+
_iWebView2.CoreWebView2.Find.Stop();
3979+
3980+
3981+
if (_findOptions == null)
3982+
{
3983+
_findOptions = CreateDefaultFindOptions();
3984+
}
3985+
3986+
_findOptions.FindTerm = dialog.Input.Text;
3987+
3988+
SetupFindEventHandlers();
3989+
3990+
_ = _iWebView2.CoreWebView2.Find.StartAsync(_findOptions);
3991+
}
3992+
#endif
3993+
}
3994+
3995+
void FindNextExecuted(object target, ExecutedRoutedEventArgs e)
3996+
{
3997+
#if USE_WEBVIEW2_EXPERIMENTAL
3998+
3999+
if (_iWebView2?.CoreWebView2?.Find == null) return;
4000+
_iWebView2.CoreWebView2.Find.FindNext();
4001+
#endif
4002+
}
4003+
4004+
void FindPreviousExecuted(object target, ExecutedRoutedEventArgs e)
4005+
{
4006+
#if USE_WEBVIEW2_EXPERIMENTAL
4007+
if (_iWebView2?.CoreWebView2?.Find == null) return;
4008+
_iWebView2.CoreWebView2.Find.FindPrevious();
4009+
#endif
4010+
}
4011+
4012+
void StopFindExecuted(object target, ExecutedRoutedEventArgs e)
4013+
{
4014+
#if USE_WEBVIEW2_EXPERIMENTAL
4015+
_iWebView2.CoreWebView2.Find.Stop();
4016+
#endif
4017+
}
4018+
#if USE_WEBVIEW2_EXPERIMENTAL
4019+
// Creating find options via environment
4020+
private CoreWebView2FindOptions CreateDefaultFindOptions()
4021+
{
4022+
var webviewEnv = _iWebView2.CoreWebView2.Environment;
4023+
if (webviewEnv == null) return null;
4024+
4025+
var findOptions = webviewEnv.CreateFindOptions();
4026+
findOptions.FindTerm = "WebView2";
4027+
findOptions.IsCaseSensitive = false;
4028+
findOptions.ShouldHighlightAllMatches = true;
4029+
findOptions.ShouldMatchWord = false;
4030+
findOptions.SuppressDefaultFindDialog = false;
4031+
return findOptions;
4032+
}
4033+
#endif
4034+
void ChangeFindTermExecuted(object target, ExecutedRoutedEventArgs e)
4035+
{
4036+
#if USE_WEBVIEW2_EXPERIMENTAL
4037+
4038+
// Make sure the WebView2 and its Find interface are available
4039+
if (_iWebView2?.CoreWebView2 == null || _iWebView2.CoreWebView2.Find == null)
4040+
{
4041+
MessageBox.Show("Find API is unavailable or not yet initialized.");
4042+
return;
4043+
}
4044+
4045+
// If we haven’t created _findOptions yet, do it now
4046+
if (_findOptions == null)
4047+
{
4048+
_findOptions = CreateDefaultFindOptions();
4049+
}
4050+
4051+
// Prompt the user for a new find term
4052+
var dialog = new TextInputDialog(
4053+
title: "Change Find on Page Term",
4054+
description: "Enter new find term:",
4055+
defaultInput: _findOptions.FindTerm // show the current term if you like
4056+
);
4057+
4058+
// If user clicks OK, update the find term
4059+
if (dialog.ShowDialog() == true)
4060+
{
4061+
_findOptions.FindTerm = dialog.Input.Text;
4062+
_lastSearchTerm = _findOptions.FindTerm; // track if desired
4063+
4064+
// We do *not* start the find here; that’s done in StartExecuted.
4065+
MessageBox.Show($"Find term changed to: {_findOptions.FindTerm}", "Find on Page");
4066+
}
4067+
#endif
4068+
}
4069+
4070+
void GetMatchCountExecuted(object target, ExecutedRoutedEventArgs e)
4071+
{
4072+
#if USE_WEBVIEW2_EXPERIMENTAL
4073+
4074+
if (_iWebView2?.CoreWebView2?.Find == null) return;
4075+
4076+
int matchCount = _iWebView2.CoreWebView2.Find.MatchCount;
4077+
MessageBox.Show($"Match Count: {matchCount}", "Find Operation", MessageBoxButton.OK);
4078+
#endif
4079+
4080+
}
4081+
4082+
void GetActiveMatchIndexExecuted(object target, ExecutedRoutedEventArgs e)
4083+
{
4084+
#if USE_WEBVIEW2_EXPERIMENTAL
4085+
4086+
if (_iWebView2?.CoreWebView2?.Find == null) return;
4087+
4088+
int activeIndex = _iWebView2.CoreWebView2.Find.ActiveMatchIndex;
4089+
MessageBox.Show($"Active Match Index: {activeIndex}", "Find Operation", MessageBoxButton.OK);
4090+
#endif
4091+
4092+
}
4093+
4094+
void ToggleCaseSensitiveExecuted(object target, ExecutedRoutedEventArgs e)
4095+
{
4096+
#if USE_WEBVIEW2_EXPERIMENTAL
4097+
4098+
ToggleFindOptionAndRestart(
4099+
() => _findOptions.IsCaseSensitive,
4100+
val => _findOptions.IsCaseSensitive = val);
4101+
#endif
4102+
4103+
}
4104+
4105+
void ToggleShouldHighlightAllMatchesExecuted(object target, ExecutedRoutedEventArgs e)
4106+
{
4107+
#if USE_WEBVIEW2_EXPERIMENTAL
4108+
4109+
ToggleFindOptionAndRestart(
4110+
() => _findOptions.ShouldHighlightAllMatches,
4111+
val => _findOptions.ShouldHighlightAllMatches = val);
4112+
#endif
4113+
4114+
}
4115+
4116+
void ToggleShouldMatchWordExecuted(object target, ExecutedRoutedEventArgs e)
4117+
{
4118+
#if USE_WEBVIEW2_EXPERIMENTAL
4119+
4120+
ToggleFindOptionAndRestart(
4121+
() => _findOptions.ShouldMatchWord,
4122+
val => _findOptions.ShouldMatchWord = val);
4123+
#endif
4124+
4125+
}
4126+
4127+
void ToggleSuppressDefaultFindDialogExecuted(object target, ExecutedRoutedEventArgs e)
4128+
{
4129+
#if USE_WEBVIEW2_EXPERIMENTAL
4130+
4131+
ToggleFindOptionAndRestart(
4132+
() => _findOptions.SuppressDefaultFindDialog,
4133+
val => _findOptions.SuppressDefaultFindDialog = val);
4134+
#endif
4135+
4136+
}
4137+
#if USE_WEBVIEW2_EXPERIMENTAL
4138+
4139+
private async void ToggleFindOptionAndRestart(Func<bool> optionGetter, Action<bool> optionSetter)
4140+
{
4141+
if (_iWebView2?.CoreWebView2?.Find == null)
4142+
return;
4143+
4144+
_iWebView2.CoreWebView2.Find.Stop();
4145+
4146+
4147+
if (_findOptions == null)
4148+
{
4149+
_findOptions = CreateDefaultFindOptions();
4150+
}
4151+
4152+
bool currentVal = optionGetter();
4153+
optionSetter(!currentVal);
4154+
4155+
await _iWebView2.CoreWebView2.Find.StartAsync(_findOptions);
4156+
}
4157+
4158+
private void SetupFindEventHandlers()
4159+
{
4160+
if (_findEventHandlersSet) return; // Only attach once
4161+
var findObject = _iWebView2.CoreWebView2.Find;
4162+
findObject.MatchCountChanged += FindObject_MatchCountChanged;
4163+
findObject.ActiveMatchIndexChanged += FindObject_ActiveMatchIndexChanged;
4164+
_findEventHandlersSet = true;
4165+
}
4166+
4167+
private void RemoveFindEventHandlers()
4168+
{
4169+
if (!_findEventHandlersSet) return;
4170+
var findObject = _iWebView2.CoreWebView2.Find;
4171+
findObject.MatchCountChanged -= FindObject_MatchCountChanged;
4172+
findObject.ActiveMatchIndexChanged -= FindObject_ActiveMatchIndexChanged;
4173+
_findEventHandlersSet = false;
4174+
}
4175+
4176+
private void FindObject_MatchCountChanged(object sender, object e)
4177+
{
4178+
var findObject = _iWebView2.CoreWebView2.Find;
4179+
int matchCount = findObject.MatchCount;
4180+
Debug.WriteLine($"[FindOnPage] MatchCountChanged -> {matchCount}");
4181+
}
4182+
4183+
private void FindObject_ActiveMatchIndexChanged(object sender, object e)
4184+
{
4185+
var findObject = _iWebView2.CoreWebView2.Find;
4186+
int activeIndex = findObject.ActiveMatchIndex;
4187+
Debug.WriteLine($"[FindOnPage] ActiveMatchIndexChanged -> {activeIndex}");
4188+
}
4189+
#endif
4190+
39344191
}
39354192
}

SampleApps/WebView2WpfBrowser/WebView2WpfBrowser.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
</Content>
6262
</ItemGroup>
6363
<ItemGroup>
64-
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3079-prerelease" />
64+
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.3116-prerelease" />
6565
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
6666
</ItemGroup>
6767
</Project>

0 commit comments

Comments
 (0)