Skip to content
Draft
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 src/PeekF1/PeekF1/PeekF1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="16.9.31025.194" />
<PackageReference Include="Microsoft.Internal.VisualStudio.Shell.Interop.14.0.DesignTime" Version="16.9.31213.332" />
<PackageReference Include="Microsoft.VisualStudio.Shell.15.0" Version="16.9.31025.104" />
<PackageReference Include="Microsoft.Web.WebView2">
<Version>1.0.3537.50</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Reference Include="PresentationCore" />
Expand Down
3 changes: 3 additions & 0 deletions src/PeekF1/PeekF1Dev17/PeekF1Dev17.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Web.WebView2">
<Version>1.0.3537.50</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Reference Include="PresentationCore" />
Expand Down
70 changes: 42 additions & 28 deletions src/PeekF1/PeekF1Shared/Peek/F1PeekResultPresentation.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using Microsoft.VisualStudio.Language.Intellisense;
using Microsoft.VisualStudio.Language.Intellisense;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Threading;
using System;
using System.ComponentModel;
using System.IO;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
Expand Down Expand Up @@ -53,7 +54,7 @@ public IWpfTextView ContainingTextView
}
}

public System.Windows.Forms.WebBrowser Browser
public Microsoft.Web.WebView2.WinForms.WebView2 Browser
{
get
{
Expand Down Expand Up @@ -82,12 +83,22 @@ public System.Windows.UIElement Create(IPeekSession session, IPeekResultScrollSt
_control = new F1PeekPresentationControl();
_control.DataContext = this;

_browser = new System.Windows.Forms.WebBrowser();
_browser.Url = _helpUri;
_control.WinFormsHost.Child = _browser;

_browser.DocumentCompleted += Browser_DocumentCompleted;
_browser.Navigating += Browser_Navigating;
_browser = new Microsoft.Web.WebView2.WinForms.WebView2();
_control.WinFormsHost.Child = _browser;

_browser.NavigationCompleted += Browser_NavigationCompleted;
_browser.NavigationStarting += Browser_NavigationStarting;

ThreadHelper.JoinableTaskFactory.WithPriority(_control.Dispatcher, DispatcherPriority.Background).RunAsync(async () =>
{
await Task.Yield();

string userDataFolder = Path.Combine(Environment.GetEnvironmentVariable("TEMP"), "VS-PPT-Peek-WV2");
Microsoft.Web.WebView2.Core.CoreWebView2Environment environment = await Microsoft.Web.WebView2.Core.CoreWebView2Environment.CreateAsync(userDataFolder: userDataFolder);
await _browser.EnsureCoreWebView2Async(environment);
_browser.CoreWebView2.Settings.AreDevToolsEnabled = false;
_browser.Source = _helpUri;
});

return _control;
}
Expand Down Expand Up @@ -118,27 +129,33 @@ protected void RaisePropertyChanged(string propertyName)
}
}

private void Browser_DocumentCompleted(object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e)
private void Browser_NavigationCompleted(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationCompletedEventArgs e)
{
_browser.DocumentCompleted -= Browser_DocumentCompleted;
_browser.NavigationCompleted -= Browser_NavigationCompleted;

_control.ProgressBar.Visibility = Visibility.Collapsed;
Keyboard.Focus(_control.PresentationRoot);

_browser.Document.Focusing += Document_Focusing;
_browser.GotFocus += Browser_GotFocus;
}

private void Browser_Navigating(object sender, System.Windows.Forms.WebBrowserNavigatingEventArgs e)
private void Browser_NavigationStarting(object sender, Microsoft.Web.WebView2.Core.CoreWebView2NavigationStartingEventArgs e)
{
if (string.IsNullOrEmpty(e.Url.Fragment) && e.Url.Host != null && e.Url.Host.EndsWith("msdn.microsoft.com"))
UriBuilder uri = new UriBuilder(e.Uri);
if (uri.Host != null)
{
e.Cancel = true;

ThreadHelper.JoinableTaskFactory.RunAsync(async () =>
{
await Task.Yield();
_browser.Navigate(e.Url.AbsoluteUri + "#content");
});
bool isMsdn = uri.Host.EndsWith("msdn.microsoft.com");
if ((isMsdn && string.IsNullOrEmpty(uri.Fragment)) || (uri.Host.EndsWith("learn.microsoft.com") && uri.Fragment == "#content"))
{
e.Cancel = true;

ThreadHelper.JoinableTaskFactory.RunAsync(async () =>
{
await Task.Yield();
uri.Fragment = isMsdn ? "content" : "article-header";
_browser.Source = uri.Uri;
});
}
}
}

Expand All @@ -151,7 +168,7 @@ private void SendFocusToPeek()
}
}

private void Document_Focusing(object sender, System.Windows.Forms.HtmlElementEventArgs e)
private void Browser_GotFocus(object sender, EventArgs e)
{
SendFocusToPeek();
}
Expand Down Expand Up @@ -191,12 +208,9 @@ public void Dispose()
{
if (_browser != null)
{
_browser.DocumentCompleted -= Browser_DocumentCompleted;
_browser.Navigating -= Browser_Navigating;
if (_browser.Document != null)
{
_browser.Document.Focusing -= Document_Focusing;
}
_browser.NavigationCompleted -= Browser_NavigationCompleted;
_browser.NavigationStarting -= Browser_NavigationStarting;
_browser.GotFocus -= Browser_GotFocus;

_browser.Dispose();
}
Expand Down Expand Up @@ -230,7 +244,7 @@ public bool IsReadOnly

#pragma warning disable 0067
public event EventHandler IsReadOnlyChanged;
private System.Windows.Forms.WebBrowser _browser;
private Microsoft.Web.WebView2.WinForms.WebView2 _browser;
#pragma warning restore 0067

event EventHandler<RecreateContentEventArgs> IPeekResultPresentation.RecreateContent
Expand Down
2 changes: 1 addition & 1 deletion src/PeekF1/PeekF1Shared/Peek/F1PeekResultScrollState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public Uri BrowserUrl
{
if (_presentation.Browser != null)
{
return _presentation.Browser.Url;
return _presentation.Browser.Source;
}
return null;
}
Expand Down