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

[FileExplorerPreview] Move everything from WebBrowser to WebView2 #17588

Merged
merged 12 commits into from Apr 14, 2022

Conversation

stefansjfw
Copy link
Collaborator

@stefansjfw stefansjfw commented Apr 7, 2022

Summary of the Pull Request

FIXED: Why WIP? Same issue as with Monaco, can't test it properly because of all of the async stuff going on while initializing WebView environment. Looking into this...

What is this about:
OPEN QUESTIONS:

  1. Do we want context menu? EDIT: Context menu disabled

image

image

  1. WebView allows opening link in the Preview Pane. I guess we don't want that, I just need to find a way to disable it.
    @Aaron-Junker Do you know how to do this? EDIT: Links are now opened in default browser
    image

What is included in the PR:

How does someone test / validate:

  • Build installer
  • Confirm that all p preview and thumbnail handlers works correctly

Quality Checklist

Contributor License Agreement (CLA)

A CLA must be signed. If not, go over here and sign the CLA.

@stefansjfw stefansjfw changed the title [Draft] [FileExplorerPreview] Move MarkdownPreviewHandler from WebBrowser to WebView2 [WIP] [FileExplorerPreview] Move MarkdownPreviewHandler from WebBrowser to WebView2 Apr 7, 2022
@Aaron-Junker
Copy link
Collaborator

OPEN QUESTIONS:

  1. Do we want context menu?
image image

I think if we want one we should create our own because of elemts like back and forward and inspect which we don't want

  1. WebView allows opening link in the Preview Pane. I guess we don't want that, I just need to find a way to disable it.
    @Aaron-Junker Do you know how to do this?
    image

My suggestion would be to execute JavaScript from the C# code (https://docs.microsoft.com/en-us/microsoft-edge/webview2/how-to/javascript) which adds a <base target="_blank" /> tag. This should open the links in a new window.

Open links in default browser
@stefansjfw
Copy link
Collaborator Author

OPEN QUESTIONS:

  1. Do we want context menu?
image image

I think if we want one we should create our own because of elemts like back and forward and inspect which we don't want

  1. WebView allows opening link in the Preview Pane. I guess we don't want that, I just need to find a way to disable it.
    @Aaron-Junker Do you know how to do this?
    image

My suggestion would be to execute JavaScript from the C# code (https://docs.microsoft.com/en-us/microsoft-edge/webview2/how-to/javascript) which adds a <base target="_blank" /> tag. This should open the links in a new window.

I disabled context menu for now, as it didn't exist previously.
Also links are now opened in default browser.

@github-actions

This comment was marked as resolved.

@stefansjfw stefansjfw changed the title [WIP] [FileExplorerPreview] Move MarkdownPreviewHandler from WebBrowser to WebView2 [FileExplorerPreview] Move everything from WebBrowser to WebView2 Apr 13, 2022
@github-actions

This comment was marked as resolved.

@stefansjfw
Copy link
Collaborator Author

This should be fully ready for review now. Tests are fixed.
@Aaron-Junker Are willing to check what I did with tests and add tests for Monaco in the same fashion? (e.g. in MarkdownPreviewHandlerUnitTests)

@Aaron-Junker
Copy link
Collaborator

This should be fully ready for review now. Tests are fixed.
@Aaron-Junker Are willing to check what I did with tests and add tests for Monaco in the same fashion? (e.g. in MarkdownPreviewHandlerUnitTests)

Maybe I can do this this week(end). Do you want it in this PR?

@stefansjfw
Copy link
Collaborator Author

Maybe I can do this this week(end). Do you want it in this PR?

Great, thanks! If this doesn't get merged until then, then you can add it to this PR.

@stefansjfw stefansjfw force-pushed the stefan/markdown_preview_webview2 branch from 8333726 to 8e9f95c Compare April 13, 2022 13:52
@stefansjfw stefansjfw force-pushed the stefan/markdown_preview_webview2 branch from 8e9f95c to 2496696 Compare April 13, 2022 13:55
@jaimecbernardo
Copy link
Collaborator

This issue can be linked: #15764

Copy link
Collaborator

@jaimecbernardo jaimecbernardo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits.
I also see some of the tests have been removed. No longer needed or is there no equivalent call in WebView 2?

Do we need to add something more to the installer for this to work?

{
// We are not the appropriate size for caller. Resize now while
// respecting the aspect ratio.
float scale = Math.Min((float)cx / thumbnail.Width, (float)cx / thumbnail.Height);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a divide by 0 check here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added


while (markdownPreviewHandlerControl.Controls.Count == 0 && Environment.TickCount < beforeTick + TenSecondsInMilliseconds)
{
Application.DoEvents();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a little sleep here to not use 100% CPU would be good.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added sleeps everywhere

@jaimecbernardo
Copy link
Collaborator

Actually, #17527 is not fixed by this, my bad.

@stefansjfw
Copy link
Collaborator Author

Actually, #17527 is not fixed by this, my bad.

removed

@Aaron-Junker
Copy link
Collaborator

@stefansjfw When I do it. Is it ok to just commit against your branch?

Copy link
Collaborator

@jaimecbernardo jaimecbernardo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

@jaimecbernardo jaimecbernardo merged commit 88517bf into main Apr 14, 2022
@Aaron-Junker
Copy link
Collaborator

Ok I guess then I make my own PR.

@jaimecbernardo
Copy link
Collaborator

@stefansjfw When I do it. Is it ok to just commit against your branch?

@Aaron-Junker , let's make that a separate PR ;)
Thank you

@crutkas crutkas deleted the stefan/markdown_preview_webview2 branch April 20, 2022 18:45
@zakius
Copy link

zakius commented May 3, 2022

using Blink is a terrible idea due to text rendering and image scaling issues

image

image

take a look at this comparison, upper one is rendered by Blink and is barely readable while the lower one is rendered using the default preview and looks much better

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants