Truly independent web browser
UI/Qt: Line up the address field's suggestions with its icon and text
Andreas Klingf108aa263a64
diff --git a/Documentation/UI/QuietDesign.md b/Documentation/UI/QuietDesign.mdindex 175ced46c52..834277caa64 100644--- a/Documentation/UI/QuietDesign.md+++ b/Documentation/UI/QuietDesign.md@@ -109,7 +109,7 @@ All sizes are in logical pixels.|---|---|---|| Toolbar buttons | 32 × 28 px | 6 px radius, 18 px icons, 2 px apart || Address field | 28 px tall | 7 px radius, no border, 8 px after the reload button |-| Icons inside the field | 16 px | Site settings (left), zoom chip and star (right) |+| Icons inside the field | 16 px | Site settings (left), zoom chip and star (right). The left icon's 16 px box sits 10 px from the field's left edge and the text starts 36 px in, in every state but the "Not secure" pill, which the text follows. || Downloads button | 32 × 28 px | Appears at the right end of the toolbar, 6 px after the field, only while there are downloads |### Ladybird button@@ -485,8 +485,14 @@ settings.ring runs around the whole surface, in place of its hairline edge. The ring never fadesor jumps when the surface opens or closes: focus hasn't moved, so its indicator doesn'tchange either.+- While editing, the site settings icon in the text row is replaced, in place, by the icon of+ what Return will do: the selected row's favicon or globe, or a magnifier for a search.- A `sep-soft` divider, inset 8 px, separates the text row from the suggestions. Rows are- 34 px, in a 6 px padded list.+ 34 px. The list has 6 px of padding top and bottom and 3 px at the sides, so the selected+ row's fill sits 3 px from the surface edge, with a 4 px radius that nests in the+ surface's 7 px corner. Inside a row, the icon sits 7 px from the row's left edge and the+ title 33 px, which puts them on the same columns as the text row's icon (10 px) and text+ (36 px). Icons and text form two straight columns from the address down.- The surface only opens when there are rows to show, and shrinks back to the field whenthere are none. It is never shown empty.- The top row is selected (selected-row colors), so Return acts on it.diff --git a/UI/Qt/Autocomplete.cpp b/UI/Qt/Autocomplete.cppindex a34a63f7c5d..1480173d8e0 100644--- a/UI/Qt/Autocomplete.cpp+++ b/UI/Qt/Autocomplete.cpp@@ -44,8 +44,13 @@ namespace Ladybird {static constexpr int LIST_PADDING = 6;static constexpr int FIELD_DIVIDER_HEIGHT = 1;static constexpr int ROW_HEIGHT = 34;-static constexpr int ROW_CORNER_RADIUS = 6;-static constexpr int CELL_HORIZONTAL_PADDING = 12;+// NB: The radius nests in the corner of the surface the rows are listed in.+static constexpr int ROW_CORNER_RADIUS = 4;+// NB: With the list's 3 px inset, a row's icon and title start 10 px and 36 px in from the surface's edge, on the same+// columns as the address field's icon and text.+static constexpr int CELL_LEADING_PADDING = 7;+static constexpr int CELL_ICON_TITLE_SPACING = 10;+static constexpr int CELL_TRAILING_PADDING = 12;static constexpr int CELL_ICON_SIZE = 16;static constexpr int CELL_SPACING = 12;// Search suggestions are set apart from pages by a line, with this much room above and below it.@@ -289,7 +294,7 @@ public:else if (!title_text.isEmpty())detail_text = url_text;- int x = row_rect.left() + CELL_HORIZONTAL_PADDING;+ int x = row_rect.left() + CELL_LEADING_PADDING;QRect icon_rect(x, row_rect.top() + (row_rect.height() - CELL_ICON_SIZE) / 2, CELL_ICON_SIZE, CELL_ICON_SIZE);auto icon_color = selected ? QColor(Qt::white) : panel.muted;if (source == WebView::AutocompleteSuggestionSource::Search || source == WebView::AutocompleteSuggestionSource::ChooseSearchEngine)@@ -298,9 +303,9 @@ public:favicon.paint(painter, icon_rect);elsecreate_chrome_icon(ChromeIcon::Globe, icon_color).paint(painter, icon_rect);- x = icon_rect.right() + 1 + CELL_SPACING;+ x = icon_rect.right() + 1 + CELL_ICON_TITLE_SPACING;- auto right = row_rect.right() - CELL_HORIZONTAL_PADDING;+ auto right = row_rect.right() - CELL_TRAILING_PADDING;auto title_font = autocomplete_title_font();auto detail_font = autocomplete_detail_font();diff --git a/UI/Qt/LocationEdit.cpp b/UI/Qt/LocationEdit.cppindex c287378f064..14a3171b783 100644--- a/UI/Qt/LocationEdit.cpp+++ b/UI/Qt/LocationEdit.cpp@@ -176,11 +176,16 @@ static int qstring_offset_for_byte_offset(String const& text, size_t byte_offsetreturn static_cast<int>(qstring_from_ak_string(prefix).length());}-// The field's content is inset more on its leading side than on its trailing side.-static constexpr int LOCATION_LEADING_EDGE_MARGIN = 2;+// The leading icon and the text start this far in from the field's leading edge, so the text stays in place, except+// after the wider "Not secure" pill, which the text follows. The suggestion rows draw their icons and titles on the+// same columns.+static constexpr int LOCATION_LEADING_ICON_X = 10;+static constexpr int LOCATION_TEXT_X = 36;static constexpr int LOCATION_TRAILING_EDGE_MARGIN = 3;-// The text starts this far in when nothing comes before it. The style sheet pads the field by as much.+// The style sheet pads the field by this much.static constexpr int LOCATION_TEXT_PADDING = 8;+// NB: QLineEdit draws its text inside its 1 px border, its padding and its text margins, and 2 px further in.+static constexpr int LOCATION_TEXT_MARGIN_FOR_TEXT_X = LOCATION_TEXT_X - 1 - LOCATION_TEXT_PADDING - 2;static constexpr int LOCATION_TRAILING_ITEM_GAP = 6;static constexpr int LOCATION_LEADING_ITEM_GAP = 6;static constexpr int LOCATION_TRAILING_ACTION_WIDTH = 24;@@ -1102,12 +1107,13 @@ void LocationEdit::fit_in_use_chips()chip->set_words_fit(width() >= width_for_words);}-// The "Not secure" pill is inset as far from the field's leading edge as from its top and bottom.-static int leading_indicator_inset(QWidget const& field, QWidget const& indicator)+// The "Not secure" pill is inset as far from the field's leading edge as from its top and bottom. Any other indicator+// is an icon, centered in its button.+static int leading_indicator_inset(QWidget const& field, QToolButton const& indicator){if (indicator.property("notSecure").toBool())return (field.height() - indicator.height()) / 2;- return LOCATION_LEADING_EDGE_MARGIN;+ return LOCATION_LEADING_ICON_X - ((indicator.width() - indicator.iconSize().width()) / 2);}void LocationEdit::update_trailing_item_positions()@@ -1261,11 +1267,11 @@ void LocationEdit::update_location_icon()m_leading_icon_button->style()->polish(m_leading_icon_button);};- auto show_indicator = [&](int width) {+ auto show_indicator = [&](int text_leading_margin) {m_leading_icon_button->show();auto inset = leading_indicator_inset(*this, *m_leading_icon_button);m_leading_icon_button->move(inset, (height() - m_leading_icon_button->height()) / 2);- m_text_leading_margin = inset + width + LOCATION_LEADING_ITEM_GAP - LOCATION_TEXT_PADDING;+ m_text_leading_margin = text_leading_margin;update_text_margins();};@@ -1273,17 +1279,13 @@ void LocationEdit::update_location_icon()m_shows_editing_icon = false;m_leading_icon_button->setAttribute(Qt::WA_TransparentForMouseEvents, false);- auto hide_indicator = [&] {- update_indicator_style(false);- m_leading_icon_button->hide();- m_leading_icon_button->setText({});- m_leading_icon_button->setIcon({});- m_leading_icon_button->setToolTip({});- m_text_leading_margin = 0;- update_text_margins();+ // NB: A page without a site of its own, such as about:blank, has no site settings, so the icon is only shown there,+ // and a click on it lands in the text.+ enum class Clickable : u8 {+ No,+ Yes,};-- auto show_site_settings_button = [&] {+ auto show_site_settings_button = [&](Clickable clickable) {update_indicator_style(false);m_leading_icon_button->setToolButtonStyle(Qt::ToolButtonIconOnly);m_leading_icon_button->setText({});@@ -1291,8 +1293,9 @@ void LocationEdit::update_location_icon()m_shows_site_settings_button = true;m_leading_icon_button->setIconSize({ 16, 16 });m_leading_icon_button->setFixedSize(LOCATION_SITE_SETTINGS_BUTTON_WIDTH, LOCATION_PILL_HEIGHT);- m_leading_icon_button->setToolTip("Site settings");- show_indicator(LOCATION_SITE_SETTINGS_BUTTON_WIDTH);+ m_leading_icon_button->setToolTip(clickable == Clickable::Yes ? "Site settings" : QString {});+ m_leading_icon_button->setAttribute(Qt::WA_TransparentForMouseEvents, clickable == Clickable::No);+ show_indicator(LOCATION_TEXT_MARGIN_FOR_TEXT_X);};auto show_not_secure_indicator = [&] {@@ -1308,7 +1311,8 @@ void LocationEdit::update_location_icon()auto width = QFontMetrics(font).horizontalAdvance("Not secure") + 14 + 5 + LOCATION_PILL_HORIZONTAL_PADDING;m_leading_icon_button->setFixedSize(width, LOCATION_PILL_HEIGHT);m_leading_icon_button->setToolTip("The connection to this site is not secure");- show_indicator(width);+ // NB: The pill is wider than the icon, so the text follows it.+ show_indicator(leading_indicator_inset(*this, *m_leading_icon_button) + width + LOCATION_LEADING_ITEM_GAP - LOCATION_TEXT_PADDING);};if (m_is_editing_location) {@@ -1323,7 +1327,7 @@ void LocationEdit::update_location_icon()m_leading_icon_button->setToolTip({});// NB: The icon only shows where the text goes, so a click on it lands in the text.m_leading_icon_button->setAttribute(Qt::WA_TransparentForMouseEvents, true);- show_indicator(LOCATION_SITE_SETTINGS_BUTTON_WIDTH);+ show_indicator(LOCATION_TEXT_MARGIN_FOR_TEXT_X);m_shows_editing_icon = true;return;}@@ -1336,14 +1340,12 @@ void LocationEdit::update_location_icon()auto scheme = m_url->scheme();if (scheme == "http"sv)show_not_secure_indicator();- else if (scheme == "https"sv)- show_site_settings_button();else- hide_indicator();+ show_site_settings_button(scheme == "https"sv ? Clickable::Yes : Clickable::No);return;}- hide_indicator();+ show_site_settings_button(Clickable::No);}void LocationEdit::update_zoom_indicator()diff --git a/UI/Qt/WindowToolbar.cpp b/UI/Qt/WindowToolbar.cppindex 4d59274c060..cda78b671e0 100644--- a/UI/Qt/WindowToolbar.cpp+++ b/UI/Qt/WindowToolbar.cpp@@ -653,7 +653,8 @@ static constexpr int FIELD_PANEL_WINDOW_MARGIN = 8;// A line inset this far from the surface's sides sets the suggestions apart from the field, and the list has this much// room around it.static constexpr int FIELD_PANEL_DIVIDER_INSET = 8;-static constexpr int FIELD_PANEL_LIST_PADDING = 6;+static constexpr int FIELD_PANEL_LIST_VERTICAL_PADDING = 6;+static constexpr int FIELD_PANEL_LIST_HORIZONTAL_PADDING = 3;// The address field floats over its place in the toolbar, in a panel that is a native child of the window wherever the// page stays native under it. So the panel stacks above the native views of the sidebar and the page, and can grow over@@ -1449,8 +1450,9 @@ void WindowToolbar::create_field_panel()// The suggestions are below the line under the field.m_suggestions_area = new QWidget(m_field_panel);auto* suggestions_layout = new QVBoxLayout(m_suggestions_area);- auto padding = FIELD_PANEL_LIST_PADDING;- suggestions_layout->setContentsMargins(padding, 1 + padding, padding, padding);+ auto vertical_padding = FIELD_PANEL_LIST_VERTICAL_PADDING;+ auto horizontal_padding = FIELD_PANEL_LIST_HORIZONTAL_PADDING;+ suggestions_layout->setContentsMargins(horizontal_padding, 1 + vertical_padding, horizontal_padding, vertical_padding);suggestions_layout->setSpacing(0);panel_layout->addWidget(m_suggestions_area);m_suggestions_area->hide();