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");
}
void Window::OnWindowWillEnterFullScreen(bool* prevent_default) {
*prevent_default = Emit("will-enter-full-screen");
}
void Window::OnWindowEnterFullScreen() {
Emit("enter-full-screen");
}

View file

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

View file

@ -445,6 +445,13 @@ void NativeWindow::NotifyWindowMoved() {
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() {
FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
OnWindowEnterFullScreen());

View file

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

View file

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

View file

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

View file

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