Skip to content

Truly independent web browser

UI/Qt: Update the tab mute state after the hub replies

Zaggy102443ae4c887299
diff --git a/UI/Qt/BrowserWindow.cpp b/UI/Qt/BrowserWindow.cpp
index 1791935219a..fb6c3e9fb00 100644
--- a/UI/Qt/BrowserWindow.cpp
+++ b/UI/Qt/BrowserWindow.cpp
@@ -952,7 +952,7 @@ void BrowserWindow::initialize_tab(Tab* tab)
QObject::connect(tab, &Tab::title_changed, this, &BrowserWindow::tab_title_changed);
QObject::connect(tab, &Tab::favicon_changed, this, &BrowserWindow::tab_favicon_changed);
- QObject::connect(tab, &Tab::playing_audio_indicator_changed, this, &BrowserWindow::tab_playing_audio_indicator_changed);
+ QObject::connect(tab, &Tab::audio_state_changed, this, &BrowserWindow::tab_audio_state_changed);
QObject::connect(tab, &Tab::microphone_in_use_changed, this, [this] {
m_tabs_container->tab_bar()->update_microphone_indicators();
});
@@ -1526,7 +1526,7 @@ void BrowserWindow::set_always_on_top(bool always_on_top)
handle->setFlags(flags);
}
-void BrowserWindow::tab_playing_audio_indicator_changed(int index)
+void BrowserWindow::tab_audio_state_changed(int index)
{
if (index < 0)
return;
@@ -1543,10 +1543,11 @@ void BrowserWindow::update_tab_audio_button(Tab& tab)
if (!tab.is_loaded() || (!shows_playing_audio && tab.view().page_mute_state() == Web::HTML::MuteState::Unmuted)) {
// The tab bar only hides the button it lets go of.
- if (auto* button = tab_bar->tabButton(index, AUDIO_STATE_BUTTON_POSITION))
+ if (auto* button = tab_bar->tabButton(index, AUDIO_STATE_BUTTON_POSITION)) {
button->deleteLater();
- tab_bar->setTabButton(index, AUDIO_STATE_BUTTON_POSITION, nullptr);
- m_tabs_container->update_tab_button_visibility();
+ tab_bar->setTabButton(index, AUDIO_STATE_BUTTON_POSITION, nullptr);
+ m_tabs_container->update_tab_button_visibility();
+ }
return;
}
@@ -1554,9 +1555,8 @@ void BrowserWindow::update_tab_audio_button(Tab& tab)
if (!button) {
button = new TabBarButton(icon_for_page_mute_state(tab), TabBarButton::Role::Audio);
button->setObjectName("LadybirdAudioState");
- connect(button, &QPushButton::clicked, this, [this, &tab]() {
+ connect(button, &QPushButton::clicked, this, [&tab]() {
tab.view().toggle_page_mute_state();
- update_tab_audio_button(tab);
});
tab_bar->setTabButton(index, AUDIO_STATE_BUTTON_POSITION, button);
m_tabs_container->update_tab_button_visibility();
diff --git a/UI/Qt/BrowserWindow.h b/UI/Qt/BrowserWindow.h
index d4c3f8df188..281ff3b9f3b 100644
--- a/UI/Qt/BrowserWindow.h
+++ b/UI/Qt/BrowserWindow.h
@@ -244,7 +244,7 @@ public:
public slots:
void tab_title_changed(int index, QString const&);
void tab_favicon_changed(int index, QIcon const& icon);
- void tab_playing_audio_indicator_changed(int index);
+ void tab_audio_state_changed(int index);
Tab& new_tab_from_url(URL::URL const&, Web::HTML::ActivateTab, TabLocation);
void open_new_tab();
void activate_tab(int index);
diff --git a/UI/Qt/RemoteView.h b/UI/Qt/RemoteView.h
index 5fa38fb8645..c3e3e1a7d2f 100644
--- a/UI/Qt/RemoteView.h
+++ b/UI/Qt/RemoteView.h
@@ -46,8 +46,10 @@ public:
void set_state(Hub::ViewState state)
{
- m_state = move(state);
+ auto previous_state = exchange(m_state, move(state));
update_view_actions();
+ if (on_state_change)
+ on_state_change(previous_state);
}
void set_initial_state(Hub::ViewState state) { set_state(move(state)); }
@@ -365,6 +367,7 @@ public:
decltype(Hub::View::on_request_permission) on_request_permission;
decltype(Hub::View::on_cancel_permission_prompt) on_cancel_permission_prompt;
decltype(Hub::View::on_tab_indicator_change) on_tab_indicator_change;
+ Function<void(Hub::ViewState const& previous_state)> on_state_change;
decltype(Hub::View::on_request_file_picker) on_request_file_picker;
decltype(Hub::View::on_request_select_dropdown) on_request_select_dropdown;
decltype(Hub::View::on_finish_handling_key_event) on_finish_handling_key_event;
diff --git a/UI/Qt/Tab.cpp b/UI/Qt/Tab.cpp
index fe7c9221a7f..028c95e18ee 100644
--- a/UI/Qt/Tab.cpp
+++ b/UI/Qt/Tab.cpp
@@ -585,10 +585,15 @@ void Tab::initialize(Optional<u64> hub_view_id)
m_permission_prompts.cancel(request);
};
+ view().on_state_change = [this](Hub::ViewState const& previous_state) {
+ if (previous_state.page_mute_state != view().page_mute_state())
+ emit audio_state_changed(tab_index());
+ };
+
view().on_tab_indicator_change = [this](WebView::TabIndicator indicator, bool visible) {
switch (indicator) {
case WebView::TabIndicator::PlayingAudio:
- emit playing_audio_indicator_changed(tab_index());
+ emit audio_state_changed(tab_index());
break;
case WebView::TabIndicator::UsingLocation:
m_location_edit->set_location_in_use(visible);
@@ -890,10 +895,8 @@ void Tab::create_tab_context_menu()
auto* mute_tab_action = new QAction("&Mute Tab", this);
QObject::connect(mute_tab_action, &QAction::triggered, this, [this]() {
- if (is_loaded()) {
+ if (is_loaded())
view().toggle_page_mute_state();
- m_window->update_tab_audio_button(*this);
- }
});
auto* move_to_new_window_action = new QAction("Move to New &Window", this);
diff --git a/UI/Qt/Tab.h b/UI/Qt/Tab.h
index c2b66448f57..68d2e6c19da 100644
--- a/UI/Qt/Tab.h
+++ b/UI/Qt/Tab.h
@@ -177,7 +177,7 @@ public slots:
signals:
void title_changed(int id, QString const&);
void favicon_changed(int id, QIcon const&);
- void playing_audio_indicator_changed(int id);
+ void audio_state_changed(int id);
void microphone_in_use_changed();
void loading_changed();
void performance_stats_changed();