cefsharp / CefSharp

.NET (WPF and Windows Forms) bindings for the Chromium Embedded Framework
http://cefsharp.github.io/
Other
9.87k stars 2.92k forks source link

HTML5 video fullscreen #1629

Closed novastream closed 8 years ago

novastream commented 8 years ago

Hi, I'm using cefsharp for my latest project but have some trouble getting a html5 / flash video work in fullscreen.

Version 47.0.3 (Winform) via nuget OS Windows 8.1 x64 Architecture x86 Service twitch.tv (eg. https://player.twitch.tv/?channel=CHANNEL_NAME)

So, when I click the fullscreen button nothing happends. If I implement DisplayHandler class and perform a throw on the fullscreen change method the program will crash which indicates that the function is triggered.

Is there any guidelines how to place the cef component on the form like docking, allowing the form to be maximized etc?

novastream commented 8 years ago

Here's a little something I did, it's kind of working but is this the right approach?

public void OnFullscreenModeChange(IWebBrowser browserControl, IBrowser browser, bool fullscreen)
        {
            var control = (Control)browserControl;
            Form test = (Form)control.Parent;

            if (fullscreen == true)
            {                
                if (control.InvokeRequired)
                {
                    control.Invoke(new MethodInvoker(
                        delegate {
                            test.WindowState = FormWindowState.Maximized;
                            test.FormBorderStyle = FormBorderStyle.None;
                            test.TopMost = true;
                        }
                    ));

                }

            }
            else
            {
                if (control.InvokeRequired)
                {
                    control.Invoke(new MethodInvoker(
                        delegate
                        {
                            test.WindowState = FormWindowState.Normal;
                            test.FormBorderStyle = FormBorderStyle.Fixed3D;
                            test.TopMost = false;
                        }
                    ));

                }
            }
        }
amaitland commented 8 years ago

Firstly read https://github.com/cefsharp/CefSharp/blob/master/ISSUE_TEMPLATE.md Questions should be asked on Gitter.

Secondly, OnFullscreenModeChange is just a notification, it's up to you to implement, use whatever approach best suites your applications layout/design.

amaitland commented 8 years ago

See https://github.com/cefsharp/CefSharp/commit/7f1f1c5f214e10c77f3c47740e8ef9ac26830be9 for an example I wrote that demos one possible option.

novastream commented 8 years ago

Thanks amaitland =)

You could also use the following if FormWindowState.Maximized isn't covering the taskbar: fullScreenForm.Bounds = Screen.FromControl(fullScreenForm).Bounds

amaitland commented 8 years ago

You could also use the following if FormWindowState.Maximized isn't covering the taskbar:

In what scenario is that required?

novastream commented 8 years ago

This seems to be the scenario (just tested on Win 7 and Win 10)

if (fullscreen) { fullScreenForm.WindowState = FormWindowState.Maximized; } else { fullScreenForm.WindowState = FormWindowState.Normal; }

So if you do it like you did and dispose the form you shouldn't have this problem but if you decide to reuse the fullScreenForm you will notice the second time you try to go fullscreen the taskbar will be visible.

amaitland commented 8 years ago

So if you do it like you did and dispose the form you shouldn't have this problem but if you decide to reuse the fullScreenForm you will notice the second time you try to go fullscreen the taskbar will be visible.

My example is just for demo purposes, something I hacked together in 5mins. By all means contribute a more polished version :+1:

realandrewjose commented 6 years ago

@amaitland Can you help my open source web browser https://github.com/flameskyofficial/FlameSky by just doing one small thing. It is based on CefSharp. Can you please help me by making a pull request and enable full screen (such that Youtube fullscreen works). I really need help, please help me Alex.