OBJECT/EMBED applets
Koos Vriezen
koos.vriezen at xs4all.nl
Sat Feb 1 21:26:15 GMT 2003
On Fri, 31 Jan 2003, Koos Vriezen wrote:
> I managed to get applets working defined in a OBJECT/EMBED tag by making a
> KPart out of KJAS. It's a standalone package for now, the source are from
> khtml/java with a kjavaappletviewer part addition.
Two replacements for this package. Previous version was pretty crashy,
which should be fixed. It also allows opening an applet from konqueror.
You will get a dialog at first to enter the applet parameters. I don't
think it's very usefull other than playing TicTacToe :-), but it's a free
bonus.
> LiveConnect only partially works. Eg.
> <EMBED src="myapplet.class" name="myname" width=500 height=80
> type="application/x-java-applet">
> </EMBED>
> JS->Java works, Java->JS not because the current
> org.kde.javascript.JSObject makes use of the document.applets collection.
> In
> <OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
> <PARAM ...
> ...
> <EMMBED ...
> </EMBED>
> </OBJECT>
> LiveConnect doesn't work. The problem here is that the part is created
> after KHTMLEmbedElementImpl::attach() :-(.
Attached a patch for khtml that enables LiveConnect; also add ID_EMBED to
the applets array in case the parent not is ID_OBJECT, make sure parts of
type 'application/x-java-applet' have a name and an id (for
document.applets) set (unfortunately this had to be done on two places
slightly different), make HTMLObjectElementImpl an override of
LiveConnectElementImpl too.
> To build it, copy a admin dir for somewhere and run 'make -f
> admin/Makefile.cvs' first.
Please comment.
Koos
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kjavaappletviewer.h.bz2
Type: application/octet-stream
Size: 1126 bytes
Desc:
URL: <https://mail.kde.org/mailman/private/kfm-devel/attachments/20030201/3b5be7d6/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kjavaappletviewer.cpp.bz2
Type: application/octet-stream
Size: 2804 bytes
Desc:
URL: <https://mail.kde.org/mailman/private/kfm-devel/attachments/20030201/3b5be7d6/attachment-0001.obj>
-------------- next part --------------
Index: ecma/kjs_html.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/ecma/kjs_html.cpp,v
retrieving revision 1.235
diff -u -3 -p -r1.235 kjs_html.cpp
--- ecma/kjs_html.cpp 22 Jan 2003 19:52:38 -0000 1.235
+++ ecma/kjs_html.cpp 1 Feb 2003 21:15:12 -0000
@@ -1219,6 +1219,7 @@ Value KJS::HTMLElement::tryGet(ExecState
}
break;
case ID_APPLET:
+ case ID_OBJECT:
case ID_EMBED: {
DOM::LiveConnectElementImpl * elm = static_cast<DOM::LiveConnectElementImpl*>(element.handle());
QString retvalue;
@@ -2212,6 +2213,7 @@ void KJS::HTMLElement::tryPut(ExecState
break;
}
case ID_APPLET:
+ case ID_OBJECT:
case ID_EMBED: {
DOM::LiveConnectElementImpl * elm = static_cast<DOM::LiveConnectElementImpl*>(element.handle());
if (elm && elm->put(0, propertyName.qstring(),
Index: html/html_objectimpl.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/html/html_objectimpl.h,v
retrieving revision 1.48
diff -u -3 -p -r1.48 html_objectimpl.h
--- html/html_objectimpl.h 13 Jan 2003 20:01:55 -0000 1.48
+++ html/html_objectimpl.h 1 Feb 2003 21:15:12 -0000
@@ -51,14 +51,13 @@ public:
bool call(const unsigned long, const QString &, const QStringList &, KParts::LiveConnectExtension::Type &, unsigned long &, QString &);
void unregister(const unsigned long);
+ void setLiveConnect(KParts::LiveConnectExtension * lc);
+
virtual void detach();
protected slots:
void liveConnectEvent(const unsigned long, const QString&, const KParts::LiveConnectExtension::ArgList&);
-protected:
- void setLiveConnect(KParts::LiveConnectExtension * lc);
-
private slots:
void timerDone();
@@ -108,7 +107,7 @@ public:
// -------------------------------------------------------------------------
-class HTMLObjectElementImpl : public HTMLElementImpl
+class HTMLObjectElementImpl : public LiveConnectElementImpl
{
public:
HTMLObjectElementImpl(DocumentPtr *doc);
Index: html/html_objectimpl.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/html/html_objectimpl.cpp,v
retrieving revision 1.101
diff -u -3 -p -r1.101 html_objectimpl.cpp
--- html/html_objectimpl.cpp 24 Jan 2003 03:09:30 -0000 1.101
+++ html/html_objectimpl.cpp 1 Feb 2003 21:15:12 -0000
@@ -321,6 +321,17 @@ void HTMLEmbedElementImpl::attach()
if (w->part()->pluginsEnabled() && getDocument()->isURLAllowed( url ) &&
parentNode()->id() != ID_OBJECT && _style->display() != NONE ) {
+ if (serviceType == "application/x-java-applet") {
+ DOMString name = getAttribute(ATTR_NAME);
+ DOMString id = getAttribute(ATTR_ID);
+ if (name.isNull()) {
+ if (id.isNull())
+ name = getAttribute(ATTR_CODE);
+ setAttribute(ATTR_NAME, name.string());
+ }
+ if (id.isNull())
+ setAttribute(ATTR_ID, name.string());
+ }
m_render = new (getDocument()->renderArena()) RenderPartObject(this);
m_render->setStyle(_style );
parentNode()->renderer()->addChild(m_render, nextRenderer());
@@ -335,7 +346,8 @@ void HTMLEmbedElementImpl::attach()
// -------------------------------------------------------------------------
-HTMLObjectElementImpl::HTMLObjectElementImpl(DocumentPtr *doc) : HTMLElementImpl(doc)
+HTMLObjectElementImpl::HTMLObjectElementImpl(DocumentPtr *doc)
+ : LiveConnectElementImpl(doc)
{
needWidgetUpdate = false;
m_renderAlternative = false;
@@ -434,7 +446,6 @@ void HTMLObjectElementImpl::attach()
}
else
m_render = new (getDocument()->renderArena()) RenderPartObject(this);
-
m_render->setStyle(_style);
parentNode()->renderer()->addChild(m_render, nextRenderer());
if (imagelike)
Index: html/html_miscimpl.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/html/html_miscimpl.cpp,v
retrieving revision 1.35
diff -u -3 -p -r1.35 html_miscimpl.cpp
--- html/html_miscimpl.cpp 24 Oct 2002 17:31:30 -0000 1.35
+++ html/html_miscimpl.cpp 1 Feb 2003 21:15:12 -0000
@@ -109,7 +109,8 @@ unsigned long HTMLCollectionImpl::calcLe
len++;
break;
case DOC_APPLETS: // all OBJECT and APPLET elements
- if(e->id() == ID_OBJECT || e->id() == ID_APPLET)
+ if(e->id() == ID_OBJECT || e->id() == ID_APPLET ||
+ (e->id() == ID_EMBED && e->parentNode()->id() != ID_OBJECT))
len++;
break;
case DOC_LINKS: // all A _and_ AREA elements with a value for href
@@ -194,7 +195,8 @@ NodeImpl *HTMLCollectionImpl::getItem(No
len++;
break;
case DOC_APPLETS: // all OBJECT and APPLET elements
- if(e->id() == ID_OBJECT || e->id() == ID_APPLET)
+ if(e->id() == ID_OBJECT || e->id() == ID_APPLET ||
+ (e->id() == ID_EMBED && e->parentNode()->id() != ID_OBJECT))
len++;
break;
case DOC_LINKS: // all A _and_ AREA elements with a value for href
@@ -319,7 +321,8 @@ NodeImpl *HTMLCollectionImpl::getNamedIt
check = true;
break;
case DOC_APPLETS: // all OBJECT and APPLET elements
- if(e->id() == ID_OBJECT || e->id() == ID_APPLET)
+ if(e->id() == ID_OBJECT || e->id() == ID_APPLET ||
+ (e->id() == ID_EMBED && e->parentNode()->id() != ID_OBJECT))
check = true;
break;
case DOC_LINKS: // all A _and_ AREA elements with a value for href
Index: rendering/render_frames.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/rendering/render_frames.cpp,v
retrieving revision 1.149
diff -u -3 -p -r1.149 render_frames.cpp
--- rendering/render_frames.cpp 29 Jan 2003 18:19:24 -0000 1.149
+++ rendering/render_frames.cpp 1 Feb 2003 21:15:13 -0000
@@ -697,8 +697,25 @@ void RenderPartObject::updateWidget()
#endif
return;
}
+ HTMLObjectElementImpl *o = static_cast<HTMLObjectElementImpl *>(element());
+ if (o->getAttribute(ATTR_WIDTH).string().isEmpty())
+ o->setAttribute(ATTR_WIDTH, embed->getAttribute(ATTR_WIDTH).string());
+ if (o->getAttribute(ATTR_HEIGHT).string().isEmpty())
+ o->setAttribute(ATTR_HEIGHT, embed->getAttribute(ATTR_HEIGHT).string());
+ if (serviceType == "application/x-java-applet") {
+ QString name = o->getAttribute(ATTR_NAME).string();
+ DOMString id = o->getAttribute(ATTR_ID);
+ if (name.isEmpty()) {
+ name = (id.isNull() ? embed->getAttribute(ATTR_CODE):id).string();
+ o->setAttribute(ATTR_NAME, name);
+ params.append( QString::fromLatin1("NAME=\"%1\"").arg(name));
+ }
+ if (id.isNull())
+ o->setAttribute(ATTR_ID, name);
+ }
part->requestObject( this, url, serviceType, params );
}
+ o->setLiveConnect(part->liveConnectExtension(this));
}
else if ( element()->id() == ID_EMBED ) {
More information about the kfm-devel
mailing list