[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kfm-devel
Subject:    Form Completion
From:       Malte.Starostik () t-online ! de (Malte Starostik)
Date:       2001-03-09 20:30:54
[Download RAW message or body]

Hello,

as suggested by Tackat on IRC I tried myself on form completion as in IE 5 
for KHTML. The attached patch does this, seems to work okay, but I'm not sure 
if I put it into the Right Places (pat. pending). Does it look okay to commit 
or should it be done in a different place?
-Malte

["formcomplete.diff" (text/x-c)]

Index: khtmlview.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtmlview.cpp,v
retrieving revision 1.366
diff -u -r1.366 khtmlview.cpp
--- khtmlview.cpp	2001/03/04 18:01:17	1.366
+++ khtmlview.cpp	2001/03/09 20:28:13
@@ -35,6 +35,8 @@
 #include "khtml_settings.h"
 
 #include <kcursor.h>
+#include <ksimpleconfig.h>
+#include <kstddirs.h>
 
 #include <qpixmap.h>
 #include <qstring.h>
@@ -66,9 +68,11 @@
         reset();
         tp=0;
         paintBuffer=0;
+        formCompletions=0;
     }
     ~KHTMLViewPrivate()
     {
+        delete formCompletions;
         delete tp; tp = 0;
         delete paintBuffer; paintBuffer =0;
     }
@@ -101,7 +105,7 @@
     bool useSlowRepaints;
 
     int borderX, borderY;
-
+    KSimpleConfig *formCompletions;
 };
 
 
@@ -862,3 +866,21 @@
     if (e)
 	e->setActive(pressed);
 }
+
+QStringList KHTMLView::formCompletionItems(const QString &name) const
+{
+    if (!d->formCompletions)
+        d->formCompletions = new KSimpleConfig(locateLocal("data", \
"khtml/formcompletions")); +    return d->formCompletions->readListEntry(name);
+}
+
+void KHTMLView::addFormCompletionItem(const QString &name, const QString &value)
+{
+    QStringList items = formCompletionItems(name);
+    if (!items.contains(value))
+        items.prepend(value);
+    while (items.count() > 10)
+        items.remove(items.fromLast());
+    d->formCompletions->writeEntry(name, items);
+}
+
Index: khtmlview.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtmlview.h,v
retrieving revision 1.127
diff -u -r1.127 khtmlview.h
--- khtmlview.h	2001/03/04 18:01:17	1.127
+++ khtmlview.h	2001/03/09 20:28:14
@@ -39,6 +39,7 @@
     class HTMLElementImpl;
     class HTMLTitleElementImpl;
     class HTMLGenericFormElementImpl;
+    class HTMLFormElementImpl;
     class Range;
     class NodeImpl;
     class CSSProperty;
@@ -48,6 +49,7 @@
     class RenderObject;
     class RenderRoot;
     class RenderStyle;
+    class RenderLineEdit;
     void applyRule(RenderStyle *style, DOM::CSSProperty *prop, DOM::ElementImpl *e);
 };
 
@@ -69,6 +71,8 @@
     friend class KHTMLPart;
     friend class khtml::RenderRoot;
     friend class DOM::HTMLGenericFormElementImpl;
+    friend class DOM::HTMLFormElementImpl;
+    friend class khtml::RenderLineEdit;
     friend void khtml::applyRule(khtml::RenderStyle *style, DOM::CSSProperty *prop, \
DOM::ElementImpl *e);  
 public:
@@ -224,6 +228,9 @@
     DOM::NodeImpl *nodeUnderMouse() const;
 
     void restoreScrollBar();
+
+    QStringList formCompletionItems(const QString &name) const;
+    void addFormCompletionItem(const QString &name, const QString &value);
 
     // ------------------------------------- member variables \
------------------------------------  private:
Index: html/html_formimpl.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/html/html_formimpl.cpp,v
retrieving revision 1.143
diff -u -r1.143 html_formimpl.cpp
--- html/html_formimpl.cpp	2001/03/09 01:10:57	1.143
+++ html/html_formimpl.cpp	2001/03/09 20:28:14
@@ -326,6 +326,16 @@
 #endif
     if(!view) return;
 
+    for(HTMLGenericFormElementImpl *current = formElements.first(); current; current \
= formElements.next()) +    {
+        if (current->id() == ID_INPUT &&
+            static_cast<HTMLInputElementImpl *>(current)->inputType() == \
HTMLInputElementImpl::TEXT) +        {
+            HTMLInputElementImpl *input = static_cast<HTMLInputElementImpl \
*>(current); +            view->addFormCompletionItem(input->name().string(), \
input->value().string()); +        }
+    }
+    
     QByteArray form_data = formData();
     if(m_post)
     {
Index: rendering/render_form.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/rendering/render_form.cpp,v
retrieving revision 1.83
diff -u -r1.83 render_form.cpp
--- rendering/render_form.cpp	2001/03/09 01:10:34	1.83
+++ rendering/render_form.cpp	2001/03/09 20:28:15
@@ -464,6 +464,7 @@
 
     if(element->inputType() == HTMLInputElementImpl::PASSWORD)
         edit->setEchoMode( QLineEdit::Password );
+    edit->completionObject()->setItems(static_cast<KHTMLView \
*>(view)->formCompletionItems(element->name().string()));  
     setQWidget(edit, false);
 }



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic