fix for img.form
David Faure
faure@kde.org
Mon, 27 Jan 2003 13:23:35 +0100
--Boundary-00=_HTSN+PeL1JRc0xA
Content-Type: Text/Plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Content-Description: clearsigned data
Content-Disposition: inline
=2D----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I still have this patch around, which associates <img> elements with their =
parent
<form>, when there is one, to fix "img.form", and to simplify the code for
form.imgname.
Dirk: ok for applying?
=2D --=20
David FAURE, faure@kde.org, dfaure@klaralvdalens-datakonsult.se
Contributing to: http://www.konqueror.org/, http://www.koffice.org/
KOffice-1.2.1 is available - http://download.kde.org/stable/koffice-1.2.1/
=2D----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.7 (GNU/Linux)
iD8DBQE+NSTI72KcVAmwbhARAgbVAKCHCshNI9N5i8GXwCvl160v7BfQlACbBqgW
Kpa87CJp9czH2caqjFjmk24=3D
=3DDz78
=2D----END PGP SIGNATURE-----
--Boundary-00=_HTSN+PeL1JRc0xA
Content-Type: text/x-diff;
charset="us-ascii";
name="img_form.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="img_form.diff"
? htmltokenizer.cpp.debugoutput
? patch_frames_coll
Index: html_formimpl.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/html/html_formimpl.cpp,v
retrieving revision 1.315
diff -u -p -r1.315 html_formimpl.cpp
--- html_formimpl.cpp 22 Jan 2003 09:39:32 -0000 1.315
+++ html_formimpl.cpp 27 Jan 2003 12:20:51 -0000
@@ -85,6 +85,9 @@ HTMLFormElementImpl::~HTMLFormElementImp
QPtrListIterator<HTMLGenericFormElementImpl> it(formElements);
for (; it.current(); ++it)
it.current()->m_form = 0;
+ QPtrListIterator<HTMLImageElementImpl> it2(imgElements);
+ for (; it2.current(); ++it2)
+ it2.current()->m_form = 0;
}
NodeImpl::Id HTMLFormElementImpl::id() const
@@ -510,6 +513,16 @@ void HTMLFormElementImpl::registerFormEl
void HTMLFormElementImpl::removeFormElement(HTMLGenericFormElementImpl *e)
{
formElements.remove(e);
+}
+
+void HTMLFormElementImpl::registerImgElement(HTMLImageElementImpl *e)
+{
+ imgElements.append(e);
+}
+
+void HTMLFormElementImpl::removeImgElement(HTMLImageElementImpl *e)
+{
+ imgElements.remove(e);
}
// -------------------------------------------------------------------------
Index: html_formimpl.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/html/html_formimpl.h,v
retrieving revision 1.135
diff -u -p -r1.135 html_formimpl.h
--- html_formimpl.h 18 Jan 2003 19:49:15 -0000 1.135
+++ html_formimpl.h 27 Jan 2003 12:20:51 -0000
@@ -26,6 +26,7 @@
#define HTML_FORMIMPL_H
#include "html/html_elementimpl.h"
+#include "html/html_imageimpl.h"
#include "dom/html_element.h"
#include <qvaluelist.h>
@@ -81,11 +82,10 @@ public:
void radioClicked( HTMLGenericFormElementImpl *caller );
- void registerFormElement(khtml::RenderFormElement *);
- void removeFormElement(khtml::RenderFormElement *);
-
void registerFormElement(HTMLGenericFormElementImpl *);
void removeFormElement(HTMLGenericFormElementImpl *);
+ void registerImgElement(HTMLImageElementImpl *);
+ void removeImgElement(HTMLImageElementImpl *);
void submitFromKeyboard();
bool prepareSubmit();
@@ -97,6 +97,7 @@ public:
private:
QPtrList<HTMLGenericFormElementImpl> formElements;
+ QPtrList<HTMLImageElementImpl> imgElements;
DOMString m_target;
DOMString m_enctype;
DOMString m_boundary;
Index: html_imageimpl.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/html/html_imageimpl.cpp,v
retrieving revision 1.138
diff -u -p -r1.138 html_imageimpl.cpp
--- html_imageimpl.cpp 21 Jan 2003 16:20:32 -0000 1.138
+++ html_imageimpl.cpp 27 Jan 2003 12:20:51 -0000
@@ -21,6 +21,7 @@
*/
#include "html/html_imageimpl.h"
+#include "html/html_formimpl.h"
#include "html/html_documentimpl.h"
#include "misc/htmlhashes.h"
@@ -51,6 +52,19 @@ using namespace khtml;
// -------------------------------------------------------------------------
+HTMLImageElementImpl::HTMLImageElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f)
+ : HTMLElementImpl(doc), ismap(false), m_form(f)
+{
+ if (m_form)
+ m_form->registerImgElement(this);
+}
+
+HTMLImageElementImpl::~HTMLImageElementImpl()
+{
+ if (m_form)
+ m_form->removeImgElement(this);
+}
+
NodeImpl::Id HTMLImageElementImpl::id() const
{
return ID_IMG;
@@ -214,7 +228,6 @@ bool HTMLImageElementImpl::complete() co
return r->complete();
return false;
}
-
// -------------------------------------------------------------------------
Index: html_imageimpl.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/html/html_imageimpl.h,v
retrieving revision 1.62
diff -u -p -r1.62 html_imageimpl.h
--- html_imageimpl.h 9 Dec 2002 07:21:44 -0000 1.62
+++ html_imageimpl.h 27 Jan 2003 12:20:51 -0000
@@ -33,13 +33,15 @@
namespace DOM {
class DOMString;
+class HTMLFormElementImpl;
class HTMLImageElementImpl
: public HTMLElementImpl
{
+ friend class HTMLFormElementImpl;
public:
- HTMLImageElementImpl(DocumentPtr *doc)
- : HTMLElementImpl(doc), ismap(false) {}
+ HTMLImageElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f = 0);
+ ~HTMLImageElementImpl();
virtual Id id() const;
@@ -61,6 +63,7 @@ public:
protected:
DOMString usemap;
bool ismap;
+ HTMLFormElementImpl *m_form;
};
Index: html_miscimpl.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/html/html_miscimpl.cpp,v
retrieving revision 1.35
diff -u -p -r1.35 html_miscimpl.cpp
--- html_miscimpl.cpp 24 Oct 2002 17:31:30 -0000 1.35
+++ html_miscimpl.cpp 27 Jan 2003 12:20:52 -0000
@@ -509,43 +509,19 @@ NodeImpl* HTMLFormCollectionImpl::getNam
// IE looks at <img> only if no <input> has the same name
if ( !foundInputElements )
{
- NodeImpl* retval = getNamedImgItem( base->firstChild(), attr_id, name, duplicateNumber );
- if ( retval )
- return retval;
- }
- }
- return 0;
-}
+ HTMLImageElementImpl* element;
+ HTMLFormElementImpl* f = static_cast<HTMLFormElementImpl*>(e);
-NodeImpl* HTMLFormCollectionImpl::getNamedImgItem(NodeImpl* current, int attr_id, const DOMString& name, int& duplicateNumber) const
-{
- // strange case. IE and NS allow to get hold of <img> tags,
- // only _if_ there is no input tag with the same name
- // and they don't include them in the elements() collection.
- while ( current )
- {
- if(current->nodeType() == Node::ELEMENT_NODE)
- {
- HTMLElementImpl *currelem = static_cast<HTMLElementImpl *>(current);
- if(currelem->id() == ID_IMG && currelem->getAttribute(attr_id) == name)
- {
- if (!duplicateNumber)
- return current;
- --duplicateNumber;
- }
- if(current->firstChild())
- {
- // The recursion here is the reason why this is a separate method
- NodeImpl *retval = getNamedImgItem(current->firstChild(), attr_id, name, duplicateNumber);
- if(retval)
+ for(element = f->imgElements.first(); element; element = f->imgElements.next())
+ if(element->getAttribute(attr_id) == name)
{
- //kdDebug( 6030 ) << "got a return value " << retval << endl;
- return retval;
+ if (!duplicateNumber)
+ return element;
+ --duplicateNumber;
+ foundInputElements = true;
}
- }
}
- current = current->nextSibling();
- } // while
+ }
return 0;
}
Index: html_miscimpl.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/html/html_miscimpl.h,v
retrieving revision 1.22
diff -u -p -r1.22 html_miscimpl.h
--- html_miscimpl.h 11 Apr 2002 08:56:40 -0000 1.22
+++ html_miscimpl.h 27 Jan 2003 12:20:52 -0000
@@ -125,7 +125,6 @@ protected:
virtual NodeImpl *nextNamedItemInternal( const DOMString &name ) const;
private:
NodeImpl* getNamedFormItem(int attr_id, const DOMString& name, int duplicateNumber) const;
- NodeImpl* getNamedImgItem(NodeImpl* current, int attr_id, const DOMString& name, int& duplicateNumber) const;
mutable int currentPos;
};
Index: htmlparser.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/html/htmlparser.cpp,v
retrieving revision 1.320
diff -u -p -r1.320 htmlparser.cpp
--- htmlparser.cpp 22 Jan 2003 09:39:33 -0000 1.320
+++ htmlparser.cpp 27 Jan 2003 12:20:52 -0000
@@ -926,7 +926,7 @@ NodeImpl *KHTMLParser::getElement(Token*
// images
case ID_IMG:
- n = new HTMLImageElementImpl(document);
+ n = new HTMLImageElementImpl(document, form);
break;
case ID_MAP:
map = new HTMLMapElementImpl(document);
--Boundary-00=_HTSN+PeL1JRc0xA--