Skip to content

Truly independent web browser

UI/Qt: Round the corners of every favicon the chrome shows

Jelle Raaijmakers9d9e0d57e18a
diff --git a/UI/Qt/Autocomplete.cpp b/UI/Qt/Autocomplete.cpp
index 6b95c838204..b2826cbedcc 100644
--- a/UI/Qt/Autocomplete.cpp
+++ b/UI/Qt/Autocomplete.cpp
@@ -144,7 +144,7 @@ public:
auto const& suggestion = m_suggestions[index];
if (!suggestion.favicon_png.has_value())
continue;
- auto icon = icon_from_png(suggestion.favicon_png->bytes(), CELL_ICON_SIZE);
+ auto icon = favicon_from_png(suggestion.favicon_png->bytes(), CELL_ICON_SIZE);
if (icon.isNull())
continue;
m_favicon_cache.append({ index, move(icon) });
diff --git a/UI/Qt/BrowserWindow.cpp b/UI/Qt/BrowserWindow.cpp
index 3258c0e85a4..4cb136c559d 100644
--- a/UI/Qt/BrowserWindow.cpp
+++ b/UI/Qt/BrowserWindow.cpp
@@ -830,7 +830,7 @@ Tab& BrowserWindow::create_restored_tab(RestoredSessionTab const& restored, int
.session_tab_id = restored.tab_id,
.url = restored.url,
.title = entry.has_value() && entry->title.has_value() ? qstring_from_ak_string(*entry->title) : qstring_from_ak_string(restored.url.serialize()),
- .favicon = entry.has_value() && entry->favicon_png.has_value() ? icon_from_png(entry->favicon_png->bytes(), TAB_ICON_SIZE) : QIcon {},
+ .favicon = entry.has_value() && entry->favicon_png.has_value() ? favicon_from_png(entry->favicon_png->bytes(), TAB_ICON_SIZE) : QIcon {},
};
auto* tab = new Tab(this, AK::move(deferred_tab));
tab->set_pinned(restored.pinned);
diff --git a/UI/Qt/Icon.cpp b/UI/Qt/Icon.cpp
index 38df3386212..87e55f46f27 100644
--- a/UI/Qt/Icon.cpp
+++ b/UI/Qt/Icon.cpp
@@ -36,22 +36,6 @@ QIcon load_icon_from_uri(StringView uri)
return QIcon { path };
}
-QIcon icon_from_png(ReadonlyBytes favicon_png, int logical_size)
-{
- QPixmap pixmap;
- if (!pixmap.loadFromData(favicon_png.data(), static_cast<uint>(favicon_png.size()), "PNG"))
- return {};
-
- QIcon icon;
- for (auto device_pixel_ratio : ICON_DEVICE_PIXEL_RATIOS) {
- auto size = logical_size * device_pixel_ratio;
- auto scaled_pixmap = pixmap.scaled(size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
- scaled_pixmap.setDevicePixelRatio(device_pixel_ratio);
- icon.addPixmap(scaled_pixmap);
- }
- return icon;
-}
-
// Favicons get slightly rounded corners, so that square ones sit well in the round shapes of the chrome around them.
static constexpr qreal FAVICON_CORNER_RADIUS_FRACTION = 3.0 / 16.0;
@@ -74,15 +58,20 @@ QPixmap favicon_with_rounded_corners(QPixmap const& favicon)
return QPixmap::fromImage(rounded);
}
-QIcon favicon_with_rounded_corners(QIcon const& favicon, int logical_size)
+QIcon favicon_from_png(ReadonlyBytes favicon_png, int logical_size)
{
- if (favicon.isNull())
+ QPixmap pixmap;
+ if (!pixmap.loadFromData(favicon_png.data(), static_cast<uint>(favicon_png.size()), "PNG"))
return {};
- QIcon rounded;
- for (auto device_pixel_ratio : ICON_DEVICE_PIXEL_RATIOS)
- rounded.addPixmap(favicon_with_rounded_corners(favicon.pixmap(QSize(logical_size, logical_size), device_pixel_ratio)));
- return rounded;
+ QIcon icon;
+ for (auto device_pixel_ratio : ICON_DEVICE_PIXEL_RATIOS) {
+ auto size = logical_size * device_pixel_ratio;
+ auto scaled_pixmap = pixmap.scaled(size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
+ scaled_pixmap.setDevicePixelRatio(device_pixel_ratio);
+ icon.addPixmap(favicon_with_rounded_corners(scaled_pixmap));
+ }
+ return icon;
}
// Parses the path data of an SVG <path> element. Only the commands used by the icons below are understood: moveto,
diff --git a/UI/Qt/Icon.h b/UI/Qt/Icon.h
index 35e2eb31981..9f95a41a103 100644
--- a/UI/Qt/Icon.h
+++ b/UI/Qt/Icon.h
@@ -74,9 +74,8 @@ constexpr inline int CHROME_ICON_CANVAS_SIZE = 16;
constexpr inline int TOOLBAR_ICON_SIZE = 18;
QIcon load_icon_from_uri(StringView);
-QIcon icon_from_png(ReadonlyBytes, int logical_size);
QPixmap favicon_with_rounded_corners(QPixmap const&);
-QIcon favicon_with_rounded_corners(QIcon const&, int logical_size);
+QIcon favicon_from_png(ReadonlyBytes, int logical_size);
QIcon create_chrome_icon(ChromeIcon, QPalette const&, ChromeStyle::WindowActivity = ChromeStyle::WindowActivity::Active, int logical_size = CHROME_ICON_CANVAS_SIZE);
// The site settings icon with its two knobs moved toward each other's place, by a travel from 0 to 1.
QIcon create_site_settings_icon(QPalette const&, qreal knob_travel);
diff --git a/UI/Qt/LocationEdit.cpp b/UI/Qt/LocationEdit.cpp
index 63fc5fd5504..8c48fcc3f1d 100644
--- a/UI/Qt/LocationEdit.cpp
+++ b/UI/Qt/LocationEdit.cpp
@@ -1257,9 +1257,7 @@ void LocationEdit::update_editing_icon()
return;
}
- QIcon favicon;
- if (!favicon_png.is_empty())
- favicon = favicon_with_rounded_corners(icon_from_png(favicon_png, 16), 16);
+ auto favicon = favicon_from_png(favicon_png, 16);
m_leading_icon_button->setIcon(favicon.isNull() ? create_chrome_icon(ChromeIcon::Globe, muted) : favicon);
}
diff --git a/UI/Qt/Menu.cpp b/UI/Qt/Menu.cpp
index 700c7fc8699..85b18d229b5 100644
--- a/UI/Qt/Menu.cpp
+++ b/UI/Qt/Menu.cpp
@@ -367,7 +367,7 @@ static Action::Observer& initialize_native_control(Action& action, QAction& qact
break;
case ActionID::BookmarkItem:
if (auto icon = action.png_icon(); icon.has_value())
- qaction.setIcon(favicon_with_rounded_corners(icon_from_png(icon->bytes(), MENU_ICON_SIZE), MENU_ICON_SIZE));
+ qaction.setIcon(favicon_from_png(icon->bytes(), MENU_ICON_SIZE));
else
qaction.setIcon(create_chrome_icon(ChromeIcon::Globe, palette));
break;
@@ -420,7 +420,7 @@ static QAction* create_session_history_traversal_menu_action(QMenu& menu, Remote
auto* action = new QAction(qstring_from_ak_string(item.title), &menu);
action->setToolTip(qstring_from_ak_string(item.url));
if (item.favicon_png.has_value())
- action->setIcon(icon_from_png(item.favicon_png->bytes(), MENU_ICON_SIZE));
+ action->setIcon(favicon_from_png(item.favicon_png->bytes(), MENU_ICON_SIZE));
else
action->setIcon(create_chrome_icon(ChromeIcon::Globe, menu.palette()));
action->setData(item.step);
@@ -522,7 +522,7 @@ static QAction* create_recent_history_menu_action(QMenu& menu, WebContentView& v
auto* action = new QAction(qstring_from_ak_string(title), &menu);
action->setToolTip(qstring_from_ak_string(entry.url));
if (entry.favicon_png.has_value())
- action->setIcon(icon_from_png(entry.favicon_png->bytes(), MENU_ICON_SIZE));
+ action->setIcon(favicon_from_png(entry.favicon_png->bytes(), MENU_ICON_SIZE));
else
action->setIcon(create_chrome_icon(ChromeIcon::Globe, menu.palette()));
diff --git a/UI/Qt/ProcessManagerWindow.cpp b/UI/Qt/ProcessManagerWindow.cpp
index f8de2f24bf5..795cb610702 100644
--- a/UI/Qt/ProcessManagerWindow.cpp
+++ b/UI/Qt/ProcessManagerWindow.cpp
@@ -621,7 +621,7 @@ QIcon ProcessManagerWindow::favicon_for(WebView::ProcessPageSnapshot const& page
return *icon;
QIcon icon;
if (auto png = m_source.favicon_png ? m_source.favicon_png(*favicon_hash) : Optional<ByteBuffer> {}; png.has_value())
- icon = favicon_with_rounded_corners(icon_from_png(png->bytes(), 16), 16);
+ icon = favicon_from_png(png->bytes(), 16);
if (icon.isNull())
icon = create_chrome_icon(ChromeIcon::Globe, Theme::panel().body);
m_favicons.set(*favicon_hash, icon);
diff --git a/UI/Qt/Tab.cpp b/UI/Qt/Tab.cpp
index aeddcd93d3d..e0863e483f1 100644
--- a/UI/Qt/Tab.cpp
+++ b/UI/Qt/Tab.cpp
@@ -101,7 +101,6 @@ static QIcon calendar_month_chevron_icon(QWidget const& widget, ChevronDirection
return QIcon(pixmap);
}
-static constexpr int TAB_FAVICON_SIZE = 16;
static constexpr int PRIVATE_SESSION_POPOVER_WIDTH = 320;
// The page's zoom, with buttons to change it and a way back to the default.
@@ -188,7 +187,7 @@ Tab::Tab(BrowserWindow* window, DeferredTab deferred_tab)
, WebView::SettingsObserver(Application::settings())
, m_window(window)
, m_title(deferred_tab.title)
- , m_favicon(favicon_with_rounded_corners(deferred_tab.favicon, TAB_FAVICON_SIZE))
+ , m_favicon(deferred_tab.favicon)
, m_session_tab_id(deferred_tab.session_tab_id)
, m_deferred_tab(AK::move(deferred_tab))
{
diff --git a/UI/Qt/TabBar.cpp b/UI/Qt/TabBar.cpp
index 453720288b5..a18eeedae3c 100644
--- a/UI/Qt/TabBar.cpp
+++ b/UI/Qt/TabBar.cpp
@@ -4866,7 +4866,7 @@ void TabWidget::update_all_tabs_entries()
if (unit.was_window)
title = unit.tab_count == 1 ? QStringLiteral("Window with 1 tab") : qformatted("Window with {} tabs", unit.tab_count);
closed_entries.append({
- .icon = entry.has_value() && entry->favicon_png.has_value() ? icon_from_png(entry->favicon_png->bytes(), TAB_ICON_SIZE) : QIcon {},
+ .icon = entry.has_value() && entry->favicon_png.has_value() ? favicon_from_png(entry->favicon_png->bytes(), TAB_ICON_SIZE) : QIcon {},
.title = AK::move(title),
.detail = time_since_closed(now - unit.closed_at),
.is_current = false,