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
This commit is contained in:
Emilio Cobos Álvarez
2025-05-12 17:38:01 +00:00
committed by ealvarez@mozilla.com
parent 018f0bf1aa
commit f088656bc3
9 changed files with 10 additions and 133 deletions

View File

@@ -14,7 +14,7 @@ menuitem[appHandlerIcon="ask"] {
richlistitem[appHandlerIcon="save"], richlistitem[appHandlerIcon="save"],
menuitem[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"], richlistitem[appHandlerIcon="plugin"],

View File

@@ -145,47 +145,6 @@ static nsresult StreamToChannel(already_AddRefed<nsIInputStream> aStream,
nsIContentPolicy::TYPE_INTERNAL_IMAGE, nsLiteralCString(IMAGE_ICON_MS)); 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 */ /* static */
nsresult nsIconChannel::GetIconWithGIO(nsIMozIconURI* aIconURI, nsresult nsIconChannel::GetIconWithGIO(nsIMozIconURI* aIconURI,
ByteBuf* aDataOut) { ByteBuf* aDataOut) {
@@ -253,7 +212,7 @@ nsresult nsIconChannel::GetIconWithGIO(nsIMozIconURI* aIconURI,
// Get default icon theme // Get default icon theme
GtkIconTheme* iconTheme = gtk_icon_theme_get_default(); GtkIconTheme* iconTheme = gtk_icon_theme_get_default();
// Get icon size and scale. // Get icon size and scale.
int32_t iconSize = GetIconSize(aIconURI); int32_t iconSize = aIconURI->GetImageSize();
int32_t scale = aIconURI->GetImageScale(); int32_t scale = aIconURI->GetImageScale();
RefPtr<GtkIconInfo> iconInfo; RefPtr<GtkIconInfo> iconInfo;

View File

@@ -38,11 +38,6 @@ using namespace mozilla::ipc;
static NS_DEFINE_CID(kThisIconURIImplementationCID, static NS_DEFINE_CID(kThisIconURIImplementationCID,
NS_THIS_ICONURI_IMPLEMENTATION_CID); 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, NS_IMPL_CLASSINFO(nsMozIconURI, nullptr, nsIClassInfo::THREADSAFE,
@@ -93,18 +88,12 @@ nsMozIconURI::GetSpec(nsACString& aSpec) {
} }
aSpec += "?size="; aSpec += "?size=";
if (mIconSize >= 0) { {
aSpec += kSizeStrings[mIconSize];
} else {
char buf[20]; char buf[20];
SprintfLiteral(buf, "%d", mSize); SprintfLiteral(buf, "%d", mSize);
aSpec.Append(buf); aSpec.Append(buf);
} }
if (mIconState >= 0) {
aSpec += "&state=";
aSpec += kStateStrings[mIconState];
}
if (!mContentType.IsEmpty()) { if (!mContentType.IsEmpty()) {
aSpec += "&contentType="; aSpec += "&contentType=";
@@ -217,8 +206,6 @@ nsresult nsMozIconURI::SetSpecInternal(const nsACString& aSpec) {
mContentType.Truncate(); mContentType.Truncate();
mFileName.Truncate(); mFileName.Truncate();
mStockIcon.Truncate(); mStockIcon.Truncate();
mIconSize = -1;
mIconState = -1;
mScale = 1; mScale = 1;
mDark.reset(); mDark.reset();
@@ -240,32 +227,12 @@ nsresult nsMozIconURI::SetSpecInternal(const nsACString& aSpec) {
nsAutoCString sizeString; nsAutoCString sizeString;
extractAttributeValue(iconSpec.get(), "size=", sizeString); extractAttributeValue(iconSpec.get(), "size=", sizeString);
if (!sizeString.IsEmpty()) { 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()); int32_t sizeValue = atoi(sizeString.get());
if (sizeValue > 0) { if (sizeValue > 0) {
mSize = sizeValue; 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; nsAutoCString scaleString;
extractAttributeValue(iconSpec.get(), "scale=", scaleString); extractAttributeValue(iconSpec.get(), "scale=", scaleString);
if (!scaleString.IsEmpty()) { if (!scaleString.IsEmpty()) {
@@ -491,8 +458,6 @@ nsresult nsMozIconURI::Clone(nsIURI** result) {
uri->mContentType = mContentType; uri->mContentType = mContentType;
uri->mFileName = mFileName; uri->mFileName = mFileName;
uri->mStockIcon = mStockIcon; uri->mStockIcon = mStockIcon;
uri->mIconSize = mIconSize;
uri->mIconState = mIconState;
uri.forget(result); uri.forget(result);
return NS_OK; return NS_OK;
@@ -586,26 +551,6 @@ nsMozIconURI::GetStockIcon(nsACString& aStockIcon) {
return NS_OK; 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) { void nsMozIconURI::Serialize(URIParams& aParams) {
IconURIParams params; IconURIParams params;
@@ -625,8 +570,6 @@ void nsMozIconURI::Serialize(URIParams& aParams) {
params.size() = mSize; params.size() = mSize;
params.fileName() = mFileName; params.fileName() = mFileName;
params.stockIcon() = mStockIcon; params.stockIcon() = mStockIcon;
params.iconSize() = mIconSize;
params.iconState() = mIconState;
params.iconScale() = mScale; params.iconScale() = mScale;
params.iconDark() = mDark; params.iconDark() = mDark;
@@ -654,18 +597,6 @@ bool nsMozIconURI::Deserialize(const URIParams& aParams) {
mFileName = params.fileName(); mFileName = params.fileName();
mStockIcon = params.stockIcon(); 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(); mScale = params.iconScale();
mDark = params.iconDark(); mDark = params.iconDark();

View File

@@ -46,10 +46,6 @@ class nsMozIconURI final : public nsIMozIconURI,
nsCString mFileName; // for if we don't have an actual file path, we're just nsCString mFileName; // for if we don't have an actual file path, we're just
// given a filename with an extension // given a filename with an extension
nsCString mStockIcon; 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; uint32_t mScale = 1;
mozilla::Maybe<bool> mDark; mozilla::Maybe<bool> mDark;

View File

@@ -64,12 +64,6 @@ interface nsIMozIconURI : nsIURI
/// stockIcon: The stock icon name requested from the OS. /// stockIcon: The stock icon name requested from the OS.
readonly attribute ACString stockIcon; 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. /// contentType: A valid mime type, or the empty string.
readonly attribute ACString contentType; readonly attribute ACString contentType;

View File

@@ -23,7 +23,7 @@ function run_test() {
// Make sure a valid file name icon URI can be created and that we can obtain // Make sure a valid file name icon URI can be created and that we can obtain
// all arguments, the spec, and the file extension. // 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 { try {
uri = ioService.newURI(currentSpec); uri = ioService.newURI(currentSpec);
} catch (e) { } catch (e) {
@@ -33,8 +33,7 @@ function run_test() {
exception = false; // reset exception value exception = false; // reset exception value
iconURI = uri.QueryInterface(Ci.nsIMozIconURI); iconURI = uri.QueryInterface(Ci.nsIMozIconURI);
Assert.equal(iconURI.iconSize, "button"); Assert.equal(iconURI.imageSize, 16);
Assert.equal(iconURI.iconState, "normal");
Assert.equal(iconURI.contentType, "bar"); Assert.equal(iconURI.contentType, "bar");
Assert.equal(iconURI.fileExtension, ".html"); Assert.equal(iconURI.fileExtension, ".html");

View File

@@ -62,8 +62,6 @@ struct IconURIParams
nsCString contentType; nsCString contentType;
nsCString fileName; nsCString fileName;
nsCString stockIcon; nsCString stockIcon;
int32_t iconSize;
int32_t iconState;
uint32_t iconScale; uint32_t iconScale;
bool? iconDark; bool? iconDark;
}; };

View File

@@ -35,7 +35,7 @@
<hbox> <hbox>
<vbox> <vbox>
#ifdef MOZ_WIDGET_GTK #ifdef MOZ_WIDGET_GTK
<image src="moz-icon://stock/gtk-dialog-warning?size=dialog"/> <image src="moz-icon://stock/gtk-dialog-warning?size=48"/>
#else #else
<image src="chrome://global/skin/icons/warning-large.png"/> <image src="chrome://global/skin/icons/warning-large.png"/>
#endif #endif

View File

@@ -20,20 +20,20 @@
/* ::::: Alert icons :::::*/ /* ::::: Alert icons :::::*/
.message-icon { .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-dialog #infoIcon,
.alert-icon { .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 { .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 { .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 { .authentication-icon {