automatically merged revision 768871:

Make flash embedding work much better..
- Make sure to give distinct callback objects distinct IDs, so they
talk to the proper KHTMLPart. Fixes only one flash object working per
window
- Rework the size/init heuristics yet again, following closer to Seli's code,
but instead of trying to count events, etc., just have the part
tell us when we were really resized, and qwidget isn't making up a random

svn path=/trunk/KDE/kdebase/apps/; revision=768880
This commit is contained in:
Maks Orlovich 2008-01-30 20:54:20 +00:00
parent 3980953c02
commit 8c731bc1d4
12 changed files with 95 additions and 58 deletions

View file

@ -66,9 +66,8 @@ NSPluginInstance::NSPluginInstance(QWidget *parent, const QString& viewerDBusId,
_instanceInterface = new org::kde::nsplugins::Instance( viewerDBusId, id, QDBusConnection::sessionBus() );
_loader = 0;
shown = false;
embedded = false;
resizedAfterShow = false;
haveSize = false;
inited = false;
QGridLayout *_layout = new QGridLayout(this);
_layout->setMargin(1);
@ -82,20 +81,23 @@ NSPluginInstance::NSPluginInstance(QWidget *parent, const QString& viewerDBusId,
show();
} else {
_button = 0;
doLoadPlugin();
}
}
void NSPluginInstance::doLoadPlugin() {
if (!_loader) {
void NSPluginInstance::doLoadPlugin(int w, int h) {
if (!inited) {
delete _button;
_button = 0L;
_loader = NSPluginLoader::instance();
// resize before showing, some plugins are stupid and can't handle repeated
// NPSetWindow() calls very well (viewer will avoid the call if not shown yet)
qApp->syncX();
_instanceInterface->setupWindow(winId(), w, h);
inited = true;
}
}
NSPluginInstance::~NSPluginInstance()
{
kDebug() << "-> NSPluginInstance::~NSPluginInstance";
@ -114,47 +116,37 @@ void NSPluginInstance::windowChanged(WId w)
}
}
void NSPluginInstance::pluginResized(int w, int h)
{
kDebug() << w << h;
haveSize = true;
embedIfNeeded(w, h);
}
/*
Flash 9.0r115 is picky, and only wants to be sized once,
so we want to do it when we're ready. For that, we wait
until we get the 2nd resize from khtml (and not the original
Qt default)
*/
void NSPluginInstance::embedIfNeeded(int w, int h)
{
if (isVisible()) {
if (haveSize && !inited)
doLoadPlugin(w, h);
else if (inited)
resizePlugin(w, h);
}
}
void NSPluginInstance::resizeEvent(QResizeEvent *event)
{
if (shown)
resizedAfterShow = true;
kDebug() << this << shown << resizedAfterShow;
kDebug() << width() << height() << isVisible() << haveSize << inited;
EMBEDCLASS::resizeEvent(event);
QTimer::singleShot(10, this, SLOT(embedIfNeeded()));
embedIfNeeded(width(), height());
}
void NSPluginInstance::showEvent(QShowEvent *event)
{
shown = true;
kDebug() << this << shown << resizedAfterShow;
kDebug() << width() << height() << isVisible() << haveSize << inited;
EMBEDCLASS::showEvent(event);
QTimer::singleShot(10, this, SLOT(embedIfNeeded()));
}
void NSPluginInstance::embedIfNeeded()
{
if (embedded)
return;
if (shown && resizedAfterShow) {
kDebug() << isVisible() << width() << height() << winId() << internalWinId();
show();
qApp->syncX();
embedded = true;
_instanceInterface->setupWindow(winId(), width(), height());
qApp->syncX();
}
embedIfNeeded(width(), height());
}
void NSPluginInstance::javascriptResult(int id, const QString &result)
@ -172,6 +164,12 @@ void NSPluginInstance::focusOutEvent( QFocusEvent* event )
_instanceInterface->gotFocusOut();
}
void NSPluginInstance::resizePlugin( int w, int h )
{
qApp->syncX();
_instanceInterface->resizePlugin( clientWinId(), w, h );
}
/*******************************************************************************/
@ -483,3 +481,4 @@ NSPluginInstance *NSPluginLoader::newInstance(QWidget *parent, const QString& ur
}
// vim: ts=4 sw=4 et
// kate: indent-width 4; replace-tabs on; tab-width 4; space-indent on;

View file

@ -56,9 +56,9 @@ public:
void javascriptResult(int id, const QString &result);
void pluginResized(int w, int h);
private Q_SLOTS:
void doLoadPlugin();
void embedIfNeeded();
void doLoadPlugin(int w, int h);
protected:
void resizeEvent(QResizeEvent *event);
void showEvent(QShowEvent *event);
@ -68,9 +68,11 @@ protected:
private:
class NSPluginLoader *_loader;
OrgKdeNspluginsInstanceInterface *_instanceInterface;
bool shown;
bool embedded; // if embedding was complete
bool resizedAfterShow;
bool inited;
bool haveSize;
void embedIfNeeded(int w, int h);
void resizePlugin(int w, int h );
QPushButton *_button;
QGridLayout *_layout;
};

View file

@ -147,7 +147,7 @@ const KComponentData &PluginFactory::componentData()
if (!s_instance) {
KAboutData about("plugin", 0, ki18n("plugin"), "1.99");
s_instance = new KComponentData(about);
s_instance = new KComponentData(about);
}
return *s_instance;
}
@ -155,14 +155,16 @@ const KComponentData &PluginFactory::componentData()
/**************************************************************************/
static const char* s_callBackObjectPath = "/CallBack";
static int s_callBackObjectCounter;
PluginPart::PluginPart(QWidget *parentWidget, QObject *parent, const QStringList &args)
: KParts::ReadOnlyPart(parent), _widget(0), _args(args),
_destructed(0L)
{
callbackPath = QString::fromLatin1("/Callback") + QString::number(s_callBackObjectCounter);
++s_callBackObjectCounter;
(void) new CallBackAdaptor( this );
QDBusConnection::sessionBus().registerObject( s_callBackObjectPath, this );
QDBusConnection::sessionBus().registerObject( callbackPath, this );
setComponentData(PluginFactory::componentData());
kDebug(1432) << "PluginPart::PluginPart";
@ -261,10 +263,11 @@ bool PluginPart::openUrl(const KUrl &url)
NSPluginInstance *inst = _loader->newInstance( _canvas, surl, smime, embed,
argn, argv,
QDBusConnection::sessionBus().baseService(),
s_callBackObjectPath, reload);
callbackPath, reload);
if ( inst ) {
_widget = inst;
_nspWidget = inst;
} else {
QLabel *label = new QLabel( i18n("Unable to load Netscape plugin for %1", url.url()), _canvas );
label->setAlignment( Qt::AlignCenter );
@ -331,7 +334,7 @@ void PluginPart::evalJavaScript(int id, const QString & script)
if (_widget) {
bool destructed = false;
_destructed = &destructed;
kDebug(1432) <<"evalJavascript: there is a widget";
kDebug(1432) <<"evalJavascript: there is a widget:";
QString rc = _liveconnect->evalJavaScript(script);
if (destructed)
return;
@ -352,7 +355,8 @@ void PluginPart::statusMessage(const QString &msg)
void PluginPart::pluginResized(int w, int h)
{
kDebug(1432) << "PluginPart::pluginResized()";
if (_nspWidget)
_nspWidget->pluginResized(w, h);
if (_widget) {
_widget->resize(w, h);

View file

@ -30,6 +30,7 @@
#include <klibloader.h>
#include <QWidget>
#include <QPointer>
#include "nspluginloader.h"
class KAboutData;
class KComponentData;
@ -101,7 +102,9 @@ protected Q_SLOTS:
void saveAs();
private:
QString callbackPath;
QPointer<QWidget> _widget;
QPointer<NSPluginInstance> _nspWidget;
PluginCanvasWidget *_canvas;
PluginBrowserExtension *_extension;
PluginLiveConnectExtension *_liveconnect;

View file

@ -6,7 +6,7 @@
Copyright (c) 2000 Matthias Hoelzer-Kluepfel <hoelzer@kde.org>
Stefan Schimanski <1Stein@gmx.de>
2003-2005 George Staikos <staikos@kde.org>
2007 Maksim orlovich <maksim@kde.org>
2007, 2008 Maksim Orlovich <maksim@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -896,10 +896,24 @@ void NSPluginInstance::setupWindow(int winId, int w, int h)
else
kWarning(1431) << "No plugin host!";
kDebug(1431) << "<- NSPluginInstance::resizePlugin";
kDebug(1431) << "<- NSPluginInstance::setupWindow";
_width = w;
_height = h;
_embedded = true;
}
void NSPluginInstance::resizePlugin(int clientWinId, int w, int h)
{
kDebug() << _width << w << _height << h << _embedded;
if (!_embedded)
return;
if (w == _width && h == _height)
return;
_pluginHost->resizePlugin(clientWinId, w, h);
_width = w;
_height = h;
}
void NSPluginInstance::javascriptResult(int id, const QString &result) {
QMap<int, Request*>::iterator i = _jsrequests.find( id );

View file

@ -171,6 +171,7 @@ public:
// DBus-exported functions
void shutdown();
void setupWindow(int winId, int w, int h);
void resizePlugin(int clientWinId, int w, int h);
void javascriptResult(int id, const QString &result);
void gotFocusIn();
void gotFocusOut();
@ -214,7 +215,6 @@ private:
friend class NSPluginStreamBase;
void destroy();
void setupWindow(); //Sets up our windows and registers it with the plugin.
bool _destroyed;
bool _embedded;
@ -229,8 +229,8 @@ private:
NPPluginFuncs _pluginFuncs;
PluginHost* _pluginHost; // Manages embedding of the plugin into us
int _width, _height; // last size we used;
Widget _area, _form, _toplevel;
QString _baseURL;
struct Request

View file

@ -8,6 +8,11 @@
<arg name="w" type="i" direction="in"/>
<arg name="h" type="i" direction="in"/>
</method>
<method name="resizePlugin">
<arg name="pluginWinId" type="i" direction="in"/>
<arg name="w" type="i" direction="in"/>
<arg name="h" type="i" direction="in"/>
</method>
<method name="javascriptResult">
<arg name="id" type="i" direction="in"/>
<arg name="result" type="s" direction="in"/>

View file

@ -30,6 +30,7 @@ class PluginHost
{
public:
virtual void setupWindow (int winId, int width, int height) = 0;
virtual void resizePlugin(int pluginWinId, int w, int h) = 0;
virtual ~PluginHost() {};
void setupPluginWindow(NSPluginInstance* instance, void* winID, int width, int height);

View file

@ -29,7 +29,7 @@
#include <QLabel>
PluginHostXEmbed::PluginHostXEmbed(NSPluginInstance* plugin):
_plugin(plugin)
_plugin(plugin), _winId(0)
{}
PluginHostXEmbed::~PluginHostXEmbed()
@ -39,7 +39,17 @@ PluginHostXEmbed::~PluginHostXEmbed()
void PluginHostXEmbed::setupWindow(int winId, int width, int height)
{
kDebug() << winId << width << height;
_winId = winId;
setupPluginWindow(_plugin, (void*)winId, width, height);
}
void PluginHostXEmbed::resizePlugin(int pluginWinId, int w, int h)
{
kDebug() << pluginWinId << _winId << w << h;
if (_winId) {
XResizeWindow(QX11Info::display(), pluginWinId, w, h);
setupPluginWindow(_plugin, (void*)_winId, w, h);
}
}
// kate: indent-width 4; replace-tabs on; tab-width 4; space-indent on;

View file

@ -31,9 +31,11 @@ class PluginHostXEmbed : public PluginHost
public:
PluginHostXEmbed(NSPluginInstance* plugin);
virtual void setupWindow(int winId, int width, int height);
virtual void resizePlugin(int clientWinId, int w, int h);
virtual ~PluginHostXEmbed();
private:
NSPluginInstance* _plugin;
int _winId;
};

View file

@ -149,9 +149,7 @@ static void resizeWidgets(Window w, int width, int height) {
}
}
#if 0
void PluginHostXt::resizePlugin(int w, int h)
void PluginHostXt::resizePlugin(int /*pluginWinId*/, int w, int h)
{
kDebug(1431) << w << h;
XResizeWindow(QX11Info::display(), XtWindow(_form), w, h);
@ -171,6 +169,4 @@ void PluginHostXt::resizePlugin(int w, int h)
resizeWidgets(XtWindow(_form), w, h);
}
#endif
// kate: indent-width 4; replace-tabs on; tab-width 4; space-indent on;

View file

@ -41,6 +41,7 @@ class PluginHostXt : public PluginHost
public:
PluginHostXt(NSPluginInstance* plugin);
virtual void setupWindow(int winId, int width, int height);
virtual void resizePlugin(int pluginWinId, int w, int h);
virtual ~PluginHostXt();
private:
static void forwarder(Widget w, XtPointer cl_data, XEvent * event, Boolean * cont);