diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index b0f0a95ed2f..734434aff1a 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -215,6 +215,36 @@ void WebContents::HandleKeyboardEvent( web_contents(), event); } +void WebContents::EnterFullscreenModeForTab(content::WebContents* source, + const GURL& origin) { + auto window = GetWindowFromGuest(source); + if (window) { + window->SetHtmlApiFullscreen(true); + window->NotifyWindowEnterHtmlFullScreen(); + source->GetRenderViewHost()->WasResized(); + Emit("enter-html-full-screen"); + } +} + +void WebContents::ExitFullscreenModeForTab(content::WebContents* source) { + auto window = GetWindowFromGuest(source); + if (window) { + window->SetHtmlApiFullscreen(false); + window->NotifyWindowLeaveHtmlFullScreen(); + source->GetRenderViewHost()->WasResized(); + Emit("leave-html-full-screen"); + } +} + +bool WebContents::IsFullscreenForTabOrPending( + const content::WebContents* source) const { + auto window = GetWindowFromGuest(source); + if (window) + return window->is_html_api_fullscreen(); + else + return false; +} + void WebContents::RenderViewDeleted(content::RenderViewHost* render_view_host) { Emit("render-view-deleted", render_view_host->GetProcess()->GetID(), diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index eb69d65bf9a..e1979a6dc5f 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -151,6 +151,11 @@ class WebContents : public mate::EventEmitter, void HandleKeyboardEvent( content::WebContents* source, const content::NativeWebKeyboardEvent& event) override; + void EnterFullscreenModeForTab(content::WebContents* source, + const GURL& origin) override; + void ExitFullscreenModeForTab(content::WebContents* source) override; + bool IsFullscreenForTabOrPending( + const content::WebContents* source) const override; // content::WebContentsObserver: void RenderViewDeleted(content::RenderViewHost*) override; diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index b71499d3699..252c8f92035 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -132,6 +132,14 @@ void Window::OnWindowLeaveFullScreen() { Emit("leave-full-screen"); } +void Window::OnWindowEnterHtmlFullScreen() { + Emit("enter-html-full-screen"); +} + +void Window::OnWindowLeaveHtmlFullScreen() { + Emit("leave-html-full-screen"); +} + void Window::OnRendererUnresponsive() { Emit("unresponsive"); } diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index d5c3ceedd2e..8aa1ed0988d 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -66,6 +66,8 @@ class Window : public mate::EventEmitter, void OnWindowRestore() override; void OnWindowEnterFullScreen() override; void OnWindowLeaveFullScreen() override; + void OnWindowEnterHtmlFullScreen() override; + void OnWindowLeaveHtmlFullScreen() override; void OnRendererUnresponsive() override; void OnRendererResponsive() override; void OnDevToolsFocus() override; diff --git a/atom/browser/lib/guest-view-manager.coffee b/atom/browser/lib/guest-view-manager.coffee index 9403466f27a..f0d2a89318d 100644 --- a/atom/browser/lib/guest-view-manager.coffee +++ b/atom/browser/lib/guest-view-manager.coffee @@ -20,6 +20,8 @@ supportedWebViewEvents = [ 'destroyed' 'page-title-set' 'page-favicon-updated' + 'enter-html-full-screen' + 'leave-html-full-screen' ] nextInstanceId = 0 diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 8bc2c4616fe..e937bbdfccf 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -99,6 +99,8 @@ NativeWindow::NativeWindow(content::WebContents* web_contents, is_closed_(false), node_integration_(true), has_dialog_attached_(false), + html_fullscreen_(false), + native_fullscreen_(false), zoom_factor_(1.0), weak_factory_(this), inspectable_web_contents_( @@ -476,6 +478,25 @@ void NativeWindow::OverrideWebkitPrefs(content::WebPreferences* prefs) { } } +void NativeWindow::SetHtmlApiFullscreen(bool enter_fullscreen) { + // Window is already in fullscreen mode, save the state. + if (enter_fullscreen && IsFullscreen()) { + native_fullscreen_ = true; + html_fullscreen_ = true; + return; + } + + // Exit html fullscreen state but not window's fullscreen mode. + if (!enter_fullscreen && native_fullscreen_) { + html_fullscreen_ = false; + return; + } + + SetFullScreen(enter_fullscreen); + html_fullscreen_ = enter_fullscreen; + native_fullscreen_ = false; +} + void NativeWindow::NotifyWindowClosed() { if (is_closed_) return; @@ -524,6 +545,16 @@ void NativeWindow::NotifyWindowLeaveFullScreen() { OnWindowLeaveFullScreen()); } +void NativeWindow::NotifyWindowEnterHtmlFullScreen() { + FOR_EACH_OBSERVER(NativeWindowObserver, observers_, + OnWindowEnterHtmlFullScreen()); +} + +void NativeWindow::NotifyWindowLeaveHtmlFullScreen() { + FOR_EACH_OBSERVER(NativeWindowObserver, observers_, + OnWindowLeaveHtmlFullScreen()); +} + bool NativeWindow::ShouldCreateWebContents( content::WebContents* web_contents, int route_id, @@ -698,16 +729,16 @@ void NativeWindow::RendererResponsive(content::WebContents* source) { void NativeWindow::EnterFullscreenModeForTab(content::WebContents* source, const GURL& origin) { - SetFullScreen(true); + SetHtmlApiFullscreen(true); } void NativeWindow::ExitFullscreenModeForTab(content::WebContents* source) { - SetFullScreen(false); + SetHtmlApiFullscreen(false); } bool NativeWindow::IsFullscreenForTabOrPending( const content::WebContents* source) const { - return IsFullscreen(); + return is_html_api_fullscreen(); } void NativeWindow::BeforeUnloadFired(const base::TimeTicks& proceed_time) { diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 39c58625ad2..b114ecf510b 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -195,6 +195,9 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, int child_process_id); void OverrideWebkitPrefs(content::WebPreferences* prefs); + // Set fullscreen mode triggered by html api. + void SetHtmlApiFullscreen(bool enter_fullscreen); + // Public API used by platform-dependent delegates and observers to send UI // related notifications. void NotifyWindowClosed(); @@ -206,6 +209,8 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, void NotifyWindowRestore(); void NotifyWindowEnterFullScreen(); void NotifyWindowLeaveFullScreen(); + void NotifyWindowEnterHtmlFullScreen(); + void NotifyWindowLeaveHtmlFullScreen(); void AddObserver(NativeWindowObserver* obs) { observers_.AddObserver(obs); @@ -217,6 +222,8 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, bool has_frame() const { return has_frame_; } + bool is_html_api_fullscreen() const { return html_fullscreen_; } + void set_has_dialog_attached(bool has_dialog_attached) { has_dialog_attached_ = has_dialog_attached; } @@ -343,6 +350,12 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, // There is a dialog that has been attached to window. bool has_dialog_attached_; + // Whether window is fullscreened by HTML5 api. + bool html_fullscreen_; + + // Whether window is fullscreened by window api. + bool native_fullscreen_; + // Closure that would be called when window is unresponsive when closing, // it should be cancelled when we can prove that the window is responsive. base::CancelableClosure window_unresposive_closure_; diff --git a/atom/browser/native_window_observer.h b/atom/browser/native_window_observer.h index aa582494673..8c09e832a82 100644 --- a/atom/browser/native_window_observer.h +++ b/atom/browser/native_window_observer.h @@ -49,6 +49,8 @@ class NativeWindowObserver { virtual void OnWindowRestore() {} virtual void OnWindowEnterFullScreen() {} virtual void OnWindowLeaveFullScreen() {} + virtual void OnWindowEnterHtmlFullScreen() {} + virtual void OnWindowLeaveHtmlFullScreen() {} // Called when devtools window gets focused. virtual void OnDevToolsFocus() {} diff --git a/atom/renderer/lib/web-view/guest-view-internal.coffee b/atom/renderer/lib/web-view/guest-view-internal.coffee index fb1b40d27e1..e856896ae61 100644 --- a/atom/renderer/lib/web-view/guest-view-internal.coffee +++ b/atom/renderer/lib/web-view/guest-view-internal.coffee @@ -22,6 +22,8 @@ WEB_VIEW_EVENTS = 'destroyed': [] 'page-title-set': ['title', 'explicitSet'] 'page-favicon-updated': ['favicons'] + 'enter-html-full-screen': [] + 'leave-html-full-screen': [] dispatchEvent = (webView, event, args...) -> throw new Error("Unkown event #{event}") unless WEB_VIEW_EVENTS[event]? diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 586f6b241aa..cc68f2008b9 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -179,6 +179,14 @@ Emitted when window enters full screen state. Emitted when window leaves full screen state. +### Event: 'enter-html-full-screen' + +Emitted when window enters full screen state triggered by html api. + +### Event: 'leave-html-full-screen' + +Emitted when window leaves full screen state triggered by html api. + ### Event: 'devtools-opened' Emitted when devtools is opened. diff --git a/docs/api/web-view-tag.md b/docs/api/web-view-tag.md index a9efb7f860d..a1a472a5f15 100644 --- a/docs/api/web-view-tag.md +++ b/docs/api/web-view-tag.md @@ -365,6 +365,14 @@ url. Fired when page receives favicon urls. +### enter-html-full-screen + +Fired when page enters fullscreen triggered by html api. + +### leave-html-full-screen + +Fired when page leaves fullscreen triggered by html api. + ### console-message * `level` Integer