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:
committed by
ealvarez@mozilla.com
parent
018f0bf1aa
commit
f088656bc3
@@ -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"],
|
||||
|
||||
@@ -145,47 +145,6 @@ static nsresult StreamToChannel(already_AddRefed<nsIInputStream> 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<GtkIconInfo> iconInfo;
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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<bool> mDark;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -62,8 +62,6 @@ struct IconURIParams
|
||||
nsCString contentType;
|
||||
nsCString fileName;
|
||||
nsCString stockIcon;
|
||||
int32_t iconSize;
|
||||
int32_t iconState;
|
||||
uint32_t iconScale;
|
||||
bool? iconDark;
|
||||
};
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
<hbox>
|
||||
<vbox>
|
||||
#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
|
||||
<image src="chrome://global/skin/icons/warning-large.png"/>
|
||||
#endif
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user