Truly independent web browser
LibWebView+UI/Qt: Tell the tab that held full screen when it leaves
sideshowbarker676c4d901796
diff --git a/Libraries/LibWebView/ViewImplementation.cpp b/Libraries/LibWebView/ViewImplementation.cppindex 048d996dc43..900b2b29bad 100644--- a/Libraries/LibWebView/ViewImplementation.cpp+++ b/Libraries/LibWebView/ViewImplementation.cpp@@ -2777,6 +2777,14 @@ void ViewImplementation::exit_fullscreen()page().async_exit_fullscreen();}+// NB: Only the page whose fullscreen request is waiting acts on the refusal. The tab's other pages ignore it.+void ViewImplementation::deny_fullscreen_window()+{+ traversable().for_each_hosting_page([](WebContentPage& page) {+ page.async_deny_fullscreen_window();+ });+}+void ViewImplementation::set_is_fullscreen(Web::ViewportIsFullscreen is_fullscreen){if (m_is_fullscreen == is_fullscreen)diff --git a/Libraries/LibWebView/ViewImplementation.h b/Libraries/LibWebView/ViewImplementation.hindex 7957bd6a02b..a885f06fa95 100644--- a/Libraries/LibWebView/ViewImplementation.h+++ b/Libraries/LibWebView/ViewImplementation.h@@ -474,6 +474,7 @@ public:void run_javascript(String const&);void js_console_input(String const&);void exit_fullscreen();+ void deny_fullscreen_window();void set_is_fullscreen(Web::ViewportIsFullscreen is_fullscreen);Web::ViewportIsFullscreen is_fullscreen() const { return m_is_fullscreen; }diff --git a/UI/Qt/BrowserWindow.cpp b/UI/Qt/BrowserWindow.cppindex 6c92c7274ca..640f3d726de 100644--- a/UI/Qt/BrowserWindow.cpp+++ b/UI/Qt/BrowserWindow.cpp@@ -119,20 +119,29 @@ FullscreenMode::FullscreenMode(BrowserWindow* window, ExitFullscreenButton* exit});}-void FullscreenMode::exit(ExitInitiatedBy initiated_by)+void FullscreenMode::exit(ExitInitiatedBy initiated_by, Tab const* requesting_tab){- if (is_api_fullscreen()) {- qApp->removeEventFilter(this);- if (initiated_by == ExitInitiatedBy::UI && m_window->tab_index(m_fullscreen_tab) != -1) {- m_fullscreen_tab->view().exit_fullscreen();- }- emit on_exit_fullscreen();+ if (!is_api_fullscreen() || (requesting_tab && requesting_tab != m_fullscreen_tab))+ return;++ qApp->removeEventFilter(this);+ // NB: The tab is let go of first, so the window leaving full screen below doesn't end it a second time.+ auto* tab = exchange(m_fullscreen_tab, nullptr);+ // NB: The tab that went full screen is told it left, even when another tab is current by now.+ if (m_window->tab_index(tab) != -1) {+ if (initiated_by == ExitInitiatedBy::UI)+ tab->view().exit_fullscreen();+ tab->view().set_is_fullscreen(Web::ViewportIsFullscreen::No);}- m_fullscreen_tab = nullptr;+ emit on_exit_fullscreen();}void FullscreenMode::enter(Tab* tab){+ // NB: One tab holds fullscreen at a time, and the window's state is restored for it before the next one takes it.+ if (m_fullscreen_tab && m_fullscreen_tab != tab)+ exit(ExitInitiatedBy::UI);+qApp->installEventFilter(this);m_fullscreen_tab = tab;m_window->enter_fullscreen();@@ -144,6 +153,7 @@ void FullscreenMode::entered_fullscreen()// neither leaves a window the user made full screen.if (!m_fullscreen_tab || m_window->tab_index(m_fullscreen_tab) == -1)return;+ m_fullscreen_tab->view().set_is_fullscreen(Web::ViewportIsFullscreen::Yes);m_exit_button->set_host(m_fullscreen_tab->url().host().has_value() ? qstring_from_ak_string(m_fullscreen_tab->url().serialized_host()) : QString {});// Let button float in place for 3 times the time it takes to animate it in place.m_debounce.start(*this, button_animation_time() * 3);@@ -1901,10 +1911,10 @@ void BrowserWindow::changeEvent(QEvent* event)if (is_fullscreen && !was_fullscreen) {m_fullscreen_mode->entered_fullscreen();- if (m_fullscreen_mode->is_api_fullscreen())- view().set_is_fullscreen(Web::ViewportIsFullscreen::Yes);} else if (!is_fullscreen && was_fullscreen) {- view().set_is_fullscreen(Web::ViewportIsFullscreen::No);+ // NB: A window that leaves full screen without the page asking, such as from the window's own controls,+ // takes the page out of full screen too.+ m_fullscreen_mode->exit(FullscreenMode::ExitInitiatedBy::UI);}}QWidget::changeEvent(event);diff --git a/UI/Qt/BrowserWindow.h b/UI/Qt/BrowserWindow.hindex ab789a765df..bb38fd2dec2 100644--- a/UI/Qt/BrowserWindow.h+++ b/UI/Qt/BrowserWindow.h@@ -78,9 +78,11 @@ public:WebContent,};- void exit(ExitInitiatedBy);+ // A page asking to leave names its tab, so a tab that already lost fullscreen can't end another tab's.+ void exit(ExitInitiatedBy, Tab const* requesting_tab = nullptr);void enter(Tab* tab);- // Called after a window change event that has identifed the current window state to be fullscreen.+ // Called after a window change event that has identifed the current window state to be fullscreen. Tells the tab+ // that asked for fullscreen that it has it.void entered_fullscreen();bool is_api_fullscreen() const;signals:diff --git a/UI/Qt/Tab.cpp b/UI/Qt/Tab.cppindex b45462f8bbb..ad36ae5a1a0 100644--- a/UI/Qt/Tab.cpp+++ b/UI/Qt/Tab.cpp@@ -846,11 +846,16 @@ void Tab::initialize(Optional<WebView::CanonicalTraversable&> traversable)};view().on_fullscreen_window = [this]() {+ // NB: Only the tab on display goes full screen. A request from another tab came after the user moved on.+ if (m_window->current_tab() != this) {+ view().deny_fullscreen_window();+ return;+ }m_window->fullscreen_mode().enter(this);};view().on_exit_fullscreen_window = [this]() {- m_window->fullscreen_mode().exit(FullscreenMode::ExitInitiatedBy::WebContent);+ m_window->fullscreen_mode().exit(FullscreenMode::ExitInitiatedBy::WebContent, this);};view().on_screen_wake_lock_state_changed = [this](auto wake_lock_state) {