-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12921 from unoplatform/mergify/bp/release/stable/…
…4.9/pr-12907 fix: Update `WebView` history properties on JS-based navigation (backport #12907)
- Loading branch information
Showing
9 changed files
with
148 additions
and
14 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...ITests.Shared/Microsoft_UI_Xaml_Controls/WebView2Tests/WebView2_NavigationProperties.xaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<Page | ||
x:Class="UITests.Microsoft_UI_Xaml_Controls.WebView2Tests.WebView2_NavigationProperties" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:local="using:UITests.Microsoft_UI_Xaml_Controls.WebView2Tests" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:controls="using:Microsoft.UI.Xaml.Controls" | ||
mc:Ignorable="d" | ||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> | ||
|
||
<StackPanel Spacing="8"> | ||
<controls:WebView2 x:Name="TestWebView" Width="300" Height="300" /> | ||
<TextBlock> | ||
<Run Text="Last history change:" /> | ||
<Run x:Name="LastHistoryChangeRun" Text="" /> | ||
</TextBlock> | ||
<CheckBox x:Name="CanGoBackCheckBox" /> | ||
<CheckBox x:Name="CanGoForwardCheckBox" /> | ||
<Button Click="GoBack_Click" Content="Go back" /> | ||
<Button Click="GoForward_Click" Content="Go forward" /> | ||
</StackPanel> | ||
</Page> |
57 changes: 57 additions & 0 deletions
57
...sts.Shared/Microsoft_UI_Xaml_Controls/WebView2Tests/WebView2_NavigationProperties.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.InteropServices.WindowsRuntime; | ||
using Windows.Foundation; | ||
using Windows.Foundation.Collections; | ||
using Windows.UI.Xaml; | ||
using Windows.UI.Xaml.Controls; | ||
using Windows.UI.Xaml.Controls.Primitives; | ||
using Windows.UI.Xaml.Data; | ||
using Windows.UI.Xaml.Input; | ||
using Windows.UI.Xaml.Media; | ||
using Windows.UI.Xaml.Navigation; | ||
using Microsoft.UI.Xaml.Controls; | ||
|
||
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 | ||
|
||
namespace UITests.Microsoft_UI_Xaml_Controls.WebView2Tests | ||
{ | ||
/// <summary> | ||
/// An empty page that can be used on its own or navigated to within a Frame. | ||
/// </summary> | ||
[Uno.UI.Samples.Controls.Sample("WebView")] | ||
public sealed partial class WebView2_NavigationProperties : Page | ||
{ | ||
public WebView2_NavigationProperties() | ||
{ | ||
this.InitializeComponent(); | ||
this.Loaded += OnLoaded; | ||
} | ||
|
||
private async void OnLoaded(object sender, RoutedEventArgs e) | ||
{ | ||
await TestWebView.EnsureCoreWebView2Async(); | ||
TestWebView.CoreWebView2.Navigate("https://nventive.com/en"); | ||
TestWebView.CoreWebView2.HistoryChanged += CoreWebView2_HistoryChanged; | ||
} | ||
|
||
private void CoreWebView2_HistoryChanged(Microsoft.Web.WebView2.Core.CoreWebView2 sender, object args) | ||
{ | ||
LastHistoryChangeRun.Text = DateTimeOffset.Now.TimeOfDay.ToString(); | ||
CanGoBackCheckBox.IsChecked = sender.CanGoBack; | ||
CanGoForwardCheckBox.IsChecked = sender.CanGoForward; | ||
} | ||
|
||
private void GoForward_Click(object sender, RoutedEventArgs e) | ||
{ | ||
TestWebView.GoForward(); | ||
} | ||
|
||
private void GoBack_Click(object sender, RoutedEventArgs e) | ||
{ | ||
TestWebView.GoBack(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
namespace Uno.UI.Xaml.Controls; | ||
using Windows.UI.Core; | ||
|
||
namespace Uno.UI.Xaml.Controls; | ||
|
||
internal interface IWebView | ||
{ | ||
bool SwitchSourceBeforeNavigating { get; } | ||
|
||
bool IsLoaded { get; } | ||
|
||
CoreDispatcher Dispatcher { get; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters