Skip to content

Truly independent web browser

UI/Qt: Put the whole toolbar in the sidebar when asked to

Andreas Kling4e06bc2d4fb1
diff --git a/Libraries/LibWebView/URL.cpp b/Libraries/LibWebView/URL.cpp
index 00317d77102..39d7b9fcbe0 100644
--- a/Libraries/LibWebView/URL.cpp
+++ b/Libraries/LibWebView/URL.cpp
@@ -307,11 +307,8 @@ Vector<URL::URL> sanitize_urls(ReadonlySpan<ByteString> raw_urls)
return sanitized_urls;
}
-String url_for_display(URL::URL const& url)
+String authority_for_display(URL::URL const& url)
{
- if (!url.scheme().is_one_of("http"sv, "https"sv))
- return url.serialize();
-
StringBuilder builder;
if (!url.username().is_empty() || !url.password().is_empty()) {
@@ -331,6 +328,17 @@ String url_for_display(URL::URL const& url)
if (url.port().has_value())
builder.appendff(":{}", *url.port());
+ return MUST(builder.to_string());
+}
+
+String url_for_display(URL::URL const& url)
+{
+ if (!url.scheme().is_one_of("http"sv, "https"sv))
+ return url.serialize();
+
+ StringBuilder builder;
+ builder.append(authority_for_display(url));
+
auto path = url.serialize_path();
if (path != "/"sv || url.query().has_value() || url.fragment().has_value())
builder.append(path);
diff --git a/Libraries/LibWebView/URL.h b/Libraries/LibWebView/URL.h
index ff5fc3a4133..d8f68a95948 100644
--- a/Libraries/LibWebView/URL.h
+++ b/Libraries/LibWebView/URL.h
@@ -37,6 +37,8 @@ WEBVIEW_API bool location_looks_like_url(StringView, AppendTLD = AppendTLD::No);
WEBVIEW_API bool is_url_handled_internally(URL::URL const&);
WEBVIEW_API Optional<URL::URL> url_from_text(StringView);
WEBVIEW_API Vector<URL::URL> sanitize_urls(ReadonlySpan<ByteString> raw_urls);
+// The user info, host and port of an http(s) URL, without "www.". This is how url_for_display() starts.
+WEBVIEW_API String authority_for_display(URL::URL const&);
WEBVIEW_API String url_for_display(URL::URL const&);
struct URLParts {
diff --git a/UI/Qt/BrowserWindow.cpp b/UI/Qt/BrowserWindow.cpp
index 84a56ac0e38..b4362ab5ec7 100644
--- a/UI/Qt/BrowserWindow.cpp
+++ b/UI/Qt/BrowserWindow.cpp
@@ -634,7 +634,9 @@ void BrowserWindow::update_tabs_display()
m_tabs_container->set_vertical_tabs_enabled(settings.vertical_tabs_enabled);
m_tabs_container->set_vertical_tabs_expanded(settings.vertical_tabs_expanded);
m_tabs_container->set_vertical_tabs_expand_on_hover(settings.vertical_tabs_expand_on_hover);
- m_tabs_container->set_vertical_tabs_position(settings.vertical_tabs_position);
+ // NB: With everything in the sidebar, the sidebar is on the left, beside the traffic lights.
+ m_tabs_container->set_vertical_tabs_position(settings.everything_in_sidebar ? WebView::VerticalTabsPosition::Left : settings.vertical_tabs_position);
+ m_tabs_container->set_everything_in_sidebar(settings.everything_in_sidebar);
}
void BrowserWindow::rebuild_bookmarks_menu()
diff --git a/UI/Qt/ChromeStyle.cpp b/UI/Qt/ChromeStyle.cpp
index 1a983df7cce..5b8bc558686 100644
--- a/UI/Qt/ChromeStyle.cpp
+++ b/UI/Qt/ChromeStyle.cpp
@@ -285,7 +285,13 @@ QWidget#LadybirdToolbarContainer[verticalTabs="true"] {{
border-bottom-color: transparent;
}}
-QWidget#LadybirdNavigationToolbar QToolButton {{
+QWidget#LadybirdToolbarContainer[inSidebar="true"] {{
+ background: transparent;
+ border-bottom: 0;
+}}
+
+QWidget#LadybirdNavigationToolbar QToolButton,
+QWidget#LadybirdSidebarFooter QToolButton {{
color: {4};
background: transparent;
border: 0;
@@ -301,24 +307,29 @@ QWidget#LadybirdNavigationToolbar QToolButton#LadybirdAllTabsButton {{
min-height: 0;
}}
-QWidget#LadybirdNavigationToolbar QToolButton:hover {{
+QWidget#LadybirdNavigationToolbar QToolButton:hover,
+QWidget#LadybirdSidebarFooter QToolButton:hover {{
background: transparent;
border-color: transparent;
}}
QWidget#LadybirdNavigationToolbar QToolButton:pressed,
-QWidget#LadybirdNavigationToolbar QToolButton:checked {{
+QWidget#LadybirdNavigationToolbar QToolButton:checked,
+QWidget#LadybirdSidebarFooter QToolButton:pressed,
+QWidget#LadybirdSidebarFooter QToolButton:checked {{
background: transparent;
border-color: transparent;
}}
-QWidget#LadybirdNavigationToolbar QToolButton:disabled {{
+QWidget#LadybirdNavigationToolbar QToolButton:disabled,
+QWidget#LadybirdSidebarFooter QToolButton:disabled {{
color: {5};
background: transparent;
border-color: transparent;
}}
-QWidget#LadybirdNavigationToolbar QToolButton::menu-indicator {{
+QWidget#LadybirdNavigationToolbar QToolButton::menu-indicator,
+QWidget#LadybirdSidebarFooter QToolButton::menu-indicator {{
image: none;
}}
diff --git a/UI/Qt/LocationEdit.cpp b/UI/Qt/LocationEdit.cpp
index ef9dfaac27f..7c3f5fe3217 100644
--- a/UI/Qt/LocationEdit.cpp
+++ b/UI/Qt/LocationEdit.cpp
@@ -1227,7 +1227,7 @@ void LocationEdit::highlight_location()
scheme_and_subdomain = scheme_and_subdomain.substring_view(scheme_prefix_length);
if (scheme_and_subdomain.starts_with("www."sv, CaseSensitivity::CaseInsensitive))
scheme_and_subdomain = scheme_and_subdomain.substring_view(4);
- if (remainder == "/"sv)
+ if (remainder == "/"sv || m_shows_host_only)
remainder = {};
append_attributes(scheme_and_subdomain, url_parts->effective_tld_plus_one, remainder);
@@ -1393,9 +1393,24 @@ QString LocationEdit::serialized_url() const
QString LocationEdit::display_url() const
{
VERIFY(m_url.has_value());
+ if (m_shows_host_only && m_url->scheme().is_one_of("http"sv, "https"sv))
+ return qstring_from_ak_string(WebView::authority_for_display(*m_url));
return qstring_from_ak_string(WebView::url_for_display(*m_url));
}
+void LocationEdit::set_shows_host_only(bool shows_host_only)
+{
+ if (m_shows_host_only == shows_host_only)
+ return;
+ auto was_showing_display_url = m_url.has_value() && !hasFocus() && text() == display_url();
+ m_shows_host_only = shows_host_only;
+ if (was_showing_display_url) {
+ set_text_and_restart_editing(display_url());
+ setCursorPosition(0);
+ highlight_location();
+ }
+}
+
QString LocationEdit::current_query() const
{
if (m_omnibox.is_editing())
diff --git a/UI/Qt/LocationEdit.h b/UI/Qt/LocationEdit.h
index 5b28aaf4cc6..549a08fff8e 100644
--- a/UI/Qt/LocationEdit.h
+++ b/UI/Qt/LocationEdit.h
@@ -65,6 +65,8 @@ public:
void set_url(Optional<URL::URL>);
bool url_is_hidden() const { return m_url_is_hidden; }
void set_url_is_hidden(bool);
+ // While idle, a website's address shows only up to its host, as where the field is narrow, in the sidebar.
+ void set_shows_host_only(bool);
void show_autocomplete();
void park_editing_session();
bool has_parked_editing_session() const { return m_parked_editing_session.has_value(); }
@@ -146,6 +148,7 @@ private:
Optional<URL::URL> m_url;
bool m_url_is_hidden { false };
+ bool m_shows_host_only { false };
bool m_is_editing_location { false };
struct ParkedEditingSession {
diff --git a/UI/Qt/Popover.cpp b/UI/Qt/Popover.cpp
index f104e6993df..0418df34a41 100644
--- a/UI/Qt/Popover.cpp
+++ b/UI/Qt/Popover.cpp
@@ -500,6 +500,31 @@ void move_popover_below(Popover& popover, QWidget& anchor, PopoverAlignment alig
popover.set_anchor_point(QPoint(anchor_x, card_position.y()));
}
+void move_popover_above(Popover& popover, QWidget& anchor, PopoverAlignment alignment)
+{
+ auto rect = anchor.rect();
+ auto card_size = popover.size().shrunkBy(POPOVER_SHADOW_MARGINS);
+ auto anchor_top_left = anchor.mapToGlobal(rect.topLeft());
+ auto card_x = alignment == PopoverAlignment::Leading ? anchor_top_left.x() : anchor.mapToGlobal(rect.topRight()).x() - card_size.width();
+ auto card_position = QPoint(card_x, anchor_top_left.y() - POPOVER_ANCHOR_GAP - card_size.height());
+
+ if (auto* screen = QGuiApplication::screenAt(anchor_top_left)) {
+ auto available_geometry = screen->availableGeometry();
+ if (card_position.x() + card_size.width() > available_geometry.right())
+ card_position.setX(available_geometry.right() - card_size.width() + 1);
+ if (card_position.x() < available_geometry.left())
+ card_position.setX(available_geometry.left());
+ if (card_position.y() < available_geometry.top())
+ card_position.setY(available_geometry.top());
+ }
+
+ popover.move(card_position - QPoint(POPOVER_SHADOW_MARGINS.left(), POPOVER_SHADOW_MARGINS.top()));
+
+ // The popover grows out of the corner of its card nearest the anchor.
+ auto anchor_x = alignment == PopoverAlignment::Leading ? card_position.x() : card_position.x() + card_size.width();
+ popover.set_anchor_point(QPoint(anchor_x, card_position.y() + card_size.height()));
+}
+
// Cards that float over other content cast the same shadow as popovers, whether they are windows of their own or not.
void cast_popover_shadow(QWidget& card)
{
diff --git a/UI/Qt/Popover.h b/UI/Qt/Popover.h
index 714c561e97a..923ca092bbb 100644
--- a/UI/Qt/Popover.h
+++ b/UI/Qt/Popover.h
@@ -133,6 +133,8 @@ enum class PopoverAlignment : u8 {
};
// The popover hangs from the anchor's rect, or from the given part of it where the anchor draws less than all of it.
void move_popover_below(Popover&, QWidget& anchor, PopoverAlignment = PopoverAlignment::Trailing, Optional<QRect> anchor_rect = {});
+// The popover stands on the anchor, for an anchor near the bottom of the window.
+void move_popover_above(Popover&, QWidget& anchor, PopoverAlignment = PopoverAlignment::Leading);
void cast_popover_shadow(QWidget&);
// A surface that is a native view of its own, floating over the page, cannot draw a shadow outside itself. This gives it
diff --git a/UI/Qt/TabBar.cpp b/UI/Qt/TabBar.cpp
index 3e9d577933a..e2288968b67 100644
--- a/UI/Qt/TabBar.cpp
+++ b/UI/Qt/TabBar.cpp
@@ -142,6 +142,10 @@ static constexpr int TAB_CARD_SHAPE_TOP_INSET = 0;
static constexpr int TAB_CARD_SHAPE_BOTTOM_INSET = 1;
// The sidebar's tab bar leaves this much room above its first tab and below its last.
static constexpr int VERTICAL_TAB_BAR_END_ROOM = 2;
+// With everything in the sidebar, the toolbar's rows and footer keep this far from the sidebar's edges, like its tabs.
+static constexpr int SIDEBAR_CONTENT_INSET = 8;
+// The gap between the address field's row and the sidebar's tabs below it.
+static constexpr int SIDEBAR_TOOLBAR_TABS_GAP = 4;
// A horizontal tab's card holds its contents. It is inset from the tab on every side.
static constexpr qreal HORIZONTAL_TAB_CARD_SHAPE_HORIZONTAL_INSET = 3;
// NB: The card is as low in the tab as the selected tab's body is, so the contents of both share the strip's line.
@@ -3531,6 +3535,21 @@ void TabWidget::set_vertical_tabs_enabled(bool enabled)
rebuild_layout();
}
+void TabWidget::set_everything_in_sidebar(bool everything_in_sidebar)
+{
+ if (m_everything_in_sidebar == everything_in_sidebar)
+ return;
+ m_everything_in_sidebar = everything_in_sidebar;
+ rebuild_layout();
+}
+
+// With everything in the sidebar, the open sidebar holds the toolbar. The collapsed sidebar leaves it across the top of
+// the window, as without.
+bool TabWidget::toolbar_is_in_sidebar() const
+{
+ return m_everything_in_sidebar && m_vertical_tabs_enabled && m_vertical_tabs_expanded;
+}
+
void TabWidget::set_vertical_tabs_expanded(bool expanded)
{
if (m_vertical_tabs_collapse_pending && !expanded)
@@ -4030,7 +4049,7 @@ int TabWidget::vertical_tabs_layout_width() const
bool TabWidget::should_show_window_controls_in_tab_toolbar() const
{
- return m_window_controls_visible && m_tab_bar->tab_layout() != TabLayout::Horizontal && !vertical_tabs_hold_window_controls();
+ return m_window_controls_visible && m_tab_bar->tab_layout() != TabLayout::Horizontal && !vertical_tabs_hold_window_controls() && !toolbar_is_in_sidebar();
}
// The native window controls sit in the window's top left corner, so the open sidebar on the left holds them.
@@ -4106,6 +4125,7 @@ void TabWidget::rebuild_layout()
m_tab_bar->set_pinned_tabs_in_rows(m_vertical_tabs_hover_expanded && !m_vertical_tabs_expanded);
m_tab_bar->set_tab_layout(current_tab_layout());
update_toolbar_window_controls_visibility();
+ m_toolbar->set_arrangement(toolbar_is_in_sidebar() ? ToolbarArrangement::Sidebar : ToolbarArrangement::Row, SIDEBAR_CONTENT_INSET - vertical_tabs_side_margin(true));
if (m_tab_bar->tab_layout() != TabLayout::Horizontal) {
rebuild_layout_for_vertical_tabs();
@@ -4411,6 +4431,9 @@ void TabWidget::rebuild_layout_for_vertical_tabs()
top_row_layout->addStretch(1);
top_row_layout->addSpacing(SIDEBAR_TOGGLE_MINIMUM_GAP);
top_row_layout->addWidget(m_vertical_tabs_toggle_button, 0, Qt::AlignVCenter);
+ // Without a toolbar row, the window controls that aren't the system's own end the sidebar's top row.
+ if (!use_native_macos_window_controls() && toolbar_is_in_sidebar())
+ top_row_layout->addWidget(m_window_controls, 0, Qt::AlignTop);
}
} else {
// The collapsed rail holds only tabs. The Ladybird and all-tabs buttons and the sidebar's toggle move to the
@@ -4423,8 +4446,15 @@ void TabWidget::rebuild_layout_for_vertical_tabs()
m_ladybird_button->set_tile_vertical_offset(0);
m_ladybird_buttons->show();
m_vertical_tab_bar_column_layout->addLayout(top_row_layout);
- m_vertical_tabs_header_spacer = new QSpacerItem(0, vertical_tabs_header_spacing(), QSizePolicy::Fixed, QSizePolicy::Fixed);
- m_vertical_tab_bar_column_layout->addItem(m_vertical_tabs_header_spacer);
+ if (toolbar_is_in_sidebar()) {
+ // Below its top row, the sidebar holds the toolbar's navigation buttons and address field.
+ m_vertical_tab_bar_column_layout->addWidget(m_toolbar);
+ m_toolbar->setVisible(m_tab_bar_visible);
+ m_vertical_tab_bar_column_layout->addSpacing(SIDEBAR_TOOLBAR_TABS_GAP - VERTICAL_TAB_BAR_END_ROOM);
+ } else {
+ m_vertical_tabs_header_spacer = new QSpacerItem(0, vertical_tabs_header_spacing(), QSizePolicy::Fixed, QSizePolicy::Fixed);
+ m_vertical_tab_bar_column_layout->addItem(m_vertical_tabs_header_spacer);
+ }
} else {
delete top_row_layout;
}
@@ -4432,6 +4462,9 @@ void TabWidget::rebuild_layout_for_vertical_tabs()
m_vertical_tab_bar_column_layout->addWidget(m_tab_bar);
m_vertical_tab_bar_column_layout->addWidget(m_new_tab_button, 0, vertical_tabs_are_on_right() ? Qt::AlignRight : Qt::AlignLeft);
m_vertical_tab_bar_column_layout->addStretch(1);
+ // The toolbar's other buttons sit at the bottom of the sidebar that holds it.
+ if (m_vertical_tabs_expanded && toolbar_is_in_sidebar())
+ m_vertical_tab_bar_column_layout->addWidget(&m_toolbar->sidebar_footer());
}
// A divider runs along the sidebar's edge toward the page.
@@ -4481,6 +4514,19 @@ void TabWidget::update_vertical_tabs_column_margins()
// field. Instead, it is placed over a stand-in at the top of the page column.
void TabWidget::rebuild_page_column()
{
+ // NB: The open sidebar that holds the toolbar is a native view on macOS, which a widget lying over it cannot draw on,
+ // so the toolbar moves into the sidebar after all. It comes back here when the sidebar no longer holds it.
+ if (toolbar_is_in_sidebar()) {
+ m_toolbar_follows_page_column = false;
+ m_toolbar_placeholder->hide();
+ add_page_to_page_column();
+ return;
+ }
+ if (m_toolbar->parentWidget() != this) {
+ m_toolbar->setParent(this);
+ m_toolbar->setVisible(m_tab_bar_visible);
+ }
+
m_toolbar_follows_page_column = true;
m_toolbar_placeholder->setVisible(m_tab_bar_visible);
m_page_column_layout->addWidget(m_toolbar_placeholder);
@@ -4749,7 +4795,7 @@ void TabWidget::update_tab_chrome_visibility()
auto show_window_controls = m_window_controls_visible
&& m_tab_bar_visible
- && is_horizontal;
+ && (is_horizontal || (!use_native_macos_window_controls() && toolbar_is_in_sidebar()));
m_window_controls->setVisible(show_window_controls);
}
diff --git a/UI/Qt/TabBar.h b/UI/Qt/TabBar.h
index f98f3620d80..a195d4ad76c 100644
--- a/UI/Qt/TabBar.h
+++ b/UI/Qt/TabBar.h
@@ -329,6 +329,7 @@ public:
void set_window_controls_visible(bool);
void update_window_button_icons();
void set_vertical_tabs_enabled(bool);
+ void set_everything_in_sidebar(bool);
void set_vertical_tabs_expanded(bool);
void set_vertical_tabs_expand_on_hover(bool);
// How strongly the vertical tabs' titles show, which they don't for long once the sidebar starts to collapse.
@@ -369,6 +370,7 @@ private:
int vertical_tabs_layout_width() const;
bool should_show_window_controls_in_tab_toolbar() const;
bool vertical_tabs_hold_window_controls() const;
+ bool toolbar_is_in_sidebar() const;
int vertical_tabs_header_spacing() const;
int minimum_vertical_tabs_expanded_width() const;
@@ -453,6 +455,7 @@ private:
bool m_tab_bar_visible { true };
bool m_window_controls_visible { true };
bool m_vertical_tabs_enabled { false };
+ bool m_everything_in_sidebar { false };
bool m_vertical_tabs_expanded { true };
bool m_vertical_tabs_expand_on_hover { false };
WebView::VerticalTabsPosition m_vertical_tabs_position { WebView::VerticalTabsPosition::Left };
diff --git a/UI/Qt/WindowToolbar.cpp b/UI/Qt/WindowToolbar.cpp
index 81a655ff37b..7daf956921d 100644
--- a/UI/Qt/WindowToolbar.cpp
+++ b/UI/Qt/WindowToolbar.cpp
@@ -613,6 +613,12 @@ static constexpr int TOOLBAR_LOCATION_EDIT_MARGIN = 6;
// The address field's focus ring reaches 3 px past its edge. With the toolbar's spacing, this room also puts the
// downloads button 6 px after the field.
static constexpr int TOOLBAR_LOCATION_FOCUS_RING_ROOM = 4;
+// In the open sidebar, the navigation buttons have a row of their own, above the address field, and the toolbar's other
+// buttons sit in a footer at its bottom.
+static constexpr int SIDEBAR_NAVIGATION_ROW_HEIGHT = 32;
+static constexpr int SIDEBAR_FIELD_TOP_MARGIN = 4;
+static constexpr int SIDEBAR_FIELD_BOTTOM_MARGIN = 8;
+static constexpr int SIDEBAR_FOOTER_HEIGHT = 40;
// NB: Window controls run to the window's edge. Without them, the address field ends the toolbar, and the room for its
// focus ring takes the place of some of the toolbar's margin.
@@ -1038,10 +1044,6 @@ WindowToolbar::WindowToolbar(WebView::IsPrivate is_private, QWidget* parent)
// NB: The container draws the line under the toolbar along its bottom edge, below the toolbar's full height.
toolbar_container_layout->setContentsMargins(0, 0, 0, 1);
- auto* toolbar_layout = new QHBoxLayout(m_toolbar);
- toolbar_layout->setSpacing(TOOLBAR_SPACING);
- toolbar_layout->setContentsMargins(TOOLBAR_HORIZONTAL_MARGIN, 0, toolbar_right_margin(false), 0);
-
m_downloads_button = new DownloadsButton(m_toolbar);
QObject::connect(m_downloads_button, &QToolButton::clicked, this, [this] {
// NB: The button only stays checked while the list is open, which showing it sees to.
@@ -1103,6 +1105,7 @@ WindowToolbar::WindowToolbar(WebView::IsPrivate is_private, QWidget* parent)
}
auto* navigation_button_cluster = new QWidget(m_toolbar);
+ m_navigation_buttons = navigation_button_cluster;
navigation_button_cluster->setProperty(WINDOW_DRAG_REGION_PROPERTY, true);
auto* navigation_button_layout = new QHBoxLayout(navigation_button_cluster);
navigation_button_layout->setSpacing(TOOLBAR_SPACING);
@@ -1118,20 +1121,15 @@ WindowToolbar::WindowToolbar(WebView::IsPrivate is_private, QWidget* parent)
};
navigation_button_layout->addWidget(m_reload_button);
- auto* location_edit_container = new QWidget(m_toolbar);
- location_edit_container->setProperty(WINDOW_DRAG_REGION_PROPERTY, true);
- m_location_edit_layout = new QHBoxLayout(location_edit_container);
+ m_location_edit_container = new QWidget(m_toolbar);
+ m_location_edit_container->setProperty(WINDOW_DRAG_REGION_PROPERTY, true);
+ m_location_edit_layout = new QHBoxLayout(m_location_edit_container);
m_location_edit_layout->setSpacing(0);
- // NB: The field reaches the end of the toolbar, leaving room for its focus ring.
- m_location_edit_layout->setContentsMargins(TOOLBAR_LOCATION_EDIT_MARGIN, 0, TOOLBAR_LOCATION_FOCUS_RING_ROOM, 0);
m_performance_monitor = new PerformanceMonitorWidget(m_toolbar);
(void)WebView::TabPerformanceMonitor::the();
m_performance_monitor->setVisible(WebView::Application::settings().config_variable_as_bool(WebView::ConfigVariableID::ShowTabPerformanceMonitor));
- if constexpr (use_native_macos_window_controls())
- toolbar_layout->addWidget(m_window_controls, 0, Qt::AlignVCenter);
-
m_sidebar_slot = new QWidget(m_toolbar);
m_sidebar_slot->setProperty(WINDOW_DRAG_REGION_PROPERTY, true);
auto* sidebar_slot_layout = new QHBoxLayout(m_sidebar_slot);
@@ -1150,30 +1148,122 @@ WindowToolbar::WindowToolbar(WebView::IsPrivate is_private, QWidget* parent)
sidebar_slot_layout->addWidget(sidebar_slot_separator, 0, Qt::AlignVCenter);
sidebar_slot_layout->addSpacing(SIDEBAR_SLOT_SEPARATOR_MARGIN);
m_sidebar_slot->hide();
- toolbar_layout->addWidget(m_sidebar_slot, 0, Qt::AlignVCenter);
- toolbar_layout->addWidget(navigation_button_cluster, 0, Qt::AlignVCenter);
- toolbar_layout->addWidget(location_edit_container, 1);
+ m_sidebar_footer = new QWidget(this);
+ m_sidebar_footer->setObjectName("LadybirdSidebarFooter");
+ m_sidebar_footer->setProperty(WINDOW_DRAG_REGION_PROPERTY, true);
+ auto* sidebar_footer_layout = new QHBoxLayout(m_sidebar_footer);
+ sidebar_footer_layout->setContentsMargins(0, 0, 0, 0);
+ sidebar_footer_layout->setSpacing(TOOLBAR_SPACING);
+ sidebar_footer_layout->addStrut(SIDEBAR_FOOTER_HEIGHT);
+ sidebar_footer_layout->addStretch(1);
+ m_sidebar_footer->hide();
+
+ lay_out_as_row();
+ toolbar_container_layout->addWidget(m_toolbar);
+
+ recreate_icons();
+ update_chrome_style();
+ set_window_controls_visible(false);
+ update_feedback_button();
+ config_variable_changed(WebView::ConfigVariableID::ShowFeedbackButton);
+}
+
+WindowToolbar::~WindowToolbar() = default;
+
+void WindowToolbar::lay_out_as_row()
+{
+ auto* toolbar_layout = new QHBoxLayout(m_toolbar);
+ toolbar_layout->setSpacing(TOOLBAR_SPACING);
+ toolbar_layout->setContentsMargins(TOOLBAR_HORIZONTAL_MARGIN, 0, toolbar_right_margin(false), 0);
+
+ if constexpr (use_native_macos_window_controls())
+ toolbar_layout->addWidget(m_window_controls, 0, Qt::AlignVCenter);
+ toolbar_layout->addWidget(m_sidebar_slot, 0, Qt::AlignVCenter);
+ toolbar_layout->addWidget(m_navigation_buttons, 0, Qt::AlignVCenter);
+ toolbar_layout->addWidget(m_location_edit_container, 1);
toolbar_layout->addWidget(m_downloads_button, 0, Qt::AlignVCenter);
if (m_feedback_button)
toolbar_layout->addWidget(m_feedback_button, 0, Qt::AlignVCenter);
toolbar_layout->addWidget(m_performance_monitor, 0, Qt::AlignVCenter);
-
if constexpr (!use_native_macos_window_controls()) {
toolbar_layout->addWidget(m_window_controls_separator, 0, Qt::AlignVCenter);
toolbar_layout->addWidget(m_window_controls, 0, Qt::AlignVCenter);
}
- toolbar_container_layout->addWidget(m_toolbar);
+ // NB: The field reaches the end of the toolbar, leaving room for its focus ring.
+ m_location_edit_layout->setContentsMargins(TOOLBAR_LOCATION_EDIT_MARGIN, 0, TOOLBAR_LOCATION_FOCUS_RING_ROOM, 0);
+ // NB: The container draws the line under the toolbar along its bottom edge, below the toolbar's full height.
+ layout()->setContentsMargins(0, 0, 0, 1);
+}
- recreate_icons();
- update_chrome_style();
- set_window_controls_visible(false);
- update_feedback_button();
- config_variable_changed(WebView::ConfigVariableID::ShowFeedbackButton);
+// In the open sidebar, the navigation buttons get a row of their own, and the address field takes the sidebar's width
+// below them. The other buttons move to the footer at the sidebar's bottom.
+void WindowToolbar::lay_out_in_sidebar()
+{
+ auto* toolbar_layout = new QVBoxLayout(m_toolbar);
+ toolbar_layout->setSpacing(0);
+ toolbar_layout->setContentsMargins(0, 0, 0, 0);
+
+ auto* navigation_row = new QHBoxLayout;
+ navigation_row->setContentsMargins(m_sidebar_inset, 0, m_sidebar_inset, 0);
+ navigation_row->addStrut(SIDEBAR_NAVIGATION_ROW_HEIGHT);
+ navigation_row->addWidget(m_navigation_buttons, 0, Qt::AlignVCenter);
+ navigation_row->addStretch(1);
+ toolbar_layout->addLayout(navigation_row);
+
+ auto* field_row = new QHBoxLayout;
+ // NB: The field's container leaves room for its focus ring all around, which the row's margins make up for.
+ auto ring_room = TOOLBAR_LOCATION_FOCUS_RING_ROOM;
+ field_row->setContentsMargins(m_sidebar_inset - ring_room, SIDEBAR_FIELD_TOP_MARGIN - ring_room, m_sidebar_inset - ring_room, SIDEBAR_FIELD_BOTTOM_MARGIN - ring_room);
+ field_row->addWidget(m_location_edit_container, 1);
+ toolbar_layout->addLayout(field_row);
+ m_location_edit_layout->setContentsMargins(ring_room, ring_room, ring_room, ring_room);
+
+ // NB: What the sidebar has no room for stays hidden, as widgets left out of a layout would show where they last were.
+ m_sidebar_slot->hide();
+ m_window_controls->hide();
+ m_window_controls_separator->hide();
+
+ auto* footer_layout = static_cast<QBoxLayout*>(m_sidebar_footer->layout());
+ footer_layout->addWidget(m_downloads_button, 0, Qt::AlignVCenter);
+ if (m_feedback_button)
+ footer_layout->addWidget(m_feedback_button, 0, Qt::AlignVCenter);
+ footer_layout->addWidget(m_performance_monitor, 0, Qt::AlignVCenter);
+ footer_layout->setContentsMargins(m_sidebar_inset, 0, m_sidebar_inset, 0);
+
+ layout()->setContentsMargins(0, 0, 0, 0);
}
-WindowToolbar::~WindowToolbar() = default;
+void WindowToolbar::set_arrangement(ToolbarArrangement arrangement, int sidebar_inset)
+{
+ if (m_arrangement == arrangement && m_sidebar_inset == sidebar_inset)
+ return;
+ m_arrangement = arrangement;
+ m_sidebar_inset = sidebar_inset;
+
+ // NB: Deleting the layout leaves the widgets it held in place, ready for the next one.
+ delete m_toolbar->layout();
+ if (arrangement == ToolbarArrangement::Row) {
+ lay_out_as_row();
+ m_sidebar_footer->hide();
+ set_window_controls_visible(m_window_controls_visible);
+ } else {
+ lay_out_in_sidebar();
+ m_toolbar->setMinimumHeight(0);
+ m_toolbar->setMaximumHeight(QWIDGETSIZE_MAX);
+ m_sidebar_footer->show();
+ }
+
+ if (m_location_edit)
+ m_location_edit->set_shows_host_only(arrangement == ToolbarArrangement::Sidebar);
+
+ setProperty("inSidebar", arrangement == ToolbarArrangement::Sidebar);
+ style()->unpolish(this);
+ style()->polish(this);
+ updateGeometry();
+ update();
+}
int WindowToolbar::toolbar_height(bool)
{
@@ -1226,8 +1316,10 @@ void WindowToolbar::show_location_edit(LocationEdit* location_edit)
if (m_location_edit && m_location_edit != location_edit)
m_location_edit->hide();
m_location_edit = location_edit;
- if (location_edit)
+ if (location_edit) {
+ location_edit->set_shows_host_only(m_arrangement == ToolbarArrangement::Sidebar);
location_edit->show();
+ }
}
// A tab that leaves the window takes its address field along.
@@ -1289,6 +1381,11 @@ QToolButton* WindowToolbar::create_navigation_history_toolbar_button(QWidget& pa
void WindowToolbar::set_window_controls_visible(bool visible)
{
+ m_window_controls_visible = visible;
+ // NB: The sidebar has no room for the window controls, and its toolbar is as tall as its two rows.
+ if (m_arrangement == ToolbarArrangement::Sidebar)
+ return;
+
auto const has_native_window_controls = use_native_macos_window_controls() && visible;
auto const has_custom_window_controls = !use_native_macos_window_controls() && visible;
@@ -1317,6 +1414,8 @@ int WindowToolbar::lead_beside_collapsed_sidebar(QWidget const& ladybird_buttons
// While the sidebar opens or closes, the toolbar's contents keep clear of where the collapsed sidebar's buttons sit.
void WindowToolbar::set_leading_room(int room)
{
+ if (m_arrangement == ToolbarArrangement::Sidebar)
+ return;
auto margins = m_toolbar->layout()->contentsMargins();
if (margins.left() == TOOLBAR_HORIZONTAL_MARGIN + room)
return;
@@ -1397,7 +1496,10 @@ void WindowToolbar::update_chrome_style()
if (m_is_updating_chrome_style)
return;
m_is_updating_chrome_style = true;
- setStyleSheet(ChromeStyle::toolbar_container_style_sheet(Theme::chrome_palette(*this)));
+ auto style_sheet = ChromeStyle::toolbar_container_style_sheet(Theme::chrome_palette(*this));
+ setStyleSheet(style_sheet);
+ // NB: The sidebar's footer lies outside the toolbar while the sidebar holds it, so it takes the style sheet itself.
+ m_sidebar_footer->setStyleSheet(style_sheet);
if (m_downloads_popover)
m_downloads_popover->update_chrome_style(palette());
if (m_feedback_popover)
@@ -1472,7 +1574,7 @@ void WindowToolbar::fit_feedback_popover()
{
m_feedback_popover->card().layout()->activate();
m_feedback_popover->adjustSize();
- move_popover_below(*m_feedback_popover, *m_feedback_button, PopoverAlignment::Trailing);
+ move_popover_to_button(*m_feedback_popover, *m_feedback_button);
}
void WindowToolbar::show_feedback_popover()
@@ -1507,7 +1609,7 @@ void WindowToolbar::show_feedback_popover()
m_feedback_popover->set_crash_report_count(crash_report_count);
fit_feedback_popover();
m_feedback_popover->show();
- move_popover_below(*m_feedback_popover, *m_feedback_button, PopoverAlignment::Trailing);
+ move_popover_to_button(*m_feedback_popover, *m_feedback_button);
m_feedback_popover->raise();
}
@@ -1577,7 +1679,17 @@ void WindowToolbar::position_downloads_popover()
card.setFixedSize(size);
m_downloads_popover->adjustSize();
- move_popover_below(*m_downloads_popover, *m_downloads_button, PopoverAlignment::Trailing);
+ move_popover_to_button(*m_downloads_popover, *m_downloads_button);
+}
+
+// A button on the toolbar row hangs its popover below it. In the sidebar's footer, at the bottom of the window, the
+// popover stands on the button instead, reaching over the page.
+void WindowToolbar::move_popover_to_button(Popover& popover, QWidget& button)
+{
+ if (m_arrangement == ToolbarArrangement::Sidebar)
+ move_popover_above(popover, button, PopoverAlignment::Leading);
+ else
+ move_popover_below(popover, button, PopoverAlignment::Trailing);
}
void WindowToolbar::download_added(WebView::FileDownloader::Download const& download)
diff --git a/UI/Qt/WindowToolbar.h b/UI/Qt/WindowToolbar.h
index 9a157b2f1ae..8283334be19 100644
--- a/UI/Qt/WindowToolbar.h
+++ b/UI/Qt/WindowToolbar.h
@@ -28,9 +28,18 @@ class FeedbackButton;
class FeedbackPopover;
class LocationEdit;
class PerformanceMonitorWidget;
+class Popover;
class ReloadButton;
class Tab;
+enum class ToolbarArrangement : u8 {
+ // One row above the page.
+ Row,
+ // Two rows in the open sidebar: the navigation buttons, then the address field. The toolbar's other buttons sit in
+ // its sidebar footer, which the sidebar shows at its bottom.
+ Sidebar,
+};
+
// A window has one toolbar, which shows the tab that is selected. Each tab keeps its own address field, which the
// toolbar holds while that tab is shown.
class WindowToolbar final
@@ -60,6 +69,11 @@ public:
void set_vertical_tabs_enabled(bool);
void set_bookmarks_bar_below(bool);
+ ToolbarArrangement arrangement() const { return m_arrangement; }
+ // The sidebar's own margin plus the given inset keeps the toolbar's contents clear of the sidebar's edges.
+ void set_arrangement(ToolbarArrangement, int sidebar_inset = 0);
+ QWidget& sidebar_footer() { return *m_sidebar_footer; }
+
void show_downloads_popover();
void update_downloads_button();
void update_feedback_button();
@@ -84,13 +98,22 @@ private:
void position_downloads_popover();
void show_feedback_popover();
void fit_feedback_popover();
+ void move_popover_to_button(Popover&, QWidget& button);
+ void lay_out_as_row();
+ void lay_out_in_sidebar();
WebView::IsPrivate m_is_private { WebView::IsPrivate::No };
QPointer<Tab> m_tab;
// The tab whose history a back or forward button's menu lists, which stays the same while the menu is open.
QPointer<Tab> m_history_menu_tab;
+ ToolbarArrangement m_arrangement { ToolbarArrangement::Row };
QWidget* m_toolbar { nullptr };
+ QWidget* m_navigation_buttons { nullptr };
+ QWidget* m_location_edit_container { nullptr };
+ QWidget* m_sidebar_footer { nullptr };
+ bool m_window_controls_visible { false };
+ int m_sidebar_inset { 0 };
// NB: The fields of the tabs shown so far share this layout, which leaves room around them for the focus ring.
QHBoxLayout* m_location_edit_layout { nullptr };
QPointer<LocationEdit> m_location_edit;