From f088656bc33c6778ef084d38ab844ed87abc788c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 12 May 2025 17:38:01 +0000 Subject: [PATCH] Bug 1965779 - Remove GTK iconSize / iconState from icon URI. r=stransky,settings-reviewers Icon state is now unused (and wasn't used anyhow). Icon sizes are hardcoded in GTK as per: https://docs.gtk.org/gtk3/enum.IconSize.html So we can migrate the few usages left to the actual sizes, and remove the supporting code. Differential Revision: https://phabricator.services.mozilla.com/D248866 --- .../themes/linux/preferences/applications.css | 2 +- image/decoders/icon/gtk/nsIconChannel.cpp | 43 +---------- image/decoders/icon/nsIconURI.cpp | 71 +------------------ image/decoders/icon/nsIconURI.h | 4 -- image/nsIIconURI.idl | 6 -- image/test/unit/test_moz_icon_uri.js | 5 +- ipc/glue/URIParams.ipdlh | 2 - .../resources/content/exceptionDialog.xhtml | 2 +- toolkit/themes/linux/global/global.css | 8 +-- 9 files changed, 10 insertions(+), 133 deletions(-) diff --git a/browser/themes/linux/preferences/applications.css b/browser/themes/linux/preferences/applications.css index 49c8aeb83d8e..5e3650f4419a 100644 --- a/browser/themes/linux/preferences/applications.css +++ b/browser/themes/linux/preferences/applications.css @@ -14,7 +14,7 @@ menuitem[appHandlerIcon="ask"] { richlistitem[appHandlerIcon="save"], menuitem[appHandlerIcon="save"] { - list-style-image: url("moz-icon://stock/gtk-save?size=menu"); + list-style-image: url("moz-icon://stock/gtk-save?size=16"); } richlistitem[appHandlerIcon="plugin"], diff --git a/image/decoders/icon/gtk/nsIconChannel.cpp b/image/decoders/icon/gtk/nsIconChannel.cpp index c75ddd2050da..5997d9cfd3ae 100644 --- a/image/decoders/icon/gtk/nsIconChannel.cpp +++ b/image/decoders/icon/gtk/nsIconChannel.cpp @@ -145,47 +145,6 @@ static nsresult StreamToChannel(already_AddRefed aStream, nsIContentPolicy::TYPE_INTERNAL_IMAGE, nsLiteralCString(IMAGE_ICON_MS)); } -static GtkIconSize moz_gtk_icon_size(const char* name) { - if (strcmp(name, "button") == 0) { - return GTK_ICON_SIZE_BUTTON; - } - - if (strcmp(name, "menu") == 0) { - return GTK_ICON_SIZE_MENU; - } - - if (strcmp(name, "toolbar") == 0) { - return GTK_ICON_SIZE_LARGE_TOOLBAR; - } - - if (strcmp(name, "toolbarsmall") == 0) { - return GTK_ICON_SIZE_SMALL_TOOLBAR; - } - - if (strcmp(name, "dnd") == 0) { - return GTK_ICON_SIZE_DND; - } - - if (strcmp(name, "dialog") == 0) { - return GTK_ICON_SIZE_DIALOG; - } - - return GTK_ICON_SIZE_MENU; -} - -static int32_t GetIconSize(nsIMozIconURI* aIconURI) { - nsAutoCString iconSizeString; - - aIconURI->GetIconSize(iconSizeString); - if (iconSizeString.IsEmpty()) { - return int32_t(aIconURI->GetImageSize()); - } - int size; - GtkIconSize icon_size = moz_gtk_icon_size(iconSizeString.get()); - gtk_icon_size_lookup(icon_size, &size, nullptr); - return size; -} - /* static */ nsresult nsIconChannel::GetIconWithGIO(nsIMozIconURI* aIconURI, ByteBuf* aDataOut) { @@ -253,7 +212,7 @@ nsresult nsIconChannel::GetIconWithGIO(nsIMozIconURI* aIconURI, // Get default icon theme GtkIconTheme* iconTheme = gtk_icon_theme_get_default(); // Get icon size and scale. - int32_t iconSize = GetIconSize(aIconURI); + int32_t iconSize = aIconURI->GetImageSize(); int32_t scale = aIconURI->GetImageScale(); RefPtr iconInfo; diff --git a/image/decoders/icon/nsIconURI.cpp b/image/decoders/icon/nsIconURI.cpp index 39926bd6d86a..c759351af33f 100644 --- a/image/decoders/icon/nsIconURI.cpp +++ b/image/decoders/icon/nsIconURI.cpp @@ -38,11 +38,6 @@ using namespace mozilla::ipc; static NS_DEFINE_CID(kThisIconURIImplementationCID, NS_THIS_ICONURI_IMPLEMENTATION_CID); -static const char* const kSizeStrings[] = {"button", "toolbar", "toolbarsmall", - "menu", "dnd", "dialog"}; - -static const char* const kStateStrings[] = {"normal", "disabled"}; - //////////////////////////////////////////////////////////////////////////////// NS_IMPL_CLASSINFO(nsMozIconURI, nullptr, nsIClassInfo::THREADSAFE, @@ -93,18 +88,12 @@ nsMozIconURI::GetSpec(nsACString& aSpec) { } aSpec += "?size="; - if (mIconSize >= 0) { - aSpec += kSizeStrings[mIconSize]; - } else { + { char buf[20]; SprintfLiteral(buf, "%d", mSize); aSpec.Append(buf); } - if (mIconState >= 0) { - aSpec += "&state="; - aSpec += kStateStrings[mIconState]; - } if (!mContentType.IsEmpty()) { aSpec += "&contentType="; @@ -217,8 +206,6 @@ nsresult nsMozIconURI::SetSpecInternal(const nsACString& aSpec) { mContentType.Truncate(); mFileName.Truncate(); mStockIcon.Truncate(); - mIconSize = -1; - mIconState = -1; mScale = 1; mDark.reset(); @@ -240,32 +227,12 @@ nsresult nsMozIconURI::SetSpecInternal(const nsACString& aSpec) { nsAutoCString sizeString; extractAttributeValue(iconSpec.get(), "size=", sizeString); if (!sizeString.IsEmpty()) { - const char* sizeStr = sizeString.get(); - for (uint32_t i = 0; i < std::size(kSizeStrings); i++) { - if (nsCRT::strcasecmp(sizeStr, kSizeStrings[i]) == 0) { - mIconSize = i; - break; - } - } - int32_t sizeValue = atoi(sizeString.get()); if (sizeValue > 0) { mSize = sizeValue; } } - nsAutoCString stateString; - extractAttributeValue(iconSpec.get(), "state=", stateString); - if (!stateString.IsEmpty()) { - const char* stateStr = stateString.get(); - for (uint32_t i = 0; i < std::size(kStateStrings); i++) { - if (nsCRT::strcasecmp(stateStr, kStateStrings[i]) == 0) { - mIconState = i; - break; - } - } - } - nsAutoCString scaleString; extractAttributeValue(iconSpec.get(), "scale=", scaleString); if (!scaleString.IsEmpty()) { @@ -491,8 +458,6 @@ nsresult nsMozIconURI::Clone(nsIURI** result) { uri->mContentType = mContentType; uri->mFileName = mFileName; uri->mStockIcon = mStockIcon; - uri->mIconSize = mIconSize; - uri->mIconState = mIconState; uri.forget(result); return NS_OK; @@ -586,26 +551,6 @@ nsMozIconURI::GetStockIcon(nsACString& aStockIcon) { return NS_OK; } -NS_IMETHODIMP -nsMozIconURI::GetIconSize(nsACString& aSize) { - if (mIconSize >= 0) { - aSize = kSizeStrings[mIconSize]; - } else { - aSize.Truncate(); - } - return NS_OK; -} - -NS_IMETHODIMP -nsMozIconURI::GetIconState(nsACString& aState) { - if (mIconState >= 0) { - aState = kStateStrings[mIconState]; - } else { - aState.Truncate(); - } - return NS_OK; -} - void nsMozIconURI::Serialize(URIParams& aParams) { IconURIParams params; @@ -625,8 +570,6 @@ void nsMozIconURI::Serialize(URIParams& aParams) { params.size() = mSize; params.fileName() = mFileName; params.stockIcon() = mStockIcon; - params.iconSize() = mIconSize; - params.iconState() = mIconState; params.iconScale() = mScale; params.iconDark() = mDark; @@ -654,18 +597,6 @@ bool nsMozIconURI::Deserialize(const URIParams& aParams) { mFileName = params.fileName(); mStockIcon = params.stockIcon(); - if (params.iconSize() < -1 || - params.iconSize() >= (int32_t)std::size(kSizeStrings)) { - return false; - } - mIconSize = params.iconSize(); - - if (params.iconState() < -1 || - params.iconState() >= (int32_t)std::size(kStateStrings)) { - return false; - } - mIconState = params.iconState(); - mScale = params.iconScale(); mDark = params.iconDark(); diff --git a/image/decoders/icon/nsIconURI.h b/image/decoders/icon/nsIconURI.h index 3bf371548e2b..a4ffaa72e952 100644 --- a/image/decoders/icon/nsIconURI.h +++ b/image/decoders/icon/nsIconURI.h @@ -46,10 +46,6 @@ class nsMozIconURI final : public nsIMozIconURI, nsCString mFileName; // for if we don't have an actual file path, we're just // given a filename with an extension nsCString mStockIcon; - int32_t mIconSize = -1; // -1 if not specified, otherwise index into - // kSizeStrings - int32_t mIconState = -1; // -1 if not specified, otherwise index into - // kStateStrings uint32_t mScale = 1; mozilla::Maybe mDark; diff --git a/image/nsIIconURI.idl b/image/nsIIconURI.idl index 3dab585d721c..1bf7700eb2b2 100644 --- a/image/nsIIconURI.idl +++ b/image/nsIIconURI.idl @@ -64,12 +64,6 @@ interface nsIMozIconURI : nsIURI /// stockIcon: The stock icon name requested from the OS. readonly attribute ACString stockIcon; - /// iconSize: The stock icon size requested from the OS. - readonly attribute ACString iconSize; - - /// iconState: The stock icon state requested from the OS. - readonly attribute ACString iconState; - /// contentType: A valid mime type, or the empty string. readonly attribute ACString contentType; diff --git a/image/test/unit/test_moz_icon_uri.js b/image/test/unit/test_moz_icon_uri.js index 0111d71d2a90..01ec56e7bd0d 100644 --- a/image/test/unit/test_moz_icon_uri.js +++ b/image/test/unit/test_moz_icon_uri.js @@ -23,7 +23,7 @@ function run_test() { // Make sure a valid file name icon URI can be created and that we can obtain // all arguments, the spec, and the file extension. - currentSpec = "moz-icon://foo.html?contentType=bar&size=button&state=normal"; + currentSpec = "moz-icon://foo.html?contentType=bar&size=16"; try { uri = ioService.newURI(currentSpec); } catch (e) { @@ -33,8 +33,7 @@ function run_test() { exception = false; // reset exception value iconURI = uri.QueryInterface(Ci.nsIMozIconURI); - Assert.equal(iconURI.iconSize, "button"); - Assert.equal(iconURI.iconState, "normal"); + Assert.equal(iconURI.imageSize, 16); Assert.equal(iconURI.contentType, "bar"); Assert.equal(iconURI.fileExtension, ".html"); diff --git a/ipc/glue/URIParams.ipdlh b/ipc/glue/URIParams.ipdlh index 0308548d603b..8aa3eb33028c 100644 --- a/ipc/glue/URIParams.ipdlh +++ b/ipc/glue/URIParams.ipdlh @@ -62,8 +62,6 @@ struct IconURIParams nsCString contentType; nsCString fileName; nsCString stockIcon; - int32_t iconSize; - int32_t iconState; uint32_t iconScale; bool? iconDark; }; diff --git a/security/manager/pki/resources/content/exceptionDialog.xhtml b/security/manager/pki/resources/content/exceptionDialog.xhtml index 38d17f2f8a3e..010cf0c6556f 100644 --- a/security/manager/pki/resources/content/exceptionDialog.xhtml +++ b/security/manager/pki/resources/content/exceptionDialog.xhtml @@ -35,7 +35,7 @@ #ifdef MOZ_WIDGET_GTK - + #else #endif diff --git a/toolkit/themes/linux/global/global.css b/toolkit/themes/linux/global/global.css index 594bc81285ea..3c66492e5c8d 100644 --- a/toolkit/themes/linux/global/global.css +++ b/toolkit/themes/linux/global/global.css @@ -20,20 +20,20 @@ /* ::::: Alert icons :::::*/ .message-icon { - list-style-image: url("moz-icon://stock/gtk-dialog-info?size=dialog"); + list-style-image: url("moz-icon://stock/gtk-dialog-info?size=48"); } .alert-dialog #infoIcon, .alert-icon { - list-style-image: url("moz-icon://stock/gtk-dialog-warning?size=dialog"); + list-style-image: url("moz-icon://stock/gtk-dialog-warning?size=48"); } .error-icon { - list-style-image: url("moz-icon://stock/gtk-dialog-error?size=dialog"); + list-style-image: url("moz-icon://stock/gtk-dialog-error?size=48"); } .question-icon { - list-style-image: url("moz-icon://stock/gtk-dialog-question?size=dialog"); + list-style-image: url("moz-icon://stock/gtk-dialog-question?size=48"); } .authentication-icon {