Introducing a will-enter-full-screen event that's cancellable

This commit is contained in:
Heilig Benedek 2016-02-09 01:17:05 +01:00
parent d5bdb17144
commit a8ae14e94f
7 changed files with 36 additions and 8 deletions

View file

@ -219,6 +219,10 @@ void Window::OnWindowMoved() {
Emit("moved"); Emit("moved");
} }
void Window::OnWindowWillEnterFullScreen(bool* prevent_default) {
*prevent_default = Emit("will-enter-full-screen");
}
void Window::OnWindowEnterFullScreen() { void Window::OnWindowEnterFullScreen() {
Emit("enter-full-screen"); Emit("enter-full-screen");
} }

View file

@ -67,6 +67,7 @@ class Window : public mate::TrackableObject<Window>,
void OnWindowMoved() override; void OnWindowMoved() override;
void OnWindowScrollTouchBegin() override; void OnWindowScrollTouchBegin() override;
void OnWindowScrollTouchEnd() override; void OnWindowScrollTouchEnd() override;
void OnWindowWillEnterFullScreen(bool* prevent_default) override;
void OnWindowEnterFullScreen() override; void OnWindowEnterFullScreen() override;
void OnWindowLeaveFullScreen() override; void OnWindowLeaveFullScreen() override;
void OnWindowEnterHtmlFullScreen() override; void OnWindowEnterHtmlFullScreen() override;

View file

@ -445,6 +445,13 @@ void NativeWindow::NotifyWindowMoved() {
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowMoved()); FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowMoved());
} }
bool NativeWindow::RequestEnterFullScreen() {
bool prevent_default = false;
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
OnWindowWillEnterFullScreen(&prevent_default));
return prevent_default;
}
void NativeWindow::NotifyWindowEnterFullScreen() { void NativeWindow::NotifyWindowEnterFullScreen() {
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
OnWindowEnterFullScreen()); OnWindowEnterFullScreen());

View file

@ -197,6 +197,9 @@ class NativeWindow : public base::SupportsUserData,
// Requests the WebContents to close, can be cancelled by the page. // Requests the WebContents to close, can be cancelled by the page.
virtual void RequestToClosePage(); virtual void RequestToClosePage();
// Request the WebContents to go fullscreen, can be cancelled by the page.
virtual bool RequestEnterFullScreen();
// Methods called by the WebContents. // Methods called by the WebContents.
virtual void CloseContents(content::WebContents* source); virtual void CloseContents(content::WebContents* source);
virtual void RendererUnresponsive(content::WebContents* source); virtual void RendererUnresponsive(content::WebContents* source);

View file

@ -602,6 +602,9 @@ void NativeWindowMac::SetFullScreen(bool fullscreen) {
if (fullscreen == IsFullscreen()) if (fullscreen == IsFullscreen())
return; return;
if (fullscreen && shell_->RequestEnterFullScreen())
return;
if (!base::mac::IsOSLionOrLater()) { if (!base::mac::IsOSLionOrLater()) {
LOG(ERROR) << "Fullscreen mode is only supported above Lion"; LOG(ERROR) << "Fullscreen mode is only supported above Lion";
return; return;

View file

@ -52,6 +52,7 @@ class NativeWindowObserver {
virtual void OnWindowMoved() {} virtual void OnWindowMoved() {}
virtual void OnWindowScrollTouchBegin() {} virtual void OnWindowScrollTouchBegin() {}
virtual void OnWindowScrollTouchEnd() {} virtual void OnWindowScrollTouchEnd() {}
virtual void OnWindowWillEnterFullScreen(bool* prevent_default) {}
virtual void OnWindowEnterFullScreen() {} virtual void OnWindowEnterFullScreen() {}
virtual void OnWindowLeaveFullScreen() {} virtual void OnWindowLeaveFullScreen() {}
virtual void OnWindowEnterHtmlFullScreen() {} virtual void OnWindowEnterHtmlFullScreen() {}

View file

@ -347,24 +347,33 @@ bool NativeWindowViews::IsMinimized() {
} }
void NativeWindowViews::SetFullScreen(bool fullscreen) { void NativeWindowViews::SetFullScreen(bool fullscreen) {
bool prevent_default = false;
if (fullscreen)
prevent_default = RequestEnterFullScreen();
#if defined(OS_WIN) #if defined(OS_WIN)
// There is no native fullscreen state on Windows. // There is no native fullscreen state on Windows.
if (fullscreen) { if (fullscreen) {
if (!prevent_default) {
last_window_state_ = ui::SHOW_STATE_FULLSCREEN; last_window_state_ = ui::SHOW_STATE_FULLSCREEN;
NotifyWindowEnterFullScreen(); NotifyWindowEnterFullScreen();
}
} else { } else {
last_window_state_ = ui::SHOW_STATE_NORMAL; last_window_state_ = ui::SHOW_STATE_NORMAL;
NotifyWindowLeaveFullScreen(); NotifyWindowLeaveFullScreen();
} }
// We set the new value after notifying, so we can handle the size event // We set the new value after notifying, so we can handle the size event
// correctly. // correctly.
if (!prevent_default)
window_->SetFullscreen(fullscreen); window_->SetFullscreen(fullscreen);
#else #else
if (!(fullscreen && prevent_default)) {
if (IsVisible()) if (IsVisible())
window_->SetFullscreen(fullscreen); window_->SetFullscreen(fullscreen);
else else
window_->native_widget_private()->ShowWithWindowState( window_->native_widget_private()->ShowWithWindowState(
ui::SHOW_STATE_FULLSCREEN); ui::SHOW_STATE_FULLSCREEN);
}
#endif #endif
} }