Truly independent web browser
UI/Qt: Make select dropdowns compact
Andreas Kling72e7fb47f433
diff --git a/UI/Qt/ChromeStyle.cpp b/UI/Qt/ChromeStyle.cppindex 72080a1d931..a2b5fbafe1b 100644--- a/UI/Qt/ChromeStyle.cpp+++ b/UI/Qt/ChromeStyle.cpp@@ -1804,6 +1804,7 @@ static constexpr int SUBMENU_DELAY_MS = 150;static constexpr int MENU_PADDING = 6;static constexpr int MENU_RADIUS = 10;static constexpr int MENU_ROW_HEIGHT = 26;+static constexpr int SELECT_DROPDOWN_ROW_HEIGHT = 22;static constexpr int MENU_ROW_INSET = 10;static constexpr int MENU_ROW_RADIUS = 6;static constexpr int MENU_SEPARATOR_HEIGHT = 11;@@ -1952,13 +1953,15 @@ public:if (auto const* item = qstyleoption_cast<QStyleOptionMenuItem const*>(option)) {if (item->menuItemType == QStyleOptionMenuItem::Separator)return { contents_size.width(), MENU_SEPARATOR_HEIGHT };+ // A select's options have no shortcuts, and sit in compact rows like the options of a list box.+ bool const is_select_dropdown = widget && widget->objectName() == QLatin1StringView("LadybirdSelectDropdown");// NB: Qt measures the label and the shortcut column into the contents' width.- auto width = contents_size.width() + (2 * MENU_ROW_INSET) + MENU_SHORTCUT_GAP;+ auto width = contents_size.width() + (2 * MENU_ROW_INSET) + (is_select_dropdown ? 0 : MENU_SHORTCUT_GAP);if (menu_item_has_leading_column(*item))width += MENU_ICON_SIZE + MENU_ICON_GAP;if (item->menuItemType == QStyleOptionMenuItem::SubMenu)width += MENU_CHEVRON_SIZE + MENU_SHORTCUT_GAP;- return { width, MENU_ROW_HEIGHT };+ return { width, is_select_dropdown ? SELECT_DROPDOWN_ROW_HEIGHT : MENU_ROW_HEIGHT };}}return QProxyStyle::sizeFromContents(type, option, contents_size, widget);diff --git a/UI/Qt/SelectDropdown.cpp b/UI/Qt/SelectDropdown.cppindex 964d280d331..e10b906e969 100644--- a/UI/Qt/SelectDropdown.cpp+++ b/UI/Qt/SelectDropdown.cpp@@ -16,6 +16,12 @@ namespace Ladybird {SelectDropdown::SelectDropdown(QWidget* parent): QMenu("Select Dropdown", parent){+ // NB: The options are sized to match the 13.333px font a select uses by default. A point size would grow with the+ // screen's DPI on some platforms, so the size is in pixels.+ setObjectName("LadybirdSelectDropdown");+ auto menu_font = font();+ menu_font.setPixelSize(13);+ setFont(menu_font);}void SelectDropdown::open(QPoint const& global_position, int minimum_width, Vector<Web::HTML::SelectItem> const& items)