|
50 | 50 |
|
51 | 51 | namespace Ladybird { |
52 | 52 |
|
| 53 | +static constexpr auto AUDIO_STATE_BUTTON_POSITION = QTabBar::LeftSide; |
| 54 | +static constexpr auto TAB_CLOSE_BUTTON_POSITION = QTabBar::RightSide; |
| 55 | + |
53 | 56 | static QString reopen_recently_closed_action_text(Optional<WebView::RecentlyClosedEntry const&> entry) |
54 | 57 | { |
55 | 58 | if (entry.has_value() && entry->was_window) |
@@ -564,8 +567,7 @@ void BrowserWindow::initialize_tab(Tab* tab) |
564 | 567 | return new_tab.view().handle(); |
565 | 568 | }; |
566 | 569 |
|
567 | | - m_tabs_container->set_tab_icon(m_tabs_container->index_of(tab), tab->tab_icon()); |
568 | | - create_close_button_for_tab(tab); |
| 570 | + initialize_tab_buttons(tab); |
569 | 571 | } |
570 | 572 |
|
571 | 573 | void BrowserWindow::uninitialize_tab(Tab* tab) |
@@ -741,38 +743,32 @@ void BrowserWindow::tab_favicon_changed(int index, QIcon const& icon) |
741 | 743 | m_tabs_container->set_tab_icon(index, icon); |
742 | 744 | } |
743 | 745 |
|
744 | | -void BrowserWindow::create_close_button_for_tab(Tab* tab) |
| 746 | +void BrowserWindow::initialize_tab_buttons(Tab* tab) |
745 | 747 | { |
746 | 748 | auto index = m_tabs_container->index_of(tab); |
747 | 749 | m_tabs_container->set_tab_icon(index, tab->tab_icon()); |
748 | 750 |
|
749 | | - auto* button = new TabBarButton(create_chrome_icon(ChromeIcon::Close, palette())); |
750 | | - button->setToolTip("Close Tab"); |
751 | | - |
752 | | - auto position = audio_button_position_for_tab(index) == QTabBar::LeftSide ? QTabBar::RightSide : QTabBar::LeftSide; |
| 751 | + auto* close_button = new TabBarButton(create_chrome_icon(ChromeIcon::Close, palette())); |
| 752 | + close_button->setToolTip("Close Tab"); |
753 | 753 |
|
754 | | - connect(button, &QPushButton::clicked, this, [this, tab]() { |
| 754 | + connect(close_button, &QPushButton::clicked, this, [this, tab]() { |
755 | 755 | auto index = m_tabs_container->index_of(tab); |
756 | 756 | request_to_close_tab(index); |
757 | 757 | }); |
758 | 758 |
|
759 | | - m_tabs_container->tab_bar()->setTabButton(index, position, button); |
| 759 | + m_tabs_container->tab_bar()->setTabButton(index, AUDIO_STATE_BUTTON_POSITION, nullptr); |
| 760 | + m_tabs_container->tab_bar()->setTabButton(index, TAB_CLOSE_BUTTON_POSITION, close_button); |
760 | 761 | } |
761 | 762 |
|
762 | 763 | void BrowserWindow::update_tab_close_button_icons() |
763 | 764 | { |
764 | | - auto update_button = [this](int index, QTabBar::ButtonPosition position) { |
765 | | - auto* button = m_tabs_container->tab_bar()->tabButton(index, position); |
| 765 | + for (int index = 0; index < m_tabs_container->count(); ++index) { |
| 766 | + auto* button = m_tabs_container->tab_bar()->tabButton(index, TAB_CLOSE_BUTTON_POSITION); |
766 | 767 | if (!button || button->objectName() != "LadybirdTabButton") |
767 | 768 | return; |
768 | 769 |
|
769 | 770 | if (auto* tab_bar_button = qobject_cast<TabBarButton*>(button)) |
770 | 771 | tab_bar_button->setIcon(create_chrome_icon(ChromeIcon::Close, palette())); |
771 | | - }; |
772 | | - |
773 | | - for (int index = 0; index < m_tabs_container->count(); ++index) { |
774 | | - update_button(index, QTabBar::LeftSide); |
775 | | - update_button(index, QTabBar::RightSide); |
776 | 772 | } |
777 | 773 | } |
778 | 774 |
|
@@ -853,36 +849,35 @@ bool BrowserWindow::start_window_move() |
853 | 849 | void BrowserWindow::tab_audio_play_state_changed(int index, Web::HTML::AudioPlayState play_state) |
854 | 850 | { |
855 | 851 | auto* tab = m_tabs_container->tab(index); |
856 | | - auto position = audio_button_position_for_tab(index); |
857 | 852 |
|
858 | 853 | switch (play_state) { |
859 | 854 | case Web::HTML::AudioPlayState::Paused: |
860 | 855 | if (tab->view().page_mute_state() == Web::HTML::MuteState::Unmuted) |
861 | | - m_tabs_container->tab_bar()->setTabButton(index, position, nullptr); |
| 856 | + m_tabs_container->tab_bar()->setTabButton(index, AUDIO_STATE_BUTTON_POSITION, nullptr); |
862 | 857 | break; |
863 | 858 |
|
864 | 859 | case Web::HTML::AudioPlayState::Playing: |
865 | 860 | auto* button = new TabBarButton(icon_for_page_mute_state(*tab)); |
866 | 861 | button->setToolTip(tool_tip_for_page_mute_state(*tab)); |
867 | 862 | button->setObjectName("LadybirdAudioState"); |
868 | 863 |
|
869 | | - connect(button, &QPushButton::clicked, this, [this, tab, position]() { |
| 864 | + connect(button, &QPushButton::clicked, this, [this, tab]() { |
870 | 865 | tab->view().toggle_page_mute_state(); |
871 | 866 | auto index = tab_index(tab); |
872 | 867 |
|
873 | 868 | switch (tab->view().audio_play_state()) { |
874 | 869 | case Web::HTML::AudioPlayState::Paused: |
875 | | - m_tabs_container->tab_bar()->setTabButton(index, position, nullptr); |
| 870 | + m_tabs_container->tab_bar()->setTabButton(index, AUDIO_STATE_BUTTON_POSITION, nullptr); |
876 | 871 | break; |
877 | 872 | case Web::HTML::AudioPlayState::Playing: |
878 | | - auto* button = m_tabs_container->tab_bar()->tabButton(index, position); |
| 873 | + auto* button = m_tabs_container->tab_bar()->tabButton(index, AUDIO_STATE_BUTTON_POSITION); |
879 | 874 | as<TabBarButton>(button)->setIcon(icon_for_page_mute_state(*tab)); |
880 | 875 | button->setToolTip(tool_tip_for_page_mute_state(*tab)); |
881 | 876 | break; |
882 | 877 | } |
883 | 878 | }); |
884 | 879 |
|
885 | | - m_tabs_container->tab_bar()->setTabButton(index, position, button); |
| 880 | + m_tabs_container->tab_bar()->setTabButton(index, AUDIO_STATE_BUTTON_POSITION, button); |
886 | 881 | break; |
887 | 882 | } |
888 | 883 | } |
@@ -911,16 +906,6 @@ QString BrowserWindow::tool_tip_for_page_mute_state(Tab& tab) const |
911 | 906 | VERIFY_NOT_REACHED(); |
912 | 907 | } |
913 | 908 |
|
914 | | -QTabBar::ButtonPosition BrowserWindow::audio_button_position_for_tab(int tab_index) const |
915 | | -{ |
916 | | - if (auto* button = m_tabs_container->tab_bar()->tabButton(tab_index, QTabBar::LeftSide)) { |
917 | | - if (button->objectName() != "LadybirdAudioState") |
918 | | - return QTabBar::RightSide; |
919 | | - } |
920 | | - |
921 | | - return QTabBar::LeftSide; |
922 | | -} |
923 | | - |
924 | 909 | void BrowserWindow::open_next_tab() |
925 | 910 | { |
926 | 911 | if (m_tabs_container->count() <= 1) |
|
0 commit comments