Bug 451263 - Implement moz-icon for Qt port. Add missing icon/qt directory part. r=vladimir.

This commit is contained in:
Oleg Romashin 2008-09-24 18:45:42 -05:00
parent 2590ca1022
commit 88bcb5a900
6 changed files with 573 additions and 0 deletions

View File

@ -0,0 +1,70 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is the Mozilla icon channel for Qt.
#
# The Initial Developer of the Original Code is Nokia
# Portions created by the Initial Developer are Copyright (C) 2008
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Oleg Romashin <romaxa@gmail.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = imgicon
LIBRARY_NAME = imgiconqt_s
LIBXUL_LIBRARY = 1
REQUIRES = xpcom \
string \
necko \
intl \
mimetype \
gtkqticonsconverter \
$(NULL)
CPPSRCS = nsIconChannel.cpp
LOCAL_INCLUDES += $(MOZ_QT_CFLAGS)
# we don't want the shared lib, but we want to force the creation of a static lib.
FORCE_STATIC_LIB = 1
# This library is used by other shared libs in a static build
FORCE_USE_PIC = 1
DIRS = public
EXTRA_PP_COMPONENTS = gtkqticonsconverter.js
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,173 @@
/* vim:set ts=2 sw=2 sts=2 cin et: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Mozilla icon channel for Qt.
*
* The Initial Developer of the Original Code is Nokia
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Oleg Romashin <romaxa@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
function GtkQtIconsConverter() { };
GtkQtIconsConverter.prototype = {
classDescription: "Gtk Qt stock icons converter",
classID: Components.ID("{c0783c34-a831-40c6-8c03-98c9f74cca45}"),
contractID: "@mozilla.org/gtkqticonsconverter;1",
QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsIGtkQtIconsConverter]),
convert: function(icon) { return this._gtk_qt_icons_table[icon]; },
_gtk_qt_icons_table: {
'about':
0,
'add':
0,
'apply':
44, /* QStyle::SP_DialogApplyButton */
'cancel':
39, /* QStyle::SP_DialogCancelButton */
'clear':
45, /* QStyle::SP_DialogResetButton */
'color-picker':
0,
'copy':
0,
'close':
43, /* QStyle::SP_DialogCloseButton */
'cut':
0,
'delete':
0,
'dialog-error':
0,
'dialog-info':
0,
'dialog-question':
12, /* QStyle::SP_MessageBoxQuestion */
'dialog-warning':
10, /* QStyle::SP_MessageBoxWarning */
'directory':
37, /* QStyle::SP_DirIcon */
'file':
24, /* QStyle::SP_FileIcon */
'find':
0,
'go-back-ltr':
53, /* QStyle::SP_ArrowBack */
'go-back-rtl':
53, /* QStyle::SP_ArrowBack */
'go-back':
53, /* QStyle::SP_ArrowBack */
'go-forward-ltr':
54, /* QStyle::SP_ArrowForward */
'go-forward-rtl':
54, /* QStyle::SP_ArrowForward */
'go-forward':
54, /* QStyle::SP_ArrowForward */
'go-up':
49, /* QStyle::SP_ArrowUp */
'goto-first':
0,
'goto-last':
0,
'help':
7, /* QStyle::SP_TitleBarContextHelpButton */
'home':
55, /* QStyle::SP_DirHomeIcon */
'info':
9, /* QStyle::SP_MessageBoxInformation */
'jump-to':
0,
'media-pause':
0,
'media-play':
0,
'network':
20, /* QStyle::SP_DriveNetIcon */
'no':
48, /* QStyle::SP_DialogNoButton */
'ok':
38, /* QStyle::SP_DialogOkButton */
'open':
21, /* QStyle::SP_DirOpenIcon */
'orientation-landscape':
0,
'orientation-portrait':
0,
'paste':
0,
'preferences':
34, /* QStyle::SP_FileDialogContentsView */
'print-preview':
0,
'print':
0,
'properties':
0,
'quit':
0,
'redo':
0,
'refresh':
58, /* QStyle::SP_BrowserReload */
'remove':
0,
'revert-to-saved':
0,
'save-as':
42, /* QStyle::SP_DialogSaveButton */
'save':
42, /* QStyle::SP_DialogSaveButton */
'select-all':
0,
'select-font':
0,
'stop':
59, /* QStyle::SP_BrowserStop */
'undelete':
0,
'undo':
0,
'yes':
47, /* QStyle::SP_DialogYesButton */
'zoom-100':
0,
'zoom-in':
0,
'zoom-out':
0
},
}
var components = [GtkQtIconsConverter];
function NSGetModule(compMgr, fileSpec) {
return XPCOMUtils.generateModule(components);
}

View File

@ -0,0 +1,161 @@
/* vim:set ts=2 sw=2 sts=2 cin et: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Mozilla icon channel for Qt.
*
* The Initial Developer of the Original Code is Nokia
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Oleg Romashin <romaxa@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include <stdlib.h>
#include <unistd.h>
#include "nsIMIMEService.h"
#include "nsIStringBundle.h"
#include "nsNetUtil.h"
#include "nsIURL.h"
#include "prlink.h"
#include "nsIconChannel.h"
#include "nsGtkQtIconsConverter.h"
#include <QIcon>
#include <QStyle>
#include <QApplication>
NS_IMPL_ISUPPORTS2(nsIconChannel,
nsIRequest,
nsIChannel)
static nsresult
moz_qicon_to_channel(QImage *image, nsIURI *aURI,
nsIChannel **aChannel)
{
NS_ENSURE_ARG_POINTER(image);
int width = image->width();
int height = image->height();
NS_ENSURE_TRUE(height < 256 && width < 256 && height > 0 && width > 0,
NS_ERROR_UNEXPECTED);
const int n_channels = 4;
long int buf_size = 2 + n_channels * height * width;
PRUint8 * const buf = (PRUint8*)NS_Alloc(buf_size);
NS_ENSURE_TRUE(buf, NS_ERROR_OUT_OF_MEMORY);
PRUint8 *out = buf;
*(out++) = width;
*(out++) = height;
const uchar * const pixels = image->bits();
int rowextra = image->bytesPerLine() - width * n_channels;
// encode the RGB data and the A data
const uchar * in = pixels;
for (int y = 0; y < height; ++y, in += rowextra) {
for (int x = 0; x < width; ++x) {
PRUint8 r = *(in++);
PRUint8 g = *(in++);
PRUint8 b = *(in++);
PRUint8 a = *(in++);
#define DO_PREMULTIPLY(c_) PRUint8(PRUint16(c_) * PRUint16(a) / PRUint16(255))
#ifdef IS_LITTLE_ENDIAN
*(out++) = DO_PREMULTIPLY(b);
*(out++) = DO_PREMULTIPLY(g);
*(out++) = DO_PREMULTIPLY(r);
*(out++) = a;
#else
*(out++) = a;
*(out++) = DO_PREMULTIPLY(r);
*(out++) = DO_PREMULTIPLY(g);
*(out++) = DO_PREMULTIPLY(b);
#endif
#undef DO_PREMULTIPLY
}
}
NS_ASSERTION(out == buf + buf_size, "size miscalculation");
nsresult rv;
nsCOMPtr<nsIStringInputStream> stream =
do_CreateInstance("@mozilla.org/io/string-input-stream;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = stream->AdoptData((char*)buf, buf_size);
NS_ENSURE_SUCCESS(rv, rv);
return NS_NewInputStreamChannel(aChannel, aURI, stream,
NS_LITERAL_CSTRING("image/icon"));
}
nsresult
nsIconChannel::Init(nsIURI* aURI)
{
nsCOMPtr<nsIMozIconURI> iconURI = do_QueryInterface(aURI);
NS_ASSERTION(iconURI, "URI is not an nsIMozIconURI");
nsCAutoString stockIcon;
iconURI->GetStockIcon(stockIcon);
nsCAutoString iconSizeString;
iconURI->GetIconSize(iconSizeString);
PRUint32 desiredImageSize;
iconURI->GetImageSize(&desiredImageSize);
nsCAutoString iconStateString;
iconURI->GetIconState(iconStateString);
bool disabled = iconStateString.EqualsLiteral("disabled");
QStyle::StandardPixmap sp_icon = (QStyle::StandardPixmap)0;
nsCOMPtr <nsIGtkQtIconsConverter> converter = do_GetService("@mozilla.org/gtkqticonsconverter;1");
if (converter) {
PRInt32 res = 0;
stockIcon.Cut(0,4);
converter->Convert(stockIcon.get(), &res);
sp_icon = (QStyle::StandardPixmap)res;
// printf("ConvertIcon: icon:'%s' -> res:%i\n", stockIcon.get(), res);
}
if (!sp_icon)
return NS_ERROR_FAILURE;
QStyle *style = qApp->style();
NS_ENSURE_TRUE(style, NS_ERROR_NULL_POINTER);
QPixmap pixmap = style->standardIcon(sp_icon).pixmap(desiredImageSize, desiredImageSize, disabled?QIcon::Disabled:QIcon::Normal);
QImage image = pixmap.toImage();
return moz_qicon_to_channel(&image, iconURI,
getter_AddRefs(mRealChannel));
}

View File

@ -0,0 +1,75 @@
/* vim:set ts=2 sw=2 sts=2 cin et: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Mozilla icon channel for Qt.
*
* The Initial Developer of the Original Code is Nokia
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Oleg Romashin <romaxa@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsIconChannel_h_
#define nsIconChannel_h_
#include "nsIChannel.h"
#include "nsIStreamListener.h"
#include "nsIURI.h"
#include "nsIIconURI.h"
#include "nsCOMPtr.h"
/**
* This class is the gnome implementation of nsIconChannel. It basically asks
* qt for an icon, and creates a new channel for
* that file to which all calls will be proxied.
*/
class nsIconChannel : public nsIChannel {
public:
NS_DECL_ISUPPORTS
NS_FORWARD_NSIREQUEST(mRealChannel->)
NS_FORWARD_NSICHANNEL(mRealChannel->)
nsIconChannel() {}
~nsIconChannel() {}
/**
* Called by nsIconProtocolHandler after it creates this channel.
* Must be called before calling any other function on this object.
* If this method fails, no other function must be called on this object.
*/
NS_HIDDEN_(nsresult) Init(nsIURI* aURI);
private:
/**
* The channel to the temp icon file (e.g. to /tmp/2qy9wjqw.html).
* Will always be non-null after a successful Init.
*/
nsCOMPtr<nsIChannel> mRealChannel;
};
#endif

View File

@ -0,0 +1,50 @@
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is the Mozilla icon channel for Qt.
#
# The Initial Developer of the Original Code is Nokia
# Portions created by the Initial Developer are Copyright (C) 2008
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Oleg Romashin <romaxa@gmail.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = gtkqticonsconverter
XPIDL_MODULE = gtkqticonsconverter
XPIDLSRCS = nsGtkQtIconsConverter.idl
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,44 @@
/* vim:set ts=2 sw=2 sts=2 cin et: */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Mozilla icon channel for Qt.
*
* The Initial Developer of the Original Code is Nokia
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Oleg Romashin <romaxa@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
[scriptable, uuid(c0783c34-a831-40c6-8c03-98c9f74cca45)]
interface nsIGtkQtIconsConverter : nsISupports
{
long convert(in string icon);
};