diff --git a/mozilla/allmakefiles.sh b/mozilla/allmakefiles.sh index 23ffe76499c..fc52b30e0bc 100755 --- a/mozilla/allmakefiles.sh +++ b/mozilla/allmakefiles.sh @@ -163,6 +163,7 @@ gfx/src/ps/Makefile gfx/src/psshared/Makefile gfx/src/photon/Makefile gfx/src/mac/Makefile +gfx/src/qt/Makefile gfx/src/xlib/Makefile gfx/src/os2/Makefile gfx/src/xlibrgb/Makefile @@ -540,6 +541,7 @@ webshell/tests/viewer/Makefile webshell/tests/viewer/public/Makefile webshell/tests/viewer/unix/Makefile webshell/tests/viewer/unix/gtk/Makefile +webshell/tests/viewer/unix/qt/Makefile webshell/tests/viewer/unix/xlib/Makefile " @@ -552,6 +554,7 @@ widget/src/build/Makefile widget/src/gtk/Makefile widget/src/gtksuperwin/Makefile widget/src/gtkxtbin/Makefile +widget/src/qt/Makefile widget/src/photon/Makefile widget/src/mac/Makefile widget/src/cocoa/Makefile diff --git a/mozilla/config/autoconf.mk.in b/mozilla/config/autoconf.mk.in index 1fb9c2207a3..544f86f492e 100644 --- a/mozilla/config/autoconf.mk.in +++ b/mozilla/config/autoconf.mk.in @@ -383,6 +383,7 @@ MOZ_ENABLE_CAIRO_GFX = @MOZ_ENABLE_CAIRO_GFX@ MOZ_ENABLE_GTK = @MOZ_ENABLE_GTK@ MOZ_ENABLE_GTK2 = @MOZ_ENABLE_GTK2@ MOZ_ENABLE_XLIB = @MOZ_ENABLE_XLIB@ +MOZ_ENABLE_QT = @MOZ_ENABLE_QT@ MOZ_ENABLE_PHOTON = @MOZ_ENABLE_PHOTON@ MOZ_ENABLE_COCOA = @MOZ_ENABLE_COCOA@ MOZ_ENABLE_XREMOTE = @MOZ_ENABLE_XREMOTE@ @@ -396,6 +397,9 @@ MOZ_GTK2_LIBS = @MOZ_GTK2_LIBS@ MOZ_XLIB_CFLAGS = @MOZ_XLIB_CFLAGS@ MOZ_XLIB_LDFLAGS = @MOZ_XLIB_LDFLAGS@ +MOZ_QT_CFLAGS = @MOZ_QT_CFLAGS@ +MOZ_QT_LDFLAGS = @MOZ_QT_LDFLAGS@ + MOZ_XPRINT_CFLAGS = @MOZ_XPRINT_CFLAGS@ MOZ_XPRINT_LDFLAGS = @MOZ_XPRINT_LDFLAGS@ MOZ_ENABLE_XPRINT = @MOZ_ENABLE_XPRINT@ diff --git a/mozilla/configure.in b/mozilla/configure.in index 6fdfb14c4ea..e73a2526f25 100644 --- a/mozilla/configure.in +++ b/mozilla/configure.in @@ -86,6 +86,8 @@ GLIB_VERSION=1.2.0 GTK_VERSION=1.2.0 LIBIDL_VERSION=0.6.3 PERL_VERSION=5.004 +QT_VERSION=3.2.0 +QT_VERSION_NUM=320 LIBART_VERSION=2.3.4 CAIRO_VERSION=0.1.17 GTK2_VERSION=1.3.7 @@ -3171,6 +3173,7 @@ MOZ_ARG_HEADER(Toolkit Options) [ _DEFAULT_TOOLKIT=$_PLATFORM_DEFAULT_TOOLKIT]) if test "$_DEFAULT_TOOLKIT" = "gtk" \ + -o "$_DEFAULT_TOOLKIT" = "qt" \ -o "$_DEFAULT_TOOLKIT" = "gtk2" \ -o "$_DEFAULT_TOOLKIT" = "xlib" \ -o "$_DEFAULT_TOOLKIT" = "os2" \ @@ -3187,7 +3190,7 @@ MOZ_ARG_HEADER(Toolkit Options) MOZ_WIDGET_TOOLKIT=`echo "$_DEFAULT_TOOLKIT" | sed -e "s/,.*$//"` else if test "$no_x" != "yes"; then - AC_MSG_ERROR([Toolkit must be xlib, gtk or gtk2.]) + AC_MSG_ERROR([Toolkit must be xlib, gtk, gtk2 or qt.]) else AC_MSG_ERROR([Toolkit must be $_PLATFORM_DEFAULT_TOOLKIT.]) fi @@ -3223,6 +3226,13 @@ xlib) AC_DEFINE(MOZ_WIDGET_XLIB) ;; +qt) + MOZ_ENABLE_QT=1 + TK_CFLAGS='$(MOZ_QT_CFLAGS)' + TK_LIBS='$(MOZ_QT_LDFLAGS)' + AC_DEFINE(MOZ_WIDGET_QT) + ;; + photon) MOZ_ENABLE_PHOTON=1 AC_DEFINE(MOZ_WIDGET_PHOTON) @@ -3290,6 +3300,75 @@ then MOZ_XLIB_LDFLAGS="$MOZ_XLIB_LDFLAGS $XEXT_LIBS $X11_LIBS" fi +if test "$MOZ_ENABLE_QT" +then + MOZ_ARG_WITH_STRING(qtdir, + [ --with-qtdir=\$dir Specify Qt directory ], + [ QTDIR=$withval]) + + if test -z "$QTDIR"; then + QTDIR="/usr" + fi + QTINCDIR="/include/qt" + if test ! -d "$QTDIR$QTINCDIR"; then + QTINCDIR="/include/X11/qt" + fi + if test ! -d "$QTDIR$QTINCDIR"; then + QTINCDIR="/include" + fi + + if test -x "$QTDIR/bin/moc"; then + HOST_MOC="$QTDIR/bin/moc" + else + AC_CHECK_PROGS(HOST_MOC, moc, "") + fi + if test -z "$HOST_MOC"; then + AC_MSG_ERROR([no acceptable moc preprocessor found]) + fi + MOC=$HOST_MOC + + QT_CFLAGS="-I${QTDIR}${QTINCDIR} -DQT_GENUINE_STR -DQT_NO_STL" + if test -z "$MOZ_DEBUG"; then + QT_CFLAGS="$QT_CFLAGS -DQT_NO_DEBUG -DNO_DEBUG" + fi + _SAVE_LDFLAGS=$LDFLAGS + QT_LDFLAGS=-L${QTDIR}/lib + LDFLAGS="$LDFLAGS $QT_LDFLAGS" + AC_LANG_SAVE + AC_LANG_CPLUSPLUS + AC_CHECK_LIB(qt, main, QT_LIB=-lqt, + AC_CHECK_LIB(qt-mt, main, QT_LIB=-lqt-mt, + AC_MSG_ERROR([Cannot find QT libraries.]))) + LDFLAGS=$_SAVE_LDFLAGS + QT_LIBS="-L/usr/X11R6/lib $QT_LDFLAGS $QT_LIB -lXext -lX11" + + MOZ_QT_LDFLAGS=$QT_LIBS + MOZ_QT_CFLAGS=$QT_CFLAGS + + _SAVE_CXXFLAGS=$CXXFLAGS + _SAVE_LIBS=$LIBS + + CXXFLAGS="$CXXFLAGS $QT_CFLAGS" + LIBS="$LIBS $QT_LIBS" + + AC_MSG_CHECKING(Qt - version >= $QT_VERSION) + AC_TRY_COMPILE([#include ], + [ + #if (QT_VERSION < $QT_VERSION_NUM) + #error "QT_VERSION too old" + #endif + ],result="yes",result="no") + + AC_MSG_RESULT("$result") + if test "$result" = "no"; then + AC_MSG_ERROR([Qt Mozilla requires at least version $QT_VERSION of Qt]) + fi + CXXFLAGS=$_SAVE_CXXFLAGS + LIBS=$_SAVE_LIBS + + AC_LANG_RESTORE +fi + AC_SUBST(MOZ_DEFAULT_TOOLKIT) AC_SUBST(GTK_CONFIG) @@ -3301,6 +3380,7 @@ AC_SUBST(MOZ_ENABLE_CAIRO) AC_SUBST(MOZ_ENABLE_GTK) AC_SUBST(MOZ_ENABLE_XLIB) AC_SUBST(MOZ_ENABLE_GTK2) +AC_SUBST(MOZ_ENABLE_QT) AC_SUBST(MOZ_ENABLE_PHOTON) AC_SUBST(MOZ_ENABLE_COCOA) AC_SUBST(MOZ_ENABLE_CAIRO_GFX) @@ -3311,10 +3391,13 @@ AC_SUBST(MOZ_GTK2_CFLAGS) AC_SUBST(MOZ_GTK2_LIBS) AC_SUBST(MOZ_XLIB_CFLAGS) AC_SUBST(MOZ_XLIB_LDFLAGS) +AC_SUBST(MOZ_QT_CFLAGS) +AC_SUBST(MOZ_QT_LDFLAGS) AC_SUBST(MOC) if test "$MOZ_ENABLE_GTK" \ +|| test "$MOZ_ENABLE_QT" \ || test "$MOZ_ENABLE_XLIB" \ || test "$MOZ_ENABLE_GTK2" then diff --git a/mozilla/embedding/browser/qt/Makefile.in b/mozilla/embedding/browser/qt/Makefile.in new file mode 100644 index 00000000000..e45495e260a --- /dev/null +++ b/mozilla/embedding/browser/qt/Makefile.in @@ -0,0 +1,13 @@ +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = qgeckoembed +DIRS=src tests + +PACKAGE_FILE = qgeckoembed.pkg + +include $(topsrcdir)/config/rules.mk diff --git a/mozilla/embedding/browser/qt/qgeckoembed.pkg b/mozilla/embedding/browser/qt/qgeckoembed.pkg new file mode 100644 index 00000000000..ffbbf8cb9d6 --- /dev/null +++ b/mozilla/embedding/browser/qt/qgeckoembed.pkg @@ -0,0 +1,3 @@ +[qeckoembed] +dist/bin/@DLLP@qeckoembed@DLLS@ +dist/bin/TestQeckoEmbed diff --git a/mozilla/embedding/browser/qt/src/EmbedContentListener.cpp b/mozilla/embedding/browser/qt/src/EmbedContentListener.cpp new file mode 100644 index 00000000000..04a03756913 --- /dev/null +++ b/mozilla/embedding/browser/qt/src/EmbedContentListener.cpp @@ -0,0 +1,160 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Zack Rusin + * + * 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 +#include + +#include "nsIURI.h" + +#include "EmbedContentListener.h" +#include "qgeckoembed.h" + +#include "nsICategoryManager.h" +#include "nsIServiceManagerUtils.h" + +EmbedContentListener::EmbedContentListener(QGeckoEmbed *aOwner) +{ + mOwner = aOwner; +} + +EmbedContentListener::~EmbedContentListener() +{ +} + +NS_IMPL_ISUPPORTS2(EmbedContentListener, + nsIURIContentListener, + nsISupportsWeakReference) + +NS_IMETHODIMP +EmbedContentListener::OnStartURIOpen(nsIURI *aURI, + PRBool *aAbortOpen) +{ + nsresult rv; + + nsCAutoString specString; + rv = aURI->GetSpec(specString); + + if (NS_FAILED(rv)) + return rv; + + //we stop loading here because we want to pass the + //control to kio to check for mimetypes and all the other jazz + bool abort = false; + mOwner->startURIOpen(specString.get(), abort); + *aAbortOpen = abort; + + return NS_OK; +} + +NS_IMETHODIMP +EmbedContentListener::DoContent(const char *aContentType, + PRBool aIsContentPreferred, + nsIRequest *aRequest, + nsIStreamListener **aContentHandler, + PRBool *aAbortProcess) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +EmbedContentListener::IsPreferred(const char *aContentType, + char **aDesiredContentType, + PRBool *aCanHandleContent) +{ + return CanHandleContent(aContentType, PR_TRUE, aDesiredContentType, + aCanHandleContent); +} + +NS_IMETHODIMP +EmbedContentListener::CanHandleContent(const char *aContentType, + PRBool aIsContentPreferred, + char **aDesiredContentType, + PRBool *_retval) +{ + *_retval = PR_FALSE; + qDebug("HANDLING:"); + + if (aContentType) { + nsCOMPtr catMgr; + nsresult rv; + catMgr = do_GetService("@mozilla.org/categorymanager;1", &rv); + NS_ENSURE_SUCCESS(rv, rv); + nsXPIDLCString value; + rv = catMgr->GetCategoryEntry("Gecko-Content-Viewers", + aContentType, + getter_Copies(value)); + + // If the category manager can't find what we're looking for + // it returns NS_ERROR_NOT_AVAILABLE, we don't want to propagate + // that to the caller since it's really not a failure + + if (NS_FAILED(rv) && rv != NS_ERROR_NOT_AVAILABLE) + return rv; + + if (value && *value) + *_retval = PR_TRUE; + } + + qDebug("\tCan handle content %s: %d", aContentType, *_retval); + return NS_OK; +} + +NS_IMETHODIMP +EmbedContentListener::GetLoadCookie(nsISupports **aLoadCookie) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +EmbedContentListener::SetLoadCookie(nsISupports *aLoadCookie) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +EmbedContentListener::GetParentContentListener(nsIURIContentListener **aParent) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +EmbedContentListener::SetParentContentListener(nsIURIContentListener *aParent) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + diff --git a/mozilla/embedding/browser/qt/src/EmbedContentListener.h b/mozilla/embedding/browser/qt/src/EmbedContentListener.h new file mode 100644 index 00000000000..5a76bcfdfe2 --- /dev/null +++ b/mozilla/embedding/browser/qt/src/EmbedContentListener.h @@ -0,0 +1,64 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 EMBEDCONTENTLISTENER_H +#define EMBEDCONTENTLISTENER_H + +#include +#include + +class QGeckoEmbed; + +class EmbedContentListener : public nsIURIContentListener, + public nsSupportsWeakReference +{ +public: + + EmbedContentListener(QGeckoEmbed *aOwner); + ~EmbedContentListener(); + + NS_DECL_ISUPPORTS + + NS_DECL_NSIURICONTENTLISTENER + +private: + QGeckoEmbed *mOwner; +}; + +#endif diff --git a/mozilla/embedding/browser/qt/src/EmbedEventListener.cpp b/mozilla/embedding/browser/qt/src/EmbedEventListener.cpp new file mode 100644 index 00000000000..9ab54f250d0 --- /dev/null +++ b/mozilla/embedding/browser/qt/src/EmbedEventListener.cpp @@ -0,0 +1,271 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Zack Rusin + * + * 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 "EmbedEventListener.h" + +#include +#include + +#include "nsIDOMKeyEvent.h" +#include "nsIDOMUIEvent.h" + +#include "EmbedEventListener.h" +#include "qgeckoembed.h" + +EmbedEventListener::EmbedEventListener(QGeckoEmbed *aOwner) +{ + mOwner = aOwner; +} + +EmbedEventListener::~EmbedEventListener() +{ + +} + +NS_IMPL_ADDREF(EmbedEventListener) +NS_IMPL_RELEASE(EmbedEventListener) +NS_INTERFACE_MAP_BEGIN(EmbedEventListener) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMKeyListener) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIDOMEventListener, nsIDOMKeyListener) + NS_INTERFACE_MAP_ENTRY(nsIDOMKeyListener) + NS_INTERFACE_MAP_ENTRY(nsIDOMMouseListener) + NS_INTERFACE_MAP_ENTRY(nsIDOMUIListener) +NS_INTERFACE_MAP_END + +NS_IMETHODIMP +EmbedEventListener::HandleEvent(nsIDOMEvent* aEvent) +{ + return NS_OK; +} + +NS_IMETHODIMP +EmbedEventListener::KeyDown(nsIDOMEvent* aDOMEvent) +{ + nsCOMPtr keyEvent; + keyEvent = do_QueryInterface(aDOMEvent); + if (!keyEvent) + return NS_OK; + + // Return FALSE to this function to mark the event as not + // consumed ? + bool returnVal = mOwner->domKeyDownEvent(keyEvent); + + if (returnVal) { + aDOMEvent->StopPropagation(); + aDOMEvent->PreventDefault(); + } + return NS_OK; +} + +NS_IMETHODIMP +EmbedEventListener::KeyUp(nsIDOMEvent* aDOMEvent) +{ + nsCOMPtr keyEvent; + keyEvent = do_QueryInterface(aDOMEvent); + if (!keyEvent) + return NS_OK; + // return FALSE to this function to mark this event as not + // consumed... + + bool returnVal = mOwner->domKeyUpEvent(keyEvent); + if (returnVal) { + aDOMEvent->StopPropagation(); + aDOMEvent->PreventDefault(); + } + + return NS_OK; +} + +NS_IMETHODIMP +EmbedEventListener::KeyPress(nsIDOMEvent* aDOMEvent) +{ + nsCOMPtr keyEvent; + keyEvent = do_QueryInterface(aDOMEvent); + if (!keyEvent) + return NS_OK; + + // return FALSE to this function to mark this event as not + // consumed... + bool returnVal = mOwner->domKeyPressEvent(keyEvent); + if (returnVal) { + aDOMEvent->StopPropagation(); + aDOMEvent->PreventDefault(); + } + return NS_OK; +} + +NS_IMETHODIMP +EmbedEventListener::MouseDown(nsIDOMEvent* aDOMEvent) +{ + nsCOMPtr mouseEvent; + mouseEvent = do_QueryInterface(aDOMEvent); + if (!mouseEvent) + return NS_OK; + // return FALSE to this function to mark this event as not + // consumed... + + bool returnVal = mOwner->domMouseDownEvent(mouseEvent); + if (returnVal) { + aDOMEvent->StopPropagation(); + aDOMEvent->PreventDefault(); + } + + return NS_OK; +} + +NS_IMETHODIMP +EmbedEventListener::MouseUp(nsIDOMEvent* aDOMEvent) +{ + nsCOMPtr mouseEvent; + mouseEvent = do_QueryInterface(aDOMEvent); + if (!mouseEvent) + return NS_OK; + // Return FALSE to this function to mark the event as not + // consumed... + + bool returnVal = mOwner->domMouseUpEvent(mouseEvent); + if (returnVal) { + aDOMEvent->StopPropagation(); + aDOMEvent->PreventDefault(); + } + return NS_OK; +} + +NS_IMETHODIMP +EmbedEventListener::MouseClick(nsIDOMEvent* aDOMEvent) +{ + nsCOMPtr mouseEvent; + mouseEvent = do_QueryInterface(aDOMEvent); + if (!mouseEvent) + return NS_OK; + // Return FALSE to this function to mark the event as not + // consumed... + bool returnVal = mOwner->domMouseClickEvent(mouseEvent); + if (returnVal) { + aDOMEvent->StopPropagation(); + aDOMEvent->PreventDefault(); + } + return NS_OK; +} + +NS_IMETHODIMP +EmbedEventListener::MouseDblClick(nsIDOMEvent* aDOMEvent) +{ + nsCOMPtr mouseEvent; + mouseEvent = do_QueryInterface(aDOMEvent); + if (!mouseEvent) + return NS_OK; + // return FALSE to this function to mark this event as not + // consumed... + bool returnVal = mOwner->domMouseDblClickEvent(mouseEvent); + if (returnVal) { + aDOMEvent->StopPropagation(); + aDOMEvent->PreventDefault(); + } + return NS_OK; +} + +NS_IMETHODIMP +EmbedEventListener::MouseOver(nsIDOMEvent* aDOMEvent) +{ + nsCOMPtr mouseEvent; + mouseEvent = do_QueryInterface(aDOMEvent); + if (!mouseEvent) + return NS_OK; + // return FALSE to this function to mark this event as not + // consumed... + bool returnVal = mOwner->domMouseOverEvent(mouseEvent); + if (returnVal) { + aDOMEvent->StopPropagation(); + aDOMEvent->PreventDefault(); + } + return NS_OK; +} + +NS_IMETHODIMP +EmbedEventListener::MouseOut(nsIDOMEvent* aDOMEvent) +{ + nsCOMPtr mouseEvent; + mouseEvent = do_QueryInterface(aDOMEvent); + if (!mouseEvent) + return NS_OK; + // return FALSE to this function to mark this event as not + // consumed... + bool returnVal = mOwner->domMouseOutEvent(mouseEvent); + if (returnVal) { + aDOMEvent->StopPropagation(); + aDOMEvent->PreventDefault(); + } + return NS_OK; +} + +NS_IMETHODIMP +EmbedEventListener::Activate(nsIDOMEvent* aDOMEvent) +{ + nsCOMPtr uiEvent = do_QueryInterface(aDOMEvent); + if (!uiEvent) + return NS_OK; + // return NS_OK to this function to mark this event as not + // consumed... + + return mOwner->domActivateEvent(uiEvent); +} + +NS_IMETHODIMP +EmbedEventListener::FocusIn(nsIDOMEvent* aDOMEvent) +{ + nsCOMPtr uiEvent = do_QueryInterface(aDOMEvent); + if (!uiEvent) + return NS_OK; + // return NS_OK to this function to mark this event as not + // consumed... + + return mOwner->domFocusInEvent(uiEvent); +} + +NS_IMETHODIMP +EmbedEventListener::FocusOut(nsIDOMEvent* aDOMEvent) +{ + nsCOMPtr uiEvent = do_QueryInterface(aDOMEvent); + if (!uiEvent) + return NS_OK; + // return NS_OK to this function to mark this event as not + // consumed... + + return mOwner->domFocusOutEvent(uiEvent); +} diff --git a/mozilla/embedding/browser/qt/src/EmbedEventListener.h b/mozilla/embedding/browser/qt/src/EmbedEventListener.h new file mode 100644 index 00000000000..9b7e1d81d32 --- /dev/null +++ b/mozilla/embedding/browser/qt/src/EmbedEventListener.h @@ -0,0 +1,89 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 EMBEDEVENTLISTENER_H +#define EMBEDEVENTLISTENER_H + +#include +#include +#include + +class QGeckoEmbed; + +class EmbedEventListener : public nsIDOMKeyListener, + public nsIDOMMouseListener, + public nsIDOMUIListener +{ +public: + EmbedEventListener(QGeckoEmbed *q); + ~EmbedEventListener(); + + NS_DECL_ISUPPORTS + + // nsIDOMEventListener + + NS_IMETHOD HandleEvent(nsIDOMEvent* aEvent); + + // nsIDOMKeyListener + + NS_IMETHOD KeyDown(nsIDOMEvent* aDOMEvent); + NS_IMETHOD KeyUp(nsIDOMEvent* aDOMEvent); + NS_IMETHOD KeyPress(nsIDOMEvent* aDOMEvent); + + // nsIDOMMouseListener + + NS_IMETHOD MouseDown(nsIDOMEvent* aDOMEvent); + NS_IMETHOD MouseUp(nsIDOMEvent* aDOMEvent); + NS_IMETHOD MouseClick(nsIDOMEvent* aDOMEvent); + NS_IMETHOD MouseDblClick(nsIDOMEvent* aDOMEvent); + NS_IMETHOD MouseOver(nsIDOMEvent* aDOMEvent); + NS_IMETHOD MouseOut(nsIDOMEvent* aDOMEvent); + + // nsIDOMUIListener + + NS_IMETHOD Activate(nsIDOMEvent* aDOMEvent); + NS_IMETHOD FocusIn(nsIDOMEvent* aDOMEvent); + NS_IMETHOD FocusOut(nsIDOMEvent* aDOMEvent); + +private: + + QGeckoEmbed *mOwner; +}; + +#endif diff --git a/mozilla/embedding/browser/qt/src/EmbedGlobalHistory.cpp b/mozilla/embedding/browser/qt/src/EmbedGlobalHistory.cpp new file mode 100644 index 00000000000..6bcfec40161 --- /dev/null +++ b/mozilla/embedding/browser/qt/src/EmbedGlobalHistory.cpp @@ -0,0 +1,74 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Zack Rusin + * + * 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 "EmbedGlobalHistory.h" + +#include + +/* Implementation file */ +NS_IMPL_ISUPPORTS1(EmbedGlobalHistory, nsIGlobalHistory) + +EmbedGlobalHistory::EmbedGlobalHistory() +{ + /* member initializers and constructor code */ +} + +EmbedGlobalHistory::~EmbedGlobalHistory() +{ + /* destructor code */ +} + +/* void addPage (in string aURL); */ +NS_IMETHODIMP EmbedGlobalHistory::AddPage(const char *aURL) +{ + qDebug("here"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* boolean isVisited (in string aURL); */ +NS_IMETHODIMP EmbedGlobalHistory::IsVisited(const char *aURL, PRBool *_retval) +{ + qDebug("HERE"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP EmbedGlobalHistory::Init() +{ + qDebug("initing embedglobal"); + return NS_OK; +} diff --git a/mozilla/embedding/browser/qt/src/EmbedGlobalHistory.h b/mozilla/embedding/browser/qt/src/EmbedGlobalHistory.h new file mode 100644 index 00000000000..92ef2955fcd --- /dev/null +++ b/mozilla/embedding/browser/qt/src/EmbedGlobalHistory.h @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 EMBEDGLOBALHISTORY_H +#define EMBEDGLOBALHISTORY_H + +#include "nsIGlobalHistory.h" + +#define NS_EMBEDGLOBALHISTORY_CID \ + { 0x2f977d51, 0x5485, 0x11d4, \ + { 0x87, 0xe2, 0x00, 0x10, 0xa4, 0xe7, 0x5e, 0xf2 } } + +/* Header file */ +class EmbedGlobalHistory : public nsIGlobalHistory +{ +public: + EmbedGlobalHistory(); + + NS_DECL_ISUPPORTS + NS_DECL_NSIGLOBALHISTORY + + NS_IMETHOD Init(); + + + +private: + ~EmbedGlobalHistory(); +}; + +#endif diff --git a/mozilla/embedding/browser/qt/src/EmbedModules.cpp b/mozilla/embedding/browser/qt/src/EmbedModules.cpp new file mode 100644 index 00000000000..95e8c5d64a4 --- /dev/null +++ b/mozilla/embedding/browser/qt/src/EmbedModules.cpp @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Zack Rusin + * + * 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 "nsIGenericFactory.h" +#include "EmbedGlobalHistory.h" +#include "nsIGlobalHistory.h" + +#if 0 +NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(EmbedGlobalHistory, Init) + +static const nsModuleComponentInfo components[] = +{ + { "Global History", + NS_EMBEDGLOBALHISTORY_CID, + "@mozilla.org/browser/global-history;1", + EmbedGlobalHistoryConstructor, + } +}; + +NS_IMPL_NSGETMODULE("Qt components", components) +#endif diff --git a/mozilla/embedding/browser/qt/src/EmbedProgress.cpp b/mozilla/embedding/browser/qt/src/EmbedProgress.cpp new file mode 100644 index 00000000000..d1f934e05e9 --- /dev/null +++ b/mozilla/embedding/browser/qt/src/EmbedProgress.cpp @@ -0,0 +1,191 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 "EmbedProgress.h" + +#include "qgeckoembed.h" + +#include +#include +#include +#include + +#include "nsIURI.h" +#include "nsCRT.h" +#include "nsString.h" + +EmbedProgress::EmbedProgress(QGeckoEmbed *aOwner) +{ + qDebug("XXX EMBEDPROGRSS"); + mOwner = aOwner; +} + +EmbedProgress::~EmbedProgress() +{ + qDebug("#########################################################################################"); +} + +NS_IMPL_ISUPPORTS2(EmbedProgress, + nsIWebProgressListener, + nsISupportsWeakReference) + +NS_IMETHODIMP +EmbedProgress::OnStateChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, + PRUint32 aStateFlags, + nsresult aStatus) +{ + // give the widget a chance to attach any listeners + mOwner->contentStateChanged(); + // if we've got the start flag, emit the signal + if ((aStateFlags & STATE_IS_NETWORK) && + (aStateFlags & STATE_START)) + { + qDebug("net start"); + emit mOwner->netStart(); + } + + //XXX: emit state all here + + if ((aStateFlags & STATE_IS_NETWORK) && + (aStateFlags & STATE_STOP)) { + //qDebug("progress: --stop"); + emit mOwner->netStop(); + mOwner->contentFinishedLoading(); + } + + return NS_OK; +} + +NS_IMETHODIMP +EmbedProgress::OnProgressChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, + PRInt32 aCurSelfProgress, + PRInt32 aMaxSelfProgress, + PRInt32 aCurTotalProgress, + PRInt32 aMaxTotalProgress) +{ +#if 0 + nsString tmpString; + RequestToURIString(aRequest, tmpString); + // is it the same as the current uri? + if (mOwner->mURI.Equals(tmpString)) + mOwner->progressAll(QString(tmpString.get()), aCurTotalProgress, aMaxTotalProgress); +#endif + //qDebug("progress self: %d %d", aCurSelfProgress, aMaxSelfProgress); + + mOwner->progress(aCurTotalProgress, aMaxTotalProgress); + return NS_OK; +} + +NS_IMETHODIMP +EmbedProgress::OnLocationChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, + nsIURI *aLocation) +{ + nsCAutoString newURI; + NS_ENSURE_ARG_POINTER(aLocation); + aLocation->GetSpec(newURI); + + // Make sure that this is the primary frame change and not + // just a subframe. + PRBool isSubFrameLoad = PR_FALSE; + if (aWebProgress) { + nsCOMPtr domWindow; + nsCOMPtr topDomWindow; + + aWebProgress->GetDOMWindow(getter_AddRefs(domWindow)); + + // get the root dom window + if (domWindow) + domWindow->GetTop(getter_AddRefs(topDomWindow)); + + if (domWindow != topDomWindow) + isSubFrameLoad = PR_TRUE; + } + + if (!isSubFrameLoad) + emit mOwner->locationChanged(newURI.get()); + + return NS_OK; +} + +NS_IMETHODIMP +EmbedProgress::OnStatusChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, + nsresult aStatus, + const PRUnichar *aMessage) +{ + QString message = QString::fromUcs2(aMessage); + emit mOwner->linkMessage(message); + + return NS_OK; +} + +NS_IMETHODIMP +EmbedProgress::OnSecurityChange(nsIWebProgress *aWebProgress, + nsIRequest *aRequest, + PRUint32 aState) +{ + //FIXME: + //emit mOwner->securityChange(aRequest, aState); + + return NS_OK; +} + +/* static */ +void +EmbedProgress::RequestToURIString(nsIRequest *aRequest, nsString &aString) +{ + // is it a channel + nsCOMPtr channel; + channel = do_QueryInterface(aRequest); + if (!channel) + return; + + nsCOMPtr uri; + channel->GetURI(getter_AddRefs(uri)); + if (!uri) + return; + + nsCAutoString uriString; + uri->GetSpec(uriString); + + CopyUTF8toUTF16(uriString, aString); +} diff --git a/mozilla/embedding/browser/qt/src/EmbedProgress.h b/mozilla/embedding/browser/qt/src/EmbedProgress.h new file mode 100644 index 00000000000..4241f533e31 --- /dev/null +++ b/mozilla/embedding/browser/qt/src/EmbedProgress.h @@ -0,0 +1,68 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 EMBEDPROGRESS_H +#define EMBEDPROGRESS_H + +#include +#include + +#include "nsStringFwd.h" + +class QGeckoEmbed; + +class EmbedProgress : public nsIWebProgressListener, + public nsSupportsWeakReference +{ +public: + EmbedProgress(QGeckoEmbed *aOwner); + ~EmbedProgress(); + + NS_DECL_ISUPPORTS + + NS_DECL_NSIWEBPROGRESSLISTENER + +private: + + static void RequestToURIString(nsIRequest *aRequest, nsString &aString); + + QGeckoEmbed *mOwner; +}; + +#endif diff --git a/mozilla/embedding/browser/qt/src/EmbedStream.cpp b/mozilla/embedding/browser/qt/src/EmbedStream.cpp new file mode 100644 index 00000000000..5948a85abee --- /dev/null +++ b/mozilla/embedding/browser/qt/src/EmbedStream.cpp @@ -0,0 +1,316 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 +#include +#include +#include +#include +#include +#include + +#include "nsXPCOMCID.h" +#include "nsICategoryManager.h" + +#include "nsIContentViewer.h" + +#include "EmbedStream.h" +#include "qgeckoembed.h" +#include "EmbedWindow.h" +#include "nsReadableUtils.h" + +// nsIInputStream interface + +NS_IMPL_ISUPPORTS1(EmbedStream, nsIInputStream) + + EmbedStream::EmbedStream() +{ + mOwner = nsnull; + mOffset = 0; + mDoingStream = PR_FALSE; +} + +EmbedStream::~EmbedStream() +{ +} + +void +EmbedStream::InitOwner(QGeckoEmbed *aOwner) +{ + mOwner = aOwner; +} + +NS_METHOD +EmbedStream::Init(void) +{ + nsresult rv = NS_OK; + + nsCOMPtr bufInStream; + nsCOMPtr bufOutStream; + + rv = NS_NewPipe(getter_AddRefs(bufInStream), + getter_AddRefs(bufOutStream)); + + if (NS_FAILED(rv)) return rv; + + mInputStream = bufInStream; + mOutputStream = bufOutStream; + return NS_OK; +} + +NS_METHOD +EmbedStream::OpenStream(const char *aBaseURI, const char *aContentType) +{ + qDebug("==================> OpenStream: %s (%s)", aBaseURI, aContentType); + NS_ENSURE_ARG_POINTER(aBaseURI); + NS_ENSURE_ARG_POINTER(aContentType); + + nsresult rv = NS_OK; + + // if we're already doing a stream then close the current one + if (mDoingStream) + CloseStream(); + + // set our state + mDoingStream = PR_TRUE; + + // initialize our streams + rv = Init(); + if (NS_FAILED(rv)) + return rv; + + // get the content area of our web browser + nsCOMPtr browser; + + + mOwner->window()->GetWebBrowser(getter_AddRefs(browser)); + + // get the viewer container + nsCOMPtr viewerContainer; + viewerContainer = do_GetInterface(browser); + + // create a new uri object + nsCOMPtr uri; + nsCAutoString spec(aBaseURI); + rv = NS_NewURI(getter_AddRefs(uri), spec.get()); + + if (NS_FAILED(rv)) + return rv; + + // create a new load group + rv = NS_NewLoadGroup(getter_AddRefs(mLoadGroup), nsnull); + if (NS_FAILED(rv)) + return rv; + + // create a new input stream channel + rv = NS_NewInputStreamChannel(getter_AddRefs(mChannel), uri, + this, + nsDependentCString(aContentType), + EmptyCString()); + if (NS_FAILED(rv)) + return rv; + + // set the channel's load group + rv = mChannel->SetLoadGroup(mLoadGroup); + if (NS_FAILED(rv)) + return rv; + + // find a document loader for this content type + + nsXPIDLCString docLoaderContractID; + nsCOMPtr catMan(do_GetService(NS_CATEGORYMANAGER_CONTRACTID, &rv)); + if (NS_FAILED(rv)) + return rv; + rv = catMan->GetCategoryEntry("Gecko-Content-Viewers", aContentType, + getter_Copies(docLoaderContractID)); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr docLoaderFactory; + docLoaderFactory = do_GetService(docLoaderContractID.get(), &rv); + if (NS_FAILED(rv)) + return rv; + + // ok, create an instance of the content viewer for that command and + // mime type + nsCOMPtr contentViewer; + rv = docLoaderFactory->CreateInstance("view", mChannel, mLoadGroup, + aContentType, viewerContainer, + nsnull, + getter_AddRefs(mStreamListener), + getter_AddRefs(contentViewer)); + if (NS_FAILED(rv)) + return rv; + + // set the container viewer container for this content view + rv = contentViewer->SetContainer(viewerContainer); + if (NS_FAILED(rv)) + return rv; + + // embed this sucker + rv = viewerContainer->Embed(contentViewer, "view", nsnull); + if (NS_FAILED(rv)) + return rv; + + // start our request + nsCOMPtr request = do_QueryInterface(mChannel); + rv = mStreamListener->OnStartRequest(request, NULL); + if (NS_FAILED(rv)) + return rv; + + return NS_OK; +} + +NS_METHOD +EmbedStream::AppendToStream(const char *aData, PRInt32 aLen) +{ + nsresult rv; + + // append the data + rv = Append(aData, aLen); + if (NS_FAILED(rv)) + return rv; + + // notify our listeners + nsCOMPtr request = do_QueryInterface(mChannel); + rv = mStreamListener->OnDataAvailable(request, + NULL, + NS_STATIC_CAST(nsIInputStream *, this), + mOffset, /* offset */ + aLen); /* len */ + // move our counter + mOffset += aLen; + if (NS_FAILED(rv)) + return rv; + + return NS_OK; +} + +NS_METHOD +EmbedStream::CloseStream(void) +{ + nsresult rv = NS_OK; + + NS_ENSURE_STATE(mDoingStream); + mDoingStream = PR_FALSE; + + nsCOMPtr request = do_QueryInterface(mChannel, &rv); + if (NS_FAILED(rv)) + goto loser; + + rv = mStreamListener->OnStopRequest(request, NULL, NS_OK); + if (NS_FAILED(rv)) + return rv; + + loser: + mLoadGroup = nsnull; + mChannel = nsnull; + mStreamListener = nsnull; + mOffset = 0; + + return rv; +} + +NS_METHOD +EmbedStream::Append(const char *aData, PRUint32 aLen) +{ + nsresult rv = NS_OK; + PRUint32 bytesWritten = 0; + rv = mOutputStream->Write(aData, aLen, &bytesWritten); + if (NS_FAILED(rv)) + return rv; + + NS_ASSERTION(bytesWritten == aLen, + "underlying byffer couldn't handle the write"); + return rv; +} + +NS_IMETHODIMP +EmbedStream::Available(PRUint32 *_retval) +{ + return mInputStream->Available(_retval); +} + +NS_IMETHODIMP +EmbedStream::Read(char * aBuf, PRUint32 aCount, PRUint32 *_retval) +{ + return mInputStream->Read(aBuf, aCount, _retval); +} + +NS_IMETHODIMP EmbedStream::Close(void) +{ + return mInputStream->Close(); +} + +NS_IMETHODIMP +EmbedStream::ReadSegments(nsWriteSegmentFun aWriter, void * aClosure, + PRUint32 aCount, PRUint32 *_retval) +{ + char *readBuf = (char *)nsMemory::Alloc(aCount); + PRUint32 nBytes; + + if (!readBuf) + return NS_ERROR_OUT_OF_MEMORY; + + nsresult rv = mInputStream->Read(readBuf, aCount, &nBytes); + + *_retval = 0; + + if (NS_SUCCEEDED(rv)) { + PRUint32 writeCount = 0; + rv = aWriter(this, aClosure, readBuf, 0, nBytes, &writeCount); + + // XXX writeCount may be less than nBytes!! This is the wrong + // way to synthesize ReadSegments. + NS_ASSERTION(writeCount == nBytes, "data loss"); + + // errors returned from the writer end here! + rv = NS_OK; + } + + nsMemory::Free(readBuf); + + return rv; +} + +NS_IMETHODIMP +EmbedStream::IsNonBlocking(PRBool *aNonBlocking) +{ + return mInputStream->IsNonBlocking(aNonBlocking); +} diff --git a/mozilla/embedding/browser/qt/src/EmbedStream.h b/mozilla/embedding/browser/qt/src/EmbedStream.h new file mode 100644 index 00000000000..5b0a8308864 --- /dev/null +++ b/mozilla/embedding/browser/qt/src/EmbedStream.h @@ -0,0 +1,84 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 +#include +#include +#include +#include +#include +#include + +class QGeckoEmbed; + +class EmbedStream : public nsIInputStream +{ +public: + + EmbedStream(); + ~EmbedStream(); + + void InitOwner (QGeckoEmbed *aOwner); + NS_METHOD Init (void); + + NS_METHOD OpenStream (const char *aBaseURI, const char *aContentType); + NS_METHOD AppendToStream (const char *aData, PRInt32 aLen); + NS_METHOD CloseStream (void); + + NS_METHOD Append (const char *aData, PRUint32 aLen); + + // nsISupports + NS_DECL_ISUPPORTS + // nsIInputStream + NS_DECL_NSIINPUTSTREAM + +private: + nsCOMPtr mOutputStream; + nsCOMPtr mInputStream; + + nsCOMPtr mLoadGroup; + nsCOMPtr mChannel; + nsCOMPtr mStreamListener; + + PRUint32 mOffset; + PRBool mDoingStream; + + QGeckoEmbed *mOwner; + +}; diff --git a/mozilla/embedding/browser/qt/src/EmbedWindow.cpp b/mozilla/embedding/browser/qt/src/EmbedWindow.cpp new file mode 100644 index 00000000000..c12fdd1ff20 --- /dev/null +++ b/mozilla/embedding/browser/qt/src/EmbedWindow.cpp @@ -0,0 +1,467 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 "EmbedWindow.h" + +#include "qgeckoembed.h" + +#include +#include +#include +#include "nsIWidget.h" +#include "nsIWebNavigation.h" +#include "nsReadableUtils.h" +#include "nsIDOMNode.h" +#include "nsIDOMElement.h" +#include "nsIDOMEvent.h" + +#include +#include +#include +#include +#include +#include +#include + +class MozTipLabel : public QLabel +{ +public: + MozTipLabel( QWidget* parent) + : QLabel( parent, "toolTipTip", + Qt::WStyle_StaysOnTop | Qt::WStyle_Customize | Qt::WStyle_NoBorder + | Qt::WStyle_Tool | Qt::WX11BypassWM ) + { + setMargin(1); + setAutoMask( FALSE ); + setFrameStyle( QFrame::Plain | QFrame::Box ); + setLineWidth( 1 ); + setAlignment( AlignAuto | AlignTop ); + setIndent(0); + polish(); + adjustSize(); + setFont(QToolTip::font()); + setPalette(QToolTip::palette()); + } +}; + + +EmbedWindow::EmbedWindow() + : mOwner(nsnull), + mVisibility(PR_FALSE), + mIsModal(PR_FALSE), + tooltip(0) +{ +} + +EmbedWindow::~EmbedWindow(void) +{ + ExitModalEventLoop(PR_FALSE); + if (tooltip) + delete tooltip; +} + +void +EmbedWindow::Init(QGeckoEmbed *aOwner) +{ + // save our owner for later + mOwner = aOwner; + + // create our nsIWebBrowser object and set up some basic defaults. + mWebBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID); + if (!mWebBrowser) { + //log an error + return; + } + + mWebBrowser->SetContainerWindow(NS_STATIC_CAST(nsIWebBrowserChrome *, this)); + + nsCOMPtr item = do_QueryInterface(mWebBrowser); + item->SetItemType(nsIDocShellTreeItem::typeContentWrapper); + +} + +nsresult +EmbedWindow::CreateWindow(void) +{ + nsresult rv; + + // Get the base window interface for the web browser object and + // create the window. + mBaseWindow = do_QueryInterface(mWebBrowser); + rv = mBaseWindow->InitWindow(mOwner, + nsnull, + 0, 0, + mOwner->width(), + mOwner->height()); + if (NS_FAILED(rv)) + return rv; + + rv = mBaseWindow->Create(); + if (NS_FAILED(rv)) + return rv; + + return NS_OK; +} + +void +EmbedWindow::ReleaseChildren(void) +{ + ExitModalEventLoop(PR_FALSE); + + mBaseWindow->Destroy(); + mBaseWindow = 0; + mWebBrowser = 0; +} + +// nsISupports + +NS_IMPL_ADDREF(EmbedWindow) + NS_IMPL_RELEASE(EmbedWindow) + + NS_INTERFACE_MAP_BEGIN(EmbedWindow) + NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebBrowserChrome) + NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome) + NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChromeFocus) + NS_INTERFACE_MAP_ENTRY(nsIEmbeddingSiteWindow) + NS_INTERFACE_MAP_ENTRY(nsITooltipListener) + NS_INTERFACE_MAP_ENTRY(nsIContextMenuListener) + NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor) + NS_INTERFACE_MAP_END + +// nsIWebBrowserChrome + +NS_IMETHODIMP +EmbedWindow::SetStatus(PRUint32 aStatusType, const PRUnichar *aStatus) +{ + switch (aStatusType) { + case STATUS_SCRIPT: + { + mOwner->emitScriptStatus(QString::fromUcs2(aStatus)); + } + break; + case STATUS_SCRIPT_DEFAULT: + // Gee, that's nice. + break; + case STATUS_LINK: + { + mLinkMessage = aStatus; + mOwner->emitLinkStatus(QString::fromUcs2(aStatus)); + } + break; + } + return NS_OK; +} + +NS_IMETHODIMP +EmbedWindow::GetWebBrowser(nsIWebBrowser **aWebBrowser) +{ + *aWebBrowser = mWebBrowser; + NS_IF_ADDREF(*aWebBrowser); + return NS_OK; +} + +NS_IMETHODIMP +EmbedWindow::SetWebBrowser(nsIWebBrowser *aWebBrowser) +{ + mWebBrowser = aWebBrowser; + return NS_OK; +} + +NS_IMETHODIMP +EmbedWindow::GetChromeFlags(PRUint32 *aChromeFlags) +{ + *aChromeFlags = mOwner->chromeMask(); + return NS_OK; +} + +NS_IMETHODIMP +EmbedWindow::SetChromeFlags(PRUint32 aChromeFlags) +{ + mOwner->setChromeMask(aChromeFlags); + return NS_OK; +} + +NS_IMETHODIMP +EmbedWindow::DestroyBrowserWindow(void) +{ + emit mOwner->destroyBrowser(); + + return NS_OK; +} + +NS_IMETHODIMP +EmbedWindow::SizeBrowserTo(PRInt32 aCX, PRInt32 aCY) +{ + emit mOwner->sizeTo(aCX, aCY); + return NS_OK; +} + +NS_IMETHODIMP +EmbedWindow::ShowAsModal(void) +{ + qDebug("setting modal"); + mIsModal = PR_TRUE; + qApp->eventLoop()->enterLoop(); + return NS_OK; +} + +NS_IMETHODIMP +EmbedWindow::IsWindowModal(PRBool *_retval) +{ + *_retval = mIsModal; + return NS_OK; +} + +NS_IMETHODIMP +EmbedWindow::ExitModalEventLoop(nsresult aStatus) +{ + qDebug("exiting modal"); + qApp->eventLoop()->exitLoop(); + return NS_OK; +} + +// nsIWebBrowserChromeFocus + +NS_IMETHODIMP +EmbedWindow::FocusNextElement() +{ + //FIXME: + //i think gecko handles that internally + //mOwner->focusNextPrevChild(TRUE); + return NS_OK; +} + +NS_IMETHODIMP +EmbedWindow::FocusPrevElement() +{ + //FIXME: same story as above + //mOwner->focusNextPrevChild(FALSE); + return NS_OK; +} + +// nsIEmbeddingSiteWindow + +NS_IMETHODIMP +EmbedWindow::SetDimensions(PRUint32 aFlags, PRInt32 aX, PRInt32 aY, + PRInt32 aCX, PRInt32 aCY) +{ + if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION && + (aFlags & (nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER | + nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER))) { + return mBaseWindow->SetPositionAndSize(aX, aY, aCX, aCY, PR_TRUE); + } + else if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION) { + return mBaseWindow->SetPosition(aX, aY); + } + else if (aFlags & (nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER | + nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER)) { + return mBaseWindow->SetSize(aCX, aCY, PR_TRUE); + } + return NS_ERROR_INVALID_ARG; +} + +NS_IMETHODIMP +EmbedWindow::GetDimensions(PRUint32 aFlags, PRInt32 *aX, + PRInt32 *aY, PRInt32 *aCX, PRInt32 *aCY) +{ + if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION && + (aFlags & (nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER | + nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER))) { + return mBaseWindow->GetPositionAndSize(aX, aY, aCX, aCY); + } + else if (aFlags & nsIEmbeddingSiteWindow::DIM_FLAGS_POSITION) { + return mBaseWindow->GetPosition(aX, aY); + } + else if (aFlags & (nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER | + nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_OUTER)) { + return mBaseWindow->GetSize(aCX, aCY); + } + return NS_ERROR_INVALID_ARG; +} + +NS_IMETHODIMP +EmbedWindow::SetFocus(void) +{ + // XXX might have to do more here. + return mBaseWindow->SetFocus(); +} + +NS_IMETHODIMP +EmbedWindow::GetTitle(PRUnichar **aTitle) +{ + *aTitle = ToNewUnicode(mTitle); + return NS_OK; +} + +NS_IMETHODIMP +EmbedWindow::SetTitle(const PRUnichar *aTitle) +{ + mTitle = aTitle; + emit mOwner->windowTitleChanged(QString::fromUcs2(aTitle)); + return NS_OK; +} + +NS_IMETHODIMP +EmbedWindow::GetSiteWindow(void **aSiteWindow) +{ + *aSiteWindow = NS_STATIC_CAST(void *, mOwner); + return NS_OK; +} + +NS_IMETHODIMP +EmbedWindow::GetVisibility(PRBool *aVisibility) +{ + *aVisibility = mVisibility; + return NS_OK; +} + +NS_IMETHODIMP +EmbedWindow::SetVisibility(PRBool aVisibility) +{ + // We always set the visibility so that if it's chrome and we finish + // the load we know that we have to show the window. + mVisibility = aVisibility; + + // if this is a chrome window and the chrome hasn't finished loading + // yet then don't show the window yet. + if (mOwner->isChrome() && !mOwner->chromeLoaded()) + return NS_OK; + + emit mOwner->visibilityChanged(aVisibility); + + return NS_OK; +} + +// nsITooltipListener + +NS_IMETHODIMP +EmbedWindow::OnShowTooltip(PRInt32 aXCoords, PRInt32 aYCoords, const PRUnichar *aTipText) +{ + QString tipText = QString::fromUcs2(aTipText); + + // get the root origin for this content window + nsCOMPtr mainWidget; + mBaseWindow->GetMainWidget(getter_AddRefs(mainWidget)); + QWidget *window; + window = NS_STATIC_CAST(QWidget*, mainWidget->GetNativeData(NS_NATIVE_WINDOW)); + + if (!window) { + NS_ERROR("no qt window in hierarchy!\n"); + return NS_ERROR_FAILURE; + } + + int screen = qApp->desktop()->screenNumber(window); + if (!tooltip || qApp->desktop()->screenNumber(tooltip) != screen) { + delete tooltip; + QWidget *s = QApplication::desktop()->screen(screen); + tooltip = new MozTipLabel(s); + } + + tooltip->setText(tipText); + tooltip->resize(tooltip->sizeHint()); + QPoint pos(aXCoords, aYCoords+24); + pos = window->mapToGlobal(pos); + tooltip->move(pos); + tooltip->show(); + + return NS_OK; +} + +NS_IMETHODIMP +EmbedWindow::OnHideTooltip(void) +{ + if (tooltip) + tooltip->hide(); + return NS_OK; +} + + +NS_IMETHODIMP +EmbedWindow::OnShowContextMenu(PRUint32 aContextFlags, nsIDOMEvent *aEvent, nsIDOMNode *aNode) +{ +// if (!aEvent->type == NS_CONTEXTMENU) +// return NS_OK; + qDebug("EmbedWindow::OnShowContextMenu"); + + QString url = mOwner->url(); + + PRUint16 nodeType; + aNode->GetNodeType(&nodeType); + if (nodeType == nsIDOMNode::ELEMENT_NODE) { + nsIDOMElement *element = static_cast(aNode); + nsString tagname; + element->GetTagName(tagname); + nsCString ctagname; + LossyCopyUTF16toASCII(tagname, ctagname); + if (!strcasecmp(ctagname.get(), "a")) { + nsString href; + nsString attr; + attr.AssignLiteral("href"); + element->GetAttribute(attr, href); + url = mOwner->resolvedUrl(QString::fromUcs2(href.get())); + } else if (!strcasecmp(ctagname.get(), "img")) { + nsString href; + nsString attr; + attr.AssignLiteral("src"); + element->GetAttribute(attr, href); + url = mOwner->resolvedUrl(QString::fromUcs2(href.get())); + } + } + + emit mOwner->showContextMenu(QCursor::pos(), url); + return NS_OK; +} + +// nsIInterfaceRequestor + +NS_IMETHODIMP +EmbedWindow::GetInterface(const nsIID &aIID, void** aInstancePtr) +{ + nsresult rv; + + rv = QueryInterface(aIID, aInstancePtr); + + // pass it up to the web browser object + if (NS_FAILED(rv) || !*aInstancePtr) { + nsCOMPtr ir = do_QueryInterface(mWebBrowser); + return ir->GetInterface(aIID, aInstancePtr); + } + + return rv; +} diff --git a/mozilla/embedding/browser/qt/src/EmbedWindow.h b/mozilla/embedding/browser/qt/src/EmbedWindow.h new file mode 100644 index 00000000000..8273ef42b7d --- /dev/null +++ b/mozilla/embedding/browser/qt/src/EmbedWindow.h @@ -0,0 +1,102 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 EMBEDWINDOW_H +#define EMBEDWINDOW_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "nsString.h" + +class QGeckoEmbed; +class MozTipLabel; + +class EmbedWindow : public nsIWebBrowserChrome, + public nsIWebBrowserChromeFocus, + public nsIEmbeddingSiteWindow, + public nsITooltipListener, + public nsIContextMenuListener, + public nsIInterfaceRequestor +{ +public: + EmbedWindow(); + ~EmbedWindow(); + void Init(QGeckoEmbed *aOwner); + + nsresult CreateWindow (void); + void ReleaseChildren (void); + + NS_DECL_ISUPPORTS + + NS_DECL_NSIWEBBROWSERCHROME + + NS_DECL_NSIWEBBROWSERCHROMEFOCUS + + NS_DECL_NSIEMBEDDINGSITEWINDOW + + NS_DECL_NSITOOLTIPLISTENER + + NS_DECL_NSICONTEXTMENULISTENER + + NS_DECL_NSIINTERFACEREQUESTOR + + nsString mTitle; + nsString mJSStatus; + nsString mLinkMessage; + + nsCOMPtr mBaseWindow; // [OWNER] + +private: + QGeckoEmbed *mOwner; + nsCOMPtr mWebBrowser; // [OWNER] + PRBool mVisibility; + PRBool mIsModal; + MozTipLabel *tooltip; +}; + +#endif diff --git a/mozilla/embedding/browser/qt/src/EmbedWindowCreator.cpp b/mozilla/embedding/browser/qt/src/EmbedWindowCreator.cpp new file mode 100644 index 00000000000..9454504dc25 --- /dev/null +++ b/mozilla/embedding/browser/qt/src/EmbedWindowCreator.cpp @@ -0,0 +1,99 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 "EmbedWindowCreator.h" + +#include "qgeckoembed.h" +#include "qgeckoglobals.h" +#include "EmbedWindow.h" + + +EmbedWindowCreator::EmbedWindowCreator() +{ +} + +EmbedWindowCreator::~EmbedWindowCreator() +{ +} + +NS_IMPL_ISUPPORTS1(EmbedWindowCreator, nsIWindowCreator) + +NS_IMETHODIMP +EmbedWindowCreator::CreateChromeWindow(nsIWebBrowserChrome *aParent, + PRUint32 aChromeFlags, + nsIWebBrowserChrome **_retval) +{ + NS_ENSURE_ARG_POINTER(_retval); + + QGeckoEmbed *newEmbed = 0; + + // No parent? Ask via the singleton object instead. + if (!aParent) { + //create single create window + qDebug("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX not implemented"); + } + else { + // Find the QGeckoEmbed object for this web browser chrome object. + QGeckoEmbed *qecko = QGeckoGlobals::findPrivateForBrowser(aParent); + + if (!qecko) + return NS_ERROR_FAILURE; + newEmbed = qecko; + emit newEmbed->newWindow(newEmbed, aChromeFlags); + } + + // check to make sure that we made a new window + if (!newEmbed) + return NS_ERROR_FAILURE; + + qDebug("MMMMM here"); + // set the chrome flag on the new window if it's a chrome open + if (aChromeFlags & nsIWebBrowserChrome::CHROME_OPENAS_CHROME) + newEmbed->setIsChrome(PR_TRUE); + + *_retval = NS_STATIC_CAST(nsIWebBrowserChrome *, + (newEmbed->window())); + + if (*_retval) { + NS_ADDREF(*_retval); + return NS_OK; + } + + return NS_ERROR_FAILURE; +} diff --git a/mozilla/embedding/browser/qt/src/EmbedWindowCreator.h b/mozilla/embedding/browser/qt/src/EmbedWindowCreator.h new file mode 100644 index 00000000000..fab210c05b8 --- /dev/null +++ b/mozilla/embedding/browser/qt/src/EmbedWindowCreator.h @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 EMBEDWINDOWCREATOR_H +#define EMBEDWINDOWCREATOR_H + +#include + +class EmbedWindowCreator : public nsIWindowCreator +{ +public: + EmbedWindowCreator(); + ~EmbedWindowCreator(); + + NS_DECL_ISUPPORTS + NS_DECL_NSIWINDOWCREATOR +}; + +#endif diff --git a/mozilla/embedding/browser/qt/src/Makefile.in b/mozilla/embedding/browser/qt/src/Makefile.in new file mode 100644 index 00000000000..33a18e0119d --- /dev/null +++ b/mozilla/embedding/browser/qt/src/Makefile.in @@ -0,0 +1,84 @@ +DEPTH = ../../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = qgeckoembed +LIBRARY_NAME = qgeckoembed +REQUIRES = xpcom \ + string \ + docshell \ + webshell \ + necko \ + widget \ + dom \ + js \ + gfx \ + layout \ + content \ + uriloader \ + webbrwsr \ + shistory \ + embed_base \ + pref \ + windowwatcher \ + profdirserviceprovider \ + $(NULL) + +ifdef ACCESSIBILITY +REQUIRES += accessibility +endif + +CPPSRCS = \ + $(MOCSRCS) \ + qgeckoembed.cpp \ + EmbedWindow.cpp \ + EmbedProgress.cpp \ + EmbedContentListener.cpp \ + EmbedEventListener.cpp \ + EmbedWindowCreator.cpp \ + EmbedStream.cpp \ + qgeckoglobals.cpp + +MOCSRCS = \ + moc_qgeckoembed.cpp \ + $(NULL) + +# Include config.mk +include $(topsrcdir)/config/config.mk + +# Force applications to be built non-statically +# when building the mozcomps meta component +ifneq (,$(filter mozcomps,$(MOZ_META_COMPONENTS))) +BUILD_STATIC_LIBS= +BUILD_SHARED_LIBS=1 +endif + +SHARED_LIBRARY_LIBS= \ + $(DIST)/lib/libembed_base_s.$(LIB_SUFFIX) \ + $(DIST)/lib/libprofdirserviceprovider_s.$(LIB_SUFFIX) \ + $(NULL) + +EXPORTS = qgeckoembed.h + +EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_LIBS) \ + $(MOZ_QT_LDFLAGS) \ + $(NULL) + +include $(topsrcdir)/config/rules.mk + +ifeq ($(OS_ARCH), SunOS) +ifndef GNU_CC +# When using Sun's WorkShop compiler, including +# /wherever/workshop-5.0/SC5.0/include/CC/std/time.h +# causes most of these compiles to fail with: +# line 29: Error: Multiple declaration for std::tm. +# So, this gets around the problem. +DEFINES += -D_TIME_H=1 +endif +endif + +CXXFLAGS += $(MOZ_QT_CFLAGS) -g02 +CFLAGS += $(MOZ_QT_CFLAGS) -g02 diff --git a/mozilla/embedding/browser/qt/src/qgeckoembed.cpp b/mozilla/embedding/browser/qt/src/qgeckoembed.cpp new file mode 100644 index 00000000000..514b4872b4d --- /dev/null +++ b/mozilla/embedding/browser/qt/src/qgeckoembed.cpp @@ -0,0 +1,728 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 "qgeckoembed.h" + +#include "EmbedWindow.h" +#include "EmbedProgress.h" +#include "EmbedStream.h" +#include "EmbedEventListener.h" +#include "EmbedContentListener.h" +#include "EmbedWindowCreator.h" +#include "qgeckoglobals.h" + +#include "nsIAppShell.h" +#include +#include +#include +#include +#include +#include +#include "nsIWidget.h" +#include "nsCRT.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "prenv.h" + +#include + +class QGeckoEmbedPrivate +{ +public: + QGeckoEmbedPrivate(QGeckoEmbed *qq); + ~QGeckoEmbedPrivate(); + + QGeckoEmbed *q; + + QWidget *mMainWidget; + + // all of the objects that we own + EmbedWindow *window; + nsCOMPtr windowGuard; + EmbedProgress *progress; + nsCOMPtr progressGuard; + EmbedContentListener *contentListener; + nsCOMPtr contentListenerGuard; + EmbedEventListener *eventListener; + nsCOMPtr eventListenerGuard; + EmbedStream *stream; + nsCOMPtr streamGuard; + + nsCOMPtr navigation; + nsCOMPtr sessionHistory; + + // our event receiver + nsCOMPtr eventReceiver; + + // chrome mask + PRUint32 chromeMask; + + bool isChrome; + bool chromeLoaded; + bool listenersAttached; + + void initGUI(); + void init(); + void ApplyChromeMask(); +}; + + +QGeckoEmbedPrivate::QGeckoEmbedPrivate(QGeckoEmbed *qq) + : q(qq), + mMainWidget(0), + chromeMask(nsIWebBrowserChrome::CHROME_ALL), + isChrome(FALSE), + chromeLoaded(FALSE), + listenersAttached(FALSE) +{ + initGUI(); + init(); +} + +QGeckoEmbedPrivate::~QGeckoEmbedPrivate() +{ + QGeckoGlobals::removeEngine(q); + QGeckoGlobals::popStartup(); +} + +void +QGeckoEmbedPrivate::init() +{ + QGeckoGlobals::initializeGlobalObjects(); + QGeckoGlobals::pushStartup(); + QGeckoGlobals::addEngine(q); + + // Create our embed window, and create an owning reference to it and + // initialize it. It is assumed that this window will be destroyed + // when we go out of scope. + window = new EmbedWindow(); + windowGuard = NS_STATIC_CAST(nsIWebBrowserChrome *, window); + window->Init(q); + // Create our progress listener object, make an owning reference, + // and initialize it. It is assumed that this progress listener + // will be destroyed when we go out of scope. + progress = new EmbedProgress(q); + progressGuard = NS_STATIC_CAST(nsIWebProgressListener *, + progress); + + // Create our content listener object, initialize it and attach it. + // It is assumed that this will be destroyed when we go out of + // scope. + contentListener = new EmbedContentListener(q); + contentListenerGuard = NS_STATIC_CAST(nsISupports*, + NS_STATIC_CAST(nsIURIContentListener*, contentListener)); + + // Create our key listener object and initialize it. It is assumed + // that this will be destroyed before we go out of scope. + eventListener = new EmbedEventListener(q); + eventListenerGuard = + NS_STATIC_CAST(nsISupports *, NS_STATIC_CAST(nsIDOMKeyListener *, + eventListener)); + + // has the window creator service been set up? + static int initialized = PR_FALSE; + // Set up our window creator ( only once ) + if (!initialized) { + // create our local object + nsCOMPtr windowCreator = new EmbedWindowCreator(); + + // Attach it via the watcher service + nsCOMPtr watcher = do_GetService(NS_WINDOWWATCHER_CONTRACTID); + if (watcher) + watcher->SetWindowCreator(windowCreator); + initialized = PR_TRUE; + } + + // Get the nsIWebBrowser object for our embedded window. + nsCOMPtr webBrowser; + window->GetWebBrowser(getter_AddRefs(webBrowser)); + + // get a handle on the navigation object + navigation = do_QueryInterface(webBrowser); + + // Create our session history object and tell the navigation object + // to use it. We need to do this before we create the web browser + // window. + sessionHistory = do_CreateInstance(NS_SHISTORY_CONTRACTID); + navigation->SetSessionHistory(sessionHistory); + + // create the window + window->CreateWindow(); + + // bind the progress listener to the browser object + nsCOMPtr supportsWeak; + supportsWeak = do_QueryInterface(progressGuard); + nsCOMPtr weakRef; + supportsWeak->GetWeakReference(getter_AddRefs(weakRef)); + webBrowser->AddWebBrowserListener(weakRef, + nsIWebProgressListener::GetIID()); + + // set ourselves as the parent uri content listener + webBrowser->SetParentURIContentListener(contentListener); + + // save the window id of the newly created window + nsCOMPtr qtWidget; + window->mBaseWindow->GetMainWidget(getter_AddRefs(qtWidget)); + // get the native drawing area + mMainWidget = NS_STATIC_CAST(QWidget*, qtWidget->GetNativeData(NS_NATIVE_WINDOW)); + + // Apply the current chrome mask + ApplyChromeMask(); +} + +void +QGeckoEmbedPrivate::initGUI() +{ + QBoxLayout *l = new QHBoxLayout(q); + l->setAutoAdd(TRUE); +} + +void +QGeckoEmbedPrivate::ApplyChromeMask() +{ + if (window) { + nsCOMPtr webBrowser; + window->GetWebBrowser(getter_AddRefs(webBrowser)); + + nsCOMPtr domWindow; + webBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); + if (domWindow) { + nsCOMPtr scrollbars; + domWindow->GetScrollbars(getter_AddRefs(scrollbars)); + if (scrollbars) { + + scrollbars->SetVisible( + chromeMask & nsIWebBrowserChrome::CHROME_SCROLLBARS ? + PR_TRUE : PR_FALSE); + } + } + } +} + + + + +QGeckoEmbed::QGeckoEmbed(QWidget *parent, const char *name) + : QWidget(parent, name) +{ + d = new QGeckoEmbedPrivate(this); +} + +QGeckoEmbed::~QGeckoEmbed() +{ + delete d; +} + + +bool +QGeckoEmbed::canGoBack() const +{ + PRBool retval = PR_FALSE; + if (d->navigation) + d->navigation->GetCanGoBack(&retval); + return retval; +} + +bool +QGeckoEmbed::canGoForward() const +{ + PRBool retval = PR_FALSE; + if (d->navigation) + d->navigation->GetCanGoForward(&retval); + return retval; +} + +void +QGeckoEmbed::loadURL(const QString &url) +{ + if (!url.isEmpty()) { + d->navigation->LoadURI((const PRUnichar*)url.ucs2(), + nsIWebNavigation::LOAD_FLAGS_NONE, // Load flags + nsnull, // Referring URI + nsnull, // Post data + nsnull); + } +} + +void +QGeckoEmbed::stopLoad() +{ + if (d->navigation) + d->navigation->Stop(nsIWebNavigation::STOP_NETWORK); +} + +void +QGeckoEmbed::goForward() +{ + if (d->navigation) + d->navigation->GoForward(); +} + +void +QGeckoEmbed::goBack() +{ + if (d->navigation) + d->navigation->GoBack(); +} + +void +QGeckoEmbed::renderData(const QCString &data, const QString &baseURI, + const QString &mimeType) +{ + openStream(baseURI, mimeType); + appendData(data); + closeStream(); +} + +int +QGeckoEmbed::openStream(const QString &baseURI, const QString &mimeType) +{ + nsresult rv; + + if (!d->stream) { + d->stream = new EmbedStream(); + d->streamGuard = do_QueryInterface(d->stream); + d->stream->InitOwner(this); + rv = d->stream->Init(); + if (NS_FAILED(rv)) + return rv; + } + + rv = d->stream->OpenStream(baseURI, mimeType); + return rv; +} + +int +QGeckoEmbed::appendData(const QCString &data) +{ + if (!d->stream) + return NS_ERROR_FAILURE; + + // Attach listeners to this document since in some cases we don't + // get updates for content added this way. + contentStateChanged(); + + return d->stream->AppendToStream(data, data.length()); +} + +int +QGeckoEmbed::closeStream() +{ + nsresult rv; + + if (!d->stream) + return NS_ERROR_FAILURE; + rv = d->stream->CloseStream(); + + // release + d->stream = 0; + d->streamGuard = 0; + + return rv; +} + +void +QGeckoEmbed::reload(ReloadFlags flags) +{ + int qeckoFlags = 0; + switch(flags) { + case Normal: + qeckoFlags = 0; + break; + case BypassCache: + qeckoFlags = nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE; + break; + case BypassProxy: + qeckoFlags = nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY; + break; + case BypassProxyAndCache: + qeckoFlags = nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE | + nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY; + break; + case CharsetChange: + qeckoFlags = nsIWebNavigation::LOAD_FLAGS_CHARSET_CHANGE; + break; + default: + qeckoFlags = 0; + break; + } + + + nsCOMPtr wn; + + if (d->sessionHistory) { + wn = do_QueryInterface(d->sessionHistory); + } + if (!wn) + wn = d->navigation; + + if (wn) + wn->Reload(qeckoFlags); +} + +bool +QGeckoEmbed::domKeyDownEvent(nsIDOMKeyEvent *keyEvent) +{ + qDebug("key event start"); + emit domKeyDown(keyEvent); + qDebug("key event stop"); + return false; +} + +bool +QGeckoEmbed::domKeyPressEvent(nsIDOMKeyEvent *keyEvent) +{ + emit domKeyPress(keyEvent); + return false; +} + +bool +QGeckoEmbed::domKeyUpEvent(nsIDOMKeyEvent *keyEvent) +{ + emit domKeyUp(keyEvent); + qDebug("key release event stop"); + return false; +} + +bool +QGeckoEmbed::domMouseDownEvent(nsIDOMMouseEvent *mouseEvent) +{ + emit domMouseDown(mouseEvent); + return false; +} + +bool +QGeckoEmbed::domMouseUpEvent(nsIDOMMouseEvent *mouseEvent) +{ + emit domMouseUp(mouseEvent); + return false; +} + +bool +QGeckoEmbed::domMouseClickEvent(nsIDOMMouseEvent *mouseEvent) +{ + emit domMouseClick(mouseEvent); + return false; +} + +bool +QGeckoEmbed::domMouseDblClickEvent(nsIDOMMouseEvent *mouseEvent) +{ + emit domMouseDblClick(mouseEvent); + return false; +} + +bool +QGeckoEmbed::domMouseOverEvent(nsIDOMMouseEvent *mouseEvent) +{ + emit domMouseOver(mouseEvent); + return false; +} + +bool +QGeckoEmbed::domMouseOutEvent(nsIDOMMouseEvent *mouseEvent) +{ + emit domMouseOut(mouseEvent); + return false; +} + +bool +QGeckoEmbed::domActivateEvent(nsIDOMUIEvent *event) +{ + emit domActivate(event); + return false; +} + +bool +QGeckoEmbed::domFocusInEvent(nsIDOMUIEvent *event) +{ + emit domFocusIn(event); + return false; +} + +bool +QGeckoEmbed::domFocusOutEvent(nsIDOMUIEvent *event) +{ + emit domFocusOut(event); + return false; +} + +void +QGeckoEmbed::emitScriptStatus(const QString &str) +{ + emit jsStatusMessage(str); +} + +void +QGeckoEmbed::emitLinkStatus(const QString &str) +{ + emit linkMessage(str); +} + +int +QGeckoEmbed::chromeMask() const +{ + return d->chromeMask; +} + +void +QGeckoEmbed::setChromeMask(int mask) +{ + d->chromeMask = mask; + + d->ApplyChromeMask(); +} + +void +QGeckoEmbed::resizeEvent(QResizeEvent *e) +{ + d->window->SetDimensions(nsIEmbeddingSiteWindow::DIM_FLAGS_SIZE_INNER, + 0, 0, e->size().width(), e->size().height()); +} + +nsIDOMDocument* +QGeckoEmbed::document() const +{ + nsIDOMDocument *doc = 0; + + nsCOMPtr window; + nsCOMPtr webBrowser; + + d->window->GetWebBrowser(getter_AddRefs(webBrowser)); + + webBrowser->GetContentDOMWindow(getter_AddRefs(window)); + if (window) { + window->GetDocument(&doc); + } + + return doc; +} + +void +QGeckoEmbed::contentStateChanged() +{ + // we don't attach listeners to chrome + if (d->listenersAttached && !d->isChrome) + return; + + setupListener(); + + if (!d->eventReceiver) + return; + + attachListeners(); +} + +void +QGeckoEmbed::contentFinishedLoading() +{ + if (d->isChrome) { + // We're done loading. + d->chromeLoaded = PR_TRUE; + + // get the web browser + nsCOMPtr webBrowser; + d->window->GetWebBrowser(getter_AddRefs(webBrowser)); + + // get the content DOM window for that web browser + nsCOMPtr domWindow; + webBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); + if (!domWindow) { + NS_WARNING("no dom window in content finished loading\n"); + return; + } + + // resize the content + domWindow->SizeToContent(); + + // and since we're done loading show the window, assuming that the + // visibility flag has been set. + PRBool visibility; + d->window->GetVisibility(&visibility); + if (visibility) + d->window->SetVisibility(PR_TRUE); + } +} + +void +QGeckoEmbed::setupListener() +{ + if (d->eventReceiver) + return; + + nsCOMPtr piWin; + GetPIDOMWindow(getter_AddRefs(piWin)); + + if (!piWin) + return; + + d->eventReceiver = do_QueryInterface(piWin->GetChromeEventHandler()); +} + +void +QGeckoEmbed::attachListeners() +{ + if (!d->eventReceiver || d->listenersAttached) + return; + + nsIDOMEventListener *eventListener = + NS_STATIC_CAST(nsIDOMEventListener *, + NS_STATIC_CAST(nsIDOMKeyListener *, d->eventListener)); + + // add the key listener + nsresult rv; + rv = d->eventReceiver->AddEventListenerByIID(eventListener, + NS_GET_IID(nsIDOMKeyListener)); + if (NS_FAILED(rv)) { + NS_WARNING("Failed to add key listener\n"); + return; + } + + rv = d->eventReceiver->AddEventListenerByIID(eventListener, + NS_GET_IID(nsIDOMMouseListener)); + if (NS_FAILED(rv)) { + NS_WARNING("Failed to add mouse listener\n"); + return; + } + + rv = d->eventReceiver->AddEventListenerByIID(eventListener, + NS_GET_IID(nsIDOMUIListener)); + if (NS_FAILED(rv)) { + NS_WARNING("Failed to add UI listener\n"); + return; + } + + // ok, all set. + d->listenersAttached = PR_TRUE; +} + +EmbedWindow * QGeckoEmbed::window() const +{ + return d->window; +} + + +int QGeckoEmbed::GetPIDOMWindow(nsPIDOMWindow **aPIWin) +{ + *aPIWin = nsnull; + + // get the web browser + nsCOMPtr webBrowser; + d->window->GetWebBrowser(getter_AddRefs(webBrowser)); + + // get the content DOM window for that web browser + nsCOMPtr domWindow; + webBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); + if (!domWindow) + return NS_ERROR_FAILURE; + + // get the private DOM window + nsCOMPtr domWindowPrivate = do_QueryInterface(domWindow); + // and the root window for that DOM window + *aPIWin = domWindowPrivate->GetPrivateRoot(); + + if (*aPIWin) { + NS_ADDREF(*aPIWin); + return NS_OK; + } + + return NS_ERROR_FAILURE; + +} + +void QGeckoEmbed::setIsChrome(bool isChrome) +{ + d->isChrome = isChrome; +} + +bool QGeckoEmbed::isChrome() const +{ + return d->isChrome; +} + +bool QGeckoEmbed::chromeLoaded() const +{ + return d->chromeLoaded; +} + +QString QGeckoEmbed::url() const +{ + nsCOMPtr uri; + d->navigation->GetCurrentURI(getter_AddRefs(uri)); + nsCAutoString acstring; + uri->GetSpec(acstring); + + return QString::fromUtf8(acstring.get()); +} + +QString QGeckoEmbed::resolvedUrl(const QString &relativepath) const +{ + nsCOMPtr uri; + d->navigation->GetCurrentURI(getter_AddRefs(uri)); + nsCAutoString rel; + rel.Assign(relativepath.utf8().data()); + nsCAutoString resolved; + uri->Resolve(rel, resolved); + + return QString::fromUtf8(resolved.get()); +} + +void QGeckoEmbed::initialize(const char *aDir, const char *aName) +{ + QGeckoGlobals::setProfilePath(aDir, aName); +} + diff --git a/mozilla/embedding/browser/qt/src/qgeckoembed.h b/mozilla/embedding/browser/qt/src/qgeckoembed.h new file mode 100644 index 00000000000..39f8a36b3fd --- /dev/null +++ b/mozilla/embedding/browser/qt/src/qgeckoembed.h @@ -0,0 +1,214 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 QECKOEMBED_H +#define QECKOEMBED_H + +#include + +class nsIDOMKeyEvent; +class nsIDOMMouseEvent; +class nsIDOMUIEvent; +class nsModuleComponentInfo; +class nsIDirectoryServiceProvider; +class nsIAppShell; +class nsVoidArray; +class nsProfileDirServiceProvider; +class nsIPref; +class nsISupports; +class EmbedWindow; +class EmbedEventListener; +class EmbedProgress; +class nsIWebNavigation; +class nsISHistory; +class nsIDOMEventReceiver; +class EmbedContentListener; +class EmbedStream; +class QHBox; +class nsIDOMDocument; +class nsPIDOMWindow; +class QPaintEvent; + +class QGeckoEmbedPrivate; + +class QGeckoEmbed : public QWidget +{ + Q_OBJECT +public: + static void initialize(const char *aDir, const char *aName); +public: + enum ReloadFlags + { + Normal, + BypassCache, + BypassProxy, + BypassProxyAndCache, + CharsetChange + }; +public: + QGeckoEmbed(QWidget *parent, const char *name); + ~QGeckoEmbed(); + + bool canGoBack() const; + bool canGoForward() const; + + void setIsChrome(bool); + int chromeMask() const; + + nsIDOMDocument *document() const; + QString url() const; + QString resolvedUrl(const QString &relativepath) const; + +public slots: + void loadURL(const QString &url); + void stopLoad(); + void goForward(); + void goBack(); + + void renderData(const QCString &data, const QString &baseURI, + const QString &mimeType); + + int openStream(const QString &baseURI, const QString &mimeType); + int appendData(const QCString &data); + int closeStream(); + + void reload(ReloadFlags flags = Normal); + + void setChromeMask(int); + +signals: + void linkMessage(const QString &message); + void jsStatusMessage(const QString &message); + void locationChanged(const QString &location); + void windowTitleChanged(const QString &title); + + void progress(int current, int max); + void progressAll(const QString &url, int current, int max); + + void netState(int state, int status); + void netStateAll(const QString &url, int state, int status); + + void netStart(); + void netStop(); + + void newWindow(QGeckoEmbed *newWindow, int chromeMask); + void visibilityChanged(bool visible); + void destroyBrowser(); + void openURI(const QString &url); + void sizeTo(int width, int height); + + void securityChange(void *request, int status, void *message); + void statusChange(void *request, int status, void *message); + + void showContextMenu(const QPoint &p, const QString &url); + + /** + * The dom signals are called only if the dom* methods + * are not reimplemented. + */ + void domKeyDown(nsIDOMKeyEvent *keyEvent); + void domKeyPress(nsIDOMKeyEvent *keyEvent); + void domKeyUp(nsIDOMKeyEvent *keyEvent); + void domMouseDown(nsIDOMMouseEvent *mouseEvent); + void domMouseUp(nsIDOMMouseEvent *mouseEvent); + void domMouseClick(nsIDOMMouseEvent *mouseEvent); + void domMouseDblClick(nsIDOMMouseEvent *mouseEvent); + void domMouseOver(nsIDOMMouseEvent *mouseEvent); + void domMouseOut(nsIDOMMouseEvent *mouseEvent); + void domActivate(nsIDOMUIEvent *event); + void domFocusIn(nsIDOMUIEvent *event); + void domFocusOut(nsIDOMUIEvent *event); + + + void startURIOpen(const QString &url, bool &abort); + +protected: + friend class EmbedEventListener; + friend class EmbedContentListener; + /** + * return true if you want to stop the propagation + * of the event. By default the events are being + * propagated + */ + + virtual bool domKeyDownEvent(nsIDOMKeyEvent *keyEvent); + virtual bool domKeyPressEvent(nsIDOMKeyEvent *keyEvent); + virtual bool domKeyUpEvent(nsIDOMKeyEvent *keyEvent); + + virtual bool domMouseDownEvent(nsIDOMMouseEvent *mouseEvent); + virtual bool domMouseUpEvent(nsIDOMMouseEvent *mouseEvent); + virtual bool domMouseClickEvent(nsIDOMMouseEvent *mouseEvent); + virtual bool domMouseDblClickEvent(nsIDOMMouseEvent *mouseEvent); + virtual bool domMouseOverEvent(nsIDOMMouseEvent *mouseEvent); + virtual bool domMouseOutEvent(nsIDOMMouseEvent *mouseEvent); + + virtual bool domActivateEvent(nsIDOMUIEvent *event); + virtual bool domFocusInEvent(nsIDOMUIEvent *event); + virtual bool domFocusOutEvent(nsIDOMUIEvent *event); + + +protected: + friend class EmbedWindow; + friend class EmbedWindowCreator; + friend class EmbedProgress; + friend class EmbedContextMenuListener; + friend class EmbedStream; + friend class QGeckoGlobals; + void emitScriptStatus(const QString &str); + void emitLinkStatus(const QString &str); + void contentStateChanged(); + void contentFinishedLoading(); + + bool isChrome() const; + bool chromeLoaded() const; + +protected: + void resizeEvent(QResizeEvent *e); + + void setupListener(); + void attachListeners(); + + EmbedWindow *window() const; + int GetPIDOMWindow(nsPIDOMWindow **aPIWin); + +protected: + QGeckoEmbedPrivate *d; +}; + +#endif diff --git a/mozilla/embedding/browser/qt/src/qgeckoglobals.cpp b/mozilla/embedding/browser/qt/src/qgeckoglobals.cpp new file mode 100644 index 00000000000..cc3e9993558 --- /dev/null +++ b/mozilla/embedding/browser/qt/src/qgeckoglobals.cpp @@ -0,0 +1,293 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 "qgeckoglobals.h" + +#include "qgeckoembed.h" +#include "EmbedWindow.h" + +#include "nsIAppShell.h" +#include +#include +#include +#include +#include +#include +#include "nsIWidget.h" +#include "nsCRT.h" +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID); + +PRUint32 QGeckoGlobals::sWidgetCount = 0; +char *QGeckoGlobals::sCompPath = nsnull; +nsIAppShell *QGeckoGlobals::sAppShell = nsnull; +char *QGeckoGlobals::sProfileDir = nsnull; +char *QGeckoGlobals::sProfileName = nsnull; +nsIPref *QGeckoGlobals::sPrefs = nsnull; +nsVoidArray *QGeckoGlobals::sWindowList = nsnull; +nsIDirectoryServiceProvider *QGeckoGlobals::sAppFileLocProvider = nsnull; +nsProfileDirServiceProvider *QGeckoGlobals::sProfileDirServiceProvider = nsnull; + +void +QGeckoGlobals::pushStartup() +{ + // increment the number of widgets + sWidgetCount++; + + // if this is the first widget, fire up xpcom + if (sWidgetCount == 1) { + nsresult rv; + nsCOMPtr binDir; + + if (sCompPath) { + rv = NS_NewNativeLocalFile(nsDependentCString(sCompPath), 1, getter_AddRefs(binDir)); + if (NS_FAILED(rv)) + return; + } + + rv = NS_InitEmbedding(binDir, sAppFileLocProvider); + if (NS_FAILED(rv)) + return; + + // we no longer need a reference to the DirectoryServiceProvider + if (sAppFileLocProvider) { + NS_RELEASE(sAppFileLocProvider); + sAppFileLocProvider = nsnull; + } + + rv = startupProfile(); + NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Warning: Failed to start up profiles.\n"); + + // XXX startup appshell service? + + nsCOMPtr appShell; + appShell = do_CreateInstance(kAppShellCID); + if (!appShell) { + NS_WARNING("Failed to create appshell in QGeckoGlobals::pushStartup!\n"); + return; + } + sAppShell = appShell.get(); + NS_ADDREF(sAppShell); + sAppShell->Create(0, nsnull); + sAppShell->Spinup(); + } +} + +void +QGeckoGlobals::popStartup() +{ + sWidgetCount--; + if (sWidgetCount == 0) { + // shut down the profiles + shutdownProfile(); + + if (sAppShell) { + // Shutdown the appshell service. + sAppShell->Spindown(); + NS_RELEASE(sAppShell); + sAppShell = 0; + } + + // shut down XPCOM/Embedding + NS_TermEmbedding(); + } +} + +void +QGeckoGlobals::setCompPath(const char *aPath) +{ + if (sCompPath) + free(sCompPath); + if (aPath) + sCompPath = strdup(aPath); + else + sCompPath = nsnull; +} + +void +QGeckoGlobals::setAppComponents(const nsModuleComponentInfo *, + int) +{ +} + +void +QGeckoGlobals::setProfilePath(const char *aDir, const char *aName) +{ + if (sProfileDir) { + nsMemory::Free(sProfileDir); + sProfileDir = nsnull; + } + + if (sProfileName) { + nsMemory::Free(sProfileName); + sProfileName = nsnull; + } + + if (aDir) + sProfileDir = (char *)nsMemory::Clone(aDir, strlen(aDir) + 1); + + if (aName) + sProfileName = (char *)nsMemory::Clone(aName, strlen(aDir) + 1); +} + +void +QGeckoGlobals::setDirectoryServiceProvider(nsIDirectoryServiceProvider + *appFileLocProvider) +{ + if (sAppFileLocProvider) + NS_RELEASE(sAppFileLocProvider); + + if (appFileLocProvider) { + sAppFileLocProvider = appFileLocProvider; + NS_ADDREF(sAppFileLocProvider); + } +} + + +/* static */ +int +QGeckoGlobals::startupProfile(void) +{ + // initialize profiles + if (sProfileDir && sProfileName) { + nsresult rv; + nsCOMPtr profileDir; + NS_NewNativeLocalFile(nsDependentCString(sProfileDir), PR_TRUE, + getter_AddRefs(profileDir)); + if (!profileDir) + return NS_ERROR_FAILURE; + rv = profileDir->AppendNative(nsDependentCString(sProfileName)); + if (NS_FAILED(rv)) + return NS_ERROR_FAILURE; + + nsCOMPtr locProvider; + NS_NewProfileDirServiceProvider(PR_TRUE, getter_AddRefs(locProvider)); + if (!locProvider) + return NS_ERROR_FAILURE; + rv = locProvider->Register(); + if (NS_FAILED(rv)) + return rv; + rv = locProvider->SetProfileDir(profileDir); + if (NS_FAILED(rv)) + return rv; + // Keep a ref so we can shut it down. + NS_ADDREF(sProfileDirServiceProvider = locProvider); + + // get prefs + nsCOMPtr pref; + pref = do_GetService(NS_PREF_CONTRACTID); + if (!pref) + return NS_ERROR_FAILURE; + sPrefs = pref.get(); + NS_ADDREF(sPrefs); + } + return NS_OK; +} + +/* static */ +void +QGeckoGlobals::shutdownProfile(void) +{ + if (sProfileDirServiceProvider) { + sProfileDirServiceProvider->Shutdown(); + NS_RELEASE(sProfileDirServiceProvider); + sProfileDirServiceProvider = 0; + } + if (sPrefs) { + NS_RELEASE(sPrefs); + sPrefs = 0; + } +} + +void QGeckoGlobals::initializeGlobalObjects() +{ + if (!sWindowList) { + sWindowList = new nsVoidArray(); + } +} + +void QGeckoGlobals::addEngine(QGeckoEmbed *embed) +{ + sWindowList->AppendElement(embed); +} + +void QGeckoGlobals::removeEngine(QGeckoEmbed *embed) +{ + sWindowList->RemoveElement(embed); +} + +QGeckoEmbed *QGeckoGlobals::findPrivateForBrowser(nsIWebBrowserChrome *aBrowser) +{ + if (!sWindowList) + return nsnull; + + // Get the number of browser windows. + PRInt32 count = sWindowList->Count(); + // This function doesn't get called very often at all ( only when + // creating a new window ) so it's OK to walk the list of open + // windows. + for (int i = 0; i < count; i++) { + QGeckoEmbed *tmpPrivate = NS_STATIC_CAST(QGeckoEmbed *, + sWindowList->ElementAt(i)); + // get the browser object for that window + nsIWebBrowserChrome *chrome = NS_STATIC_CAST(nsIWebBrowserChrome *, + tmpPrivate->window()); + if (chrome == aBrowser) + return tmpPrivate; + } + + return nsnull; +} diff --git a/mozilla/embedding/browser/qt/src/qgeckoglobals.h b/mozilla/embedding/browser/qt/src/qgeckoglobals.h new file mode 100644 index 00000000000..2ca792e2c05 --- /dev/null +++ b/mozilla/embedding/browser/qt/src/qgeckoglobals.h @@ -0,0 +1,94 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Zack Rusin + * + * 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 QECKOGLOBALS_H +#define QECKOGLOBALS_H + +#include "prenv.h" + +class nsModuleComponentInfo; +class nsIDirectoryServiceProvider; +class nsModuleComponentInfo; +class nsIAppShell; +class nsVoidArray; +class nsProfileDirServiceProvider; +class nsIPref; +class nsIDirectoryServiceProvider; +class nsIWebBrowserChrome; + +class QGeckoGlobals +{ + friend class QGeckoEmbed; +public: + static void initializeGlobalObjects(); + static void pushStartup(); + static void popStartup(); + static void setCompPath(const char *aPath); + static void setAppComponents(const nsModuleComponentInfo *aComps, + int aNumComponents); + static void setProfilePath(const char *aDir, const char *aName); + static void setDirectoryServiceProvider(nsIDirectoryServiceProvider + *appFileLocProvider); + static int startupProfile(void); + static void shutdownProfile(void); + + static void addEngine(QGeckoEmbed *embed); + static void removeEngine(QGeckoEmbed *embed); + static QGeckoEmbed *findPrivateForBrowser(nsIWebBrowserChrome *aBrowser); +private: + static PRUint32 sWidgetCount; + // the path to components + static char *sCompPath; + // the list of application-specific components to register + static const nsModuleComponentInfo *sAppComps; + static int sNumAppComps; + // the appshell we have created + static nsIAppShell *sAppShell; + // what is our profile path? + static char *sProfileDir; + static char *sProfileName; + // for profiles + static nsProfileDirServiceProvider *sProfileDirServiceProvider; + static nsIPref *sPrefs; + static nsIDirectoryServiceProvider *sAppFileLocProvider; + + // the list of all open windows + static nsVoidArray *sWindowList; +}; + +#endif diff --git a/mozilla/embedding/browser/qt/tests/Makefile.in b/mozilla/embedding/browser/qt/tests/Makefile.in new file mode 100644 index 00000000000..31f5781ce79 --- /dev/null +++ b/mozilla/embedding/browser/qt/tests/Makefile.in @@ -0,0 +1,87 @@ +DEPTH = ../../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = qgeckoembed +REQUIRES = xpcom \ + string \ + dom \ + $(NULL) + +ifdef NS_TRACE_MALLOC +REQUIRES += tracemalloc +endif + +ifdef MOZ_JPROF +REQUIRES += jprof +endif + +CPPSRCS = \ + $(MOCSRCS) \ + mainwindow.cpp \ + TestQGeckoEmbed.cpp + +MOCSRCS = \ + moc_mainwindow.cpp \ + $(NULL) + +CXXFLAGS += $(MOZ_QT_CFLAGS) +PROGRAM = $(CPPSRCS:.cpp=) + +ifdef MOZ_ENABLE_QT +LIBS += \ + -lqgeckoembed \ + $(XLDFLAGS) \ + $(XLIBS) \ + $(NULL) +endif + +include $(topsrcdir)/config/config.mk + +# Force applications to be built non-statically +# when building the mozcomps meta component +ifneq (,$(filter mozcomps,$(MOZ_META_COMPONENTS))) +BUILD_STATIC_LIBS= +BUILD_SHARED_LIBS=1 +endif + +ifdef NS_TRACE_MALLOC +EXTRA_LIBS += -ltracemalloc +endif + +ifdef MOZ_PERF_METRICS +EXTRA_LIBS += -lmozutil_s +endif + +ifdef MOZ_JPROF +EXTRA_LIBS += -ljprof +endif + +EXTRA_LIBS += $(MOZ_JS_LIBS) +EXTRA_LIBS += $(MOZ_COMPONENT_LIBS) + +include $(topsrcdir)/config/rules.mk + +CXXFLAGS += $(MOZ_QT_CFLAGS) + +EXTRA_LIBS += \ + $(TK_LIBS) \ + $(NULL) + +ifeq ($(OS_ARCH), SunOS) +ifndef GNU_CC +# When using Sun's WorkShop compiler, including +# /wherever/workshop-5.0/SC5.0/include/CC/std/time.h +# causes most of these compiles to fail with: +# line 29: Error: Multiple declaration for std::tm. +# So, this gets around the problem. +DEFINES += -D_TIME_H=1 +endif +endif + +ifeq ($(OS_ARCH), OpenVMS) +DEFINES += -DGENERIC_MOTIF_REDEFINES +endif diff --git a/mozilla/embedding/browser/qt/tests/TestQGeckoEmbed.cpp b/mozilla/embedding/browser/qt/tests/TestQGeckoEmbed.cpp new file mode 100644 index 00000000000..be5a2a5c9b2 --- /dev/null +++ b/mozilla/embedding/browser/qt/tests/TestQGeckoEmbed.cpp @@ -0,0 +1,29 @@ +#include +#include "mainwindow.h" +#include "qgeckoembed.h" + +#include + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + QGeckoEmbed::initialize(QDir::homeDirPath().latin1(), + ".TestQGeckoEmbed"); + + MyMainWindow *mainWindow = new MyMainWindow(); + app.setMainWidget(mainWindow); + + mainWindow->resize(700, 500); + mainWindow->show(); + + QString url; + if (argc > 1) + url = argv[1]; + else + url = "http://www.kde.org"; + + mainWindow->qecko->loadURL(url); + + return app.exec(); +} diff --git a/mozilla/embedding/browser/qt/tests/mainwindow.cpp b/mozilla/embedding/browser/qt/tests/mainwindow.cpp new file mode 100644 index 00000000000..851cfae7111 --- /dev/null +++ b/mozilla/embedding/browser/qt/tests/mainwindow.cpp @@ -0,0 +1,52 @@ +#include "mainwindow.h" + +#include +#include +#include +#include +#include +#include + +#include "qgeckoembed.h" + + +MyMainWindow::MyMainWindow() +{ + QHBox *box = new QHBox(this); + qecko = new QGeckoEmbed(box, "qgecko"); + box->setFrameStyle(QFrame::Panel | QFrame::Sunken); + setCentralWidget( box ); + + //QToolBar *toolbar = new QToolBar(this); + + QPopupMenu *menu = new QPopupMenu(this); + menuBar()->insertItem( tr( "&File" ), menu ); + + QAction *a = new QAction( QPixmap::fromMimeSource( "filenew.xpm" ), tr( "&Open..." ), CTRL + Key_O, this, "fileOpen" ); + connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) ); + //a->addTo( toolbar ); + a->addTo( menu ); + + + connect( qecko, SIGNAL(linkMessage(const QString &)), + statusBar(), SLOT(message(const QString &)) ); + connect( qecko, SIGNAL(jsStatusMessage(const QString &)), + statusBar(), SLOT(message(const QString &)) ); + connect( qecko, SIGNAL(windowTitleChanged(const QString &)), + SLOT(setCaption(const QString &)) ); + connect( qecko, SIGNAL(startURIOpen(const QString &, bool &)), + SLOT(startURIOpen(const QString &, bool &)) ); + +} + +void MyMainWindow::fileOpen() +{ + QString fn = QFileDialog::getOpenFileName( QString::null, tr( "HTML-Files (*.htm *.html);;All Files (*)" ), this ); + if ( !fn.isEmpty() ) + qecko->loadURL( fn ); +} + +void MyMainWindow::startURIOpen(const QString &, bool &) +{ + qDebug("XX in the signal"); +} diff --git a/mozilla/embedding/browser/qt/tests/mainwindow.h b/mozilla/embedding/browser/qt/tests/mainwindow.h new file mode 100644 index 00000000000..8cce176ea00 --- /dev/null +++ b/mozilla/embedding/browser/qt/tests/mainwindow.h @@ -0,0 +1,21 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +class QGeckoEmbed; + +class MyMainWindow : public QMainWindow +{ + Q_OBJECT +public: + MyMainWindow(); + +public slots: + void fileOpen(); + void startURIOpen(const QString &, bool &); +public: + QGeckoEmbed *qecko; +}; + +#endif diff --git a/mozilla/gfx/src/Makefile.in b/mozilla/gfx/src/Makefile.in index 60347f5e73d..bdd1a80d194 100644 --- a/mozilla/gfx/src/Makefile.in +++ b/mozilla/gfx/src/Makefile.in @@ -96,12 +96,16 @@ else ifdef MOZ_ENABLE_GTK2 DIRS += gtk endif + ifdef MOZ_ENABLE_QT + DIRS += qt + endif ifdef MOZ_ENABLE_XLIB DIRS += xlib endif ifdef MOZ_ENABLE_PHOTON DIRS += photon endif + endif CPPSRCS = \ diff --git a/mozilla/gfx/src/qt/Makefile.in b/mozilla/gfx/src/qt/Makefile.in new file mode 100644 index 00000000000..2fbf6a06454 --- /dev/null +++ b/mozilla/gfx/src/qt/Makefile.in @@ -0,0 +1,111 @@ +# +# The contents of this file are subject to the Netscape 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/NPL/ +# +# 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 mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): +# John C. Griggs +# Zack Rusin +# + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = gfx +LIBRARY_NAME = gfx_qt +EXPORT_LIBRARY = 1 +GRE_MODULE = 1 +IS_COMPONENT = 1 +MODULE_NAME = nsGfxQtModule + +REQUIRES = xpcom \ + string \ + widget \ + view \ + uconv \ + pref \ + util \ + js \ + mozcomps \ + unicharutil \ + intl \ + locale \ + content \ + $(NULL) + + +CPPSRCS = \ + nsDeviceContextQt.cpp \ + nsDeviceContextSpecFactoryQt.cpp \ + nsDeviceContextSpecQt.cpp \ + nsDrawingSurfaceQt.cpp \ + nsFontMetricsQt.cpp \ + nsGfxFactoryQt.cpp \ + nsImageQt.cpp \ + nsNativeThemeQt.cpp \ + nsRegionQt.cpp \ + nsRenderingContextQt.cpp \ + nsScreenManagerQt.cpp \ + nsScreenQt.cpp \ + $(NULL) + +EXTRA_DSO_LIBS = gkgfx gfxshared_s + +include $(topsrcdir)/config/rules.mk + +CXXFLAGS += $(MOZ_QT_CFLAGS) +CFLAGS += $(MOZ_QT_CFLAGS) + +EXTRA_DSO_LDOPTS += \ + $(LIBS_DIR) \ + $(EXTRA_DSO_LIBS) \ + $(MOZ_COMPONENT_LIBS) \ + $(MOZ_JS_LIBS) \ + $(MOZ_QT_LDFLAGS) \ + $(NULL) + +ifeq ($(OS_ARCH), Linux) +DEFINES += -D_BSD_SOURCE +endif +ifeq ($(OS_ARCH), SunOS) +ifndef GNU_CC +# When using Sun's WorkShop compiler, including +# /wherever/workshop-5.0/SC5.0/include/CC/std/time.h +# causes most of these compiles to fail with: +# line 29: Error: Multiple declaration for std::tm. +# So, this gets around the problem. +DEFINES += -D_TIME_H=1 +endif +endif + +ifdef MOZ_ENABLE_POSTSCRIPT +DEFINES += -DUSE_POSTSCRIPT +endif + +ifdef MOZ_ENABLE_XPRINT +REQUIRES += xprintutil +endif + +LOCAL_INCLUDES = \ + -I$(srcdir)/. \ + -I$(srcdir)/.. \ + -I$(srcdir)/../shared \ + $(NULL) + diff --git a/mozilla/gfx/src/qt/nsDeviceContextQt.cpp b/mozilla/gfx/src/qt/nsDeviceContextQt.cpp new file mode 100644 index 00000000000..fa4731d5dad --- /dev/null +++ b/mozilla/gfx/src/qt/nsDeviceContextQt.cpp @@ -0,0 +1,512 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * John C. Griggs + * Esben Mose Hansen + * Roland Mainz + * + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include + +#include "nspr.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" +#include "nsIPrefBranchInternal.h" +#include "nsIServiceManager.h" +#include "nsCRT.h" +#include "nsDeviceContextQt.h" +#include "nsFontMetricsQt.h" +#include "nsFont.h" +#include "nsGfxCIID.h" +#include "nsRenderingContextQt.h" +#include "nsDeviceContextSpecQt.h" + +#ifdef USE_POSTSCRIPT +#include "nsGfxPSCID.h" +#include "nsIDeviceContextPS.h" +#endif /* USE_POSTSCRIPT */ +#ifdef USE_XPRINT +#include "nsGfxXPrintCID.h" +#include "nsIDeviceContextXPrint.h" +#endif /* USE_XPRINT */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "nsIScreenManager.h" + +#include "qtlog.h" + +#define QCOLOR_TO_NS_RGB(c) \ + ((nscolor)NS_RGB(c.red(),c.green(),c.blue())) + +nscoord nsDeviceContextQt::mDpi = 0; + +nsDeviceContextQt::nsDeviceContextQt() + : DeviceContextImpl() +{ + mTwipsToPixels = 1.0; + mPixelsToTwips = 1.0; + mDepth = 0 ; + mWidthFloat = 0.0f; + mHeightFloat = 0.0f; + mWidth = -1; + mHeight = -1; +} + +nsDeviceContextQt::~nsDeviceContextQt() +{ + nsCOMPtr pbi = do_GetService(NS_PREFSERVICE_CONTRACTID); + if (pbi) { + pbi->RemoveObserver("browser.display.screen_resolution", this); + } +} + +NS_IMETHODIMP nsDeviceContextQt::Init(nsNativeWidget aNativeWidget) +{ + PRBool bCleanUp = PR_FALSE; + QWidget *pWidget = nsnull; + + mWidget = (QWidget*)aNativeWidget; + + if (mWidget != nsnull) + pWidget = mWidget; + else { + pWidget = new QWidget(); + bCleanUp = PR_TRUE; + } + + nsresult ignore; + nsCOMPtr sm(do_GetService("@mozilla.org/gfx/screenmanager;1", + &ignore)); + if (sm) { + nsCOMPtr screen; + sm->GetPrimaryScreen(getter_AddRefs(screen)); + if (screen) { + PRInt32 x,y,width,height,depth; + + screen->GetAvailRect(&x,&y,&width,&height); + screen->GetPixelDepth(&depth); + mWidthFloat = float(width); + mHeightFloat = float(height); + mDepth = NS_STATIC_CAST(PRUint32,depth); + } + } + + if (!mDpi) { + // Set prefVal the value of the preference "browser.display.screen_resolution" + // or -1 if we can't get it. + // If it's negative, we pretend it's not set. + // If it's 0, it means force use of the operating system's logical resolution. + // If it's positive, we use it as the logical resolution + PRInt32 prefVal = -1; + nsCOMPtr prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID)); + if (prefBranch) { + nsresult res = prefBranch->GetIntPref("browser.display.screen_resolution", + &prefVal); + if (NS_FAILED(res)) { + prefVal = -1; + } + nsCOMPtr pbi(do_QueryInterface(prefBranch)); + pbi->AddObserver("browser.display.screen_resolution", this, PR_FALSE); + } + + SetDPI(prefVal); + } else { + SetDPI(mDpi); + } + +#ifdef MOZ_LOGGING + static PRBool once = PR_TRUE; + if (once) { + PR_LOG(gQtLogModule, QT_BASIC, ("GFX: dpi=%d t2p=%g p2t=%g depth=%d\n", + mDpi,mTwipsToPixels,mPixelsToTwips,mDepth)); + once = PR_FALSE; + } +#endif + + QStyle &style = pWidget->style(); + mScrollbarWidth = mScrollbarHeight = style.pixelMetric(QStyle::PM_ScrollBarExtent); + + DeviceContextImpl::CommonInit(); + + if (bCleanUp) + delete pWidget; + return NS_OK; +} + +NS_IMETHODIMP +nsDeviceContextQt::CreateRenderingContext(nsIRenderingContext *&aContext) +{ + nsresult rv; + nsDrawingSurfaceQt *surf; + QPaintDevice *pDev = nsnull; + + if (mWidget) + pDev = (QPaintDevice*)mWidget; + + // to call init for this, we need to have a valid nsDrawingSurfaceQt created + nsCOMPtr pContext( new nsRenderingContextQt() ); + + // create the nsDrawingSurfaceQt + surf = new nsDrawingSurfaceQt(); + + if (surf) { + //Handled by the nsDrawingSurfaceQt + //FIXME: instead of passing it around + // create it in the nsDrawingSurface init method + QPainter *gc = new QPainter(); + + // init the nsDrawingSurfaceQt + if (pDev) + rv = surf->Init(pDev,gc); + else + rv = surf->Init(gc,10,10,0); + + if (NS_SUCCEEDED(rv)) + // Init the nsRenderingContextQt + rv = pContext->Init(this,surf); + } + else + rv = NS_ERROR_OUT_OF_MEMORY; + + if (NS_SUCCEEDED(rv)) { + aContext = pContext; + NS_ADDREF(aContext); + } + return rv; +} + + +NS_IMETHODIMP nsDeviceContextQt::CreateRenderingContextInstance(nsIRenderingContext *&aContext) +{ + return CreateRenderingContext(aContext); +} + +NS_IMETHODIMP +nsDeviceContextQt::SupportsNativeWidgets(PRBool &aSupportsWidgets) +{ + //XXX it is very critical that this not lie!! MMP + // read the comments in the mac code for this + // ############## + aSupportsWidgets = PR_TRUE; + + return NS_OK; +} + +NS_IMETHODIMP nsDeviceContextQt::GetScrollBarDimensions(float &aWidth, + float &aHeight) const +{ + float scale; + GetCanonicalPixelScale(scale); + aWidth = mScrollbarWidth * mPixelsToTwips * scale; + aHeight = mScrollbarHeight * mPixelsToTwips * scale; + + return NS_OK; +} + +NS_IMETHODIMP +nsDeviceContextQt::GetSystemFont(nsSystemFontID anID, nsFont *aFont) const +{ + nsresult status = NS_OK; + + switch (anID) { + case eSystemFont_Caption: + case eSystemFont_Icon: + case eSystemFont_Menu: + case eSystemFont_MessageBox: + case eSystemFont_SmallCaption: + case eSystemFont_StatusBar: + case eSystemFont_Window: // css3 + case eSystemFont_Document: + case eSystemFont_Workspace: + case eSystemFont_Desktop: + case eSystemFont_Info: + case eSystemFont_Dialog: + case eSystemFont_Button: + case eSystemFont_PullDownMenu: + case eSystemFont_List: + case eSystemFont_Field: + case eSystemFont_Tooltips: + case eSystemFont_Widget: + status = GetSystemFontInfo(aFont); + break; + } + return status; +} + +NS_IMETHODIMP nsDeviceContextQt::CheckFontExistence(const nsString& aFontName) +{ + QString family = QString::fromUcs2(aFontName.get()); + QStringList families = QFontDatabase().families(); + return families.find(family) != families.end(); +} + +NS_IMETHODIMP nsDeviceContextQt::GetDeviceSurfaceDimensions(PRInt32 &aWidth, + PRInt32 &aHeight) +{ + if (-1 == mWidth) + mWidth = NSToIntRound(mWidthFloat * mDevUnitsToAppUnits); + + if (-1 == mHeight) + mHeight = NSToIntRound(mHeightFloat * mDevUnitsToAppUnits); + + aWidth = mWidth; + aHeight = mHeight; + + return NS_OK; +} + +NS_IMETHODIMP nsDeviceContextQt::GetRect(nsRect &aRect) +{ + PRInt32 width,height; + nsresult rv; + + rv = GetDeviceSurfaceDimensions(width,height); + aRect.x = 0; + aRect.y = 0; + aRect.width = width; + aRect.height = height; + + return rv; +} + +NS_IMETHODIMP nsDeviceContextQt::GetClientRect(nsRect &aRect) +{ + return GetRect(aRect); +} + +NS_IMETHODIMP nsDeviceContextQt::GetDeviceContextFor(nsIDeviceContextSpec *aDevice, + nsIDeviceContext *&aContext) +{ + nsresult rv; + PrintMethod method; + nsDeviceContextSpecQt *spec = NS_STATIC_CAST(nsDeviceContextSpecQt *, aDevice); + + rv = spec->GetPrintMethod(method); + if (NS_FAILED(rv)) + return rv; + +#ifdef USE_XPRINT + if (method == pmXprint) { // XPRINT + static NS_DEFINE_CID(kCDeviceContextXp, NS_DEVICECONTEXTXP_CID); + nsCOMPtr dcxp(do_CreateInstance(kCDeviceContextXp, &rv)); + NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't create Xp Device context."); + if (NS_FAILED(rv)) + return rv; + + rv = dcxp->SetSpec(aDevice); + if (NS_FAILED(rv)) + return rv; + + rv = dcxp->InitDeviceContextXP((nsIDeviceContext*)aContext, + (nsIDeviceContext*)this); + if (NS_FAILED(rv)) + return rv; + + rv = dcxp->QueryInterface(NS_GET_IID(nsIDeviceContext), + (void **)&aContext); + return rv; + } + else +#endif /* USE_XPRINT */ +#ifdef USE_POSTSCRIPT + if (method == pmPostScript) { // PostScript + // default/PS + static NS_DEFINE_CID(kCDeviceContextPS, NS_DEVICECONTEXTPS_CID); + + // Create a Postscript device context + nsCOMPtr dcps(do_CreateInstance(kCDeviceContextPS, &rv)); + NS_ASSERTION(NS_SUCCEEDED(rv), "Couldn't create PS Device context."); + if (NS_FAILED(rv)) + return rv; + + rv = dcps->SetSpec(aDevice); + if (NS_FAILED(rv)) + return rv; + + rv = dcps->InitDeviceContextPS((nsIDeviceContext*)aContext, + (nsIDeviceContext*)this); + if (NS_FAILED(rv)) + return rv; + + rv = dcps->QueryInterface(NS_GET_IID(nsIDeviceContext), + (void **)&aContext); + return rv; + } +#endif /* USE_POSTSCRIPT */ + + NS_WARNING("no print module created."); + return NS_ERROR_UNEXPECTED; +} + +NS_IMETHODIMP nsDeviceContextQt::BeginDocument(PRUnichar * /*aTitle*/, + PRUnichar* /*aPrintToFileName*/, + PRInt32 /*aStartPage*/, + PRInt32 /*aEndPage*/) +{ + return NS_OK; +} + +NS_IMETHODIMP nsDeviceContextQt::EndDocument(void) +{ + return NS_OK; +} + +NS_IMETHODIMP nsDeviceContextQt::BeginPage(void) +{ + return NS_OK; +} + +NS_IMETHODIMP nsDeviceContextQt::EndPage(void) +{ + return NS_OK; +} + +NS_IMETHODIMP nsDeviceContextQt::GetDepth(PRUint32& aDepth) +{ + aDepth = mDepth; + return NS_OK; +} + +nsresult nsDeviceContextQt::SetDPI(PRInt32 aDpi) +{ + // Set OSVal to what the operating system thinks the logical resolution is. + PRInt32 OSVal = 0; + + QWidget *pDev = mWidget; + if (!pDev) { + QWidgetList *wlist = QApplication::allWidgets(); + pDev = wlist->first(); + qDebug("number of widgets is %d", wlist->count() ); + delete wlist; + } + + QPaintDeviceMetrics qPaintMetrics(pDev); + OSVal = qPaintMetrics.logicalDpiX(); + + +#ifdef DEBUG + if (!pDev) + qDebug("nsDeviceContextQt::SetDPI called without widget (find cleaner solution)"); +#endif + + if (aDpi > 0) { + // If there's a valid pref value for the logical resolution, + // use it. + mDpi = aDpi; + } + else if (aDpi == 0 || OSVal > 96) { + // Either if the pref is 0 (force use of OS value) or the OS + // value is bigger than 96, use the OS value. + mDpi = OSVal; + } + else { + // if we couldn't get the pref or it's negative, and the OS + // value is under 96ppi, then use 96. + mDpi = 96; + } + + int pt2t = 72; + + // make p2t a nice round number - this prevents rounding problems + mPixelsToTwips = float(NSToIntRound(float(NSIntPointsToTwips(pt2t)) / float(aDpi))); + mTwipsToPixels = 1.0f / mPixelsToTwips; + + // XXX need to reflow all documents + + return NS_OK; +} + +NS_IMETHODIMP +nsDeviceContextQt::Observe(nsISupports* aSubject, const char* aTopic, + const PRUnichar* aData) +{ + if (nsCRT::strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) != 0) { + // Our local observer only handles pref changes. + // Forward everything else to our super class. + return DeviceContextImpl::Observe(aSubject, aTopic, aData); + } + + nsCOMPtr prefBranch(do_QueryInterface(aSubject)); + NS_ASSERTION(prefBranch, + "All pref change observer subjects implement nsIPrefBranch"); + nsCAutoString prefName(NS_LossyConvertUCS2toASCII(aData).get()); + + if (prefName.Equals(NS_LITERAL_CSTRING("browser.display.screen_resolution"))) { + PRInt32 dpi; + nsresult rv = prefBranch->GetIntPref(prefName.get(), &dpi); + if (NS_SUCCEEDED(rv)) + SetDPI(dpi); + return NS_OK; + } else + return DeviceContextImpl::Observe(aSubject, aTopic, aData); +} + +nsresult +nsDeviceContextQt::GetSystemFontInfo(nsFont* aFont) const +{ + nsresult status = NS_OK; + int rawWeight; + QFont theFont = QApplication::font(); + QFontInfo theFontInfo(theFont); + + aFont->style = NS_FONT_STYLE_NORMAL; + aFont->weight = NS_FONT_WEIGHT_NORMAL; + aFont->decorations = NS_FONT_DECORATION_NONE; + aFont->name.Assign(theFontInfo.family().ucs2()); + if (theFontInfo.bold()) { + aFont->weight = NS_FONT_WEIGHT_BOLD; + } + rawWeight = theFontInfo.pixelSize(); + aFont->size = NSIntPixelsToTwips(rawWeight,mPixelsToTwips); + if (theFontInfo.italic()) { + aFont->style = NS_FONT_STYLE_ITALIC; + } + if (theFontInfo.underline()) { + aFont->decorations = NS_FONT_DECORATION_UNDERLINE; + } + + return (status); +} diff --git a/mozilla/gfx/src/qt/nsDeviceContextQt.h b/mozilla/gfx/src/qt/nsDeviceContextQt.h new file mode 100644 index 00000000000..83f330f7209 --- /dev/null +++ b/mozilla/gfx/src/qt/nsDeviceContextQt.h @@ -0,0 +1,114 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * John C. Griggs + * + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ +#ifndef nsDeviceContextQt_h___ +#define nsDeviceContextQt_h___ + +#include "nsDeviceContext.h" +#include "nsUnitConversion.h" +#include "nsIWidget.h" +#include "nsIView.h" +#include "nsIRenderingContext.h" + +class QWidget; + +class nsDeviceContextQt : public DeviceContextImpl +{ +public: + nsDeviceContextQt(); + virtual ~nsDeviceContextQt(); + + NS_IMETHOD Init(nsNativeWidget aNativeWidget); + + NS_IMETHOD CreateRenderingContext(nsIRenderingContext *&aContext); + NS_IMETHOD CreateRenderingContext(nsIView *aView, nsIRenderingContext *&aContext) + {return (DeviceContextImpl::CreateRenderingContext(aView,aContext));} + NS_IMETHOD CreateRenderingContext(nsIWidget *aWidget, nsIRenderingContext *&aContext) + {return (DeviceContextImpl::CreateRenderingContext(aWidget,aContext));} + NS_IMETHOD CreateRenderingContext(nsIDrawingSurface* aSurface, nsIRenderingContext *&aContext) + {return (DeviceContextImpl::CreateRenderingContext(aSurface, aContext));} + NS_IMETHOD CreateRenderingContextInstance(nsIRenderingContext *&aContext); + + NS_IMETHOD SupportsNativeWidgets(PRBool &aSupportsWidgets); + + NS_IMETHOD GetScrollBarDimensions(float &aWidth,float &aHeight) const; + NS_IMETHOD GetSystemFont(nsSystemFontID anID, nsFont *aFont) const; + + NS_IMETHOD CheckFontExistence(const nsString &aFontName); + + NS_IMETHOD GetDeviceSurfaceDimensions(PRInt32 &aWidth,PRInt32 &aHeight); + NS_IMETHOD GetClientRect(nsRect &aRect); + NS_IMETHOD GetRect(nsRect &aRect); + + NS_IMETHOD GetDeviceContextFor(nsIDeviceContextSpec *aDevice, + nsIDeviceContext *&aContext); + + NS_IMETHOD BeginDocument(PRUnichar * aTitle, PRUnichar* aPrintToFileName, + PRInt32 aStartPage, PRInt32 aEndPage); + NS_IMETHOD EndDocument(void); + + NS_IMETHOD BeginPage(void); + NS_IMETHOD EndPage(void); + + // Overridden DeviceContextImpl functions. + NS_IMETHOD GetDepth(PRUint32 &aDepth); + + NS_IMETHOD Observe(nsISupports* aSubject, const char* aTopic, + const PRUnichar* aData); + + nsresult SetDPI(PRInt32 dpi); + +private: + PRUint32 mDepth; + PRInt16 mScrollbarHeight; + PRInt16 mScrollbarWidth; + QWidget *mWidget; + PRInt32 mWidth; + PRInt32 mHeight; + float mWidthFloat; + float mHeightFloat; + + static nscoord mDpi; + + nsresult GetSystemFontInfo(nsFont *aFont) const; +}; + +#endif /* nsDeviceContextQt_h___ */ + diff --git a/mozilla/gfx/src/qt/nsDeviceContextSpecFactoryQt.cpp b/mozilla/gfx/src/qt/nsDeviceContextSpecFactoryQt.cpp new file mode 100644 index 00000000000..7e3e3b33067 --- /dev/null +++ b/mozilla/gfx/src/qt/nsDeviceContextSpecFactoryQt.cpp @@ -0,0 +1,82 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * Roland Mainz + * + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsDeviceContextSpecFactoryQt.h" +#include "nsDeviceContextSpecQt.h" +#include "nsGfxCIID.h" +#include "plstr.h" + +NS_IMPL_ISUPPORTS1(nsDeviceContextSpecFactoryQt, nsIDeviceContextSpecFactory) + +nsDeviceContextSpecFactoryQt::nsDeviceContextSpecFactoryQt() +{ +} + +nsDeviceContextSpecFactoryQt::~nsDeviceContextSpecFactoryQt() +{ +} + +NS_IMETHODIMP nsDeviceContextSpecFactoryQt::Init(void) +{ + return NS_OK; +} + +NS_IMETHODIMP nsDeviceContextSpecFactoryQt::CreateDeviceContextSpec(nsIWidget *aWidget, + nsIPrintSettings* aPrintSettings, + nsIDeviceContextSpec *&aNewSpec, + PRBool aIsPrintPreview) +{ + nsresult rv; + static NS_DEFINE_CID(kDeviceContextSpecCID, NS_DEVICE_CONTEXT_SPEC_CID); + nsCOMPtr devSpec = do_CreateInstance(kDeviceContextSpecCID, &rv); + if (NS_SUCCEEDED(rv)) + { + rv = ((nsDeviceContextSpecQt *)devSpec.get())->Init(aPrintSettings); + if (NS_SUCCEEDED(rv)) + { + aNewSpec = devSpec; + NS_ADDREF(aNewSpec); + } + } + + return rv; +} + diff --git a/mozilla/gfx/src/qt/nsDeviceContextSpecFactoryQt.h b/mozilla/gfx/src/qt/nsDeviceContextSpecFactoryQt.h new file mode 100644 index 00000000000..b1f9c06c702 --- /dev/null +++ b/mozilla/gfx/src/qt/nsDeviceContextSpecFactoryQt.h @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * Roland Mainz + * + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsDeviceContextSpecFactoryQt_h___ +#define nsDeviceContextSpecFactoryQt_h___ + +#include "nsIDeviceContextSpecFactory.h" +#include "nsIDeviceContextSpec.h" + +class nsDeviceContextSpecFactoryQt : public nsIDeviceContextSpecFactory +{ + +public: + nsDeviceContextSpecFactoryQt(); + + NS_DECL_ISUPPORTS + + NS_IMETHOD Init(void); + NS_IMETHOD CreateDeviceContextSpec(nsIWidget *aWidget, + nsIPrintSettings* aPrintSettings, + nsIDeviceContextSpec *&aNewSpec, + PRBool aIsPrintPreview); + +protected: + virtual ~nsDeviceContextSpecFactoryQt(); +}; + +#endif /* !nsDeviceContextSpecFactoryQt_h___ */ diff --git a/mozilla/gfx/src/qt/nsDeviceContextSpecQt.cpp b/mozilla/gfx/src/qt/nsDeviceContextSpecQt.cpp new file mode 100644 index 00000000000..3a0cc4a7841 --- /dev/null +++ b/mozilla/gfx/src/qt/nsDeviceContextSpecQt.cpp @@ -0,0 +1,1057 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * Roland Mainz + * + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +/* Store per-printer features in temp. prefs vars that the + * print dialog can pick them up... */ +#define SET_PRINTER_FEATURES_VIA_PREFS 1 +#define PRINTERFEATURES_PREF "print.tmp.printerfeatures" + +#define FORCE_PR_LOG /* Allow logging in the release build */ +#define PR_LOGGING 1 +#include "prlog.h" + +#include "nsDeviceContextSpecQt.h" + +#include "nsIPref.h" +#include "prenv.h" /* for PR_GetEnv */ + +#include "nsPrintfCString.h" +#include "nsReadableUtils.h" +#include "nsIServiceManager.h" +#include "nsCRT.h" + +#ifdef USE_XPRINT +#include "xprintutil.h" +#endif /* USE_XPRINT */ + +#ifdef USE_POSTSCRIPT +/* Fetch |postscript_module_paper_sizes| */ +#undef USE_POSTSCRIPT +#warning "fixme: postscript disabled" +//#include "nsPaperPS.h" +#endif /* USE_POSTSCRIPT */ + +/* Ensure that the result is always equal to either PR_TRUE or PR_FALSE */ +#define MAKE_PR_BOOL(val) ((val)?(PR_TRUE):(PR_FALSE)) + +#ifdef PR_LOGGING +static PRLogModuleInfo *DeviceContextSpecQtLM = PR_NewLogModule("DeviceContextSpecQt"); +#endif /* PR_LOGGING */ +/* Macro to make lines shorter */ +#define DO_PR_DEBUG_LOG(x) PR_LOG(DeviceContextSpecQtLM, PR_LOG_DEBUG, x) + +//---------------------------------------------------------------------------------- +// The printer data is shared between the PrinterEnumerator and the nsDeviceContextSpecQt +// The PrinterEnumerator creates the printer info +// but the nsDeviceContextSpecQt cleans it up +// If it gets created (via the Page Setup Dialog) but the user never prints anything +// then it will never be delete, so this class takes care of that. +class GlobalPrinters { +public: + static GlobalPrinters* GetInstance() { return &mGlobalPrinters; } + ~GlobalPrinters() { FreeGlobalPrinters(); } + + void FreeGlobalPrinters(); + nsresult InitializeGlobalPrinters(); + + PRBool PrintersAreAllocated() { return mGlobalPrinterList != nsnull; } + PRInt32 GetNumPrinters() { return mGlobalNumPrinters; } + nsString* GetStringAt(PRInt32 aInx) { return mGlobalPrinterList->StringAt(aInx); } + void GetDefaultPrinterName(PRUnichar **aDefaultPrinterName); + +protected: + GlobalPrinters() {} + + static GlobalPrinters mGlobalPrinters; + static nsStringArray* mGlobalPrinterList; + static int mGlobalNumPrinters; +}; + +#ifdef SET_PRINTER_FEATURES_VIA_PREFS +/* "Prototype" for the new nsPrinterFeatures service */ +class nsPrinterFeatures { +public: + nsPrinterFeatures( const char *printername ); + ~nsPrinterFeatures() {}; + + /* Does this device allow to set/change the paper size ? */ + void SetCanChangePaperSize( PRBool aCanSetPaperSize ); + /* Set number of paper size records and the records itself */ + void SetNumPaperSizeRecords( PRInt32 aCount ); + void SetPaperRecord( PRInt32 aIndex, const char *aName, PRInt32 aWidthMM, PRInt32 aHeightMM, PRBool aIsInch ); + + /* Does this device allow to set/change the content orientation ? */ + void SetCanChangeOrientation( PRBool aCanSetOrientation ); + /* Set number of orientation records and the records itself */ + void SetNumOrientationRecords( PRInt32 aCount ); + void SetOrientationRecord( PRInt32 aIndex, const char *aName ); + + /* Does this device allow to set/change the spooler command ? */ + void SetCanChangeSpoolerCommand( PRBool aCanSetSpoolerCommand ); + + /* Does this device allow to set/change number of copies for an document ? */ + void SetCanChangeNumCopies( PRBool aCanSetNumCopies ); + + /* Does this device allow multiple devicecontext instances to be used in + * parallel (e.g. print while the device is already in use by print-preview + * or printing while another print job is in progress) ? */ + void SetMultipleConcurrentDeviceContextsSupported( PRBool aCanUseMultipleInstances ); + +private: + /* private helper methods */ + void SetBoolValue( const char *tagname, PRBool value ); + void SetIntValue( const char *tagname, PRInt32 value ); + void SetCharValue( const char *tagname, const char *value ); + + nsXPIDLCString mPrinterName; + nsCOMPtr mPrefs; +}; + +void nsPrinterFeatures::SetBoolValue( const char *tagname, PRBool value ) +{ + mPrefs->SetBoolPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.%s", mPrinterName.get(), tagname).get(), value); +} + +void nsPrinterFeatures::SetIntValue( const char *tagname, PRInt32 value ) +{ + mPrefs->SetIntPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.%s", mPrinterName.get(), tagname).get(), value); +} + +void nsPrinterFeatures::SetCharValue( const char *tagname, const char *value ) +{ + mPrefs->SetCharPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.%s", mPrinterName.get(), tagname).get(), value); +} + +nsPrinterFeatures::nsPrinterFeatures( const char *printername ) +{ + DO_PR_DEBUG_LOG(("nsPrinterFeatures::nsPrinterFeatures('%s')\n", printername)); + mPrinterName.Assign(printername); + mPrefs = do_GetService(NS_PREF_CONTRACTID); + + SetBoolValue("has_special_printerfeatures", PR_TRUE); +} + +void nsPrinterFeatures::SetCanChangePaperSize( PRBool aCanSetPaperSize ) +{ + SetBoolValue("can_change_paper_size", aCanSetPaperSize); +} + +/* Set number of paper size records and the records itself */ +void nsPrinterFeatures::SetNumPaperSizeRecords( PRInt32 aCount ) +{ + SetIntValue("paper.count", aCount); +} + +void nsPrinterFeatures::SetPaperRecord(PRInt32 aIndex, const char *aPaperName, PRInt32 aWidthMM, PRInt32 aHeightMM, PRBool aIsInch) +{ + SetCharValue(nsPrintfCString(256, "paper.%d.name", aIndex).get(), aPaperName); + SetIntValue( nsPrintfCString(256, "paper.%d.width_mm", aIndex).get(), aWidthMM); + SetIntValue( nsPrintfCString(256, "paper.%d.height_mm", aIndex).get(), aHeightMM); + SetBoolValue(nsPrintfCString(256, "paper.%d.is_inch", aIndex).get(), aIsInch); +} + +void nsPrinterFeatures::SetCanChangeOrientation( PRBool aCanSetOrientation ) +{ + SetBoolValue("can_change_orientation", aCanSetOrientation); +} + +void nsPrinterFeatures::SetNumOrientationRecords( PRInt32 aCount ) +{ + SetIntValue("orientation.count", aCount); +} + +void nsPrinterFeatures::SetOrientationRecord( PRInt32 aIndex, const char *aOrientationName ) +{ + SetCharValue(nsPrintfCString(256, "orientation.%d.name", aIndex).get(), aOrientationName); +} + +void nsPrinterFeatures::SetCanChangeSpoolerCommand( PRBool aCanSetSpoolerCommand ) +{ + SetBoolValue("can_change_spoolercommand", aCanSetSpoolerCommand); +} + +void nsPrinterFeatures::SetCanChangeNumCopies( PRBool aCanSetNumCopies ) +{ + SetBoolValue("can_change_num_copies", aCanSetNumCopies); +} + +void nsPrinterFeatures::SetMultipleConcurrentDeviceContextsSupported( PRBool aCanUseMultipleInstances ) +{ + SetBoolValue("can_use_multiple_devicecontexts_concurrently", aCanUseMultipleInstances); +} + +#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ + +//--------------- +// static members +GlobalPrinters GlobalPrinters::mGlobalPrinters; +nsStringArray* GlobalPrinters::mGlobalPrinterList = nsnull; +int GlobalPrinters::mGlobalNumPrinters = 0; +//--------------- + +nsDeviceContextSpecQt::nsDeviceContextSpecQt() +{ + DO_PR_DEBUG_LOG(("nsDeviceContextSpecQt::nsDeviceContextSpecQt()\n")); +} + +nsDeviceContextSpecQt::~nsDeviceContextSpecQt() +{ + DO_PR_DEBUG_LOG(("nsDeviceContextSpecQt::~nsDeviceContextSpecQt()\n")); +} + +/* Use both PostScript and Xprint module */ +#if defined(USE_XPRINT) && defined(USE_POSTSCRIPT) +NS_IMPL_ISUPPORTS3(nsDeviceContextSpecQt, + nsIDeviceContextSpec, + nsIDeviceContextSpecPS, + nsIDeviceContextSpecXp) +/* Use only PostScript module */ +#elif !defined(USE_XPRINT) && defined(USE_POSTSCRIPT) +NS_IMPL_ISUPPORTS2(nsDeviceContextSpecQt, + nsIDeviceContextSpec, + nsIDeviceContextSpecPS) +/* Use only Xprint module module */ +#elif defined(USE_XPRINT) && !defined(USE_POSTSCRIPT) +NS_IMPL_ISUPPORTS2(nsDeviceContextSpecQt, + nsIDeviceContextSpec, + nsIDeviceContextSpecXp) +/* Both Xprint and PostScript module are missing */ +#elif !defined(USE_XPRINT) && !defined(USE_POSTSCRIPT) +NS_IMPL_ISUPPORTS1(nsDeviceContextSpecQt, + nsIDeviceContextSpec) +#else +#error "This should not happen" +#endif + +/** ------------------------------------------------------- + * Initialize the nsDeviceContextSpecQt + * @update dc 2/15/98 + * @update syd 3/2/99 + * + * gisburn: Please note that this function exists as 1:1 copy in other + * toolkits including: + * - GTK+-toolkit: + * file: mozilla/gfx/src/gtk/nsDeviceContextSpecG.cpp + * function: NS_IMETHODIMP nsDeviceContextSpecGTK::Init() + * - Xlib-toolkit: + * file: mozilla/gfx/src/xlib/nsDeviceContextSpecQt.cpp + * function: NS_IMETHODIMP nsDeviceContextSpecQt::Init() + * - Qt-toolkit: + * file: mozilla/gfx/src/qt/nsDeviceContextSpecQt.cpp + * function: NS_IMETHODIMP nsDeviceContextSpecQt::Init() + * + * ** Please update the other toolkits when changing this function. + */ +NS_IMETHODIMP nsDeviceContextSpecQt::Init(nsIPrintSettings *aPS) +{ + DO_PR_DEBUG_LOG(("nsDeviceContextSpecQt::Init(aPS=%p\n", aPS)); + nsresult rv = NS_ERROR_FAILURE; + + mPrintSettings = aPS; + + // if there is a current selection then enable the "Selection" radio button + if (mPrintSettings) { + PRBool isOn; + mPrintSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &isOn); + nsCOMPtr pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv)) { + (void) pPrefs->SetBoolPref("print.selection_radio_enabled", isOn); + } + } + + rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters(); + if (NS_FAILED(rv)) { + return rv; + } + + GlobalPrinters::GetInstance()->FreeGlobalPrinters(); + + if (aPS) { + PRBool reversed = PR_FALSE; + PRBool color = PR_FALSE; + PRBool tofile = PR_FALSE; + PRInt16 printRange = nsIPrintSettings::kRangeAllPages; + PRInt32 orientation = NS_PORTRAIT; + PRInt32 fromPage = 1; + PRInt32 toPage = 1; + PRUnichar *command = nsnull; + PRInt32 copies = 1; + PRUnichar *printer = nsnull; + PRUnichar *papername = nsnull; + PRUnichar *printfile = nsnull; + double dleft = 0.5; + double dright = 0.5; + double dtop = 0.5; + double dbottom = 0.5; + + aPS->GetPrinterName(&printer); + aPS->GetPrintReversed(&reversed); + aPS->GetPrintInColor(&color); + aPS->GetPaperName(&papername); + aPS->GetOrientation(&orientation); + aPS->GetPrintCommand(&command); + aPS->GetPrintRange(&printRange); + aPS->GetToFileName(&printfile); + aPS->GetPrintToFile(&tofile); + aPS->GetStartPageRange(&fromPage); + aPS->GetEndPageRange(&toPage); + aPS->GetNumCopies(&copies); + aPS->GetMarginTop(&dtop); + aPS->GetMarginLeft(&dleft); + aPS->GetMarginBottom(&dbottom); + aPS->GetMarginRight(&dright); + + if (printfile) + strcpy(mPath, NS_ConvertUCS2toUTF8(printfile).get()); + if (command) + strcpy(mCommand, NS_ConvertUCS2toUTF8(command).get()); + if (printer) + strcpy(mPrinter, NS_ConvertUCS2toUTF8(printer).get()); + if (papername) + strcpy(mPaperName, NS_ConvertUCS2toUTF8(papername).get()); + + DO_PR_DEBUG_LOG(("margins: %5.2f,%5.2f,%5.2f,%5.2f\n", dtop, dleft, dbottom, dright)); + DO_PR_DEBUG_LOG(("printRange %d\n", printRange)); + DO_PR_DEBUG_LOG(("fromPage %d\n", fromPage)); + DO_PR_DEBUG_LOG(("toPage %d\n", toPage)); + DO_PR_DEBUG_LOG(("tofile %d\n", tofile)); + DO_PR_DEBUG_LOG(("printfile '%s'\n", printfile? NS_ConvertUCS2toUTF8(printfile).get():"")); + DO_PR_DEBUG_LOG(("command '%s'\n", command? NS_ConvertUCS2toUTF8(command).get():"")); + DO_PR_DEBUG_LOG(("printer '%s'\n", printer? NS_ConvertUCS2toUTF8(printer).get():"")); + DO_PR_DEBUG_LOG(("papername '%s'\n", papername? NS_ConvertUCS2toUTF8(papername).get():"")); + + mTop = dtop; + mBottom = dbottom; + mLeft = dleft; + mRight = dright; + mFpf = !reversed; + mGrayscale = !color; + mOrientation = orientation; + mToPrinter = !tofile; + mCopies = copies; + } + + return rv; +} + +NS_IMETHODIMP nsDeviceContextSpecQt::GetToPrinter(PRBool &aToPrinter) +{ + aToPrinter = mToPrinter; + return NS_OK; +} + +NS_IMETHODIMP nsDeviceContextSpecQt::GetPrinterName ( const char **aPrinter ) +{ + *aPrinter = mPrinter; + return NS_OK; +} + +NS_IMETHODIMP nsDeviceContextSpecQt::GetCopies ( int &aCopies ) +{ + aCopies = mCopies; + return NS_OK; +} + +NS_IMETHODIMP nsDeviceContextSpecQt::GetFirstPageFirst(PRBool &aFpf) +{ + aFpf = mFpf; + return NS_OK; +} + +NS_IMETHODIMP nsDeviceContextSpecQt::GetGrayscale(PRBool &aGrayscale) +{ + aGrayscale = mGrayscale; + return NS_OK; +} + +NS_IMETHODIMP nsDeviceContextSpecQt::GetLandscape(PRBool &aLandscape) +{ + aLandscape = (mOrientation == NS_LANDSCAPE); + return NS_OK; +} + +NS_IMETHODIMP nsDeviceContextSpecQt::GetTopMargin(float &aValue) +{ + aValue = mTop; + return NS_OK; +} + +NS_IMETHODIMP nsDeviceContextSpecQt::GetBottomMargin(float &aValue) +{ + aValue = mBottom; + return NS_OK; +} + +NS_IMETHODIMP nsDeviceContextSpecQt::GetRightMargin(float &aValue) +{ + aValue = mRight; + return NS_OK; +} + +NS_IMETHODIMP nsDeviceContextSpecQt::GetLeftMargin(float &aValue) +{ + aValue = mLeft; + return NS_OK; +} + +NS_IMETHODIMP nsDeviceContextSpecQt::GetCommand(const char **aCommand) +{ + *aCommand = mCommand; + return NS_OK; +} + +NS_IMETHODIMP nsDeviceContextSpecQt::GetPath(const char **aPath) +{ + *aPath = mPath; + return NS_OK; +} + +NS_IMETHODIMP nsDeviceContextSpecQt::GetUserCancelled(PRBool &aCancel) +{ + aCancel = mCancel; + return NS_OK; +} + +NS_IMETHODIMP nsDeviceContextSpecQt::GetPaperName( const char **aPaperName ) +{ + *aPaperName = mPaperName; + return NS_OK; +} + +NS_IMETHODIMP nsDeviceContextSpecQt::GetPageSizeInTwips(PRInt32 *aWidth, PRInt32 *aHeight) +{ + return mPrintSettings->GetPageSizeInTwips(aWidth, aHeight); +} + +NS_IMETHODIMP nsDeviceContextSpecQt::GetPrintMethod(PrintMethod &aMethod) +{ + return GetPrintMethod(mPrinter, aMethod); +} + +/* static !! */ +nsresult nsDeviceContextSpecQt::GetPrintMethod(const char *aPrinter, PrintMethod &aMethod) +{ +#if defined(USE_POSTSCRIPT) && defined(USE_XPRINT) + /* printer names for the PostScript module alwas start with + * the NS_POSTSCRIPT_DRIVER_NAME string */ + if (strncmp(aPrinter, NS_POSTSCRIPT_DRIVER_NAME, + NS_POSTSCRIPT_DRIVER_NAME_LEN) != 0) + aMethod = pmXprint; + else + aMethod = pmPostScript; + return NS_OK; +#elif defined(USE_XPRINT) + aMethod = pmXprint; + return NS_OK; +#elif defined(USE_POSTSCRIPT) + aMethod = pmPostScript; + return NS_OK; +#else + return NS_ERROR_UNEXPECTED; +#endif +} + +NS_IMETHODIMP nsDeviceContextSpecQt::ClosePrintManager() +{ + return NS_OK; +} + +/* Get prefs for printer + * Search order: + * - Get prefs per printer name and module name + * - Get prefs per printer name + * - Get prefs per module name + * - Get prefs + */ +static +nsresult CopyPrinterCharPref(nsIPref *pref, const char *modulename, const char *printername, const char *prefname, char **return_buf) +{ + DO_PR_DEBUG_LOG(("CopyPrinterCharPref('%s', '%s', '%s')\n", modulename, printername, prefname)); + + NS_ENSURE_ARG_POINTER(return_buf); + + nsXPIDLCString name; + nsresult rv = NS_ERROR_FAILURE; + + if (printername && modulename) { + /* Get prefs per printer name and module name */ + name = nsPrintfCString(512, "print.%s.printer_%s.%s", modulename, printername, prefname); + DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get())); + rv = pref->CopyCharPref(name, return_buf); + } + + if (NS_FAILED(rv)) { + if (printername) { + /* Get prefs per printer name */ + name = nsPrintfCString(512, "print.printer_%s.%s", printername, prefname); + DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get())); + rv = pref->CopyCharPref(name, return_buf); + } + + if (NS_FAILED(rv)) { + if (modulename) { + /* Get prefs per module name */ + name = nsPrintfCString(512, "print.%s.%s", modulename, prefname); + DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get())); + rv = pref->CopyCharPref(name, return_buf); + } + + if (NS_FAILED(rv)) { + /* Get prefs */ + name = nsPrintfCString(512, "print.%s", prefname); + DO_PR_DEBUG_LOG(("trying to get '%s'\n", name.get())); + rv = pref->CopyCharPref(name, return_buf); + } + } + } + +#ifdef PR_LOG + if (NS_SUCCEEDED(rv)) { + DO_PR_DEBUG_LOG(("CopyPrinterCharPref returning '%s'.\n", *return_buf)); + } + else + { + DO_PR_DEBUG_LOG(("CopyPrinterCharPref failure.\n")); + } +#endif /* PR_LOG */ + + return rv; +} + +// Printer Enumerator +nsPrinterEnumeratorQt::nsPrinterEnumeratorQt() +{ +} + +NS_IMPL_ISUPPORTS1(nsPrinterEnumeratorQt, nsIPrinterEnumerator) + +NS_IMETHODIMP nsPrinterEnumeratorQt::EnumeratePrinters(PRUint32* aCount, PRUnichar*** aResult) +{ + NS_ENSURE_ARG(aCount); + NS_ENSURE_ARG_POINTER(aResult); + + if (aCount) + *aCount = 0; + else + return NS_ERROR_NULL_POINTER; + + if (aResult) + *aResult = nsnull; + else + return NS_ERROR_NULL_POINTER; + + nsresult rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters(); + if (NS_FAILED(rv)) { + return rv; + } + + PRInt32 numPrinters = GlobalPrinters::GetInstance()->GetNumPrinters(); + + PRUnichar** array = (PRUnichar**) nsMemory::Alloc(numPrinters * sizeof(PRUnichar*)); + if (!array && numPrinters > 0) { + GlobalPrinters::GetInstance()->FreeGlobalPrinters(); + return NS_ERROR_OUT_OF_MEMORY; + } + + int count = 0; + while( count < numPrinters ) + { + PRUnichar *str = ToNewUnicode(*GlobalPrinters::GetInstance()->GetStringAt(count)); + + if (!str) { + for (int i = count - 1; i >= 0; i--) + nsMemory::Free(array[i]); + + nsMemory::Free(array); + + GlobalPrinters::GetInstance()->FreeGlobalPrinters(); + return NS_ERROR_OUT_OF_MEMORY; + } + array[count++] = str; + + } + *aCount = count; + *aResult = array; + GlobalPrinters::GetInstance()->FreeGlobalPrinters(); + + return NS_OK; +} + +/* readonly attribute wstring defaultPrinterName; */ +NS_IMETHODIMP nsPrinterEnumeratorQt::GetDefaultPrinterName(PRUnichar **aDefaultPrinterName) +{ + DO_PR_DEBUG_LOG(("nsPrinterEnumeratorQt::GetDefaultPrinterName()\n")); + NS_ENSURE_ARG_POINTER(aDefaultPrinterName); + + GlobalPrinters::GetInstance()->GetDefaultPrinterName(aDefaultPrinterName); + + DO_PR_DEBUG_LOG(("GetDefaultPrinterName(): default printer='%s'.\n", NS_ConvertUCS2toUTF8(*aDefaultPrinterName).get())); + return NS_OK; +} + +/* void initPrintSettingsFromPrinter (in wstring aPrinterName, in nsIPrintSettings aPrintSettings); */ +NS_IMETHODIMP nsPrinterEnumeratorQt::InitPrintSettingsFromPrinter(const PRUnichar *aPrinterName, nsIPrintSettings *aPrintSettings) +{ + DO_PR_DEBUG_LOG(("nsPrinterEnumeratorQt::InitPrintSettingsFromPrinter()")); + nsresult rv; + + NS_ENSURE_ARG_POINTER(aPrinterName); + NS_ENSURE_ARG_POINTER(aPrintSettings); + + NS_ENSURE_TRUE(*aPrinterName, NS_ERROR_FAILURE); + NS_ENSURE_TRUE(aPrintSettings, NS_ERROR_FAILURE); + + nsCOMPtr pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv); + if (NS_FAILED(rv)) + return rv; + + nsXPIDLCString fullPrinterName, /* Full name of printer incl. driver-specific prefix */ + printerName; /* "Stripped" name of printer */ + fullPrinterName.Assign(NS_ConvertUCS2toUTF8(aPrinterName)); + printerName.Assign(NS_ConvertUCS2toUTF8(aPrinterName)); + DO_PR_DEBUG_LOG(("printerName='%s'\n", printerName.get())); + + PrintMethod type = pmInvalid; + rv = nsDeviceContextSpecQt::GetPrintMethod(printerName, type); + if (NS_FAILED(rv)) + return rv; + +#ifdef USE_POSTSCRIPT + /* "Demangle" postscript printer name */ + if (type == pmPostScript) { + /* Strip the leading NS_POSTSCRIPT_DRIVER_NAME from |printerName|, + * e.g. turn "PostScript/foobar" to "foobar" */ + printerName.Cut(0, NS_POSTSCRIPT_DRIVER_NAME_LEN); + } +#endif /* USE_POSTSCRIPT */ + +#ifdef SET_PRINTER_FEATURES_VIA_PREFS + /* Defaults to FALSE */ + pPrefs->SetBoolPref(nsPrintfCString(256, PRINTERFEATURES_PREF ".%s.has_special_printerfeatures", fullPrinterName.get()).get(), PR_FALSE); +#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ + + + /* Set filename */ + nsXPIDLCString filename; + if (NS_FAILED(CopyPrinterCharPref(pPrefs, nsnull, printerName, "filename", getter_Copies(filename)))) { + const char *path; + + if (!(path = PR_GetEnv("PWD"))) + path = PR_GetEnv("HOME"); + + if (path) + filename = nsPrintfCString(PATH_MAX, "%s/mozilla.ps", path); + else + filename.Assign("mozilla.ps"); + } + DO_PR_DEBUG_LOG(("Setting default filename to '%s'\n", filename.get())); + aPrintSettings->SetToFileName(NS_ConvertUTF8toUCS2(filename).get()); + + aPrintSettings->SetIsInitializedFromPrinter(PR_TRUE); +#ifdef USE_XPRINT + if (type == pmXprint) { + DO_PR_DEBUG_LOG(("InitPrintSettingsFromPrinter() for Xprint printer\n")); + + Display *pdpy; + XPContext pcontext; + if (XpuGetPrinter(printerName, &pdpy, &pcontext) != 1) + return NS_ERROR_GFX_PRINTER_NAME_NOT_FOUND; + + XpuSupportedFlags supported_doc_attrs = XpuGetSupportedDocAttributes(pdpy, pcontext); + +#ifdef SET_PRINTER_FEATURES_VIA_PREFS + nsPrinterFeatures printerFeatures(fullPrinterName); +#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ + + /* Setup orientation stuff */ + XpuOrientationList olist; + int ocount; + XpuOrientationRec *default_orientation; + +#ifdef SET_PRINTER_FEATURES_VIA_PREFS + PRBool canSetOrientation = MAKE_PR_BOOL(supported_doc_attrs & XPUATTRIBUTESUPPORTED_CONTENT_ORIENTATION); + printerFeatures.SetCanChangeOrientation(canSetOrientation); +#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ + + /* Get list of supported orientations */ + olist = XpuGetOrientationList(pdpy, pcontext, &ocount); + if (olist) { + default_orientation = &olist[0]; /* First entry is the default one */ + + if (!PL_strcasecmp(default_orientation->orientation, "portrait")) { + DO_PR_DEBUG_LOG(("setting default orientation to 'portrait'\n")); + aPrintSettings->SetOrientation(nsIPrintSettings::kPortraitOrientation); + } + else if (!PL_strcasecmp(default_orientation->orientation, "landscape")) { + DO_PR_DEBUG_LOG(("setting default orientation to 'landscape'\n")); + aPrintSettings->SetOrientation(nsIPrintSettings::kLandscapeOrientation); + } + else { + DO_PR_DEBUG_LOG(("Unknown default orientation '%s'\n", default_orientation->orientation)); + } + +#ifdef SET_PRINTER_FEATURES_VIA_PREFS + int i; + for( i = 0 ; i < ocount ; i++ ) + { + XpuOrientationRec *curr = &olist[i]; + printerFeatures.SetOrientationRecord(i, curr->orientation); + } + printerFeatures.SetNumOrientationRecords(ocount); +#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ + + XpuFreeOrientationList(olist); + } + + /* Setup Number of Copies */ +#ifdef SET_PRINTER_FEATURES_VIA_PREFS + PRBool canSetNumCopies = MAKE_PR_BOOL(supported_doc_attrs & XPUATTRIBUTESUPPORTED_COPY_COUNT); + printerFeatures.SetCanChangeNumCopies(canSetNumCopies); +#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ + long numCopies; + if( XpuGetOneLongAttribute(pdpy, pcontext, XPDocAttr, "copy-count", &numCopies) != 1 ) + { + /* Fallback on failure */ + numCopies = 1; + } + aPrintSettings->SetNumCopies(numCopies); + + /* Setup paper size stuff */ + XpuMediumSourceSizeList mlist; + int mcount; + XpuMediumSourceSizeRec *default_medium; + +#ifdef SET_PRINTER_FEATURES_VIA_PREFS + PRBool canSetPaperSize = MAKE_PR_BOOL(supported_doc_attrs & XPUATTRIBUTESUPPORTED_DEFAULT_MEDIUM); + printerFeatures.SetCanChangePaperSize(canSetPaperSize); +#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ + + mlist = XpuGetMediumSourceSizeList(pdpy, pcontext, &mcount); + if (mlist) { + nsXPIDLCString papername; + + default_medium = &mlist[0]; /* First entry is the default one */ + double total_width = default_medium->ma1 + default_medium->ma2, + total_height = default_medium->ma3 + default_medium->ma4; + + /* Either "paper" or "tray/paper" */ + if (default_medium->tray_name) { + papername = nsPrintfCString(256, "%s/%s", default_medium->tray_name, default_medium->medium_name); + } + else { + papername.Assign(default_medium->medium_name); + } + + DO_PR_DEBUG_LOG(("setting default paper size to '%s' (%g/%g mm)\n", papername.get(), total_width, total_height)); + aPrintSettings->SetPaperSizeType(nsIPrintSettings::kPaperSizeDefined); + aPrintSettings->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeMillimeters); + aPrintSettings->SetPaperWidth(total_width); + aPrintSettings->SetPaperHeight(total_height); + aPrintSettings->SetPaperName(NS_ConvertUTF8toUCS2(papername).get()); + +#ifdef SET_PRINTER_FEATURES_VIA_PREFS + int i; + for( i = 0 ; i < mcount ; i++ ) + { + XpuMediumSourceSizeRec *curr = &mlist[i]; + double total_width = curr->ma1 + curr->ma2, + total_height = curr->ma3 + curr->ma4; + if (curr->tray_name) { + papername = nsPrintfCString(256, "%s/%s", curr->tray_name, curr->medium_name); + } + else { + papername.Assign(curr->medium_name); + } + + printerFeatures.SetPaperRecord(i, papername, PRInt32(total_width), PRInt32(total_height), PR_FALSE); + } + printerFeatures.SetNumPaperSizeRecords(mcount); +#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ + + XpuFreeMediumSourceSizeList(mlist); + } + +#ifdef SET_PRINTER_FEATURES_VIA_PREFS + /* Xprint does not allow the client to set a spooler command. + * Job spooling is the job of the server side (=Xprt) */ + printerFeatures.SetCanChangeSpoolerCommand(PR_FALSE); + + /* Mozilla's Xprint support allows multiple nsIDeviceContext instances + * be used in parallel */ + printerFeatures.SetMultipleConcurrentDeviceContextsSupported(PR_TRUE); +#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ + + XpuClosePrinterDisplay(pdpy, pcontext); + + return NS_OK; + } + else +#endif /* USE_XPRINT */ + +#ifdef USE_POSTSCRIPT + if (type == pmPostScript) { + DO_PR_DEBUG_LOG(("InitPrintSettingsFromPrinter() for PostScript printer\n")); + +#ifdef SET_PRINTER_FEATURES_VIA_PREFS + nsPrinterFeatures printerFeatures(fullPrinterName); +#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ + +#ifdef SET_PRINTER_FEATURES_VIA_PREFS + printerFeatures.SetCanChangeOrientation(PR_TRUE); +#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ + + nsXPIDLCString orientation; + if (NS_SUCCEEDED(CopyPrinterCharPref(pPrefs, "postscript", printerName, "orientation", getter_Copies(orientation)))) { + if (!PL_strcasecmp(orientation, "portrait")) { + DO_PR_DEBUG_LOG(("setting default orientation to 'portrait'\n")); + aPrintSettings->SetOrientation(nsIPrintSettings::kPortraitOrientation); + } + else if (!PL_strcasecmp(orientation, "landscape")) { + DO_PR_DEBUG_LOG(("setting default orientation to 'landscape'\n")); + aPrintSettings->SetOrientation(nsIPrintSettings::kLandscapeOrientation); + } + else { + DO_PR_DEBUG_LOG(("Unknown default orientation '%s'\n", orientation.get())); + } + } + +#ifdef SET_PRINTER_FEATURES_VIA_PREFS + int i; + for( i = 0 ; postscript_module_orientations[i].orientation != nsnull ; i++ ) + { + const PSOrientationRec *curr = &postscript_module_orientations[i]; + printerFeatures.SetOrientationRecord(i, curr->orientation); + } + printerFeatures.SetNumOrientationRecords(i); +#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ + +#ifdef SET_PRINTER_FEATURES_VIA_PREFS + printerFeatures.SetCanChangePaperSize(PR_TRUE); +#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ + nsXPIDLCString papername; + if (NS_SUCCEEDED(CopyPrinterCharPref(pPrefs, "postscript", printerName, "paper_size", getter_Copies(papername)))) { + int i; + const PSPaperSizeRec *default_paper = nsnull; + + for( i = 0 ; postscript_module_paper_sizes[i].name != nsnull ; i++ ) + { + const PSPaperSizeRec *curr = &postscript_module_paper_sizes[i]; + + if (!PL_strcasecmp(papername, curr->name)) { + default_paper = curr; + break; + } + } + + if (default_paper) { + DO_PR_DEBUG_LOG(("setting default paper size to '%s' (%g inch/%g inch)\n", + default_paper->name, + PSPaperSizeRec_FullPaperWidth(default_paper), + PSPaperSizeRec_FullPaperHeight(default_paper))); + aPrintSettings->SetPaperSizeType(nsIPrintSettings::kPaperSizeDefined); + aPrintSettings->SetPaperSizeUnit(nsIPrintSettings::kPaperSizeInches); + aPrintSettings->SetPaperWidth(PSPaperSizeRec_FullPaperWidth(default_paper)); + aPrintSettings->SetPaperHeight(PSPaperSizeRec_FullPaperHeight(default_paper)); + aPrintSettings->SetPaperName(NS_ConvertUTF8toUCS2(default_paper->name).get()); + } + else { + DO_PR_DEBUG_LOG(("Unknown paper size '%s' given.\n", papername.get())); + } +#ifdef SET_PRINTER_FEATURES_VIA_PREFS + for( i = 0 ; postscript_module_paper_sizes[i].name != nsnull ; i++ ) + { + const PSPaperSizeRec *curr = &postscript_module_paper_sizes[i]; +#define CONVERT_INCH_TO_MILLIMETERS(inch) ((inch) * 25.4) + double total_width = CONVERT_INCH_TO_MILLIMETERS(PSPaperSizeRec_FullPaperWidth(curr)), + total_height = CONVERT_INCH_TO_MILLIMETERS(PSPaperSizeRec_FullPaperHeight(curr)); + + printerFeatures.SetPaperRecord(i, curr->name, PRInt32(total_width), PRInt32(total_height), PR_TRUE); + } + printerFeatures.SetNumPaperSizeRecords(i); +#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ + } + +#ifdef SET_PRINTER_FEATURES_VIA_PREFS + printerFeatures.SetCanChangeSpoolerCommand(PR_TRUE); +#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ + + nsXPIDLCString command; + if (NS_SUCCEEDED(CopyPrinterCharPref(pPrefs, "postscript", printerName, "print_command", getter_Copies(command)))) { + DO_PR_DEBUG_LOG(("setting default print command to '%s'\n", command.get())); + aPrintSettings->SetPrintCommand(NS_ConvertUTF8toUCS2(command).get()); + } + +#ifdef SET_PRINTER_FEATURES_VIA_PREFS + printerFeatures.SetCanChangeNumCopies(PR_TRUE); +#endif /* SET_PRINTER_FEATURES_VIA_PREFS */ + + return NS_OK; + } +#endif /* USE_POSTSCRIPT */ + + return NS_ERROR_UNEXPECTED; +} + +NS_IMETHODIMP nsPrinterEnumeratorQt::DisplayPropertiesDlg(const PRUnichar *aPrinter, nsIPrintSettings *aPrintSettings) +{ + return NS_OK; +} + +//---------------------------------------------------------------------- +nsresult GlobalPrinters::InitializeGlobalPrinters () +{ + if (PrintersAreAllocated()) { + return NS_OK; + } + + mGlobalNumPrinters = 0; + mGlobalPrinterList = new nsStringArray(); + if (!mGlobalPrinterList) + return NS_ERROR_OUT_OF_MEMORY; + +#ifdef USE_XPRINT + XPPrinterList plist = XpuGetPrinterList(nsnull, &mGlobalNumPrinters); + + if (plist && (mGlobalNumPrinters > 0)) + { + int i; + for( i = 0 ; i < mGlobalNumPrinters ; i++ ) + { + mGlobalPrinterList->AppendString(nsString(NS_ConvertASCIItoUCS2(plist[i].name))); + } + + XpuFreePrinterList(plist); + } +#endif /* USE_XPRINT */ + +#ifdef USE_POSTSCRIPT + /* Get the list of PostScript-module printers */ + char *printerList = nsnull; + PRBool added_default_printer = PR_FALSE; /* Did we already add the default printer ? */ + + /* The env var MOZILLA_POSTSCRIPT_PRINTER_LIST can "override" the prefs */ + printerList = PR_GetEnv("MOZILLA_POSTSCRIPT_PRINTER_LIST"); + + if (!printerList) { + nsresult rv; + nsCOMPtr pPrefs = do_GetService(NS_PREF_CONTRACTID, &rv); + if (NS_SUCCEEDED(rv)) { + (void) pPrefs->CopyCharPref("print.printer_list", &printerList); + } + } + + if (printerList) { + char *tok_lasts; + const char *name; + + /* PL_strtok_r() will modify the string - copy it! */ + printerList = strdup(printerList); + if (!printerList) + return NS_ERROR_OUT_OF_MEMORY; + + for( name = PL_strtok_r(printerList, " ", &tok_lasts) ; + name != nsnull ; + name = PL_strtok_r(nsnull, " ", &tok_lasts) ) + { + /* Is this the "default" printer ? */ + if (!strcmp(name, "default")) + added_default_printer = PR_TRUE; + + mGlobalPrinterList->AppendString( + nsString(NS_ConvertASCIItoUCS2(NS_POSTSCRIPT_DRIVER_NAME)) + + nsString(NS_ConvertASCIItoUCS2(name))); + mGlobalNumPrinters++; + } + + free(printerList); + } + + /* Add an entry for the default printer (see nsPostScriptObj.cpp) if we + * did not add it already... */ + if (!added_default_printer) + { + mGlobalPrinterList->AppendString( + nsString(NS_ConvertASCIItoUCS2(NS_POSTSCRIPT_DRIVER_NAME "default"))); + mGlobalNumPrinters++; + } +#endif /* USE_POSTSCRIPT */ + + if (mGlobalNumPrinters == 0) + return NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE; + + return NS_OK; +} + +//---------------------------------------------------------------------- +void GlobalPrinters::FreeGlobalPrinters() +{ + if (mGlobalPrinterList) { + delete mGlobalPrinterList; + mGlobalPrinterList = nsnull; + mGlobalNumPrinters = 0; + } +} + +void +GlobalPrinters::GetDefaultPrinterName(PRUnichar **aDefaultPrinterName) +{ + *aDefaultPrinterName = nsnull; + + PRBool allocate = (GlobalPrinters::GetInstance()->PrintersAreAllocated() == PR_FALSE); + + if (allocate) { + nsresult rv = GlobalPrinters::GetInstance()->InitializeGlobalPrinters(); + if (NS_FAILED(rv)) { + return; + } + } + NS_ASSERTION(GlobalPrinters::GetInstance()->PrintersAreAllocated(), "no GlobalPrinters"); + + if (GlobalPrinters::GetInstance()->GetNumPrinters() == 0) + return; + + *aDefaultPrinterName = ToNewUnicode(*GlobalPrinters::GetInstance()->GetStringAt(0)); + + if (allocate) { + GlobalPrinters::GetInstance()->FreeGlobalPrinters(); + } +} + diff --git a/mozilla/gfx/src/qt/nsDeviceContextSpecQt.h b/mozilla/gfx/src/qt/nsDeviceContextSpecQt.h new file mode 100644 index 00000000000..d9f2444da71 --- /dev/null +++ b/mozilla/gfx/src/qt/nsDeviceContextSpecQt.h @@ -0,0 +1,136 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * Roland Mainz + * + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsDeviceContextSpecQt_h___ +#define nsDeviceContextSpecQt_h___ + +#include "nsCOMPtr.h" +#include "nsIDeviceContextSpec.h" +#include "nsIPrintSettings.h" +#include "nsIPrintOptions.h" +#include "nsVoidArray.h" +#include +#ifdef USE_POSTSCRIPT +#include "nsIDeviceContextSpecPS.h" +#endif /* USE_POSTSCRIPT */ +#ifdef USE_XPRINT +#include "nsIDeviceContextSpecXPrint.h" +#endif /* USE_XPRINT */ + +#define NS_PORTRAIT 0 +#define NS_LANDSCAPE 1 + +typedef enum +{ + pmInvalid = 0, + pmXprint, + pmPostScript +} PrintMethod; + +class nsDeviceContextSpecQt : public nsIDeviceContextSpec +#ifdef USE_POSTSCRIPT +#warning "postscript hardcore disabled" +#if 0 + + , public nsIDeviceContextSpecPS +#endif +#endif /* USE_POSTSCRIPT */ +#ifdef USE_XPRINT + , public nsIDeviceContextSpecXp +#endif /* USE_XPRINT */ +{ +public: + nsDeviceContextSpecQt(); + + NS_DECL_ISUPPORTS + + NS_IMETHOD Init(nsIPrintSettings* aPS); + NS_IMETHOD ClosePrintManager(); + + NS_IMETHOD GetToPrinter(PRBool &aToPrinter); + NS_IMETHOD GetPrinterName ( const char **aPrinter ); + NS_IMETHOD GetCopies ( int &aCopies ); + NS_IMETHOD GetFirstPageFirst(PRBool &aFpf); + NS_IMETHOD GetGrayscale(PRBool &aGrayscale); + NS_IMETHOD GetTopMargin(float &value); + NS_IMETHOD GetBottomMargin(float &value); + NS_IMETHOD GetLeftMargin(float &value); + NS_IMETHOD GetRightMargin(float &value); + NS_IMETHOD GetCommand(const char **aCommand); + NS_IMETHOD GetPath (const char **aPath); + NS_IMETHOD GetLandscape (PRBool &aLandscape); + NS_IMETHOD GetUserCancelled(PRBool &aCancel); + NS_IMETHOD GetPrintMethod(PrintMethod &aMethod); + static nsresult GetPrintMethod(const char *aPrinter, PrintMethod &aMethod); + NS_IMETHOD GetPageSizeInTwips(PRInt32 *aWidth, PRInt32 *aHeight); + NS_IMETHOD GetPaperName(const char **aPaperName); + virtual ~nsDeviceContextSpecQt(); + +protected: + nsCOMPtr mPrintSettings; + PRBool mToPrinter; /* If PR_TRUE, print to printer */ + PRBool mFpf; /* If PR_TRUE, first page first */ + PRBool mGrayscale; /* If PR_TRUE, print grayscale */ + int mOrientation; /* Orientation e.g. Portrait */ + char mCommand[PATH_MAX]; /* Print command e.g., lpr */ + char mPath[PATH_MAX]; /* If toPrinter = PR_FALSE, dest file */ + char mPrinter[256]; /* Printer name */ + char mPaperName[256]; /* Printer name */ + int mCopies; /* number of copies */ + PRBool mCancel; /* If PR_TRUE, user cancelled */ + float mLeft; /* left margin */ + float mRight; /* right margin */ + float mTop; /* top margin */ + float mBottom; /* bottom margin */ +}; + +//------------------------------------------------------------------------- +// Printer Enumerator +//------------------------------------------------------------------------- +class nsPrinterEnumeratorQt : public nsIPrinterEnumerator +{ +public: + nsPrinterEnumeratorQt(); + NS_DECL_ISUPPORTS + NS_DECL_NSIPRINTERENUMERATOR +}; + +#endif /* !nsDeviceContextSpecQt_h___ */ diff --git a/mozilla/gfx/src/qt/nsDrawingSurfaceQt.cpp b/mozilla/gfx/src/qt/nsDrawingSurfaceQt.cpp new file mode 100644 index 00000000000..ec90a178286 --- /dev/null +++ b/mozilla/gfx/src/qt/nsDrawingSurfaceQt.cpp @@ -0,0 +1,258 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * John C. Griggs + * + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsDrawingSurfaceQt.h" +#include "nsRenderingContextQt.h" +#include + +#include "qtlog.h" + +#ifdef DEBUG +PRUint32 gDSCount = 0; +PRUint32 gDSID = 0; +#endif + +NS_IMPL_ISUPPORTS1(nsDrawingSurfaceQt, nsIDrawingSurface) + +nsDrawingSurfaceQt::nsDrawingSurfaceQt() +{ +#ifdef DEBUG + gDSCount++; + mID = gDSID++; + PR_LOG(gQtLogModule, QT_BASIC, + ("nsDrawingSurfaceQt CTOR (%p) ID: %d, Count: %d\n", + this, mID, gDSCount)); +#endif + + mPaintDevice = nsnull; + mGC = nsnull; + mDepth = -1; + mWidth = 0; + mHeight = 0; + mFlags = 0; + mLockWidth = 0; + mLockHeight = 0; + mLockFlags = 0; + mLocked = PR_FALSE; + + // I have no idea how to compute these values. + // FIXME + mPixFormat.mRedMask = 0; + mPixFormat.mGreenMask = 0; + mPixFormat.mBlueMask = 0; + mPixFormat.mAlphaMask = 0; + + mPixFormat.mRedShift = 0; + mPixFormat.mGreenShift = 0; + mPixFormat.mBlueShift = 0; + mPixFormat.mAlphaShift = 0; +} + +nsDrawingSurfaceQt::~nsDrawingSurfaceQt() +{ +#ifdef DEBUG + gDSCount--; + PR_LOG(gQtLogModule, QT_BASIC, + ("nsDrawingSurfaceQt DTOR (%p) ID: %d, Count: %d\n", + this, mID, gDSCount)); +#endif + + if (mGC && mGC->isActive()) { + mGC->end(); + } + + delete mGC; + mGC = nsnull; + + if (mPaintDevice) { + if (mIsOffscreen && !mPaintDevice->paintingActive() && mPaintDevice != &mPixmap) + delete mPaintDevice; + mPaintDevice = nsnull; + } +} + +NS_IMETHODIMP nsDrawingSurfaceQt::Lock(PRInt32 aX,PRInt32 aY, + PRUint32 aWidth,PRUint32 aHeight, + void **aBits,PRInt32 *aStride, + PRInt32 *aWidthBytes,PRUint32 aFlags) +{ + if (mLocked) { + NS_ASSERTION(0, "nested lock attempt"); + return NS_ERROR_FAILURE; + } + if (mPixmap.isNull()) { + NS_ASSERTION(0, "NULL pixmap in lock attempt"); + return NS_ERROR_FAILURE; + } + mLocked = PR_TRUE; + mLockX = aX; + mLockY = aY; + mLockWidth = aWidth; + mLockHeight = aHeight; + mLockFlags = aFlags; + + if (mImage.isNull()) + mImage = mPixmap.convertToImage(); + + *aBits = mImage.bits(); + *aStride = mImage.bytesPerLine(); + *aWidthBytes = mImage.bytesPerLine(); + + return NS_OK; +} + +NS_IMETHODIMP nsDrawingSurfaceQt::Unlock(void) +{ + if (!mLocked) { + NS_ASSERTION(0,"attempting to unlock an DrawingSurface that isn't locked"); + return NS_ERROR_FAILURE; + } + if (mPixmap.isNull()) { + NS_ASSERTION(0, "NULL pixmap in unlock attempt"); + return NS_ERROR_FAILURE; + } + if (!(mLockFlags & NS_LOCK_SURFACE_READ_ONLY)) { + qDebug("nsDrawingSurfaceQt::Unlock: w/h=%d/%d", mPixmap.width(), mPixmap.height()); + mGC->drawPixmap(0, 0, mPixmap, mLockY, mLockY, mLockWidth, mLockHeight); + } + mLocked = PR_FALSE; + + return NS_OK; +} + +NS_IMETHODIMP nsDrawingSurfaceQt::GetDimensions(PRUint32 *aWidth, + PRUint32 *aHeight) +{ + *aWidth = mWidth; + *aHeight = mHeight; + + return NS_OK; +} + +NS_IMETHODIMP nsDrawingSurfaceQt::IsOffscreen(PRBool *aOffScreen) +{ + *aOffScreen = mIsOffscreen; + return NS_OK; +} + +NS_IMETHODIMP nsDrawingSurfaceQt::IsPixelAddressable(PRBool *aAddressable) +{ + *aAddressable = PR_FALSE; + return NS_OK; +} + +NS_IMETHODIMP nsDrawingSurfaceQt::GetPixelFormat(nsPixelFormat *aFormat) +{ + *aFormat = mPixFormat; + + return NS_OK; +} + +NS_IMETHODIMP nsDrawingSurfaceQt::Init(QPaintDevice *aPaintDevice, + QPainter *aGC) +{ + PR_LOG(gQtLogModule, QT_BASIC, ("[%p] nsDrawingSurface::Init\n", this)); + NS_ASSERTION(aPaintDevice, "need paint dev."); + QPaintDeviceMetrics qMetrics(aPaintDevice); + mGC = aGC; + + mPaintDevice = aPaintDevice; + + mWidth = qMetrics.width(); + mHeight = qMetrics.height(); + mDepth = qMetrics.depth(); + + mIsOffscreen = PR_FALSE; + + mImage.reset(); + + return CommonInit(); +} + +NS_IMETHODIMP nsDrawingSurfaceQt::Init(QPainter *aGC, + PRUint32 aWidth, + PRUint32 aHeight, + PRUint32 aFlags) +{ + PR_LOG(gQtLogModule, QT_BASIC, ("[%p] nsDrawingSurface::Init\n", this)); + if (nsnull == aGC || aWidth <= 0 || aHeight <= 0) { + return NS_ERROR_FAILURE; + } + mGC = aGC; + mWidth = aWidth; + mHeight = aHeight; + mFlags = aFlags; + + mPixmap = QPixmap(mWidth, mHeight, mDepth); + mPaintDevice = &mPixmap; + NS_ASSERTION(mPaintDevice, "this better not fail"); + + mIsOffscreen = PR_TRUE; + + mImage.reset(); + + return CommonInit(); +} + +NS_IMETHODIMP nsDrawingSurfaceQt::CommonInit() +{ + PR_LOG(gQtLogModule, QT_BASIC, ("[%p] nsDrawingSurface::CommonInit\n", this)); + if (nsnull == mGC || nsnull == mPaintDevice) { + return NS_ERROR_FAILURE; + } + if (mGC->isActive()) { + mGC->end(); + } + mGC->begin(mPaintDevice); + return NS_OK; +} + +QPainter* nsDrawingSurfaceQt::GetGC() +{ + return mGC; +} + +QPaintDevice* nsDrawingSurfaceQt::GetPaintDevice() +{ + PR_LOG(gQtLogModule, QT_BASIC, ("[%p] nsDrawingSurfaceQt::GetPaintDevice\n", this)); + NS_ASSERTION(mPaintDevice, "No paint device! Something will probably crash soon."); + return mPaintDevice; +} diff --git a/mozilla/gfx/src/qt/nsDrawingSurfaceQt.h b/mozilla/gfx/src/qt/nsDrawingSurfaceQt.h new file mode 100644 index 00000000000..b44dc8216f8 --- /dev/null +++ b/mozilla/gfx/src/qt/nsDrawingSurfaceQt.h @@ -0,0 +1,129 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * John C. Griggs + * + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsDrawingSurfaceQt_h___ +#define nsDrawingSurfaceQt_h___ + +#include "nsIDrawingSurface.h" + +#include +#include + +class QPixmap; + +class nsDrawingSurfaceQt : public nsIDrawingSurface +{ +public: + nsDrawingSurfaceQt(); + virtual ~nsDrawingSurfaceQt(); + + NS_DECL_ISUPPORTS + + //nsIDrawingSurface interface + NS_IMETHOD Lock(PRInt32 aX,PRInt32 aY, + PRUint32 aWidth,PRUint32 aHeight, + void **aBits,PRInt32 *aStride, + PRInt32 *aWidthBytes,PRUint32 aFlags); + NS_IMETHOD Unlock(void); + NS_IMETHOD GetDimensions(PRUint32 *aWidth, PRUint32 *aHeight); + NS_IMETHOD IsOffscreen(PRBool *aOffScreen); + NS_IMETHOD IsPixelAddressable(PRBool *aAddressable); + NS_IMETHOD GetPixelFormat(nsPixelFormat *aFormat); + + /** + * Initialize a drawing surface using a QPainter and QPaintDevice. + * these are "owned" by the drawing surface until the drawing + * surface is destroyed. + * @param aGC QPainter to initialize drawing surface with + * @param aPaintDevice QPixmap to initialize drawing surface with + * @return error status + */ + NS_IMETHOD Init(QPaintDevice * aPaintDevice, QPainter *aGC); + + /** + * Initialize an offscreen drawing surface using a + * QPainter. aGC is not "owned" by this drawing surface, instead + * it is used to create a drawing surface compatible + * with aGC. if width or height are less than zero, aGC will + * be created with no offscreen bitmap installed. + * @param aGC QPainter to initialize drawing surface with + * @param aWidth width of drawing surface + * @param aHeight height of drawing surface + * @param aFlags flags used to control type of drawing + * surface created + * @return error status + */ + NS_IMETHOD Init(QPainter *aGC,PRUint32 aWidth,PRUint32 aHeight, + PRUint32 aFlags); + + // utility functions. + PRInt32 GetDepth() { return mDepth; } + QPainter *GetGC(void); + QPaintDevice *GetPaintDevice(void); + +protected: + NS_IMETHOD CommonInit(); + +private: + /* general */ + QPaintDevice *mPaintDevice; + QPixmap mPixmap; + QPainter *mGC; + int mDepth; + nsPixelFormat mPixFormat; + PRUint32 mWidth; + PRUint32 mHeight; + PRUint32 mFlags; + PRBool mIsOffscreen; + + /* for locks */ + QImage mImage; + PRInt32 mLockX; + PRInt32 mLockY; + PRUint32 mLockWidth; + PRUint32 mLockHeight; + PRUint32 mLockFlags; + PRBool mLocked; + + PRUint32 mID; +}; + +#endif diff --git a/mozilla/gfx/src/qt/nsFontMetricsQt.cpp b/mozilla/gfx/src/qt/nsFontMetricsQt.cpp new file mode 100644 index 00000000000..b59d5ee352a --- /dev/null +++ b/mozilla/gfx/src/qt/nsFontMetricsQt.cpp @@ -0,0 +1,381 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * John C. Griggs + * Jean Claude Batista + * + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsQuickSort.h" +#include "nsFontMetricsQt.h" +#include "nsFont.h" +#include "nsString.h" +#include "nsXPIDLString.h" +#include "nsReadableUtils.h" +#include "nsIServiceManager.h" +#include "nsISaveAsCharset.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" +#include "nsCOMPtr.h" +#include "nspr.h" +#include "nsHashtable.h" +#include "nsDrawingSurfaceQt.h" +#include "nsRenderingContextQt.h" +#include "nsILanguageAtomService.h" +#include "nsDrawingSurfaceQt.h" +#include "nsRenderingContextQt.h" + +#include +#include +#include + +#include "qtlog.h" + +nsFontQt::nsFontQt(const nsFont &aFont, nsIAtom *aLangGroup, nsIDeviceContext *aContext) +{ + mFont = aFont; + mLangGroup = aLangGroup; + mDeviceContext = aContext; + + float a2d = aContext->AppUnitsToDevUnits(); + mPixelSize = NSToIntRound(a2d * mFont.size); + + if (mLangGroup) { + nsCAutoString name("font.min-size.variable."); + const char* langGroup = nsnull; + mLangGroup->GetUTF8String(&langGroup); + + PRInt32 minimum = 0; + nsresult res; + nsCOMPtr prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &res); + if (NS_SUCCEEDED(res)) { + nsCOMPtr branch; + prefs->GetBranch(name.get(), getter_AddRefs(branch)); + branch->GetIntPref(langGroup, &minimum); + } + if (minimum < 0) { + minimum = 0; + } + if (mPixelSize < minimum) { + mPixelSize = minimum; + } + } + + font.setFamily(QString::fromUcs2(mFont.name.get())); + font.setPixelSize(mPixelSize); + font.setWeight(mFont.weight/10); + font.setItalic(mFont.style != NS_FONT_STYLE_NORMAL); + + RealizeFont(); +} + +void nsFontQt::RealizeFont() +{ + QFontMetrics fm(font); + + float f = mDeviceContext->DevUnitsToAppUnits(); + + mMaxAscent = nscoord(fm.ascent() * f) ; + mMaxDescent = nscoord(fm.descent() * f); + mMaxHeight = mMaxAscent + mMaxDescent; + + mEmHeight = nscoord(fm.height() * f); + mMaxAdvance = nscoord(fm.maxWidth() * f); + + mAveCharWidth = nscoord(fm.width(QChar('x')) * f); + + mEmAscent = mMaxAscent; + mEmDescent = mMaxDescent; + + mXHeight = NSToCoordRound(fm.boundingRect('x').height() * f); + + mUnderlineOffset = - nscoord(fm.underlinePos() * f); + + mUnderlineSize = NSToIntRound(fm.lineWidth() * f); + + mSuperscriptOffset = mXHeight; + mSubscriptOffset = mXHeight; + + mStrikeoutOffset = nscoord(fm.strikeOutPos() * f); + mStrikeoutSize = mUnderlineSize; + + mLeading = nscoord(fm.leading() * f); + mSpaceWidth = nscoord(fm.width(QChar(' ')) * f); +} + +nsFontMetricsQt::nsFontMetricsQt() +{ + qFont = 0; +} + +nsFontMetricsQt::~nsFontMetricsQt() +{ + NS_ASSERTION(qFont == 0, "deleting non destroyed nsFontMetricsQt"); +} + +NS_IMPL_ISUPPORTS1(nsFontMetricsQt,nsIFontMetrics) + + NS_IMETHODIMP nsFontMetricsQt::Init(const nsFont &aFont, nsIAtom *aLangGroup, + nsIDeviceContext *aContext) +{ + NS_ASSERTION(!(nsnull == aContext), "attempt to init fontmetrics with null device context"); + + qFont = new nsFontQt(aFont, aLangGroup, aContext); + return NS_OK; +} + +NS_IMETHODIMP nsFontMetricsQt::Destroy() +{ + delete qFont; + qFont = 0; + return NS_OK; +} + +NS_IMETHODIMP nsFontMetricsQt::GetXHeight(nscoord &aResult) +{ + aResult = qFont->mXHeight; + return NS_OK; +} + +NS_IMETHODIMP nsFontMetricsQt::GetSuperscriptOffset(nscoord &aResult) +{ + aResult = qFont->mSuperscriptOffset; + return NS_OK; +} + +NS_IMETHODIMP nsFontMetricsQt::GetSubscriptOffset(nscoord &aResult) +{ + aResult = qFont->mSubscriptOffset; + return NS_OK; +} + +NS_IMETHODIMP nsFontMetricsQt::GetStrikeout(nscoord &aOffset,nscoord &aSize) +{ + aOffset = qFont->mStrikeoutOffset; + aSize = qFont->mStrikeoutSize; + return NS_OK; +} + +NS_IMETHODIMP nsFontMetricsQt::GetUnderline(nscoord &aOffset,nscoord &aSize) +{ + aOffset = qFont->mUnderlineOffset; + aSize = qFont->mUnderlineSize; + return NS_OK; +} + +NS_IMETHODIMP nsFontMetricsQt::GetHeight(nscoord &aHeight) +{ + aHeight = qFont->mMaxHeight; + return NS_OK; +} + +NS_IMETHODIMP nsFontMetricsQt::GetNormalLineHeight(nscoord &aHeight) +{ + aHeight = qFont->mEmHeight + qFont->mLeading; + return NS_OK; +} + +NS_IMETHODIMP nsFontMetricsQt::GetLeading(nscoord &aLeading) +{ + aLeading = qFont->mLeading; + return NS_OK; +} + +NS_IMETHODIMP nsFontMetricsQt::GetEmHeight(nscoord &aHeight) +{ + aHeight = qFont->mEmHeight; + return NS_OK; +} + +NS_IMETHODIMP nsFontMetricsQt::GetEmAscent(nscoord &aAscent) +{ + aAscent = qFont->mEmAscent; + return NS_OK; +} + +NS_IMETHODIMP nsFontMetricsQt::GetEmDescent(nscoord &aDescent) +{ + aDescent = qFont->mEmDescent; + return NS_OK; +} + +NS_IMETHODIMP nsFontMetricsQt::GetMaxHeight(nscoord &aHeight) +{ + aHeight = qFont->mMaxHeight; + return NS_OK; +} + +NS_IMETHODIMP nsFontMetricsQt::GetMaxAscent(nscoord &aAscent) +{ + aAscent = qFont->mMaxAscent; + return NS_OK; +} + +NS_IMETHODIMP nsFontMetricsQt::GetMaxDescent(nscoord &aDescent) +{ + aDescent = qFont->mMaxDescent; + return NS_OK; +} + +NS_IMETHODIMP nsFontMetricsQt::GetMaxAdvance(nscoord &aAdvance) +{ + aAdvance = qFont->mMaxAdvance; + return NS_OK; +} + +NS_IMETHODIMP nsFontMetricsQt::GetAveCharWidth(nscoord &aAveCharWidth) +{ + aAveCharWidth = qFont->mAveCharWidth; + return NS_OK; +} + +NS_IMETHODIMP nsFontMetricsQt::GetSpaceWidth(nscoord &aSpaceWidth) +{ + aSpaceWidth = qFont->mSpaceWidth; + return NS_OK; +} + +NS_IMETHODIMP nsFontMetricsQt::GetFont(const nsFont *&aFont) +{ + aFont = &qFont->mFont; + return NS_OK; +} + +NS_IMETHODIMP nsFontMetricsQt::GetLangGroup(nsIAtom **aLangGroup) +{ + if (!aLangGroup) { + return NS_ERROR_NULL_POINTER; + } + *aLangGroup = qFont->mLangGroup; + NS_IF_ADDREF(*aLangGroup); + return NS_OK; +} + + +NS_IMETHODIMP nsFontMetricsQt::GetFontHandle(nsFontHandle &aHandle) +{ + aHandle = (nsFontHandle)qFont; + return NS_OK; +} + +static nsresult EnumFonts(nsIAtom *aLangGroup,const char *aGeneric, + PRUint32 *aCount,PRUnichar ***aResult) +{ + /* Get list of all fonts */ + QStringList qFamilies = QFontDatabase().families(); + int count = qFamilies.count(); + + PRUnichar **array = (PRUnichar**)nsMemory::Alloc(count * sizeof(PRUnichar*)); + + int i = 0; + for (QStringList::ConstIterator famIt = qFamilies.begin(); famIt != qFamilies.end(); ++famIt) { + QString family = *famIt; + array[i] = new PRUnichar[family.length()]; + memcpy(array[i], family.unicode(), family.length()*sizeof(PRUnichar)); + } + + *aCount = count; + *aResult = array; + return NS_OK; +} + +nsFontEnumeratorQt::nsFontEnumeratorQt() +{ +} + +NS_IMPL_ISUPPORTS1(nsFontEnumeratorQt, nsIFontEnumerator) + +NS_IMETHODIMP +nsFontEnumeratorQt::EnumerateAllFonts(PRUint32 *aCount,PRUnichar ***aResult) +{ + NS_ENSURE_ARG_POINTER(aResult); + *aResult = nsnull; + NS_ENSURE_ARG_POINTER(aCount); + *aCount = 0; + + return EnumFonts(nsnull,nsnull,aCount,aResult); +} + +NS_IMETHODIMP +nsFontEnumeratorQt::EnumerateFonts(const char *aLangGroup,const char *aGeneric, + PRUint32 *aCount,PRUnichar ***aResult) +{ + nsresult res; + + NS_ENSURE_ARG_POINTER(aResult); + *aResult = nsnull; + NS_ENSURE_ARG_POINTER(aCount); + *aCount = 0; + NS_ENSURE_ARG_POINTER(aGeneric); + NS_ENSURE_ARG_POINTER(aLangGroup); + + nsIAtom *langGroup = NS_NewAtom(aLangGroup); + res = EnumFonts(langGroup,aGeneric,aCount,aResult); + NS_IF_RELEASE(langGroup); + return(res); +} + +NS_IMETHODIMP +nsFontEnumeratorQt::HaveFontFor(const char *aLangGroup,PRBool *aResult) +{ + NS_ENSURE_ARG_POINTER(aResult); + NS_ENSURE_ARG_POINTER(aLangGroup); + + *aResult = PR_TRUE; // always return true for now. + // Finish me + return NS_OK; +} + +NS_IMETHODIMP +nsFontEnumeratorQt::GetDefaultFont(const char *aLangGroup, + const char *aGeneric, + PRUnichar **aResult) +{ + // aLangGroup=null or "" means any (i.e., don't care) + // aGeneric=null or "" means any (i.e, don't care) + + NS_ENSURE_ARG_POINTER(aResult); + *aResult = nsnull; + + return NS_OK; +} + +NS_IMETHODIMP +nsFontEnumeratorQt::UpdateFontList(PRBool *updateFontList) +{ + *updateFontList = PR_FALSE; // always return false for now + return NS_OK; +} diff --git a/mozilla/gfx/src/qt/nsFontMetricsQt.h b/mozilla/gfx/src/qt/nsFontMetricsQt.h new file mode 100644 index 00000000000..bae60faa65d --- /dev/null +++ b/mozilla/gfx/src/qt/nsFontMetricsQt.h @@ -0,0 +1,222 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * John C. Griggs + * Jean Claude Batista + * + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsFontMetricsQt_h__ +#define nsFontMetricsQt_h__ + +#include "nsIFontMetrics.h" +#include "nsIFontEnumerator.h" +#include "nsIDeviceContext.h" +#include "nsCRT.h" +#include "nsCOMPtr.h" +#include "nsICharRepresentable.h" +#include "nsICharsetConverterManager.h" +#include "nsVoidArray.h" +#include "nsFont.h" + +#include +#include + +class nsFont; +class nsString; +class nsRenderingContextQt; +class nsDrawingSurfaceQt; +class nsFontMetricsQt; +class nsFontQtUserDefined; +class QString; +class QFontInfo; +class QFontDatabase; + +#undef FONT_HAS_GLYPH +#define FONT_HAS_GLYPH(map,char) IS_REPRESENTABLE(map,char) + +typedef struct nsFontCharSetInfo nsFontCharSetInfo; + +class nsFontQt +{ +public: + nsFontQt(const nsFont &afont, nsIAtom *aLangGroup, nsIDeviceContext *acontext); + ~nsFontQt() {} + NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW + + bool SupportsChar(PRUnichar c) { return QFontMetrics(font).inFont(QChar(c)); } + + QFont font; + + nsIDeviceContext *mDeviceContext; + nsCOMPtr mLangGroup; + nsFont mFont; + + nscoord mLeading; + nscoord mEmHeight; + nscoord mEmAscent; + nscoord mEmDescent; + nscoord mMaxHeight; + nscoord mMaxAscent; + nscoord mMaxDescent; + nscoord mMaxAdvance; + nscoord mAveCharWidth; + nscoord mXHeight; + nscoord mSuperscriptOffset; + nscoord mSubscriptOffset; + nscoord mStrikeoutSize; + nscoord mStrikeoutOffset; + nscoord mUnderlineSize; + nscoord mUnderlineOffset; + nscoord mSpaceWidth; + + PRUint16 mPixelSize; + PRUint16 mWeight; + + void RealizeFont(); + +#ifdef DEBUG +private: + PRUint32 mID; +#endif +}; + +class nsFontMetricsQt : public nsIFontMetrics +{ +public: + nsFontMetricsQt(); + virtual ~nsFontMetricsQt(); + + NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW + + NS_DECL_ISUPPORTS + + NS_IMETHOD Init(const nsFont& aFont, nsIAtom* aLangGroup, + nsIDeviceContext* aContext); + NS_IMETHOD Destroy(); + + NS_IMETHOD GetXHeight(nscoord& aResult); + NS_IMETHOD GetSuperscriptOffset(nscoord& aResult); + NS_IMETHOD GetSubscriptOffset(nscoord& aResult); + NS_IMETHOD GetStrikeout(nscoord& aOffset, nscoord& aSize); + NS_IMETHOD GetUnderline(nscoord& aOffset, nscoord& aSize); + + NS_IMETHOD GetHeight(nscoord &aHeight); + NS_IMETHOD GetNormalLineHeight(nscoord &aHeight); + NS_IMETHOD GetLeading(nscoord &aLeading); + NS_IMETHOD GetEmHeight(nscoord &aHeight); + NS_IMETHOD GetEmAscent(nscoord &aAscent); + NS_IMETHOD GetEmDescent(nscoord &aDescent); + NS_IMETHOD GetMaxHeight(nscoord &aHeight); + NS_IMETHOD GetMaxAscent(nscoord &aAscent); + NS_IMETHOD GetMaxDescent(nscoord &aDescent); + NS_IMETHOD GetMaxAdvance(nscoord &aAdvance); + NS_IMETHOD GetAveCharWidth(nscoord &aAveCharWidth); + NS_IMETHOD GetFont(const nsFont *&aFont); + NS_IMETHOD GetLangGroup(nsIAtom** aLangGroup); + NS_IMETHOD GetFontHandle(nsFontHandle &aHandle); + + NS_IMETHOD GetSpaceWidth(nscoord &aSpaceWidth); + + nsFontQt *qFont; + +#if 0 + nsFontQt* FindFont(PRUnichar aChar); + nsFontQt* FindUserDefinedFont(PRUnichar aChar); + nsFontQt* FindLangGroupPrefFont(nsIAtom *aLangGroup,PRUnichar aChar); + nsFontQt* FindLocalFont(PRUnichar aChar); + nsFontQt* FindGenericFont(PRUnichar aChar); + nsFontQt* FindGlobalFont(PRUnichar aChar); + nsFontQt* FindSubstituteFont(PRUnichar aChar); + + nsFontQt* LookUpFontPref(nsCAutoString &aName,PRUnichar aChar); + nsFontQt* LoadFont(QString &aName,PRUnichar aChar); + nsFontQt* LoadFont(QString &aName,const QString &aCharSet, + PRUnichar aChar); + QFont* LoadQFont(QString &aName); + + static nsresult FamilyExists(const nsString& aFontName); + + PRUint16 mLoadedFontsAlloc; + PRUint16 mLoadedFontsCount; + + nsFontQt *mSubstituteFont; + nsFontQtUserDefined *mUserDefinedFont; + + nsCOMPtr mLangGroup; + nsCStringArray mFonts; + PRUint16 mFontsIndex; + nsVoidArray mFontIsGeneric; + nsCAutoString mDefaultFont; + nsCString *mGeneric; + nsCAutoString mUserDefined; + + PRUint8 mTriedAllGenerics; + PRUint8 mIsUserDefined; + + static QFontDatabase *GetQFontDB(); + +protected: + void RealizeFont(); + + nsIDeviceContext *mDeviceContext; + nsFont *mFont; + nsFontQt *mWesternFont; + + QString *mQStyle; + + QIntDict mCharSubst; + + + static QFontDatabase *mQFontDB; +#endif + +#ifdef DEBUG +private: + PRUint32 mID; +#endif +}; + +class nsFontEnumeratorQt : public nsIFontEnumerator +{ +public: + nsFontEnumeratorQt(); + NS_DECL_ISUPPORTS + NS_DECL_NSIFONTENUMERATOR +}; + +#endif diff --git a/mozilla/gfx/src/qt/nsGfxFactoryQt.cpp b/mozilla/gfx/src/qt/nsGfxFactoryQt.cpp new file mode 100644 index 00000000000..ba330ff0db1 --- /dev/null +++ b/mozilla/gfx/src/qt/nsGfxFactoryQt.cpp @@ -0,0 +1,182 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Christopher Blizzard. + * Portions created by the Initial Developer are Copyright (C) 2000 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * John C. Griggs + * + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsIGenericFactory.h" +#include "nsIModule.h" +#include "nsCOMPtr.h" +#include "nsGfxCIID.h" + +#include "nsBlender.h" +#include "nsFontMetricsQt.h" +#include "nsRenderingContextQt.h" +#include "nsDeviceContextSpecQt.h" +#include "nsDeviceContextSpecFactoryQt.h" +#include "nsScreenManagerQt.h" +#include "nsScriptableRegion.h" +#include "nsDeviceContextQt.h" +#include "nsImageQt.h" +#include "nsFontList.h" +#include "nsPrintSession.h" +#include "nsNativeThemeQt.h" +#include "gfxImageFrame.h" + +#include "qtlog.h" + +// Initialize qt logging +PRLogModuleInfo *gQtLogModule = PR_NewLogModule("QtGfx"); + +// objects that just require generic constructors + +NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontMetricsQt) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextQt) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsRenderingContextQt) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsImageQt) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsBlender) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsRegionQt) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextSpecQt) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsDeviceContextSpecFactoryQt) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontEnumeratorQt) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsFontList) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsScreenManagerQt) +NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintSession, Init) +NS_GENERIC_FACTORY_CONSTRUCTOR(gfxImageFrame) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsNativeThemeQt) + +// our custom constructors +static nsresult nsScriptableRegionConstructor(nsISupports *aOuter,REFNSIID aIID,void **aResult) +{ + nsresult rv; + + nsIScriptableRegion *inst = 0; + + if (NULL == aResult) { + rv = NS_ERROR_NULL_POINTER; + return rv; + } + *aResult = NULL; + if (NULL != aOuter) { + rv = NS_ERROR_NO_AGGREGATION; + return rv; + } + // create an nsRegionQt and get the scriptable region from it + nsCOMPtr rgn; + NS_NEWXPCOM(rgn, nsRegionQt); + if (rgn != nsnull) { + nsCOMPtr scriptableRgn = new nsScriptableRegion(rgn); + inst = scriptableRgn; + } + if (NULL == inst) { + rv = NS_ERROR_OUT_OF_MEMORY; + return rv; + } + NS_ADDREF(inst); + rv = inst->QueryInterface(aIID, aResult); + NS_RELEASE(inst); + + return rv; +} + +static const nsModuleComponentInfo components[] = +{ + { "Qt Font Metrics", + NS_FONT_METRICS_CID, + "@mozilla.org/gfx/fontmetrics;1", + nsFontMetricsQtConstructor }, + { "Qt Device Context", + NS_DEVICE_CONTEXT_CID, + "@mozilla.org/gfx/devicecontext;1", + nsDeviceContextQtConstructor }, + { "Qt Rendering Context", + NS_RENDERING_CONTEXT_CID, + "@mozilla.org/gfx/renderingcontext;1", + nsRenderingContextQtConstructor }, + { "Qt Image", + NS_IMAGE_CID, + "@mozilla.org/gfx/image;1", + nsImageQtConstructor }, + { "Qt Region", + NS_REGION_CID, + "@mozilla.org/gfx/region/qt;1", + nsRegionQtConstructor }, + { "Scriptable Region", + NS_SCRIPTABLE_REGION_CID, + "@mozilla.org/gfx/region;1", + nsScriptableRegionConstructor }, + { "Blender", + NS_BLENDER_CID, + "@mozilla.org/gfx/blender;1", + nsBlenderConstructor }, + { "Qt Device Context Spec", + NS_DEVICE_CONTEXT_SPEC_CID, + "@mozilla.org/gfx/devicecontextspec;1", + nsDeviceContextSpecQtConstructor }, + { "Qt Device Context Spec Factory", + NS_DEVICE_CONTEXT_SPEC_FACTORY_CID, + "@mozilla.org/gfx/devicecontextspecfactory;1", + nsDeviceContextSpecFactoryQtConstructor }, + { "Qt Font Enumerator", + NS_FONT_ENUMERATOR_CID, + "@mozilla.org/gfx/fontenumerator;1", + nsFontEnumeratorQtConstructor }, + { "Font List", + NS_FONTLIST_CID, + // "@mozilla.org/gfx/fontlist;1" + NS_FONTLIST_CONTRACTID, + nsFontListConstructor }, + { "Qt Screen Manager", + NS_SCREENMANAGER_CID, + "@mozilla.org/gfx/screenmanager;1", + nsScreenManagerQtConstructor }, + { "shared image frame", + GFX_IMAGEFRAME_CID, + "@mozilla.org/gfx/image/frame;2", + gfxImageFrameConstructor, }, + { "Native Theme Renderer", + NS_THEMERENDERER_CID, + "@mozilla.org/chrome/chrome-native-theme;1", + nsNativeThemeQtConstructor }, + { "Print Session", + NS_PRINTSESSION_CID, + "@mozilla.org/gfx/printsession;1", + nsPrintSessionConstructor } +}; + +NS_IMPL_NSGETMODULE(nsGfxQtModule, components) + diff --git a/mozilla/gfx/src/qt/nsImageQt.cpp b/mozilla/gfx/src/qt/nsImageQt.cpp new file mode 100644 index 00000000000..650c245d011 --- /dev/null +++ b/mozilla/gfx/src/qt/nsImageQt.cpp @@ -0,0 +1,524 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * John C. Griggs + * + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsImageQt.h" +#include "nsRenderingContextQt.h" + +#include "nspr.h" +#include "qtlog.h" + +#define IsFlagSet(a,b) ((a) & (b)) + +#ifdef DEBUG +PRUint32 gImageCount = 0; +PRUint32 gImageID = 0; +#endif + +NS_IMPL_ISUPPORTS1(nsImageQt, nsIImage) + +//------------------------------------------------------------ +nsImageQt::nsImageQt() + : mWidth(0) + , mHeight(0) + , mDepth(0) + , mRowBytes(0) + , mImageBits(nsnull) + , mAlphaDepth(0) + , mAlphaRowBytes(0) + , mAlphaBits(nsnull) + , mNumBytesPixel(0) + , pixmapDirty(PR_FALSE) +{ +#ifdef DEBUG + gImageCount++; + mID = gImageID++; + PR_LOG(gQtLogModule, QT_BASIC, + ("nsImageQt CTOR (%p) ID: %d, Count: %d\n", this, mID, gImageCount)); +#endif +} + +//------------------------------------------------------------ +nsImageQt::~nsImageQt() +{ +#ifdef DEBUG + gImageCount--; + PR_LOG(gQtLogModule, QT_BASIC, + ("nsImageQt DTOR (%p) ID: %d, Count: %d\n", this, mID, gImageCount)); +#endif + if (nsnull != mImageBits) { + delete[] mImageBits; + mImageBits = nsnull; + } + if (nsnull != mAlphaBits) { + delete[] mAlphaBits; + mAlphaBits = nsnull; + } +} + +//------------------------------------------------------------ +nsresult nsImageQt::Init(PRInt32 aWidth,PRInt32 aHeight, + PRInt32 aDepth, + nsMaskRequirements aMaskRequirements) +{ + // gfxImageFrame forces only one nsImageQt::Init + if (aWidth == 0 || aHeight == 0) { + return NS_ERROR_FAILURE; + } + +// if (32 == aDepth) { +// mNumBytesPixel = 4; +// mDepth = aDepth; +// } +// else + if (24 == aDepth) { + mNumBytesPixel = 3; + mDepth = aDepth; + } + else { + NS_NOTREACHED("unexpected image depth"); + return NS_ERROR_UNEXPECTED; + } + mWidth = aWidth; + mHeight = aHeight; + mRowBytes = (mWidth*mDepth/8 + 3) & ~0x3; + + switch (aMaskRequirements) { + case nsMaskRequirements_kNeeds1Bit: + mAlphaRowBytes = (aWidth + 7) / 8; + mAlphaDepth = 1; + // 32-bit align each row + mAlphaRowBytes = (mAlphaRowBytes + 3) & ~0x3; + break; + + case nsMaskRequirements_kNeeds8Bit: + mAlphaRowBytes = aWidth; + mAlphaDepth = 8; + // 32-bit align each row + mAlphaRowBytes = (mAlphaRowBytes + 3) & ~0x3; + break; + default: + mAlphaDepth = 0; + mAlphaRowBytes = 0; + break; + } + + mImageBits = (PRUint8*)new PRUint8[mRowBytes * mHeight]; + mAlphaBits = new PRUint8[mAlphaRowBytes * mHeight]; + + pixmapDirty = PR_TRUE; + + PR_LOG(gQtLogModule, QT_BASIC, ("nsImageQt::Init succeeded")); + return NS_OK; +} + +//------------------------------------------------------------ + +PRInt32 nsImageQt::GetHeight() +{ + return mHeight; +} + +PRInt32 nsImageQt::GetWidth() +{ + return mWidth; +} + +PRUint8 *nsImageQt::GetBits() +{ + return mImageBits; +} + +void *nsImageQt::GetBitInfo() +{ + return nsnull; +} + +PRInt32 nsImageQt::GetLineStride() +{ + return mRowBytes; +} + +nsColorMap *nsImageQt::GetColorMap() +{ + return nsnull; +} + +PRUint8 *nsImageQt::GetAlphaBits() +{ + return mAlphaBits; +} + +PRInt32 nsImageQt::GetAlphaLineStride() +{ + return mAlphaRowBytes; +} + +//------------------------------------------------------------ + +// set up the palette to the passed in color array, RGB only in this array +void nsImageQt::ImageUpdated(nsIDeviceContext *aContext, + PRUint8 aFlags,nsRect *aUpdateRect) +{ + //qDebug("image updated"); + if (IsFlagSet(nsImageUpdateFlags_kBitsChanged,aFlags)) + pixmapDirty = PR_TRUE; + + mDecodedRect.UnionRect(mDecodedRect, *aUpdateRect); +} + +// Draw the bitmap, this method has a source and destination coordinates +NS_IMETHODIMP nsImageQt::Draw(nsIRenderingContext &aContext, + nsIDrawingSurface *aSurface, + PRInt32 aSX, PRInt32 aSY, + PRInt32 aSWidth, PRInt32 aSHeight, + PRInt32 aDX, PRInt32 aDY, + PRInt32 aDWidth, PRInt32 aDHeight) +{ + // qDebug("draw x = %d, y = %d, w = %d, h = %d, dx = %d, dy = %d, dw = %d, dy = %d", + // aSX, aSY, aSWidth, aSHeight, aDX, aDY, aDWidth, aDHeight); + if (aSWidth <= 0 || aDWidth <= 0 || aSHeight <= 0 || aDHeight <= 0) + return NS_OK; + if (nsnull == aSurface) { + return NS_ERROR_FAILURE; + } + if (pixmapDirty) + updatePixmap(); + + nsDrawingSurfaceQt *drawing = (nsDrawingSurfaceQt*)aSurface; + + // The code below seems to be wrong and not what gecko expects. +// if ((aSWidth != aDWidth || aSHeight != aDHeight) +// && (aSWidth != mWidth || aSHeight != mHeight)) { +// QPixmap tmp(aSWidth, aSHeight); +// copyBlt(&tmp, 0, 0, &pixmap, aSX, aSY, aSWidth, aSHeight); +// drawing->GetGC()->drawPixmap(aDX, aDY, pixmap, aSX, aSY, aSWidth, aSHeight); +// } + + nsRect sourceRect(aSX, aSY, aSWidth, aSHeight); + if (!sourceRect.IntersectRect(sourceRect, mDecodedRect)) + return NS_OK; + + // Now get the part of the image that should be drawn + // Copy into a new image so we can scale afterwards + QImage image(pixmap.convertToImage().copy(sourceRect.x, sourceRect.y, + sourceRect.width, sourceRect.height)); + + if (image.isNull()) + return NS_ERROR_FAILURE; + + // Find the scale factor + float w_factor = (float)aDWidth / aSWidth; + float h_factor = (float)aDHeight / aSHeight; + + // If we had to draw only part of the requested image, must adjust + // destination coordinates + aDX += PRInt32((sourceRect.x - aSX) * w_factor); + aDY += PRInt32((sourceRect.y - aSY) * h_factor); + image = image.scale(int(sourceRect.width * w_factor), int(sourceRect.height * h_factor)); + drawing->GetGC()->drawImage(QPoint(aDX, aDY), image); + + //drawing->GetGC()->drawPixmap(aDX, aDY, pixmap, aSX, aSY, aSWidth, aSHeight); + + + return NS_OK; +} + +//------------------------------------------------------------ + +// Draw the bitmap, this draw just has destination coordinates +NS_IMETHODIMP nsImageQt::Draw(nsIRenderingContext &aContext, + nsIDrawingSurface *aSurface, + PRInt32 aX, PRInt32 aY, + PRInt32 aWidth, PRInt32 aHeight) +{ + return Draw(aContext, aSurface, 0, 0, mWidth, mHeight, aX, aY, aWidth, aHeight); +} + +void nsImageQt::updatePixmap() +{ + //qDebug("updatePixmap"); + QImage qimage(mWidth, mHeight, 32); + const PRInt32 bytesPerPixel = mDepth / 8; + PRUint8 *image = mImageBits; + PRUint8 *alpha = mAlphaBits; + + PRInt32 i,j; + QRgb *line; + + qimage.setAlphaBuffer(mAlphaDepth != 0); + switch(mAlphaDepth) { + case 0: + for (i = 0; i < mHeight; i++) { + line = (QRgb*)qimage.scanLine(i); + + PRUint8 *imagePtr = image; + for (j = 0; j < mWidth; j++) { + line[j] = qRgb(*imagePtr, *(imagePtr+1), *(imagePtr+2)); + imagePtr += bytesPerPixel; + } + image += mRowBytes; + } + break; + case 1: + for (i = 0; i < mHeight; i++) { + line = (QRgb*)qimage.scanLine(i); + + PRUint8 *imagePtr = image; + for (j = 0; j < mWidth; j++) { + uchar a = (alpha[j / 8] & (1 << (7 - (j % 8)))) ? 0xff : 0; + line[j] = qRgba(*imagePtr, *(imagePtr+1), *(imagePtr+2), a); + imagePtr += bytesPerPixel; + } + image += mRowBytes; + alpha += mAlphaRowBytes; + } + break; + case 8: + for (i = 0; i < mHeight; i++) { + line = (QRgb*)qimage.scanLine(i); + + PRUint8 *imagePtr = image; + PRUint8 *alphaPtr = alpha; + for (j = 0; j < mWidth; j++) { + line[j] = qRgba(*imagePtr, *(imagePtr+1), *(imagePtr+2), *alphaPtr); + imagePtr += bytesPerPixel; + alphaPtr++; + } + image += mRowBytes; + alpha += mAlphaRowBytes; + } + break; + } + + pixmap = QPixmap(qimage); + pixmapDirty = PR_FALSE; +} + +NS_IMETHODIMP nsImageQt::DrawTile(nsIRenderingContext &aContext, + nsIDrawingSurface *aSurface, + PRInt32 aSXOffset, PRInt32 aSYOffset, + PRInt32 aPadX, PRInt32 aPadY, + const nsRect &aTileRect) +{ + //qDebug("draw tile"); +#if 1 + nsRect aSrcRect(aSXOffset, aSYOffset, mWidth, mHeight); + + nsDrawingSurfaceQt *drawing = (nsDrawingSurfaceQt*)aSurface; + + if (aTileRect.width <= 0 || aTileRect.height <= 0) { + NS_ASSERTION(aTileRect.width > 0 && aTileRect.height > 0, + "Error: image has 0 width or height!"); + return NS_OK; + } + if (drawing->GetDepth() == 8 || mAlphaDepth == 8) { + PRInt32 aY0 = aTileRect.y, aX0 = aTileRect.x; + PRInt32 aY1 = aTileRect.y + aTileRect.height; + PRInt32 aX1 = aTileRect.x + aTileRect.width; + + for (PRInt32 y = aY0; y < aY1; y += aSrcRect.height + aPadY) + for (PRInt32 x = aX0; x < aX1; x += aSrcRect.width + aPadX) + Draw(aContext, aSurface, x, y, PR_MIN(aSrcRect.width, aX1 - x), + PR_MIN(aSrcRect.height, aY1 - y)); + + return NS_OK; + } +#if 0 + // Render unique image bits onto an off screen pixmap only once + // The image bits can change as a result of ImageUpdated() - for + // example: animated GIFs. + if (nsnull == mImagePixmap) { + CreateImagePixmap(); + } + if (nsnull == mImagePixmap) + return NS_ERROR_FAILURE; + + QPixmap qPmap; + + qPmap.convertFromImage(*mImagePixmap); +#endif + /*qDebug("draw tilePixmap x = %d, y = %d, wid = %d, hei = %d, sx = %d, sy = %d", + aTileRect.x, aTileRect.y, aTileRect.width, aTileRect.height, + aSrcRect.x, aSrcRect.y);*/ + drawing->GetGC()->drawTiledPixmap(aTileRect.x, aTileRect.y, + aTileRect.width, aTileRect.height, + pixmap, aSrcRect.x, aSrcRect.y); + //qPmap, aSrcRect.x, aSrcRect.y); +#endif + return NS_OK; +} + +//------------------------------------------------------------ + +nsresult nsImageQt::Optimize(nsIDeviceContext* aContext) +{ + return NS_OK; +} + +PRInt32 nsImageQt::GetBytesPix() +{ + return mNumBytesPixel; +} + +//------------------------------------------------------------ +// lock the image pixels. Implement this if you need it. +NS_IMETHODIMP +nsImageQt::LockImagePixels(PRBool aMaskPixels) +{ + return NS_OK; +} + +//------------------------------------------------------------ +// unlock the image pixels. Implement this if you need it. +NS_IMETHODIMP +nsImageQt::UnlockImagePixels(PRBool aMaskPixels) +{ + return NS_OK; +} + +NS_IMETHODIMP nsImageQt::DrawToImage(nsIImage* aDstImage, + nscoord aDX, nscoord aDY, + nscoord aDWidth, nscoord aDHeight) +{ + //qDebug("DrawToIMAGE"); + nsImageQt *dest = NS_STATIC_CAST(nsImageQt *, aDstImage); + + if (!dest) + return NS_ERROR_FAILURE; + + if (aDX >= dest->mWidth || aDY >= dest->mHeight) + return NS_OK; + + PRUint8 *rgbPtr=0, *alphaPtr=0; + PRUint32 rgbStride, alphaStride; + + rgbPtr = mImageBits; + rgbStride = mRowBytes; + alphaPtr = mAlphaBits; + alphaStride = mAlphaRowBytes; + + PRInt32 y; + PRInt32 ValidWidth = ( aDWidth < ( dest->mWidth - aDX ) ) ? aDWidth : ( dest->mWidth - aDX ); + PRInt32 ValidHeight = ( aDHeight < ( dest->mHeight - aDY ) ) ? aDHeight : ( dest->mHeight - aDY ); + + // now composite the two images together + switch (mAlphaDepth) { + case 1: + { + PRUint8 *dst = dest->mImageBits + aDY*dest->mRowBytes + 3*aDX; + PRUint8 *dstAlpha = dest->mAlphaBits + aDY*dest->mAlphaRowBytes; + PRUint8 *src = rgbPtr; + PRUint8 *alpha = alphaPtr; + PRUint8 offset = aDX & 0x7; // x starts at 0 + int iterations = (ValidWidth+7)/8; // round up + + for (y=0; y= ValidWidth) { + alphaPixels &= 0xff << (8 - (ValidWidth-x)); // no, mask off unused + if (alphaPixels == 0) + continue; // no 1 alpha pixels left + } + if (offset == 0) { + dstAlpha[(aDX+x)>>3] |= alphaPixels; // the cheap aligned case + } + else { + dstAlpha[(aDX+x)>>3] |= alphaPixels >> offset; + // avoid write if no 1's to write - also avoids going past end of array + PRUint8 alphaTemp = alphaPixels << (8U - offset); + if (alphaTemp & 0xff) + dstAlpha[((aDX+x)>>3) + 1] |= alphaTemp; + } + + if (alphaPixels == 0xff) { + // fix - could speed up by gathering a run of 0xff's and doing 1 memcpy + // all 8 pixels set; copy and jump forward + memcpy(dst,src,8*3); + continue; + } + else { + // else mix of 1's and 0's in alphaPixels, do 1 bit at a time + // Don't go past end of line! + PRUint8 *d = dst, *s = src; + for (PRUint8 aMask = 1<<7, j = 0; aMask && j < ValidWidth-x; aMask >>= 1, j++) { + // if this pixel is opaque then copy into the destination image + if (alphaPixels & aMask) { + // might be faster with *d++ = *s++ 3 times? + d[0] = s[0]; + d[1] = s[1]; + d[2] = s[2]; + // dstAlpha bit already set + } + d += 3; + s += 3; + } + } + } + // at end of each line, bump pointers. Use wordy code because of + // bug 127455 to avoid possibility of unsigned underflow + dst = (dst - 3*8*iterations) + dest->mRowBytes; + src = (src - 3*8*iterations) + rgbStride; + alpha = (alpha - iterations) + alphaStride; + dstAlpha += dest->mAlphaRowBytes; + } + } + break; + case 0: + default: + for (y=0; ymImageBits + (y+aDY)*dest->mRowBytes + 3*aDX, + rgbPtr + y*rgbStride, + 3*ValidWidth); + } + + nsRect rect(aDX, aDY, ValidWidth, ValidHeight); + dest->ImageUpdated(nsnull, 0, &rect); + + return NS_OK; +} diff --git a/mozilla/gfx/src/qt/nsImageQt.h b/mozilla/gfx/src/qt/nsImageQt.h new file mode 100644 index 00000000000..72e70d08dbd --- /dev/null +++ b/mozilla/gfx/src/qt/nsImageQt.h @@ -0,0 +1,142 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * John C. Griggs + * + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsImageQt_h___ +#define nsImageQt_h___ + +#include "nsIImage.h" +#include "nsRect.h" + +#include +#include + +#undef Bool + +class nsImageQt : public nsIImage +{ +public: + nsImageQt(); + virtual ~nsImageQt(); + + NS_DECL_ISUPPORTS + + /** + * @see nsIImage.h + */ + virtual nsresult Init(PRInt32 aWidth, PRInt32 aHeight, + PRInt32 aDepth, nsMaskRequirements aMaskRequirements); + + virtual PRInt32 GetBytesPix(); + virtual PRBool GetIsRowOrderTopToBottom() {return PR_TRUE;} + virtual PRInt32 GetHeight(); + virtual PRInt32 GetWidth(); + virtual PRUint8 *GetBits(); + virtual PRInt32 GetLineStride(); + virtual PRBool GetHasAlphaMask() {return mAlphaBits != nsnull;} + virtual PRUint8 *GetAlphaBits(); + virtual PRInt32 GetAlphaLineStride(); + + virtual void ImageUpdated(nsIDeviceContext *aContext, + PRUint8 aFlags,nsRect *aUpdateRect); + + virtual nsresult Optimize(nsIDeviceContext *aContext); + + virtual nsColorMap *GetColorMap(); + + NS_IMETHOD Draw(nsIRenderingContext &aContext, + nsIDrawingSurface* aSurface, + PRInt32 aX, PRInt32 aY, + PRInt32 aWidth, PRInt32 aHeight); + + NS_IMETHOD Draw(nsIRenderingContext &aContext, + nsIDrawingSurface *aSurface, + PRInt32 aSX, PRInt32 aSY, + PRInt32 aSWidth, PRInt32 aSHeight, + PRInt32 aDX, PRInt32 aDY, + PRInt32 aDWidth, PRInt32 aDHeight); + + NS_IMETHOD DrawTile(nsIRenderingContext &aContext, + nsIDrawingSurface* aSurface, + PRInt32 aSXOffset, PRInt32 aSYOffset, + PRInt32 aPadX, PRInt32 aPadY, + const nsRect &aTileRect); + + NS_IMETHOD DrawToImage(nsIImage *aDstImage, PRInt32 aDX, PRInt32 aDY, + PRInt32 aDWidth, PRInt32 aDHeight); + + virtual PRInt8 GetAlphaDepth() { return(mAlphaDepth); } + + virtual void *GetBitInfo(); + + NS_IMETHOD LockImagePixels(PRBool aMaskPixels); + + NS_IMETHOD UnlockImagePixels(PRBool aMaskPixels); + +private: + /** + * Calculate the amount of memory needed for the initialization of the + * image + */ + void updatePixmap(); + +private: + PRInt32 mWidth; + PRInt32 mHeight; + PRInt32 mDepth; + PRInt32 mRowBytes; + PRUint8 *mImageBits; + + PRInt8 mAlphaDepth; // alpha layer depth + PRInt16 mAlphaRowBytes; // alpha bytes per row + PRUint8 *mAlphaBits; + + + PRInt8 mNumBytesPixel; + + nsRect mDecodedRect; // Keeps track of what part of image has been decoded. + + QPixmap pixmap; + PRBool pixmapDirty; + + PRUint32 mID; +}; + +#endif diff --git a/mozilla/gfx/src/qt/nsNativeThemeQt.cpp b/mozilla/gfx/src/qt/nsNativeThemeQt.cpp new file mode 100644 index 00000000000..4e778fc71c4 --- /dev/null +++ b/mozilla/gfx/src/qt/nsNativeThemeQt.cpp @@ -0,0 +1,328 @@ +/* ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * David Hyatt (hyatt@netscape.com). + * Portions created by the Initial Developer are Copyright (C) 2001 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * Tim Hill (tim@prismelite.com) + * + * Alternatively, the contents of this file may be used under the terms of + * either of 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 "nsNativeThemeQt.h" +#include "nsRenderingContextQt.h" +#include "nsDeviceContextQt.h" +#include "nsRect.h" +#include "nsSize.h" +#include "nsTransform2D.h" +#include "nsThemeConstants.h" +#include "nsILookAndFeel.h" +#include "nsIServiceManager.h" +#include "nsIEventStateManager.h" +#include + +#include +#include +#include +#include + +nsNativeThemeQt::nsNativeThemeQt() +{ + combo = new QComboBox((QWidget *)0); + ThemeChanged(); +} + +nsNativeThemeQt::~nsNativeThemeQt() +{ + delete combo; +} + +NS_IMPL_ISUPPORTS1(nsNativeThemeQt, nsITheme) + +NS_IMETHODIMP +nsNativeThemeQt::DrawWidgetBackground(nsIRenderingContext* aContext, + nsIFrame* aFrame, + PRUint8 aWidgetType, + const nsRect& aRect, + const nsRect& aClipRect) +{ + nsRenderingContextQt *context = (nsRenderingContextQt *)aContext; + QPainter *p = context->painter(); + + //qDebug("aWidgetType = %d", aWidgetType); + if (!p) + return NS_OK; + + QStyle &s = qApp->style(); + const QColorGroup &cg = qApp->palette().active(); + + QRect r = context->qRect(aRect); + QRect cr = context->qRect(aClipRect); + context->UpdateGC(); + //qDebug("rect=%d %d %d %d", aRect.x, aRect.y, aRect.width, aRect.height); + p->save(); + p->translate(r.x(), r.y()); + r.moveBy(-r.x(), -r.y()); + + QStyle::PrimitiveElement pe = QStyle::PE_CustomBase; + QStyle::SFlags flags = IsDisabled(aFrame) ? + QStyle::Style_Default : + QStyle::Style_Enabled; + + PRInt32 eventState = GetContentState(aFrame, aWidgetType); + //qDebug("eventState = %d", eventState); + + if (eventState & NS_EVENT_STATE_HOVER) + flags |= QStyle::Style_MouseOver; + if (eventState & NS_EVENT_STATE_FOCUS) + flags |= QStyle::Style_HasFocus; + if (eventState & NS_EVENT_STATE_ACTIVE) + flags |= QStyle::Style_Down; + + switch (aWidgetType) { + case NS_THEME_RADIO: + flags |= (IsChecked(aFrame) ? QStyle::Style_On : QStyle::Style_Off); + pe = QStyle::PE_ExclusiveIndicator; + break; + case NS_THEME_CHECKBOX: + flags |= (IsChecked(aFrame) ? QStyle::Style_On : QStyle::Style_Off); + pe = QStyle::PE_Indicator; + break; + case NS_THEME_SCROLLBAR: + case NS_THEME_SCROLLBAR_TRACK_HORIZONTAL: + case NS_THEME_SCROLLBAR_TRACK_VERTICAL: + p->fillRect(r, qApp->palette().brush(QPalette::Active, QColorGroup::Background)); + break; + case NS_THEME_SCROLLBAR_BUTTON_LEFT: + flags |= QStyle::Style_Horizontal; + // fall through + case NS_THEME_SCROLLBAR_BUTTON_UP: + pe = QStyle::PE_ScrollBarSubLine; + break; + case NS_THEME_SCROLLBAR_BUTTON_RIGHT: + flags |= QStyle::Style_Horizontal; + // fall through + case NS_THEME_SCROLLBAR_BUTTON_DOWN: + pe = QStyle::PE_ScrollBarAddLine; + break; + case NS_THEME_SCROLLBAR_GRIPPER_HORIZONTAL: + case NS_THEME_SCROLLBAR_THUMB_HORIZONTAL: + flags |= QStyle::Style_Horizontal; + // fall through + case NS_THEME_SCROLLBAR_GRIPPER_VERTICAL: + case NS_THEME_SCROLLBAR_THUMB_VERTICAL: + pe = QStyle::PE_ScrollBarSlider; + break; + case NS_THEME_BUTTON_BEVEL: + pe = QStyle::PE_ButtonBevel; + flags |= QStyle::Style_Raised; + break; + case NS_THEME_BUTTON: + pe = IsDefaultButton(aFrame) ? QStyle::PE_ButtonDefault : QStyle::PE_ButtonCommand; + flags |= QStyle::Style_Raised; + break; + case NS_THEME_DROPDOWN: + s.drawComplexControl(QStyle::CC_ComboBox, p, combo, r, cg, flags, QStyle::SC_ComboBoxFrame); + break; + case NS_THEME_DROPDOWN_BUTTON: + r.moveBy(frameWidth, -frameWidth); + r.setHeight(r.height() + 2*frameWidth); + s.drawComplexControl(QStyle::CC_ComboBox, p, combo, r, cg, flags, QStyle::SC_ComboBoxArrow); + break; + case NS_THEME_DROPDOWN_TEXT: + case NS_THEME_DROPDOWN_TEXTFIELD: + break; + case NS_THEME_TEXTFIELD: + case NS_THEME_LISTBOX: + pe = QStyle::PE_PanelLineEdit; + break; + default: + break; + } + if (pe != QStyle::PE_CustomBase) + s.drawPrimitive(pe, p, r, cg, flags); + p->restore(); + return NS_OK; +} + +NS_IMETHODIMP +nsNativeThemeQt::GetWidgetBorder(nsIDeviceContext* aContext, + nsIFrame* aFrame, + PRUint8 aWidgetType, + nsMargin* aResult) +{ + (*aResult).top = (*aResult).bottom = (*aResult).left = (*aResult).right = 0; + + switch(aWidgetType) { + case NS_THEME_TEXTFIELD: + case NS_THEME_LISTBOX: + (*aResult).top = (*aResult).bottom = (*aResult).left = (*aResult).right = + frameWidth; + } + + return NS_OK; +} + +PRBool +nsNativeThemeQt::GetWidgetPadding(nsIDeviceContext* , + nsIFrame*, PRUint8 aWidgetType, + nsMargin* aResult) +{ + //XXX: is this really correct? + if (aWidgetType == NS_THEME_BUTTON_FOCUS || + aWidgetType == NS_THEME_TOOLBAR_BUTTON || + aWidgetType == NS_THEME_TOOLBAR_DUAL_BUTTON) { + aResult->SizeTo(0, 0, 0, 0); + return PR_TRUE; + } + + return PR_FALSE; +} + +NS_IMETHODIMP +nsNativeThemeQt::GetMinimumWidgetSize(nsIRenderingContext* aContext, nsIFrame* aFrame, + PRUint8 aWidgetType, + nsSize* aResult, PRBool* aIsOverridable) +{ + (*aResult).width = (*aResult).height = 0; + *aIsOverridable = PR_TRUE; + + QStyle &s = qApp->style(); + + switch (aWidgetType) { + case NS_THEME_RADIO: + case NS_THEME_CHECKBOX: { + QRect rect = s.subRect(aWidgetType == NS_THEME_CHECKBOX + ? QStyle::SR_CheckBoxIndicator + : QStyle::SR_RadioButtonIndicator, + 0); + (*aResult).width = rect.width(); + (*aResult).height = rect.height(); + break; + } + case NS_THEME_SCROLLBAR_BUTTON_UP: + case NS_THEME_SCROLLBAR_BUTTON_DOWN: + case NS_THEME_SCROLLBAR_BUTTON_LEFT: + case NS_THEME_SCROLLBAR_BUTTON_RIGHT: + (*aResult).width = s.pixelMetric(QStyle::PM_ScrollBarExtent); + (*aResult).height = (*aResult).width; + *aIsOverridable = PR_FALSE; + break; + case NS_THEME_SCROLLBAR_THUMB_VERTICAL: + (*aResult).width = s.pixelMetric(QStyle::PM_ScrollBarExtent); + (*aResult).height = s.pixelMetric(QStyle::PM_ScrollBarSliderMin); + *aIsOverridable = PR_FALSE; + break; + case NS_THEME_SCROLLBAR_THUMB_HORIZONTAL: + (*aResult).width = s.pixelMetric(QStyle::PM_ScrollBarSliderMin); + (*aResult).height = s.pixelMetric(QStyle::PM_ScrollBarExtent); + *aIsOverridable = PR_FALSE; + break; + case NS_THEME_SCROLLBAR_TRACK_VERTICAL: + break; + case NS_THEME_SCROLLBAR_TRACK_HORIZONTAL: + break; + case NS_THEME_DROPDOWN_BUTTON: { + QRect r = s.querySubControlMetrics(QStyle::CC_ComboBox, combo, QStyle::SC_ComboBoxArrow); + (*aResult).width = r.width() - 2*frameWidth; + (*aResult).height = r.height() - 2*frameWidth; + break; + } + case NS_THEME_DROPDOWN: + case NS_THEME_DROPDOWN_TEXT: + case NS_THEME_DROPDOWN_TEXTFIELD: + case NS_THEME_TEXTFIELD: + break; + } + return NS_OK; +} + + NS_IMETHODIMP + nsNativeThemeQt::WidgetStateChanged(nsIFrame* aFrame, PRUint8 aWidgetType, + nsIAtom* aAttribute, PRBool* aShouldRepaint) +{ + *aShouldRepaint = TRUE; + return NS_OK; +} + + +NS_IMETHODIMP +nsNativeThemeQt::ThemeChanged() +{ + QStyle & s = qApp->style(); + frameWidth = s.pixelMetric(QStyle::PM_DefaultFrameWidth); + return NS_OK; +} + +PRBool +nsNativeThemeQt::ThemeSupportsWidget(nsPresContext* aPresContext, + nsIFrame* aFrame, + PRUint8 aWidgetType) +{ + switch (aWidgetType) { + case NS_THEME_SCROLLBAR: + case NS_THEME_SCROLLBAR_BUTTON_UP: + case NS_THEME_SCROLLBAR_BUTTON_DOWN: + case NS_THEME_SCROLLBAR_BUTTON_LEFT: + case NS_THEME_SCROLLBAR_BUTTON_RIGHT: + case NS_THEME_SCROLLBAR_THUMB_HORIZONTAL: + case NS_THEME_SCROLLBAR_THUMB_VERTICAL: + case NS_THEME_SCROLLBAR_GRIPPER_HORIZONTAL: + case NS_THEME_SCROLLBAR_GRIPPER_VERTICAL: + case NS_THEME_SCROLLBAR_TRACK_HORIZONTAL: + case NS_THEME_SCROLLBAR_TRACK_VERTICAL: + case NS_THEME_RADIO: + case NS_THEME_CHECKBOX: + case NS_THEME_BUTTON_BEVEL: + case NS_THEME_BUTTON: + case NS_THEME_DROPDOWN: + case NS_THEME_DROPDOWN_BUTTON: + case NS_THEME_DROPDOWN_TEXT: + case NS_THEME_DROPDOWN_TEXTFIELD: + case NS_THEME_TEXTFIELD: + case NS_THEME_LISTBOX: + return PR_TRUE; + default: + break; + } + return PR_FALSE; +} + +PRBool +nsNativeThemeQt::WidgetIsContainer(PRUint8 aWidgetType) +{ + // XXXdwh At some point flesh all of this out. + if (aWidgetType == NS_THEME_DROPDOWN_BUTTON || + aWidgetType == NS_THEME_RADIO || + aWidgetType == NS_THEME_CHECKBOX) + return PR_FALSE; + return PR_TRUE; +} diff --git a/mozilla/gfx/src/qt/nsNativeThemeQt.h b/mozilla/gfx/src/qt/nsNativeThemeQt.h new file mode 100644 index 00000000000..8cff570c3b8 --- /dev/null +++ b/mozilla/gfx/src/qt/nsNativeThemeQt.h @@ -0,0 +1,95 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * ***** 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 browser. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1999 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * Tim Hill (tim@prismelite.com) + * + * Alternatively, the contents of this file may be used under the terms of + * either of 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 "nsITheme.h" +#include "nsCOMPtr.h" +#include "nsIAtom.h" +#include "nsNativeTheme.h" + +class QComboBox; + +class nsNativeThemeQt : private nsNativeTheme, + public nsITheme +{ +public: + NS_DECL_ISUPPORTS + + // The nsITheme interface. + NS_IMETHOD DrawWidgetBackground(nsIRenderingContext* aContext, + nsIFrame* aFrame, + PRUint8 aWidgetType, + const nsRect& aRect, + const nsRect& aClipRect); + + NS_IMETHOD GetWidgetBorder(nsIDeviceContext* aContext, + nsIFrame* aFrame, + PRUint8 aWidgetType, + nsMargin* aResult); + + NS_IMETHOD GetMinimumWidgetSize(nsIRenderingContext* aContext, nsIFrame* aFrame, + PRUint8 aWidgetType, + nsSize* aResult, + PRBool* aIsOverridable); + + NS_IMETHOD WidgetStateChanged(nsIFrame* aFrame, PRUint8 aWidgetType, + nsIAtom* aAttribute, PRBool* aShouldRepaint); + + NS_IMETHOD ThemeChanged(); + + PRBool ThemeSupportsWidget(nsPresContext* aPresContext, + nsIFrame* aFrame, + PRUint8 aWidgetType); + + PRBool WidgetIsContainer(PRUint8 aWidgetType); + + virtual NS_HIDDEN_(PRBool) GetWidgetPadding(nsIDeviceContext* aContext, + nsIFrame* aFrame, + PRUint8 aWidgetType, + nsMargin* aResult); + + nsNativeThemeQt(); + virtual ~nsNativeThemeQt(); + +private: + QComboBox *combo; + int frameWidth; +}; + diff --git a/mozilla/gfx/src/qt/nsRegionQt.cpp b/mozilla/gfx/src/qt/nsRegionQt.cpp new file mode 100644 index 00000000000..dd27b28ddda --- /dev/null +++ b/mozilla/gfx/src/qt/nsRegionQt.cpp @@ -0,0 +1,247 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * John C. Griggs + * + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsRegionQt.h" +#include "prmem.h" +#include "nsRenderingContextQt.h" +#include + +#include "qtlog.h" + +#ifdef DEBUG +PRUint32 gRegionCount = 0; +PRUint32 gRegionID = 0; +#endif + +nsRegionQt::nsRegionQt() : mRegion() +{ +#ifdef DEBUG + gRegionCount++; + mID = gRegionID++; + PR_LOG(gQtLogModule, QT_BASIC, + ("nsRegionQt CTOR (%p) ID: %d, Count: %d\n", this, mID, gRegionCount)); +#endif +} + +nsRegionQt::~nsRegionQt() +{ +#ifdef DEBUG + gRegionCount--; + PR_LOG(gQtLogModule, QT_BASIC, + ("nsRegionQt DTOR (%p) ID: %d, Count: %d\n", this, mID, gRegionCount)); +#endif +} + +NS_IMPL_ISUPPORTS1(nsRegionQt, nsIRegion) + +nsresult nsRegionQt::Init(void) +{ + mRegion = QRegion(); + return NS_OK; +} + +void nsRegionQt::SetTo(const nsIRegion &aRegion) +{ + nsRegionQt *pRegion = (nsRegionQt*)&aRegion; + + mRegion = pRegion->mRegion; +} + +void nsRegionQt::SetTo(const nsRegionQt *aRegion) +{ + mRegion = aRegion->mRegion; +} + +void nsRegionQt::SetTo(PRInt32 aX,PRInt32 aY,PRInt32 aWidth,PRInt32 aHeight) +{ + mRegion = QRegion(aX, aY, aWidth, aHeight);; +} + +void nsRegionQt::Intersect(const nsIRegion &aRegion) +{ + nsRegionQt *pRegion = (nsRegionQt*)&aRegion; + + mRegion = mRegion.intersect(pRegion->mRegion); +} + +void nsRegionQt::Intersect(PRInt32 aX,PRInt32 aY, + PRInt32 aWidth,PRInt32 aHeight) +{ + mRegion = mRegion.intersect(QRect(aX, aY, aWidth, aHeight)); +} + +void nsRegionQt::Union(const nsIRegion &aRegion) +{ + nsRegionQt *pRegion = (nsRegionQt*)&aRegion; + + mRegion = mRegion.unite(pRegion->mRegion); +} + +void nsRegionQt::Union(PRInt32 aX,PRInt32 aY,PRInt32 aWidth,PRInt32 aHeight) +{ + mRegion = mRegion.unite(QRect(aX, aY, aWidth, aHeight)); +} + +void nsRegionQt::Subtract(const nsIRegion &aRegion) +{ + nsRegionQt *pRegion = (nsRegionQt*)&aRegion; + + mRegion = mRegion.subtract(pRegion->mRegion); +} + +void nsRegionQt::Subtract(PRInt32 aX,PRInt32 aY,PRInt32 aWidth,PRInt32 aHeight) +{ + mRegion = mRegion.subtract(QRect(aX, aY, aWidth, aHeight)); +} + +PRBool nsRegionQt::IsEmpty(void) +{ + return mRegion.isEmpty(); +} + +PRBool nsRegionQt::IsEqual(const nsIRegion &aRegion) +{ + nsRegionQt *pRegion = (nsRegionQt*)&aRegion; + + return (mRegion == pRegion->mRegion); +} + +void nsRegionQt::GetBoundingBox(PRInt32 *aX,PRInt32 *aY, + PRInt32 *aWidth,PRInt32 *aHeight) +{ + QRect rect = mRegion.boundingRect(); + + *aX = rect.x(); + *aY = rect.y(); + *aWidth = rect.width(); + *aHeight = rect.height(); +} + +void nsRegionQt::Offset(PRInt32 aXOffset, PRInt32 aYOffset) +{ + mRegion.translate(aXOffset, aYOffset); +} + +PRBool nsRegionQt::ContainsRect(PRInt32 aX,PRInt32 aY, + PRInt32 aWidth,PRInt32 aHeight) +{ + return mRegion.contains(QRect(aX, aY, aWidth, aHeight)); +} + +NS_IMETHODIMP nsRegionQt::GetRects(nsRegionRectSet **aRects) +{ + NS_ASSERTION(!(nsnull == aRects), "bad ptr"); + + QMemArray array = mRegion.rects(); + PRUint32 size = array.size(); + nsRegionRect *rect = nsnull; + nsRegionRectSet *rects = *aRects; + + if (nsnull == rects || rects->mRectsLen < (PRUint32)size) { + void *buf = PR_Realloc(rects, + sizeof(nsRegionRectSet) + + (sizeof(nsRegionRect) * (size - 1))); + + if (nsnull == buf) { + if (nsnull != rects) + rects->mNumRects = 0; + return NS_OK; + } + rects = (nsRegionRectSet*)buf; + rects->mRectsLen = size; + } + rects->mNumRects = size; + rects->mArea = 0; + rect = &rects->mRects[0]; + + for (PRUint32 i = 0; i < size; i++) { + const QRect &qRect = array.at(i); + + rect->x = qRect.x(); + rect->y = qRect.y(); + rect->width = qRect.width(); + rect->height = qRect.height(); + + rects->mArea += rect->width * rect->height; + + rect++; + } + *aRects = rects; + return NS_OK; +} + +NS_IMETHODIMP nsRegionQt::FreeRects(nsRegionRectSet *aRects) +{ + if (nsnull != aRects) { + PR_Free((void*)aRects); + } + return NS_OK; +} + +NS_IMETHODIMP nsRegionQt::GetNativeRegion(void *&aRegion) const +{ + aRegion = (void*)&mRegion; + return NS_OK; +} + +NS_IMETHODIMP nsRegionQt::GetRegionComplexity(nsRegionComplexity &aComplexity) const +{ + // cast to avoid const-ness problems on some compilers + if (mRegion.isEmpty()) { + aComplexity = eRegionComplexity_empty; + } + else { + aComplexity = eRegionComplexity_rect; + } + return NS_OK; +} + +void nsRegionQt::SetRegionEmpty() +{ + mRegion = QRegion(); +} + +NS_IMETHODIMP nsRegionQt::GetNumRects(PRUint32 *aRects) const +{ + *aRects = mRegion.rects().size(); + + return NS_OK; +} diff --git a/mozilla/gfx/src/qt/nsRegionQt.h b/mozilla/gfx/src/qt/nsRegionQt.h new file mode 100644 index 00000000000..aeefc592b67 --- /dev/null +++ b/mozilla/gfx/src/qt/nsRegionQt.h @@ -0,0 +1,89 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * John C. Griggs + * + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsRegionQt_h___ +#define nsRegionQt_h___ + +#include "nsIRegion.h" + +#include + +class nsRegionQt : public nsIRegion +{ +public: + nsRegionQt(); + virtual ~nsRegionQt(); + + NS_DECL_ISUPPORTS + + virtual nsresult Init(); + + virtual void SetTo(const nsIRegion &aRegion); + virtual void SetTo(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight); + void SetTo(const nsRegionQt *aRegion); + virtual void Intersect(const nsIRegion &aRegion); + virtual void Intersect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight); + virtual void Union(const nsIRegion &aRegion); + virtual void Union(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight); + virtual void Subtract(const nsIRegion &aRegion); + virtual void Subtract(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight); + virtual PRBool IsEmpty(void); + virtual PRBool IsEqual(const nsIRegion &aRegion); + virtual void GetBoundingBox(PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight); + virtual void Offset(PRInt32 aXOffset, PRInt32 aYOffset); + virtual PRBool ContainsRect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight); + NS_IMETHOD GetRects(nsRegionRectSet **aRects); + NS_IMETHOD FreeRects(nsRegionRectSet *aRects); + NS_IMETHOD GetNativeRegion(void *&aRegion) const; + NS_IMETHOD GetRegionComplexity(nsRegionComplexity &aComplexity) const; + NS_IMETHOD GetNumRects(PRUint32* aRects) const; + +private: + virtual void SetRegionEmpty(); + +private: + QRegion mRegion; +#ifdef DEBUG + PRUint32 mID; +#endif +}; + +#endif // nsRegionQt_h___ diff --git a/mozilla/gfx/src/qt/nsRenderingContextQt.cpp b/mozilla/gfx/src/qt/nsRenderingContextQt.cpp new file mode 100644 index 00000000000..a7168dea179 --- /dev/null +++ b/mozilla/gfx/src/qt/nsRenderingContextQt.cpp @@ -0,0 +1,1331 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * John C. Griggs + * + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsFontMetricsQt.h" +#include "nsRenderingContextQt.h" +#include "nsRegionQt.h" +#include "nsImageQt.h" +#include "nsGfxCIID.h" +#include "nsICharRepresentable.h" +#include + +#include +#include +#include +#include "prmem.h" + +#include "qtlog.h" + +#ifdef DEBUG +PRUint32 gRCCount = 0; +PRUint32 gRCID = 0; + +PRUint32 gGSCount = 0; +PRUint32 gGSID = 0; +#endif + +class GraphicsState +{ +public: + GraphicsState(); + ~GraphicsState(); + + nsTransform2D *mMatrix; + nsRect mLocalClip; + nsCOMPtr mClipRegion; + nscolor mColor; + nsLineStyle mLineStyle; + nsIFontMetrics *mFontMetrics; + +private: + PRUint32 mID; +}; + +GraphicsState::GraphicsState() +{ +#ifdef DEBUG + gGSCount++; + mID = gGSID++; + PR_LOG(gQtLogModule, QT_BASIC, + ("GraphicsState CTOR (%p) ID: %d, Count: %d\n", this, mID, gGSCount)); +#endif + mMatrix = nsnull; + mLocalClip.x = mLocalClip.y = mLocalClip.width = mLocalClip.height = 0; + mClipRegion = nsnull; + mColor = NS_RGB(0,0,0); + mLineStyle = nsLineStyle_kSolid; + mFontMetrics = nsnull; +} + +GraphicsState::~GraphicsState() +{ +#ifdef DEBUG + gGSCount--; + PR_LOG(gQtLogModule, QT_BASIC, + ("GraphicsState DTOR (%p) ID: %d, Count: %d\n", this, mID, gGSCount)); +#endif +} + +NS_IMPL_THREADSAFE_ISUPPORTS1(nsRenderingContextQt, nsIRenderingContext) + +static NS_DEFINE_CID(kRegionCID, NS_REGION_CID); + +nsRenderingContextQt::nsRenderingContextQt() +{ +#ifdef DEBUG + gRCCount++; + mID = gRCID++; + PR_LOG(gQtLogModule, QT_BASIC, + ("nsRenderingContextQt CTOR (%p) ID: %d, Count: %d\n", this, mID, gRCCount)); +#endif + + mFontMetrics = nsnull; + mContext = nsnull; + mSurface = nsnull; + mOffscreenSurface = nsnull; + mCurrentColor = NS_RGB(255,255,255); // set it to white + mCurrentLineStyle = nsLineStyle_kSolid; + mCurrentFont = nsnull; + mTranMatrix = nsnull; + mP2T = 1.0f; + mClipRegion = nsnull; + + mFunction = Qt::CopyROP; + mQLineStyle = Qt::SolidLine; + + PushState(); +} + +nsRenderingContextQt::~nsRenderingContextQt() +{ +#ifdef DEBUG + gRCCount--; + PR_LOG(gQtLogModule, QT_BASIC, + ("nsRenderingContextQt DTOR (%p) ID: %d, Count: %d\n", this, mID, gRCCount)); +#endif + // Destroy the State Machine + PRInt32 cnt = mStateCache.Count(); + + while (--cnt >= 0) { + PopState(); + } + + delete mTranMatrix; + + NS_IF_RELEASE(mOffscreenSurface); + NS_IF_RELEASE(mFontMetrics); + NS_IF_RELEASE(mContext); +} + +NS_IMETHODIMP nsRenderingContextQt::Init(nsIDeviceContext *aContext, + nsIWidget *aWindow) +{ + mContext = aContext; + NS_IF_ADDREF(mContext); + + mSurface = new nsDrawingSurfaceQt(); + + QPaintDevice *pdevice = (QWidget*)aWindow->GetNativeData(NS_NATIVE_WINDOW); + Q_ASSERT(pdevice); + QPainter *gc = new QPainter(); + + mSurface->Init(pdevice,gc); + + mOffscreenSurface = mSurface; + + NS_ADDREF(mSurface); + + return(CommonInit()); +} + +NS_IMETHODIMP nsRenderingContextQt::Init(nsIDeviceContext *aContext, + nsIDrawingSurface* aSurface) +{ + mContext = aContext; + NS_IF_ADDREF(mContext); + + mSurface = (nsDrawingSurfaceQt*)aSurface; + NS_ADDREF(mSurface); + return (CommonInit()); +} + +NS_IMETHODIMP nsRenderingContextQt::CommonInit() +{ + mP2T = mContext->DevUnitsToAppUnits(); + float app2dev; + + app2dev = mContext->AppUnitsToDevUnits(); + mTranMatrix->SetToIdentity(); + mTranMatrix->AddScale(app2dev,app2dev); + + return NS_OK; +} + +NS_IMETHODIMP nsRenderingContextQt::GetHints(PRUint32 &aResult) +{ + PRUint32 result = 0; + + // Most X servers implement 8 bit text rendering alot faster than + // XChar2b rendering. In addition, we can avoid the PRUnichar to + // XChar2b conversion. So we set this bit... + //result |= NS_RENDERING_HINT_FAST_8BIT_TEXT; + + // XXX see if we are rendering to the local display or to a remote + // dispaly and set the NS_RENDERING_HINT_REMOTE_RENDERING accordingly + aResult = result; + return NS_OK; +} + +NS_IMETHODIMP nsRenderingContextQt::LockDrawingSurface(PRInt32 aX, + PRInt32 aY, + PRUint32 aWidth, + PRUint32 aHeight, + void **aBits, + PRInt32 *aStride, + PRInt32 *aWidthBytes, + PRUint32 aFlags) +{ + PushState(); + return mSurface->Lock(aX,aY,aWidth,aHeight,aBits,aStride, + aWidthBytes,aFlags); +} + +NS_IMETHODIMP nsRenderingContextQt::UnlockDrawingSurface(void) +{ + PopState(); + mSurface->Unlock(); + return NS_OK; +} + +NS_IMETHODIMP +nsRenderingContextQt::SelectOffScreenDrawingSurface(nsIDrawingSurface* aSurface) +{ + if (nsnull == aSurface) + mSurface = mOffscreenSurface; + else + mSurface = (nsDrawingSurfaceQt*)aSurface; + return NS_OK; +} + +NS_IMETHODIMP +nsRenderingContextQt::GetDrawingSurface(nsIDrawingSurface* *aSurface) +{ + *aSurface = mSurface; + return NS_OK; +} + +NS_IMETHODIMP nsRenderingContextQt::Reset() +{ + return NS_OK; +} + +NS_IMETHODIMP +nsRenderingContextQt::GetDeviceContext(nsIDeviceContext *&aContext) +{ + NS_IF_ADDREF(mContext); + aContext = mContext; + return NS_OK; +} + +NS_IMETHODIMP nsRenderingContextQt::PushState(void) +{ +#ifdef USE_GS_POOL + nsGraphicsState *state = nsGraphicsStatePool::GetNewGS(); +#else + GraphicsState *state = new GraphicsState(); +#endif + if (!state) + return NS_ERROR_FAILURE; + + // Push into this state object, add to vector + state->mMatrix = mTranMatrix; + + if (nsnull == mTranMatrix) + mTranMatrix = new nsTransform2D(); + else + mTranMatrix = new nsTransform2D(mTranMatrix); + + state->mClipRegion = mClipRegion; + + NS_IF_ADDREF(mFontMetrics); + state->mFontMetrics = mFontMetrics; + + state->mColor = mCurrentColor; + state->mLineStyle = mCurrentLineStyle; + + mStateCache.AppendElement(state); + return NS_OK; +} + +NS_IMETHODIMP nsRenderingContextQt::PopState() +{ + GraphicsState *state; + PRUint32 cnt = mStateCache.Count(); + + if (cnt > 0) { + state = (GraphicsState*)mStateCache.ElementAt(cnt - 1); + mStateCache.RemoveElementAt(cnt - 1); + + // Assign all local attributes from the state object just popped + if (state->mMatrix) { + delete mTranMatrix; + mTranMatrix = state->mMatrix; + } + mClipRegion = state->mClipRegion; + + if (state->mColor != mCurrentColor) + SetColor(state->mColor); + + if (state->mLineStyle != mCurrentLineStyle) + SetLineStyle(state->mLineStyle); + + if (state->mFontMetrics && (mFontMetrics != state->mFontMetrics)) + SetFont(state->mFontMetrics); + + // Delete this graphics state object +#ifdef USE_GS_POOL + nsGraphicsStatePool::ReleaseGS(state); +#else + delete state; +#endif + } + + return NS_OK; +} + +NS_IMETHODIMP nsRenderingContextQt::IsVisibleRect(const nsRect &aRect, + PRBool &aVisible) +{ + aVisible = PR_TRUE; + return NS_OK; +} + +NS_IMETHODIMP nsRenderingContextQt::GetClipRect(nsRect &aRect, + PRBool &aClipValid) +{ + PRInt32 x,y,w,h; + + if (!mClipRegion) + return NS_ERROR_FAILURE; + + if (!mClipRegion->IsEmpty()) { + mClipRegion->GetBoundingBox(&x,&y,&w,&h); + aRect.SetRect(x,y,w,h); + aClipValid = PR_TRUE; + } + else { + aRect.SetRect(0,0,0,0); + aClipValid = PR_FALSE; + } + return NS_OK; +} + +/** + * Fills in |aRegion| with a copy of the current clip region. + */ +NS_IMETHODIMP nsRenderingContextQt::CopyClipRegion(nsIRegion &aRegion) +{ + if (!mClipRegion) + return NS_ERROR_FAILURE; + + aRegion.SetTo(*mClipRegion); + return NS_OK; +} + +void nsRenderingContextQt::CreateClipRegion() +{ + if (mClipRegion) + return; + + mClipRegion = do_CreateInstance(kRegionCID); + if (mClipRegion) { + PRUint32 w,h; + + mSurface->GetDimensions(&w,&h); + mClipRegion->Init(); + mClipRegion->SetTo(0,0,w,h); + } +} + +NS_IMETHODIMP nsRenderingContextQt::SetClipRect(const nsRect &aRect, + nsClipCombine aCombine) +{ + GraphicsState *state = nsnull; + PRUint32 cnt = mStateCache.Count(); + + if (cnt > 0) { + state = (GraphicsState*)mStateCache.ElementAt(cnt - 1); + } + if (state) { + if (state->mClipRegion) { + if (state->mClipRegion == mClipRegion) { + nsCOMPtr tmpRgn; + + GetClipRegion(getter_AddRefs(tmpRgn)); + mClipRegion = tmpRgn; + } + } + } + CreateClipRegion(); + + nsRect trect = aRect; + + mTranMatrix->TransformCoord(&trect.x,&trect.y, + &trect.width,&trect.height); + + switch (aCombine) { + case nsClipCombine_kIntersect: + mClipRegion->Intersect(trect.x,trect.y,trect.width,trect.height); + break; + + case nsClipCombine_kUnion: + mClipRegion->Union(trect.x,trect.y,trect.width,trect.height); + break; + + case nsClipCombine_kSubtract: + mClipRegion->Subtract(trect.x,trect.y,trect.width,trect.height); + break; + + case nsClipCombine_kReplace: + mClipRegion->SetTo(trect.x,trect.y,trect.width,trect.height); + break; + } + + return NS_OK; +} + +NS_IMETHODIMP nsRenderingContextQt::SetClipRegion(const nsIRegion &aRegion, + nsClipCombine aCombine) +{ + PRUint32 cnt = mStateCache.Count(); + GraphicsState *state = nsnull; + + if (cnt > 0) { + state = (GraphicsState *)mStateCache.ElementAt(cnt - 1); + } + if (state) { + if (state->mClipRegion) { + if (state->mClipRegion == mClipRegion) { + nsCOMPtr tmpRgn; + + GetClipRegion(getter_AddRefs(tmpRgn)); + mClipRegion = tmpRgn; + } + } + } + CreateClipRegion(); + + switch(aCombine) { + case nsClipCombine_kIntersect: + mClipRegion->Intersect(aRegion); + break; + + case nsClipCombine_kUnion: + mClipRegion->Union(aRegion); + break; + + case nsClipCombine_kSubtract: + mClipRegion->Subtract(aRegion); + break; + + case nsClipCombine_kReplace: + mClipRegion->SetTo(aRegion); + break; + } + + return NS_OK; +} + +NS_IMETHODIMP nsRenderingContextQt::GetClipRegion(nsIRegion **aRegion) +{ + nsresult rv = NS_ERROR_FAILURE; + + if (!aRegion || !mClipRegion) + return NS_ERROR_NULL_POINTER; + + if (*aRegion) { + (*aRegion)->SetTo(*mClipRegion); + rv = NS_OK; + } + else { + nsCOMPtr newRegion = do_CreateInstance(kRegionCID,&rv); + if (NS_SUCCEEDED(rv)) { + newRegion->Init(); + newRegion->SetTo(*mClipRegion); + NS_ADDREF(*aRegion = newRegion); + } + } + return rv; +} + +NS_IMETHODIMP nsRenderingContextQt::SetColor(nscolor aColor) +{ + if (nsnull == mContext) + return NS_ERROR_FAILURE; + + mCurrentColor = aColor; + return NS_OK; +} + +NS_IMETHODIMP nsRenderingContextQt::GetColor(nscolor &aColor) const +{ + aColor = mCurrentColor; + return NS_OK; +} + +NS_IMETHODIMP nsRenderingContextQt::SetFont(const nsFont &aFont, nsIAtom* aLangGroup) +{ + nsCOMPtr newMetrics; + nsresult rv = mContext->GetMetricsFor(aFont, aLangGroup, *getter_AddRefs(newMetrics)); + + if (NS_SUCCEEDED(rv)) { + rv = SetFont(newMetrics); + } + return rv; +} + +NS_IMETHODIMP nsRenderingContextQt::SetFont(nsIFontMetrics *aFontMetrics) +{ + NS_IF_RELEASE(mFontMetrics); + mFontMetrics = aFontMetrics; + NS_IF_ADDREF(mFontMetrics); + + if (mFontMetrics) { + nsFontHandle fontHandle; + + mFontMetrics->GetFontHandle(fontHandle); + mCurrentFont = (nsFontQt*)fontHandle; + } + return NS_OK; +} + +NS_IMETHODIMP nsRenderingContextQt::SetLineStyle(nsLineStyle aLineStyle) +{ + if (aLineStyle != mCurrentLineStyle) { + switch (aLineStyle) { + case nsLineStyle_kSolid: + mQLineStyle = QPen::SolidLine; + break; + + case nsLineStyle_kDashed: + mQLineStyle = QPen::DashLine; + break; + + case nsLineStyle_kDotted: + mQLineStyle = QPen::DotLine; + break; + + default: + break; + } + mCurrentLineStyle = aLineStyle ; + } + return NS_OK; +} + +NS_IMETHODIMP nsRenderingContextQt::GetLineStyle(nsLineStyle &aLineStyle) +{ + aLineStyle = mCurrentLineStyle; + return NS_OK; +} + +NS_IMETHODIMP +nsRenderingContextQt::GetFontMetrics(nsIFontMetrics *&aFontMetrics) +{ + NS_IF_ADDREF(mFontMetrics); + aFontMetrics = mFontMetrics; + return NS_OK; +} + +// add the passed in translation to the current translation +NS_IMETHODIMP nsRenderingContextQt::Translate(nscoord aX,nscoord aY) +{ + mTranMatrix->AddTranslation((float)aX,(float)aY); + return NS_OK; +} + +// add the passed in scale to the current scale +NS_IMETHODIMP nsRenderingContextQt::Scale(float aSx,float aSy) +{ + mTranMatrix->AddScale(aSx,aSy); + return NS_OK; +} + +NS_IMETHODIMP +nsRenderingContextQt::GetCurrentTransform(nsTransform2D *&aTransform) +{ + aTransform = mTranMatrix; + return NS_OK; +} + +NS_IMETHODIMP +nsRenderingContextQt::CreateDrawingSurface(const nsRect& aBounds, + PRUint32 aSurfFlags, + nsIDrawingSurface* &aSurface) +{ + if (nsnull == mSurface) { + aSurface = nsnull; + return NS_ERROR_FAILURE; + } + if (aBounds.width <= 0 || aBounds.height <= 0) + return NS_ERROR_FAILURE; + + nsDrawingSurfaceQt *surface = new nsDrawingSurfaceQt(); + + if (surface) { + //QPainter *gc = mSurface->GetGC(); + QPainter *gc = new QPainter(); + NS_ADDREF(surface); + //PushState(); + surface->Init(gc,aBounds.width,aBounds.height,aSurfFlags); + //PopState(); + } + else { + aSurface = nsnull; + return NS_ERROR_FAILURE; + } + aSurface = surface; + return NS_OK; +} + +NS_IMETHODIMP nsRenderingContextQt::DestroyDrawingSurface(nsIDrawingSurface* aDS) +{ + nsDrawingSurfaceQt *surface = (nsDrawingSurfaceQt*)aDS; + + if (surface == NULL) + return NS_ERROR_FAILURE; + + NS_IF_RELEASE(surface); + return NS_OK; +} + +void nsRenderingContextQt::UpdateGC() +{ + QPainter *pGC; + QColor color(NS_GET_R(mCurrentColor), + NS_GET_G(mCurrentColor), + NS_GET_B(mCurrentColor)); + QPen pen(color,0,mQLineStyle); + QBrush brush(color); + + pGC = mSurface->GetGC(); + pGC->setPen(pen); + pGC->setBrush(brush); + pGC->setRasterOp(mFunction); + if (mCurrentFont) + pGC->setFont(mCurrentFont->font); + if (mClipRegion) { + QRegion *rgn = nsnull; + + pGC->setClipping(TRUE); + mClipRegion->GetNativeRegion((void*&)rgn); + pGC->setClipRegion(*rgn); + } + else { + pGC->setClipping(FALSE); + } +} + +NS_IMETHODIMP nsRenderingContextQt::DrawLine(nscoord aX0,nscoord aY0, + nscoord aX1,nscoord aY1) +{ + nscoord diffX,diffY; + + if (nsnull == mTranMatrix || nsnull == mSurface + || nsnull == mSurface->GetGC() || nsnull == mSurface->GetPaintDevice()) + return NS_ERROR_FAILURE; + + mTranMatrix->TransformCoord(&aX0,&aY0); + mTranMatrix->TransformCoord(&aX1,&aY1); + + diffX = aX1 - aX0; + diffY = aY1 - aY0; + + if (0 != diffX) { + diffX = (diffX > 0 ? 1 : -1); + } + if (0 != diffY) { + diffY = (diffY > 0 ? 1 : -1); + } + UpdateGC(); + mSurface->GetGC()->drawLine(aX0,aY0,aX1 - diffX,aY1 - diffY); + return NS_OK; +} + +NS_IMETHODIMP nsRenderingContextQt::DrawStdLine(nscoord aX0,nscoord aY0, + nscoord aX1,nscoord aY1) +{ + nscoord diffX,diffY; + + if (nsnull == mTranMatrix || nsnull == mSurface + || nsnull == mSurface->GetGC() || nsnull == mSurface->GetPaintDevice()) + return NS_ERROR_FAILURE; + + mTranMatrix->TransformCoord(&aX0,&aY0); + mTranMatrix->TransformCoord(&aX1,&aY1); + + diffX = aX1 - aX0; + diffY = aY1 - aY0; + + if (0 != diffX) { + diffX = (diffX > 0 ? 1 : -1); + } + if (0 != diffY) { + diffY = (diffY > 0 ? 1 : -1); + } + UpdateGC(); + mSurface->GetGC()->drawLine(aX0,aY0,aX1 - diffX,aY1 - diffY); + return NS_OK; +} + +NS_IMETHODIMP nsRenderingContextQt::DrawPolyline(const nsPoint aPoints[], + PRInt32 aNumPoints) +{ + PRInt32 i; + + if (nsnull == mTranMatrix || nsnull == mSurface + || nsnull == mSurface->GetGC() || nsnull == mSurface->GetPaintDevice()) + return NS_ERROR_FAILURE; + + QPointArray pts(aNumPoints); + for (i = 0; i < aNumPoints; i++) { + nsPoint p = aPoints[i]; + + mTranMatrix->TransformCoord(&p.x,&p.y); + pts.setPoint(i,p.x,p.y); + } + UpdateGC(); + + mSurface->GetGC()->drawPolyline(pts); + + return NS_OK; +} + +void nsRenderingContextQt::ConditionRect(nscoord &x,nscoord &y, + nscoord &w,nscoord &h) +{ + if (y < -32766) { + y = -32766; + } + if (y + h > 32766) { + h = 32766 - y; + } + if (x < -32766) { + x = -32766; + } + if (x + w > 32766) { + w = 32766 - x; + } +} + +NS_IMETHODIMP nsRenderingContextQt::DrawRect(const nsRect &aRect) +{ + return DrawRect(aRect.x,aRect.y,aRect.width,aRect.height); +} + +NS_IMETHODIMP nsRenderingContextQt::DrawRect(nscoord aX,nscoord aY, + nscoord aWidth,nscoord aHeight) +{ + if (nsnull == mTranMatrix || nsnull == mSurface + || nsnull == mSurface->GetGC() || nsnull == mSurface->GetPaintDevice()) + return NS_ERROR_FAILURE; + + nscoord x,y,w,h; + + x = aX; + y = aY; + w = aWidth; + h = aHeight; + mTranMatrix->TransformCoord(&x,&y,&w,&h); + + // After the transform, if the numbers are huge, chop them, because + // they're going to be converted from 32 bit to 16 bit. + // It's all way off the screen anyway. + ConditionRect(x,y,w,h); + + if (w && h) { + UpdateGC(); + mSurface->GetGC()->drawRect(x,y,w,h); + } + return NS_OK; +} + +NS_IMETHODIMP nsRenderingContextQt::FillRect(const nsRect &aRect) +{ + return FillRect(aRect.x,aRect.y,aRect.width,aRect.height); +} + +NS_IMETHODIMP nsRenderingContextQt::FillRect(nscoord aX,nscoord aY, + nscoord aWidth,nscoord aHeight) +{ + if (nsnull == mTranMatrix || nsnull == mSurface + || nsnull == mSurface->GetGC() || nsnull == mSurface->GetPaintDevice()) + return NS_ERROR_FAILURE; + + nscoord x,y,w,h; + + x = aX; + y = aY; + w = aWidth; + h = aHeight; + mTranMatrix->TransformCoord(&x,&y,&w,&h); + + // After the transform, if the numbers are huge, chop them, because + // they're going to be converted from 32 bit to 16 bit. + // It's all way off the screen anyway. + ConditionRect(x,y,w,h); + UpdateGC(); + + QColor color(NS_GET_R(mCurrentColor), + NS_GET_G(mCurrentColor), + NS_GET_B(mCurrentColor)); + + mSurface->GetGC()->fillRect(x,y,w,h,color); + return NS_OK; +} + +NS_IMETHODIMP nsRenderingContextQt::InvertRect(const nsRect &aRect) +{ + return InvertRect(aRect.x,aRect.y,aRect.width,aRect.height); +} + +NS_IMETHODIMP nsRenderingContextQt::InvertRect(nscoord aX,nscoord aY, + nscoord aWidth,nscoord aHeight) +{ + if (nsnull == mTranMatrix || nsnull == mSurface + || nsnull == mSurface->GetGC() || nsnull == mSurface->GetPaintDevice()) + return NS_ERROR_FAILURE; + + nscoord x,y,w,h; + + x = aX; + y = aY; + w = aWidth; + h = aHeight; + mTranMatrix->TransformCoord(&x,&y,&w,&h); + + // After the transform, if the numbers are huge, chop them, because + // they're going to be converted from 32 bit to 16 bit. + // It's all way off the screen anyway. + ConditionRect(x,y,w,h); + + // Set XOR drawing mode + mFunction = Qt::XorROP; + UpdateGC(); + + // Fill the rect + QColor color(NS_GET_R(mCurrentColor), + NS_GET_G(mCurrentColor), + NS_GET_B(mCurrentColor)); + + mSurface->GetGC()->fillRect(x,y,w,h,color); + + // Back to normal copy drawing mode + mFunction = Qt::CopyROP; + return NS_OK; +} + +NS_IMETHODIMP nsRenderingContextQt::DrawPolygon(const nsPoint aPoints[], + PRInt32 aNumPoints) +{ + if (nsnull == mTranMatrix || nsnull == mSurface + || nsnull == mSurface->GetGC() || nsnull == mSurface->GetPaintDevice()) + return NS_ERROR_FAILURE; + + QPointArray pts(aNumPoints); + for (PRInt32 i = 0; i < aNumPoints; i++) { + nsPoint p = aPoints[i]; + + mTranMatrix->TransformCoord(&p.x,&p.y); + pts.setPoint(i,p.x,p.y); + } + UpdateGC(); + + mSurface->GetGC()->drawPolyline(pts); + + return NS_OK; +} + +NS_IMETHODIMP nsRenderingContextQt::FillPolygon(const nsPoint aPoints[], + PRInt32 aNumPoints) +{ + if (nsnull == mTranMatrix || nsnull == mSurface + || nsnull == mSurface->GetGC() || nsnull == mSurface->GetPaintDevice()) + return NS_ERROR_FAILURE; + + QPointArray pts(aNumPoints); + for (PRInt32 i = 0; i < aNumPoints; i++) { + nsPoint p = aPoints[i]; + + mTranMatrix->TransformCoord(&p.x,&p.y); + pts.setPoint(i,p.x,p.y); + } + UpdateGC(); + + mSurface->GetGC()->drawPolygon(pts); + + return NS_OK; +} + +NS_IMETHODIMP nsRenderingContextQt::DrawEllipse(const nsRect &aRect) +{ + return DrawEllipse(aRect.x,aRect.y,aRect.width,aRect.height); +} + +NS_IMETHODIMP nsRenderingContextQt::DrawEllipse(nscoord aX,nscoord aY, + nscoord aWidth,nscoord aHeight) +{ + if (nsnull == mTranMatrix || nsnull == mSurface + || nsnull == mSurface->GetGC() || nsnull == mSurface->GetPaintDevice()) + return NS_ERROR_FAILURE; + + nscoord x,y,w,h; + + x = aX; + y = aY; + w = aWidth; + h = aHeight; + mTranMatrix->TransformCoord(&x,&y,&w,&h); + UpdateGC(); + + mSurface->GetGC()->drawEllipse(x,y,w,h); + return NS_OK; +} + +NS_IMETHODIMP nsRenderingContextQt::FillEllipse(const nsRect &aRect) +{ + return FillEllipse(aRect.x,aRect.y,aRect.width,aRect.height); +} + +NS_IMETHODIMP nsRenderingContextQt::FillEllipse(nscoord aX,nscoord aY, + nscoord aWidth,nscoord aHeight) +{ + if (nsnull == mTranMatrix || nsnull == mSurface + || nsnull == mSurface->GetGC() || nsnull == mSurface->GetPaintDevice()) + return NS_ERROR_FAILURE; + + nscoord x,y,w,h; + + x = aX; + y = aY; + w = aWidth; + h = aHeight; + mTranMatrix->TransformCoord(&x,&y,&w,&h); + UpdateGC(); + + mSurface->GetGC()->drawChord(x,y,w,h,0,16 * 360); + return NS_OK; +} + +NS_IMETHODIMP nsRenderingContextQt::DrawArc(const nsRect &aRect, + float aStartAngle,float aEndAngle) +{ + return DrawArc(aRect.x,aRect.y,aRect.width,aRect.height, + aStartAngle,aEndAngle); +} + +NS_IMETHODIMP nsRenderingContextQt::DrawArc(nscoord aX,nscoord aY, + nscoord aWidth,nscoord aHeight, + float aStartAngle,float aEndAngle) +{ + if (nsnull == mTranMatrix || nsnull == mSurface + || nsnull == mSurface->GetGC() || nsnull == mSurface->GetPaintDevice()) + return NS_ERROR_FAILURE; + + nscoord x,y,w,h; + + x = aX; + y = aY; + w = aWidth; + h = aHeight; + mTranMatrix->TransformCoord(&x,&y,&w,&h); + UpdateGC(); + + mSurface->GetGC()->drawArc(x,y,w,h,NSToIntRound(aStartAngle * 16.0f), + NSToIntRound(aEndAngle * 16.0f)); + return NS_OK; +} + +NS_IMETHODIMP nsRenderingContextQt::FillArc(const nsRect &aRect, + float aStartAngle,float aEndAngle) +{ + return FillArc(aRect.x,aRect.y,aRect.width,aRect.height, + aStartAngle,aEndAngle); +} + +NS_IMETHODIMP nsRenderingContextQt::FillArc(nscoord aX,nscoord aY, + nscoord aWidth,nscoord aHeight, + float aStartAngle,float aEndAngle) +{ + if (nsnull == mTranMatrix || nsnull == mSurface + || nsnull == mSurface->GetGC() || nsnull == mSurface->GetPaintDevice()) + return NS_ERROR_FAILURE; + + nscoord x,y,w,h; + + x = aX; + y = aY; + w = aWidth; + h = aHeight; + mTranMatrix->TransformCoord(&x,&y,&w,&h); + UpdateGC(); + + mSurface->GetGC()->drawPie(x,y,w,h,NSToIntRound(aStartAngle * 16.0f), + NSToIntRound(aEndAngle * 16.0f)); + return NS_OK; +} + +NS_IMETHODIMP nsRenderingContextQt::GetWidth(char aC, nscoord &aWidth) +{ + if (!mFontMetrics) + return NS_ERROR_FAILURE; + if (aC == ' ') { + aWidth = mCurrentFont->mSpaceWidth; + } else { + QFontMetrics fm(mCurrentFont->font); + aWidth = NSToCoordRound(fm.width(aC) * mP2T); + } + return NS_OK; +} + +NS_IMETHODIMP nsRenderingContextQt::GetWidth(PRUnichar aC,nscoord &aWidth, + PRInt32 *aFontID) +{ + if (!mFontMetrics) + return NS_ERROR_FAILURE; + if (aC == ' ') { + aWidth = mCurrentFont->mSpaceWidth; + } else { + QFontMetrics fm(mCurrentFont->font); + aWidth = NSToCoordRound(fm.width(QChar(aC)) * mP2T); + } + return NS_OK; +} + +NS_IMETHODIMP nsRenderingContextQt::GetWidth(const nsString &aString, nscoord &aWidth,PRInt32 *aFontID) +{ + return GetWidth(aString.get(), aString.Length(), aWidth, aFontID); +} + +NS_IMETHODIMP nsRenderingContextQt::GetWidth(const char *aString, nscoord &aWidth) +{ + return GetWidth(aString,strlen(aString),aWidth); +} + +NS_IMETHODIMP nsRenderingContextQt::GetWidth(const char *aString, PRUint32 aLength,nscoord &aWidth) +{ + if (0 == aLength) { + aWidth = 0; + return NS_OK; + } + if (nsnull == aString || nsnull == mCurrentFont) + return NS_ERROR_FAILURE; + + QFontMetrics curFontMetrics(mCurrentFont->font); + int rawWidth = curFontMetrics.width(QString::fromLatin1(aString, aLength)); + aWidth = NSToCoordRound(rawWidth * mP2T); + return NS_OK; +} + +NS_IMETHODIMP nsRenderingContextQt::GetWidth(const PRUnichar *aString, + PRUint32 aLength,nscoord &aWidth, + PRInt32 *aFontID) +{ + if (aFontID) + *aFontID = 0; + if (0 == aLength) { + aWidth = 0; + return NS_OK; + } + if (!aString || !mFontMetrics) + return NS_ERROR_FAILURE; + + QConstString cstr((const QChar *)aString, aLength); + QFontMetrics curFontMetrics(mCurrentFont->font); + int rawWidth = curFontMetrics.width(cstr.string()); + aWidth = NSToCoordRound(rawWidth * mP2T); + return NS_OK; +} + +NS_IMETHODIMP +nsRenderingContextQt::GetTextDimensions(const char* aString, PRUint32 aLength, + nsTextDimensions& aDimensions) +{ + aDimensions.Clear(); + if (aLength == 0) + return NS_OK; + if (nsnull == aString) + return NS_ERROR_FAILURE; + + QString str = QString::fromLatin1(aString, aLength); + QFontMetrics fm(mCurrentFont->font); + aDimensions.ascent = NSToCoordRound(fm.ascent()*mP2T); + aDimensions.descent = NSToCoordRound(fm.descent()*mP2T); + aDimensions.width = NSToCoordRound(fm.width(str)*mP2T); + return NS_OK; +} + +NS_IMETHODIMP +nsRenderingContextQt::GetTextDimensions(const PRUnichar *aString, + PRUint32 aLength, + nsTextDimensions &aDimensions, + PRInt32 *aFontID) +{ + aDimensions.Clear(); + if (0 == aLength) + return NS_OK; + if (nsnull == aString) + return NS_ERROR_FAILURE; + + QConstString str((const QChar *)aString, aLength); + QFontMetrics fm(mCurrentFont->font); + aDimensions.ascent = NSToCoordRound(fm.ascent()*mP2T); + aDimensions.descent = NSToCoordRound(fm.descent()*mP2T); + aDimensions.width = NSToCoordRound(fm.width(str.string())*mP2T); + + if (nsnull != aFontID) + *aFontID = 0; + + return NS_OK; +} + +NS_IMETHODIMP +nsRenderingContextQt::GetTextDimensions(const char* aString, + PRInt32 aLength, + PRInt32 aAvailWidth, + PRInt32* aBreaks, + PRInt32 aNumBreaks, + nsTextDimensions& aDimensions, + PRInt32& aNumCharsFit, + nsTextDimensions& aLastWordDimensions, + PRInt32* aFontID) +{ + NS_NOTREACHED("nsRenderingContextQt::GetTextDimensions not implemented\n"); + return NS_ERROR_NOT_IMPLEMENTED; +} +NS_IMETHODIMP +nsRenderingContextQt::GetTextDimensions(const PRUnichar* aString, + PRInt32 aLength, + PRInt32 aAvailWidth, + PRInt32* aBreaks, + PRInt32 aNumBreaks, + nsTextDimensions& aDimensions, + PRInt32& aNumCharsFit, + nsTextDimensions& aLastWordDimensions, + PRInt32* aFontID) +{ + NS_NOTREACHED("nsRenderingContextQt::GetTextDimensions not implemented\n"); + return NS_ERROR_NOT_IMPLEMENTED; +} + + +NS_IMETHODIMP nsRenderingContextQt::DrawString(const char *aString, + PRUint32 aLength, + nscoord aX, nscoord aY, + const nscoord *aSpacing) +{ + if (0 == aLength) + return NS_OK; + + if (!mCurrentFont || nsnull == mTranMatrix || nsnull == mSurface + || nsnull == mSurface->GetGC() || nsnull == mSurface->GetPaintDevice() + || nsnull == aString) + return NS_ERROR_FAILURE; + + nscoord x = aX; + nscoord y = aY; + + UpdateGC(); + + QString str = QString::fromLatin1(aString, aLength); + + if (nsnull != aSpacing) { + // Render the string, one character at a time... + for (uint i = 0; i < aLength; ++i) { + nscoord xx = x; + nscoord yy = y; + mTranMatrix->TransformCoord(&xx,&yy); + mSurface->GetGC()->drawText(xx, yy, str, i, 1); + x += *aSpacing++; + } + } else { + mTranMatrix->TransformCoord(&x,&y); + mSurface->GetGC()->drawText(x, y, str, aLength, QPainter::LTR); + } + return NS_OK; +} + +NS_IMETHODIMP nsRenderingContextQt::DrawString(const PRUnichar *aString, + PRUint32 aLength, + nscoord aX,nscoord aY, + PRInt32 aFontID, + const nscoord *aSpacing) +{ + if (!aLength) + return NS_OK; + + if (!mCurrentFont || nsnull == mTranMatrix || nsnull == mSurface + || nsnull == mSurface->GetGC() + || nsnull == mSurface->GetPaintDevice() || nsnull == aString) + return NS_ERROR_FAILURE; + + nscoord x = aX; + nscoord y = aY; + + UpdateGC(); + QConstString str((const QChar *)aString, aLength); + + if (nsnull != aSpacing) { + // Render the string, one character at a time... + for (uint i = 0; i < aLength; ++i) { + nscoord xx = x; + nscoord yy = y; + mTranMatrix->TransformCoord(&xx,&yy); + mSurface->GetGC()->drawText(xx, yy, str.string(), i, 1); + x += *aSpacing++; + } + } + else { + mTranMatrix->TransformCoord(&x,&y); + mSurface->GetGC()->drawText(x, y, str.string(), aLength, QPainter::LTR); + } + return NS_OK; +} + +NS_IMETHODIMP nsRenderingContextQt::DrawString(const nsString &aString, + nscoord aX,nscoord aY, + PRInt32 aFontID, + const nscoord *aSpacing) +{ + return DrawString(aString.get(), aString.Length(), aX, aY, aFontID, aSpacing); +} + +NS_IMETHODIMP +nsRenderingContextQt::CopyOffScreenBits(nsIDrawingSurface* aSrcSurf, + PRInt32 aSrcX, + PRInt32 aSrcY, + const nsRect &aDestBounds, + PRUint32 aCopyFlags) +{ + PRInt32 x = aSrcX; + PRInt32 y = aSrcY; + nsRect drect = aDestBounds; + nsDrawingSurfaceQt *destsurf; + + if (nsnull == aSrcSurf || nsnull == mTranMatrix || nsnull == mSurface + || nsnull == mSurface->GetPaintDevice() || nsnull == mSurface->GetGC()) + return NS_ERROR_FAILURE; + + if (aCopyFlags & NS_COPYBITS_TO_BACK_BUFFER) { + NS_ASSERTION(!(nsnull == mSurface), "no back buffer"); + destsurf = mSurface; + } + else + destsurf = mOffscreenSurface; + + if (aCopyFlags & NS_COPYBITS_XFORM_SOURCE_VALUES) + mTranMatrix->TransformCoord(&x,&y); + + if (aCopyFlags & NS_COPYBITS_XFORM_DEST_VALUES) + mTranMatrix->TransformCoord(&drect.x,&drect.y, + &drect.width,&drect.height); + QPixmap pm = *(QPixmap*)((nsDrawingSurfaceQt*)aSrcSurf)->GetPaintDevice(); + + QPainter *p = destsurf->GetGC(); + UpdateGC(); + +// qDebug("copy offscreen bits: aSrcX=%d, aSrcY=%d, w/h = %d/%d aCopyFlags=%d", +// aSrcX, aSrcY, pm.width(), pm.height(), aCopyFlags); + + //XXX flags are unused. that would seem to mean that there is + //inefficiency somewhere... MMP + + p->drawPixmap(drect.x,drect.y, pm, x, y, drect.width, drect.height); + return NS_OK; +} + +NS_IMETHODIMP +nsRenderingContextQt::RetrieveCurrentNativeGraphicData(PRUint32 *ngd) +{ + return NS_OK; +} + +#ifdef MOZ_MATHML +NS_IMETHODIMP +nsRenderingContextQt::GetBoundingMetrics(const char *aString,PRUint32 aLength, + nsBoundingMetrics &aBoundingMetrics) +{ + aBoundingMetrics.Clear(); + if (0 >= aLength || !aString || !mCurrentFont) + return(NS_ERROR_FAILURE); + + QString str = QString::fromLatin1(aString, aLength); + QFontMetrics fm(mCurrentFont->font); + QRect br = fm.boundingRect(str); + aBoundingMetrics.width = NSToCoordRound(br.width() * mP2T); + aBoundingMetrics.ascent = NSToCoordRound(-br.y() * mP2T); + aBoundingMetrics.descent = NSToCoordRound(br.bottom() * mP2T); + aBoundingMetrics.leftBearing = NSToCoordRound(br.x() * mP2T); + aBoundingMetrics.rightBearing = NSToCoordRound(fm.rightBearing(str.at(aLength - 1)) * mP2T); + return NS_OK; +} + +NS_IMETHODIMP +nsRenderingContextQt::GetBoundingMetrics(const PRUnichar *aString, + PRUint32 aLength, + nsBoundingMetrics &aBoundingMetrics, + PRInt32 *aFontID) +{ + aBoundingMetrics.Clear(); + if (0 >= aLength || !aString || !mCurrentFont) + return(NS_ERROR_FAILURE); + + QConstString str((const QChar *)aString, aLength); + QFontMetrics fm(mCurrentFont->font); + QRect br = fm.boundingRect(str.string()); + aBoundingMetrics.width = NSToCoordRound(br.width() * mP2T); + aBoundingMetrics.ascent = NSToCoordRound(-br.y() * mP2T); + aBoundingMetrics.descent = NSToCoordRound(br.bottom() * mP2T); + aBoundingMetrics.leftBearing = NSToCoordRound(br.x() * mP2T); + aBoundingMetrics.rightBearing = NSToCoordRound(fm.rightBearing(str.string().at(aLength - 1)) * mP2T); + return NS_OK; +} +#endif /* MOZ_MATHML */ diff --git a/mozilla/gfx/src/qt/nsRenderingContextQt.h b/mozilla/gfx/src/qt/nsRenderingContextQt.h new file mode 100644 index 00000000000..a3fd9d4a023 --- /dev/null +++ b/mozilla/gfx/src/qt/nsRenderingContextQt.h @@ -0,0 +1,254 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * John C. Griggs + * + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsRenderingContextQt_h___ +#define nsRenderingContextQt_h___ + +#include "nsRenderingContextImpl.h" +#include "nsUnitConversion.h" +#include "nsFont.h" +#include "nsIFontMetrics.h" +#include "nsPoint.h" +#include "nsString.h" +#include "nsCRT.h" +#include "nsTransform2D.h" +#include "nsIWidget.h" +#include "nsRect.h" +#include "nsIDeviceContext.h" +#include "nsVoidArray.h" +#include "nsCOMPtr.h" + +#include "nsRegionQt.h" +#include "nsDrawingSurfaceQt.h" +#include "prlog.h" + +class nsFontQt; +class nsDrawingSurface; + +class nsRenderingContextQt : public nsRenderingContextImpl +{ +public: + nsRenderingContextQt(); + virtual ~nsRenderingContextQt(); + + NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW + + NS_DECL_ISUPPORTS + + NS_IMETHOD Init(nsIDeviceContext* aContext, nsIWidget *aWindow); + NS_IMETHOD Init(nsIDeviceContext* aContext, nsIDrawingSurface* aSurface); + + NS_IMETHOD Reset(void); + + NS_IMETHOD GetDeviceContext(nsIDeviceContext *&aContext); + + NS_IMETHOD LockDrawingSurface(PRInt32 aX,PRInt32 aY,PRUint32 aWidth, + PRUint32 aHeight,void **aBits, + PRInt32 *aStride,PRInt32 *aWidthBytes, + PRUint32 aFlags); + NS_IMETHOD UnlockDrawingSurface(void); + + NS_IMETHOD SelectOffScreenDrawingSurface(nsIDrawingSurface* aSurface); + NS_IMETHOD GetDrawingSurface(nsIDrawingSurface* *aSurface); + NS_IMETHOD GetHints(PRUint32& aResult); + + NS_IMETHOD PushState(void); + NS_IMETHOD PopState(void); + + NS_IMETHOD IsVisibleRect(const nsRect& aRect, PRBool &aVisible); + + NS_IMETHOD SetClipRect(const nsRect& aRect, nsClipCombine aCombine); + NS_IMETHOD CopyClipRegion(nsIRegion &aRegion); + NS_IMETHOD GetClipRect(nsRect &aRect, PRBool &aClipValid); + NS_IMETHOD SetClipRegion(const nsIRegion& aRegion, nsClipCombine aCombine); + NS_IMETHOD GetClipRegion(nsIRegion **aRegion); + + NS_IMETHOD SetLineStyle(nsLineStyle aLineStyle); + NS_IMETHOD GetLineStyle(nsLineStyle &aLineStyle); + + NS_IMETHOD SetColor(nscolor aColor); + NS_IMETHOD GetColor(nscolor &aColor) const; + + NS_IMETHOD SetFont(const nsFont& aFont, nsIAtom* aLangGroup); + NS_IMETHOD SetFont(nsIFontMetrics *aFontMetrics); + + NS_IMETHOD GetFontMetrics(nsIFontMetrics *&aFontMetrics); + + NS_IMETHOD Translate(nscoord aX, nscoord aY); + NS_IMETHOD Scale(float aSx, float aSy); + NS_IMETHOD GetCurrentTransform(nsTransform2D *&aTransform); + + NS_IMETHOD CreateDrawingSurface(const nsRect& aBounds,PRUint32 aSurfFlags, + nsIDrawingSurface* &aSurface); + NS_IMETHOD DestroyDrawingSurface(nsIDrawingSurface* aDS); + + NS_IMETHOD DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1); + NS_IMETHOD DrawStdLine(nscoord aX0,nscoord aY0,nscoord aX1,nscoord aY1); + NS_IMETHOD DrawPolyline(const nsPoint aPoints[], PRInt32 aNumPoints); + + NS_IMETHOD DrawRect(const nsRect& aRect); + NS_IMETHOD DrawRect(nscoord aX,nscoord aY,nscoord aWidth,nscoord aHeight); + NS_IMETHOD FillRect(const nsRect& aRect); + NS_IMETHOD FillRect(nscoord aX,nscoord aY,nscoord aWidth,nscoord aHeight); + NS_IMETHOD InvertRect(const nsRect& aRect); + NS_IMETHOD InvertRect(nscoord aX,nscoord aY,nscoord aWidth,nscoord aHeight); + + NS_IMETHOD DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints); + NS_IMETHOD FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints); + + NS_IMETHOD DrawEllipse(const nsRect& aRect); + NS_IMETHOD DrawEllipse(nscoord aX,nscoord aY,nscoord aWidth, + nscoord aHeight); + NS_IMETHOD FillEllipse(const nsRect& aRect); + NS_IMETHOD FillEllipse(nscoord aX,nscoord aY,nscoord aWidth, + nscoord aHeight); + + NS_IMETHOD DrawArc(const nsRect& aRect,float aStartAngle,float aEndAngle); + NS_IMETHOD DrawArc(nscoord aX,nscoord aY,nscoord aWidth,nscoord aHeight, + float aStartAngle,float aEndAngle); + NS_IMETHOD FillArc(const nsRect& aRect,float aStartAngle,float aEndAngle); + NS_IMETHOD FillArc(nscoord aX,nscoord aY,nscoord aWidth,nscoord aHeight, + float aStartAngle,float aEndAngle); + + NS_IMETHOD GetWidth(char aC, nscoord &aWidth); + NS_IMETHOD GetWidth(PRUnichar aC, nscoord &aWidth, PRInt32 *aFontID); + NS_IMETHOD GetWidth(const nsString& aString,nscoord &aWidth, + PRInt32 *aFontID); + NS_IMETHOD GetWidth(const char *aString, nscoord &aWidth); + NS_IMETHOD GetWidth(const char *aString,PRUint32 aLength,nscoord &aWidth); + NS_IMETHOD GetWidth(const PRUnichar *aString,PRUint32 aLength, + nscoord &aWidth,PRInt32 *aFontID); + + NS_IMETHOD GetTextDimensions(const char* aString, + PRUint32 aLength, + nsTextDimensions& aDimensions); + + NS_IMETHOD GetTextDimensions(const PRUnichar *aString, + PRUint32 aLength, + nsTextDimensions& aDimensions, + PRInt32 *aFontID); + + NS_IMETHOD GetTextDimensions(const char* aString, + PRInt32 aLength, + PRInt32 aAvailWidth, + PRInt32* aBreaks, + PRInt32 aNumBreaks, + nsTextDimensions& aDimensions, + PRInt32& aNumCharsFit, + nsTextDimensions& aLastWordDimensions, + PRInt32* aFontID); + + NS_IMETHOD GetTextDimensions(const PRUnichar* aString, + PRInt32 aLength, + PRInt32 aAvailWidth, + PRInt32* aBreaks, + PRInt32 aNumBreaks, + nsTextDimensions& aDimensions, + PRInt32& aNumCharsFit, + nsTextDimensions& aLastWordDimensions, + PRInt32* aFontID); + +#ifdef MOZ_MATHML + /* Returns metrics (in app units) of an 8-bit character string */ + NS_IMETHOD GetBoundingMetrics(const char *aString,PRUint32 aLength, + nsBoundingMetrics& aBoundingMetrics); + + /* Returns metrics (in app units) of a Unicode character string */ + NS_IMETHOD GetBoundingMetrics(const PRUnichar *aString,PRUint32 aLength, + nsBoundingMetrics& aBoundingMetrics, + PRInt32 *aFontID = nsnull); +#endif /* MOZ_MATHML */ + + NS_IMETHOD DrawString(const char *aString,PRUint32 aLength, + nscoord aX,nscoord aY,const nscoord* aSpacing); + NS_IMETHOD DrawString(const PRUnichar *aString,PRUint32 aLength, + nscoord aX,nscoord aY,PRInt32 aFontID, + const nscoord* aSpacing); + NS_IMETHOD DrawString(const nsString& aString,nscoord aX,nscoord aY, + PRInt32 aFontID,const nscoord* aSpacing); + + NS_IMETHOD CopyOffScreenBits(nsIDrawingSurface* aSrcSurf, + PRInt32 aSrcX, PRInt32 aSrcY, + const nsRect &aDestBounds, + PRUint32 aCopyFlags); + + NS_IMETHOD RetrieveCurrentNativeGraphicData(PRUint32 *ngd); + + //locals + NS_IMETHOD CommonInit(); + void UpdateGC(); + void ConditionRect(nscoord &x, nscoord &y, nscoord &w, nscoord &h); + void CreateClipRegion(); + + QPainter *painter() const { return mSurface->GetGC(); } + QPaintDevice *paintDevice() const { return mSurface->GetPaintDevice(); } + nsTransform2D *matrix() const { return mTranMatrix; } + + QRect qRect(const nsRect &aRect) { + int x = aRect.x; + int y = aRect.y; + int w = aRect.width; + int h = aRect.height; + mTranMatrix->TransformCoord(&x,&y,&w,&h); + return QRect (x, y, w, h); + } + +protected: + nsDrawingSurfaceQt *mOffscreenSurface; + nsDrawingSurfaceQt *mSurface; + nsIDeviceContext *mContext; + nsIFontMetrics *mFontMetrics; + nsCOMPtr mClipRegion; + float mP2T; + + // graphic state stack (GraphicsState) + nsVoidArray mStateCache; + + nscolor mCurrentColor; + nsLineStyle mCurrentLineStyle; + + nsFontQt *mCurrentFont; + Qt::PenStyle mQLineStyle; + Qt::RasterOp mFunction; + PRUint32 mID; +}; + +#endif /* nsRenderingContextQt_h___ */ diff --git a/mozilla/gfx/src/qt/nsScreenManagerQt.cpp b/mozilla/gfx/src/qt/nsScreenManagerQt.cpp new file mode 100644 index 00000000000..acd6d4e0038 --- /dev/null +++ b/mozilla/gfx/src/qt/nsScreenManagerQt.cpp @@ -0,0 +1,153 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 2000 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * John C. Griggs + * + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsScreenManagerQt.h" +#include "nsScreenQt.h" + +#include "qdesktopwidget.h" +#include "qapplication.h" +#include "qtlog.h" + +#ifdef DEBUG +PRUint32 gSMCount = 0; +PRUint32 gSMID = 0; +#endif + +nsScreenManagerQt::nsScreenManagerQt() +{ +#ifdef DEBUG + gSMCount++; + mID = gSMID++; + PR_LOG(gQtLogModule, QT_BASIC, + ("nsScreenManagerQt CTOR (%p) ID: %d, Count: %d\n", this, mID, gSMCount)); +#endif + + desktop = 0; +} + + +nsScreenManagerQt::~nsScreenManagerQt() +{ +#ifdef DEBUG + gSMCount--; + PR_LOG(gQtLogModule, QT_BASIC, + ("nsScreenManagerQt DTOR (%p) ID: %d, Count: %d\n", this, mID, gSMCount)); +#endif + // nothing to see here. +} + +// addref, release, QI +NS_IMPL_ISUPPORTS1(nsScreenManagerQt, nsIScreenManager) + +void nsScreenManagerQt::init() +{ + if (desktop) + return; + + desktop = QApplication::desktop(); + nScreens = desktop->numScreens(); + screens = new nsCOMPtr[nScreens]; + + for (int i = 0; i < nScreens; ++i) + screens[i] = new nsScreenQt(i); +} + +// +// ScreenForRect +// +// Returns the screen that contains the rectangle. If the rect overlaps +// multiple screens, it picks the screen with the greatest area of intersection. +// +// The coordinates are in pixels (not twips) and in screen coordinates. +// +NS_IMETHODIMP +nsScreenManagerQt::ScreenForRect(PRInt32 inLeft, PRInt32 inTop, + PRInt32 inWidth, PRInt32 inHeight, + nsIScreen **outScreen) +{ + if (!desktop) + init(); + + QRect r(inLeft, inTop, inWidth, inHeight); + int best = 0; + int area = 0; + for (int i = 0; i < nScreens; ++i) { + const QRect& rect = desktop->screenGeometry(i); + QRect intersection = r▭ + int a = intersection.width()*intersection.height(); + if (a > area) { + best = i; + area = a; + } + } + NS_IF_ADDREF(*outScreen = screens[best]); + return NS_OK; +} + +// +// GetPrimaryScreen +// +// The screen with the menubar/taskbar. This shouldn't be needed very +// often. +// +NS_IMETHODIMP +nsScreenManagerQt::GetPrimaryScreen(nsIScreen **aPrimaryScreen) +{ + if (!desktop) + init(); + + NS_IF_ADDREF(*aPrimaryScreen = screens[0]); + return NS_OK; +} + +// +// GetNumberOfScreens +// +// Returns how many physical screens are available. +// +NS_IMETHODIMP +nsScreenManagerQt::GetNumberOfScreens(PRUint32 *aNumberOfScreens) +{ + if (!desktop) + init(); + + *aNumberOfScreens = desktop->numScreens(); + return NS_OK; +} diff --git a/mozilla/gfx/src/qt/nsScreenManagerQt.h b/mozilla/gfx/src/qt/nsScreenManagerQt.h new file mode 100644 index 00000000000..af45eba23e4 --- /dev/null +++ b/mozilla/gfx/src/qt/nsScreenManagerQt.h @@ -0,0 +1,75 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 2000 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * John C. Griggs + * + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsScreenManagerQt_h___ +#define nsScreenManagerQt_h___ + +#include "nsIScreenManager.h" +#include "nsIScreen.h" +#include "nsCOMPtr.h" + +//------------------------------------------------------------------------ +class QDesktopWidget; + +class nsScreenManagerQt : public nsIScreenManager +{ +public: + nsScreenManagerQt ( ); + virtual ~nsScreenManagerQt(); + + NS_DECL_ISUPPORTS + NS_DECL_NSISCREENMANAGER + +private: + + void init (); + + nsCOMPtr *screens; + QDesktopWidget *desktop; + int nScreens; + +#ifdef DEBUG + PRUint32 mID; +#endif + +}; + +#endif // nsScreenManagerQt_h___ diff --git a/mozilla/gfx/src/qt/nsScreenQt.cpp b/mozilla/gfx/src/qt/nsScreenQt.cpp new file mode 100644 index 00000000000..81e3318167f --- /dev/null +++ b/mozilla/gfx/src/qt/nsScreenQt.cpp @@ -0,0 +1,120 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 2000 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * John C. Griggs + * + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsScreenQt.h" + +#include +#include + +#include "qtlog.h" + +#ifdef DEBUG +PRUint32 gScreenCount = 0; +PRUint32 gScreenID = 0; +#endif + +nsScreenQt::nsScreenQt(int aScreen) +{ + screen = aScreen; + +#ifdef DEBUG + gScreenCount++; + mID = gScreenID++; + PR_LOG(gQtLogModule, QT_BASIC, + ("nsScreenQt CTOR (%p) ID: %d, Count: %d\n", this, mID, gScreenCount)); +#endif + // nothing else to do. I guess we could cache a bunch of information + // here, but we want to ask the device at runtime in case anything + // has changed. +} + +nsScreenQt::~nsScreenQt() +{ +#ifdef DEBUG + gScreenCount--; + PR_LOG(gQtLogModule, QT_BASIC, + ("nsScreenQt DTOR (%p) ID: %d, Count: %d\n", this, mID, gScreenCount)); +#endif + // nothing to see here. +} + +// addref, release, QI +NS_IMPL_ISUPPORTS1(nsScreenQt, nsIScreen) + + NS_IMETHODIMP +nsScreenQt::GetRect(PRInt32 *outLeft,PRInt32 *outTop, + PRInt32 *outWidth,PRInt32 *outHeight) +{ + QRect r = QApplication::desktop()->screenGeometry(screen); + *outTop = r.x(); + *outLeft = r.y(); + *outWidth = r.width(); + *outHeight = r.height(); + + return NS_OK; +} + +NS_IMETHODIMP +nsScreenQt::GetAvailRect(PRInt32 *outLeft,PRInt32 *outTop, + PRInt32 *outWidth,PRInt32 *outHeight) +{ + QRect r = QApplication::desktop()->availableGeometry(screen); + *outTop = r.x(); + *outLeft = r.y(); + *outWidth = r.width(); + *outHeight = r.height(); + + return NS_OK; +} + +NS_IMETHODIMP +nsScreenQt::GetPixelDepth(PRInt32 *aPixelDepth) +{ + // ############# + *aPixelDepth = (PRInt32)QColor::numBitPlanes(); + return NS_OK; +} + +NS_IMETHODIMP +nsScreenQt::GetColorDepth(PRInt32 *aColorDepth) +{ + // ############### + return GetPixelDepth(aColorDepth); +} diff --git a/mozilla/gfx/src/qt/nsScreenQt.h b/mozilla/gfx/src/qt/nsScreenQt.h new file mode 100644 index 00000000000..b7c292bc2a2 --- /dev/null +++ b/mozilla/gfx/src/qt/nsScreenQt.h @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 2000 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * John C. Griggs + * + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsScreenQt_h___ +#define nsScreenQt_h___ + +#include "nsIScreen.h" + +//------------------------------------------------------------------------ + +class nsScreenQt : public nsIScreen +{ +public: + nsScreenQt (int aScreen); + virtual ~nsScreenQt(); + + NS_DECL_ISUPPORTS + NS_DECL_NSISCREEN + +private: + int screen; +#ifdef DEBUG + PRUint32 mID; +#endif + +}; + +#endif // nsScreenQt_h___ diff --git a/mozilla/gfx/src/qt/qtlog.h b/mozilla/gfx/src/qt/qtlog.h new file mode 100644 index 00000000000..fb1bedafb7c --- /dev/null +++ b/mozilla/gfx/src/qt/qtlog.h @@ -0,0 +1,49 @@ +/* ***** 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 Qt Port logging code. + * + * The Initial Developer of the Original Code is + * Christian Biesinger . + * Portions created by the Initial Developer are Copyright (C) 2002 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * 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 QT_LOG_H__ +#define QT_LOG_H__ + +#define FORCE_PR_LOG +#include "prlog.h" + +extern PRLogModuleInfo *gQtLogModule; + +const int QT_BASIC = 3; +const int QT_FONTS = 4; +const int QT_EXTRA_FONTS = 5; + +#endif diff --git a/mozilla/gfx/src/shared/Makefile.in b/mozilla/gfx/src/shared/Makefile.in index f23dcac1f9f..973c0e0c5ae 100644 --- a/mozilla/gfx/src/shared/Makefile.in +++ b/mozilla/gfx/src/shared/Makefile.in @@ -64,8 +64,7 @@ CPPSRCS = \ gfxImageFrame.cpp \ $(NULL) - -ifneq (,$(filter gtk gtk2 windows mac cocoa,$(MOZ_WIDGET_TOOLKIT))) +ifneq (,$(filter gtk gtk2 qt windows mac cocoa,$(MOZ_WIDGET_TOOLKIT))) CPPSRCS += nsNativeTheme.cpp endif diff --git a/mozilla/modules/plugin/base/src/Makefile.in b/mozilla/modules/plugin/base/src/Makefile.in index f9ae66f74fc..3c05dec3036 100644 --- a/mozilla/modules/plugin/base/src/Makefile.in +++ b/mozilla/modules/plugin/base/src/Makefile.in @@ -178,3 +178,9 @@ CXXFLAGS += $(MOZ_XLIB_CFLAGS) CFLAGS += $(MOZ_XLIB_CFLAGS) endif #MOZ_ENABLE_XLIB +ifdef MOZ_ENABLE_QT +EXTRA_DSO_LDOPTS += $(MOZ_QT_LDFLAGS) +CXXFLAGS += $(MOZ_QT_CFLAGS) +CFLAGS += $(MOZ_QT_CFLAGS) +endif #MOZ_ENABLE_QT + diff --git a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp index 163dd36178f..e2fade47c9d 100644 --- a/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp +++ b/mozilla/modules/plugin/base/src/nsPluginHostImpl.cpp @@ -41,6 +41,7 @@ #include "nscore.h" #include "nsPluginHostImpl.h" + #include #include "prio.h" #include "prmem.h" @@ -54,8 +55,8 @@ #include "nsIJVMManager.h" #endif #include "nsIPluginStreamListener.h" -#include "nsIHTTPHeaderListener.h" -#include "nsIHttpHeaderVisitor.h" +#include "nsIHTTPHeaderListener.h" +#include "nsIHttpHeaderVisitor.h" #include "nsIObserverService.h" #include "nsIHttpProtocolHandler.h" #include "nsIHttpChannel.h" @@ -91,6 +92,12 @@ #undef None #endif +#ifdef CursorShape +#undef CursorShape /*X.h defines it as 0, + qnamespace.h makes an enum type by that name + */ +#endif + //#include "nsIRegistry.h" #include "nsEnumeratorUtils.h" #include "nsXPCOM.h" @@ -166,6 +173,8 @@ #ifdef XP_UNIX #if defined(MOZ_WIDGET_GTK) || defined (MOZ_WIDGET_GTK2) #include // for GDK_DISPLAY() +#elif defined(MOZ_WIDGET_QT) +#include // for qt_xdisplay() #elif defined(MOZ_WIDGET_XLIB) #include "xlibrgb.h" // for xlib_rgb_get_display() #endif @@ -179,7 +188,7 @@ #ifdef XP_OS2 #include "nsILegacyPluginWrapperOS2.h" -#endif +#endif // this is the name of the directory which will be created // to cache temporary files. @@ -193,15 +202,15 @@ // 0.05 added new entry point check for the default plugin, bug 132430 // 0.06 strip off suffixes in mime description strings, bug 53895 // 0.07 changed nsIRegistry to flat file support for caching plugins info -// 0.08 mime entry point on MachO, bug 137535 +// 0.08 mime entry point on MachO, bug 137535 static const char *kPluginRegistryVersion = "0.08"; //////////////////////////////////////////////////////////////////////// // CID's && IID's static NS_DEFINE_IID(kIPluginInstanceIID, NS_IPLUGININSTANCE_IID); -static NS_DEFINE_IID(kIPluginInstancePeerIID, NS_IPLUGININSTANCEPEER_IID); +static NS_DEFINE_IID(kIPluginInstancePeerIID, NS_IPLUGININSTANCEPEER_IID); static NS_DEFINE_IID(kIPluginStreamInfoIID, NS_IPLUGINSTREAMINFO_IID); static NS_DEFINE_CID(kPluginCID, NS_PLUGIN_CID); -static NS_DEFINE_IID(kIPluginTagInfo2IID, NS_IPLUGINTAGINFO2_IID); +static NS_DEFINE_IID(kIPluginTagInfo2IID, NS_IPLUGINTAGINFO2_IID); static NS_DEFINE_CID(kProtocolProxyServiceCID, NS_PROTOCOLPROXYSERVICE_CID); static NS_DEFINE_CID(kCookieServiceCID, NS_COOKIESERVICE_CID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); @@ -270,7 +279,7 @@ PRBool ReadSectionHeader(nsPluginManifestLineReader& reader, const char *token) if (*p != ']') break; *p = 0; - + char* values[1]; if (1 != reader.ParseLine(values, 1)) break; @@ -286,7 +295,7 @@ PRBool ReadSectionHeader(nsPluginManifestLineReader& reader, const char *token) //////////////////////////////////////////////////////////////////////// // Little helper struct to asynchronously reframe any presentations (embedded) -// or reload any documents (full-page), that contained plugins +// or reload any documents (full-page), that contained plugins // which were shutdown as a result of a plugins.refresh(1) struct nsPluginDocReframeEvent: public PLEvent { nsPluginDocReframeEvent (nsISupportsArray* aDocs) { mDocs = aDocs; } @@ -294,19 +303,19 @@ struct nsPluginDocReframeEvent: public PLEvent { nsCOMPtr mDocs; }; -nsresult nsPluginDocReframeEvent::HandlePluginDocReframeEvent() { +nsresult nsPluginDocReframeEvent::HandlePluginDocReframeEvent() { NS_ENSURE_TRUE(mDocs, NS_ERROR_FAILURE); - + PRUint32 c; mDocs->Count(&c); - + // for each document (which previously had a running instance), tell // the frame constructor to rebuild for (PRUint32 i = 0; i < c; i++) { nsCOMPtr doc (do_QueryElementAt(mDocs, i)); if (doc) { nsIPresShell *shell = doc->GetShellAt(0); - + // if this document has a presentation shell, then it has frames and can be reframed if (shell) { /** @@ -321,7 +330,7 @@ nsresult nsPluginDocReframeEvent::HandlePluginDocReframeEvent() { shell->ReconstructFrames(); // causes reframe of document } else { // no pres shell --> full-page plugin - + NS_NOTREACHED("all plugins should have a pres shell!"); } @@ -332,7 +341,7 @@ nsresult nsPluginDocReframeEvent::HandlePluginDocReframeEvent() { } - + //---------------------------------------------------------------------- static void* PR_CALLBACK HandlePluginDocReframePLEvent(PLEvent* aEvent) @@ -349,7 +358,7 @@ static void PR_CALLBACK DestroyPluginDocReframePLEvent(PLEvent* aEvent) //////////////////////////////////////////////////////////////////////// nsActivePlugin::nsActivePlugin(nsPluginTag* aPluginTag, - nsIPluginInstance* aInstance, + nsIPluginInstance* aInstance, const char * url, PRBool aDefaultPlugin, nsIPluginInstancePeer* peer) @@ -390,11 +399,11 @@ nsActivePlugin::~nsActivePlugin() } // now check for cached plugins because they haven't had nsIPluginInstance::Destroy() - // called yet. For non-cached plugins, nsIPluginInstance::Destroy() is called + // called yet. For non-cached plugins, nsIPluginInstance::Destroy() is called // in either nsObjectFrame::Destroy() or nsActivePluginList::stopRunning() - PRBool doCache = PR_TRUE; + PRBool doCache = PR_TRUE; mInstance->GetValue(nsPluginInstanceVariable_DoCacheBool, (void *) &doCache); - if (doCache) + if (doCache) mInstance->Destroy(); NS_RELEASE(mInstance); @@ -516,9 +525,9 @@ PRBool nsActivePluginList::remove(nsActivePlugin * plugin) { // cache some things as we are going to destroy it right now nsPluginTag *pluginTag = p->mPluginTag; - + delete p; // plugin instance is destroyed here - + if(pluginTag) pluginTag->TryUnloadPlugin(); else @@ -554,7 +563,7 @@ void nsActivePluginList::stopRunning(nsISupportsArray* aReloadDocs) { // then determine if the plugin wants Destroy to be called after // Set Window. This is for bug 50547. - p->mInstance->GetValue(nsPluginInstanceVariable_CallSetWindowAfterDestroyBool, + p->mInstance->GetValue(nsPluginInstanceVariable_CallSetWindowAfterDestroyBool, (void *) &doCallSetWindowAfterDestroy); if (doCallSetWindowAfterDestroy) { p->mInstance->Stop(); @@ -570,7 +579,7 @@ void nsActivePluginList::stopRunning(nsISupportsArray* aReloadDocs) p->setStopped(PR_TRUE); // If we've been passed an array to return, lets collect all our documents, - // removing duplicates. These will be reframed (embedded) or reloaded (full-page) later + // removing duplicates. These will be reframed (embedded) or reloaded (full-page) later // to kickstart our instances. if (aReloadDocs && p->mPeer) { nsCOMPtr peer(do_QueryInterface(p->mPeer)); @@ -777,14 +786,14 @@ nsPluginTag::nsPluginTag(nsPluginTag* aPluginTag) mMimeTypeArray[i] = new_str(aPluginTag->mMimeTypeArray[i]); } - if(aPluginTag->mMimeDescriptionArray != nsnull) + if(aPluginTag->mMimeDescriptionArray != nsnull) { mMimeDescriptionArray = new char*[mVariants]; for (int i = 0; i < mVariants; i++) mMimeDescriptionArray[i] = new_str(aPluginTag->mMimeDescriptionArray[i]); } - if(aPluginTag->mExtensionsArray != nsnull) + if(aPluginTag->mExtensionsArray != nsnull) { mExtensionsArray = new char*[mVariants]; for (int i = 0; i < mVariants; i++) @@ -821,13 +830,13 @@ nsPluginTag::nsPluginTag(nsPluginInfo* aPluginInfo) mMimeTypeArray[i] = new_str(aPluginInfo->fMimeTypeArray[i]); } - if(aPluginInfo->fMimeDescriptionArray != nsnull) + if(aPluginInfo->fMimeDescriptionArray != nsnull) { mMimeDescriptionArray = new char*[mVariants]; for (int i = 0; i < mVariants; i++) { - // we should cut off the list of suffixes which the mime + // we should cut off the list of suffixes which the mime // description string may have, see bug 53895 - // it is usually in form "some description (*.sf1, *.sf2)" + // it is usually in form "some description (*.sf1, *.sf2)" // so we can search for the opening round bracket char cur = '\0'; char pre = '\0'; @@ -840,7 +849,7 @@ nsPluginTag::nsPluginTag(nsPluginInfo* aPluginInfo) cur = *p; *p = '\0'; } - + } mMimeDescriptionArray[i] = new_str(aPluginInfo->fMimeDescriptionArray[i]); // restore the original string @@ -851,7 +860,7 @@ nsPluginTag::nsPluginTag(nsPluginInfo* aPluginInfo) } } - if(aPluginInfo->fExtensionArray != nsnull) + if(aPluginInfo->fExtensionArray != nsnull) { mExtensionsArray = new char*[mVariants]; for (int i = 0; i < mVariants; i++) @@ -983,11 +992,11 @@ void nsPluginTag::SetHost(nsPluginHostImpl * aHost) // helper struct for asynchronous handeling of plugin unloading struct nsPluginUnloadEvent: public PLEvent { nsPluginUnloadEvent (PRLibrary* aLibrary); - + void HandleEvent() { if (mLibrary) NS_TRY_SAFE_CALL_VOID(PR_UnloadLibrary(mLibrary), nsnull, nsnull); // put our unload call in a saftey wrapper - else + else NS_WARNING("missing library from nsPluginUnloadEvent"); } @@ -1013,7 +1022,7 @@ nsresult PostPluginUnloadEvent (PRLibrary* aLibrary) { nsCOMPtr eventService(do_GetService(kEventQueueServiceCID)); if (eventService) { - nsCOMPtr eventQueue; + nsCOMPtr eventQueue; eventService->GetThreadEventQueue(PR_GetCurrentThread(), getter_AddRefs(eventQueue)); if (eventQueue) { nsPluginUnloadEvent * ev = new nsPluginUnloadEvent(aLibrary); @@ -1021,7 +1030,7 @@ nsresult PostPluginUnloadEvent (PRLibrary* aLibrary) PL_InitEvent(ev, nsnull, (PLHandleEventProc) ::HandlePluginUnloadPLEvent, (PLDestroyEventProc) ::DestroyPluginUnloadPLEvent); if (NS_SUCCEEDED(eventQueue->PostEvent(ev))) - return NS_OK; + return NS_OK; else NS_WARNING("failed to post event onto queue"); } else NS_WARNING("not able to create plugin unload event"); @@ -1056,8 +1065,8 @@ void nsPluginTag::TryUnloadPlugin(PRBool aForceShutdown) if (mLibrary && mCanUnloadLibrary && !isXPCOM) { // NPAPI plugins can be unloaded now if they don't use XPConnect if (!mXPConnected) - // unload the plugin asynchronously by posting a PLEvent - PostPluginUnloadEvent(mLibrary); + // unload the plugin asynchronously by posting a PLEvent + PostPluginUnloadEvent(mLibrary); else { // add library to the unused library list to handle it later if (mPluginHost) @@ -1065,9 +1074,9 @@ void nsPluginTag::TryUnloadPlugin(PRBool aForceShutdown) } } - // we should zero it anyway, it is going to be unloaded by - // CleanUnsedLibraries before we need to call the library - // again so the calling code should not be fooled and reload + // we should zero it anyway, it is going to be unloaded by + // CleanUnsedLibraries before we need to call the library + // again so the calling code should not be fooled and reload // the library fresh mLibrary = nsnull; } @@ -1099,7 +1108,7 @@ class nsPluginStreamInfo : public nsI4xPluginStreamInfo public: nsPluginStreamInfo(); virtual ~nsPluginStreamInfo(); - + NS_DECL_ISUPPORTS // nsIPluginStreamInfo interface @@ -1121,7 +1130,7 @@ public: NS_IMETHOD RequestRead(nsByteRange* rangeList); - + NS_IMETHOD GetStreamOffset(PRInt32 *result); @@ -1198,13 +1207,13 @@ public: NS_DECL_NSIHTTPHEADERVISITOR // Called by GetURL and PostURL (via NewStream) - nsresult Initialize(nsIURI *aURL, - nsIPluginInstance *aInstance, + nsresult Initialize(nsIURI *aURL, + nsIPluginInstance *aInstance, nsIPluginStreamListener *aListener, PRInt32 requestCount = 1); - nsresult InitializeEmbeded(nsIURI *aURL, - nsIPluginInstance* aInstance, + nsresult InitializeEmbeded(nsIURI *aURL, + nsIPluginInstance* aInstance, nsIPluginInstanceOwner *aOwner = nsnull, nsIPluginHost *aHost = nsnull); @@ -1367,7 +1376,7 @@ nsPluginStreamInfo::MakeByteRangeString(nsByteRange* aRangeList, nsACString &ran string.AppendInt(range->offset + range->length - 1); if(range->next) string += ","; - + requestCnt++; } @@ -1383,74 +1392,74 @@ nsPluginStreamInfo::MakeByteRangeString(nsByteRange* aRangeList, nsACString &ran //////////////////////////////////////////////////////////////////////// NS_IMETHODIMP nsPluginStreamInfo::RequestRead(nsByteRange* rangeList) -{ +{ nsCAutoString rangeString; PRInt32 numRequests; - + //first of all lets see if mPluginStreamListenerPeer is still alive nsCOMPtr suppWeakRef( do_QueryInterface((nsISupportsWeakReference *)(mPluginStreamListenerPeer))); if (!suppWeakRef) return NS_ERROR_FAILURE; - - nsCOMPtr pWeakRefPluginStreamListenerPeer = + + nsCOMPtr pWeakRefPluginStreamListenerPeer = do_GetWeakReference(suppWeakRef); if (!pWeakRefPluginStreamListenerPeer) return NS_ERROR_FAILURE; MakeByteRangeString(rangeList, rangeString, &numRequests); - + if(numRequests == 0) return NS_ERROR_FAILURE; - + nsresult rv = NS_OK; nsCOMPtr url; - + rv = NS_NewURI(getter_AddRefs(url), nsDependentCString(mURL)); - + nsCOMPtr callbacks = do_QueryReferent(mPluginStreamListenerPeer->mWeakPtrChannelCallbacks); nsCOMPtr loadGroup = do_QueryReferent(mPluginStreamListenerPeer->mWeakPtrChannelLoadGroup); nsCOMPtr channel; rv = NS_NewChannel(getter_AddRefs(channel), url, nsnull, loadGroup, callbacks); - if (NS_FAILED(rv)) + if (NS_FAILED(rv)) return rv; - + nsCOMPtr httpChannel(do_QueryInterface(channel)); if(!httpChannel) return NS_ERROR_FAILURE; - + httpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Range"), rangeString, PR_FALSE); - + mPluginStreamListenerPeer->mAbort = PR_TRUE; // instruct old stream listener to cancel // the request on the next ODA. nsCOMPtr converter; - + if (numRequests == 1) { converter = mPluginStreamListenerPeer; - + // set current stream offset equal to the first offset in the range list // it will work for single byte range request - // for multy range we'll reset it in ODA + // for multy range we'll reset it in ODA SetStreamOffset(rangeList->offset); } else { - nsPluginByteRangeStreamListener *brrListener = + nsPluginByteRangeStreamListener *brrListener = new nsPluginByteRangeStreamListener(pWeakRefPluginStreamListenerPeer); if (brrListener) converter = brrListener; else return NS_ERROR_OUT_OF_MEMORY; } - + mPluginStreamListenerPeer->mPendingRequests += numRequests; - + nsCOMPtr container = do_CreateInstance(NS_SUPPORTS_PRUINT32_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; rv = container->SetData(MAGIC_REQUEST_CONTEXT); if (NS_FAILED(rv)) return rv; - + return channel->AsyncOpen(converter, container); } @@ -1464,7 +1473,7 @@ nsPluginStreamInfo::GetStreamOffset(PRInt32 *result) //////////////////////////////////////////////////////////////////////// NS_IMETHODIMP nsPluginStreamInfo::SetStreamOffset(PRInt32 offset) -{ +{ mStreamOffset = offset; return NS_OK; } @@ -1472,7 +1481,7 @@ nsPluginStreamInfo::SetStreamOffset(PRInt32 offset) //////////////////////////////////////////////////////////////////////// void nsPluginStreamInfo::SetContentType(const nsMIMEType contentType) -{ +{ if(mContentType != nsnull) PL_strfree(mContentType); @@ -1507,7 +1516,7 @@ nsPluginStreamInfo::SetLastModified(const PRUint32 modified) //////////////////////////////////////////////////////////////////////// void nsPluginStreamInfo::SetURL(const char* url) -{ +{ if(mURL != nsnull) PL_strfree(mURL); @@ -1575,10 +1584,10 @@ nsPluginCacheListener::OnStartRequest(nsIRequest *request, nsISupports* ctxt) //////////////////////////////////////////////////////////////////////// -NS_IMETHODIMP -nsPluginCacheListener::OnDataAvailable(nsIRequest *request, nsISupports* ctxt, - nsIInputStream* aIStream, - PRUint32 sourceOffset, +NS_IMETHODIMP +nsPluginCacheListener::OnDataAvailable(nsIRequest *request, nsISupports* ctxt, + nsIInputStream* aIStream, + PRUint32 sourceOffset, PRUint32 aLength) { @@ -1600,9 +1609,9 @@ nsPluginCacheListener::OnDataAvailable(nsIRequest *request, nsISupports* ctxt, //////////////////////////////////////////////////////////////////////// -NS_IMETHODIMP -nsPluginCacheListener::OnStopRequest(nsIRequest *request, - nsISupports* aContext, +NS_IMETHODIMP +nsPluginCacheListener::OnStopRequest(nsIRequest *request, + nsISupports* aContext, nsresult aStatus) { return NS_OK; @@ -1652,7 +1661,7 @@ nsPluginStreamListenerPeer::~nsPluginStreamListenerPeer() mFileCacheOutputStream = nsnull; // if we have mLocalCachedFile lets release it - // and it'll be fiscally remove if refcnt == 1 + // and it'll be fiscally remove if refcnt == 1 if (mLocalCachedFile) { nsrefcnt refcnt; NS_RELEASE2(mLocalCachedFile, refcnt); @@ -1686,7 +1695,7 @@ NS_IMPL_ISUPPORTS4(nsPluginStreamListenerPeer, /* Called as a result of GetURL and PostURL */ //////////////////////////////////////////////////////////////////////// -nsresult nsPluginStreamListenerPeer::Initialize(nsIURI *aURL, +nsresult nsPluginStreamListenerPeer::Initialize(nsIURI *aURL, nsIPluginInstance *aInstance, nsIPluginStreamListener* aListener, PRInt32 requestCount) @@ -1706,7 +1715,7 @@ nsresult nsPluginStreamListenerPeer::Initialize(nsIURI *aURL, mInstance = aInstance; NS_ADDREF(mInstance); - + mPStreamListener = aListener; NS_ADDREF(mPStreamListener); @@ -1720,22 +1729,22 @@ nsresult nsPluginStreamListenerPeer::Initialize(nsIURI *aURL, mPendingRequests = requestCount; mDataForwardToRequest = new nsHashtable(16, PR_FALSE); - if (!mDataForwardToRequest) + if (!mDataForwardToRequest) return NS_ERROR_FAILURE; return NS_OK; } -/* - Called by NewEmbededPluginStream() - if this is called, we weren't - able to load the plugin, so we need to load it later once we figure - out the mimetype. In order to load it later, we need the plugin +/* + Called by NewEmbededPluginStream() - if this is called, we weren't + able to load the plugin, so we need to load it later once we figure + out the mimetype. In order to load it later, we need the plugin host and instance owner. */ //////////////////////////////////////////////////////////////////////// -nsresult nsPluginStreamListenerPeer::InitializeEmbeded(nsIURI *aURL, - nsIPluginInstance* aInstance, +nsresult nsPluginStreamListenerPeer::InitializeEmbeded(nsIURI *aURL, + nsIPluginInstance* aInstance, nsIPluginInstanceOwner *aOwner, nsIPluginHost *aHost) { @@ -1772,7 +1781,7 @@ nsresult nsPluginStreamListenerPeer::InitializeEmbeded(nsIURI *aURL, mPluginStreamInfo->SetPluginStreamListenerPeer(this); mDataForwardToRequest = new nsHashtable(16, PR_FALSE); - if (!mDataForwardToRequest) + if (!mDataForwardToRequest) return NS_ERROR_FAILURE; return NS_OK; @@ -1798,7 +1807,7 @@ nsresult nsPluginStreamListenerPeer::InitializeFullPage(nsIPluginInstance *aInst mPluginStreamInfo->SetPluginStreamListenerPeer(this); mDataForwardToRequest = new nsHashtable(16, PR_FALSE); - if (!mDataForwardToRequest) + if (!mDataForwardToRequest) return NS_ERROR_FAILURE; return NS_OK; @@ -1808,7 +1817,7 @@ nsresult nsPluginStreamListenerPeer::InitializeFullPage(nsIPluginInstance *aInst //////////////////////////////////////////////////////////////////////// // SetupPluginCacheFile is called if we have to save the stream to disk. // the most likely cause for this is either there is no disk cache available -// or the stream is coming from a https server. +// or the stream is coming from a https server. // // These files will be deleted when the host is destroyed. // @@ -1817,11 +1826,11 @@ nsresult nsPluginStreamListenerPeer::SetupPluginCacheFile(nsIChannel* channel) { nsresult rv = NS_OK; - // lets try to reused a file if we already have in the local plugin cache + // lets try to reused a file if we already have in the local plugin cache // we loop through all of active plugins - // and call |nsPluginStreamInfo::UseExistingPluginCacheFile()| on opened stream - // will return RP_TRUE if file exisrs - // and some conditions are matched, in this case that file will be use + // and call |nsPluginStreamInfo::UseExistingPluginCacheFile()| on opened stream + // will return RP_TRUE if file exisrs + // and some conditions are matched, in this case that file will be use // in |::OnFileAvailable()| calls w/o rewriting the file again. // The file will be deleted in |nsPluginStreamListenerPeer::~nsPluginStreamListenerPeer| PRBool useExistingCacheFile = PR_FALSE; @@ -1836,7 +1845,7 @@ nsPluginStreamListenerPeer::SetupPluginCacheFile(nsIChannel* channel) if (lp) { if (lp->mLocalCachedFile && lp->mPluginStreamInfo && - (useExistingCacheFile = + (useExistingCacheFile = lp->mPluginStreamInfo->UseExistingPluginCacheFile(mPluginStreamInfo))) { NS_ADDREF(mLocalCachedFile = lp->mLocalCachedFile); @@ -1846,39 +1855,39 @@ nsPluginStreamListenerPeer::SetupPluginCacheFile(nsIChannel* channel) } pActivePlugins = pActivePlugins->mNext; } - + if (!useExistingCacheFile) { nsCOMPtr pluginTmp; // Is this the best place to put this temp file? rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(pluginTmp)); if (NS_FAILED(rv)) return rv; - + rv = pluginTmp->AppendNative(kPluginTmpDirName); if (NS_FAILED(rv)) return rv; - + (void) pluginTmp->Create(nsIFile::DIRECTORY_TYPE,0777); - + // Get the filename from the channel nsCOMPtr uri; rv = channel->GetURI(getter_AddRefs(uri)); if (NS_FAILED(rv)) return rv; - + nsCOMPtr url(do_QueryInterface(uri)); if(!url) return NS_ERROR_FAILURE; - + nsCAutoString filename; url->GetFileName(filename); if (NS_FAILED(rv)) return rv; - + // Create a file to save our stream into. Should we scramble the name? rv = pluginTmp->AppendNative(filename); if (NS_FAILED(rv)) return rv; - + // Yes, make it unique. - rv = pluginTmp->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0600); + rv = pluginTmp->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0600); if (NS_FAILED(rv)) return rv; @@ -1887,14 +1896,14 @@ nsPluginStreamListenerPeer::SetupPluginCacheFile(nsIChannel* channel) rv = NS_NewLocalFileOutputStream(getter_AddRefs(mFileCacheOutputStream), pluginTmp, -1, 00600); if (NS_FAILED(rv)) return rv; - + // save the file. CallQueryInterface(pluginTmp, &mLocalCachedFile); // no need to check return value, just addref // add one extra refcnt, we can use NS_RELEASE2(mLocalCachedFile...) in dtor - // to remove this file when refcnt == 1 + // to remove this file when refcnt == 1 NS_ADDREF(mLocalCachedFile); } - + // add this listenerPeer to list of stream peers for this instance // it'll delay release of listenerPeer until nsActivePlugin::~nsActivePlugin // and the temp file is going to stay alive until then @@ -1908,7 +1917,7 @@ nsPluginStreamListenerPeer::SetupPluginCacheFile(nsIChannel* channel) nsISupports* supports = NS_STATIC_CAST(nsISupports*, (NS_STATIC_CAST(nsIStreamListener*, this))); pActivePlugins->mStreams->AppendElement(supports); } - + return rv; } @@ -1931,14 +1940,14 @@ nsPluginStreamListenerPeer::OnStartRequest(nsIRequest *request, nsISupports* aCo if (mOwner) { nsCOMPtr pti2 = do_QueryInterface(mOwner); NS_ENSURE_TRUE(pti2, NS_ERROR_FAILURE); - nsPluginTagType tagType; + nsPluginTagType tagType; if (NS_FAILED(pti2->GetTagType(&tagType))) return NS_ERROR_FAILURE; // something happened to our object frame, so bail! } nsCOMPtr channel = do_QueryInterface(request); NS_ENSURE_TRUE(channel, NS_ERROR_FAILURE); - + // deal with 404 (Not Found) HTTP response, // just return, this causes the request to be ignored. nsCOMPtr httpChannel(do_QueryInterface(channel)); @@ -1974,7 +1983,7 @@ nsPluginStreamListenerPeer::OnStartRequest(nsIRequest *request, nsISupports* aCo // it's possible for the server to not send a Content-Length. // we should still work in this case. if (NS_FAILED(rv) || length == -1) { - // check out if this is file channel + // check out if this is file channel nsCOMPtr fileChannel = do_QueryInterface(channel); if (fileChannel) { // file does not exist @@ -1991,12 +2000,12 @@ nsPluginStreamListenerPeer::OnStartRequest(nsIRequest *request, nsISupports* aCo nsCAutoString aContentType; rv = channel->GetContentType(aContentType); - if (NS_FAILED(rv)) + if (NS_FAILED(rv)) return rv; nsCOMPtr aURL; rv = channel->GetURI(getter_AddRefs(aURL)); - if (NS_FAILED(rv)) + if (NS_FAILED(rv)) return rv; nsCAutoString urlSpec; @@ -2019,7 +2028,7 @@ nsPluginStreamListenerPeer::OnStartRequest(nsIRequest *request, nsISupports* aCo // if we don't have an nsIPluginInstance (mInstance), it means // we weren't able to load a plugin previously because we // didn't have the mimetype. Now that we do (aContentType), - // we'll try again with SetUpPluginInstance() + // we'll try again with SetUpPluginInstance() // which is called by InstantiateEmbededPlugin() // NOTE: we don't want to try again if we didn't get the MIME type this time @@ -2071,9 +2080,9 @@ nsPluginStreamListenerPeer::OnStartRequest(nsIRequest *request, nsISupports* aCo //////////////////////////////////////////////////////////////////////// -NS_IMETHODIMP nsPluginStreamListenerPeer::OnProgress(nsIRequest *request, - nsISupports* aContext, - PRUint32 aProgress, +NS_IMETHODIMP nsPluginStreamListenerPeer::OnProgress(nsIRequest *request, + nsISupports* aContext, + PRUint32 aProgress, PRUint32 aProgressMax) { nsresult rv = NS_OK; @@ -2082,7 +2091,7 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnProgress(nsIRequest *request, //////////////////////////////////////////////////////////////////////// -NS_IMETHODIMP nsPluginStreamListenerPeer::OnStatus(nsIRequest *request, +NS_IMETHODIMP nsPluginStreamListenerPeer::OnStatus(nsIRequest *request, nsISupports* aContext, nsresult aStatus, const PRUnichar* aStatusArg) @@ -2113,10 +2122,10 @@ public: //////////////////////////////////////////////////////////////////////// -NS_IMETHODIMP nsPluginStreamListenerPeer::OnDataAvailable(nsIRequest *request, - nsISupports* aContext, - nsIInputStream *aIStream, - PRUint32 sourceOffset, +NS_IMETHODIMP nsPluginStreamListenerPeer::OnDataAvailable(nsIRequest *request, + nsISupports* aContext, + nsIInputStream *aIStream, + PRUint32 sourceOffset, PRUint32 aLength) { if (mRequestFailed) @@ -2128,7 +2137,7 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnDataAvailable(nsIRequest *request, nsCOMPtr container = do_QueryInterface(aContext); if (container) container->GetData(&magicNumber); - + if (magicNumber != MAGIC_REQUEST_CONTEXT) { // this is not one of our range requests @@ -2151,7 +2160,7 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnDataAvailable(nsIRequest *request, ("nsPluginStreamListenerPeer::OnDataAvailable this=%p request=%p, offset=%d, length=%d, url=%s\n", this, request, sourceOffset, aLength, url ? url : "no url set")); - // if the plugin has requested an AsFileOnly stream, then don't + // if the plugin has requested an AsFileOnly stream, then don't // call OnDataAvailable if(mStreamType != nsPluginStreamType_AsFileOnly) { @@ -2187,12 +2196,12 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnDataAvailable(nsIRequest *request, if (mFileCacheOutputStream) { rv = NS_NewInputStreamTee(getter_AddRefs(stream), aIStream, mFileCacheOutputStream); - if (NS_FAILED(rv)) + if (NS_FAILED(rv)) return rv; } - rv = mPStreamListener->OnDataAvailable(mPluginStreamInfo, - stream, + rv = mPStreamListener->OnDataAvailable(mPluginStreamInfo, + stream, aLength); // if a plugin returns an error, the peer must kill the stream @@ -2206,7 +2215,7 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnDataAvailable(nsIRequest *request, char* buffer = new char[aLength]; PRUint32 amountRead, amountWrote = 0; rv = aIStream->Read(buffer, aLength, &amountRead); - + // if we are caching this to disk ourselves, lets write the bytes out. if (mFileCacheOutputStream) { while (amountWrote < amountRead && NS_SUCCEEDED(rv)) { @@ -2220,7 +2229,7 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnDataAvailable(nsIRequest *request, //////////////////////////////////////////////////////////////////////// -NS_IMETHODIMP nsPluginStreamListenerPeer::OnStopRequest(nsIRequest *request, +NS_IMETHODIMP nsPluginStreamListenerPeer::OnStopRequest(nsIRequest *request, nsISupports* aContext, nsresult aStatus) { @@ -2229,18 +2238,18 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnStopRequest(nsIRequest *request, PLUGIN_LOG(PLUGIN_LOG_NOISY, ("nsPluginStreamListenerPeer::OnStopRequest this=%p aStatus=%d request=%p\n", this, aStatus, request)); - + // for ByteRangeRequest we're just updating the mDataForwardToRequest hash and return. nsCOMPtr brr = do_QueryInterface(request); if (brr) { PRInt32 absoluteOffset = 0; brr->GetStartRange(&absoluteOffset); - + nsPRUintKey key(absoluteOffset); - - // remove the request from our data forwarding count hash. + + // remove the request from our data forwarding count hash. (void) mDataForwardToRequest->Remove(&key); - + PLUGIN_LOG(PLUGIN_LOG_NOISY, (" ::OnStopRequest for ByteRangeRequest Started=%d\n", @@ -2255,7 +2264,7 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnStopRequest(nsIRequest *request, // if we still have pending stuff to do, lets not close the plugin socket. if (--mPendingRequests > 0) return NS_OK; - + // we keep our connections around... nsCOMPtr container = do_QueryInterface(aContext); if (container) { @@ -2266,17 +2275,17 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnStopRequest(nsIRequest *request, return NS_OK; } } - + if(!mPStreamListener) return NS_ERROR_FAILURE; - + nsCOMPtr channel = do_QueryInterface(request); - if (!channel) + if (!channel) return NS_ERROR_FAILURE; // Set the content type to ensure we don't pass null to the plugin nsCAutoString aContentType; rv = channel->GetContentType(aContentType); - if (NS_FAILED(rv)) + if (NS_FAILED(rv)) return rv; if (!aContentType.IsEmpty()) @@ -2287,7 +2296,7 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnStopRequest(nsIRequest *request, aStatus = NS_ERROR_FAILURE; if (NS_FAILED(aStatus)) { - // on error status cleanup the stream + // on error status cleanup the stream // and return w/o OnFileAvailable() mPStreamListener->OnStopBinding(mPluginStreamInfo, aStatus); return NS_OK; @@ -2308,7 +2317,7 @@ NS_IMETHODIMP nsPluginStreamListenerPeer::OnStopRequest(nsIRequest *request, } } } - + if (localFile) { OnFileAvailable(localFile); } @@ -2349,12 +2358,12 @@ nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIRequest *request, { nsresult rv = NS_OK; - // If we don't yet have a stream listener, we need to get + // If we don't yet have a stream listener, we need to get // one from the plugin. - // NOTE: this should only happen when a stream was NOT created - // with GetURL or PostURL (i.e. it's the initial stream we + // NOTE: this should only happen when a stream was NOT created + // with GetURL or PostURL (i.e. it's the initial stream we // send to the plugin as determined by the SRC or DATA attribute) - if(mPStreamListener == nsnull && mInstance != nsnull) + if(mPStreamListener == nsnull && mInstance != nsnull) rv = mInstance->NewStream(&mPStreamListener); if(rv != NS_OK) @@ -2362,7 +2371,7 @@ nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIRequest *request, if(mPStreamListener == nsnull) return NS_ERROR_NULL_POINTER; - + PRBool useLocalCache = PR_FALSE; // get httpChannel to retrieve some info we need for nsIPluginStreamInfo setup @@ -2376,7 +2385,7 @@ nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIRequest *request, */ if (httpChannel) { httpChannel->VisitResponseHeaders(this); - + // set seekability (seekable if the stream has a known length and if the // http server accepts byte ranges). PRBool bSeekable = PR_FALSE; @@ -2412,7 +2421,7 @@ nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIRequest *request, { PRTime time64; PR_ParseTimeString(lastModified.get(), PR_TRUE, &time64); //convert string time to interger time - + // Convert PRTime to unix-style time_t, i.e. seconds since the epoch double fpTime; LL_L2D(fpTime, time64); @@ -2427,7 +2436,7 @@ nsresult nsPluginStreamListenerPeer::SetUpStreamListener(nsIRequest *request, if (NS_FAILED(rv)) return rv; - + mPStreamListener->GetStreamType(&mStreamType); if (!useLocalCache && mStreamType >= nsPluginStreamType_AsFile) { @@ -2494,10 +2503,10 @@ nsPluginHostImpl::nsPluginHostImpl() mOverrideInternalTypes = PR_FALSE; mAllowAlienStarHandler = PR_FALSE; mUnusedLibraries.Clear(); - + gActivePluginList = &mActivePluginList; - // check to see if pref is set at startup to let plugins take over in + // check to see if pref is set at startup to let plugins take over in // full page mode for certain image mime types that we handle internally mPrefService = do_GetService(NS_PREFSERVICE_CONTRACTID); if (mPrefService) { @@ -2516,11 +2525,11 @@ nsPluginHostImpl::nsPluginHostImpl() nsPluginLogging::gNPNLog = PR_NewLogModule(NPN_LOG_NAME); nsPluginLogging::gNPPLog = PR_NewLogModule(NPP_LOG_NAME); nsPluginLogging::gPluginLog = PR_NewLogModule(PLUGIN_LOG_NAME); - + PR_LOG(nsPluginLogging::gNPNLog, PLUGIN_LOG_ALWAYS,("NPN Logging Active!\n")); PR_LOG(nsPluginLogging::gPluginLog, PLUGIN_LOG_ALWAYS,("General Plugin Logging Active! (nsPluginHostImpl::ctor)\n")); PR_LOG(nsPluginLogging::gNPPLog, PLUGIN_LOG_ALWAYS,("NPP Logging Active!\n")); - + PLUGIN_LOG(PLUGIN_LOG_ALWAYS,("nsPluginHostImpl::ctor\n")); PR_LogFlush(); #endif @@ -2580,6 +2589,8 @@ NS_IMETHODIMP nsPluginHostImpl::GetValue(nsPluginManagerVariable aVariable, void Display** value = NS_REINTERPRET_CAST(Display**, aValue); #if defined(MOZ_WIDGET_GTK) || defined (MOZ_WIDGET_GTK2) *value = GDK_DISPLAY(); +#elif defined(MOZ_WIDGET_QT) + *value = qt_xdisplay(); #elif defined(MOZ_WIDGET_XLIB) *value = xxlib_rgb_get_display(xxlib_find_handle(XXLIBRGB_DEFAULT_HANDLE)); #endif @@ -2647,12 +2658,12 @@ nsresult nsPluginHostImpl::ReloadPlugins(PRBool reloadPages) // if no changed detected, return an appropriate error code if (!pluginschanged) return NS_ERROR_PLUGINS_PLUGINSNOTCHANGED; - + nsCOMPtr instsToReload; if(reloadPages) { NS_NewISupportsArray(getter_AddRefs(instsToReload)); - + // Then stop any running plugin instances but hold on to the documents in the array // We are going to need to restart the instances in these documents later mActivePluginList.stopRunning(instsToReload); @@ -2698,13 +2709,13 @@ nsresult nsPluginHostImpl::ReloadPlugins(PRBool reloadPages) // Post an event to do the rest as we are going to be destroying the frame tree and we also want // any posted unload events to finish PRUint32 c; - if (reloadPages && - instsToReload && - NS_SUCCEEDED(instsToReload->Count(&c)) && + if (reloadPages && + instsToReload && + NS_SUCCEEDED(instsToReload->Count(&c)) && c > 0) { nsCOMPtr eventService(do_GetService(kEventQueueServiceCID)); if (eventService) { - nsCOMPtr eventQueue; + nsCOMPtr eventQueue; eventService->GetThreadEventQueue(PR_GetCurrentThread(), getter_AddRefs(eventQueue)); if (eventQueue) { nsPluginDocReframeEvent * ev = new nsPluginDocReframeEvent(instsToReload); @@ -2734,13 +2745,13 @@ nsresult nsPluginHostImpl::UserAgent(const char **retstring) nsresult res; nsCOMPtr http = do_GetService(kHttpHandlerCID, &res); - if (NS_FAILED(res)) + if (NS_FAILED(res)) return res; nsCAutoString uaString; res = http->GetUserAgent(uaString); - if (NS_SUCCEEDED(res)) + if (NS_SUCCEEDED(res)) { if(NS_RETURN_UASTRING_SIZE > uaString.Length()) { @@ -2752,7 +2763,7 @@ nsresult nsPluginHostImpl::UserAgent(const char **retstring) *retstring = nsnull; res = NS_ERROR_OUT_OF_MEMORY; } - } + } else *retstring = nsnull; @@ -2766,7 +2777,7 @@ nsresult nsPluginHostImpl:: GetPrompt(nsIPluginInstanceOwner *aOwner, nsIPrompt nsresult rv; nsCOMPtr prompt; nsCOMPtr wwatch = do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv); - + if (wwatch) { nsCOMPtr domWindow; if (aOwner) { @@ -2788,34 +2799,34 @@ nsresult nsPluginHostImpl:: GetPrompt(nsIPluginInstanceOwner *aOwner, nsIPrompt } //////////////////////////////////////////////////////////////////////// -NS_IMETHODIMP nsPluginHostImpl::GetURL(nsISupports* pluginInst, - const char* url, +NS_IMETHODIMP nsPluginHostImpl::GetURL(nsISupports* pluginInst, + const char* url, const char* target, nsIPluginStreamListener* streamListener, const char* altHost, const char* referrer, PRBool forceJSEnabled) { - return GetURLWithHeaders(pluginInst, url, target, streamListener, + return GetURLWithHeaders(pluginInst, url, target, streamListener, altHost, referrer, forceJSEnabled, nsnull, nsnull); } //////////////////////////////////////////////////////////////////////// -NS_IMETHODIMP nsPluginHostImpl::GetURLWithHeaders(nsISupports* pluginInst, - const char* url, +NS_IMETHODIMP nsPluginHostImpl::GetURLWithHeaders(nsISupports* pluginInst, + const char* url, const char* target, nsIPluginStreamListener* streamListener, const char* altHost, const char* referrer, PRBool forceJSEnabled, - PRUint32 getHeadersLength, + PRUint32 getHeadersLength, const char* getHeaders) { nsAutoString string; string.AssignWithConversion(url); nsresult rv; - // we can only send a stream back to the plugin (as specified by a + // we can only send a stream back to the plugin (as specified by a // null target) if we also have a nsIPluginStreamListener to talk to if(target == nsnull && streamListener == nsnull) return NS_ERROR_ILLEGAL_VALUE; @@ -2827,12 +2838,12 @@ NS_IMETHODIMP nsPluginHostImpl::GetURLWithHeaders(nsISupports* pluginInst, { // if this is a Java plugin calling, we need to do a security check nsCOMPtr javaInstance(do_QueryInterface(instance)); - + if (javaInstance) rv = DoURLLoadSecurityCheck(instance, url); } #endif - + if (NS_SUCCEEDED(rv)) { if (nsnull != target) @@ -2846,7 +2857,7 @@ NS_IMETHODIMP nsPluginHostImpl::GetURLWithHeaders(nsISupports* pluginInst, rv = privpeer->GetOwner(getter_AddRefs(owner)); if (owner) { - if ((0 == PL_strcmp(target, "newwindow")) || + if ((0 == PL_strcmp(target, "newwindow")) || (0 == PL_strcmp(target, "_new"))) target = "_blank"; else if (0 == PL_strcmp(target, "_current")) @@ -2858,7 +2869,7 @@ NS_IMETHODIMP nsPluginHostImpl::GetURLWithHeaders(nsISupports* pluginInst, } if (nsnull != streamListener) - rv = NewPluginURLStream(string, instance, streamListener, nsnull, + rv = NewPluginURLStream(string, instance, streamListener, nsnull, PR_FALSE, nsnull, getHeaders, getHeadersLength); } @@ -2869,26 +2880,26 @@ NS_IMETHODIMP nsPluginHostImpl::GetURLWithHeaders(nsISupports* pluginInst, //////////////////////////////////////////////////////////////////////// NS_IMETHODIMP nsPluginHostImpl::PostURL(nsISupports* pluginInst, const char* url, - PRUint32 postDataLen, + PRUint32 postDataLen, const char* postData, PRBool isFile, const char* target, nsIPluginStreamListener* streamListener, - const char* altHost, + const char* altHost, const char* referrer, PRBool forceJSEnabled, - PRUint32 postHeadersLength, + PRUint32 postHeadersLength, const char* postHeaders) { nsAutoString string; string.AssignWithConversion(url); nsresult rv; - - // we can only send a stream back to the plugin (as specified - // by a null target) if we also have a nsIPluginStreamListener + + // we can only send a stream back to the plugin (as specified + // by a null target) if we also have a nsIPluginStreamListener // to talk to also if(target == nsnull && streamListener == nsnull) return NS_ERROR_ILLEGAL_VALUE; - + nsCOMPtr instance = do_QueryInterface(pluginInst, &rv); #ifdef OJI @@ -2896,7 +2907,7 @@ NS_IMETHODIMP nsPluginHostImpl::PostURL(nsISupports* pluginInst, { // if this is a Java plugin calling, we need to do a security check nsCOMPtr javaInstance(do_QueryInterface(instance)); - + if (javaInstance) rv = DoURLLoadSecurityCheck(instance, url); } @@ -2912,21 +2923,21 @@ NS_IMETHODIMP nsPluginHostImpl::PostURL(nsISupports* pluginInst, } else { PRUint32 newDataToPostLen; ParsePostBufferToFixHeaders(postData, postDataLen, &dataToPost, &newDataToPostLen); - if (!dataToPost) + if (!dataToPost) return NS_ERROR_UNEXPECTED; - // we use nsIStringInputStream::adoptDataa() + // we use nsIStringInputStream::adoptDataa() // in NS_NewPluginPostDataStream to set the stream // all new data alloced in ParsePostBufferToFixHeaders() - // well be nsMemory::Free()d on destroy the stream + // well be nsMemory::Free()d on destroy the stream postDataLen = newDataToPostLen; } if (nsnull != target) { - nsCOMPtr peer; + nsCOMPtr peer; rv = instance->GetPeer(getter_AddRefs(peer)); - + if (NS_SUCCEEDED(rv) && peer) { nsCOMPtr privpeer(do_QueryInterface(peer)); @@ -2938,7 +2949,7 @@ NS_IMETHODIMP nsPluginHostImpl::PostURL(nsISupports* pluginInst, target = "_self"; } else { - if ((0 == PL_strcmp(target, "newwindow")) || + if ((0 == PL_strcmp(target, "newwindow")) || (0 == PL_strcmp(target, "_new"))) target = "_blank"; else if (0 == PL_strcmp(target, "_current")) @@ -2950,7 +2961,7 @@ NS_IMETHODIMP nsPluginHostImpl::PostURL(nsISupports* pluginInst, } } } - + // if we don't have a target, just create a stream. This does // NS_OpenURI()! if (streamListener != nsnull) @@ -2961,7 +2972,7 @@ NS_IMETHODIMP nsPluginHostImpl::PostURL(nsISupports* pluginInst, nsCRT::free(dataToPost); } } - + return rv; } @@ -3020,7 +3031,7 @@ NS_IMETHODIMP nsPluginHostImpl::NotifyStatusChange(nsIPlugin* plugin, nsresult e * when no proxy host or port is specified * when only the proxy host is specified * when only the proxy port is specified - * This method conforms to the return code specified in + * This method conforms to the return code specified in * http://developer.netscape.com/docs/manuals/proxy/adminnt/autoconf.htm#1020923 * with the exception that multiple values are not implemented. */ @@ -3041,7 +3052,7 @@ NS_IMETHODIMP nsPluginHostImpl::FindProxyForURL(const char* url, char* *result) if (NS_FAILED(res) || !proxyService) { return res; } - + if (NS_FAILED(proxyService->GetProxyEnabled(&isProxyEnabled))) { return res; } @@ -3053,12 +3064,12 @@ NS_IMETHODIMP nsPluginHostImpl::FindProxyForURL(const char* url, char* *result) } return res; } - + ioService = do_GetService(kIOServiceCID, &res); if (NS_FAILED(res) || !ioService) { return res; } - + // make an nsURI from the argument url res = ioService->NewURI(nsDependentCString(url), nsnull, nsnull, getter_AddRefs(uriIn)); if (NS_FAILED(res)) { @@ -3067,7 +3078,7 @@ NS_IMETHODIMP nsPluginHostImpl::FindProxyForURL(const char* url, char* *result) nsCOMPtr pi; - res = proxyService->ExamineForProxy(uriIn, + res = proxyService->ExamineForProxy(uriIn, getter_AddRefs(pi)); if (NS_FAILED(res)) { return res; @@ -3094,7 +3105,7 @@ NS_IMETHODIMP nsPluginHostImpl::FindProxyForURL(const char* url, char* *result) if (nsnull == *result) { res = NS_ERROR_OUT_OF_MEMORY; } - + return res; } @@ -3176,9 +3187,9 @@ NS_IMETHODIMP nsPluginHostImpl::Destroy(void) mIsDestroyed = PR_TRUE; - // we should call nsIPluginInstance::Stop and nsIPluginInstance::SetWindow + // we should call nsIPluginInstance::Stop and nsIPluginInstance::SetWindow // for those plugins who want it - mActivePluginList.stopRunning(nsnull); + mActivePluginList.stopRunning(nsnull); // at this point nsIPlugin::Shutdown calls will be performed if needed mActivePluginList.shut(); @@ -3193,10 +3204,10 @@ NS_IMETHODIMP nsPluginHostImpl::Destroy(void) { nsPluginTag *temp = mPlugins->mNext; - // while walking through the list of the plugins see if we still have anything - // to shutdown some plugins may have never created an instance but still expect + // while walking through the list of the plugins see if we still have anything + // to shutdown some plugins may have never created an instance but still expect // the shutdown call see bugzilla bug 73071 - // with current logic, no need to do anything special as nsIPlugin::Shutdown + // with current logic, no need to do anything special as nsIPlugin::Shutdown // will be performed in the destructor delete mPlugins; @@ -3215,7 +3226,7 @@ NS_IMETHODIMP nsPluginHostImpl::Destroy(void) nsCOMPtr pluginTmp; nsresult rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(pluginTmp)); if (NS_FAILED(rv)) return rv; - + rv = pluginTmp->AppendNative(kPluginTmpDirName); if (NS_FAILED(rv)) return rv; @@ -3228,7 +3239,7 @@ NS_IMETHODIMP nsPluginHostImpl::Destroy(void) dirService->UnregisterProvider(mPrivateDirServiceProvider); mPrivateDirServiceProvider = nsnull; } - + mPrefService = nsnull; // release prefs service to avoid leaks! return NS_OK; @@ -3248,7 +3259,7 @@ void nsPluginHostImpl::UnloadUnusedLibraries() //////////////////////////////////////////////////////////////////////// /* Called by nsPluginInstanceOwner (nsObjectFrame.cpp - embeded case) */ -NS_IMETHODIMP nsPluginHostImpl::InstantiateEmbededPlugin(const char *aMimeType, +NS_IMETHODIMP nsPluginHostImpl::InstantiateEmbededPlugin(const char *aMimeType, nsIURI* aURL, nsIPluginInstanceOwner *aOwner) { @@ -3269,13 +3280,13 @@ NS_IMETHODIMP nsPluginHostImpl::InstantiateEmbededPlugin(const char *aMimeType, nsPluginTagType tagType; PRBool isJavaEnabled = PR_TRUE; PRBool isJava = PR_FALSE; - + rv = aOwner->QueryInterface(kIPluginTagInfo2IID, getter_AddRefs(pti2)); - + if(rv != NS_OK) { return rv; } - + rv = pti2->GetTagType(&tagType); if((rv != NS_OK) || !((tagType == nsPluginTagType_Embed) @@ -3285,7 +3296,7 @@ NS_IMETHODIMP nsPluginHostImpl::InstantiateEmbededPlugin(const char *aMimeType, return rv; } - if (tagType == nsPluginTagType_Applet || + if (tagType == nsPluginTagType_Applet || PL_strncasecmp(aMimeType, "application/x-java-vm", 21) == 0 || PL_strncasecmp(aMimeType, "application/x-java-applet", 25) == 0) { #ifdef OJI @@ -3302,7 +3313,7 @@ NS_IMETHODIMP nsPluginHostImpl::InstantiateEmbededPlugin(const char *aMimeType, else { // if we were unable to get the pref, assume java is enabled // and rely on the "find the plugin or not" logic. - + // make sure the value wasn't modified in GetBoolPref isJavaEnabled = PR_TRUE; } @@ -3329,16 +3340,16 @@ NS_IMETHODIMP nsPluginHostImpl::InstantiateEmbededPlugin(const char *aMimeType, if(FindStoppedPluginForURL(aURL, aOwner) == NS_OK) { - PLUGIN_LOG(PLUGIN_LOG_NOISY, + PLUGIN_LOG(PLUGIN_LOG_NOISY, ("nsPluginHostImpl::InstatiateEmbededPlugin FoundStopped mime=%s\n", aMimeType)); aOwner->GetInstance(instance); if((!aMimeType || !isJava) && bCanHandleInternally) rv = NewEmbededPluginStream(aURL, aOwner, instance); - // notify Java DOM component + // notify Java DOM component nsresult res; - nsCOMPtr javaDOM = + nsCOMPtr javaDOM = do_GetService("@mozilla.org/blackwood/java-dom;1", &res); if (NS_SUCCEEDED(res) && javaDOM) javaDOM->SetInstance(instance); @@ -3347,8 +3358,8 @@ NS_IMETHODIMP nsPluginHostImpl::InstantiateEmbededPlugin(const char *aMimeType, return NS_OK; } - // if we don't have a MIME type at this point, we still have one more chance by - // opening the stream and seeing if the server hands one back + // if we don't have a MIME type at this point, we still have one more chance by + // opening the stream and seeing if the server hands one back if (!aMimeType) return bCanHandleInternally ? NewEmbededPluginStream(aURL, aOwner, nsnull) : NS_ERROR_FAILURE; @@ -3356,7 +3367,7 @@ NS_IMETHODIMP nsPluginHostImpl::InstantiateEmbededPlugin(const char *aMimeType, if(rv == NS_OK) rv = aOwner->GetInstance(instance); - else + else { /* * If we are here, it's time to either show the default plugin @@ -3368,13 +3379,13 @@ NS_IMETHODIMP nsPluginHostImpl::InstantiateEmbededPlugin(const char *aMimeType, PRBool bHasPluginURL = PR_FALSE; nsCOMPtr pti2(do_QueryInterface(aOwner)); - + if(pti2) { const char *value; bHasPluginURL = NS_SUCCEEDED(pti2->GetParameter("PLUGINURL", &value)); } - // if we didn't find a pluginURL param on the object tag, + // if we didn't find a pluginURL param on the object tag, // there's nothing more to do here if(nsPluginTagType_Object == tagType && !bHasPluginURL) return rv; @@ -3395,7 +3406,7 @@ NS_IMETHODIMP nsPluginHostImpl::InstantiateEmbededPlugin(const char *aMimeType, // if we are here then we have loaded a plugin for this mimetype // and it could be the Default plugin - + nsPluginWindow *window = nsnull; //we got a plugin built, now stream @@ -3413,12 +3424,12 @@ NS_IMETHODIMP nsPluginHostImpl::InstantiateEmbededPlugin(const char *aMimeType, ((nsPluginNativeWindow*)window)->CallSetWindow(inst); } - // create an initial stream with data + // create an initial stream with data // don't make the stream if it's a java applet or we don't have SRC or DATA attribute PRBool havedata = PR_FALSE; nsCOMPtr pti(do_QueryInterface(aOwner, &rv)); - + if(pti) { const char *value; havedata = NS_SUCCEEDED(pti->GetAttribute("SRC", &value)); @@ -3428,9 +3439,9 @@ NS_IMETHODIMP nsPluginHostImpl::InstantiateEmbededPlugin(const char *aMimeType, if(havedata && !isJava && bCanHandleInternally) rv = NewEmbededPluginStream(aURL, aOwner, instance); - // notify Java DOM component + // notify Java DOM component nsresult res; - nsCOMPtr javaDOM = + nsCOMPtr javaDOM = do_GetService("@mozilla.org/blackwood/java-dom;1", &res); if (NS_SUCCEEDED(res) && javaDOM) javaDOM->SetInstance(instance); @@ -3455,7 +3466,7 @@ NS_IMETHODIMP nsPluginHostImpl::InstantiateEmbededPlugin(const char *aMimeType, //////////////////////////////////////////////////////////////////////// /* Called by full-page case */ -NS_IMETHODIMP nsPluginHostImpl::InstantiateFullPagePlugin(const char *aMimeType, +NS_IMETHODIMP nsPluginHostImpl::InstantiateFullPagePlugin(const char *aMimeType, nsString& aURLSpec, nsIStreamListener *&aStreamListener, nsIPluginInstanceOwner *aOwner) @@ -3484,7 +3495,7 @@ NS_IMETHODIMP nsPluginHostImpl::InstantiateFullPagePlugin(const char *aMimeType, rv = NewFullPagePluginStream(aStreamListener, instance); NS_IF_RELEASE(instance); return NS_OK; - } + } rv = SetUpPluginInstance(aMimeType, url, aOwner); @@ -3525,7 +3536,7 @@ NS_IMETHODIMP nsPluginHostImpl::InstantiateFullPagePlugin(const char *aMimeType, //////////////////////////////////////////////////////////////////////// -nsresult nsPluginHostImpl::FindStoppedPluginForURL(nsIURI* aURL, +nsresult nsPluginHostImpl::FindStoppedPluginForURL(nsIURI* aURL, nsIPluginInstanceOwner *aOwner) { nsCAutoString url; @@ -3533,7 +3544,7 @@ nsresult nsPluginHostImpl::FindStoppedPluginForURL(nsIURI* aURL, return NS_ERROR_FAILURE; (void)aURL->GetAsciiSpec(url); - + nsActivePlugin * plugin = mActivePluginList.findStopped(url.get()); if((plugin != nsnull) && (plugin->mStopped)) @@ -3579,7 +3590,7 @@ nsresult nsPluginHostImpl::AddInstanceToActiveList(nsCOMPtr aPlugin, (void)aURL->GetSpec(url); // let's find the corresponding plugin tag by matching nsIPlugin pointer - // it's legal for XPCOM plugins not to have nsIPlugin implemented but + // it's legal for XPCOM plugins not to have nsIPlugin implemented but // this is OK, we don't need the plugin tag for XPCOM plugins. It is going // to be used later when we decide whether or not we should delay unloading // NPAPI dll from memory, and XPCOM dlls will stay in memory anyway. @@ -3617,9 +3628,9 @@ nsPluginTag::RegisterWithCategoryManager(PRBool aOverrideInternalTypes, nsCOMPtr catMan = do_GetService(NS_CATEGORYMANAGER_CONTRACTID); if (!catMan) return; - + const char *contractId = "@mozilla.org/content/plugin/document-loader-factory;1"; - + for(int i = 0; i < mVariants; i++) { if (aType == ePluginUnregister) { nsXPIDLCString value; @@ -3650,7 +3661,7 @@ nsPluginTag::RegisterWithCategoryManager(PRBool aOverrideInternalTypes, //////////////////////////////////////////////////////////////////////// -NS_IMETHODIMP nsPluginHostImpl::SetUpPluginInstance(const char *aMimeType, +NS_IMETHODIMP nsPluginHostImpl::SetUpPluginInstance(const char *aMimeType, nsIURI *aURL, nsIPluginInstanceOwner *aOwner) { @@ -3675,7 +3686,7 @@ NS_IMETHODIMP nsPluginHostImpl::SetUpPluginInstance(const char *aMimeType, mCurrentDocument = do_GetWeakReference(document); - // ReloadPlugins will do the job smartly: nothing will be done + // ReloadPlugins will do the job smartly: nothing will be done // if no changes detected, in such a case just return if (NS_ERROR_PLUGINS_PLUGINSNOTCHANGED == ReloadPlugins(PR_FALSE)) return rv; @@ -3687,7 +3698,7 @@ NS_IMETHODIMP nsPluginHostImpl::SetUpPluginInstance(const char *aMimeType, return rv; } -NS_IMETHODIMP nsPluginHostImpl::TrySetUpPluginInstance(const char *aMimeType, +NS_IMETHODIMP nsPluginHostImpl::TrySetUpPluginInstance(const char *aMimeType, nsIURI *aURL, nsIPluginInstanceOwner *aOwner) { @@ -3716,13 +3727,13 @@ NS_IMETHODIMP nsPluginHostImpl::TrySetUpPluginInstance(const char *aMimeType, if(!aMimeType || NS_FAILED(IsPluginEnabledForType(aMimeType))) { nsCOMPtr url = do_QueryInterface(aURL); if (!url) return NS_ERROR_FAILURE; - + nsCAutoString fileExtension; url->GetFileExtension(fileExtension); - + // if we don't have an extension or no plugin for this extension, // return failure as there is nothing more we can do - if (fileExtension.IsEmpty() || + if (fileExtension.IsEmpty() || NS_FAILED(IsPluginEnabledForExtension(fileExtension.get(), mimetype))) return NS_ERROR_FAILURE; } @@ -3730,7 +3741,7 @@ NS_IMETHODIMP nsPluginHostImpl::TrySetUpPluginInstance(const char *aMimeType, mimetype = aMimeType; PRBool isJavaPlugin = PR_FALSE; - if (aMimeType && + if (aMimeType && (PL_strncasecmp(aMimeType, "application/x-java-vm", 21) == 0 || PL_strncasecmp(aMimeType, "application/x-java-applet", 25) == 0)) { @@ -3762,7 +3773,7 @@ NS_IMETHODIMP nsPluginHostImpl::TrySetUpPluginInstance(const char *aMimeType, // if (isJavaPlugin) { - // If Java is installed, get proxy JNI. + // If Java is installed, get proxy JNI. nsCOMPtr jvmManager = do_GetService(nsIJVMManager::GetCID(), &result); if (NS_SUCCEEDED(result)) { @@ -3782,10 +3793,10 @@ NS_IMETHODIMP nsPluginHostImpl::TrySetUpPluginInstance(const char *aMimeType, result = CallCreateInstance(contractID.get(), &instance); // couldn't create an XPCOM plugin, try to create wrapper for a legacy plugin - if (NS_FAILED(result)) + if (NS_FAILED(result)) { if(plugin) - { + { #ifdef XP_WIN static BOOL firstJavaPlugin = FALSE; BOOL restoreOrigDir = FALSE; @@ -3795,7 +3806,7 @@ NS_IMETHODIMP nsPluginHostImpl::TrySetUpPluginInstance(const char *aMimeType, DWORD dw = ::GetCurrentDirectory(_MAX_PATH, origDir); NS_ASSERTION(dw <= _MAX_PATH, "Falied to obtain the current directory, which may leads to incorrect class laoding"); nsCOMPtr binDirectory; - result = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR, + result = NS_GetSpecialDirectory(NS_XPCOM_CURRENT_PROCESS_DIR, getter_AddRefs(binDirectory)); if (NS_SUCCEEDED(result)) @@ -3817,11 +3828,11 @@ NS_IMETHODIMP nsPluginHostImpl::TrySetUpPluginInstance(const char *aMimeType, } #endif } - if (NS_FAILED(result)) + if (NS_FAILED(result)) { - nsCOMPtr bwPlugin = + nsCOMPtr bwPlugin = do_GetService("@mozilla.org/blackwood/pluglet-engine;1", &result); - if (NS_SUCCEEDED(result)) + if (NS_SUCCEEDED(result)) { result = bwPlugin->CreatePluginInstance(NULL, kIPluginInstanceIID, @@ -3831,7 +3842,7 @@ NS_IMETHODIMP nsPluginHostImpl::TrySetUpPluginInstance(const char *aMimeType, } } - // neither an XPCOM or legacy plugin could be instantiated, + // neither an XPCOM or legacy plugin could be instantiated, // so return the failure if (NS_FAILED(result)) return result; @@ -3844,7 +3855,7 @@ NS_IMETHODIMP nsPluginHostImpl::TrySetUpPluginInstance(const char *aMimeType, return NS_ERROR_OUT_OF_MEMORY; // set up the peer for the instance - peer->Initialize(aOwner, mimetype); + peer->Initialize(aOwner, mimetype); nsCOMPtr pIpeer; peer->QueryInterface(kIPluginInstancePeerIID, getter_AddRefs(pIpeer)); @@ -3852,7 +3863,7 @@ NS_IMETHODIMP nsPluginHostImpl::TrySetUpPluginInstance(const char *aMimeType, delete peer; return NS_ERROR_NO_INTERFACE; } - + result = instance->Initialize(pIpeer); // this should addref the peer but not the instance or owner if (NS_FAILED(result)) // except in some cases not Java, see bug 140931 return result; // our COM pointer will free the peer @@ -3899,7 +3910,7 @@ nsresult nsPluginHostImpl::SetUpDefaultPluginInstance(const char *aMimeType, nsI &result); // couldn't create an XPCOM plugin, try to create wrapper for a legacy plugin - if (NS_FAILED(result)) + if (NS_FAILED(result)) { if(plugin) result = plugin->CreateInstance(NULL, kIPluginInstanceIID, @@ -3933,7 +3944,7 @@ nsresult nsPluginHostImpl::SetUpDefaultPluginInstance(const char *aMimeType, nsI } // set up the peer for the instance - peer->Initialize(aOwner, mimetype.get()); + peer->Initialize(aOwner, mimetype.get()); nsCOMPtr pIpeer; peer->QueryInterface(kIPluginInstancePeerIID, getter_AddRefs(pIpeer)); @@ -3962,7 +3973,7 @@ nsPluginHostImpl::IsPluginEnabledForType(const char* aMimeType) LoadPlugins(); - // if we have a mimetype passed in, search the mPlugins linked + // if we have a mimetype passed in, search the mPlugins linked // list for a match if (nsnull != aMimeType) { @@ -4018,7 +4029,7 @@ static int CompareExtensions(const char *aExtensionList, const char *aExtension) //////////////////////////////////////////////////////////////////////// NS_IMETHODIMP -nsPluginHostImpl::IsPluginEnabledForExtension(const char* aExtension, +nsPluginHostImpl::IsPluginEnabledForExtension(const char* aExtension, const char* &aMimeType) { nsPluginTag *plugins = nsnull; @@ -4026,7 +4037,7 @@ nsPluginHostImpl::IsPluginEnabledForExtension(const char* aExtension, LoadPlugins(); - // if we have a mimetype passed in, search the mPlugins linked + // if we have a mimetype passed in, search the mPlugins linked // list for a match if (nsnull != aExtension) { @@ -4039,7 +4050,7 @@ nsPluginHostImpl::IsPluginEnabledForExtension(const char* aExtension, for (cnt = 0; cnt < variants; cnt++) { //if (0 == strcmp(plugins->mExtensionsArray[cnt], aExtension)) - // mExtensionsArray[cnt] could be not a single extension but + // mExtensionsArray[cnt] could be not a single extension but // rather a list separated by commas if (0 == CompareExtensions(plugins->mExtensionsArray[cnt], aExtension)) { @@ -4060,7 +4071,7 @@ nsPluginHostImpl::IsPluginEnabledForExtension(const char* aExtension, //////////////////////////////////////////////////////////////////////// -// Utility functions for a charset convertor +// Utility functions for a charset convertor // which converts platform charset to unicode. static nsresult CreateUnicodeDecoder(nsIUnicodeDecoder **aUnicodeDecoder) @@ -4082,7 +4093,7 @@ static nsresult CreateUnicodeDecoder(nsIUnicodeDecoder **aUnicodeDecoder) return rv; } -static nsresult DoCharsetConversion(nsIUnicodeDecoder *aUnicodeDecoder, +static nsresult DoCharsetConversion(nsIUnicodeDecoder *aUnicodeDecoder, const char* aANSIString, nsAString& aUnicodeString) { NS_ENSURE_TRUE(aUnicodeDecoder, NS_ERROR_FAILURE); @@ -4122,7 +4133,7 @@ public: mType.AssignWithConversion(aPluginTag->mMimeTypeArray[aMimeTypeIndex]); } } - + virtual ~DOMMimeTypeImpl() { } @@ -4165,12 +4176,12 @@ NS_IMPL_ISUPPORTS1(DOMMimeTypeImpl, nsIDOMMimeType) class DOMPluginImpl : public nsIDOMPlugin { public: NS_DECL_ISUPPORTS - + DOMPluginImpl(nsPluginTag* aPluginTag) : mPluginTag(aPluginTag) { (void) CreateUnicodeDecoder(getter_AddRefs(mUnicodeDecoder)); } - + virtual ~DOMPluginImpl() { } @@ -4203,7 +4214,7 @@ public: #if !(defined(XP_MAC) || defined(XP_MACOSX)) NS_ERROR("Only MAC should be using nsPluginTag::mFullPath!"); #endif - spec = mPluginTag.mFullPath; + spec = mPluginTag.mFullPath; } else { @@ -4216,7 +4227,7 @@ public: getter_AddRefs(pluginPath)); pluginPath->GetNativeLeafName(leafName); - + nsresult rv = DoCharsetConversion(mUnicodeDecoder, leafName.get(), aFilename); return rv; } @@ -4284,39 +4295,39 @@ NS_IMETHODIMP nsPluginHostImpl::GetPlugins(PRUint32 aPluginCount, nsIDOMPlugin* aPluginArray[]) { LoadPlugins(); - + nsPluginTag* plugin = mPlugins; - for (PRUint32 i = 0; i < aPluginCount && plugin != nsnull; + for (PRUint32 i = 0; i < aPluginCount && plugin != nsnull; i++, plugin = plugin->mNext) { nsIDOMPlugin* domPlugin = new DOMPluginImpl(plugin); NS_IF_ADDREF(domPlugin); aPluginArray[i] = domPlugin; } - + return NS_OK; } //////////////////////////////////////////////////////////////////////// nsresult -nsPluginHostImpl::FindPluginEnabledForType(const char* aMimeType, +nsPluginHostImpl::FindPluginEnabledForType(const char* aMimeType, nsPluginTag* &aPlugin) { nsPluginTag *plugins = nsnull; PRInt32 variants, cnt; - + aPlugin = nsnull; - + LoadPlugins(); - - // if we have a mimetype passed in, search the mPlugins + + // if we have a mimetype passed in, search the mPlugins // linked list for a match if (nsnull != aMimeType) { plugins = mPlugins; - + while (nsnull != plugins) { variants = plugins->mVariants; - + for (cnt = 0; cnt < variants; cnt++) { if (plugins->mMimeTypeArray[cnt] && (0 == PL_strcasecmp(plugins->mMimeTypeArray[cnt], aMimeType))) { aPlugin = plugins; @@ -4326,7 +4337,7 @@ nsPluginHostImpl::FindPluginEnabledForType(const char* aMimeType, if (cnt < variants) break; - + plugins = plugins->mNext; } } @@ -4513,7 +4524,7 @@ NS_IMETHODIMP nsPluginHostImpl::GetPluginFactory(const char *aMimeType, nsIPlugi { // XPCOM-style plugins (or at least the OJI one) cause crashes on // on windows GCC builds, so we're just turning them off for now. -#if !defined(XP_WIN) || !defined(__GNUC__) +#if !defined(XP_WIN) || !defined(__GNUC__) rv = nsGetFactory(serviceManager, kPluginCID, nsnull, nsnull, // XXX fix ClassName/ContractID (nsIFactory**)&pluginTag->mEntryPoint); plugin = pluginTag->mEntryPoint; @@ -4547,19 +4558,19 @@ NS_IMETHODIMP nsPluginHostImpl::GetPluginFactory(const char *aMimeType, nsIPlugi #if defined(XP_MAC) && TARGET_CARBON // on Carbon, first let's see if this is a Classic plugin // should we also look for a 'carb' resource? - if (PR_FindSymbol(pluginTag->mLibrary, "mainRD") != NULL) + if (PR_FindSymbol(pluginTag->mLibrary, "mainRD") != NULL) { - nsCOMPtr factory = + nsCOMPtr factory = do_GetService(NS_CLASSIC_PLUGIN_FACTORY_CONTRACTID, &rv); - if (NS_SUCCEEDED(rv)) - rv = factory->CreatePlugin(serviceManager, - pluginTag->mFileName, + if (NS_SUCCEEDED(rv)) + rv = factory->CreatePlugin(serviceManager, + pluginTag->mFileName, pluginTag->mFullPath, - pluginTag->mLibrary, + pluginTag->mLibrary, &pluginTag->mEntryPoint); if (!pluginTag->mEntryPoint) // plugin wasn't found rv = NS_ERROR_FAILURE; // setup failure to try normal loading next - } + } #endif if (NS_FAILED(rv)) rv = ns4xPlugin::CreatePlugin(serviceManager, @@ -4576,11 +4587,11 @@ NS_IMETHODIMP nsPluginHostImpl::GetPluginFactory(const char *aMimeType, nsIPlugi #if defined(XP_MAC) || defined (XP_MACOSX) #if TARGET_CARBON - /* Flash 6.0 r50 and older on Mac has a bug which calls ::UseInputWindow(NULL, true) - which turn off all our inline IME. Turn it back after the plugin + /* Flash 6.0 r50 and older on Mac has a bug which calls ::UseInputWindow(NULL, true) + which turn off all our inline IME. Turn it back after the plugin initializtion and hope that future versions will be fixed. See bug 159016 */ - if (pluginTag->mDescription && + if (pluginTag->mDescription && !PL_strncasecmp(pluginTag->mDescription, "Shockwave Flash 6.0", 19)) { int ver = atoi(pluginTag->mDescription + 21); if (ver && ver <= 50) { @@ -4669,7 +4680,7 @@ PRBool nsPluginHostImpl::IsDuplicatePlugin(nsPluginTag * aPluginTag) if (PL_strcmp(tag->mFileName, aPluginTag->mFileName)) return PR_TRUE; - // if they are equal, compare mFullPath fields just in case + // if they are equal, compare mFullPath fields just in case // mFileName contained leaf name only, and if not equal, return true if (tag->mFullPath && aPluginTag->mFullPath && PL_strcmp(tag->mFullPath, aPluginTag->mFullPath)) return PR_TRUE; @@ -4703,7 +4714,7 @@ static int PR_CALLBACK ComparePluginFileInDirectory (const void *v1, const void result = Compare(pfd1->mFilename, pfd2->mFilename, nsCaseInsensitiveStringComparator()); else if (LL_CMP(pfd1->mModTime, >, pfd2->mModTime)) result = -1; - else + else result = 1; return result; @@ -4721,8 +4732,8 @@ static nsresult FixUpPluginInfo(nsPluginInfo &aInfo, nsPluginFile &aPluginFile) if (PL_strcmp(aInfo.fMimeTypeArray[i], "*")) continue; - // we got "*" type - // check if this is an alien plugin (not our default plugin) + // we got "*" type + // check if this is an alien plugin (not our default plugin) // by trying to find a special entry point PRLibrary *library = nsnull; if (NS_FAILED(aPluginFile.LoadPlugin(library)) || !library) @@ -4737,7 +4748,7 @@ static nsresult FixUpPluginInfo(nsPluginInfo &aInfo, nsPluginFile &aPluginFile) return NS_OK; } - // if we are here that means we have an alien plugin + // if we are here that means we have an alien plugin // which wants to take over "*" type // change its "*" mime type to "[*]" @@ -4750,8 +4761,8 @@ static nsresult FixUpPluginInfo(nsPluginInfo &aInfo, nsPluginFile &aPluginFile) } //////////////////////////////////////////////////////////////////////// -nsresult nsPluginHostImpl::ScanPluginsDirectory(nsIFile * pluginsDir, - nsIComponentManager * compManager, +nsresult nsPluginHostImpl::ScanPluginsDirectory(nsIFile * pluginsDir, + nsIComponentManager * compManager, PRBool aCreatePluginList, PRBool * aPluginsChanged, PRBool checkForUnwantedPlugins) @@ -4786,19 +4797,19 @@ nsresult nsPluginHostImpl::ScanPluginsDirectory(nsIFile * pluginsDir, continue; // Sun's JRE 1.3.1 plugin must have symbolic links resolved or else it'll crash. - // See bug 197855. + // See bug 197855. dirEntry->Normalize(); nsAutoString filePath; rv = dirEntry->GetPath(filePath); if (NS_FAILED(rv)) continue; - + if (nsPluginsDir::IsPluginFile(dirEntry)) { pluginFileinDirectory * item = new pluginFileinDirectory(); - if (!item) + if (!item) return NS_ERROR_OUT_OF_MEMORY; - + // Get file mod time PRInt64 fileModTime = LL_ZERO; dirEntry->GetLastModifiedTime(&fileModTime); @@ -4863,13 +4874,13 @@ nsresult nsPluginHostImpl::ScanPluginsDirectory(nsIFile * pluginsDir, if (!pluginTag) { nsPluginFile pluginFile(file); PRLibrary* pluginLibrary = nsnull; - + // load the plugin's library so we can ask it some questions, but not for Windows #ifndef XP_WIN if (pluginFile.LoadPlugin(pluginLibrary) != NS_OK || pluginLibrary == nsnull) continue; #endif - + // create a tag describing this plugin. nsPluginInfo info = { sizeof(info) }; nsresult res = pluginFile.GetPluginInfo(info); @@ -4882,23 +4893,23 @@ nsresult nsPluginHostImpl::ScanPluginsDirectory(nsIFile * pluginsDir, continue; } - // Check for any potential '*' mime type handlers which are not our - // own default plugin and disable them as they will break the plugin + // Check for any potential '*' mime type handlers which are not our + // own default plugin and disable them as they will break the plugin // finder service, see Bugzilla bug 132430 if (!mAllowAlienStarHandler) FixUpPluginInfo(info, pluginFile); pluginTag = new nsPluginTag(&info); pluginFile.FreePluginInfo(info); - + if(pluginTag == nsnull) return NS_ERROR_OUT_OF_MEMORY; - + pluginTag->mLibrary = pluginLibrary; pluginTag->mLastModifiedTime = fileModTime; - // if this is unwanted plugin we are checkin for, or this is a duplicate plugin, - // add it to our cache info list so we can cache the unwantedness of this plugin + // if this is unwanted plugin we are checkin for, or this is a duplicate plugin, + // add it to our cache info list so we can cache the unwantedness of this plugin // when we sync cached plugins to registry if((checkForUnwantedPlugins && isUnwantedPlugin(pluginTag)) || IsDuplicatePlugin(pluginTag) || isUnwantedJavaPlugin(pluginTag)) { pluginTag->Mark(NS_PLUGIN_FLAG_UNWANTED); @@ -4938,7 +4949,7 @@ nsresult nsPluginHostImpl::ScanPluginsDirectory(nsIFile * pluginsDir, } else if (!(pluginTag->mFlags & NS_PLUGIN_FLAG_UNWANTED)) { // we don't need it, delete it; - // but don't delete unwanted plugins since they are cached + // but don't delete unwanted plugins since they are cached // in the cache info list and will be deleted later delete pluginTag; } @@ -4947,7 +4958,7 @@ nsresult nsPluginHostImpl::ScanPluginsDirectory(nsIFile * pluginsDir, } nsresult nsPluginHostImpl::ScanPluginsDirectoryList(nsISimpleEnumerator * dirEnum, - nsIComponentManager * compManager, + nsIComponentManager * compManager, PRBool aCreatePluginList, PRBool * aPluginsChanged, PRBool checkForUnwantedPlugins) @@ -4961,7 +4972,7 @@ nsresult nsPluginHostImpl::ScanPluginsDirectoryList(nsISimpleEnumerator * dirEnu nsCOMPtr nextDir(do_QueryInterface(supports, &rv)); if (NS_FAILED(rv)) continue; - + // don't pass aPluginsChanged directly to prevent it from been reset PRBool pluginschanged = PR_FALSE; ScanPluginsDirectory(nextDir, compManager, aCreatePluginList, &pluginschanged, checkForUnwantedPlugins); @@ -5025,21 +5036,21 @@ nsresult nsPluginHostImpl::FindPlugins(PRBool aCreatePluginList, PRBool * aPlugi ReadPluginInfo(); nsCOMPtr compManager = do_GetService(kComponentManagerCID, &rv); - if (compManager) + if (compManager) LoadXPCOMPlugins(compManager); - + // Failure here is not a show-stopper so just warn. rv = EnsurePrivateDirServiceProvider(); NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Failed to register dir service provider."); - + nsCOMPtr dirService(do_GetService(kDirectoryServiceContractID, &rv)); if (NS_FAILED(rv)) return rv; - + nsCOMPtr dirList; - + // Scan plugins directories; - // don't pass aPluginsChanged directly, to prevent its + // don't pass aPluginsChanged directly, to prevent its // possible reset in subsequent ScanPluginsDirectory calls PRBool pluginschanged = PR_FALSE; @@ -5051,21 +5062,21 @@ nsresult nsPluginHostImpl::FindPlugins(PRBool aCreatePluginList, PRBool * aPlugi if (pluginschanged) *aPluginsChanged = PR_TRUE; - // if we are just looking for possible changes, + // if we are just looking for possible changes, // no need to proceed if changes are detected if (!aCreatePluginList && *aPluginsChanged) { ClearCachedPluginInfoList(); return NS_OK; } } - + mPluginsLoaded = PR_TRUE; // at this point 'some' plugins have been loaded, // the rest is optional - + #if defined (XP_WIN) - + PRBool bScanPLIDs = PR_FALSE; - + if (mPrefService) mPrefService->GetBoolPref("plugin.scan.plid.all", &bScanPLIDs); @@ -5087,9 +5098,9 @@ nsresult nsPluginHostImpl::FindPlugins(PRBool aCreatePluginList, PRBool * aPlugi } } - + // Scan the installation paths of our popular plugins if the prefs are enabled - + // This table controls the order of scanning const char* const prefs[] = {NS_WIN_JRE_SCAN_KEY, nsnull, NS_WIN_ACROBAT_SCAN_KEY, nsnull, @@ -5104,12 +5115,12 @@ nsresult nsPluginHostImpl::FindPlugins(PRBool aCreatePluginList, PRBool * aPlugi PRBool bExists; if (NS_SUCCEEDED(dirService->Get(prefs[i], NS_GET_IID(nsIFile), getter_AddRefs(dirToScan))) && dirToScan && - NS_SUCCEEDED(dirToScan->Exists(&bExists)) && + NS_SUCCEEDED(dirToScan->Exists(&bExists)) && bExists) { - + PRBool bFilterUnwanted = PR_FALSE; - // 4.x plugins folder stuff: + // 4.x plugins folder stuff: // Normally we "filter" the 4.x folder through |IsUnwantedPlugin| // Check for a pref to see if we want to scan the entire 4.x plugins folder if (prefs[i+1]) { @@ -5126,7 +5137,7 @@ nsresult nsPluginHostImpl::FindPlugins(PRBool aCreatePluginList, PRBool * aPlugi if (pluginschanged) *aPluginsChanged = PR_TRUE; - // if we are just looking for possible changes, + // if we are just looking for possible changes, // no need to proceed if changes are detected if (!aCreatePluginList && *aPluginsChanged) { ClearCachedPluginInfoList(); @@ -5136,7 +5147,7 @@ nsresult nsPluginHostImpl::FindPlugins(PRBool aCreatePluginList, PRBool * aPlugi } #endif - + // if get to this point and did not detect changes in plugins // that means no plugins got updated or added // let's see if plugins have been removed @@ -5151,7 +5162,7 @@ nsresult nsPluginHostImpl::FindPlugins(PRBool aCreatePluginList, PRBool * aPlugi // if there is something left in cache, some plugins got removed from the directory // and therefor their info did not get removed from the cache info list during directory scan; // flag this fact - if (cachecount > 0) + if (cachecount > 0) *aPluginsChanged = PR_TRUE; } @@ -5178,7 +5189,7 @@ nsresult nsPluginHostImpl::FindPlugins(PRBool aCreatePluginList, PRBool * aPlugi if (aCreatePluginList) ScanForRealInComponentsFolder(compManager); - // reverse our list of plugins + // reverse our list of plugins nsPluginTag *next,*prev = nsnull; for (nsPluginTag *cur = mPlugins; cur; cur = next) { next = cur->mNext; @@ -5194,7 +5205,7 @@ nsresult nsPluginHostImpl::FindPlugins(PRBool aCreatePluginList, PRBool * aPlugi return NS_OK; } -void nsPluginHostImpl::ClearCachedPluginInfoList() +void nsPluginHostImpl::ClearCachedPluginInfoList() { while (mCachedPlugins) { nsPluginTag *next = mCachedPlugins->mNext; @@ -5230,20 +5241,20 @@ nsPluginHostImpl::WritePluginInfo() if (NS_FAILED(rv)) return rv; - directoryService->Get(NS_APP_APPLICATION_REGISTRY_DIR, NS_GET_IID(nsIFile), + directoryService->Get(NS_APP_APPLICATION_REGISTRY_DIR, NS_GET_IID(nsIFile), getter_AddRefs(mPluginRegFile)); if (!mPluginRegFile) return NS_ERROR_FAILURE; PRFileDesc* fd = nsnull; - + nsCOMPtr pluginReg; rv = mPluginRegFile->Clone(getter_AddRefs(pluginReg)); if (NS_FAILED(rv)) return rv; - + rv = pluginReg->AppendNative(kPluginRegistryFilename); if (NS_FAILED(rv)) return rv; @@ -5293,9 +5304,9 @@ nsPluginHostImpl::WritePluginInfo() tag->mFlags, PLUGIN_REGISTRY_FIELD_DELIMITER, PLUGIN_REGISTRY_END_OF_LINE_MARKER); - + //description, name & mtypecount are on separate line - PR_fprintf(fd, "%s%c%c\n%s%c%c\n%d\n", + PR_fprintf(fd, "%s%c%c\n%s%c%c\n%d\n", (tag->mDescription ? tag->mDescription : ""), PLUGIN_REGISTRY_FIELD_DELIMITER, PLUGIN_REGISTRY_END_OF_LINE_MARKER, @@ -5303,7 +5314,7 @@ nsPluginHostImpl::WritePluginInfo() PLUGIN_REGISTRY_FIELD_DELIMITER, PLUGIN_REGISTRY_END_OF_LINE_MARKER, tag->mVariants); - + // Add in each mimetype this plugin supports for (int i=0; imVariants; i++) { PR_fprintf(fd, "%d%c%s%c%s%c%s%c%c\n", @@ -5336,14 +5347,14 @@ nsPluginHostImpl::ReadPluginInfo() directoryService->Get(NS_APP_APPLICATION_REGISTRY_DIR, NS_GET_IID(nsIFile), getter_AddRefs(mPluginRegFile)); - + if (!mPluginRegFile) - return NS_ERROR_FAILURE; + return NS_ERROR_FAILURE; PRFileDesc* fd = nsnull; - + nsCOMPtr pluginReg; - + rv = mPluginRegFile->Clone(getter_AddRefs(pluginReg)); if (NS_FAILED(rv)) return rv; @@ -5377,16 +5388,16 @@ nsPluginHostImpl::ReadPluginInfo() rv = localFile->OpenNSPRFileDesc(PR_RDONLY, 0444, &fd); if (NS_FAILED(rv)) return rv; - - // set rv to return an error on goto out + + // set rv to return an error on goto out rv = NS_ERROR_FAILURE; PRInt32 bread = PR_Read(fd, registry, flen); PR_Close(fd); - if (flen > bread) + if (flen > bread) return rv; - + if (!ReadSectionHeader(reader, "HEADER")) { return rv;; } @@ -5395,18 +5406,18 @@ nsPluginHostImpl::ReadPluginInfo() return rv; } - char* values[6]; - + char* values[6]; + // VersionLiteral, kPluginRegistryVersion if (2 != reader.ParseLine(values, 2)) { return rv; } - + // VersionLiteral if (PL_strcmp(values[0], "Version")) { return rv; } - + // kPluginRegistryVersion if (PL_strcmp(values[1], kPluginRegistryVersion)) { return rv; @@ -5416,7 +5427,7 @@ nsPluginHostImpl::ReadPluginInfo() return rv; } - while (reader.NextLine()) { + while (reader.NextLine()) { char *filename = reader.LinePtr(); if (!reader.NextLine()) return rv; @@ -5444,7 +5455,7 @@ nsPluginHostImpl::ReadPluginInfo() return rv; int mimetypecount = atoi(reader.LinePtr()); - + char *stackalloced[PLUGIN_REG_MIMETYPES_ARRAY_SIZE * 3]; char **mimetypes; char **mimedescriptions; @@ -5458,30 +5469,30 @@ nsPluginHostImpl::ReadPluginInfo() } mimedescriptions = mimetypes + mimetypecount; extensions = mimedescriptions + mimetypecount; - + int mtr = 0; //mimetype read for (; mtr < mimetypecount; mtr++) { if (!reader.NextLine()) break; - + //line number|mimetype|description|extension if (4 != reader.ParseLine(values, 4)) break; int line = atoi(values[0]); if (line != mtr) - break; + break; mimetypes[mtr] = values[1]; mimedescriptions[mtr] = values[2]; extensions[mtr] = values[3]; } - + if (mtr != mimetypecount) { if (heapalloced) { delete [] heapalloced; } return rv; } - + nsPluginTag* tag = new nsPluginTag(name, description, filename, @@ -5493,18 +5504,18 @@ nsPluginHostImpl::ReadPluginInfo() if (heapalloced) { delete [] heapalloced; } - + if (!tag) { continue; } - + // Mark plugin as loaded from cache tag->Mark(tagflag | NS_PLUGIN_FLAG_FROMCACHE); PR_LOG(nsPluginLogging::gPluginLog, PLUGIN_LOG_BASIC, ("LoadCachedPluginsInfo : Loading Cached plugininfo for %s\n", tag->mFileName)); tag->mNext = mCachedPlugins; mCachedPlugins = tag; - + } return NS_OK; } @@ -5555,9 +5566,9 @@ NS_IMETHODIMP nsPluginHostImpl::NewPluginURLStream(const nsString& aURL, nsIPluginInstance *aInstance, nsIPluginStreamListener* aListener, const char *aPostData, - PRBool aIsFile, - PRUint32 aPostDataLen, - const char *aHeadersData, + PRBool aIsFile, + PRUint32 aPostDataLen, + const char *aHeadersData, PRUint32 aHeadersDataLen) { nsCOMPtr url; @@ -5602,16 +5613,16 @@ NS_IMETHODIMP nsPluginHostImpl::NewPluginURLStream(const nsString& aURL, NS_ADDREF(listenerPeer); rv = listenerPeer->Initialize(url, aInstance, aListener); - if (NS_SUCCEEDED(rv)) + if (NS_SUCCEEDED(rv)) { nsCOMPtr callbacks; - if (doc) + if (doc) { // Get the script global object owner and use that as the notification callback nsIScriptGlobalObject* global = doc->GetScriptGlobalObject(); - if (global) + if (global) { callbacks = do_QueryInterface(global->GetGlobalObjectOwner()); } @@ -5624,10 +5635,10 @@ NS_IMETHODIMP nsPluginHostImpl::NewPluginURLStream(const nsString& aURL, on the load group otherwise this channel could be canceled form |nsWebShell::OnLinkClickSync| bug 166613 */ callbacks); - if (NS_FAILED(rv)) + if (NS_FAILED(rv)) return rv; - if (doc) + if (doc) { // Set the owner of channel to the document principal... channel->SetOwner(doc->GetPrincipal()); @@ -5637,12 +5648,12 @@ NS_IMETHODIMP nsPluginHostImpl::NewPluginURLStream(const nsString& aURL, nsCOMPtr httpChannel(do_QueryInterface(channel)); if(httpChannel) { if (aPostData) { - + nsCOMPtr postDataStream; - rv = NS_NewPluginPostDataStream(getter_AddRefs(postDataStream), (const char*)aPostData, + rv = NS_NewPluginPostDataStream(getter_AddRefs(postDataStream), (const char*)aPostData, aPostDataLen, aIsFile); - if (!postDataStream) + if (!postDataStream) { NS_RELEASE(aInstance); return NS_ERROR_UNEXPECTED; @@ -5651,7 +5662,7 @@ NS_IMETHODIMP nsPluginHostImpl::NewPluginURLStream(const nsString& aURL, // XXX it's a bit of a hack to rewind the postdata stream // here but it has to be done in case the post data is // being reused multiple times. - nsCOMPtr + nsCOMPtr postDataSeekable(do_QueryInterface(postDataStream)); if (postDataSeekable) postDataSeekable->Seek(nsISeekableStream::NS_SEEK_SET, 0); @@ -5662,7 +5673,7 @@ NS_IMETHODIMP nsPluginHostImpl::NewPluginURLStream(const nsString& aURL, uploadChannel->SetUploadStream(postDataStream, EmptyCString(), -1); } - if (aHeadersData) + if (aHeadersData) rv = AddHeadersToChannel(aHeadersData, aHeadersDataLen, httpChannel); } rv = channel->AsyncOpen(listenerPeer, nsnull); @@ -5720,8 +5731,8 @@ nsPluginHostImpl::DoURLLoadSecurityCheck(nsIPluginInstance *aInstance, //////////////////////////////////////////////////////////////////////// NS_IMETHODIMP -nsPluginHostImpl::AddHeadersToChannel(const char *aHeadersData, - PRUint32 aHeadersDataLen, +nsPluginHostImpl::AddHeadersToChannel(const char *aHeadersData, + PRUint32 aHeadersDataLen, nsIChannel *aGenericChannel) { nsresult rv = NS_OK; @@ -5738,7 +5749,7 @@ nsPluginHostImpl::AddHeadersToChannel(const char *aHeadersData, nsCAutoString headerValue; PRInt32 crlf = 0; PRInt32 colon = 0; - + // // Turn the char * buffer into an nsString. // @@ -5748,7 +5759,7 @@ nsPluginHostImpl::AddHeadersToChannel(const char *aHeadersData, // Iterate over the nsString: for each "\r\n" delimeted chunk, // add the value as a header to the nsIHTTPChannel // - + while (PR_TRUE) { crlf = headersString.Find("\r\n", PR_TRUE); if (-1 == crlf) { @@ -5766,17 +5777,17 @@ nsPluginHostImpl::AddHeadersToChannel(const char *aHeadersData, oneHeader.Left(headerName, colon); colon++; oneHeader.Mid(headerValue, colon, oneHeader.Length() - colon); - + // // FINALLY: we can set the header! - // - + // + rv = aChannel->SetRequestHeader(headerName, headerValue, PR_TRUE); if (NS_FAILED(rv)) { rv = NS_ERROR_NULL_POINTER; return rv; } - } + } return rv; } @@ -5803,9 +5814,9 @@ nsPluginHostImpl::StopPluginInstance(nsIPluginInstance* aInstance) library = plugin->mPluginTag->mLibrary; mActivePluginList.remove(plugin); - } + } else { - // if it is allowed to be cached simply stop it, but first we should check + // if it is allowed to be cached simply stop it, but first we should check // if we haven't exceeded the maximum allowed number of cached instances // try to get the max cached plugins from a pref or use default @@ -5834,7 +5845,7 @@ nsresult nsPluginHostImpl::NewEmbededPluginStream(nsIURI* aURL, { if (!aURL) return NS_OK; - + nsPluginStreamListenerPeer *listener = (nsPluginStreamListenerPeer *)new nsPluginStreamListenerPeer(); if (listener == nsnull) return NS_ERROR_OUT_OF_MEMORY; @@ -5885,7 +5896,7 @@ nsresult nsPluginHostImpl::NewEmbededPluginStream(nsIURI* aURL, //////////////////////////////////////////////////////////////////////// /* Called by InstantiateFullPagePlugin() */ -nsresult nsPluginHostImpl::NewFullPagePluginStream(nsIStreamListener *&aStreamListener, +nsresult nsPluginHostImpl::NewFullPagePluginStream(nsIStreamListener *&aStreamListener, nsIPluginInstance *aInstance) { nsPluginStreamListenerPeer *listener = (nsPluginStreamListenerPeer *)new nsPluginStreamListenerPeer(); @@ -5918,7 +5929,7 @@ NS_IMETHODIMP nsPluginHostImpl::GetProgramPath(const char* *result) nsresult rv; NS_ENSURE_ARG_POINTER(result); *result = nsnull; - + nsCOMPtr dirService(do_GetService(kDirectoryServiceContractID, &rv)); if (NS_FAILED(rv)) return rv; @@ -5926,7 +5937,7 @@ NS_IMETHODIMP nsPluginHostImpl::GetProgramPath(const char* *result) rv = dirService->Get(NS_XPCOM_CURRENT_PROCESS_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(programDir)); if (NS_FAILED(rv)) return rv; - + nsCAutoString temp; rv = programDir->GetNativePath(temp); *result = ToNewCString(temp); @@ -5940,7 +5951,7 @@ NS_IMETHODIMP nsPluginHostImpl::GetTempDirPath(const char* *result) nsresult rv; NS_ENSURE_ARG_POINTER(result); *result = nsnull; - + nsCOMPtr dirService(do_GetService(kDirectoryServiceContractID, &rv)); if (NS_FAILED(rv)) return rv; @@ -5948,7 +5959,7 @@ NS_IMETHODIMP nsPluginHostImpl::GetTempDirPath(const char* *result) rv = dirService->Get(NS_OS_TEMP_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(tempDir)); if (NS_FAILED(rv)) return rv; - + nsCAutoString temp; rv = tempDir->GetNativePath(temp); *result = ToNewCString(temp); @@ -5972,20 +5983,20 @@ NS_IMETHODIMP nsPluginHostImpl::GetCookie(const char* inCookieURL, void* inOutCo nsXPIDLCString cookieString; PRUint32 cookieStringLen = 0; nsCOMPtr uriIn; - + if ((nsnull == inCookieURL) || (0 >= inOutCookieSize)) { return NS_ERROR_INVALID_ARG; } nsCOMPtr ioService(do_GetService(kIOServiceCID, &rv)); - + if (NS_FAILED(rv) || (nsnull == ioService)) { return rv; } - nsCOMPtr cookieService = + nsCOMPtr cookieService = do_GetService(kCookieServiceCID, &rv); - + if (NS_FAILED(rv) || (nsnull == cookieService)) { return NS_ERROR_INVALID_ARG; } @@ -5997,7 +6008,7 @@ NS_IMETHODIMP nsPluginHostImpl::GetCookie(const char* inCookieURL, void* inOutCo } rv = cookieService->GetCookieString(uriIn, nsnull, getter_Copies(cookieString)); - + if (NS_FAILED(rv) || (!cookieString) || (inOutCookieSize <= (cookieStringLen = PL_strlen(cookieString.get())))) { return NS_ERROR_FAILURE; @@ -6006,7 +6017,7 @@ NS_IMETHODIMP nsPluginHostImpl::GetCookie(const char* inCookieURL, void* inOutCo PL_strcpy((char *) inOutCookieBuffer, cookieString.get()); inOutCookieSize = cookieStringLen; rv = NS_OK; - + return rv; } @@ -6016,25 +6027,25 @@ NS_IMETHODIMP nsPluginHostImpl::SetCookie(const char* inCookieURL, const void* i { nsresult rv = NS_ERROR_NOT_IMPLEMENTED; nsCOMPtr uriIn; - - if ((nsnull == inCookieURL) || (nsnull == inCookieBuffer) || + + if ((nsnull == inCookieURL) || (nsnull == inCookieBuffer) || (0 >= inCookieSize)) { return NS_ERROR_INVALID_ARG; } - + nsCOMPtr ioService(do_GetService(kIOServiceCID, &rv)); - + if (NS_FAILED(rv) || (nsnull == ioService)) { return rv; } - - nsCOMPtr cookieService = + + nsCOMPtr cookieService = do_GetService(kCookieServiceCID, &rv); - + if (NS_FAILED(rv) || (nsnull == cookieService)) { return NS_ERROR_FAILURE; } - + // make an nsURI from the argument url rv = ioService->NewURI(nsDependentCString(inCookieURL), nsnull, nsnull, getter_AddRefs(uriIn)); if (NS_FAILED(rv)) { @@ -6049,7 +6060,7 @@ NS_IMETHODIMP nsPluginHostImpl::SetCookie(const char* inCookieURL, const void* i cookie[inCookieSize] = '\0'; rv = cookieService->SetCookieString(uriIn, prompt, cookie, nsnull); cookie[inCookieSize] = c; - + return rv; } @@ -6073,7 +6084,7 @@ NS_IMETHODIMP nsPluginHostImpl::Observe(nsISupports *aSubject, } //////////////////////////////////////////////////////////////////////// -NS_IMETHODIMP +NS_IMETHODIMP nsPluginHostImpl::HandleBadPlugin(PRLibrary* aLibrary, nsIPluginInstance *aInstance) { // the |aLibrary| parameter is not needed anymore, after we added |aInstance| which @@ -6086,13 +6097,13 @@ nsPluginHostImpl::HandleBadPlugin(PRLibrary* aLibrary, nsIPluginInstance *aInsta if(mDontShowBadPluginMessage) return rv; - + nsCOMPtr owner; - + if (aInstance) { nsCOMPtr peer; rv = aInstance->GetPeer(getter_AddRefs(peer)); - if (NS_SUCCEEDED(rv) && peer) { + if (NS_SUCCEEDED(rv) && peer) { nsCOMPtr privpeer(do_QueryInterface(peer)); privpeer->GetOwner(getter_AddRefs(owner)); } @@ -6109,20 +6120,20 @@ nsPluginHostImpl::HandleBadPlugin(PRLibrary* aLibrary, nsIPluginInstance *aInsta rv = strings->CreateBundle(PLUGIN_PROPERTIES_URL, getter_AddRefs(bundle)); if (NS_FAILED(rv)) return rv; - + nsXPIDLString title, message, checkboxMessage; if (NS_FAILED(rv = bundle->GetStringFromName(NS_LITERAL_STRING("BadPluginTitle").get(), getter_Copies(title)))) return rv; - if (NS_FAILED(rv = bundle->GetStringFromName(NS_LITERAL_STRING("BadPluginMessage").get(), + if (NS_FAILED(rv = bundle->GetStringFromName(NS_LITERAL_STRING("BadPluginMessage").get(), getter_Copies(message)))) return rv; - if (NS_FAILED(rv = bundle->GetStringFromName(NS_LITERAL_STRING("BadPluginCheckboxMessage").get(), + if (NS_FAILED(rv = bundle->GetStringFromName(NS_LITERAL_STRING("BadPluginCheckboxMessage").get(), getter_Copies(checkboxMessage)))) return rv; - + // add plugin name to the message char * pluginname = nsnull; nsActivePlugin * p = mActivePluginList.find(aInstance); @@ -6160,7 +6171,7 @@ nsPluginHostImpl::HandleBadPlugin(PRLibrary* aLibrary, nsIPluginInstance *aInsta * nsPIPluginHost interface */ -NS_IMETHODIMP +NS_IMETHODIMP nsPluginHostImpl::SetIsScriptableInstance(nsIPluginInstance * aPluginInstance, PRBool aScriptable) { nsActivePlugin * p = mActivePluginList.find(aPluginInstance); @@ -6176,18 +6187,18 @@ nsPluginHostImpl::SetIsScriptableInstance(nsIPluginInstance * aPluginInstance, P NS_IMETHODIMP nsPluginHostImpl::ParsePostBufferToFixHeaders( - const char *inPostData, PRUint32 inPostDataLen, + const char *inPostData, PRUint32 inPostDataLen, char **outPostData, PRUint32 *outPostDataLen) { if (!inPostData || !outPostData || !outPostDataLen) return NS_ERROR_NULL_POINTER; - + *outPostData = 0; *outPostDataLen = 0; const char CR = '\r'; const char LF = '\n'; - const char CRLFCRLF[] = {CR,LF,CR,LF,'\0'}; // C string"\r\n\r\n" + const char CRLFCRLF[] = {CR,LF,CR,LF,'\0'}; // C string"\r\n\r\n" const char ContentLenHeader[] = "Content-length"; nsAutoVoidArray singleLF; @@ -6201,11 +6212,11 @@ nsPluginHostImpl::ParsePostBufferToFixHeaders( // line ('\n') to the beginning of the file or buffer. // so *inPostData == '\n' is valid pSod = inPostData + 1; - } else { + } else { const char *s = inPostData; //tmp pointer to sourse inPostData while (s < pEod) { - if (!pSCntlh && - (*s == 'C' || *s == 'c') && + if (!pSCntlh && + (*s == 'C' || *s == 'c') && (s + sizeof(ContentLenHeader) - 1 < pEod) && (!PL_strncasecmp(s, ContentLenHeader, sizeof(ContentLenHeader) - 1))) { @@ -6215,8 +6226,8 @@ nsPluginHostImpl::ParsePostBufferToFixHeaders( // search for first CR or LF == end of ContentLenHeader for (; p < pEod; p++) { if (*p == CR || *p == LF) { - // got delimiter, - // one more check; if previous char is a digit + // got delimiter, + // one more check; if previous char is a digit // most likely pSCntlh points to the start of ContentLenHeader if (*(p-1) >= '0' && *(p-1) <= '9') { s = p; @@ -6224,7 +6235,7 @@ nsPluginHostImpl::ParsePostBufferToFixHeaders( break; //for loop } } - if (pSCntlh == s) { // curret ptr is the same + if (pSCntlh == s) { // curret ptr is the same pSCntlh = 0; // that was not ContentLenHeader break; // there is nothing to parse, break *WHILE LOOP* here } @@ -6263,10 +6274,10 @@ nsPluginHostImpl::ParsePostBufferToFixHeaders( PRUint32 newBufferLen = 0; PRUint32 dataLen = pEod - pSod; PRUint32 headersLen = pEoh ? pSod - inPostData : 0; - + char *p; // tmp ptr into new output buf if (headersLen) { // we got a headers - // this function does not make any assumption on correctness + // this function does not make any assumption on correctness // of ContentLenHeader value in this case. newBufferLen = dataLen + headersLen; @@ -6324,12 +6335,12 @@ nsPluginHostImpl::ParsePostBufferToFixHeaders( } *outPostDataLen = newBufferLen; - + return NS_OK; } NS_IMETHODIMP -nsPluginHostImpl::CreateTmpFileToPost(const char *postDataURL, char **pTmpFileName) +nsPluginHostImpl::CreateTmpFileToPost(const char *postDataURL, char **pTmpFileName) { *pTmpFileName = 0; nsresult rv; @@ -6356,14 +6367,14 @@ nsPluginHostImpl::CreateTmpFileToPost(const char *postDataURL, char **pTmpFileNa nsCOMPtr inStream; rv = NS_NewLocalFileInputStream(getter_AddRefs(inStream), inFile); if (NS_FAILED(rv)) return rv; - - // Create a temporary file to write the http Content-length: %ld\r\n\" header + + // Create a temporary file to write the http Content-length: %ld\r\n\" header // and "\r\n" == end of headers for post data to nsCOMPtr tempFile; rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(tempFile)); if (NS_FAILED(rv)) return rv; - + rv = tempFile->AppendNative(kPluginTmpDirName); if (NS_FAILED(rv)) return rv; @@ -6372,18 +6383,18 @@ nsPluginHostImpl::CreateTmpFileToPost(const char *postDataURL, char **pTmpFileNa tempFile->Exists(&dirExists); if (!dirExists) (void) tempFile->Create(nsIFile::DIRECTORY_TYPE, 0777); - + nsCAutoString inFileName; inFile->GetNativeLeafName(inFileName); // XXX hack around bug 70083 inFileName.Insert(NS_LITERAL_CSTRING("post-"), 0); rv = tempFile->AppendNative(inFileName); - - if (NS_FAILED(rv)) + + if (NS_FAILED(rv)) return rv; - + // make it unique, and mode == 0600, not world-readable - rv = tempFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0600); + rv = tempFile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0600); if (NS_FAILED(rv)) return rv; @@ -6404,23 +6415,23 @@ nsPluginHostImpl::CreateTmpFileToPost(const char *postDataURL, char **pTmpFileNa while (1) { // Read() mallocs if buffer is null rv = inStream->Read(buf, 1024, &br); - if (NS_FAILED(rv) || (PRInt32)br <= 0) + if (NS_FAILED(rv) || (PRInt32)br <= 0) break; if (firstRead) { - // according to the 4.x spec + // according to the 4.x spec // http://developer.netscape.com/docs/manuals/communicator/plugin/pgfn2.htm#1007707 - //"For protocols in which the headers must be distinguished from the body, + //"For protocols in which the headers must be distinguished from the body, // such as HTTP, the buffer or file should contain the headers, followed by - // a blank line, then the body. If no custom headers are required, simply + // a blank line, then the body. If no custom headers are required, simply // add a blank line ('\n') to the beginning of the file or buffer. - + char *parsedBuf; // assuming first 1K (or what we got) has all headers in, // lets parse it through nsPluginHostImpl::ParsePostBufferToFixHeaders() ParsePostBufferToFixHeaders((const char *)buf, br, &parsedBuf, &bw); rv = outStream->Write(parsedBuf, bw, &br); nsMemory::Free(parsedBuf); - if (NS_FAILED(rv) || (bw != br)) + if (NS_FAILED(rv) || (bw != br)) break; firstRead = PR_FALSE; @@ -6428,7 +6439,7 @@ nsPluginHostImpl::CreateTmpFileToPost(const char *postDataURL, char **pTmpFileNa } bw = br; rv = outStream->Write(buf, bw, &br); - if (NS_FAILED(rv) || (bw != br)) + if (NS_FAILED(rv) || (bw != br)) break; } @@ -6463,23 +6474,23 @@ nsPluginHostImpl::ScanForRealInComponentsFolder(nsIComponentManager * aCompManag nsresult rv = NS_OK; #ifdef XP_WIN - + // First, lets check if we already have Real. No point in doing this if it's installed correctly if (NS_SUCCEEDED(IsPluginEnabledForType("audio/x-pn-realaudio-plugin"))) return rv; - + // Next, maybe the pref wants to override PRBool bSkipRealPlayerHack = PR_FALSE; if (!mPrefService || (NS_SUCCEEDED(mPrefService->GetBoolPref("plugin.skip_real_player_hack", &bSkipRealPlayerHack)) && bSkipRealPlayerHack)) return rv; - + // now we need the XPCOM components folder nsCOMPtr RealPlugin; if (NS_FAILED(NS_GetSpecialDirectory(NS_XPCOM_COMPONENT_DIR, getter_AddRefs(RealPlugin))) || !RealPlugin) return rv; - + // make sure the file is actually there RealPlugin->AppendNative(nsDependentCString("nppl3260.dll")); PRBool exists; @@ -6490,21 +6501,21 @@ nsPluginHostImpl::ScanForRealInComponentsFolder(nsIComponentManager * aCompManag // now make sure it's a plugin nsCOMPtr localfile; - NS_NewNativeLocalFile(filePath, + NS_NewNativeLocalFile(filePath, PR_TRUE, getter_AddRefs(localfile)); if (!nsPluginsDir::IsPluginFile(localfile)) return rv; - + // try to get the mime info and descriptions out of the plugin nsPluginFile pluginFile(localfile); nsPluginInfo info = { sizeof(info) }; if (NS_FAILED(pluginFile.GetPluginInfo(info))) return rv; - + nsCOMPtr compManager = do_GetService(kComponentManagerCID, &rv); - + // finally, create our "plugin tag" and add it to the list if (info.fMimeTypeArray) { nsPluginTag *pluginTag = new nsPluginTag(&info); @@ -6512,12 +6523,12 @@ nsPluginHostImpl::ScanForRealInComponentsFolder(nsIComponentManager * aCompManag pluginTag->SetHost(this); pluginTag->mNext = mPlugins; mPlugins = pluginTag; - + // last thing we need is to register this plugin with layout so it can be used in full-page mode pluginTag->RegisterWithCategoryManager(mOverrideInternalTypes); } } - + // free allocated strings in GetPluginInfo pluginFile.FreePluginInfo(info); @@ -6526,7 +6537,7 @@ nsPluginHostImpl::ScanForRealInComponentsFolder(nsIComponentManager * aCompManag return rv; } -nsresult nsPluginHostImpl::AddUnusedLibrary(PRLibrary * aLibrary) +nsresult nsPluginHostImpl::AddUnusedLibrary(PRLibrary * aLibrary) { if (mUnusedLibraries.IndexOf(aLibrary) == -1) // don't add duplicates mUnusedLibraries.AppendElement(aLibrary); @@ -6535,15 +6546,15 @@ nsresult nsPluginHostImpl::AddUnusedLibrary(PRLibrary * aLibrary) } //////////////////////////////////////////////////////////////////////////////////// -nsresult nsPluginStreamListenerPeer::ServeStreamAsFile(nsIRequest *request, +nsresult nsPluginStreamListenerPeer::ServeStreamAsFile(nsIRequest *request, nsISupports* aContext) { if (!mInstance) return NS_ERROR_FAILURE; - // mInstance->Stop calls mPStreamListener->CleanUpStream(), so stream will be properly clean up + // mInstance->Stop calls mPStreamListener->CleanUpStream(), so stream will be properly clean up mInstance->Stop(); - mInstance->Start(); + mInstance->Start(); nsCOMPtr peer; mInstance->GetPeer(getter_AddRefs(peer)); if (peer) { @@ -6560,11 +6571,11 @@ nsresult nsPluginStreamListenerPeer::ServeStreamAsFile(nsIRequest *request, } } } - + mPluginStreamInfo->SetSeekable(0); mPStreamListener->OnStartBinding(mPluginStreamInfo); mPluginStreamInfo->SetStreamOffset(0); - + // force the plugin use stream as file mStreamType = nsPluginStreamType_AsFile; @@ -6577,7 +6588,7 @@ nsresult nsPluginStreamListenerPeer::ServeStreamAsFile(nsIRequest *request, } } - // unset mPendingRequests + // unset mPendingRequests mPendingRequests = 0; return NS_OK; @@ -6625,7 +6636,7 @@ nsPluginByteRangeStreamListener::OnStartRequest(nsIRequest *request, nsISupports if (!httpChannel) { return NS_ERROR_FAILURE; } - + PRUint32 responseCode = 0; rv = httpChannel->GetResponseStatus(&responseCode); if (NS_FAILED(rv) || responseCode != 200) { @@ -6637,7 +6648,7 @@ nsPluginByteRangeStreamListener::OnStartRequest(nsIRequest *request, nsISupports mStreamConverter = finalStreamListener; mRemoveMagicNumber = PR_TRUE; - //get nsPluginStreamListenerPeer* ptr from finalStreamListener + //get nsPluginStreamListenerPeer* ptr from finalStreamListener nsPluginStreamListenerPeer *pslp = NS_REINTERPRET_CAST(nsPluginStreamListenerPeer*, finalStreamListener.get()); rv = pslp->ServeStreamAsFile(request, ctxt); @@ -6652,7 +6663,7 @@ nsPluginByteRangeStreamListener::OnStopRequest(nsIRequest *request, nsISupports return NS_ERROR_FAILURE; nsCOMPtr finalStreamListener = do_QueryReferent(mWeakPtrPluginStreamListenerPeer); - if (!finalStreamListener) + if (!finalStreamListener) return NS_ERROR_FAILURE; if (mRemoveMagicNumber) { @@ -6670,7 +6681,7 @@ nsPluginByteRangeStreamListener::OnStopRequest(nsIRequest *request, nsISupports NS_WARNING("Bad state of nsPluginByteRangeStreamListener"); } } - + return mStreamConverter->OnStopRequest(request, ctxt, status); } @@ -6680,18 +6691,18 @@ nsPluginByteRangeStreamListener::OnDataAvailable(nsIRequest *request, nsISupport { if (!mStreamConverter) return NS_ERROR_FAILURE; - + nsCOMPtr finalStreamListener = do_QueryReferent(mWeakPtrPluginStreamListenerPeer); if (!finalStreamListener) return NS_ERROR_FAILURE; - + return mStreamConverter->OnDataAvailable(request, ctxt, inStr, sourceOffset, count); } PRBool -nsPluginStreamInfo::UseExistingPluginCacheFile(nsPluginStreamInfo* psi) +nsPluginStreamInfo::UseExistingPluginCacheFile(nsPluginStreamInfo* psi) { - + NS_ENSURE_ARG_POINTER(psi); if ( psi->mLength == mLength && @@ -6700,7 +6711,7 @@ nsPluginStreamInfo::UseExistingPluginCacheFile(nsPluginStreamInfo* psi) !PL_strcmp(psi->mURL, mURL)) { return PR_TRUE; - } + } return PR_FALSE; } diff --git a/mozilla/webshell/tests/viewer/unix/Makefile.in b/mozilla/webshell/tests/viewer/unix/Makefile.in index 778f76a6ddb..ba28c727fa7 100644 --- a/mozilla/webshell/tests/viewer/unix/Makefile.in +++ b/mozilla/webshell/tests/viewer/unix/Makefile.in @@ -53,6 +53,9 @@ endif ifdef MOZ_ENABLE_XLIB DIRS += xlib endif +ifdef MOZ_ENABLE_QT +DIRS += qt +endif include $(topsrcdir)/config/rules.mk diff --git a/mozilla/webshell/tests/viewer/unix/qt/Makefile.in b/mozilla/webshell/tests/viewer/unix/qt/Makefile.in new file mode 100644 index 00000000000..d754679cfb4 --- /dev/null +++ b/mozilla/webshell/tests/viewer/unix/qt/Makefile.in @@ -0,0 +1,64 @@ +# +# The contents of this file are subject to the Netscape 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/NPL/ +# +# 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 mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): +# + +DEPTH = ../../../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = webshell_tests +LIBRARY_NAME = viewer_qt_s +REQUIRES = xpcom \ + string \ + docshell \ + necko \ + dom \ + widget \ + gfx \ + layout \ + content \ + uriloader \ + webbrwsr \ + webshell \ + locale \ + util \ + $(NULL) + +CPPSRCS = \ + nsQtMain.cpp \ + nsQtMenu.cpp \ + moc_nsQtMenu.cpp \ + $(NULL) + +FORCE_STATIC_LIB = 1 + +include $(topsrcdir)/config/rules.mk + +INCLUDES += -I$(srcdir)/../.. + +ifeq ($(OS_ARCH), Linux) +DEFINES += -D_XOPEN_SOURCE=500 +endif + +CXXFLAGS += $(MOZ_QT_CFLAGS) + diff --git a/mozilla/webshell/tests/viewer/unix/qt/nsQtMain.cpp b/mozilla/webshell/tests/viewer/unix/qt/nsQtMain.cpp new file mode 100644 index 00000000000..26118f961d2 --- /dev/null +++ b/mozilla/webshell/tests/viewer/unix/qt/nsQtMain.cpp @@ -0,0 +1,215 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * Alternatively, the contents of this file may be used under the terms of + * either of 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 "nsViewerApp.h" +#include "nsBrowserWindow.h" +#include "nsQtMenu.h" +#include "nsIServiceManager.h" +#include "nsIThread.h" +#include "plevent.h" +#include "prinit.h" +#include "prlog.h" + +#ifdef NS_TRACE_MALLOC +#include "nsTraceMalloc.h" +#endif + +static nsNativeViewerApp* gTheApp; + +nsNativeViewerApp::nsNativeViewerApp() +{ +} + +nsNativeViewerApp::~nsNativeViewerApp() +{ +} + +int +nsNativeViewerApp::Run() +{ + OpenWindow(); + // XXX mAppShell can be set to NULL while mAppShell->Run() is running + // because nsViewerApp::Exit() is called. I don't know what should + // happen, but this is a workaround that neither crashes nor leaks. + // See + nsIAppShell* theAppShell = mAppShell; + NS_ADDREF(theAppShell); + theAppShell->Run(); + NS_RELEASE(theAppShell); + return 0; +} + +//---------------------------------------------------------------------- + +nsNativeBrowserWindow::nsNativeBrowserWindow() +{ +} + +nsNativeBrowserWindow::~nsNativeBrowserWindow() +{ +} + +nsresult +nsNativeBrowserWindow::InitNativeWindow() +{ + // override to do something special with platform native windows + return NS_OK; +} + +static QWidget * sgHackMenuBar = nsnull; + +nsresult +nsNativeBrowserWindow::CreateMenuBar(PRInt32 aWidth) +{ + CreateViewerMenus(mWindow, this, &sgHackMenuBar); + mHaveMenuBar = PR_TRUE; + return NS_OK; +} + +nsresult +nsNativeBrowserWindow::GetMenuBarHeight(PRInt32 * aHeightOut) +{ + NS_ASSERTION(nsnull != aHeightOut,"null out param."); + + *aHeightOut = 0; + + if (nsnull != sgHackMenuBar && mHaveMenuBar) + { + *aHeightOut = sgHackMenuBar->height(); + } + + qDebug("menubar height = %d", *aHeightOut); + return NS_OK; +} + +nsEventStatus +nsNativeBrowserWindow::DispatchMenuItem(PRInt32 aID) +{ + // Dispatch motif-only menu code goes here + + // Dispatch xp menu items + return nsBrowserWindow::DispatchMenuItem(aID); +} + +//---------------------------------------------------------------------- + + +#ifdef DEBUG_ramiro +#define CRAWL_STACK_ON_SIGSEGV +#endif // DEBUG_ramiro + + +#ifdef CRAWL_STACK_ON_SIGSEGV + +#include +#include +#include "nsTraceRefcntImpl.h" + +extern "C" char * strsignal(int); + +static char _progname[1024] = "huh?"; + +void +ah_crap_handler(int signum) +{ + PR_GetCurrentThread(); + + printf("prog = %s\npid = %d\nsignal = %s\n", + _progname, + getpid(), + strsignal(signum)); + + printf("stack logged to someplace\n"); + nsTraceRefcntImpl::WalkTheStack(stdout); + + printf("Sleeping for 5 minutes.\n"); + printf("Type 'gdb %s %d' to attach your debugger to this thread.\n", + _progname, + getpid()); + + sleep(300); + + printf("Done sleeping...\n"); +} +#endif // CRAWL_STACK_ON_SIGSEGV + +int main(int argc, char **argv) +{ +#ifdef NS_TRACE_MALLOC + argc = NS_TraceMallocStartupArgs(argc, argv); +#endif + +#ifdef CRAWL_STACK_ON_SIGSEGV + strcpy(_progname,argv[0]); + signal(SIGSEGV, ah_crap_handler); + signal(SIGILL, ah_crap_handler); + signal(SIGABRT, ah_crap_handler); +#endif // CRAWL_STACK_ON_SIGSEGV + + // Initialize XPCOM + nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull); + NS_ASSERTION(NS_SUCCEEDED(rv), "NS_InitXPCOM failed"); + if (NS_SUCCEEDED(rv)) { + // The toolkit service in mozilla will look in the environment + // to determine which toolkit to use. Yes, it is a dumb hack to + // force it here, but we have no choice because of toolkit specific + // code linked into the viewer. + putenv("MOZ_TOOLKIT=qt"); + + gTheApp = new nsNativeViewerApp(); + gTheApp->Initialize(argc, argv); + gTheApp->Run(); + delete gTheApp; + + // Shutdown XPCOM + rv = NS_ShutdownXPCOM(nsnull); + NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed"); + + // XXX This is disabled because sometimes it hangs waiting for a + // netlib thread to exit, which isn't exiting :-(. Need more + // shutdown logic in necko first. +#if 0 + // Shutdown NSPR + PR_LogFlush(); + PR_Cleanup(); +#endif + } + + return 0; +} diff --git a/mozilla/webshell/tests/viewer/unix/qt/nsQtMenu.cpp b/mozilla/webshell/tests/viewer/unix/qt/nsQtMenu.cpp new file mode 100644 index 00000000000..d943ecdc51a --- /dev/null +++ b/mozilla/webshell/tests/viewer/unix/qt/nsQtMenu.cpp @@ -0,0 +1,264 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include +#include "nsBrowserWindow.h" +#include "nsQtMenu.h" +#include "resources.h" +#include "nscore.h" +#include + +nsMenuEventHandler::nsMenuEventHandler(nsBrowserWindow * window) +{ + mWindow = window; +} + +void nsMenuEventHandler::MenuItemActivated(int id) +{ + mWindow->DispatchMenuItem(id); +} + +void CreateViewerMenus(nsIWidget * aParentInterface, void *data, QWidget ** aMenuBarOut) +{ + QWidget *aParent = (QWidget *)aParentInterface->GetNativeData(NS_NATIVE_WIDGET); + + nsBrowserWindow * window = (nsBrowserWindow *) data; + + nsMenuEventHandler * eventHandler = new nsMenuEventHandler(window); + + QMenuBar * menuBar = new QMenuBar(aParent); + QPopupMenu * file = new QPopupMenu(aParent); + QObject::connect(file, + SIGNAL(activated(int)), + eventHandler, + SLOT(MenuItemActivated(int))); + QPopupMenu * samples = new QPopupMenu(aParent); + QObject::connect(samples, + SIGNAL(activated(int)), + eventHandler, + SLOT(MenuItemActivated(int))); + QPopupMenu * xptests = new QPopupMenu(aParent); + QObject::connect(xptests, + SIGNAL(activated(int)), + eventHandler, + SLOT(MenuItemActivated(int))); + QPopupMenu * edit = new QPopupMenu(aParent); + QObject::connect(edit, + SIGNAL(activated(int)), + eventHandler, + SLOT(MenuItemActivated(int))); + QPopupMenu * debug = new QPopupMenu(aParent); + QObject::connect(debug, + SIGNAL(activated(int)), + eventHandler, + SLOT(MenuItemActivated(int))); + QPopupMenu * eventdebug = new QPopupMenu(aParent); + QObject::connect(eventdebug, + SIGNAL(activated(int)), + eventHandler, + SLOT(MenuItemActivated(int))); + QPopupMenu * style = new QPopupMenu(aParent); + QObject::connect(style, + SIGNAL(activated(int)), + eventHandler, + SLOT(MenuItemActivated(int))); + QPopupMenu * tools = new QPopupMenu(aParent); + QObject::connect(tools, + SIGNAL(activated(int)), + eventHandler, + SLOT(MenuItemActivated(int))); + QPopupMenu * select = new QPopupMenu(aParent); + QObject::connect(select, + SIGNAL(activated(int)), + eventHandler, + SLOT(MenuItemActivated(int))); + QPopupMenu * compatibility = new QPopupMenu(aParent); + QObject::connect(compatibility, + SIGNAL(activated(int)), + eventHandler, + SLOT(MenuItemActivated(int))); + QPopupMenu * render = new QPopupMenu(aParent); + QObject::connect(render, + SIGNAL(activated(int)), + eventHandler, + SLOT(MenuItemActivated(int))); + + InsertMenuItem(file, "&New Window", eventHandler, VIEWER_WINDOW_OPEN); + InsertMenuItem(file, "&Open", eventHandler, VIEWER_FILE_OPEN); + InsertMenuItem(file, "&View Source", eventHandler, VIEW_SOURCE); + + InsertMenuItem(samples, "demo #0", eventHandler, VIEWER_DEMO0); + InsertMenuItem(samples, "demo #1", eventHandler, VIEWER_DEMO1); + InsertMenuItem(samples, "demo #2", eventHandler, VIEWER_DEMO2); + InsertMenuItem(samples, "demo #3", eventHandler, VIEWER_DEMO3); + InsertMenuItem(samples, "demo #4", eventHandler, VIEWER_DEMO4); + InsertMenuItem(samples, "demo #5", eventHandler, VIEWER_DEMO5); + InsertMenuItem(samples, "demo #6", eventHandler, VIEWER_DEMO6); + InsertMenuItem(samples, "demo #7", eventHandler, VIEWER_DEMO7); + InsertMenuItem(samples, "demo #8", eventHandler, VIEWER_DEMO8); + InsertMenuItem(samples, "demo #9", eventHandler, VIEWER_DEMO9); + InsertMenuItem(samples, "demo #10", eventHandler, VIEWER_DEMO10); + InsertMenuItem(samples, "demo #11", eventHandler, VIEWER_DEMO11); + InsertMenuItem(samples, "demo #12", eventHandler, VIEWER_DEMO12); + InsertMenuItem(samples, "demo #13", eventHandler, VIEWER_DEMO13); + InsertMenuItem(samples, "demo #14", eventHandler, VIEWER_DEMO14); + InsertMenuItem(samples, "demo #15", eventHandler, VIEWER_DEMO15); + InsertMenuItem(samples, "demo #16", eventHandler, VIEWER_DEMO16); + InsertMenuItem(samples, "demo #17", eventHandler, VIEWER_DEMO17); + + file->insertItem("&Samples", samples); + + InsertMenuItem(file, "&Test Sites", eventHandler, VIEWER_TOP100); + + InsertMenuItem(xptests, "Toolbar Test 1", eventHandler, VIEWER_XPTOOLKITTOOLBAR1); + InsertMenuItem(xptests, "Tree Test 1", eventHandler, VIEWER_XPTOOLKITTREE1); + + file->insertItem("XPToolkit Tests", xptests); + + InsertMenuItem(file, nsnull, nsnull, 0); + InsertMenuItem(file, "Print Preview", eventHandler, VIEWER_ONE_COLUMN); + InsertMenuItem(file, "Print", eventHandler, VIEWER_PRINT); + InsertMenuItem(file, nsnull, nsnull, 0); + InsertMenuItem(file, "&Exit", eventHandler, VIEWER_EXIT); + + InsertMenuItem(edit, "Cu&t", eventHandler, VIEWER_EDIT_CUT); + InsertMenuItem(edit, "&Copy", eventHandler, VIEWER_EDIT_COPY); + InsertMenuItem(edit, "&Paste", eventHandler, VIEWER_EDIT_PASTE); + InsertMenuItem(edit, nsnull, nsnull, 0); + InsertMenuItem(edit, "Select All", eventHandler, VIEWER_EDIT_SELECTALL); + InsertMenuItem(edit, nsnull, nsnull, 0); + InsertMenuItem(edit, "Find in Page", eventHandler, VIEWER_EDIT_FINDINPAGE); + + InsertMenuItem(debug, "&Visual Debugging", eventHandler, VIEWER_VISUAL_DEBUGGING); + InsertMenuItem(debug, nsnull, nsnull, 0); + + InsertMenuItem(eventdebug, "Toggle Paint Flashing", eventHandler, VIEWER_TOGGLE_PAINT_FLASHING); + InsertMenuItem(eventdebug, "Toggle Paint Dumping", eventHandler, VIEWER_TOGGLE_PAINT_DUMPING); + InsertMenuItem(eventdebug, "Toggle Invalidate Dumping", eventHandler, VIEWER_TOGGLE_INVALIDATE_DUMPING); + InsertMenuItem(eventdebug, "Toggle Event Dumping", eventHandler, VIEWER_TOGGLE_EVENT_DUMPING); + InsertMenuItem(eventdebug, nsnull, nsnull, 0); + InsertMenuItem(eventdebug, "Toggle Motion Event Dumping", eventHandler, VIEWER_TOGGLE_MOTION_EVENT_DUMPING); + InsertMenuItem(eventdebug, "Toggle Crossing Event Dumping", eventHandler, VIEWER_TOGGLE_CROSSING_EVENT_DUMPING); + + debug->insertItem("Event Debugging", eventdebug); + + InsertMenuItem(debug, nsnull, nsnull, 0); + InsertMenuItem(debug, "&Reflow Test", eventHandler, VIEWER_REFLOW_TEST); + InsertMenuItem(debug, nsnull, nsnull, 0); + InsertMenuItem(debug, "Dump &Content", eventHandler, VIEWER_DUMP_CONTENT); + InsertMenuItem(debug, "Dump &Frames", eventHandler, VIEWER_DUMP_FRAMES); + InsertMenuItem(debug, "Dump &Views", eventHandler, VIEWER_DUMP_VIEWS); + InsertMenuItem(debug, nsnull, nsnull, 0); + InsertMenuItem(debug, "Dump &Style Sheets", eventHandler, VIEWER_DUMP_STYLE_SHEETS); + InsertMenuItem(debug, "Dump &Style Contexts", eventHandler, VIEWER_DUMP_STYLE_CONTEXTS); + InsertMenuItem(debug, nsnull, nsnull, 0); +// InsertMenuItem(debug, "Show Content Size", eventHandler, VIEWER_SHOW_CONTENT_SIZE); +// InsertMenuItem(debug, "Show Frame Size", eventHandler, VIEWER_SHOW_FRAME_SIZE); +// InsertMenuItem(debug, "Show Style Size", eventHandler, VIEWER_SHOW_STYLE_SIZE); + InsertMenuItem(debug, nsnull, nsnull, 0); + InsertMenuItem(debug, "Debug Save", eventHandler, VIEWER_DEBUGSAVE); + InsertMenuItem(debug, "Debug Output Text", eventHandler, VIEWER_DISPLAYTEXT); + InsertMenuItem(debug, "Debug Output HTML", eventHandler, VIEWER_DISPLAYHTML); + InsertMenuItem(debug, "Debug Toggle Selection", eventHandler, VIEWER_TOGGLE_SELECTION); + InsertMenuItem(debug, nsnull, nsnull, 0); + InsertMenuItem(debug, "Debug Robot", eventHandler, VIEWER_DEBUGROBOT); + InsertMenuItem(debug, nsnull, nsnull, 0); +// InsertMenuItem(debug, "Show Content Quality", eventHandler, VIEWER_SHOW_CONTENT_QUALITY); + InsertMenuItem(debug, nsnull, nsnull, 0); + debug->insertItem("Style", style); + + InsertMenuItem(select, "List Available Sheets", eventHandler, VIEWER_SELECT_STYLE_LIST); + InsertMenuItem(select, nsnull, nsnull, 0); + InsertMenuItem(select, "Select Default", eventHandler, VIEWER_SELECT_STYLE_DEFAULT); + InsertMenuItem(select, nsnull, nsnull, 0); + InsertMenuItem(select, "Select Alternative 1", eventHandler, VIEWER_SELECT_STYLE_ONE); + InsertMenuItem(select, "Select Alternative 2", eventHandler, VIEWER_SELECT_STYLE_TWO); + InsertMenuItem(select, "Select Alternative 3", eventHandler, VIEWER_SELECT_STYLE_THREE); + InsertMenuItem(select, "Select Alternative 4", eventHandler, VIEWER_SELECT_STYLE_FOUR); + + style->insertItem("Select &Style Sheet", select); + + InsertMenuItem(compatibility, "Use DTD", eventHandler, VIEWER_USE_DTD_MODE); + InsertMenuItem(compatibility, "Nav Quirks", eventHandler, VIEWER_NAV_QUIRKS_MODE); + InsertMenuItem(compatibility, "Standard", eventHandler, VIEWER_STANDARD_MODE); + + style->insertItem("&Compatibility Mode", compatibility); + + InsertMenuItem(render, "Native", eventHandler, VIEWER_NATIVE_WIDGET_MODE); + InsertMenuItem(render, "Gfx", eventHandler, VIEWER_GFX_WIDGET_MODE); + + style->insertItem("&Widget Render Mode", render); + + InsertMenuItem(tools, "&JavaScript Console", eventHandler, JS_CONSOLE); + InsertMenuItem(tools, "&Editor Mode", eventHandler, EDITOR_MODE); + + menuBar->insertItem("&File", file); + menuBar->insertItem("&Edit", edit); + menuBar->insertItem("&Debug", debug); + menuBar->insertItem("&Tools", tools); + + qDebug("menubar height = %d", menuBar->height()); + menuBar->resize(menuBar->sizeHint()); + menuBar->show(); +} + + +void InsertMenuItem(QPopupMenu * popup, const char * string, QObject * receiver, int id) +{ + if (popup) + { + if (string) + { + popup->insertItem(string, id); + + //popup->connectItem(id, receiver, SLOT(MenuItemActivated(int))); +#if 0 + popup->insertItem(string, + receiver, + SLOT(MenuItemActivated(int)), + 0, + id); +#endif + } + else + { + popup->insertSeparator(); + } + } +} diff --git a/mozilla/webshell/tests/viewer/unix/qt/nsQtMenu.h b/mozilla/webshell/tests/viewer/unix/qt/nsQtMenu.h new file mode 100644 index 00000000000..fa052d7e720 --- /dev/null +++ b/mozilla/webshell/tests/viewer/unix/qt/nsQtMenu.h @@ -0,0 +1,74 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef _nsMotifMenu_h_ +#define _nsMotifMenu_h_ + +#include "nscore.h" + +#include +#include + +class nsBrowserWindow; +class nsIWidget; +class QWidget; + +class nsMenuEventHandler : public QObject +{ + Q_OBJECT +public: + nsMenuEventHandler(nsBrowserWindow * window); + +public slots: + void MenuItemActivated(int id); + +private: + nsBrowserWindow * mWindow; +}; + + +void CreateViewerMenus(nsIWidget * aParent, + void * data, + QWidget ** aMenuBarOut); +void InsertMenuItem(QPopupMenu * popup, + const char * string, + QObject * receiver, + int id); + +#endif // _nsMotifMenu_h_ diff --git a/mozilla/widget/src/Makefile.in b/mozilla/widget/src/Makefile.in index 686e98a00c1..bd9b3b5488c 100644 --- a/mozilla/widget/src/Makefile.in +++ b/mozilla/widget/src/Makefile.in @@ -86,6 +86,10 @@ DIRS += xlibxtbin DIRS += xlib endif +ifdef MOZ_ENABLE_QT +DIRS += qt +endif + ifdef MOZ_ENABLE_PHOTON DIRS += photon endif diff --git a/mozilla/widget/src/gtk2/nsWindow.cpp b/mozilla/widget/src/gtk2/nsWindow.cpp index 271a5657c74..b3aea062670 100644 --- a/mozilla/widget/src/gtk2/nsWindow.cpp +++ b/mozilla/widget/src/gtk2/nsWindow.cpp @@ -144,8 +144,8 @@ static void style_set_cb (GtkWidget *widget, #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ -static GdkFilterReturn plugin_window_filter_func (GdkXEvent *gdk_xevent, - GdkEvent *event, +static GdkFilterReturn plugin_window_filter_func (GdkXEvent *gdk_xevent, + GdkEvent *event, gpointer data); static GdkFilterReturn plugin_client_message_filter (GdkXEvent *xevent, GdkEvent *event, @@ -181,7 +181,7 @@ static void drag_data_received_event_cb(GtkWidget *aWidget, /* initialization static functions */ static nsresult initialize_prefs (void); - + // this is the last window that had a drag event happen on it. nsWindow *nsWindow::mLastDragMotionWindow = NULL; PRBool nsWindow::sIsDraggingOutOf = PR_FALSE; @@ -258,7 +258,7 @@ nsWindow::nsWindow() // It's OK if either of these fail, but it may not be one day. initialize_prefs(); } - + if (mLastDragMotionWindow == this) mLastDragMotionWindow = NULL; mDragMotionWidget = 0; @@ -396,7 +396,7 @@ nsWindow::Destroy(void) gtk_widget_destroy(GTK_WIDGET(mContainer)); mContainer = nsnull; } - + if (mDrawingarea) { g_object_unref(mDrawingarea); mDrawingarea = nsnull; @@ -525,7 +525,7 @@ nsWindow::PlaceBehind(nsTopLevelWidgetZPlacement aPlacement, nsIWidget *aWidget, PRBool aActivate) { - return NS_ERROR_NOT_IMPLEMENTED; + return NS_ERROR_NOT_IMPLEMENTED; } NS_IMETHODIMP @@ -645,11 +645,11 @@ nsWindow::SetFocus(PRBool aRaise) IMESetFocus(); #endif - LOGFOCUS((" widget now has focus - dispatching events [%p]\n", + LOGFOCUS((" widget now has focus - dispatching events [%p]\n", (void *)this)); DispatchGotFocusEvent(); - + // unset the activate flag if (owningWindow->mActivatePending) { owningWindow->mActivatePending = PR_FALSE; @@ -951,7 +951,7 @@ nsWindow::SetIcon(const nsAString& aIconSpec) if (iconFile) { iconFile->GetNativePath(path); iconList.AppendCString(path); - } + } // Get the 16px icon path as well ResolveIconName(aIconSpec, NS_LITERAL_STRING("16.xpm"), @@ -1052,7 +1052,7 @@ nsWindow::CaptureMouse(PRBool aCapture) if (!mDrawingarea) return NS_OK; - GtkWidget *widget = + GtkWidget *widget = get_gtk_widget_for_gdk_window(mDrawingarea->inner_window); if (aCapture) { @@ -1075,7 +1075,7 @@ nsWindow::CaptureRollupEvents(nsIRollupListener *aListener, if (!mDrawingarea) return NS_OK; - GtkWidget *widget = + GtkWidget *widget = get_gtk_widget_for_gdk_window(mDrawingarea->inner_window); LOG(("CaptureRollupEvents %p\n", (void *)this)); @@ -1113,7 +1113,7 @@ nsWindow::GetAttention(PRInt32 aCycleCount) if (top_window && GTK_WIDGET_VISIBLE(top_window)) { gdk_window_show(top_window->window); } - + return NS_OK; } @@ -1624,7 +1624,7 @@ nsWindow::OnKeyReleaseEvent(GtkWidget *aWidget, GdkEventKey *aEvent) #endif nsEventStatus status; - + // unset the repeat flag mInKeyRepeat = PR_FALSE; @@ -1722,7 +1722,7 @@ nsWindow::ThemeChanged() return; // Dispatch NS_THEMECHANGED to all child windows - GList *children = + GList *children = gdk_window_peek_children(mDrawingarea->inner_window); while (children) { GdkWindow *gdkWin = GDK_WINDOW(children->data); @@ -1817,7 +1817,7 @@ nsWindow::OnDragMotionEvent(GtkWidget *aWidget, // we're done with the drag motion event. notify the drag service. dragSessionGTK->TargetEndDragMotion(aWidget, aDragContext, aTime); - + // and unset our context dragSessionGTK->TargetSetLastContext(0, 0, 0); @@ -1867,7 +1867,7 @@ nsWindow::OnDragDropEvent(GtkWidget *aWidget, nscoord retx = 0; nscoord rety = 0; - + GdkWindow *thisWindow = aWidget->window; GdkWindow *returnWindow = NULL; returnWindow = get_inner_gdk_window(thisWindow, aX, aY, &retx, &rety); @@ -2000,7 +2000,7 @@ nsWindow::OnDragEnter(nscoord aX, nscoord aY) // XXX Do we want to pass this on only if the event's subwindow is null? LOG(("nsWindow::OnDragEnter(%p)\n", this)); - + nsMouseEvent event(NS_DRAGDROP_ENTER, this); event.point.x = aX; @@ -2064,7 +2064,7 @@ nsWindow::NativeCreate(nsIWidget *aParent, if (parentGdkWindow) { // find the mozarea on that window gpointer user_data = nsnull; - user_data = g_object_get_data(G_OBJECT(parentGdkWindow), + user_data = g_object_get_data(G_OBJECT(parentGdkWindow), "mozdrawingarea"); parentArea = MOZ_DRAWINGAREA(user_data); @@ -2131,7 +2131,7 @@ nsWindow::NativeCreate(nsIWidget *aParent, else if (mWindowType == eWindowType_popup) { mShell = gtk_window_new(GTK_WINDOW_POPUP); if (topLevelParent) { - gtk_window_set_transient_for(GTK_WINDOW(mShell), + gtk_window_set_transient_for(GTK_WINDOW(mShell), topLevelParent); mTransientParent = topLevelParent; @@ -2199,7 +2199,7 @@ nsWindow::NativeCreate(nsIWidget *aParent, break; } // Disable the double buffer because it will make the caret crazy - // For bug#153805 (Gtk2 double buffer makes carets misbehave) + // For bug#153805 (Gtk2 double buffer makes carets misbehave) if (mContainer) gtk_widget_set_double_buffered (GTK_WIDGET(mContainer),FALSE); @@ -2266,7 +2266,7 @@ nsWindow::NativeCreate(nsIWidget *aParent, G_CALLBACK(scroll_event_cb), NULL); g_signal_connect(G_OBJECT(mContainer), "visibility_notify_event", G_CALLBACK(visibility_notify_event_cb), NULL); - + gtk_drag_dest_set((GtkWidget *)mContainer, (GtkDestDefaults)0, NULL, @@ -2784,7 +2784,7 @@ nsWindow::GetToplevelWidget(GtkWidget **aWidget) return; } - if (!mDrawingarea) + if (!mDrawingarea) return; GtkWidget *widget = @@ -2798,7 +2798,7 @@ nsWindow::GetToplevelWidget(GtkWidget **aWidget) void nsWindow::GetContainerWindow(nsWindow **aWindow) { - if (!mDrawingarea) + if (!mDrawingarea) return; GtkWidget *owningWidget = @@ -2828,7 +2828,7 @@ nsWindow::SetupPluginPort(void) xattrs.your_event_mask | SubstructureNotifyMask); - gdk_window_add_filter(mDrawingarea->inner_window, + gdk_window_add_filter(mDrawingarea->inner_window, plugin_window_filter_func, this); @@ -2938,9 +2938,9 @@ nsWindow::SetNonXEmbedPluginFocus() gdk_error_trap_pop(); gPluginFocusWindow = this; gdk_window_add_filter(NULL, plugin_client_message_filter, this); - + LOGFOCUS(("nsWindow::SetNonXEmbedPluginFocus oldfocus=%p new=%p\n", - mOldFocusWindow, + mOldFocusWindow, GDK_WINDOW_XWINDOW(mDrawingarea->inner_window))); } @@ -2962,11 +2962,11 @@ nsWindow::LoseNonXEmbedPluginFocus() &curFocusWindow, &focusState); - // we only switch focus between plugin window and focus proxy. If the - // current focused window is not the plugin window, just removing the + // we only switch focus between plugin window and focus proxy. If the + // current focused window is not the plugin window, just removing the // event filter that blocks the WM_TAKE_FOCUS is enough. WM and gtk2 // will take care of the focus later. - if (!curFocusWindow || + if (!curFocusWindow || curFocusWindow == GDK_WINDOW_XWINDOW(mDrawingarea->inner_window)) { gdk_error_trap_push(); @@ -3033,9 +3033,9 @@ nsWindow::HideWindowChrome(PRBool aShouldHide) // confused if we change the window decorations while the window // is visible. #if GTK_CHECK_VERSION(2,2,0) - if (aShouldHide) + if (aShouldHide) gdk_window_fullscreen (mShell->window); - else + else gdk_window_unfullscreen (mShell->window); #else gdk_window_hide(mShell->window); @@ -3550,7 +3550,7 @@ plugin_window_filter_func (GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data nsWindow *nswindow = (nsWindow*)data; GdkFilterReturn return_val; - + xevent = (XEvent *)gdk_xevent; return_val = GDK_FILTER_CONTINUE; @@ -3602,7 +3602,7 @@ plugin_window_filter_func (GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data } /* static */ -GdkFilterReturn +GdkFilterReturn plugin_client_message_filter (GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data) @@ -3624,12 +3624,12 @@ plugin_client_message_filter (GdkXEvent *gdk_xevent, Display *dpy ; dpy = GDK_WINDOW_XDISPLAY((GdkWindow*)(gPluginFocusWindow-> GetNativeData(NS_NATIVE_WINDOW))); - if (gdk_x11_get_xatom_by_name("WM_PROTOCOLS") + if (gdk_x11_get_xatom_by_name("WM_PROTOCOLS") != xevent->xclient.message_type) { return return_val; } - - if ((Atom) xevent->xclient.data.l[0] == + + if ((Atom) xevent->xclient.data.l[0] == gdk_x11_get_xatom_by_name("WM_TAKE_FOCUS")) { // block it from gtk2.0 focus proxy return_val = GDK_FILTER_REMOVE; @@ -3755,11 +3755,11 @@ nsWindow::UpdateDragStatus(nsMouseEvent &aEvent, { // default is to do nothing int action = nsIDragService::DRAGDROP_ACTION_NONE; - + // set the default just in case nothing matches below if (aDragContext->actions & GDK_ACTION_DEFAULT) action = nsIDragService::DRAGDROP_ACTION_MOVE; - + // first check to see if move is set if (aDragContext->actions & GDK_ACTION_MOVE) action = nsIDragService::DRAGDROP_ACTION_MOVE; @@ -3767,7 +3767,7 @@ nsWindow::UpdateDragStatus(nsMouseEvent &aEvent, // then fall to the others else if (aDragContext->actions & GDK_ACTION_LINK) action = nsIDragService::DRAGDROP_ACTION_LINK; - + // copy is ctrl else if (aDragContext->actions & GDK_ACTION_COPY) action = nsIDragService::DRAGDROP_ACTION_COPY; @@ -3793,7 +3793,7 @@ drag_motion_event_cb(GtkWidget *aWidget, nsWindow *window = get_window_for_gtk_widget(aWidget); if (!window) return FALSE; - + return window->OnDragMotionEvent(aWidget, aDragContext, aX, aY, aTime, aData); @@ -3825,7 +3825,7 @@ drag_drop_event_cb(GtkWidget *aWidget, if (!window) return FALSE; - + return window->OnDragDropEvent(aWidget, aDragContext, aX, aY, aTime, aData); @@ -3876,7 +3876,7 @@ nsWindow::ResetDragMotionTimer(GtkWidget *aWidget, GdkDragContext *aDragContext, gint aX, gint aY, guint aTime) { - + // We have to be careful about ref ordering here. if aWidget == // mDraMotionWidget be careful not to let the refcnt drop to zero. // Same with the drag context. @@ -3908,7 +3908,7 @@ nsWindow::ResetDragMotionTimer(GtkWidget *aWidget, if (!aWidget) { return; } - + // otherwise we create a new timer mDragMotionTimerID = gtk_timeout_add(100, (GtkFunction)DragMotionTimerCallback, @@ -4063,7 +4063,7 @@ nsWindow::GetRootAccessible(nsIAccessible** aAccessible) *aAccessible = docAcc; NS_ADDREF(*aAccessible); break; - } + } docAcc->GetParent(getter_AddRefs(parentAcc)); docAcc = parentAcc; } @@ -4228,7 +4228,7 @@ nsWindow::IMEComposeText (const PRUnichar *aText, nsEventStatus status; DispatchEvent(&textEvent, status); - + if (textEvent.rangeArray) { delete[] textEvent.rangeArray; } @@ -4276,7 +4276,7 @@ nsWindow::IMECreateContext(void) } PRBool -nsWindow::IMEFilterEvent(GdkEventKey *aEvent) +nsWindow::IMEFilterEvent(GdkEventKey *aEvent) { GtkIMContext *im = IMEGetContext(); if (!im) @@ -4320,11 +4320,11 @@ IM_preedit_changed_cb(GtkIMContext *aContext, nsWindow *window = gFocusWindow ? gFocusWindow : gIMEFocusWindow; if (!window) return; - + // Should use cursor_pos ? gtk_im_context_get_preedit_string(aContext, &preedit_string, &feedback_list, &cursor_pos); - + LOGIM(("preedit string is: %s length is: %d\n", preedit_string, strlen(preedit_string))); @@ -4443,7 +4443,7 @@ IM_set_text_range(const PRInt32 aLen, aTextRangeListResult = NULL; return; } - + PangoAttrIterator * aFeedbackIterator; aFeedbackIterator = pango_attr_list_get_iterator((PangoAttrList*)aFeedback); //(NS_REINTERPRET_CAST(PangoAttrList*, aFeedback)); @@ -4460,7 +4460,7 @@ IM_set_text_range(const PRInt32 aLen, aMaxLenOfTextRange = 2*aLen + 1; *aTextRangeListResult = new nsTextRange[aMaxLenOfTextRange]; NS_ASSERTION(*aTextRangeListResult, "No enough memory."); - + // Set caret's postion SET_FEEDBACKTYPE(0, NS_TEXTRANGE_CARETPOSITION); START_OFFSET(0) = aLen; @@ -4515,7 +4515,7 @@ IM_set_text_range(const PRInt32 aLen, count++; START_OFFSET(count) = 0; END_OFFSET(count) = 0; - + uniStr = NULL; if (start > 0) { uniStr = g_utf8_to_utf16(aPreeditString, start, @@ -4525,7 +4525,7 @@ IM_set_text_range(const PRInt32 aLen, START_OFFSET(count) = uniStrLen; g_free(uniStr); } - + uniStr = NULL; uniStr = g_utf8_to_utf16(aPreeditString + start, end - start, NULL, &uniStrLen, NULL); diff --git a/mozilla/widget/src/qt/Makefile.in b/mozilla/widget/src/qt/Makefile.in new file mode 100644 index 00000000000..e704a812f87 --- /dev/null +++ b/mozilla/widget/src/qt/Makefile.in @@ -0,0 +1,116 @@ +# +# The contents of this file are subject to the Netscape 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/NPL/ +# +# 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 mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): +# John C. Griggs +# + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = widget +LIBRARY_NAME = widget_qt +EXPORT_LIBRARY = 1 +IS_COMPONENT = 1 +MODULE_NAME = nsWidgetQtModule +GRE_MODULE = 1 + +REQUIRES = xpcom \ + string \ + gfx \ + layout \ + content \ + dom \ + appshell \ + pref \ + uconv \ + necko \ + $(NULL) + +CPPSRCS = \ + $(MOCSRCS) \ + nsAppShell.cpp \ + nsBidiKeyboard.cpp \ + nsClipboard.cpp \ + nsCommonWidget.cpp \ + nsDragService.cpp \ + nsEventQueueWatcher.cpp \ + nsLookAndFeel.cpp \ + nsMime.cpp \ + nsQtEventDispatcher.cpp \ + nsSound.cpp \ + nsToolkit.cpp \ + nsWidgetFactory.cpp \ + nsScrollbar.cpp \ + nsWindow.cpp \ + nsFilePicker.cpp \ + $(NULL) + +MOCSRCS = \ + moc_nsMime.cpp \ + moc_nsEventQueueWatcher.cpp \ + moc_nsQtEventDispatcher.cpp \ + moc_nsScrollbar.cpp \ + $(NULL) + +SHARED_LIBRARY_LIBS = $(DIST)/lib/libxpwidgets_s.a + +EXTRA_DSO_LDOPTS = \ + $(MOZ_COMPONENT_LIBS) \ + -lgkgfx \ + -I$(topsrcdir)/gfx/src/qt \ + $(MOZ_JS_LIBS) \ + $(NULL) + +EXTRA_DSO_LDOPTS += -L$(DIST)/lib $(MOZ_QT_LDFLAGS) $(MOZ_XLIB_LDFLAGS) + +# If not primary toolkit, install in secondary path +ifneq (qt,$(MOZ_WIDGET_TOOLKIT)) +INACTIVE_COMPONENT = 1 +endif + +include $(topsrcdir)/config/rules.mk + +CXXFLAGS += $(MOZ_QT_CFLAGS) +CFLAGS += $(MOZ_QT_CFLAGS) + +DEFINES += -D_IMPL_NS_WIDGET + +ifeq ($(OS_ARCH), Linux) +DEFINES += -D_BSD_SOURCE +endif +ifeq ($(OS_ARCH), SunOS) +ifndef GNU_CC +# When using Sun's WorkShop compiler, including +# /wherever/workshop-5.0/SC5.0/include/CC/std/time.h +# causes most of these compiles to fail with: +# line 29: Error: Multiple declaration for std::tm. +# So, this gets around the problem. +DEFINES += -D_TIME_H=1 +endif +endif + +LOCAL_INCLUDES = -I$(srcdir)/../xpwidgets \ + -I$(srcdir) \ + -I$(topsrcdir)/gfx/src/qt \ + $(NULL) + diff --git a/mozilla/widget/src/qt/nsAppShell.cpp b/mozilla/widget/src/qt/nsAppShell.cpp new file mode 100644 index 00000000000..300435845ef --- /dev/null +++ b/mozilla/widget/src/qt/nsAppShell.cpp @@ -0,0 +1,228 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 "nsAppShell.h" + +#include "nsEventQueueWatcher.h" + +#include "nsIEventQueueService.h" +#include "nsIServiceManagerUtils.h" +#include "nsIEventQueue.h" + +#include + +nsAppShell::nsAppShell() +{ +} + +nsAppShell::~nsAppShell() +{ +} + +//------------------------------------------------------------------------- +// nsISupports implementation macro +//------------------------------------------------------------------------- +NS_IMPL_ISUPPORTS1(nsAppShell, nsIAppShell) + +NS_IMETHODIMP +nsAppShell::Create(int *argc, char **argv) +{ + qDebug("Qt: nsAppShell::create"); + + /** + * If !qApp then it means we're not embedding + * but running a full application. + */ + if (!qApp) { + //oh, this is fun. yes, argc can be null here + int argcSafe = 0; + if (argc) + argcSafe = *argc; + + new QApplication(argcSafe, argv); + + if (argc) + *argc = argcSafe; + } + + return NS_OK; +} + +NS_IMETHODIMP +nsAppShell::Run(void) +{ + if (!mEventQueue) + Spinup(); + + if (!mEventQueue) + return NS_ERROR_NOT_INITIALIZED; + + qApp->exec(); + + Spindown(); + + return NS_OK; +} + +//i don't like this method flow, but i left it because it follows what +//other ports are doing here +NS_IMETHODIMP +nsAppShell::Spinup() +{ + nsresult rv = NS_OK; + + // Get the event queue service + nsCOMPtr eventQService = + do_GetService(NS_EVENTQUEUESERVICE_CONTRACTID,&rv); + + if (NS_FAILED(rv)) { + NS_WARNING("Could not obtain event queue service"); + return rv; + } + + //Get the event queue for the thread. + rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, + getter_AddRefs(mEventQueue)); + + // If a queue already present use it. + if (mEventQueue) + goto done; + + // Create the event queue for the thread + rv = eventQService->CreateThreadEventQueue(); + if (NS_FAILED(rv)) { + NS_WARNING("Could not create the thread event queue"); + return rv; + } + + // Ask again for the event queue now that we have create one. + rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD,getter_AddRefs(mEventQueue)); + if (NS_FAILED(rv)) { + NS_ASSERTION("Could not obtain the thread event queue",PR_FALSE); + return rv; + } +done: + AddEventQueue(mEventQueue); + + return NS_OK; +} + +NS_IMETHODIMP +nsAppShell::Spindown(void) +{ + // stop listening to the event queue + if (mEventQueue) { + RemoveEventQueue(mEventQueue); + mEventQueue->ProcessPendingEvents(); + mEventQueue = nsnull; + } + + return NS_OK; +} + +NS_IMETHODIMP +nsAppShell::ListenToEventQueue(nsIEventQueue *aQueue, PRBool aListen) +{ + // whoever came up with the idea of passing bool to this + // method to decide what its effect should be is getting + // his ass kicked + + if (aListen) + AddEventQueue(aQueue); + else + RemoveEventQueue(aQueue); + + return NS_OK; +} + +void +nsAppShell::AddEventQueue(nsIEventQueue *aQueue) +{ + nsEventQueueWatcher *que = 0; + + if ((que = mQueueDict.find(aQueue->GetEventQueueSelectFD()))) { + que->ref(); + } + else { + mQueueDict.insert(aQueue->GetEventQueueSelectFD(), + new nsEventQueueWatcher(aQueue, qApp)); + } +} + +void +nsAppShell::RemoveEventQueue(nsIEventQueue *aQueue) +{ + nsEventQueueWatcher *qtQueue = 0; + + if ((qtQueue = mQueueDict.find(aQueue->GetEventQueueSelectFD()))) { + qtQueue->DataReceived(); + qtQueue->deref(); + if (qtQueue->count <= 0) { + mQueueDict.take(aQueue->GetEventQueueSelectFD()); + delete qtQueue; + } + } +} + +NS_IMETHODIMP +nsAppShell::GetNativeEvent(PRBool &aRealEvent, void * &aEvent) +{ + aRealEvent = PR_FALSE; + aEvent = 0; + + return NS_OK; +} + +NS_IMETHODIMP +nsAppShell::DispatchNativeEvent(PRBool aRealEvent, void *aEvent) +{ + if (!mEventQueue) + return NS_ERROR_NOT_INITIALIZED; + + qApp->processEvents(); + + return NS_OK; +} + +NS_IMETHODIMP +nsAppShell::Exit(void) +{ + qApp->exit(0); + return NS_OK; +} diff --git a/mozilla/widget/src/qt/nsAppShell.h b/mozilla/widget/src/qt/nsAppShell.h new file mode 100644 index 00000000000..fc409a132ea --- /dev/null +++ b/mozilla/widget/src/qt/nsAppShell.h @@ -0,0 +1,78 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 NSAPPSHELL_H +#define NSAPPSHELL_H + +#include "nsIAppShell.h" +#include "nsIEventQueue.h" +#include "nsCOMPtr.h" +#include "prenv.h" + +#include + +class nsEventQueueWatcher; + +/** + * Gecko Qt application. + * + * Please note that the Create method on it _has_ to be + * called _after_ QApplication has been instantiated if + * we want to embed it. + */ +class nsAppShell : public nsIAppShell +{ +public: + nsAppShell(); + ~nsAppShell(); + + NS_DECL_ISUPPORTS + NS_DECL_NSIAPPSHELL + +private: + void AddEventQueue(nsIEventQueue *equeue); + void RemoveEventQueue(nsIEventQueue *equeue); + +private: + nsCOMPtr mEventQueue; + PRInt32 mID; + QIntDict mQueueDict; +}; + +#endif diff --git a/mozilla/widget/src/qt/nsBidiKeyboard.cpp b/mozilla/widget/src/qt/nsBidiKeyboard.cpp new file mode 100644 index 00000000000..4d2a6626238 --- /dev/null +++ b/mozilla/widget/src/qt/nsBidiKeyboard.cpp @@ -0,0 +1,46 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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 IBM code. + * + * The Initial Developer of the Original Code is IBM. + * Portions created by IBM are + * Copyright (C) International Business Machines + * Corporation, 2000. All Rights Reserved. + * + * Contributor(s): Simon Montagu + */ + +#include "nsBidiKeyboard.h" + +NS_IMPL_ISUPPORTS1(nsBidiKeyboard, nsIBidiKeyboard) + +nsBidiKeyboard::nsBidiKeyboard() : nsIBidiKeyboard() +{ +} + +nsBidiKeyboard::~nsBidiKeyboard() +{ +} + +NS_IMETHODIMP nsBidiKeyboard::IsLangRTL(PRBool *aIsRTL) +{ + *aIsRTL = PR_FALSE; + // XXX Insert platform specific code to determine keyboard direction + return NS_OK; +} + +NS_IMETHODIMP nsBidiKeyboard::SetLangFromBidiLevel(PRUint8 aLevel) +{ + // XXX Insert platform specific code to set keyboard language + return NS_OK; +} diff --git a/mozilla/widget/src/qt/nsBidiKeyboard.h b/mozilla/widget/src/qt/nsBidiKeyboard.h new file mode 100644 index 00000000000..107f09a4501 --- /dev/null +++ b/mozilla/widget/src/qt/nsBidiKeyboard.h @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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 IBM code. + * + * The Initial Developer of the Original Code is IBM. + * Portions created by IBM are + * Copyright (C) International Business Machines + * Corporation, 2000. All Rights Reserved. + * + * Contributor(s): Simon Montagu + */ + +#ifndef __nsBidiKeyboard +#define __nsBidiKeyboard +#include "nsIBidiKeyboard.h" + +class nsBidiKeyboard : public nsIBidiKeyboard +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIBIDIKEYBOARD + + nsBidiKeyboard(); + virtual ~nsBidiKeyboard(); + /* additional members */ +}; + + +#endif // __nsBidiKeyboard diff --git a/mozilla/widget/src/qt/nsClipboard.cpp b/mozilla/widget/src/qt/nsClipboard.cpp new file mode 100644 index 00000000000..8bfba2f815f --- /dev/null +++ b/mozilla/widget/src/qt/nsClipboard.cpp @@ -0,0 +1,362 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * Denis Issoupov + * John C. Griggs + * Dan Rosen + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsClipboard.h" +#include "nsMime.h" +#include "nsCOMPtr.h" +#include "nsCRT.h" +#include "nsString.h" +#include "nsISupportsArray.h" +#include "nsXPCOM.h" +#include "nsISupportsPrimitives.h" +#include "nsXPIDLString.h" +#include "nsPrimitiveHelpers.h" +#include "nsIComponentManager.h" +#include "nsWidgetsCID.h" + +#include +#include +#include + +// interface definitions +// static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID); + +NS_IMPL_ISUPPORTS1(nsClipboard, nsIClipboard) + +//------------------------------------------------------------------------- +// +// nsClipboard constructor +// +//------------------------------------------------------------------------- +nsClipboard::nsClipboard() : + mSelectionOwner(nsnull), + mGlobalOwner(nsnull), + mSelectionTransferable(nsnull), + mGlobalTransferable(nsnull), + mIgnoreEmptyNotification(PR_FALSE) +{ +} + +//------------------------------------------------------------------------- +// +// nsClipboard destructor +// +//------------------------------------------------------------------------- +nsClipboard::~nsClipboard() +{ +} + +#ifdef DEBUG_timeless +// XXX nsBaseClipboard will have an init method to allow for constructors to fail +NS_IMETHODIMP +nsClipboard::Init() +{ + return NS_OK; +} +#endif + +NS_IMETHODIMP +nsClipboard::SetNativeClipboardData(PRInt32 aWhichClipboard) +{ + qDebug("SetNativeClipboardData"); + mIgnoreEmptyNotification = PR_TRUE; + + nsCOMPtr transferable( + getter_AddRefs(GetTransferable(aWhichClipboard))); + + // make sure we have a good transferable + if (nsnull == transferable) { + qDebug("nsClipboard::SetNativeClipboardData(): no transferable!\n"); + return NS_ERROR_FAILURE; + } + // get flavor list that includes all flavors that can be written (including + // ones obtained through conversion) + nsCOMPtr flavorList; + nsresult errCode = transferable->FlavorsTransferableCanExport( + getter_AddRefs(flavorList)); + + if (NS_FAILED(errCode)) { + qDebug("nsClipboard::SetNativeClipboardData(): no FlavorsTransferable !\n"); + return NS_ERROR_FAILURE; + } + QClipboard *cb = QApplication::clipboard(); + nsMimeStore *mimeStore = new nsMimeStore(); + PRUint32 cnt; + + flavorList->Count(&cnt); + for (PRUint32 i = 0; i < cnt; ++i) { + nsCOMPtr genericFlavor; + + flavorList->GetElementAt(i,getter_AddRefs(genericFlavor)); + + nsCOMPtr currentFlavor(do_QueryInterface(genericFlavor)); + + if (currentFlavor) { + nsXPIDLCString flavorStr; + + currentFlavor->ToString(getter_Copies(flavorStr)); + + // add these types as selection targets + PRUint32 len; + void* data; + nsCOMPtr clip; + + transferable->GetTransferData(flavorStr,getter_AddRefs(clip),&len); + + nsPrimitiveHelpers::CreateDataFromPrimitive(flavorStr,clip,&data,len); + + QString str = QString::fromAscii((const char*)data, len); + qDebug("HERE %s '%s'", flavorStr.get(), str.latin1()); + + mimeStore->AddFlavorData(flavorStr,data,len); + } + } + cb->setData(mimeStore); + mIgnoreEmptyNotification = PR_FALSE; + return NS_OK; +} + +NS_IMETHODIMP +nsClipboard::GetNativeClipboardData(nsITransferable *aTransferable, + PRInt32 aWhichClipboard) +{ + qDebug("GetNativeClipboardData"); + // make sure we have a good transferable + if (nsnull == aTransferable) { + qDebug(" GetNativeClipboardData: Transferable is null!\n"); + return NS_ERROR_FAILURE; + } + // get flavor list that includes all acceptable flavors (including + // ones obtained through conversion) + nsCOMPtr flavorList; + nsresult errCode = aTransferable->FlavorsTransferableCanImport( + getter_AddRefs(flavorList)); + + if (NS_FAILED(errCode)) { + qDebug("nsClipboard::GetNativeClipboardData(): no FlavorsTransferable %i !\n", + errCode); + return NS_ERROR_FAILURE; + } + QClipboard *cb = QApplication::clipboard(); + QMimeSource *ms = cb->data(); + + // Walk through flavors and see which flavor matches the one being pasted: + PRUint32 cnt; + + flavorList->Count(&cnt); + + nsCAutoString foundFlavor; + for (PRUint32 i = 0; i < cnt; ++i) { + nsCOMPtr genericFlavor; + + flavorList->GetElementAt(i,getter_AddRefs(genericFlavor)); + nsCOMPtr currentFlavor(do_QueryInterface( + genericFlavor)); + + if (currentFlavor) { + nsXPIDLCString flavorStr; + + currentFlavor->ToString(getter_Copies(flavorStr)); + foundFlavor = nsCAutoString(flavorStr); + + if (ms->provides((const char*)flavorStr)) { + QByteArray ba = ms->encodedData((const char*)flavorStr); + nsCOMPtr genericDataWrapper; + PRUint32 len = (PRUint32)ba.count(); + + nsPrimitiveHelpers::CreatePrimitiveForData( + foundFlavor.get(), + (void*)ba.data(),len, + getter_AddRefs(genericDataWrapper)); + + aTransferable->SetTransferData(foundFlavor.get(), + genericDataWrapper,len); + } + } + } + return NS_OK; +} + +/* inline */ +nsITransferable * +nsClipboard::GetTransferable(PRInt32 aWhichClipboard) +{ + qDebug("GetTransferable"); + nsITransferable *transferable = nsnull; + + switch (aWhichClipboard) { + case kGlobalClipboard: + transferable = mGlobalTransferable; + break; + + case kSelectionClipboard: + transferable = mSelectionTransferable; + break; + } + NS_IF_ADDREF(transferable); + return transferable; +} + +//------------------------------------------------------------------------- +NS_IMETHODIMP +nsClipboard::HasDataMatchingFlavors(nsISupportsArray *aFlavorList, + PRInt32 aWhichClipboard, + PRBool *_retval) +{ + qDebug("HasDataMatchingFlavors"); + *_retval = PR_FALSE; + if (aWhichClipboard != kGlobalClipboard) + return NS_OK; + + QClipboard *cb = QApplication::clipboard(); + QMimeSource *ms = cb->data(); + PRUint32 cnt; + + aFlavorList->Count(&cnt); + for (PRUint32 i = 0;i < cnt; ++i) { + nsCOMPtr genericFlavor; + + aFlavorList->GetElementAt(i,getter_AddRefs(genericFlavor)); + + nsCOMPtr currentFlavor(do_QueryInterface(genericFlavor)); + if (currentFlavor) { + nsXPIDLCString flavorStr; + + currentFlavor->ToString(getter_Copies(flavorStr)); + + if (strcmp(flavorStr,kTextMime) == 0) + NS_WARNING("DO NOT USE THE text/plain DATA FLAVOR ANY MORE. USE text/unicode INSTEAD"); + + if (ms->provides((const char*)flavorStr)) { + *_retval = PR_TRUE; + qDebug("GetFormat %s\n",(const char*)flavorStr); + break; + } + } + } + return NS_OK; +} + +/** + * Sets the transferable object + */ +NS_IMETHODIMP +nsClipboard::SetData(nsITransferable *aTransferable, + nsIClipboardOwner *anOwner, + PRInt32 aWhichClipboard) +{ + qDebug("SetData"); + if ((aTransferable == mGlobalTransferable.get() + && anOwner == mGlobalOwner.get() + && aWhichClipboard == kGlobalClipboard) + || (aTransferable == mSelectionTransferable.get() + && anOwner == mSelectionOwner.get() + && aWhichClipboard == kSelectionClipboard)) { + return NS_OK; + } + EmptyClipboard(aWhichClipboard); + + switch (aWhichClipboard) { + case kSelectionClipboard: + mSelectionOwner = anOwner; + mSelectionTransferable = aTransferable; + break; + + case kGlobalClipboard: + mGlobalOwner = anOwner; + mGlobalTransferable = aTransferable; + break; + } + QApplication::clipboard()->clear(); + return SetNativeClipboardData(aWhichClipboard); +} + +/** + * Gets the transferable object + */ +NS_IMETHODIMP +nsClipboard::GetData(nsITransferable *aTransferable,PRInt32 aWhichClipboard) +{ + qDebug("GetData"); + if (nsnull != aTransferable) { + return GetNativeClipboardData(aTransferable,aWhichClipboard); + } else { + qDebug(" nsClipboard::GetData(), aTransferable is NULL.\n"); + } + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP +nsClipboard::EmptyClipboard(PRInt32 aWhichClipboard) +{ + qDebug("EmptyClipoard"); + if (mIgnoreEmptyNotification) { + return NS_OK; + } + switch(aWhichClipboard) { + case kSelectionClipboard: + if (mSelectionOwner) { + mSelectionOwner->LosingOwnership(mSelectionTransferable); + mSelectionOwner = nsnull; + } + mSelectionTransferable = nsnull; + break; + + case kGlobalClipboard: + if (mGlobalOwner) { + mGlobalOwner->LosingOwnership(mGlobalTransferable); + mGlobalOwner = nsnull; + } + mGlobalTransferable = nsnull; + break; + } + return NS_OK; +} + +NS_IMETHODIMP +nsClipboard::SupportsSelectionClipboard(PRBool *_retval) +{ + qDebug("SuppotsSelectionClipboard"); + NS_ENSURE_ARG_POINTER(_retval); + + *_retval = PR_TRUE; // we support the selection clipboard on unix. + return NS_OK; +} diff --git a/mozilla/widget/src/qt/nsClipboard.h b/mozilla/widget/src/qt/nsClipboard.h new file mode 100644 index 00000000000..94c4f5e861c --- /dev/null +++ b/mozilla/widget/src/qt/nsClipboard.h @@ -0,0 +1,78 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Denis Issoupov + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ +#ifndef nsClipboard_h__ +#define nsClipboard_h__ + +#include "nsIClipboard.h" +#include "nsITransferable.h" +#include "nsIClipboardOwner.h" +#include "nsCOMPtr.h" + +#include +#include +#include + +/* Native Qt Clipboard wrapper */ +class nsClipboard : public nsIClipboard +{ +public: + nsClipboard(); + virtual ~nsClipboard(); + + //nsISupports + NS_DECL_ISUPPORTS + + // nsIClipboard + NS_DECL_NSICLIPBOARD + +protected: + NS_IMETHOD SetNativeClipboardData(PRInt32 aWhichClipboard); + NS_IMETHOD GetNativeClipboardData(nsITransferable *aTransferable, + PRInt32 aWhichClipboard); + + inline nsITransferable *GetTransferable(PRInt32 aWhichClipboard); + + nsCOMPtr mSelectionOwner; + nsCOMPtr mGlobalOwner; + nsCOMPtr mSelectionTransferable; + nsCOMPtr mGlobalTransferable; + + PRBool mIgnoreEmptyNotification; +}; + +#endif // nsClipboard_h__ diff --git a/mozilla/widget/src/qt/nsCommonWidget.cpp b/mozilla/widget/src/qt/nsCommonWidget.cpp new file mode 100644 index 00000000000..ef5342c9bd7 --- /dev/null +++ b/mozilla/widget/src/qt/nsCommonWidget.cpp @@ -0,0 +1,1386 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 "nsCommonWidget.h" + +#include "nsGUIEvent.h" +#include "nsQtEventDispatcher.h" +#include "nsIRenderingContext.h" +#include "nsIServiceManager.h" +#include "nsGfxCIID.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" + +#include +#include +#include +#include +#include +#include + +#include +#include + +static const int WHEEL_DELTA = 120; +static const int kWindowPositionSlop = 20; + +struct nsKeyConverter +{ + int vkCode; // Platform independent key code + int keysym; // Qt key code +}; + +static void backTrace() +{ + int levels = -1; + QString s; + void* trace[256]; + int n = backtrace(trace, 256); + if (!n) + return; + char** strings = backtrace_symbols (trace, n); + + if ( levels != -1 ) + n = QMIN( n, levels ); + s = "[\n"; + + for (int i = 0; i < n; ++i) + s += QString::number(i) + + QString::fromLatin1(": ") + + QString::fromLatin1(strings[i]) + QString::fromLatin1("\n"); + s += "]\n"; + if (strings) + free (strings); + qDebug("stacktrace:\n%s", s.latin1()); +} + +static struct nsKeyConverter nsKeycodes[] = +{ +// { NS_VK_CANCEL, Qt::Key_Cancel }, + { NS_VK_BACK, Qt::Key_BackSpace }, + { NS_VK_TAB, Qt::Key_Tab }, +// { NS_VK_CLEAR, Qt::Key_Clear }, + { NS_VK_RETURN, Qt::Key_Return }, + { NS_VK_RETURN, Qt::Key_Enter }, + { NS_VK_SHIFT, Qt::Key_Shift }, + { NS_VK_CONTROL, Qt::Key_Control }, + { NS_VK_ALT, Qt::Key_Alt }, + { NS_VK_PAUSE, Qt::Key_Pause }, + { NS_VK_CAPS_LOCK, Qt::Key_CapsLock }, + { NS_VK_ESCAPE, Qt::Key_Escape }, + { NS_VK_SPACE, Qt::Key_Space }, + { NS_VK_PAGE_UP, Qt::Key_PageUp }, + { NS_VK_PAGE_DOWN, Qt::Key_PageDown }, + { NS_VK_END, Qt::Key_End }, + { NS_VK_HOME, Qt::Key_Home }, + { NS_VK_LEFT, Qt::Key_Left }, + { NS_VK_UP, Qt::Key_Up }, + { NS_VK_RIGHT, Qt::Key_Right }, + { NS_VK_DOWN, Qt::Key_Down }, + { NS_VK_PRINTSCREEN, Qt::Key_Print }, + { NS_VK_INSERT, Qt::Key_Insert }, + { NS_VK_DELETE, Qt::Key_Delete }, + + { NS_VK_0, Qt::Key_0 }, + { NS_VK_1, Qt::Key_1 }, + { NS_VK_2, Qt::Key_2 }, + { NS_VK_3, Qt::Key_3 }, + { NS_VK_4, Qt::Key_4 }, + { NS_VK_5, Qt::Key_5 }, + { NS_VK_6, Qt::Key_6 }, + { NS_VK_7, Qt::Key_7 }, + { NS_VK_8, Qt::Key_8 }, + { NS_VK_9, Qt::Key_9 }, + + { NS_VK_SEMICOLON, Qt::Key_Semicolon }, + { NS_VK_EQUALS, Qt::Key_Equal }, + + { NS_VK_A, Qt::Key_A }, + { NS_VK_B, Qt::Key_B }, + { NS_VK_C, Qt::Key_C }, + { NS_VK_D, Qt::Key_D }, + { NS_VK_E, Qt::Key_E }, + { NS_VK_F, Qt::Key_F }, + { NS_VK_G, Qt::Key_G }, + { NS_VK_H, Qt::Key_H }, + { NS_VK_I, Qt::Key_I }, + { NS_VK_J, Qt::Key_J }, + { NS_VK_K, Qt::Key_K }, + { NS_VK_L, Qt::Key_L }, + { NS_VK_M, Qt::Key_M }, + { NS_VK_N, Qt::Key_N }, + { NS_VK_O, Qt::Key_O }, + { NS_VK_P, Qt::Key_P }, + { NS_VK_Q, Qt::Key_Q }, + { NS_VK_R, Qt::Key_R }, + { NS_VK_S, Qt::Key_S }, + { NS_VK_T, Qt::Key_T }, + { NS_VK_U, Qt::Key_U }, + { NS_VK_V, Qt::Key_V }, + { NS_VK_W, Qt::Key_W }, + { NS_VK_X, Qt::Key_X }, + { NS_VK_Y, Qt::Key_Y }, + { NS_VK_Z, Qt::Key_Z }, + + { NS_VK_NUMPAD0, Qt::Key_0 }, + { NS_VK_NUMPAD1, Qt::Key_1 }, + { NS_VK_NUMPAD2, Qt::Key_2 }, + { NS_VK_NUMPAD3, Qt::Key_3 }, + { NS_VK_NUMPAD4, Qt::Key_4 }, + { NS_VK_NUMPAD5, Qt::Key_5 }, + { NS_VK_NUMPAD6, Qt::Key_6 }, + { NS_VK_NUMPAD7, Qt::Key_7 }, + { NS_VK_NUMPAD8, Qt::Key_8 }, + { NS_VK_NUMPAD9, Qt::Key_9 }, + { NS_VK_MULTIPLY, Qt::Key_Asterisk }, + { NS_VK_ADD, Qt::Key_Plus }, +// { NS_VK_SEPARATOR, Qt::Key_Separator }, + { NS_VK_SUBTRACT, Qt::Key_Minus }, + { NS_VK_DECIMAL, Qt::Key_Period }, + { NS_VK_DIVIDE, Qt::Key_Slash }, + { NS_VK_F1, Qt::Key_F1 }, + { NS_VK_F2, Qt::Key_F2 }, + { NS_VK_F3, Qt::Key_F3 }, + { NS_VK_F4, Qt::Key_F4 }, + { NS_VK_F5, Qt::Key_F5 }, + { NS_VK_F6, Qt::Key_F6 }, + { NS_VK_F7, Qt::Key_F7 }, + { NS_VK_F8, Qt::Key_F8 }, + { NS_VK_F9, Qt::Key_F9 }, + { NS_VK_F10, Qt::Key_F10 }, + { NS_VK_F11, Qt::Key_F11 }, + { NS_VK_F12, Qt::Key_F12 }, + { NS_VK_F13, Qt::Key_F13 }, + { NS_VK_F14, Qt::Key_F14 }, + { NS_VK_F15, Qt::Key_F15 }, + { NS_VK_F16, Qt::Key_F16 }, + { NS_VK_F17, Qt::Key_F17 }, + { NS_VK_F18, Qt::Key_F18 }, + { NS_VK_F19, Qt::Key_F19 }, + { NS_VK_F20, Qt::Key_F20 }, + { NS_VK_F21, Qt::Key_F21 }, + { NS_VK_F22, Qt::Key_F22 }, + { NS_VK_F23, Qt::Key_F23 }, + { NS_VK_F24, Qt::Key_F24 }, + + { NS_VK_NUM_LOCK, Qt::Key_NumLock }, + { NS_VK_SCROLL_LOCK, Qt::Key_ScrollLock }, + + { NS_VK_COMMA, Qt::Key_Comma }, + { NS_VK_PERIOD, Qt::Key_Period }, + { NS_VK_SLASH, Qt::Key_Slash }, + { NS_VK_BACK_QUOTE, Qt::Key_QuoteLeft }, + { NS_VK_OPEN_BRACKET, Qt::Key_ParenLeft }, + { NS_VK_CLOSE_BRACKET, Qt::Key_ParenRight }, + { NS_VK_QUOTE, Qt::Key_QuoteDbl }, + + { NS_VK_META, Qt::Key_Meta } +}; + +static PRInt32 NS_GetKey(PRInt32 aKey) +{ + PRInt32 length = sizeof(nsKeycodes) / sizeof(nsKeyConverter); + + for (PRInt32 i = 0; i < length; i++) { + if (nsKeycodes[i].keysym == aKey) { + return nsKeycodes[i].vkCode; + } + } + return 0; +} + +static PRBool +isContextMenuKey(const nsKeyEvent &aKeyEvent) +{ + return ((aKeyEvent.keyCode == NS_VK_F10 && aKeyEvent.isShift && + !aKeyEvent.isControl && !aKeyEvent.isMeta && !aKeyEvent.isAlt) || + (aKeyEvent.keyCode == NS_VK_CONTEXT_MENU && !aKeyEvent.isShift && + !aKeyEvent.isControl && !aKeyEvent.isMeta && !aKeyEvent.isAlt)); +} + +static void +keyEventToContextMenuEvent(const nsKeyEvent* aKeyEvent, + nsMouseEvent* aCMEvent) +{ + memcpy(aCMEvent, aKeyEvent, sizeof(nsInputEvent)); + aCMEvent->message = NS_CONTEXTMENU_KEY; + aCMEvent->isShift = aCMEvent->isControl = PR_FALSE; + aCMEvent->isAlt = aCMEvent->isMeta = PR_FALSE; + aCMEvent->clickCount = 0; + aCMEvent->acceptActivation = PR_FALSE; +} + +nsCommonWidget::nsCommonWidget() + : mContainer(0), + mWidget(0), + mListenForResizes(PR_FALSE) +{ +} + +NS_IMPL_ISUPPORTS_INHERITED0(nsCommonWidget,nsBaseWidget) +nsCommonWidget::~nsCommonWidget() +{ + delete mDispatcher; + mDispatcher = 0; +} + +void +nsCommonWidget::Initialize(QWidget *widget) +{ + Q_ASSERT(widget); + + mWidget = widget; + mWidget->setMouseTracking(PR_TRUE); + mWidget->setFocusPolicy(QWidget::WheelFocus); +} + +NS_IMETHODIMP +nsCommonWidget::Show(PRBool aState) +{ + if (!mWidget) { + //XXX: apperently can be null during the printing, check whether + // that's true + qDebug("nsCommon::Show : widget empty"); + return NS_OK; + } + + if (mContainer) + mContainer->setShown(aState); + mWidget->setShown(aState); + + return NS_OK; +} + +NS_IMETHODIMP +nsCommonWidget::IsVisible(PRBool &visible) +{ + if (mWidget) + visible = mWidget->isVisible(); + else + visible = PR_FALSE; + return NS_OK; +} + +NS_IMETHODIMP +nsCommonWidget::ConstrainPosition(int aAllowSlop, PRInt32 *aX, PRInt32 *aY) +{ + if (mContainer) { + PRInt32 screenWidth = QApplication::desktop()->width(); + PRInt32 screenHeight = QApplication::desktop()->height(); + if (aAllowSlop) { + if (*aX < (kWindowPositionSlop - mBounds.width)) + *aX = kWindowPositionSlop - mBounds.width; + if (*aX > (screenWidth - kWindowPositionSlop)) + *aX = screenWidth - kWindowPositionSlop; + if (*aY < (kWindowPositionSlop - mBounds.height)) + *aY = kWindowPositionSlop - mBounds.height; + if (*aY > (screenHeight - kWindowPositionSlop)) + *aY = screenHeight - kWindowPositionSlop; + } else { + if (*aX < 0) + *aX = 0; + if (*aX > (screenWidth - mBounds.width)) + *aX = screenWidth - mBounds.width; + if (*aY < 0) + *aY = 0; + if (*aY > (screenHeight - mBounds.height)) + *aY = screenHeight - mBounds.height; + } + } + return NS_OK; +} + +NS_IMETHODIMP +nsCommonWidget::Move(PRInt32 x, PRInt32 y) +{ + if (x == mBounds.x && y == mBounds.y) + return NS_OK; + + mBounds.x = x; + mBounds.y = y; + + QPoint pos(x, y); + if (mContainer) { + //if (mContainer->isPopup() && mContainer->parentWidget()) { + //pos = mContainer->parentWidget()->mapToGlobal(pos); + //} + mContainer->move(pos); + } + else if (mWidget) + mWidget->move(pos); + + return NS_OK; +} + +NS_IMETHODIMP +nsCommonWidget::Resize(PRInt32 aWidth, + PRInt32 aHeight, + PRBool aRepaint) +{ + mBounds.width = aWidth; + mBounds.height = aHeight; + + if (!mWidget || (mWidget->width() == aWidth && + mWidget->height() == aHeight)) + return NS_OK; + qDebug("Resize: mWidget=%p, aWidth=%d,aHeight=%d", (void*)mWidget, aWidth, aHeight); + + if (mWidget) { + + if (AreBoundsSane()) { + if (mContainer) { + mContainer->setGeometry( mBounds.x, mBounds.y, + mBounds.width, mBounds.height); + } + + mWidget->resize(mBounds.width, mBounds.height); + + if (aRepaint) { + if (mWidget->isVisible()) + mWidget->repaint(false); + } + } + } else if (mWidget) { + if (AreBoundsSane() && mListenForResizes) { + if (mContainer) + mContainer->resize(mBounds.width, mBounds.height); + mWidget->resize(mBounds.width, mBounds.height); + } + } + + // synthesize a resize event if this isn't a toplevel + if (mContainer || mListenForResizes) { + nsRect rect(mBounds.x, mBounds.y, aWidth, aHeight); + nsEventStatus status; + DispatchResizeEvent(rect, status); + } + + return NS_OK; +} + +/* + * XXXX: This sucks because it basically hardcore duplicates the + * code from the above function. + */ +NS_IMETHODIMP +nsCommonWidget::Resize(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight, + PRBool aRepaint) +{ + mBounds.x = aX; + mBounds.y = aY; + mBounds.width = aWidth; + mBounds.height = aHeight; + + if (!mWidget || (mWidget->x() == aX && + mWidget->y() == aY && + mWidget->height() == aHeight && + mWidget->width() == aWidth)) + return NS_OK; + + qDebug("2 Resize: mWidget=%p, aWidth=%d, aHeight=%d, aX = %d, aY = %d", (void*)mWidget, aWidth, aHeight, aX, aY); + + if (AreBoundsSane()) { + if (mContainer) + mContainer->setGeometry(mBounds.x, mBounds.y, + mBounds.width, mBounds.height); + + mWidget->setGeometry( mBounds.x, mBounds.y, + mBounds.width, mBounds.height); + + if (aRepaint) { + if (mWidget->isVisible()) + mWidget->repaint(false); + } + } + + // synthesize a resize event if this isn't a toplevel + if (mContainer || mListenForResizes) { + nsRect rect(mBounds.x, mBounds.y, mBounds.width, mBounds.height); + nsEventStatus status; + DispatchResizeEvent(rect, status); + } + + return NS_OK; +} + +NS_IMETHODIMP +nsCommonWidget::Enable(PRBool aState) +{ + if (mWidget) + mWidget->setEnabled(aState); + + return NS_OK; +} + +NS_IMETHODIMP +nsCommonWidget::IsEnabled(PRBool *aState) +{ + if (mWidget) + *aState = mWidget->isEnabled(); + + return NS_OK; +} + +NS_IMETHODIMP +nsCommonWidget::SetFocus(PRBool aSet) +{ + if (mWidget && aSet) + mWidget->setFocus(); + + return NS_OK; +} + +nsIFontMetrics* +nsCommonWidget::GetFont() +{ + qDebug("nsCommonWidget.cpp: GetFont not implemented"); + return nsnull; +} + +NS_IMETHODIMP +nsCommonWidget::SetFont(const nsFont&) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsCommonWidget::Invalidate(PRBool aIsSynchronous) +{ + if (mContainer) { + qDebug("invalidate 1"); + if (aIsSynchronous) + mContainer->update(); + else + mContainer->repaint(); + } + return NS_OK; +} + +NS_IMETHODIMP +nsCommonWidget::Invalidate(const nsRect & aRect, PRBool aIsSynchronous) +{ + if (mContainer) { + qDebug("invalidate 2"); + if (aIsSynchronous) + mContainer->update(aRect.x, aRect.y, aRect.width, aRect.height); + else + mContainer->repaint(aRect.x, aRect.y, aRect.width, aRect.height); + } + return NS_OK; +} + +NS_IMETHODIMP +nsCommonWidget::Update() +{ + //qDebug("Update!!!!!!"); + if (mContainer) { + mContainer->update(); + } else if (mWidget) { + mWidget->update(); + } + + return NS_OK; +} + +NS_IMETHODIMP +nsCommonWidget::SetColorMap(nsColorMap*) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsCommonWidget::Scroll(int aDx, int aDy, nsRect *aClipRect) +{ + if (mWidget) + mWidget->scroll(aDx, aDy); + + // Update bounds on our child windows + for (nsIWidget* kid = mFirstChild; kid; kid = kid->GetNextSibling()) { + nsRect bounds; + kid->GetBounds(bounds); + bounds.x += aDx; + bounds.y += aDy; + NS_STATIC_CAST(nsBaseWidget*, kid)->SetBounds(bounds); + } + return NS_OK; +} + +NS_IMETHODIMP +nsCommonWidget::ScrollWidgets(PRInt32 aDx, + PRInt32 aDy) +{ + if (mWidget) + mWidget->scroll(aDx, aDy); + + return NS_OK; +} + +void* +nsCommonWidget::GetNativeData(PRUint32 aDataType) +{ + switch(aDataType) { + case NS_NATIVE_WINDOW: + return mWidget; + break; + + case NS_NATIVE_DISPLAY: + if (mWidget) + return mWidget->x11Display(); + break; + + case NS_NATIVE_WIDGET: + return mWidget; + break; + + case NS_NATIVE_PLUGIN_PORT: + if (mWidget) + return (void*)mWidget->winId(); + break; + + default: + break; + } + + return nsnull; +} + +NS_IMETHODIMP +nsCommonWidget::SetTitle(const nsAString &str) +{ + nsAString::const_iterator it; + QString qStr = QString::fromUcs2(str.BeginReading(it).get()); + + if (mContainer) + mContainer->setCaption(qStr); + + return NS_OK; +} + +NS_IMETHODIMP +nsCommonWidget::SetMenuBar(nsIMenuBar*) +{ + qDebug("XXXXX SetMenuBar"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsCommonWidget::ShowMenuBar(int) +{ + qDebug("XXXXX ShowMenuBar"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsCommonWidget::WidgetToScreen(const nsRect &aOldRect, nsRect &aNewRect) +{ + aNewRect.width = aOldRect.width; + aNewRect.height = aOldRect.height; + + if (mWidget) { + PRInt32 x,y; + + QPoint offset(0,0); + offset = mWidget->mapToGlobal(offset); + x = offset.x(); + y = offset.y(); + + aNewRect.x = aOldRect.x + x; + aNewRect.y = aOldRect.y + y; + } + + return NS_OK; +} + +NS_IMETHODIMP +nsCommonWidget::ScreenToWidget(const nsRect &aOldRect, nsRect &aNewRect) +{ + if (mWidget) { + PRInt32 X,Y; + + QPoint offset(0,0); + offset = mWidget->mapFromGlobal(offset); + X = offset.x(); + Y = offset.y(); + + aNewRect.x = aOldRect.x + X; + aNewRect.y = aOldRect.y + Y; + } + return NS_OK; +} + +NS_IMETHODIMP +nsCommonWidget::BeginResizingChildren() +{ + qDebug("XXXXXX BeginResizingChildren"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsCommonWidget::EndResizingChildren() +{ + qDebug("XXXXXXX EndResizingChildren"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsCommonWidget::GetPreferredSize(PRInt32 &aWidth, PRInt32 &aHeight) +{ + if (!mWidget) + return NS_ERROR_FAILURE; + + QSize sh = mWidget->sizeHint(); + aWidth = QMAX(0, sh.width()); + aHeight = QMAX(0, sh.height()); + return NS_OK; +} + +NS_IMETHODIMP +nsCommonWidget::SetPreferredSize(int w, int h) +{ + qDebug("SetPreferredSize %d %d", w, h); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsCommonWidget::DispatchEvent(nsGUIEvent *aEvent, nsEventStatus &aStatus) +{ + aStatus = nsEventStatus_eIgnore; + + // hold a widget reference while we dispatch this event + NS_ADDREF(aEvent->widget); + + if (mEventCallback) + aStatus = (*mEventCallback)(aEvent); + + // dispatch to event listener if event was not consumed + if ((aStatus != nsEventStatus_eIgnore) && mEventListener) + aStatus = mEventListener->ProcessEvent(*aEvent); + + NS_IF_RELEASE(aEvent->widget); + + return NS_OK; +} + +NS_IMETHODIMP +nsCommonWidget::CaptureRollupEvents(nsIRollupListener*, PRBool, PRBool) +{ + return NS_OK; +} + +void +nsCommonWidget::DispatchGotFocusEvent(void) +{ + nsGUIEvent event(NS_GOTFOCUS, this); + nsEventStatus status; + DispatchEvent(&event, status); +} + +void +nsCommonWidget::DispatchLostFocusEvent(void) +{ + nsGUIEvent event(NS_LOSTFOCUS, this); + nsEventStatus status; + DispatchEvent(&event, status); +} + +void +nsCommonWidget::DispatchActivateEvent(void) +{ + nsGUIEvent event(NS_ACTIVATE, this); + nsEventStatus status; + DispatchEvent(&event, status); +} + +void +nsCommonWidget::DispatchDeactivateEvent(void) +{ + nsGUIEvent event(NS_DEACTIVATE, this); + nsEventStatus status; + DispatchEvent(&event, status); +} + +void +nsCommonWidget::DispatchResizeEvent(nsRect &aRect, nsEventStatus &aStatus) +{ + nsSizeEvent event(NS_SIZE, this); + + event.windowSize = &aRect; + event.point.x = aRect.x; + event.point.y = aRect.y; + event.mWinWidth = aRect.width; + event.mWinHeight = aRect.height; + + DispatchEvent(&event, aStatus); +} + +bool +nsCommonWidget::mousePressEvent(QMouseEvent *e) +{ + //qDebug("mousePressEvent mWidget=%p", (void*)mWidget); +// backTrace(); + PRUint32 eventType; + + switch (e->button()) { + case Qt::MidButton: + eventType = NS_MOUSE_MIDDLE_BUTTON_DOWN; + break; + case Qt::RightButton: + eventType = NS_MOUSE_RIGHT_BUTTON_DOWN; + break; + default: + eventType = NS_MOUSE_LEFT_BUTTON_DOWN; + break; + } + + nsMouseEvent event(eventType, this); + + InitMouseEvent(&event, e, 1); + + nsEventStatus status; + DispatchEvent(&event, status); + + // right menu click on linux should also pop up a context menu + if (eventType == NS_MOUSE_RIGHT_BUTTON_DOWN) { + nsMouseEvent contextMenuEvent(NS_CONTEXTMENU, this); + InitMouseEvent(&contextMenuEvent, e, 1); + DispatchEvent(&contextMenuEvent, status); + } + + return TRUE;//ignoreEvent(status); +} + +bool +nsCommonWidget::mouseReleaseEvent(QMouseEvent *e) +{ + //qDebug("mouseReleaseEvent mWidget=%p", (void*)mWidget); + PRUint32 eventType; + + switch (e->button()) { + case Qt::MidButton: + eventType = NS_MOUSE_MIDDLE_BUTTON_UP; + break; + case Qt::RightButton: + eventType = NS_MOUSE_RIGHT_BUTTON_UP; + break; + default: + eventType = NS_MOUSE_LEFT_BUTTON_UP; + break; + } + + nsMouseEvent event(eventType, this); + + InitMouseEvent(&event, e, 1); + + //not pressed + nsEventStatus status; + DispatchEvent(&event, status); + return TRUE;//ignoreEvent(status); +} + +bool +nsCommonWidget::mouseDoubleClickEvent(QMouseEvent *e) +{ + PRUint32 eventType; + + switch (e->button()) { + case Qt::MidButton: + eventType = NS_MOUSE_MIDDLE_BUTTON_DOWN; + break; + case Qt::RightButton: + eventType = NS_MOUSE_RIGHT_BUTTON_DOWN; + break; + default: + eventType = NS_MOUSE_LEFT_BUTTON_DOWN; + break; + } + + nsMouseEvent event(eventType, this); + + InitMouseEvent(&event, e, 2); + //pressed + nsEventStatus status; + DispatchEvent(&event, status); + return TRUE;//ignoreEvent(status); +} + +bool +nsCommonWidget::mouseMoveEvent(QMouseEvent *e) +{ + nsMouseEvent event(NS_MOUSE_MOVE, this); + + InitMouseEvent(&event, e, 0); + nsEventStatus status; + DispatchEvent(&event, status); + return TRUE;//ignoreEvent(status); +} + +bool +nsCommonWidget::wheelEvent(QWheelEvent *e) +{ + nsMouseScrollEvent nsEvent(NS_MOUSE_SCROLL, this); + + InitMouseWheelEvent(&nsEvent, e); + + nsEventStatus status; + DispatchEvent(&nsEvent, status); + return TRUE;//ignoreEvent(status); +} + +bool +nsCommonWidget::keyPressEvent(QKeyEvent *e) +{ + qDebug("keyPressEvent"); + + nsEventStatus status; + + // If the key repeat flag isn't set then set it so we don't send + // another key down event on the next key press -- DOM events are + // key down, key press and key up. X only has key press and key + // release. gtk2 already filters the extra key release events for + // us. + + if (!e->isAutoRepeat()) { + + // send the key down event + nsKeyEvent downEvent(NS_KEY_DOWN, this); + InitKeyEvent(&downEvent, e); + DispatchEvent(&downEvent, status); + } + + nsKeyEvent event(NS_KEY_PRESS, this); + InitKeyEvent(&event, e); + event.charCode = (PRInt32)e->text()[0].unicode(); + + // before we dispatch a key, check if it's the context menu key. + // If so, send a context menu key event instead. + if (isContextMenuKey(event)) { + nsMouseEvent contextMenuEvent; + keyEventToContextMenuEvent(&event, &contextMenuEvent); + DispatchEvent(&contextMenuEvent, status); + } + else { + // send the key press event + DispatchEvent(&event, status); + } + + return TRUE;//ignoreEvent(status); +} + +bool +nsCommonWidget::keyReleaseEvent(QKeyEvent *e) +{ + nsKeyEvent event(NS_KEY_UP, this); + + InitKeyEvent(&event, e); + + nsEventStatus status; + DispatchEvent(&event, status); + return TRUE;//ignoreEvent(status); +} + +bool +nsCommonWidget::focusInEvent(QFocusEvent *) +{ + //qDebug("focusInEvent mWidget=%p", (void*)mWidget); + // dispatch a got focus event + DispatchGotFocusEvent(); + + // send the activate event if it wasn't already sent via any + // SetFocus() calls that were the result of the GOTFOCUS event + // above. + if (mContainer) + DispatchActivateEvent(); + return FALSE; +} + +bool +nsCommonWidget::focusOutEvent(QFocusEvent *) +{ + //qDebug("focusOutEvent mWidget=%p", (void*)mWidget); + DispatchLostFocusEvent(); + return FALSE; +} + +bool +nsCommonWidget::enterEvent(QEvent *) +{ + nsMouseEvent event(NS_MOUSE_ENTER, this); + + nsEventStatus status; + DispatchEvent(&event, status); + return FALSE; +} + +bool +nsCommonWidget::leaveEvent(QEvent *aEvent) +{ + nsMouseEvent event(NS_MOUSE_EXIT, this); + + nsEventStatus status; + DispatchEvent(&event, status); + return FALSE; +} + +bool +nsCommonWidget::paintEvent(QPaintEvent *e) +{ + //qDebug("paintEvent: mWidget=%p x = %d, y = %d, width = %d, height = %d", (void*)mWidget, + //e->rect().x(), e->rect().y(), e->rect().width(), e->rect().height()); +// qDebug("paintEvent: Widgetrect %d %d %d %d", mWidget->x(), mWidget->y(), +// mWidget->width(), mWidget->height()); + + QRect r = e->rect(); + if (!r.isValid()) + r = mWidget->rect(); + nsRect rect(r.x(), r.y(), r.width(), r.height()); + + nsCOMPtr rc = getter_AddRefs(GetRenderingContext()); + + // Generate XPFE paint event + nsPaintEvent event(NS_PAINT, this); + event.point.x = 0; + event.point.y = 0; + event.rect = ▭ + // XXX fix this! + event.region = nsnull; + // XXX fix this! + event.renderingContext = rc; + + nsEventStatus status; + DispatchEvent(&event, status); + return ignoreEvent(status); +} + +bool +nsCommonWidget::moveEvent(QMoveEvent *e) +{ + qDebug("moveEvent mWidget=%p %d %d", (void*)mWidget, e->pos().x(), e->pos().y()); + // can we shortcut? + if (!mWidget || (mBounds.x == e->pos().x() && + mBounds.y == e->pos().y())) + return FALSE; + + // Toplevel windows need to have their bounds set so that we can + // keep track of our location. It's not often that the x,y is set + // by the layout engine. Width and height are set elsewhere. + QPoint pos = e->pos(); + + //if (mWidget->isPopup()) { + // pos = mWidget->parentWidget()->mapToGlobal(pos); + // qDebug("global pos: %d/%d", pos.x(), pos.y()); + //} + if (mContainer) { + // Need to translate this into the right coordinates + nsRect oldrect, newrect; + WidgetToScreen(oldrect, newrect); + mBounds.x = newrect.x; + mBounds.y = newrect.y; + } + + nsGUIEvent event(NS_MOVE, this); + event.point.x = pos.x(); + event.point.y = pos.y(); + + // XXX mozilla will invalidate the entire window after this move + // complete. wtf? + nsEventStatus status; + DispatchEvent(&event, status); + return ignoreEvent(status); +} + +bool +nsCommonWidget::resizeEvent(QResizeEvent *e) +{ + nsRect rect; + + // Generate XPFE resize event + GetBounds(rect); + rect.width = e->size().width(); + rect.height = e->size().height(); + + qDebug("resizeEvent: mWidget=%p, aWidth=%d, aHeight=%d, aX = %d, aY = %d", (void*)mWidget, + rect.width, rect.height, rect.x, rect.y); + + nsEventStatus status; + DispatchResizeEvent(rect, status); + return ignoreEvent(status); +} + +bool +nsCommonWidget::closeEvent(QCloseEvent *) +{ + nsGUIEvent event(NS_XUL_CLOSE, this); + + event.point.x = 0; + event.point.y = 0; + + nsEventStatus status; + DispatchEvent(&event, status); + + return ignoreEvent(status); +} + +bool +nsCommonWidget::contextMenuEvent(QContextMenuEvent *) +{ + //qDebug("context menu"); + return false; +} + +bool +nsCommonWidget::imStartEvent(QIMEvent *) +{ + qDebug("imStartEvent"); + return false; +} + +bool +nsCommonWidget::imComposeEvent(QIMEvent *) +{ + qDebug("imComposeEvent"); + return false; +} + +bool +nsCommonWidget::imEndEvent(QIMEvent * ) +{ + qDebug("imComposeEvent"); + return false; +} + +bool +nsCommonWidget::dragEnterEvent(QDragEnterEvent *) +{ + qDebug("dragEnterEvent"); + return false; +} + +bool +nsCommonWidget::dragMoveEvent(QDragMoveEvent *) +{ + qDebug("dragMoveEvent"); + return false; +} + +bool +nsCommonWidget::dragLeaveEvent(QDragLeaveEvent *) +{ + qDebug("dragLeaveEvent"); + return false; +} + +bool +nsCommonWidget::dropEvent(QDropEvent *) +{ + qDebug("dropEvent"); + return false; +} + +bool +nsCommonWidget::showEvent(QShowEvent *) +{ + qDebug("showEvent mWidget=%p", (void*)mWidget); + + QRect r = mWidget->rect(); + nsRect rect(r.x(), r.y(), r.width(), r.height()); + + nsCOMPtr rc = getter_AddRefs(GetRenderingContext()); + // Generate XPFE paint event + nsPaintEvent event(NS_PAINT, this); + event.point.x = 0; + event.point.y = 0; + event.rect = ▭ + // XXX fix this! + event.region = nsnull; + // XXX fix this! + event.renderingContext = rc; + + nsEventStatus status; + DispatchEvent(&event, status); + + return false; +} + +bool +nsCommonWidget::hideEvent(QHideEvent *) +{ + qDebug("hideEvent mWidget=%p", (void*)mWidget); + return false; +} + +void +nsCommonWidget::InitKeyEvent(nsKeyEvent *nsEvent, QKeyEvent *qEvent) +{ + nsEvent->isShift = qEvent->state() & Qt::ShiftButton; + nsEvent->isControl = qEvent->state() & Qt::ControlButton; + nsEvent->isAlt = qEvent->state() & Qt::AltButton; + nsEvent->isMeta = qEvent->state() & Qt::MetaButton; + nsEvent->time = 0; + + if (qEvent->text().length() && qEvent->text()[0].isPrint()) { + nsEvent->charCode = (PRInt32)qEvent->text()[0].unicode(); + } + else { + nsEvent->charCode = 0; + } + + if (nsEvent->charCode) { + nsEvent->keyCode = 0; + } + else { + nsEvent->keyCode = NS_GetKey(qEvent->key()); + } +} + +void +nsCommonWidget::InitMouseEvent(nsMouseEvent *nsEvent, QMouseEvent *qEvent, int aClickCount) +{ + nsEvent->point.x = nscoord(qEvent->x()); + nsEvent->point.y = nscoord(qEvent->y()); + + nsEvent->isShift = qEvent->state() & Qt::ShiftButton; + nsEvent->isControl = qEvent->state() & Qt::ControlButton; + nsEvent->isAlt = qEvent->state() & Qt::AltButton; + nsEvent->isMeta = qEvent->state() & Qt::MetaButton; + nsEvent->clickCount = aClickCount; +} + +void +nsCommonWidget::InitMouseWheelEvent(nsMouseScrollEvent *aEvent, + QWheelEvent *qEvent) +{ + switch (qEvent->orientation()) { + case Qt::Vertical: + aEvent->scrollFlags = nsMouseScrollEvent::kIsVertical; + break; + case Qt::Horizontal: + aEvent->scrollFlags = nsMouseScrollEvent::kIsHorizontal; + break; + default: + Q_ASSERT(0); + break; + } + aEvent->delta = (int)((qEvent->delta() / WHEEL_DELTA) * -3); + + aEvent->point.x = nscoord(qEvent->x()); + aEvent->point.y = nscoord(qEvent->y()); + + aEvent->isShift = qEvent->state() & Qt::ShiftButton; + aEvent->isControl = qEvent->state() & Qt::ControlButton; + aEvent->isAlt = qEvent->state() & Qt::AltButton; + aEvent->isMeta = qEvent->state() & Qt::MetaButton; + aEvent->time = 0; +} + +void +nsCommonWidget::CommonCreate(nsIWidget *aParent, PRBool aListenForResizes) +{ + mParent = aParent; + mListenForResizes = aListenForResizes; +} + +PRBool +nsCommonWidget::AreBoundsSane() const +{ + if (mBounds.width > 0 && mBounds.height > 0) + return PR_TRUE; + + return PR_FALSE; +} + +NS_IMETHODIMP +nsCommonWidget::Create(nsIWidget *aParent, const nsRect &aRect, EVENT_CALLBACK aHandleEventFunction, + nsIDeviceContext *aContext, nsIAppShell *aAppShell, nsIToolkit *aToolkit, + nsWidgetInitData *aInitData) +{ + return NativeCreate(aParent, nsnull, aRect, aHandleEventFunction, aContext, aAppShell, + aToolkit, aInitData); +} + +NS_IMETHODIMP +nsCommonWidget::Create(nsNativeWidget aParent, const nsRect &aRect, EVENT_CALLBACK aHandleEventFunction, + nsIDeviceContext *aContext, nsIAppShell *aAppShell, nsIToolkit *aToolkit, + nsWidgetInitData *aInitData) +{ + return NativeCreate(nsnull, (QWidget*)aParent, aRect, aHandleEventFunction, aContext, aAppShell, + aToolkit, aInitData); +} + +nsresult +nsCommonWidget::NativeCreate(nsIWidget *aParent, + QWidget *aNativeParent, + const nsRect &aRect, + EVENT_CALLBACK aHandleEventFunction, + nsIDeviceContext *aContext, + nsIAppShell *aAppShell, + nsIToolkit *aToolkit, + nsWidgetInitData *aInitData) +{ + // only set the base parent if we're going to be a dialog or a + // toplevel + nsIWidget *baseParent = aInitData && + (aInitData->mWindowType == eWindowType_dialog || + aInitData->mWindowType == eWindowType_toplevel || + aInitData->mWindowType == eWindowType_invisible) ? + nsnull : aParent; + + // initialize all the common bits of this class + BaseCreate(baseParent, aRect, aHandleEventFunction, aContext, + aAppShell, aToolkit, aInitData); + + // Do we need to listen for resizes? + PRBool listenForResizes = PR_FALSE;; + if (aNativeParent || (aInitData && aInitData->mListenForResizes)) + listenForResizes = PR_TRUE; + + // and do our common creation + CommonCreate(aParent, listenForResizes); + + // save our bounds + mBounds = aRect; + + QWidget *parent = 0; + if (aParent != nsnull) + parent = (QWidget*)aParent->GetNativeData(NS_NATIVE_WIDGET); + else + parent = aNativeParent; + + mWidget = createQWidget(parent, aInitData); + + Initialize(mWidget); + + Resize(mBounds.width, mBounds.height, PR_FALSE); + + return NS_OK; +} + +nsCursor nsCommonWidget::GetCursor() +{ + return mCursor; +} + +NS_METHOD nsCommonWidget::SetCursor(nsCursor aCursor) +{ + mCursor = aCursor; + Qt::CursorShape cursor = Qt::ArrowCursor; + switch(mCursor) { + case eCursor_standard: + cursor = Qt::ArrowCursor; + break; + case eCursor_wait: + cursor = Qt::WaitCursor; + break; + case eCursor_select: + cursor = Qt::IbeamCursor; + break; + case eCursor_hyperlink: + cursor = Qt::PointingHandCursor; + break; + case eCursor_ew_resize: + cursor = Qt::SplitHCursor; + break; + case eCursor_ns_resize: + cursor = Qt::SplitVCursor; + break; + case eCursor_nw_resize: + case eCursor_se_resize: + cursor = Qt::SizeBDiagCursor; + break; + case eCursor_ne_resize: + case eCursor_sw_resize: + cursor = Qt::SizeFDiagCursor; + break; + case eCursor_crosshair: + case eCursor_move: + cursor = Qt::SizeAllCursor; + break; + case eCursor_help: + cursor = Qt::WhatsThisCursor; + break; + case eCursor_copy: + case eCursor_alias: + break; + case eCursor_context_menu: + case eCursor_cell: + case eCursor_grab: + case eCursor_grabbing: + case eCursor_spinning: + case eCursor_zoom_in: + case eCursor_zoom_out: + + default: + break; + } + mWidget->setCursor(cursor); + return NS_OK; +} + +bool nsCommonWidget::ignoreEvent(nsEventStatus aStatus) const +{ + switch(aStatus) { + case nsEventStatus_eIgnore: + return(PR_FALSE); + + case nsEventStatus_eConsumeNoDefault: + return(PR_TRUE); + + case nsEventStatus_eConsumeDoDefault: + return(PR_FALSE); + + default: + NS_ASSERTION(0,"Illegal nsEventStatus enumeration value"); + break; + } + return(PR_FALSE); +} + + +NS_METHOD nsCommonWidget::SetModal(PRBool aModal) +{ + qDebug("------------> SetModal mWidget=%p",(void*) mWidget); + return NS_ERROR_FAILURE; +} + +// generic xp assumption is that events should be processed +NS_METHOD nsCommonWidget::ModalEventFilter(PRBool aRealEvent, void *aEvent, PRBool *aForWindow) +{ + qDebug("ModalEventFilter mWidget=%p", (void*)mWidget); + *aForWindow = PR_TRUE; + return NS_OK; +} diff --git a/mozilla/widget/src/qt/nsCommonWidget.h b/mozilla/widget/src/qt/nsCommonWidget.h new file mode 100644 index 00000000000..5899a372bff --- /dev/null +++ b/mozilla/widget/src/qt/nsCommonWidget.h @@ -0,0 +1,206 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 NSCOMMONWIDGET_H +#define NSCOMMONWIDGET_H + +#include "nsBaseWidget.h" + +#include "nsEvent.h" + +#include //XXX switch for forward-decl + +class nsIToolkit; +class nsWidgetInitData; +class nsIDeviceContext; +class nsIAppShell; +class nsIFontMetrics; +class nsColorMap; +class nsFont; +class nsRect; +class nsAString; +class nsIMenuBar; +class nsGUIEvent; +class nsIRollupListener; +class QWidget; +class nsQtEventDispatcher; + +class nsCommonWidget : public nsBaseWidget +{ +public: + nsCommonWidget(); + ~nsCommonWidget(); + + NS_DECL_ISUPPORTS_INHERITED + + NS_IMETHOD Show(PRBool); + NS_IMETHOD IsVisible(PRBool&); + + NS_IMETHOD ConstrainPosition(int, PRInt32*, PRInt32*); + NS_IMETHOD Move(int, int); + NS_IMETHOD Resize(int, int, int); + NS_IMETHOD Resize(int, int, int, int, int); + NS_IMETHOD Enable(int); + NS_IMETHOD IsEnabled(PRBool*); + NS_IMETHOD SetFocus(int); + + virtual nsIFontMetrics* GetFont(); + + NS_IMETHOD SetFont(const nsFont&); + NS_IMETHOD Invalidate(int); + NS_IMETHOD Invalidate(const nsRect&, int); + NS_IMETHOD Update(); + NS_IMETHOD SetColorMap(nsColorMap*); + NS_IMETHOD Scroll(int, int, nsRect*); + NS_IMETHOD ScrollWidgets(PRInt32 aDx, PRInt32 aDy); + + NS_METHOD SetModal(PRBool aModal); + NS_METHOD ModalEventFilter(PRBool aRealEvent, void *aEvent, PRBool *aForWindow); + + virtual void* GetNativeData(unsigned int); + + NS_IMETHOD SetTitle(const nsAString&); + NS_IMETHOD SetMenuBar(nsIMenuBar*); + NS_IMETHOD ShowMenuBar(int); + NS_IMETHOD WidgetToScreen(const nsRect&, nsRect&); + NS_IMETHOD ScreenToWidget(const nsRect&, nsRect&); + NS_IMETHOD BeginResizingChildren(); + NS_IMETHOD EndResizingChildren(); + NS_IMETHOD GetPreferredSize(PRInt32&, PRInt32&); + NS_IMETHOD SetPreferredSize(int, int); + NS_IMETHOD DispatchEvent(nsGUIEvent*, nsEventStatus&); + NS_IMETHOD CaptureRollupEvents(nsIRollupListener*, int, int); + + // nsIWidget + NS_IMETHOD Create(nsIWidget *aParent, + const nsRect &aRect, + EVENT_CALLBACK aHandleEventFunction, + nsIDeviceContext *aContext, + nsIAppShell *aAppShell, + nsIToolkit *aToolkit, + nsWidgetInitData *aInitData); + NS_IMETHOD Create(nsNativeWidget aParent, + const nsRect &aRect, + EVENT_CALLBACK aHandleEventFunction, + nsIDeviceContext *aContext, + nsIAppShell *aAppShell, + nsIToolkit *aToolkit, + nsWidgetInitData *aInitData); + + nsCursor GetCursor(); + NS_METHOD SetCursor(nsCursor aCursor); + +protected: + /** + * Event handlers (proxied from the actual qwidget). + * They follow normal Qt widget semantics. + */ + friend class nsQtEventDispatcher; + + virtual bool mousePressEvent(QMouseEvent *); + virtual bool mouseReleaseEvent(QMouseEvent *); + virtual bool mouseDoubleClickEvent(QMouseEvent *); + virtual bool mouseMoveEvent(QMouseEvent *); + virtual bool wheelEvent(QWheelEvent *); + virtual bool keyPressEvent(QKeyEvent *); + virtual bool keyReleaseEvent(QKeyEvent *); + virtual bool focusInEvent(QFocusEvent *); + virtual bool focusOutEvent(QFocusEvent *); + virtual bool enterEvent(QEvent *); + virtual bool leaveEvent(QEvent *); + virtual bool paintEvent(QPaintEvent *); + virtual bool moveEvent(QMoveEvent *); + virtual bool resizeEvent(QResizeEvent *); + virtual bool closeEvent(QCloseEvent *); + virtual bool contextMenuEvent(QContextMenuEvent *); + virtual bool imStartEvent(QIMEvent *); + virtual bool imComposeEvent(QIMEvent *); + virtual bool imEndEvent(QIMEvent *); + virtual bool dragEnterEvent(QDragEnterEvent *); + virtual bool dragMoveEvent(QDragMoveEvent *); + virtual bool dragLeaveEvent(QDragLeaveEvent *); + virtual bool dropEvent(QDropEvent *); + virtual bool showEvent(QShowEvent *); + virtual bool hideEvent(QHideEvent *); + +protected: + virtual QWidget *createQWidget(QWidget *parent, nsWidgetInitData *aInitData) = 0; + bool ignoreEvent(nsEventStatus aStatus) const; + + /** + * Has to be called in subclasses after they created + * the actual QWidget if they overwrite the Create + * calls from the nsCommonWidget class. + */ + void Initialize(QWidget *widget); + + void DispatchGotFocusEvent(void); + void DispatchLostFocusEvent(void); + void DispatchActivateEvent(void); + void DispatchDeactivateEvent(void); + void DispatchResizeEvent(nsRect &aRect, nsEventStatus &aStatus); + + void InitKeyEvent(nsKeyEvent *nsEvent, QKeyEvent *qEvent); + void InitMouseEvent(nsMouseEvent *nsEvent, QMouseEvent *qEvent, int aClickCount); + void InitMouseWheelEvent(nsMouseScrollEvent *aEvent, QWheelEvent *qEvent); + + void CommonCreate(nsIWidget *aParent, PRBool aListenForResizes); + + PRBool AreBoundsSane() const; + +protected: + QWidget *mContainer; + QWidget *mWidget; + nsQtEventDispatcher *mDispatcher; + PRPackedBool mListenForResizes; + nsCOMPtr mParent; + +private: + nsresult NativeCreate(nsIWidget *aParent, + QWidget *aNativeParent, + const nsRect &aRect, + EVENT_CALLBACK aHandleEventFunction, + nsIDeviceContext *aContext, + nsIAppShell *aAppShell, + nsIToolkit *aToolkit, + nsWidgetInitData *aInitData); + +}; + +#endif diff --git a/mozilla/widget/src/qt/nsDragService.cpp b/mozilla/widget/src/qt/nsDragService.cpp new file mode 100644 index 00000000000..ffbaaf29f12 --- /dev/null +++ b/mozilla/widget/src/qt/nsDragService.cpp @@ -0,0 +1,301 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * Pierre Phaneuf + * Denis Issoupov + * John C. Griggs + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ +#ifdef NDEBUG +#define NO_DEBUG +#endif + +#include "nsDragService.h" +#include "nsIServiceManager.h" +#include "nsXPCOM.h" +#include "nsISupportsPrimitives.h" +#include "nsCOMPtr.h" +#include "nsXPIDLString.h" +#include "nsPrimitiveHelpers.h" +#include "nsMime.h" +#include "nsWidgetsCID.h" +#include "nsString.h" + +// static NS_DEFINE_IID(kIDragServiceIID, NS_IDRAGSERVICE_IID); +// static NS_DEFINE_IID(kIDragSessionQtIID, NS_IDRAGSESSIONQT_IID); +// static NS_DEFINE_CID(kCDragServiceCID, NS_DRAGSERVICE_CID); + +NS_IMPL_ADDREF_INHERITED(nsDragService, nsBaseDragService) +NS_IMPL_RELEASE_INHERITED(nsDragService, nsBaseDragService) +NS_IMPL_QUERY_INTERFACE3(nsDragService, nsIDragService, nsIDragSession, nsIDragSessionQt ) + +//------------------------------------------------------------------------- +// static variables +//------------------------------------------------------------------------- +static PRBool gHaveDrag = PR_FALSE; + +//------------------------------------------------------------------------- +// +// DragService constructor +// +//------------------------------------------------------------------------- +nsDragService::nsDragService() +{ + // our hidden source widget + mHiddenWidget = new QWidget(0,QWidget::tr("DragDrop"),0); +} + +//------------------------------------------------------------------------- +// +// DragService destructor +// +//------------------------------------------------------------------------- +nsDragService::~nsDragService() +{ + delete mHiddenWidget; +} + +//--------------------------------------------------------- +NS_IMETHODIMP +nsDragService::InvokeDragSession(nsIDOMNode *aDOMNode, + nsISupportsArray *aArrayTransferables, + nsIScriptableRegion *aRegion, + PRUint32 aActionType) +{ + PRUint32 numItemsToDrag = 0; + + nsBaseDragService::InvokeDragSession(aDOMNode, aArrayTransferables, + aRegion, aActionType); + + // make sure that we have an array of transferables to use + if (!aArrayTransferables) { + return NS_ERROR_INVALID_ARG; + } + // set our reference to the transferables. this will also addref + // the transferables since we're going to hang onto this beyond the + // length of this call + mSourceDataItems = aArrayTransferables; + + mSourceDataItems->Count(&numItemsToDrag); + if (!numItemsToDrag) { + return NS_ERROR_FAILURE; + } + if (numItemsToDrag > 1) { + return NS_ERROR_FAILURE; + } + nsCOMPtr genericItem; + + mSourceDataItems->GetElementAt(0,getter_AddRefs(genericItem)); + + nsCOMPtr transferable(do_QueryInterface(genericItem)); + + mDragObject = RegisterDragFlavors(transferable); + gHaveDrag = PR_TRUE; + + if (aActionType == DRAGDROP_ACTION_MOVE) + mDragObject->dragMove(); + else + mDragObject->dragCopy(); + + gHaveDrag = PR_FALSE; + mDragObject = 0; + return NS_OK; +} + +QDragObject *nsDragService::RegisterDragFlavors(nsITransferable *transferable) +{ + nsMimeStore *pMimeStore = new nsMimeStore(); + nsCOMPtr flavorList; + + if (NS_SUCCEEDED(transferable->FlavorsTransferableCanExport(getter_AddRefs(flavorList)))) { + PRUint32 numFlavors; + + flavorList->Count(&numFlavors); + + for (PRUint32 flavorIndex = 0; flavorIndex < numFlavors; ++flavorIndex) { + nsCOMPtr genericWrapper; + + flavorList->GetElementAt(flavorIndex,getter_AddRefs(genericWrapper)); + + nsCOMPtr currentFlavor(do_QueryInterface(genericWrapper)); + + if (currentFlavor) { + nsXPIDLCString flavorStr; + + currentFlavor->ToString(getter_Copies(flavorStr)); + + PRUint32 len; + void* data; + nsCOMPtr clip; + + transferable->GetTransferData(flavorStr,getter_AddRefs(clip),&len); + nsPrimitiveHelpers::CreateDataFromPrimitive(flavorStr,clip,&data,len); + pMimeStore->AddFlavorData(flavorStr,data,len); + } + } // foreach flavor in item + } // if valid flavor list +#ifdef NS_DEBUG + else + printf(" DnD ERROR: cannot export any flavor\n"); +#endif + return new nsDragObject(pMimeStore,mHiddenWidget); +} // RegisterDragItemsAndFlavors + +NS_IMETHODIMP nsDragService::StartDragSession() +{ +#ifdef NS_DEBUG + printf(" DnD: StartDragSession\n"); +#endif + return nsBaseDragService::StartDragSession(); +} + +NS_IMETHODIMP nsDragService::EndDragSession() +{ +#ifdef NS_DEBUG + printf(" DnD: EndDragSession\n"); +#endif + mDragObject = 0; + return nsBaseDragService::EndDragSession(); +} + +// nsIDragSession +NS_IMETHODIMP nsDragService::SetCanDrop(PRBool aCanDrop) +{ + mCanDrop = aCanDrop; + return NS_OK; +} + +NS_IMETHODIMP nsDragService::GetCanDrop(PRBool *aCanDrop) +{ + *aCanDrop = mCanDrop; + return NS_OK; +} + +NS_IMETHODIMP nsDragService::GetNumDropItems(PRUint32 *aNumItems) +{ + *aNumItems = 1; + return NS_OK; +} + +NS_IMETHODIMP nsDragService::GetData(nsITransferable *aTransferable, + PRUint32 aItemIndex) +{ + // make sure that we have a transferable + if (!aTransferable) + return NS_ERROR_INVALID_ARG; + + nsresult rv = NS_ERROR_FAILURE; + nsCOMPtr flavorList; + + rv = aTransferable->FlavorsTransferableCanImport(getter_AddRefs(flavorList)); + if (NS_FAILED(rv)) + return rv; + + // count the number of flavors + PRUint32 cnt; + + flavorList->Count(&cnt); + + // Now walk down the list of flavors. When we find one that is + // actually present, copy out the data into the transferable in that + // format. SetTransferData() implicitly handles conversions. + for (unsigned int i = 0; i < cnt; ++i) { + nsCAutoString foundFlavor; + nsCOMPtr genericWrapper; + + flavorList->GetElementAt(i,getter_AddRefs(genericWrapper)); + + nsCOMPtr currentFlavor; + + currentFlavor = do_QueryInterface(genericWrapper); + if (currentFlavor) { + nsXPIDLCString flavorStr; + + currentFlavor->ToString(getter_Copies(flavorStr)); + foundFlavor = nsCAutoString(flavorStr); + + if (mDragObject && mDragObject->provides(flavorStr)) { + QByteArray ba = mDragObject->encodedData((const char*)flavorStr); + nsCOMPtr genericDataWrapper; + PRUint32 len = (PRUint32)ba.count(); + + nsPrimitiveHelpers::CreatePrimitiveForData(foundFlavor.get(), + (void*)ba.data(),len, + getter_AddRefs(genericDataWrapper)); + + aTransferable->SetTransferData(foundFlavor.get(),genericDataWrapper,len); + } + } + } + return NS_OK; +} + +NS_IMETHODIMP nsDragService::IsDataFlavorSupported(const char *aDataFlavor, + PRBool *_retval) +{ + if (!_retval) + return NS_ERROR_INVALID_ARG; + + *_retval = PR_FALSE; + + if (mDragObject) + *_retval = mDragObject->provides(aDataFlavor); + +#ifdef NS_DEBUG + if (!*_retval) + printf("nsDragService::IsDataFlavorSupported not provides [%s] \n", aDataFlavor); +#endif + return NS_OK; +} + +NS_IMETHODIMP nsDragService::SetDragReference(QMimeSource* aDragRef) +{ + nsMimeStore* pMimeStore = new nsMimeStore(); + int c = 0; + const char* format; + + while ((format = aDragRef->format(c++)) != 0) { + // this is usualy between different processes + // so, we need to copy datafrom one to onother + + QByteArray ba = aDragRef->encodedData(format); + char *data = new char[ba.size()]; + memcpy(data,ba.data(),ba.size()); + pMimeStore->AddFlavorData(format,data,ba.size()); + } + mDragObject = new nsDragObject(pMimeStore,mHiddenWidget); + return NS_OK; +} diff --git a/mozilla/widget/src/qt/nsDragService.h b/mozilla/widget/src/qt/nsDragService.h new file mode 100644 index 00000000000..2629e7c11e4 --- /dev/null +++ b/mozilla/widget/src/qt/nsDragService.h @@ -0,0 +1,89 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Denis Issoupov + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ +#ifndef nsDragService_h__ +#define nsDragService_h__ + +#include "nsBaseDragService.h" +#include "nsClipboard.h" +#include "nsIDragSessionQt.h" + +#include +#include + +//---------------------------------------------------------- +/* Native Qt DragService wrapper */ +class nsDragService : public nsBaseDragService, public nsIDragSessionQt +{ +public: + nsDragService(); + virtual ~nsDragService(); + + //nsISupports + NS_DECL_ISUPPORTS_INHERITED + + //nsIDragService + NS_IMETHOD InvokeDragSession(nsIDOMNode *aDOMNode, + nsISupportsArray *anArrayTransferables, + nsIScriptableRegion *aRegion, + PRUint32 aActionType); + NS_IMETHOD StartDragSession(); + NS_IMETHOD EndDragSession(); + + // nsIDragSession + NS_IMETHOD SetCanDrop(PRBool aCanDrop); + NS_IMETHOD GetCanDrop(PRBool *aCanDrop); + NS_IMETHOD GetNumDropItems(PRUint32 *aNumItems); + NS_IMETHOD GetData(nsITransferable *aTransferable,PRUint32 aItemIndex); + NS_IMETHOD IsDataFlavorSupported(const char *aDataFlavor,PRBool *_retval); + + // nsIDragSessionQt + NS_IMETHOD SetDragReference(QMimeSource* aDragRef); + +protected: + QDragObject *RegisterDragFlavors(nsITransferable* transferable); + +private: + // the source of our drags + QWidget *mHiddenWidget; + QDragObject *mDragObject; + + // our source data items + nsCOMPtr mSourceDataItems; +}; + +#endif // nsDragService_h__ diff --git a/mozilla/widget/src/qt/nsEventQueueWatcher.cpp b/mozilla/widget/src/qt/nsEventQueueWatcher.cpp new file mode 100644 index 00000000000..2d49698d2b5 --- /dev/null +++ b/mozilla/widget/src/qt/nsEventQueueWatcher.cpp @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 "nsEventQueueWatcher.h" + +#include "nsIEventQueue.h" +#include "nsIEventQueueService.h" + +#include + +nsEventQueueWatcher::nsEventQueueWatcher(nsIEventQueue *equeue, QObject *parent, const char *name) + : QObject( parent, name ), + mEventQueue(equeue) +{ + NS_IF_ADDREF(mEventQueue); + + Q_ASSERT(mEventQueue); + + mNotifier = new QSocketNotifier(mEventQueue->GetEventQueueSelectFD(), + QSocketNotifier::Read, this); + connect(mNotifier, SIGNAL(activated(int)), + this, SLOT(DataReceived()) ); +} + +nsEventQueueWatcher::~nsEventQueueWatcher() +{ + delete mNotifier; + NS_IF_RELEASE(mEventQueue); +} + +void nsEventQueueWatcher::DataReceived() +{ + if (mEventQueue) + mEventQueue->ProcessPendingEvents(); +} + diff --git a/mozilla/widget/src/qt/nsEventQueueWatcher.h b/mozilla/widget/src/qt/nsEventQueueWatcher.h new file mode 100644 index 00000000000..23200c4e7cd --- /dev/null +++ b/mozilla/widget/src/qt/nsEventQueueWatcher.h @@ -0,0 +1,76 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 NSEVENTQUEUEWATCHER_H +#define NSEVENTQUEUEWATCHER_H + +#include +#include + +#include "prenv.h" + +class nsIEventQueue; +class QSocketNotifier; + +/** + * This class watches the Gecko nsIEventQueue. If notificatiion + * comes it calls the processing method on the nsIEventQueue so + * that the event are event handled. + */ +class nsEventQueueWatcher : public QObject, + public QShared +{ + Q_OBJECT +public: + nsEventQueueWatcher(nsIEventQueue *equeue, QObject *parent, const char *name=0); + ~nsEventQueueWatcher(); + +public slots: + //public because for some freaky reason we have to call it from + //shell to cleanup. Essentially we can make it private if we're + //certain all events are eaten by gecko correctly + void DataReceived(); + +private: + nsIEventQueue *mEventQueue; + QSocketNotifier *mNotifier; + PRUint32 mRefCnt; +}; + +#endif diff --git a/mozilla/widget/src/qt/nsFilePicker.cpp b/mozilla/widget/src/qt/nsFilePicker.cpp new file mode 100644 index 00000000000..504f09733ed --- /dev/null +++ b/mozilla/widget/src/qt/nsFilePicker.cpp @@ -0,0 +1,286 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 "nsFilePicker.h" + +#include "nsILocalFile.h" +#include "nsIFileURL.h" +#include "nsIURI.h" +#include "nsISupportsArray.h" +#include "nsMemory.h" +#include "nsEnumeratorUtils.h" +#include "nsNetUtil.h" +#include "nsReadableUtils.h" + +#include +#include +#include + +/* Implementation file */ +NS_IMPL_ISUPPORTS1(nsFilePicker, nsIFilePicker) + +nsFilePicker::nsFilePicker() + : mDialog(0), + mMode(nsIFilePicker::modeOpen) +{ +} + +nsFilePicker::~nsFilePicker() +{ + delete mDialog; +} + +NS_IMETHODIMP +nsFilePicker::Init(nsIDOMWindow *parent, const nsAString & title, PRInt16 mode) +{ + return nsBaseFilePicker::Init(parent, title, mode); +} + +/* void appendFilters (in long filterMask); */ +NS_IMETHODIMP +nsFilePicker::AppendFilters(PRInt32 filterMask) +{ + return nsBaseFilePicker::AppendFilters(filterMask); +} + +/* void appendFilter (in AString title, in AString filter); */ +NS_IMETHODIMP +nsFilePicker::AppendFilter(const nsAString & aTitle, const nsAString & aFilter) +{ + if (aFilter.Equals(NS_LITERAL_STRING("..apps"))) { + // No platform specific thing we can do here, really.... + return NS_OK; + } + + nsCAutoString filter, name; + CopyUTF16toUTF8(aFilter, filter); + CopyUTF16toUTF8(aTitle, name); + + mFilters.AppendCString(filter); + mFilterNames.AppendCString(name); + + return NS_OK; +} + +/* attribute AString defaultString; */ +NS_IMETHODIMP +nsFilePicker::GetDefaultString(nsAString & aDefaultString) +{ + mDefault = aDefaultString; + + return NS_OK; +} +NS_IMETHODIMP +nsFilePicker::SetDefaultString(const nsAString & aDefaultString) +{ + return NS_ERROR_FAILURE; +} + +/* attribute AString defaultExtension; */ +NS_IMETHODIMP +nsFilePicker::GetDefaultExtension(nsAString & aDefaultExtension) +{ + aDefaultExtension = mDefaultExtension; + + return NS_OK; +} +NS_IMETHODIMP +nsFilePicker::SetDefaultExtension(const nsAString & aDefaultExtension) +{ + mDefaultExtension = aDefaultExtension; + + return NS_OK; +} + +/* attribute long filterIndex; */ +NS_IMETHODIMP +nsFilePicker::GetFilterIndex(PRInt32 *aFilterIndex) +{ + *aFilterIndex = mSelectedType; + + return NS_OK; +} +NS_IMETHODIMP +nsFilePicker::SetFilterIndex(PRInt32 aFilterIndex) +{ + mSelectedType = aFilterIndex; + + return NS_OK; +} + +/* attribute nsILocalFile displayDirectory; */ +NS_IMETHODIMP +nsFilePicker::GetDisplayDirectory(nsILocalFile * *aDisplayDirectory) +{ + NS_IF_ADDREF(*aDisplayDirectory = mDisplayDirectory); + + return NS_OK; +} +NS_IMETHODIMP +nsFilePicker::SetDisplayDirectory(nsILocalFile * aDisplayDirectory) +{ + mDisplayDirectory = aDisplayDirectory; + return NS_OK; +} + +/* readonly attribute nsILocalFile file; */ +NS_IMETHODIMP +nsFilePicker::GetFile(nsILocalFile * *aFile) +{ + NS_ENSURE_ARG_POINTER(aFile); + + *aFile = nsnull; + if (mFile.IsEmpty()) { + return NS_OK; + } + + nsCOMPtr file(do_CreateInstance("@mozilla.org/file/local;1")); + NS_ENSURE_TRUE(file, NS_ERROR_FAILURE); + + file->InitWithNativePath(mFile); + + NS_ADDREF(*aFile = file); + + return NS_OK; +} + +/* readonly attribute nsIFileURL fileURL; */ +NS_IMETHODIMP +nsFilePicker::GetFileURL(nsIFileURL * *aFileURL) +{ + nsCOMPtr file; + GetFile(getter_AddRefs(file)); + + nsCOMPtr uri; + NS_NewFileURI(getter_AddRefs(uri), file); + NS_ENSURE_TRUE(uri, NS_ERROR_FAILURE); + + return CallQueryInterface(uri, aFileURL); +} + +/* readonly attribute nsISimpleEnumerator files; */ +NS_IMETHODIMP +nsFilePicker::GetFiles(nsISimpleEnumerator * *aFiles) +{ + NS_ENSURE_ARG_POINTER(aFiles); + + if (mMode == nsIFilePicker::modeOpenMultiple) { + return NS_NewArrayEnumerator(aFiles, mFiles); + } + + return NS_ERROR_FAILURE; +} + +/* short show (); */ +NS_IMETHODIMP +nsFilePicker::Show(PRInt16 *aReturn) +{ + nsCAutoString directory; + if (mDisplayDirectory) { + mDisplayDirectory->GetNativePath(directory); + } + + switch (mMode) { + case nsIFilePicker::modeOpen: + break; + case nsIFilePicker::modeOpenMultiple: + mDialog->setMode(QFileDialog::ExistingFiles); + break; + case nsIFilePicker::modeSave: + mDialog->setMode(QFileDialog::AnyFile); + break; + case nsIFilePicker::modeGetFolder: + mDialog->setMode(QFileDialog::DirectoryOnly); + break; + default: + break; + } + + mDialog->setSelection(QString::fromUcs2(mDefault.get())); + + mDialog->setDir(directory.get()); + + QStringList filters; + PRInt32 count = mFilters.Count(); + for (PRInt32 i = 0; i < count; ++i) { + filters.append( mFilters[i]->get() ); + } + mDialog->setFilters(filters); + + switch (mDialog->exec()) { + case QDialog::Accepted: { + QCString path = QFile::encodeName(mDialog->selectedFile()); + qDebug("path is '%s'", path.data()); + mFile.Assign(path); + *aReturn = nsIFilePicker::returnOK; + if (mMode == modeSave) { + nsCOMPtr file; + GetFile(getter_AddRefs(file)); + if (file) { + PRBool exists = PR_FALSE; + file->Exists(&exists); + if (exists) { + *aReturn = nsIFilePicker::returnReplace; + } + } + } + } + break; + case QDialog::Rejected: { + *aReturn = nsIFilePicker::returnCancel; + } + break; + default: + *aReturn = nsIFilePicker::returnCancel; + break; + } + + + return NS_OK; +} + +void nsFilePicker::InitNative(nsIWidget *parent, const nsAString &title, PRInt16 mode) +{ + QWidget *parentWidget = (parent)? (QWidget*)parent->GetNativeData(NS_NATIVE_WIDGET):0; + + nsAutoString str(title); + mDialog = new QFileDialog(parentWidget); + mDialog->setCaption(QString::fromUcs2(str.get())); + mMode = mode; +} diff --git a/mozilla/widget/src/qt/nsFilePicker.h b/mozilla/widget/src/qt/nsFilePicker.h new file mode 100644 index 00000000000..7d7afdf8ee3 --- /dev/null +++ b/mozilla/widget/src/qt/nsFilePicker.h @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 NSFILEPICKER_H +#define NSFILEPICKER_H + +#include "nsBaseFilePicker.h" +#include "nsString.h" +#include "nsVoidArray.h" + +class nsIWidget; +class nsILocalFile; +class nsISupportsArray; +class QFileDialog; + +class nsFilePicker : public nsBaseFilePicker +{ +public: + NS_DECL_ISUPPORTS + NS_DECL_NSIFILEPICKER + + nsFilePicker(); + +private: + ~nsFilePicker(); + void InitNative(nsIWidget*, const nsAString&, short int); + +protected: + QFileDialog *mDialog; + nsCOMPtr mDisplayDirectory; + nsCOMPtr mFiles; + + PRInt16 mMode; + PRInt16 mSelectedType; + nsCString mFile; + nsString mTitle; + nsString mDefault; + nsString mDefaultExtension; + + nsCStringArray mFilters; + nsCStringArray mFilterNames; +}; + +#endif diff --git a/mozilla/widget/src/qt/nsIDragSessionQt.h b/mozilla/widget/src/qt/nsIDragSessionQt.h new file mode 100644 index 00000000000..021f5ef6f80 --- /dev/null +++ b/mozilla/widget/src/qt/nsIDragSessionQt.h @@ -0,0 +1,61 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Denis Issoupov + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ +#ifndef nsIDragSessionQt_h__ +#define nsIDragSessionQt_h__ + +#include "nsISupports.h" +#include + +#define NS_IDRAGSESSIONQT_IID \ +{ 0x36c4c381, 0x09e3, 0x11d4, { 0xb0, 0x33, 0xa4, 0x20, 0xf4, 0x2c, 0xfd, 0x7c } }; + +class nsIDragSessionQt : public nsISupports +{ + public: + NS_DEFINE_STATIC_IID_ACCESSOR(NS_IDRAGSESSIONQT_IID) + + /** + * Since the drag may originate in an external application, we need some + * way of communicating the QDragObject to the session so it can use it + * when filling in data requests. + * + */ + NS_IMETHOD SetDragReference(QMimeSource* aDragRef) = 0; +}; + +#endif diff --git a/mozilla/widget/src/qt/nsLookAndFeel.cpp b/mozilla/widget/src/qt/nsLookAndFeel.cpp new file mode 100644 index 00000000000..40bcc94f7d9 --- /dev/null +++ b/mozilla/widget/src/qt/nsLookAndFeel.cpp @@ -0,0 +1,474 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * John C. Griggs + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ +#include "nsLookAndFeel.h" + +#include +#include + +#define QCOLOR_TO_NS_RGB(c) \ + ((nscolor)NS_RGB(c.red(),c.green(),c.blue())) + +//------------------------------------------------------------------------- +// +// Query interface implementation +// +//------------------------------------------------------------------------- +nsLookAndFeel::nsLookAndFeel() : nsXPLookAndFeel() +{ +} + +nsLookAndFeel::~nsLookAndFeel() +{ +} + +nsresult nsLookAndFeel::NativeGetColor(const nsColorID aID,nscolor &aColor) +{ + nsresult res = NS_OK; + + if (!qApp) + return NS_ERROR_FAILURE; + + QPalette palette = qApp->palette(); + QColorGroup normalGroup = palette.inactive(); + QColorGroup activeGroup = palette.active(); + QColorGroup disabledGroup = palette.disabled(); + + switch (aID) { + case eColor_WindowBackground: + aColor = QCOLOR_TO_NS_RGB(normalGroup.background()); + break; + + case eColor_WindowForeground: + aColor = QCOLOR_TO_NS_RGB(normalGroup.foreground()); + break; + + case eColor_WidgetBackground: + aColor = QCOLOR_TO_NS_RGB(normalGroup.background()); + break; + + case eColor_WidgetForeground: + aColor = QCOLOR_TO_NS_RGB(normalGroup.foreground()); + break; + + case eColor_WidgetSelectBackground: + aColor = QCOLOR_TO_NS_RGB(activeGroup.background()); + break; + + case eColor_WidgetSelectForeground: + aColor = QCOLOR_TO_NS_RGB(activeGroup.foreground()); + break; + + case eColor_Widget3DHighlight: + aColor = NS_RGB(0xa0,0xa0,0xa0); + break; + + case eColor_Widget3DShadow: + aColor = NS_RGB(0x40,0x40,0x40); + break; + + case eColor_TextBackground: + aColor = QCOLOR_TO_NS_RGB(normalGroup.background()); + break; + + case eColor_TextForeground: + aColor = QCOLOR_TO_NS_RGB(normalGroup.text()); + break; + + case eColor_TextSelectBackground: + aColor = QCOLOR_TO_NS_RGB(activeGroup.highlight()); + break; + + case eColor_TextSelectForeground: + aColor = QCOLOR_TO_NS_RGB(activeGroup.highlightedText()); + break; + + case eColor_activeborder: + aColor = QCOLOR_TO_NS_RGB(normalGroup.background()); + break; + + case eColor_activecaption: + aColor = QCOLOR_TO_NS_RGB(normalGroup.background()); + break; + + case eColor_appworkspace: + aColor = QCOLOR_TO_NS_RGB(normalGroup.background()); + break; + + case eColor_background: + aColor = QCOLOR_TO_NS_RGB(normalGroup.background()); + break; + + case eColor_captiontext: + aColor = QCOLOR_TO_NS_RGB(normalGroup.text()); + break; + + case eColor_graytext: + aColor = QCOLOR_TO_NS_RGB(disabledGroup.text()); + break; + + case eColor_highlight: + aColor = QCOLOR_TO_NS_RGB(activeGroup.highlight()); + break; + + case eColor_highlighttext: + aColor = QCOLOR_TO_NS_RGB(activeGroup.highlightedText()); + break; + + case eColor_inactiveborder: + aColor = QCOLOR_TO_NS_RGB(normalGroup.background()); + break; + + case eColor_inactivecaption: + aColor = QCOLOR_TO_NS_RGB(disabledGroup.background()); + break; + + case eColor_inactivecaptiontext: + aColor = QCOLOR_TO_NS_RGB(disabledGroup.text()); + break; + + case eColor_infobackground: + aColor = QCOLOR_TO_NS_RGB(normalGroup.background()); + break; + + case eColor_infotext: + aColor = QCOLOR_TO_NS_RGB(normalGroup.text()); + break; + + case eColor_menu: + aColor = QCOLOR_TO_NS_RGB(normalGroup.background()); + break; + + case eColor_menutext: + aColor = QCOLOR_TO_NS_RGB(normalGroup.text()); + break; + + case eColor_scrollbar: + aColor = QCOLOR_TO_NS_RGB(activeGroup.background()); + break; + + case eColor_threedface: + case eColor_buttonface: + aColor = QCOLOR_TO_NS_RGB(normalGroup.background()); + break; + + case eColor_buttonhighlight: + case eColor_threedhighlight: + aColor = QCOLOR_TO_NS_RGB(normalGroup.light()); + break; + + case eColor_buttontext: + aColor = QCOLOR_TO_NS_RGB(normalGroup.text()); + break; + + case eColor_buttonshadow: + case eColor_threedshadow: + aColor = QCOLOR_TO_NS_RGB(normalGroup.shadow()); + break; + + case eColor_threeddarkshadow: + aColor = QCOLOR_TO_NS_RGB(normalGroup.dark()); + break; + + case eColor_threedlightshadow: + aColor = QCOLOR_TO_NS_RGB(normalGroup.light()); + break; + + case eColor_window: + case eColor_windowframe: + aColor = QCOLOR_TO_NS_RGB(normalGroup.background()); + break; + + case eColor_windowtext: + aColor = QCOLOR_TO_NS_RGB(normalGroup.text()); + break; + + // from the CSS3 working draft (not yet finalized) + // http://www.w3.org/tr/2000/wd-css3-userint-20000216.html#color + case eColor__moz_field: + aColor = QCOLOR_TO_NS_RGB(normalGroup.base()); + break; + + case eColor__moz_fieldtext: + aColor = QCOLOR_TO_NS_RGB(normalGroup.text()); + break; + + case eColor__moz_dialog: + aColor = QCOLOR_TO_NS_RGB(normalGroup.background()); + break; + + case eColor__moz_dialogtext: + aColor = QCOLOR_TO_NS_RGB(normalGroup.text()); + break; + + case eColor__moz_dragtargetzone: + aColor = QCOLOR_TO_NS_RGB(activeGroup.background()); + break; + + default: + aColor = 0; + res = NS_ERROR_FAILURE; + break; + } + return res; +} + +static const char *metricToString[] = { + "eMetric_WindowTitleHeight", + "eMetric_WindowBorderWidth", + "eMetric_WindowBorderHeight", + "eMetric_Widget3DBorder", + "eMetric_TextFieldBorder" + "eMetric_TextFieldHeight", + "eMetric_TextVerticalInsidePadding", + "eMetric_TextShouldUseVerticalInsidePadding", + "eMetric_TextHorizontalInsideMinimumPadding", + "eMetric_TextShouldUseHorizontalInsideMinimumPadding", + "eMetric_ButtonHorizontalInsidePaddingNavQuirks", + "eMetric_ButtonHorizontalInsidePaddingOffsetNavQuirks", + "eMetric_CheckboxSize", + "eMetric_RadioboxSize", + + "eMetric_ListShouldUseHorizontalInsideMinimumPadding", + "eMetric_ListHorizontalInsideMinimumPadding", + + "eMetric_ListShouldUseVerticalInsidePadding", + "eMetric_ListVerticalInsidePadding", + + "eMetric_CaretBlinkTime", + "eMetric_SingleLineCaretWidth", + "eMetric_MultiLineCaretWidth", + "eMetric_ShowCaretDuringSelection", + "eMetric_SelectTextfieldsOnKeyFocus", + "eMetric_SubmenuDelay", + "eMetric_MenusCanOverlapOSBar", + "eMetric_DragFullWindow", + "eMetric_DragThresholdX", + "eMetric_DragThresholdY", + "eMetric_UseAccessibilityTheme", + + "eMetric_ScrollArrowStyle", + "eMetric_ScrollSliderStyle", + + "eMetric_TreeOpenDelay", + "eMetric_TreeCloseDelay", + "eMetric_TreeLazyScrollDelay", + "eMetric_TreeScrollDelay", + "eMetric_TreeScrollLinesMax" + }; + + +NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID,PRInt32 &aMetric) +{ +// qDebug("nsLookAndFeel::GetMetric aID = %s", metricToString[aID]); + nsresult res = nsXPLookAndFeel::GetMetric(aID, aMetric); + if (NS_SUCCEEDED(res)) + return res; +// qDebug(" checking ourselves"); + res = NS_OK; + + switch (aID) { + case eMetric_WindowTitleHeight: + aMetric = 0; + break; + + case eMetric_WindowBorderWidth: + // There was once code in nsDeviceContextQt::GetSystemAttribute to + // use the border width obtained from a widget in its Init method. + break; + + case eMetric_WindowBorderHeight: + // There was once code in nsDeviceContextQt::GetSystemAttribute to + // use the border width obtained from a widget in its Init method. + break; + + case eMetric_Widget3DBorder: + aMetric = 4; + break; + + case eMetric_TextFieldHeight: + aMetric = 15; + break; + + case eMetric_TextFieldBorder: + aMetric = 2; + break; + + case eMetric_TextVerticalInsidePadding: + aMetric = 0; + break; + + case eMetric_TextShouldUseVerticalInsidePadding: + aMetric = 0; + break; + + case eMetric_TextHorizontalInsideMinimumPadding: + aMetric = 15; + break; + + case eMetric_TextShouldUseHorizontalInsideMinimumPadding: + aMetric = 1; + break; + + case eMetric_ButtonHorizontalInsidePaddingNavQuirks: + aMetric = 10; + break; + + case eMetric_ButtonHorizontalInsidePaddingOffsetNavQuirks: + aMetric = 8; + break; + + case eMetric_CheckboxSize: + aMetric = 15; + break; + + case eMetric_RadioboxSize: + aMetric = 15; + break; + + case eMetric_ListShouldUseHorizontalInsideMinimumPadding: + aMetric = 15; + break; + + case eMetric_ListHorizontalInsideMinimumPadding: + aMetric = 15; + break; + + case eMetric_ListShouldUseVerticalInsidePadding: + aMetric = 1; + break; + + case eMetric_ListVerticalInsidePadding: + aMetric = 1; + break; + + case eMetric_CaretBlinkTime: + aMetric = 500; + break; + + case eMetric_SingleLineCaretWidth: + case eMetric_MultiLineCaretWidth: + aMetric = 1; + break; + + case eMetric_ShowCaretDuringSelection: + aMetric = 0; + break; + + case eMetric_SelectTextfieldsOnKeyFocus: + // Select textfield content when focused by kbd + // used by nsEventStateManager::sTextfieldSelectModel + aMetric = 1; + break; + + case eMetric_SubmenuDelay: + aMetric = 200; + break; + + case eMetric_MenusCanOverlapOSBar: + // we want XUL popups to be able to overlap the task bar. + aMetric = 1; + break; + + case eMetric_DragFullWindow: + aMetric = 1; + break; + + case eMetric_ScrollArrowStyle: + aMetric = eMetric_ScrollArrowStyleSingle; + break; + + case eMetric_ScrollSliderStyle: + aMetric = eMetric_ScrollThumbStyleProportional; + break; + + default: + aMetric = 0; + res = NS_ERROR_FAILURE; + } + return res; +} + +NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricFloatID aID, + float &aMetric) +{ + nsresult res = nsXPLookAndFeel::GetMetric(aID, aMetric); + if (NS_SUCCEEDED(res)) + return res; + res = NS_OK; + + switch (aID) { + case eMetricFloat_TextFieldVerticalInsidePadding: + aMetric = 0.25f; + break; + + case eMetricFloat_TextFieldHorizontalInsidePadding: + aMetric = 0.95f; // large number on purpose so minimum padding is used + break; + + case eMetricFloat_TextAreaVerticalInsidePadding: + aMetric = 0.40f; + break; + + case eMetricFloat_TextAreaHorizontalInsidePadding: + aMetric = 0.40f; // large number on purpose so minimum padding is used + break; + + case eMetricFloat_ListVerticalInsidePadding: + aMetric = 0.10f; + break; + + case eMetricFloat_ListHorizontalInsidePadding: + aMetric = 0.40f; + break; + + case eMetricFloat_ButtonVerticalInsidePadding: + aMetric = 0.25f; + break; + + case eMetricFloat_ButtonHorizontalInsidePadding: + aMetric = 0.25f; + break; + + default: + aMetric = -1.0; + res = NS_ERROR_FAILURE; + } + return res; +} diff --git a/mozilla/widget/src/qt/nsLookAndFeel.h b/mozilla/widget/src/qt/nsLookAndFeel.h new file mode 100644 index 00000000000..e957109393a --- /dev/null +++ b/mozilla/widget/src/qt/nsLookAndFeel.h @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * John C. Griggs + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ +#ifndef __nsLookAndFeel +#define __nsLookAndFeel + +#include "nsXPLookAndFeel.h" + +class nsLookAndFeel: public nsXPLookAndFeel +{ +public: + nsLookAndFeel(); + virtual ~nsLookAndFeel(); + + nsresult NativeGetColor(const nsColorID aID, nscolor &aColor); + NS_IMETHOD GetMetric(const nsMetricID aID, PRInt32 & aMetric); + NS_IMETHOD GetMetric(const nsMetricFloatID aID, float & aMetric); +}; + +#endif diff --git a/mozilla/widget/src/qt/nsMime.cpp b/mozilla/widget/src/qt/nsMime.cpp new file mode 100644 index 00000000000..26c85ea43b4 --- /dev/null +++ b/mozilla/widget/src/qt/nsMime.cpp @@ -0,0 +1,184 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * Denis Issoupov + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsDragService.h" +#include "nsIServiceManager.h" +#include "nsXPCOM.h" +#include "nsISupportsPrimitives.h" +#include "nsXPIDLString.h" +#include "nsPrimitiveHelpers.h" +#include "nsReadableUtils.h" +#include "nsClipboard.h" +#include "nsMime.h" +#include "nsCRT.h" + +#include +#include + +//---------------------------------------------------------- +nsMimeStoreData::nsMimeStoreData(QCString& name, QByteArray& data) +{ + flavorName = name; + flavorData = data; +} + +nsMimeStoreData::nsMimeStoreData(const char* name,void* rawdata,PRInt32 rawlen) +{ + flavorName = name; + flavorData.assign((char*)rawdata,(unsigned int)rawlen); +} + +//---------------------------------------------------------- +nsMimeStore::nsMimeStore() +{ + mMimeStore.setAutoDelete(TRUE); +} + +nsMimeStore::~nsMimeStore() +{ +} + +const char* nsMimeStore::format(int n) const +{ + if (n >= (int)mMimeStore.count()) + return 0; + + // because of const + + const nsMimeStoreData* msd; + msd = mMimeStore.at(n); + + return msd->flavorName; +} + +QByteArray nsMimeStore::encodedData(const char* name) const +{ + QByteArray qba; + + QString mime(name); + + /* XXX: for some reason in here we're getting mimetype + * with charset, eg "text/plain;charset=UTF-8" so here + * we remove the charset + */ + int n = mime.findRev(";"); + mime = mime.remove(n, mime.length() - n); + + // because of const + nsMimeStoreData* msd; + QPtrList::const_iterator it = mMimeStore.begin(); + while ((msd = *it)) { + if (mime.utf8() == msd->flavorName) { + qba = msd->flavorData; + return qba; + } + ++it; + } +#ifdef NS_DEBUG + printf("nsMimeStore::encodedData requested unknown %s\n", name); +#endif + return qba; +} + +PRBool nsMimeStore::ContainsFlavor(const char* name) +{ + for (nsMimeStoreData *msd = mMimeStore.first(); msd; msd = mMimeStore.next()) { + if (!strcmp(name, msd->flavorName)) + return PR_TRUE; + } + return PR_FALSE; +} + +PRBool nsMimeStore::AddFlavorData(const char* name, void* data, PRInt32 len) +{ + if (ContainsFlavor(name)) + return PR_FALSE; + mMimeStore.append(new nsMimeStoreData(name, data, len)); + + // we're done unless we're given text/unicode, + // and text/plain is not already advertised, + if (strcmp(name, kUnicodeMime) || ContainsFlavor(kTextMime)) + return PR_TRUE; + // in which case we also advertise text/plain + // which we will convert on our own in nsDataObj::GetText(). + + char *as = ToNewCString(nsDependentString((PRUnichar*)data)); + + // let's text/plain be first for stupid programs + // Ownership of |as| is transfered to mMimeStore + mMimeStore.insert(0,new nsMimeStoreData(kTextMime,as,nsCRT::strlen(as) + 1)); + return PR_TRUE; +} + +//---------------------------------------------------------- +nsDragObject::nsDragObject(nsMimeStore* mimeStore,QWidget* dragSource, + const char* name) + : QDragObject(dragSource, name) +{ + if (!mimeStore) + NS_ASSERTION(PR_TRUE, "Invalid pointer."); + + mMimeStore = mimeStore; +} + +nsDragObject::~nsDragObject() +{ + delete mMimeStore; +} + +const char* nsDragObject::format(int i) const +{ + if (i >= (int)mMimeStore->count()) + return 0; + + const char* frm = mMimeStore->format(i); +#ifdef NS_DEBUG + printf("nsDragObject::format i=%i %s\n",i, frm); +#endif + return frm; +} + +QByteArray nsDragObject::encodedData(const char* frm) const +{ +#ifdef NS_DEBUG + printf("nsDragObject::encodedData %s\n",frm); +#endif + return mMimeStore->encodedData(frm); +} diff --git a/mozilla/widget/src/qt/nsMime.h b/mozilla/widget/src/qt/nsMime.h new file mode 100644 index 00000000000..fb18720eb29 --- /dev/null +++ b/mozilla/widget/src/qt/nsMime.h @@ -0,0 +1,98 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * Denis Issoupov + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ +#ifndef nsMime_h__ +#define nsMime_h__ + +#include "nsITransferable.h" +#include "nsCOMPtr.h" + +#include +#include +#include +#include +#include + +class nsMimeStoreData +{ +public: + nsMimeStoreData(QCString& name, QByteArray& data); + nsMimeStoreData(const char* name, void* rawdata, PRInt32 rawlen); + + QCString flavorName; + QByteArray flavorData; +}; + +class nsMimeStore: public QMimeSource +{ +public: + nsMimeStore(); + virtual ~nsMimeStore(); + + virtual const char* format(int n = 0) const ; + virtual QByteArray encodedData(const char*) const; + + PRBool AddFlavorData(const char* name, void* data, PRInt32 len); + PRBool ContainsFlavor(const char* name); + PRUint32 count(); + +protected: + mutable QPtrList mMimeStore; + nsMimeStoreData* at(int n); +}; + +inline PRUint32 nsMimeStore::count() { return mMimeStore.count(); } + +//---------------------------------------------------------- +class nsDragObject : public QDragObject +{ + Q_OBJECT +public: + nsDragObject(nsMimeStore* mimeStore,QWidget* dragSource = 0, + const char* name = 0); + ~nsDragObject(); + + const char* format(int i) const; + virtual QByteArray encodedData(const char*) const; + +protected: + nsMimeStore* mMimeStore; +}; + +#endif diff --git a/mozilla/widget/src/qt/nsQtEventDispatcher.cpp b/mozilla/widget/src/qt/nsQtEventDispatcher.cpp new file mode 100644 index 00000000000..3c1117a3401 --- /dev/null +++ b/mozilla/widget/src/qt/nsQtEventDispatcher.cpp @@ -0,0 +1,230 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 "nsQtEventDispatcher.h" + +#include "nsCommonWidget.h" + +#include +#include + +nsQtEventDispatcher::nsQtEventDispatcher(nsCommonWidget *receiver, + QWidget *watchedWidget, + const char *name, bool paint ) + : QObject(watchedWidget, name), + mReceiver(receiver), + m_paint(paint) + +{ + watchedWidget->installEventFilter(this); +} + +bool +nsQtEventDispatcher::eventFilter(QObject *o, QEvent *e) +{ +#if 0 + if (m_paint && e->type() == QEvent::Paint) { + qDebug("MMM PAINT FROM %d", o); + QPaintEvent *ev = (QPaintEvent*)(e); + return mReceiver->paintEvent(ev); + } +#endif + + switch(e->type()) { + case QEvent::Accessibility: + { + qDebug("accessibility event received"); + } + break; + case QEvent::MouseButtonPress: + { + QMouseEvent *ms = (QMouseEvent*)(e); + return mReceiver->mousePressEvent(ms); + } + break; + case QEvent::MouseButtonRelease: + { + QMouseEvent *ms = (QMouseEvent*)(e); + return mReceiver->mouseReleaseEvent(ms); + } + break; + case QEvent::MouseButtonDblClick: + { + QMouseEvent *ms = (QMouseEvent*)(e); + return mReceiver->mouseDoubleClickEvent(ms); + } + break; + case QEvent::MouseMove: + { + QMouseEvent *ms = (QMouseEvent*)(e); + return mReceiver->mouseMoveEvent(ms); + } + break; + case QEvent::KeyPress: + { + QKeyEvent *kev = (QKeyEvent*)(e); + return mReceiver->keyPressEvent(kev); + } + break; + case QEvent::KeyRelease: + { + QKeyEvent *kev = (QKeyEvent*)(e); + return mReceiver->keyReleaseEvent(kev); + } + break; + case QEvent::IMStart: + { + QIMEvent *iev = (QIMEvent*)(e); + return mReceiver->imStartEvent(iev); + } + break; + case QEvent::IMCompose: + { + QIMEvent *iev = (QIMEvent*)(e); + return mReceiver->imComposeEvent(iev); + } + break; + case QEvent::IMEnd: + { + QIMEvent *iev = (QIMEvent*)(e); + return mReceiver->imEndEvent(iev); + } + break; + case QEvent::FocusIn: + { + QFocusEvent *fev = (QFocusEvent*)(e); + return mReceiver->focusInEvent(fev); + } + break; + case QEvent::FocusOut: + { + QFocusEvent *fev = (QFocusEvent*)(e); + return mReceiver->focusOutEvent(fev); + } + break; + case QEvent::Enter: + { + return mReceiver->enterEvent(e); + } + break; + case QEvent::Leave: + { + return mReceiver->enterEvent(e); + } + break; + case QEvent::Paint: + { + QPaintEvent *ev = (QPaintEvent*)(e); + mReceiver->paintEvent(ev); + return TRUE; + } + break; + case QEvent::Move: + { + QMoveEvent *mev = (QMoveEvent*)(e); + return mReceiver->moveEvent(mev); + } + break; + case QEvent::Resize: + { + QResizeEvent *rev = (QResizeEvent*)(e); + return mReceiver->resizeEvent(rev); + } + break; + case QEvent::Show: + { + QShowEvent *sev = (QShowEvent*)(e); + return mReceiver->showEvent(sev); + } + break; + case QEvent::Hide: + { + QHideEvent *hev = (QHideEvent*)(e); + return mReceiver->hideEvent(hev); + } + break; + case QEvent::Close: + { + QCloseEvent *cev = (QCloseEvent*)(e); + return mReceiver->closeEvent(cev); + } + break; + case QEvent::Wheel: + { + QWheelEvent *wev = (QWheelEvent*)(e); + return mReceiver->wheelEvent(wev); + } + break; + case QEvent::ContextMenu: + { + QContextMenuEvent *cev = (QContextMenuEvent*)(e); + return mReceiver->contextMenuEvent(cev); + } + break; + case QEvent::DragEnter: + { + QDragEnterEvent *dev = (QDragEnterEvent*)(e); + return mReceiver->dragEnterEvent(dev); + } + break; + case QEvent::DragMove: + { + QDragMoveEvent *dev = (QDragMoveEvent*)(e); + return mReceiver->dragMoveEvent(dev); + } + break; + case QEvent::DragLeave: + { + QDragLeaveEvent *dev = (QDragLeaveEvent*)(e); + return mReceiver->dragLeaveEvent(dev); + } + break; + case QEvent::Drop: + { + QDropEvent *dev = (QDropEvent*)(e); + return mReceiver->dropEvent(dev); + } + break; + default: + break; + } + + return FALSE; +} + diff --git a/mozilla/widget/src/qt/nsQtEventDispatcher.h b/mozilla/widget/src/qt/nsQtEventDispatcher.h new file mode 100644 index 00000000000..afe672e762b --- /dev/null +++ b/mozilla/widget/src/qt/nsQtEventDispatcher.h @@ -0,0 +1,64 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 NSQTEVENTDISPATCHER_H +#define NSQTEVENTDISPATCHER_H + +#include + +class nsCommonWidget; +class QEvent; +class QWidget; + +class nsQtEventDispatcher : public QObject +{ + Q_OBJECT +public: + nsQtEventDispatcher(nsCommonWidget *receiver, QWidget *watchedObject, + const char *name=0, bool justPaint = false); + +protected: + bool eventFilter(QObject *, QEvent *); + +protected: + nsCommonWidget *mReceiver; + bool m_paint; +}; + +#endif diff --git a/mozilla/widget/src/qt/nsScrollbar.cpp b/mozilla/widget/src/qt/nsScrollbar.cpp new file mode 100644 index 00000000000..ffb3e5291d9 --- /dev/null +++ b/mozilla/widget/src/qt/nsScrollbar.cpp @@ -0,0 +1,292 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 "nsScrollbar.h" +#include "nsGUIEvent.h" + +#define mScroll ((QScrollBar*)mWidget) + +nsQScrollBar::nsQScrollBar(int aMinValue, int aMaxValue, int aLineStep, + int aPageStep, int aValue, Orientation aOrientation, + QWidget *aParent, const char *aName) + : QScrollBar(aMinValue, aMaxValue, aLineStep, aPageStep, aValue, + aOrientation, aParent, aName) +{ + qDebug("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); + connect(this,SIGNAL(valueChanged(int)), + SLOT(slotValueChanged(int))); +} + +void nsQScrollBar::slotValueChanged(int aValue) +{ + ScrollBarMoved(NS_SCROLLBAR_POS,aValue); +} + +void nsQScrollBar::ScrollBarMoved(int aMessage,int aValue) +{ + nsScrollbarEvent nsEvent; + + nsEvent.message = aMessage; + nsEvent.widget = 0; + nsEvent.eventStructType = NS_SCROLLBAR_EVENT; + nsEvent.position = aValue; + + //mReceiver->scrollEvent(nsEvent,aValue); + //FIXME: +} + +//============================================================================= +// nsScrollBar class +//============================================================================= +NS_IMPL_ADDREF_INHERITED(nsNativeScrollbar,nsCommonWidget) +NS_IMPL_RELEASE_INHERITED(nsNativeScrollbar,nsCommonWidget) +NS_IMPL_QUERY_INTERFACE2(nsNativeScrollbar,nsINativeScrollbar,nsIWidget) + +nsNativeScrollbar::nsNativeScrollbar() + : nsCommonWidget(), + nsINativeScrollbar() +{ + + qDebug("YESSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS"); + mOrientation = true ? QScrollBar::Vertical : QScrollBar::Horizontal; + mLineStep = 1; + mPageStep = 10; + mMaxValue = 100; + mValue = 0; + mListenForResizes = PR_TRUE; +} + +nsNativeScrollbar::~nsNativeScrollbar() +{ +} + +NS_METHOD +nsNativeScrollbar::SetMaxRange(PRUint32 aEndRange) +{ + mMaxValue = aEndRange; + + mScroll->setRange(0,mMaxValue - mPageStep); + + return NS_OK; +} + +NS_METHOD +nsNativeScrollbar::GetMaxRange(PRUint32 *aMaxRange) +{ + *aMaxRange = mMaxValue; + return NS_OK; +} + +NS_METHOD nsNativeScrollbar::SetPosition(PRUint32 aPos) +{ + mValue = aPos; + + mScroll->setValue(mValue); + + return NS_OK; +} + +NS_METHOD +nsNativeScrollbar::GetPosition(PRUint32 *aPos) +{ + *aPos = mValue; + return NS_OK; +} + +//------------------------------------------------------------------------- +// Set the line increment for this scrollbar +//------------------------------------------------------------------------- +NS_METHOD +nsNativeScrollbar::SetLineIncrement(PRUint32 aLineIncrement) +{ + if (aLineIncrement > 0) { + mLineStep = aLineIncrement; + + mScroll->setSteps(mLineStep,mPageStep); + } + return NS_OK; +} + +//------------------------------------------------------------------------- +// Get the line increment for this scrollbar +//------------------------------------------------------------------------- +NS_METHOD +nsNativeScrollbar::GetLineIncrement(PRUint32 *aLineInc) +{ + *aLineInc = mLineStep; + return NS_OK; +} + +#if 0 +NS_METHOD +nsNativeScrollbar::SetParameters(PRUint32 aMaxRange,PRUint32 aThumbSize, + PRUint32 aPosition,PRUint32 aLineIncrement) +{ + mPageStep = (aThumbSize > 0) ? aThumbSize : 1; + mValue = (aPosition > 0) ? aPosition : 0; + mLineStep = (aLineIncrement > 0) ? aLineIncrement : 1; + mMaxValue = (aMaxRange > 0) ? aMaxRange : 10; + + mScroll->setValue(mValue); + mScroll->setSteps(mLineStep,mPageStep); + mScroll->setRange(0,mMaxValue - mPageStep); + return NS_OK; +} +#endif + +//------------------------------------------------------------------------- +// Deal with scrollbar messages (actually implemented only in nsNativeScrollbar) +//------------------------------------------------------------------------- +PRBool nsNativeScrollbar::OnScroll(nsScrollbarEvent &aEvent,PRUint32 cPos) +{ + nsEventStatus result = nsEventStatus_eIgnore; + + switch (aEvent.message) { + // scroll one line right or down + case NS_SCROLLBAR_LINE_NEXT: + mScroll->addLine(); + mValue = mScroll->value(); + + // if an event callback is registered, give it the chance + // to change the increment + if (mEventCallback) { + aEvent.position = (PRUint32)mValue; + result = (*mEventCallback)(&aEvent); + mValue = aEvent.position; + } + break; + + // scroll one line left or up + case NS_SCROLLBAR_LINE_PREV: + mScroll->subtractLine(); + mValue = mScroll->value(); + + // if an event callback is registered, give it the chance + // to change the decrement + if (mEventCallback) { + aEvent.position = (PRUint32)mValue; + result = (*mEventCallback)(&aEvent); + mValue = aEvent.position; + } + break; + + // Scrolls one page right or down + case NS_SCROLLBAR_PAGE_NEXT: + mScroll->addPage(); + mValue = mScroll->value(); + + // if an event callback is registered, give it the chance + // to change the increment + if (mEventCallback) { + aEvent.position = (PRUint32)mValue; + result = (*mEventCallback)(&aEvent); + mValue = aEvent.position; + } + break; + + // Scrolls one page left or up. + case NS_SCROLLBAR_PAGE_PREV: + mScroll->subtractPage(); + mValue = mScroll->value(); + + // if an event callback is registered, give it the chance + // to change the increment + if (mEventCallback) { + aEvent.position = (PRUint32)mValue; + result = (*mEventCallback)(&aEvent); + mValue = aEvent.position; + } + break; + + // Scrolls to the absolute position. The current position is specified by + // the cPos parameter. + case NS_SCROLLBAR_POS: + mValue = cPos; + + // if an event callback is registered, give it the chance + // to change the increment + if (mEventCallback) { + aEvent.position = (PRUint32)mValue; + result = (*mEventCallback)(&aEvent); + mValue = aEvent.position; + } + break; + } + + return ignoreEvent(result); +} + +QWidget* +nsNativeScrollbar::createQWidget(QWidget *parent, nsWidgetInitData */*aInitData*/) +{ + mWidget = new nsQScrollBar(0, mMaxValue, mLineStep, mPageStep, + mValue, mOrientation, parent); + mWidget->setMouseTracking(PR_TRUE); + + return mWidget; +} + +/* void setContent (in nsIContent content, in nsISupports scrollbar, in nsIScrollbarMediator mediator); */ +NS_IMETHODIMP +nsNativeScrollbar::SetContent(nsIContent *content, nsISupports *scrollbar, nsIScrollbarMediator *mediator) +{ + qDebug("XXXXXXXX SetContent"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* readonly attribute long narrowSize; */ +NS_IMETHODIMP +nsNativeScrollbar::GetNarrowSize(PRInt32 *aNarrowSize) +{ + qDebug("XXXXXXXXXXXX GetNarrowSize"); + return NS_ERROR_NOT_IMPLEMENTED; +} +/* attribute unsigned long viewSize; */ +NS_IMETHODIMP +nsNativeScrollbar::GetViewSize(PRUint32 *aViewSize) +{ + qDebug("XXXXXXXXX GetViewSize"); + return NS_ERROR_NOT_IMPLEMENTED; +} +NS_IMETHODIMP +nsNativeScrollbar::SetViewSize(PRUint32 aViewSize) +{ + qDebug("XXXXXXXXXXX SetViewSize"); + return NS_ERROR_NOT_IMPLEMENTED; +} diff --git a/mozilla/widget/src/qt/nsScrollbar.h b/mozilla/widget/src/qt/nsScrollbar.h new file mode 100644 index 00000000000..e4312345dc1 --- /dev/null +++ b/mozilla/widget/src/qt/nsScrollbar.h @@ -0,0 +1,99 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 nsScrollbar_h__ +#define nsScrollbar_h__ + +#include "nsCommonWidget.h" +#include "nsINativeScrollbar.h" +#include + +//============================================================================= +// nsQScrollBar class: +// Customizes QScrollBar for use by XPFE +//============================================================================= +class nsQScrollBar : public QScrollBar +{ + Q_OBJECT +public: + nsQScrollBar(int aMinValue, int aMaxValue, int aLineStep, + int aPageStep, int aValue, Orientation aOrientation, + QWidget *aParent, const char *aName = 0); + + void ScrollBarMoved(int aMessage,int aValue = -1); + +public slots: + void slotValueChanged(int aValue); +private: +}; + +//============================================================================= +// nsScrollBar class: +// the XPFE Scrollbar +//============================================================================= +class nsNativeScrollbar : public nsCommonWidget, + public nsINativeScrollbar +{ +public: + nsNativeScrollbar(); + virtual ~nsNativeScrollbar(); + + // nsISupports + NS_DECL_ISUPPORTS_INHERITED + NS_DECL_NSINATIVESCROLLBAR + + // nsIScrollBar implementation + + virtual PRBool OnScroll(nsScrollbarEvent &aEvent,PRUint32 cPos); + + virtual PRBool IsScrollBar() const { return PR_TRUE; } +protected: + QWidget *createQWidget(QWidget *parent, nsWidgetInitData *aInitData); + + +private: + QScrollBar::Orientation mOrientation; + int mMaxValue; + int mLineStep; + int mPageStep; + int mValue; + PRUint32 mNsSBID; +}; + +#endif // nsScrollbar_h__ diff --git a/mozilla/widget/src/qt/nsSound.cpp b/mozilla/widget/src/qt/nsSound.cpp new file mode 100644 index 00000000000..80533d36b9f --- /dev/null +++ b/mozilla/widget/src/qt/nsSound.cpp @@ -0,0 +1,114 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 2000 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 + +#include "nscore.h" +#include "plstr.h" +#include "prlink.h" + +#include "nsSound.h" + +#include "nsIURL.h" +#include "nsIFileURL.h" +#include "nsNetUtil.h" +#include "nsCOMPtr.h" + +#include +#include +#include + +NS_IMPL_ISUPPORTS1(nsSound, nsISound) + +//////////////////////////////////////////////////////////////////////// +nsSound::nsSound() +{ +} + +nsSound::~nsSound() +{ +} + +NS_IMETHODIMP +nsSound::Init() +{ + return NS_OK; +} + +NS_METHOD nsSound::Beep() +{ + QApplication::beep(); + + return NS_OK; +} + +NS_METHOD nsSound::Play(nsIURL *aURL) +{ + return NS_ERROR_FAILURE; +} + +NS_IMETHODIMP nsSound::PlaySystemSound(const char *aSoundAlias) +{ + if (!aSoundAlias) + return NS_ERROR_FAILURE; + if (strcmp(aSoundAlias, "_moz_mailbeep") == 0) { + QApplication::beep(); + return NS_OK; + } + + return NS_ERROR_FAILURE; + +// nsresult rv; +// nsCOMPtr fileURI; + +// // create a nsILocalFile and then a nsIFileURL from that +// nsCOMPtr soundFile; +// rv = NS_NewNativeLocalFile(nsDependentCString(aSoundAlias), PR_TRUE, +// getter_AddRefs(soundFile)); +// NS_ENSURE_SUCCESS(rv,rv); + +// rv = NS_NewFileURI(getter_AddRefs(fileURI), soundFile); +// NS_ENSURE_SUCCESS(rv,rv); + +// nsCOMPtr fileURL = do_QueryInterface(fileURI,&rv); +// NS_ENSURE_SUCCESS(rv,rv); +// rv = Play(fileURL); +// return rv; +} diff --git a/mozilla/widget/src/qt/nsSound.h b/mozilla/widget/src/qt/nsSound.h new file mode 100644 index 00000000000..5a2ee9515eb --- /dev/null +++ b/mozilla/widget/src/qt/nsSound.h @@ -0,0 +1,57 @@ +/* + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 2000 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Stuart Parmenter + * + * 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 __nsSound_h__ +#define __nsSound_h__ + +#include "nsISound.h" +#include "nsIStreamLoader.h" + +class nsSound : public nsISound +{ + public: + + nsSound(); + virtual ~nsSound(); + + NS_DECL_ISUPPORTS + NS_DECL_NSISOUND +}; + +#endif /* __nsSound_h__ */ diff --git a/mozilla/widget/src/qt/nsToolkit.cpp b/mozilla/widget/src/qt/nsToolkit.cpp new file mode 100644 index 00000000000..4e766dca2ba --- /dev/null +++ b/mozilla/widget/src/qt/nsToolkit.cpp @@ -0,0 +1,119 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * John C. Griggs + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nscore.h" // needed for 'nsnull' +#include "nsToolkit.h" +#include "nsGUIEvent.h" +#include "plevent.h" + +// Static thread local storage index of the Toolkit +// object associated with a given thread... +static PRUintn gToolkitTLSIndex = 0; + +//------------------------------------------------------------------------- +// constructor +//------------------------------------------------------------------------- +nsToolkit::nsToolkit() +{ +} + +//------------------------------------------------------------------------- +// destructor +//------------------------------------------------------------------------- +nsToolkit::~nsToolkit() +{ + // Remove the TLS reference to the toolkit... + PR_SetThreadPrivate(gToolkitTLSIndex, nsnull); +} + +//------------------------------------------------------------------------- +// nsISupports implementation macro +//------------------------------------------------------------------------- +NS_IMPL_ISUPPORTS1(nsToolkit, nsIToolkit) + +//------------------------------------------------------------------------- +NS_IMETHODIMP nsToolkit::Init(PRThread *aThread) +{ + return NS_OK; +} + +//------------------------------------------------------------------------- +// Return the nsIToolkit for the current thread. If a toolkit does not +// yet exist, then one will be created... +//------------------------------------------------------------------------- +NS_METHOD NS_GetCurrentToolkit(nsIToolkit* *aResult) +{ + nsIToolkit* toolkit = nsnull; + nsresult rv = NS_OK; + PRStatus status; + + // Create the TLS index the first time through... + if (0 == gToolkitTLSIndex) { + status = PR_NewThreadPrivateIndex(&gToolkitTLSIndex, NULL); + if (PR_FAILURE == status) { + rv = NS_ERROR_FAILURE; + } + } + if (NS_SUCCEEDED(rv)) { + toolkit = (nsIToolkit*)PR_GetThreadPrivate(gToolkitTLSIndex); + + // Create a new toolkit for this thread... + if (!toolkit) { + toolkit = new nsToolkit(); + + if (!toolkit) { + rv = NS_ERROR_OUT_OF_MEMORY; + } + else { + NS_ADDREF(toolkit); + toolkit->Init(PR_GetCurrentThread()); + + // The reference stored in the TLS is weak. It is removed in the + // nsToolkit destructor... + PR_SetThreadPrivate(gToolkitTLSIndex, (void*)toolkit); + } + } + else { + NS_ADDREF(toolkit); + } + *aResult = toolkit; + } + return rv; +} diff --git a/mozilla/widget/src/qt/nsToolkit.h b/mozilla/widget/src/qt/nsToolkit.h new file mode 100644 index 00000000000..72217c96bdb --- /dev/null +++ b/mozilla/widget/src/qt/nsToolkit.h @@ -0,0 +1,58 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * John C. Griggs + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ +#ifndef nsToolkit_h__ +#define nsToolkit_h__ + +#include "nsIToolkit.h" + +/** + * Wrapper around the thread running the message pump. + * The toolkit abstraction is necessary because the message pump must + * execute within the same thread that created the widget under Win32. + */ +class nsToolkit : public nsIToolkit +{ +public: + nsToolkit(); + virtual ~nsToolkit(); + + NS_DECL_ISUPPORTS + NS_IMETHOD Init(PRThread *aThread); +}; + +#endif // nsToolkit_h__ diff --git a/mozilla/widget/src/qt/nsWidgetFactory.cpp b/mozilla/widget/src/qt/nsWidgetFactory.cpp new file mode 100644 index 00000000000..d1fc80b6fe5 --- /dev/null +++ b/mozilla/widget/src/qt/nsWidgetFactory.cpp @@ -0,0 +1,155 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: NPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Netscape 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/NPL/ + * + * 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * John C. Griggs + * Portions created by the Initial Developer are Copyright (C) 2000 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Zack Rusin + * Lars Knoll + * John C. Griggs + * Dan Rosen + * + * 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 NPL, 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 NPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsIGenericFactory.h" +#include "nsIModule.h" +#include "nsCOMPtr.h" +#include "nsWidgetsCID.h" +#include "nsIComponentRegistrar.h" +#include "nsComponentManagerUtils.h" +#include "nsAutoPtr.h" + +#include "nsWindow.h" +#include "nsAppShell.h" +#include "nsToolkit.h" +#include "nsLookAndFeel.h" +#include "nsTransferable.h" +#include "nsClipboard.h" +#include "nsClipboardHelper.h" +#include "nsHTMLFormatConverter.h" +#include "nsDragService.h" +#include "nsScrollbar.h" +#include "nsFilePicker.h" +#include "nsSound.h" + +#include "nsGUIEvent.h" +#include "nsQtEventDispatcher.h" +#include "nsIRenderingContext.h" +#include "nsIServiceManager.h" +#include "nsGfxCIID.h" +#include "nsIPrefBranch.h" +#include "nsIPrefService.h" + +#include "nsBidiKeyboard.h" + +static NS_DEFINE_CID(kNativeScrollCID, NS_NATIVESCROLLBAR_CID); + +NS_GENERIC_FACTORY_CONSTRUCTOR(nsWindow) +NS_GENERIC_FACTORY_CONSTRUCTOR(ChildWindow) +NS_GENERIC_FACTORY_CONSTRUCTOR(PopupWindow) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsAppShell) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsToolkit) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsLookAndFeel) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsTransferable) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboard) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsClipboardHelper) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTMLFormatConverter) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsDragService) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsBidiKeyboard) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsNativeScrollbar) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsSound) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsFilePicker) + +static const nsModuleComponentInfo components[] = +{ + { "Qt nsWindow", + NS_WINDOW_CID, + "@mozilla.org/widgets/window/qt;1", + nsWindowConstructor }, + { "Qt Child nsWindow", + NS_CHILD_CID, + "@mozilla.org/widgets/child_window/qt;1", + ChildWindowConstructor }, + { "Qt Popup nsWindow", + NS_POPUP_CID, + "@mozilla.org/widgets/popup_window/qt;1", + PopupWindowConstructor }, + { "Qt Native Scrollbar", + NS_NATIVESCROLLBAR_CID, + "@mozilla.org/widget/nativescrollbar/qt;1", + nsNativeScrollbarConstructor}, + { "Qt AppShell", + NS_APPSHELL_CID, + "@mozilla.org/widget/appshell/qt;1", + nsAppShellConstructor }, + { "Qt Toolkit", + NS_TOOLKIT_CID, + "@mozilla.org/widget/toolkit/qt;1", + nsToolkitConstructor }, + { "Qt Look And Feel", + NS_LOOKANDFEEL_CID, + "@mozilla.org/widget/lookandfeel/qt;1", + nsLookAndFeelConstructor }, + { "Transferrable", + NS_TRANSFERABLE_CID, + "@mozilla.org/widget/transferable;1", + nsTransferableConstructor }, + { "Qt Clipboard", + NS_CLIPBOARD_CID, + "@mozilla.org/widget/clipboard;1", + nsClipboardConstructor }, + { "Clipboard Helper", + NS_CLIPBOARDHELPER_CID, + "@mozilla.org/widget/clipboardhelper;1", + nsClipboardHelperConstructor }, + { "HTML Format Converter", + NS_HTMLFORMATCONVERTER_CID, + "@mozilla.org/widget/htmlformatconverter/qt;1", + nsHTMLFormatConverterConstructor }, + { "Qt Drag Service", + NS_DRAGSERVICE_CID, + "@mozilla.org/widget/dragservice;1", + nsDragServiceConstructor }, + { "Qt Bidi Keyboard", + NS_BIDIKEYBOARD_CID, + "@mozilla.org/widget/bidikeyboard;1", + nsBidiKeyboardConstructor }, + { "Qt Sound", + NS_SOUND_CID, + "@mozilla.org/sound;1", + nsSoundConstructor }, + { "Qt File Picker", + NS_FILEPICKER_CID, + "@mozilla.org/filepicker;1", + nsFilePickerConstructor } +}; + +NS_IMPL_NSGETMODULE(nsWidgetQtModule,components) diff --git a/mozilla/widget/src/qt/nsWindow.cpp b/mozilla/widget/src/qt/nsWindow.cpp new file mode 100644 index 00000000000..40eb05b09cb --- /dev/null +++ b/mozilla/widget/src/qt/nsWindow.cpp @@ -0,0 +1,149 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 "nsWindow.h" + +#include "nsQtEventDispatcher.h" + +#include +#include +#include + +NS_IMPL_ISUPPORTS_INHERITED1(nsWindow, nsCommonWidget, + nsISupportsWeakReference) + +nsWindow::nsWindow() +{ +} + +nsWindow::~nsWindow() +{ +} + +QWidget* +nsWindow::createQWidget(QWidget *parent, nsWidgetInitData *aInitData) +{ + Qt::WFlags flags = Qt::WNoAutoErase|Qt::WStaticContents; + qDebug("\tparent is %p", (void*)parent); + if (parent) + parent->dumpObjectInfo(); + // ok, create our windows + switch (mWindowType) { + case eWindowType_dialog: + case eWindowType_popup: + case eWindowType_toplevel: + case eWindowType_invisible: { + if (mWindowType == eWindowType_dialog) { + flags |= Qt::WType_Dialog; + qDebug("\t\t#### dialog"); + mContainer = new QWidget(parent, "topLevelDialog", flags); + //SetDefaultIcon(); + } + else if (mWindowType == eWindowType_popup) { + flags |= Qt::WType_Popup; + mContainer = new QWidget(parent, "topLevelPopup", flags); + qDebug("\t\t#### popup"); + mContainer->setFocusPolicy(QWidget::WheelFocus); + } + else { // must be eWindowType_toplevel + flags |= Qt::WType_TopLevel; + qDebug("\t\t#### toplevel"); + mContainer = new QWidget(parent, "topLevelWindow", flags); + //SetDefaultIcon(); + } + + //QBoxLayout *l = new QVBoxLayout(mContainer); + // and the drawing area + //mWidget = new QWidget(mContainer, "paintArea"); + //l->addWidget(mWidget); + mWidget = mContainer; + } + break; + case eWindowType_child: { + qDebug("\t\t#### child"); + mWidget = new QWidget(parent, "paintArea"); + } + break; + default: + break; + } + + mWidget->setBackgroundMode(Qt::NoBackground); + + // attach listeners for events + mDispatcher = new nsQtEventDispatcher(this, mWidget, "xxxdispatcher", true); + + return mWidget; +} + +NS_IMETHODIMP +nsWindow::PreCreateWidget(nsWidgetInitData *aWidgetInitData) +{ + if (nsnull != aWidgetInitData) { + mWindowType = aWidgetInitData->mWindowType; + mBorderStyle = aWidgetInitData->mBorderStyle; + return NS_OK; + } + return NS_ERROR_FAILURE; +} + +////////////////////////////////////////////////////////////////////// +ChildWindow::ChildWindow() +{ +} + +ChildWindow::~ChildWindow() +{ +} + +PRBool +ChildWindow::IsChild() const +{ + return PR_TRUE; +} + +PopupWindow::PopupWindow() +{ + qDebug("===================== popup!"); +} + +PopupWindow::~PopupWindow() +{ +} + diff --git a/mozilla/widget/src/qt/nsWindow.h b/mozilla/widget/src/qt/nsWindow.h new file mode 100644 index 00000000000..eebb23b6b47 --- /dev/null +++ b/mozilla/widget/src/qt/nsWindow.h @@ -0,0 +1,81 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * ***** 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 mozilla.org code. + * + * The Initial Developer of the Original Code is + * Zack Rusin . + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Lars Knoll + * Zack Rusin + * + * 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 NSWINDOWNG_H +#define NSWINDOWNG_H + +#include "nsCommonWidget.h" +#include "nsWeakReference.h" + +class nsWindow : public nsCommonWidget, + public nsSupportsWeakReference +{ +public: + nsWindow(); + virtual ~nsWindow(); + + + NS_DECL_ISUPPORTS_INHERITED + + NS_IMETHOD PreCreateWidget(nsWidgetInitData *aWidgetInitData); + +protected: + QWidget *createQWidget(QWidget *parent, nsWidgetInitData *aInitData); +}; + +class ChildWindow : public nsWindow +{ +public: + ChildWindow(); + ~ChildWindow(); + virtual PRBool IsChild() const; + + PRInt32 mChildID; +}; + +class PopupWindow : public nsWindow +{ +public: + PopupWindow(); + ~PopupWindow(); + + PRInt32 mChildID; +}; + +#endif diff --git a/mozilla/widget/src/xpwidgets/Makefile.in b/mozilla/widget/src/xpwidgets/Makefile.in index da8f6a5cfb3..d9fe6250b33 100644 --- a/mozilla/widget/src/xpwidgets/Makefile.in +++ b/mozilla/widget/src/xpwidgets/Makefile.in @@ -74,11 +74,11 @@ ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT))) CPPSRCS += nsWidgetAtoms.cpp endif -ifneq (,$(filter beos os2 mac cocoa windows,$(MOZ_WIDGET_TOOLKIT))) +ifneq (,$(filter beos os2 mac qt cocoa windows,$(MOZ_WIDGET_TOOLKIT))) CPPSRCS += nsBaseClipboard.cpp endif -ifneq (,$(filter beos gtk2 os2 mac cocoa photon windows,$(MOZ_WIDGET_TOOLKIT))) +ifneq (,$(filter beos gtk2 os2 mac qt cocoa photon windows,$(MOZ_WIDGET_TOOLKIT))) CPPSRCS += nsBaseFilePicker.cpp REQUIRES += docshell view intl endif diff --git a/mozilla/xpfe/bootstrap/Makefile.in b/mozilla/xpfe/bootstrap/Makefile.in index 1630a833715..368c1da7a11 100644 --- a/mozilla/xpfe/bootstrap/Makefile.in +++ b/mozilla/xpfe/bootstrap/Makefile.in @@ -238,7 +238,7 @@ LIBS += $(MOZ_GTK2_LIBS) endif # Add explicit X11 dependency when building against X11 toolkits -ifneq (,$(filter gtk gtk2 xlib,$(MOZ_WIDGET_TOOLKIT))) +ifneq (,$(filter gtk gtk2 qt xlib,$(MOZ_WIDGET_TOOLKIT))) LIBS += $(XLDFLAGS) $(XLIBS) endif