Merge pull request #1616 from deepak1556/webview_fullscreen_patch
webContents: override fullscreen notification apis for webview
This commit is contained in:
commit
fd41f1e8bc
11 changed files with 114 additions and 3 deletions
|
@ -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(),
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -20,6 +20,8 @@ supportedWebViewEvents = [
|
|||
'destroyed'
|
||||
'page-title-set'
|
||||
'page-favicon-updated'
|
||||
'enter-html-full-screen'
|
||||
'leave-html-full-screen'
|
||||
]
|
||||
|
||||
nextInstanceId = 0
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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_;
|
||||
|
|
|
@ -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() {}
|
||||
|
|
|
@ -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]?
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue