[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677

hyatt hyatt at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 08:30:19 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit 42be8345e343df1532f523be630243a7ea86506b
Author: hyatt <hyatt at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Mar 23 00:17:26 2004 +0000

    	Factoring of form control code to enable sharing between three types of text fields: normal, password, and
    	the new search field.  Also made search field creatable using <input type="search">.  There are still many
    	bugs with the field, but you can at least type in it and submit it with a form.
    
            Reviewed by darin
    
            * khtml/html/html_formimpl.cpp:
            (HTMLInputElementImpl::setType):
            (HTMLInputElementImpl::type):
            (HTMLInputElementImpl::click):
            (HTMLInputElementImpl::accessKeyAction):
            (HTMLInputElementImpl::rendererIsNeeded):
            (HTMLInputElementImpl::createRenderer):
            (HTMLInputElementImpl::encoding):
            (HTMLInputElementImpl::defaultEventHandler):
            (HTMLInputElementImpl::isEditable):
            * khtml/html/html_formimpl.h:
            (DOM::HTMLInputElementImpl::):
            * khtml/rendering/render_form.cpp:
            (RenderLineEdit::RenderLineEdit):
            * kwq/KWQKLineEdit.h:
            (KLineEdit::KLineEdit):
            * kwq/KWQLineEdit.h:
            (QLineEdit::):
            * kwq/KWQLineEdit.mm:
            (QLineEdit::QLineEdit):
            (QLineEdit::~QLineEdit):
            (QLineEdit::setFont):
            (QLineEdit::setText):
            (QLineEdit::text):
            (QLineEdit::setMaxLength):
            (QLineEdit::isReadOnly):
            (QLineEdit::setReadOnly):
            (QLineEdit::maxLength):
            (QLineEdit::selectAll):
            (QLineEdit::edited):
            (QLineEdit::setEdited):
            (QLineEdit::sizeForCharacterWidth):
            (QLineEdit::baselinePosition):
            (QLineEdit::setAlignment):
            (QLineEdit::setWritingDirection):
            (KWQNSTextAlignmentForAlignmentFlags):
            (QLineEdit::setLiveSearch):
            * kwq/KWQTextField.h:
            * kwq/KWQTextField.mm:
            (-[KWQTextFieldController initWithTextField:QLineEdit:]):
            (-[KWQTextFieldController action:]):
            (-[KWQTextFieldController dealloc]):
            (-[KWQTextFieldController widget]):
            (-[KWQTextFieldController setMaximumLength:]):
            (-[KWQTextFieldController controlTextDidBeginEditing:]):
            (-[KWQTextFieldController controlTextDidEndEditing:]):
            (-[KWQTextFieldController controlTextDidChange:]):
            (-[KWQTextFieldController control:textShouldBeginEditing:]):
            (-[KWQTextFieldController control:textShouldEndEditing:]):
            (-[KWQTextFieldController control:didFailToFormatString:errorDescription:]):
            (-[KWQTextFieldController control:didFailToValidatePartialString:errorDescription:]):
            (-[KWQTextFieldController control:isValidObject:]):
            (-[KWQTextFieldController control:textView:doCommandBySelector:]):
            (-[KWQTextFieldController textChanged]):
            (-[KWQTextFieldController setInDrawingMachinery:]):
            (-[KWQTextFieldController textView:shouldDrawInsertionPointInRect:color:turnedOn:]):
            (-[KWQTextFieldController textView:shouldHandleEvent:]):
            (-[KWQTextFieldController textView:didHandleEvent:]):
            (-[KWQTextFieldController setBaseWritingDirection:]):
            (-[KWQTextFieldController baseWritingDirection]):
            (-[KWQTextFieldController selectedRange]):
            (-[KWQTextFieldController setSelectedRange:]):
            (-[KWQTextFieldController setHasFocus:]):
            (-[KWQTextFieldController updateTextAttributes:]):
            (+[KWQTextField cellClass]):
            (-[KWQTextField initWithQLineEdit:]):
            (-[KWQTextField dealloc]):
            (-[KWQTextField controller]):
            (-[KWQTextField widget]):
            (-[KWQTextField selectText:]):
            (-[KWQTextField setStringValue:]):
            (-[KWQTextField nextKeyView]):
            (-[KWQTextField previousKeyView]):
            (-[KWQTextField nextValidKeyView]):
            (-[KWQTextField previousValidKeyView]):
            (-[KWQTextField acceptsFirstResponder]):
            (-[KWQTextField display]):
            (-[KWQTextField displayRectIgnoringOpacity:]):
            (-[KWQTextField textView:shouldDrawInsertionPointInRect:color:turnedOn:]):
            (-[KWQTextField textView:shouldHandleEvent:]):
            (-[KWQTextField textView:didHandleEvent:]):
            (-[KWQTextFieldCell editWithFrame:inView:editor:delegate:event:]):
            (-[KWQTextFieldCell selectWithFrame:inView:editor:delegate:start:length:]):
            (-[KWQTextFieldCell _textAttributes]):
            (-[KWQSecureTextField initWithQLineEdit:]):
            (-[KWQSecureTextField dealloc]):
            (-[KWQSecureTextField controller]):
            (-[KWQSecureTextField widget]):
            (-[KWQSecureTextField setStringValue:]):
            (-[KWQSecureTextField nextKeyView]):
            (-[KWQSecureTextField previousKeyView]):
            (-[KWQSecureTextField acceptsFirstResponder]):
            (-[KWQSecureTextField display]):
            (-[KWQSecureTextField displayRectIgnoringOpacity:]):
            (-[KWQSecureTextField textView:shouldDrawInsertionPointInRect:color:turnedOn:]):
            (-[KWQSecureTextField textView:shouldHandleEvent:]):
            (-[KWQSecureTextField textView:didHandleEvent:]):
            (-[KWQSecureTextField selectText:]):
            (-[KWQSecureTextFieldCell editWithFrame:inView:editor:delegate:event:]):
            (-[KWQSecureTextFieldCell selectWithFrame:inView:editor:delegate:start:length:]):
            (-[KWQSecureTextFieldCell _textAttributes]):
            (+[KWQSearchField cellClass]):
            (-[KWQSearchField initWithQLineEdit:]):
            (-[KWQSearchField dealloc]):
            (-[KWQSearchField controller]):
            (-[KWQSearchField widget]):
            (-[KWQSearchField selectText:]):
            (-[KWQSearchField setStringValue:]):
            (-[KWQSearchField nextKeyView]):
            (-[KWQSearchField previousKeyView]):
            (-[KWQSearchField nextValidKeyView]):
            (-[KWQSearchField previousValidKeyView]):
            (-[KWQSearchField acceptsFirstResponder]):
            (-[KWQSearchField display]):
            (-[KWQSearchField displayRectIgnoringOpacity:]):
            (-[KWQSearchField textView:shouldDrawInsertionPointInRect:color:turnedOn:]):
            (-[KWQSearchField textView:shouldHandleEvent:]):
            (-[KWQSearchField textView:didHandleEvent:]):
            (-[KWQSearchFieldCell editWithFrame:inView:editor:delegate:event:]):
            (-[KWQSearchFieldCell selectWithFrame:inView:editor:delegate:start:length:]):
            (-[KWQSearchFieldCell _textAttributes]):
            (-[KWQTextFieldFormatter init]):
            (-[KWQTextFieldFormatter setMaximumLength:]):
            (-[KWQTextFieldFormatter maximumLength]):
            (-[KWQTextFieldFormatter stringForObjectValue:]):
            (-[KWQTextFieldFormatter getObjectValue:forString:errorDescription:]):
            (-[KWQTextFieldFormatter isPartialStringValid:newEditingString:errorDescription:]):
            (-[KWQTextFieldFormatter attributedStringForObjectValue:withDefaultAttributes:]):
            (-[NSString _KWQ_truncateToNumComposedCharacterSequences:]):
            (-[NSTextField _KWQ_currentEditor]):
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@6243 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index 9e6406f..8b7b4b7 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,142 @@
+2004-03-22  David Hyatt  <hyatt at apple.com>
+
+	Factoring of form control code to enable sharing between three types of text fields: normal, password, and
+	the new search field.  Also made search field creatable using <input type="search">.  There are still many
+	bugs with the field, but you can at least type in it and submit it with a form.
+	
+        Reviewed by darin
+
+        * khtml/html/html_formimpl.cpp:
+        (HTMLInputElementImpl::setType):
+        (HTMLInputElementImpl::type):
+        (HTMLInputElementImpl::click):
+        (HTMLInputElementImpl::accessKeyAction):
+        (HTMLInputElementImpl::rendererIsNeeded):
+        (HTMLInputElementImpl::createRenderer):
+        (HTMLInputElementImpl::encoding):
+        (HTMLInputElementImpl::defaultEventHandler):
+        (HTMLInputElementImpl::isEditable):
+        * khtml/html/html_formimpl.h:
+        (DOM::HTMLInputElementImpl::):
+        * khtml/rendering/render_form.cpp:
+        (RenderLineEdit::RenderLineEdit):
+        * kwq/KWQKLineEdit.h:
+        (KLineEdit::KLineEdit):
+        * kwq/KWQLineEdit.h:
+        (QLineEdit::):
+        * kwq/KWQLineEdit.mm:
+        (QLineEdit::QLineEdit):
+        (QLineEdit::~QLineEdit):
+        (QLineEdit::setFont):
+        (QLineEdit::setText):
+        (QLineEdit::text):
+        (QLineEdit::setMaxLength):
+        (QLineEdit::isReadOnly):
+        (QLineEdit::setReadOnly):
+        (QLineEdit::maxLength):
+        (QLineEdit::selectAll):
+        (QLineEdit::edited):
+        (QLineEdit::setEdited):
+        (QLineEdit::sizeForCharacterWidth):
+        (QLineEdit::baselinePosition):
+        (QLineEdit::setAlignment):
+        (QLineEdit::setWritingDirection):
+        (KWQNSTextAlignmentForAlignmentFlags):
+        (QLineEdit::setLiveSearch):
+        * kwq/KWQTextField.h:
+        * kwq/KWQTextField.mm:
+        (-[KWQTextFieldController initWithTextField:QLineEdit:]):
+        (-[KWQTextFieldController action:]):
+        (-[KWQTextFieldController dealloc]):
+        (-[KWQTextFieldController widget]):
+        (-[KWQTextFieldController setMaximumLength:]):
+        (-[KWQTextFieldController controlTextDidBeginEditing:]):
+        (-[KWQTextFieldController controlTextDidEndEditing:]):
+        (-[KWQTextFieldController controlTextDidChange:]):
+        (-[KWQTextFieldController control:textShouldBeginEditing:]):
+        (-[KWQTextFieldController control:textShouldEndEditing:]):
+        (-[KWQTextFieldController control:didFailToFormatString:errorDescription:]):
+        (-[KWQTextFieldController control:didFailToValidatePartialString:errorDescription:]):
+        (-[KWQTextFieldController control:isValidObject:]):
+        (-[KWQTextFieldController control:textView:doCommandBySelector:]):
+        (-[KWQTextFieldController textChanged]):
+        (-[KWQTextFieldController setInDrawingMachinery:]):
+        (-[KWQTextFieldController textView:shouldDrawInsertionPointInRect:color:turnedOn:]):
+        (-[KWQTextFieldController textView:shouldHandleEvent:]):
+        (-[KWQTextFieldController textView:didHandleEvent:]):
+        (-[KWQTextFieldController setBaseWritingDirection:]):
+        (-[KWQTextFieldController baseWritingDirection]):
+        (-[KWQTextFieldController selectedRange]):
+        (-[KWQTextFieldController setSelectedRange:]):
+        (-[KWQTextFieldController setHasFocus:]):
+        (-[KWQTextFieldController updateTextAttributes:]):
+        (+[KWQTextField cellClass]):
+        (-[KWQTextField initWithQLineEdit:]):
+        (-[KWQTextField dealloc]):
+        (-[KWQTextField controller]):
+        (-[KWQTextField widget]):
+        (-[KWQTextField selectText:]):
+        (-[KWQTextField setStringValue:]):
+        (-[KWQTextField nextKeyView]):
+        (-[KWQTextField previousKeyView]):
+        (-[KWQTextField nextValidKeyView]):
+        (-[KWQTextField previousValidKeyView]):
+        (-[KWQTextField acceptsFirstResponder]):
+        (-[KWQTextField display]):
+        (-[KWQTextField displayRectIgnoringOpacity:]):
+        (-[KWQTextField textView:shouldDrawInsertionPointInRect:color:turnedOn:]):
+        (-[KWQTextField textView:shouldHandleEvent:]):
+        (-[KWQTextField textView:didHandleEvent:]):
+        (-[KWQTextFieldCell editWithFrame:inView:editor:delegate:event:]):
+        (-[KWQTextFieldCell selectWithFrame:inView:editor:delegate:start:length:]):
+        (-[KWQTextFieldCell _textAttributes]):
+        (-[KWQSecureTextField initWithQLineEdit:]):
+        (-[KWQSecureTextField dealloc]):
+        (-[KWQSecureTextField controller]):
+        (-[KWQSecureTextField widget]):
+        (-[KWQSecureTextField setStringValue:]):
+        (-[KWQSecureTextField nextKeyView]):
+        (-[KWQSecureTextField previousKeyView]):
+        (-[KWQSecureTextField acceptsFirstResponder]):
+        (-[KWQSecureTextField display]):
+        (-[KWQSecureTextField displayRectIgnoringOpacity:]):
+        (-[KWQSecureTextField textView:shouldDrawInsertionPointInRect:color:turnedOn:]):
+        (-[KWQSecureTextField textView:shouldHandleEvent:]):
+        (-[KWQSecureTextField textView:didHandleEvent:]):
+        (-[KWQSecureTextField selectText:]):
+        (-[KWQSecureTextFieldCell editWithFrame:inView:editor:delegate:event:]):
+        (-[KWQSecureTextFieldCell selectWithFrame:inView:editor:delegate:start:length:]):
+        (-[KWQSecureTextFieldCell _textAttributes]):
+        (+[KWQSearchField cellClass]):
+        (-[KWQSearchField initWithQLineEdit:]):
+        (-[KWQSearchField dealloc]):
+        (-[KWQSearchField controller]):
+        (-[KWQSearchField widget]):
+        (-[KWQSearchField selectText:]):
+        (-[KWQSearchField setStringValue:]):
+        (-[KWQSearchField nextKeyView]):
+        (-[KWQSearchField previousKeyView]):
+        (-[KWQSearchField nextValidKeyView]):
+        (-[KWQSearchField previousValidKeyView]):
+        (-[KWQSearchField acceptsFirstResponder]):
+        (-[KWQSearchField display]):
+        (-[KWQSearchField displayRectIgnoringOpacity:]):
+        (-[KWQSearchField textView:shouldDrawInsertionPointInRect:color:turnedOn:]):
+        (-[KWQSearchField textView:shouldHandleEvent:]):
+        (-[KWQSearchField textView:didHandleEvent:]):
+        (-[KWQSearchFieldCell editWithFrame:inView:editor:delegate:event:]):
+        (-[KWQSearchFieldCell selectWithFrame:inView:editor:delegate:start:length:]):
+        (-[KWQSearchFieldCell _textAttributes]):
+        (-[KWQTextFieldFormatter init]):
+        (-[KWQTextFieldFormatter setMaximumLength:]):
+        (-[KWQTextFieldFormatter maximumLength]):
+        (-[KWQTextFieldFormatter stringForObjectValue:]):
+        (-[KWQTextFieldFormatter getObjectValue:forString:errorDescription:]):
+        (-[KWQTextFieldFormatter isPartialStringValid:newEditingString:errorDescription:]):
+        (-[KWQTextFieldFormatter attributedStringForObjectValue:withDefaultAttributes:]):
+        (-[NSString _KWQ_truncateToNumComposedCharacterSequences:]):
+        (-[NSTextField _KWQ_currentEditor]):
+
 === Safari-133 ===
 
 2004-03-19  Darin Adler  <darin at apple.com>
diff --git a/WebCore/khtml/html/html_formimpl.cpp b/WebCore/khtml/html/html_formimpl.cpp
index c29c255..1840e20 100644
--- a/WebCore/khtml/html/html_formimpl.cpp
+++ b/WebCore/khtml/html/html_formimpl.cpp
@@ -1213,6 +1213,8 @@ void HTMLInputElementImpl::setType(const DOMString& t)
         newType = BUTTON;
     else if ( strcasecmp( t, "khtml_isindex" ) == 0 )
         newType = ISINDEX;
+    else if ( strcasecmp( t, "search" ) == 0 )
+        newType = SEARCH;
     else
         newType = TEXT;
 
@@ -1245,6 +1247,7 @@ DOMString HTMLInputElementImpl::type() const
     case HIDDEN: return "hidden";
     case IMAGE: return "image";
     case BUTTON: return "button";
+    case SEARCH: return "search";
     default: return "";
     }
 }
@@ -1326,6 +1329,7 @@ void HTMLInputElementImpl::click()
         case IMAGE:
         case ISINDEX:
         case PASSWORD:
+        case SEARCH:
         case TEXT:
             HTMLGenericFormElementImpl::click();
             break;
@@ -1340,6 +1344,7 @@ void HTMLInputElementImpl::accessKeyAction()
             break;
         case TEXT:
         case PASSWORD:
+        case SEARCH:
         case ISINDEX:
             focus();
             break;
@@ -1454,6 +1459,7 @@ bool HTMLInputElementImpl::rendererIsNeeded(RenderStyle *style)
     {
     case TEXT:
     case PASSWORD:
+    case SEARCH:
     case ISINDEX:
     case CHECKBOX:
     case RADIO:
@@ -1474,6 +1480,7 @@ RenderObject *HTMLInputElementImpl::createRenderer(RenderArena *arena, RenderSty
     {
     case TEXT:
     case PASSWORD:
+    case SEARCH:
     case ISINDEX:  return new (arena) RenderLineEdit(this);
     case CHECKBOX: return new (arena) RenderCheckBox(this);
     case RADIO:    return new (arena) RenderRadioButton(this);
@@ -1586,6 +1593,7 @@ bool HTMLInputElementImpl::encoding(const QTextCodec* codec, khtml::encodingList
     switch (m_type) {
         case HIDDEN:
         case TEXT:
+        case SEARCH:
         case PASSWORD:
             // always successful
             encoding += fixUpfromUnicode(codec, value().string());
@@ -1847,6 +1855,7 @@ void HTMLInputElementImpl::defaultEventHandler(EventImpl *evt)
                 }
                 break;
             case TEXT:
+            case SEARCH:
             case PASSWORD: {
                 // For enter, find the first successful image or submit element 
                 // send it a simulated mouse click.
@@ -1867,7 +1876,8 @@ void HTMLInputElementImpl::defaultEventHandler(EventImpl *evt)
 
 bool HTMLInputElementImpl::isEditable()
 {
-    return ((m_type == TEXT) || (m_type == PASSWORD) || (m_type == ISINDEX) || (m_type == FILE));
+    return ((m_type == TEXT) || (m_type == PASSWORD) ||
+            (m_type == SEARCH) || (m_type == ISINDEX) || (m_type == FILE));
 }
 
 bool HTMLInputElementImpl::isSubresourceURLAttribute(AttributeImpl *attr) const
diff --git a/WebCore/khtml/html/html_formimpl.h b/WebCore/khtml/html/html_formimpl.h
index 5e323b0..348ecad 100644
--- a/WebCore/khtml/html/html_formimpl.h
+++ b/WebCore/khtml/html/html_formimpl.h
@@ -276,7 +276,8 @@ public:
         FILE,
         HIDDEN,
         IMAGE,
-        BUTTON
+        BUTTON,
+        SEARCH
     };
 
     HTMLInputElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f = 0);
diff --git a/WebCore/khtml/rendering/render_form.cpp b/WebCore/khtml/rendering/render_form.cpp
index 1c561d0..1c659ee 100644
--- a/WebCore/khtml/rendering/render_form.cpp
+++ b/WebCore/khtml/rendering/render_form.cpp
@@ -532,7 +532,20 @@ RenderLineEdit::RenderLineEdit(HTMLInputElementImpl *element)
     : RenderFormElement(element), m_updating(false)
 {
 #if APPLE_CHANGES
-    KLineEdit *edit = new KLineEdit(view()->viewport());
+    QLineEdit::Type type;
+    switch (element->inputType()) {
+        case HTMLInputElementImpl::PASSWORD:
+            type = QLineEdit::Password;
+            break;
+        case HTMLInputElementImpl::SEARCH:
+            type = QLineEdit::Search;
+            break;
+        default:
+            type = QLineEdit::Normal;
+    }
+    KLineEdit *edit = new KLineEdit(type);
+    if (type == QLineEdit::Search)
+        edit->setLiveSearch(false);
 #else
     LineEditWidget *edit = new LineEditWidget(view()->viewport());
 #endif
@@ -540,10 +553,10 @@ RenderLineEdit::RenderLineEdit(HTMLInputElementImpl *element)
     connect(edit,SIGNAL(textChanged(const QString &)),this,SLOT(slotTextChanged(const QString &)));
     connect(edit,SIGNAL(clicked()),this,SLOT(slotClicked()));
 
+#if !APPLE_CHANGES
     if(element->inputType() == HTMLInputElementImpl::PASSWORD)
         edit->setEchoMode( QLineEdit::Password );
 
-#if !APPLE_CHANGES
     if ( element->autoComplete() ) {
         QStringList completions = view()->formCompletionItems(element->name().string());
         if (completions.count()) {
diff --git a/WebCore/kwq/KWQKLineEdit.h b/WebCore/kwq/KWQKLineEdit.h
index b384e9b..c455e91 100644
--- a/WebCore/kwq/KWQKLineEdit.h
+++ b/WebCore/kwq/KWQKLineEdit.h
@@ -32,7 +32,7 @@
 
 class KLineEdit : public QLineEdit, public KCompletionBase {
 public:
-    KLineEdit(QWidget *parent) { }
+    KLineEdit(Type t) : QLineEdit(t) { }
 
     void setContextMenuEnabled(bool showMenu) { }
     KCompletionBox *completionBox(bool create) { return 0; }
diff --git a/WebCore/kwq/KWQLineEdit.h b/WebCore/kwq/KWQLineEdit.h
index fcdc157..a856ddc 100644
--- a/WebCore/kwq/KWQLineEdit.h
+++ b/WebCore/kwq/KWQLineEdit.h
@@ -29,19 +29,23 @@
 #include "KWQString.h"
 #include "KWQWidget.h"
 
+#ifdef __OBJC__
+ at class KWQTextFieldController;
+#else
+class KWQTextFieldController;
+#endif
+
 class QLineEdit : public QWidget {
 public:
-    enum EchoMode { Normal, Password };
+    enum Type { Normal, Password, Search };
 
-    QLineEdit();
+    QLineEdit(Type);
     ~QLineEdit();
     void setAlignment(AlignmentFlags);
 
     void setCursorPosition(int);
     int cursorPosition() const;
 
-    void setEchoMode(EchoMode);
-
     void setEdited(bool);
     bool edited() const;
 
@@ -70,10 +74,14 @@ public:
     
     virtual bool checksDescendantsForFocus() const;
 
+    void setLiveSearch(bool liveSearch);
+
 private:
     KWQSignal m_returnPressed;
     KWQSignal m_textChanged;
     KWQSignal m_clicked;
+    Type m_type;
+    KWQTextFieldController *m_controller;
 };
 
 #ifdef __OBJC__
diff --git a/WebCore/kwq/KWQLineEdit.mm b/WebCore/kwq/KWQLineEdit.mm
index 715a7ab..37fe01a 100644
--- a/WebCore/kwq/KWQLineEdit.mm
+++ b/WebCore/kwq/KWQLineEdit.mm
@@ -23,6 +23,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
 
+#import "KWQButton.h"
 #import "KWQLineEdit.h"
 
 #import "KWQExceptions.h"
@@ -31,15 +32,27 @@
 #import "WebCoreTextRenderer.h"
 #import "WebCoreTextRendererFactory.h"
 
-QLineEdit::QLineEdit()
+QLineEdit::QLineEdit(Type type)
     : m_returnPressed(this, SIGNAL(returnPressed()))
     , m_textChanged(this, SIGNAL(textChanged(const QString &)))
-    , m_clicked(this, SIGNAL(clicked()))
+    , m_clicked(this, SIGNAL(clicked())), m_type(type)
 {
-    KWQTextField *view = nil;
+    id view = nil;
 
     KWQ_BLOCK_EXCEPTIONS;
-    view = [[KWQTextField alloc] initWithQLineEdit:this];
+    switch (type) {
+        case Normal:
+            view = [KWQTextField alloc];
+            break;
+        case Password:
+            view = [KWQSecureTextField alloc];
+            break;
+        case Search:
+            view = [KWQSearchField alloc];
+            break;
+    }
+    [view initWithQLineEdit:this];
+    m_controller = [view controller];
     setView(view);
     [view release];
     [view setSelectable:YES]; // must do this explicitly so setEditable:NO does not make it NO
@@ -48,17 +61,8 @@ QLineEdit::QLineEdit()
 
 QLineEdit::~QLineEdit()
 {
-    KWQTextField* textField = (KWQTextField*)getView();
     KWQ_BLOCK_EXCEPTIONS;
-    [textField invalidate];
-    KWQ_UNBLOCK_EXCEPTIONS;
-}
-
-void QLineEdit::setEchoMode(EchoMode mode)
-{
-    KWQTextField *textField = (KWQTextField *)getView();
-    KWQ_BLOCK_EXCEPTIONS;
-    [textField setPasswordMode:mode == Password];
+    [m_controller invalidate];
     KWQ_UNBLOCK_EXCEPTIONS;
 }
 
@@ -76,15 +80,23 @@ int QLineEdit::cursorPosition() const
 void QLineEdit::setFont(const QFont &font)
 {
     QWidget::setFont(font);
-    KWQTextField *textField = (KWQTextField *)getView();
-    KWQ_BLOCK_EXCEPTIONS;
-    [textField setFont:font.getNSFont()];
-    KWQ_UNBLOCK_EXCEPTIONS;
+    if (m_type == Search) {
+        const NSControlSize size = KWQNSControlSizeForFont(font);    
+        NSControl * const searchField = static_cast<NSControl *>(getView());
+        [[searchField cell] setControlSize:size];
+        [searchField setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:size]]];
+    }
+    else {
+        NSTextField *textField = (NSTextField *)getView();
+        KWQ_BLOCK_EXCEPTIONS;
+        [textField setFont:font.getNSFont()];
+        KWQ_UNBLOCK_EXCEPTIONS;
+    }
 }
 
 void QLineEdit::setText(const QString &s)
 {
-    KWQTextField *textField = (KWQTextField *)getView();
+    NSTextField *textField = (NSTextField *)getView();
     KWQ_BLOCK_EXCEPTIONS;
     [textField setStringValue:s.getNSString()];
     KWQ_UNBLOCK_EXCEPTIONS;
@@ -92,7 +104,7 @@ void QLineEdit::setText(const QString &s)
 
 QString QLineEdit::text()
 {
-    KWQTextField *textField = (KWQTextField *)getView();
+    NSTextField *textField = (NSTextField *)getView();
 
     KWQ_BLOCK_EXCEPTIONS;
     NSMutableString *text = [[[textField stringValue] mutableCopy] autorelease];
@@ -106,13 +118,12 @@ QString QLineEdit::text()
 
 void QLineEdit::setMaxLength(int len)
 {
-    KWQTextField *textField = (KWQTextField *)getView();
-    [textField setMaximumLength:len];
+    [m_controller setMaximumLength:len];
 }
 
 bool QLineEdit::isReadOnly() const
 {
-    KWQTextField *textField = (KWQTextField *)getView();
+    NSTextField *textField = (NSTextField *)getView();
 
     KWQ_BLOCK_EXCEPTIONS;
     return ![textField isEditable];
@@ -123,7 +134,7 @@ bool QLineEdit::isReadOnly() const
 
 void QLineEdit::setReadOnly(bool flag)
 {
-    KWQTextField *textField = (KWQTextField *)getView();
+    NSTextField *textField = (NSTextField *)getView();
     KWQ_BLOCK_EXCEPTIONS;
     [textField setEditable:!flag];
     KWQ_UNBLOCK_EXCEPTIONS;
@@ -131,18 +142,12 @@ void QLineEdit::setReadOnly(bool flag)
 
 int QLineEdit::maxLength() const
 {
-    KWQTextField *textField = (KWQTextField *)getView();
-    
-    KWQ_BLOCK_EXCEPTIONS;
-    return [textField maximumLength];
-    KWQ_UNBLOCK_EXCEPTIONS;
-
-    return 0;
+    return [m_controller maximumLength];
 }
 
 void QLineEdit::selectAll()
 {
-    KWQTextField *textField = (KWQTextField *)getView();
+    NSTextField *textField = (NSTextField *)getView();
     KWQ_BLOCK_EXCEPTIONS;
     [textField selectText:nil];
     KWQ_UNBLOCK_EXCEPTIONS;
@@ -150,21 +155,12 @@ void QLineEdit::selectAll()
 
 bool QLineEdit::edited() const
 {
-    KWQTextField *textField = (KWQTextField *)getView();
-    
-    KWQ_BLOCK_EXCEPTIONS;
-    return [textField edited];
-    KWQ_UNBLOCK_EXCEPTIONS;
-
-    return false;
+    return [m_controller edited];
 }
 
 void QLineEdit::setEdited(bool flag)
 {
-    KWQTextField *textField = (KWQTextField *)getView();
-    KWQ_BLOCK_EXCEPTIONS;
-    [textField setEdited:flag];
-    KWQ_UNBLOCK_EXCEPTIONS;
+    [m_controller setEdited:flag];
 }
 
 QSize QLineEdit::sizeForCharacterWidth(int numCharacters) const
@@ -172,7 +168,7 @@ QSize QLineEdit::sizeForCharacterWidth(int numCharacters) const
     // Figure out how big a text field needs to be for a given number of characters
     // (using "0" as the nominal character).
 
-    KWQTextField *textField = (KWQTextField *)getView();
+    NSTextField *textField = (NSTextField *)getView();
 
     ASSERT(numCharacters > 0);
 
@@ -206,7 +202,7 @@ QSize QLineEdit::sizeForCharacterWidth(int numCharacters) const
 
 int QLineEdit::baselinePosition(int height) const
 {
-    KWQTextField *textField = (KWQTextField *)getView();
+    NSTextField *textField = (NSTextField *)getView();
 
     KWQ_BLOCK_EXCEPTIONS;
     NSRect bounds = [textField bounds];
@@ -227,7 +223,7 @@ void QLineEdit::setAlignment(AlignmentFlags alignment)
 {
     KWQ_BLOCK_EXCEPTIONS;
 
-    KWQTextField *textField = getView();
+    NSTextField *textField = (NSTextField *)getView();
     [textField setAlignment:KWQNSTextAlignmentForAlignmentFlags(alignment)];
 
     KWQ_UNBLOCK_EXCEPTIONS;
@@ -236,10 +232,7 @@ void QLineEdit::setAlignment(AlignmentFlags alignment)
 void QLineEdit::setWritingDirection(QPainter::TextDirection direction)
 {
     KWQ_BLOCK_EXCEPTIONS;
-
-    KWQTextField *textField = getView();
-    [textField setBaseWritingDirection:(direction == QPainter::RTL ? NSWritingDirectionRightToLeft : NSWritingDirectionLeftToRight)];
-
+    [m_controller setBaseWritingDirection:(direction == QPainter::RTL ? NSWritingDirectionRightToLeft : NSWritingDirectionLeftToRight)];
     KWQ_UNBLOCK_EXCEPTIONS;
 }
 
@@ -261,3 +254,12 @@ NSTextAlignment KWQNSTextAlignmentForAlignmentFlags(Qt::AlignmentFlags a)
             return NSCenterTextAlignment;
     }
 }
+
+void QLineEdit::setLiveSearch(bool liveSearch)
+{
+    if (m_type != Search)
+        return;
+    
+    NSSearchField *searchField = (NSSearchField *)getView();
+    [[searchField cell] setSendsWholeSearchString: !liveSearch];
+}
diff --git a/WebCore/kwq/KWQTextField.h b/WebCore/kwq/KWQTextField.h
index b121b65..9a009c2 100644
--- a/WebCore/kwq/KWQTextField.h
+++ b/WebCore/kwq/KWQTextField.h
@@ -29,25 +29,22 @@ class QLineEdit;
 @class KWQTextFieldFormatter;
 @protocol KWQWidgetHolder;
 
- at interface KWQTextField : NSTextField <KWQWidgetHolder>
+ at interface KWQTextFieldController : NSObject
 {
 @private
+    NSTextField* field;
     QLineEdit *widget;
-    NSTextField *secureField;
     KWQTextFieldFormatter *formatter;
     BOOL hasFocus;
     BOOL edited;
-    BOOL inNextValidKeyView;
     NSRange lastSelectedRange;
     BOOL inDrawingMachinery;
+    NSWritingDirection baseWritingDirection;
 }
 
-- (id)initWithQLineEdit:(QLineEdit *)widget;
-
 - (void)invalidate;
 
-- (void)setPasswordMode:(BOOL)flag;
-- (BOOL)passwordMode;
+- (void)setHasFocus:(BOOL)hasFocus;
 
 - (void)setMaximumLength:(int)len;
 - (int)maximumLength;
@@ -56,5 +53,44 @@ class QLineEdit;
 - (BOOL)edited;
 
 - (void)setBaseWritingDirection:(NSWritingDirection)direction;
+- (NSWritingDirection)baseWritingDirection;
 
 @end
+
+ at interface KWQTextField : NSTextField <KWQWidgetHolder>
+{
+ at private
+    KWQTextFieldController* controller;
+    BOOL inNextValidKeyView;
+}
+
+- (id)initWithQLineEdit:(QLineEdit *)widget;
+- (KWQTextFieldController *)controller;
+
+ at end
+
+ at interface KWQSecureTextField : NSSecureTextField <KWQWidgetHolder>
+{
+ at private
+    KWQTextFieldController* controller;
+    BOOL inNextValidKeyView;
+    BOOL inSetFrameSize;
+}
+
+- (id)initWithQLineEdit:(QLineEdit *)widget;
+- (KWQTextFieldController *)controller;
+
+ at end
+
+ at interface KWQSearchField : NSSearchField <KWQWidgetHolder>
+{
+ at private
+    KWQTextFieldController* controller;
+    BOOL inNextValidKeyView;
+}
+
+- (id)initWithQLineEdit:(QLineEdit *)widget;
+- (KWQTextFieldController *)controller;
+
+ at end
+
diff --git a/WebCore/kwq/KWQTextField.mm b/WebCore/kwq/KWQTextField.mm
index 8176cb0..b9d51af 100644
--- a/WebCore/kwq/KWQTextField.mm
+++ b/WebCore/kwq/KWQTextField.mm
@@ -37,22 +37,21 @@
 - (NSString *)_KWQ_truncateToNumComposedCharacterSequences:(int)num;
 @end
 
- at interface NSCell (KWQTextFieldKnowsAppKitSecrets)
-- (NSMutableDictionary *)_textAttributes;
+ at interface NSTextField (KWQTextField)
+- (NSText *)_KWQ_currentEditor;
 @end
 
- at interface KWQTextField (KWQInternal)
-- (void)setHasFocus:(BOOL)hasFocus;
+ at interface NSCell (KWQTextFieldKnowsAppKitSecrets)
+- (NSMutableDictionary *)_textAttributes;
 @end
 
-// KWQTextFieldCell allows us to tell when we get focus without an editor subclass,
+// The three cell subclasses allow us to tell when we get focus without an editor subclass,
 // and override the base writing direction.
 @interface KWQTextFieldCell : NSTextFieldCell
-{
-    NSWritingDirection baseWritingDirection;
-}
-- (void)setBaseWritingDirection:(NSWritingDirection)direction;
-- (NSWritingDirection)baseWritingDirection;
+ at end
+ at interface KWQSecureTextFieldCell : NSSecureTextFieldCell
+ at end
+ at interface KWQSearchFieldCell : NSSearchFieldCell
 @end
 
 // KWQTextFieldFormatter enforces a maximum length.
@@ -64,67 +63,37 @@
 - (int)maximumLength;
 @end
 
-// KWQSecureTextField has a few purposes.
-// One is a workaround for bug 3024443.
-// Another is hook up next and previous key views to KHTML.
- at interface KWQSecureTextField : NSSecureTextField <KWQWidgetHolder>
-{
-    QLineEdit *widget;
-    BOOL inNextValidKeyView;
-    BOOL inSetFrameSize;
-}
-
-- (id)initWithQLineEdit:(QLineEdit *)widget;
-
- at end
-
-// KWQSecureTextFieldCell allows us to tell when we get focus without an editor subclass,
-// and override the base writing direction.
- at interface KWQSecureTextFieldCell : NSSecureTextFieldCell
-{
-    NSWritingDirection baseWritingDirection;
-}
-- (void)setBaseWritingDirection:(NSWritingDirection)direction;
+ at interface KWQTextFieldController (KWQInternal)
+- (id)initWithTextField:(NSTextField *)f QLineEdit:(QLineEdit *)w;
+- (QWidget *)widget;
+- (void)textChanged;
+- (void)setInDrawingMachinery:(BOOL)inDrawing;
+- (BOOL)textView:(NSTextView *)view shouldDrawInsertionPointInRect:(NSRect)rect color:(NSColor *)color turnedOn:(BOOL)drawInsteadOfErase;
+- (BOOL)textView:(NSTextView *)view shouldHandleEvent:(NSEvent *)event;
+- (void)textView:(NSTextView *)view didHandleEvent:(NSEvent *)event;
+- (void)updateTextAttributes:(NSMutableDictionary *)attributes;
 @end
 
- at implementation KWQTextField
+ at implementation KWQTextFieldController
 
-+ (void)initialize
+- (id)initWithTextField:(NSTextField *)f QLineEdit:(QLineEdit *)w
 {
-    if (self == [KWQTextField class]) {
-        [self setCellClass:[KWQTextFieldCell class]];
-    }
-}
-
-- (void)setUpTextField:(NSTextField *)field
-{
-    // This is initialization that's shared by both self and the secure text field.
-
-    [[field cell] setScrollable:YES];
+    [self init];
     
+    // This is initialization that's shared by all types of text fields.
+    widget = w;
+    field = f;
+    formatter = [[KWQTextFieldFormatter alloc] init];
+    lastSelectedRange.location = NSNotFound;
+    [[field cell] setScrollable:YES];
     [field setFormatter:formatter];
-
     [field setDelegate:self];
-    
     [field setTarget:self];
     [field setAction:@selector(action:)];
-}
-
--(id)initWithFrame:(NSRect)frame
-{
-    [super initWithFrame:frame];
-    formatter = [[KWQTextFieldFormatter alloc] init];
-    [self setUpTextField:self];
-    lastSelectedRange.location = NSNotFound;
+    
     return self;
 }
 
--(id)initWithQLineEdit:(QLineEdit *)w 
-{
-    widget = w;
-    return [self init];
-}
-
 -(void)invalidate
 {
     widget = NULL;
@@ -132,109 +101,27 @@
 
 - (void)action:sender
 {
-    if (!widget) {
+    if (!widget)
 	return;
-    }
-
     widget->returnPressed();
 }
 
 - (void)dealloc
 {
-    [secureField release];
     [formatter release];
     [super dealloc];
 }
 
-- (KWQTextFieldFormatter *)formatter
-{
-    return formatter;
-}
-
-- (void)updateSecureFieldFrame
-{
-    [secureField setFrame:[self bounds]];
-}
-
-- (void)setFrameSize:(NSSize)size
-{
-    [super setFrameSize:size];
-    [self updateSecureFieldFrame];
-}
-
-- (void)setPasswordMode:(BOOL)flag
-{
-    if (!flag == ![secureField superview]) {
-        return;
-    }
-    
-    if (!flag) {
-        // Don't use [self setStringValue:] because there are unwanted side effects,
-        // like sending out a text changed signal.
-        [super setStringValue:[secureField stringValue]];
-        [secureField removeFromSuperview];
-    } else {
-        if (secureField == nil) {
-            secureField = [[KWQSecureTextField alloc] initWithQLineEdit:widget];
-            [secureField setFormatter:formatter];
-            [secureField setFont:[self font]];
-            [secureField setEditable:[self isEditable]];
-            [secureField setSelectable:[self isSelectable]];
-            [[secureField cell] setBaseWritingDirection:[[self cell] baseWritingDirection]];
-            [self setUpTextField:secureField];
-            [self updateSecureFieldFrame];
-        }
-        [secureField setStringValue:[super stringValue]];
-        [self addSubview:secureField];
-    }
-}
-
-- (void)setEditable:(BOOL)flag
-{
-    [secureField setEditable:flag];
-    [super setEditable:flag];
-}
-
-- (void)setSelectable:(BOOL)flag
-{
-    [secureField setSelectable:flag];
-    [super setSelectable:flag];
-}
-
-- (void)selectText:(id)sender
+- (QWidget*)widget
 {
-    if ([self passwordMode]) {
-        [secureField selectText:sender];
-        return;
-    }
-    
-    // Don't call the NSTextField's selectText if the field is already first responder.
-    // If we do, we'll end up deactivating and then reactivating, which will send
-    // unwanted onBlur events.
-    NSText *editor = [self currentEditor];
-    if (editor) {
-        [editor setSelectedRange:NSMakeRange(0, [[editor string] length])];
-        return;
-    }
-    
-    [super selectText:sender];
-}
-
-- (BOOL)isEditable
-{
-    return [super isEditable];
-}
-
-- (BOOL)passwordMode
-{
-    return [secureField superview] != nil;
+    return widget;
 }
 
 - (void)setMaximumLength:(int)len
 {
-    NSString *oldValue = [self stringValue];
+    NSString *oldValue = [field stringValue];
     if ([oldValue _KWQ_numComposedCharacterSequences] > len) {
-        [self setStringValue:[oldValue _KWQ_truncateToNumComposedCharacterSequences:len]];
+        [field setStringValue:[oldValue _KWQ_truncateToNumComposedCharacterSequences:len]];
     }
     [formatter setMaximumLength:len];
 }
@@ -256,20 +143,18 @@
 
 -(void)controlTextDidBeginEditing:(NSNotification *)notification
 {
-    if (!widget) {
+    if (!widget)
 	return;
-    }
-
+    
     WebCoreBridge *bridge = KWQKHTMLPart::bridgeForWidget(widget);
     [bridge controlTextDidBeginEditing:notification];
 }
 
 -(void)controlTextDidEndEditing:(NSNotification *)notification
 {
-    if (!widget) {
+    if (!widget)
 	return;
-    }
-
+    
     WebCoreBridge *bridge = KWQKHTMLPart::bridgeForWidget(widget);
     [bridge controlTextDidEndEditing:notification];
     
@@ -278,14 +163,12 @@
 
 -(void)controlTextDidChange:(NSNotification *)notification
 {
-    if (!widget) {
+    if (!widget)
 	return;
-    }
     
-    if (KWQKHTMLPart::handleKeyboardOptionTabInView(self)) {
+    if (KWQKHTMLPart::handleKeyboardOptionTabInView(field))
         return;
-    }
-
+    
     WebCoreBridge *bridge = KWQKHTMLPart::bridgeForWidget(widget);
     [bridge controlTextDidChange:notification];
     
@@ -295,12 +178,11 @@
 
 -(BOOL)control:(NSControl *)control textShouldBeginEditing:(NSText *)fieldEditor
 {
-    if (!widget) {
-	return NO;
-    }
-
+    if (!widget)
+        return NO;
+    
     WebCoreBridge *bridge = KWQKHTMLPart::bridgeForWidget(widget);
-
+    
     // In WebHTMLView, we set a clip. This is not typical to do in an
     // NSView, and while correct for any one invocation of drawRect:,
     // it causes some bad problems if that clip is cached between calls.
@@ -312,165 +194,64 @@
     // See bug 3457875 and 3310943 for more context.
     [fieldEditor releaseGState];
     [[fieldEditor superview] releaseGState];
-
+    
     return [bridge control:control textShouldBeginEditing:fieldEditor];
 }
 
 -(BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor
 {
-    if (!widget) {
+    if (!widget)
 	return NO;
-    }
-
+    
     WebCoreBridge *bridge = KWQKHTMLPart::bridgeForWidget(widget);
     return [bridge control:control textShouldEndEditing:fieldEditor];
 }
 
 -(BOOL)control:(NSControl *)control didFailToFormatString:(NSString *)string errorDescription:(NSString *)error
 {
-    if (!widget) {
+    if (!widget)
 	return NO;
-    }
-
+    
     WebCoreBridge *bridge = KWQKHTMLPart::bridgeForWidget(widget);
     return [bridge control:control didFailToFormatString:string errorDescription:error];
 }
 
 -(void)control:(NSControl *)control didFailToValidatePartialString:(NSString *)string errorDescription:(NSString *)error
 {
-    if (!widget) {
+    if (!widget)
 	return;
-    }
-
+    
     WebCoreBridge *bridge = KWQKHTMLPart::bridgeForWidget(widget);
     [bridge control:control didFailToValidatePartialString:string errorDescription:error];
 }
 
 -(BOOL)control:(NSControl *)control isValidObject:(id)obj
 {
-    if (!widget) {
+    if (!widget)
 	return NO;
-    }
-
+    
     WebCoreBridge *bridge = KWQKHTMLPart::bridgeForWidget(widget);
     return [bridge control:control isValidObject:obj];
 }
 
 -(BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)commandSelector
 {
-    if (!widget) {
+    if (!widget)
 	return NO;
-    }
-
+    
     WebCoreBridge *bridge = KWQKHTMLPart::bridgeForWidget(widget);
     return [bridge control:control textView:textView doCommandBySelector:commandSelector];
 }
 
--(NSString *)stringValue
-{
-    if ([secureField superview]) {
-        return [secureField stringValue];
-    }
-    return [super stringValue];
-}
-
--(void)setStringValue:(NSString *)string
-{
-    if (!widget) {
-	return;
-    }
-
-    int maxLength = [formatter maximumLength];
-    string = [string _KWQ_truncateToNumComposedCharacterSequences:maxLength];
-    [secureField setStringValue:string];
-    [super setStringValue:string];
-    widget->textChanged();
-}
-
--(void)setFont:(NSFont *)font
-{
-    [secureField setFont:font];
-    [super setFont:font];
-}
-
--(NSView *)nextKeyView
+-(void)textChanged
 {
-    if (!widget) {
-	return [super nextKeyView];
-    }
-
-    return inNextValidKeyView
-        ? KWQKHTMLPart::nextKeyViewForWidget(widget, KWQSelectingNext)
-        : [super nextKeyView];
-}
-
--(NSView *)previousKeyView
-{
-    if (!widget) {
-	return [super previousKeyView];
-    }
-
-    return inNextValidKeyView
-        ? KWQKHTMLPart::nextKeyViewForWidget(widget, KWQSelectingPrevious)
-        : [super previousKeyView];
-}
-
--(NSView *)nextValidKeyView
-{
-    inNextValidKeyView = YES;
-    NSView *view = [super nextValidKeyView];
-    inNextValidKeyView = NO;
-    return view;
+    if (widget)
+        widget->textChanged();
 }
 
--(NSView *)previousValidKeyView
+- (void)setInDrawingMachinery:(BOOL)inDrawing
 {
-    inNextValidKeyView = YES;
-    NSView *view = [super previousValidKeyView];
-    inNextValidKeyView = NO;
-    return view;
-}
-
-- (BOOL)acceptsFirstResponder
-{
-    return [self isEnabled];
-}
-
-- (BOOL)becomeFirstResponder
-{
-    if ([self passwordMode]) {
-        return [[self window] makeFirstResponder:secureField];
-    }
-    return [super becomeFirstResponder];
-}
-
-- (void)display
-{
-    // This is a workaround for Radar 2753974.
-    // Also, in the web page context, it's never OK to just display.
-    [self setNeedsDisplay:YES];
-}
-
-- (QWidget *)widget
-{
-    return widget;
-}
-
-- (void)setAlignment:(NSTextAlignment)alignment
-{
-    [secureField setAlignment:alignment];
-    [super setAlignment:alignment];
-}
-
-// This is the only one of the display family of calls that we use, and the way we do
-// displaying in WebCore means this is called on this NSView explicitly, so this catches
-// all cases where we are inside the normal display machinery. (Used only by the insertion
-// point method below.)
-- (void)displayRectIgnoringOpacity:(NSRect)rect
-{
-    inDrawingMachinery = YES;
-    [super displayRectIgnoringOpacity:rect];
-    inDrawingMachinery = NO;
+    inDrawingMachinery = inDrawing;
 }
 
 // Use the "needs display" mechanism to do all insertion point drawing in the web view.
@@ -479,9 +260,8 @@
     // We only need to take control of the cases where we are being asked to draw by something
     // outside the normal display machinery, and when we are being asked to draw the insertion
     // point, not erase it.
-    if (inDrawingMachinery || !drawInsteadOfErase) {
+    if (inDrawingMachinery || !drawInsteadOfErase)
         return YES;
-    }
 
     // NSTextView's insertion-point drawing code sets the rect width to 1.
     // So we do the same thing, to affect exactly the same rectangle.
@@ -501,10 +281,9 @@
 
 - (BOOL)textView:(NSTextView *)view shouldHandleEvent:(NSEvent *)event
 {
-    if (!widget) {
+    if (!widget)
 	return YES;
-    }
-
+    
     NSEventType type = [event type];
     if ((type == NSKeyDown || type == NSKeyUp) && 
 	![[NSInputManager currentInputManager] hasMarkedText]) {
@@ -520,9 +299,9 @@
 
 - (void)textView:(NSTextView *)view didHandleEvent:(NSEvent *)event
 {
-    if (!widget) {
+    if (!widget)
 	return;
-    }
+
     if ([event type] == NSLeftMouseUp) {
         widget->sendConsumedMouseUp();
         widget->clicked();
@@ -531,36 +310,20 @@
 
 - (void)setBaseWritingDirection:(NSWritingDirection)direction
 {
-    KWQTextFieldCell *cell = [self cell];
-    if ([cell baseWritingDirection] != direction) {
-        [cell setBaseWritingDirection:direction];
-        [[secureField cell] setBaseWritingDirection:direction];
-
-        // One call to setNeedsDisplay will take care of both text fields.
-        [self setNeedsDisplay:YES];
+    if (baseWritingDirection != direction) {
+        baseWritingDirection = direction;
+        [field setNeedsDisplay:YES];
     }
 }
 
- at end
-
- at implementation KWQTextField (KWQInternal)
-
-- (NSText *)currentEditorForEitherField
+- (NSWritingDirection)baseWritingDirection
 {
-    NSResponder *firstResponder = [[self window] firstResponder];
-    if ([firstResponder isKindOfClass:[NSText class]]) {
-        NSText *editor = (NSText *)firstResponder;
-        id delegate = [editor delegate];
-        if (delegate == self || delegate == secureField) {
-            return editor;
-        }
-    }
-    return nil;
+    return baseWritingDirection;
 }
 
 - (NSRange)selectedRange
 {
-    NSText *editor = [self currentEditorForEitherField];
+    NSText *editor = [field _KWQ_currentEditor];
     return editor ? [editor selectedRange] : NSMakeRange(NSNotFound, 0);
 }
 
@@ -569,7 +332,7 @@
     // Range check just in case the saved range has gotten out of sync.
     // Even though we don't see this in testing, we really don't want
     // an exception in this case, so we protect ourselves.
-    NSText *editor = [self currentEditorForEitherField];    
+    NSText *editor = [field _KWQ_currentEditor];    
     if (NSMaxRange(range) <= [[editor string] length]) {
         [editor setSelectedRange:range];
     }
@@ -577,34 +340,26 @@
 
 - (void)setHasFocus:(BOOL)nowHasFocus
 {
-    if (!widget) {
+    if (!widget || nowHasFocus == hasFocus)
 	return;
-    }
-
-    if (nowHasFocus == hasFocus) {
-        return;
-    }
 
     hasFocus = nowHasFocus;
-
+    
     if (nowHasFocus) {
         // Select all the text if we are tabbing in, but otherwise preserve/remember
         // the selection from last time we had focus (to match WinIE).
-        if ([[self window] keyViewSelectionDirection] != NSDirectSelection) {
+        if ([[field window] keyViewSelectionDirection] != NSDirectSelection)
             lastSelectedRange.location = NSNotFound;
-        }
-
-        if (lastSelectedRange.location != NSNotFound) {
+        
+        if (lastSelectedRange.location != NSNotFound)
             [self setSelectedRange:lastSelectedRange];
-        }
         
-        if (!KWQKHTMLPart::currentEventIsMouseDownInWidget(widget)) {
-            [self _KWQ_scrollFrameToVisible];
-        }
-
+        if (!KWQKHTMLPart::currentEventIsMouseDownInWidget(widget))
+            [field _KWQ_scrollFrameToVisible];
+        
         QFocusEvent event(QEvent::FocusIn);
         const_cast<QObject *>(widget->eventFilterObject())->eventFilter(widget, &event);
-
+        
 	// Sending the onFocus event above, may have resulted in a blur() - if this
 	// happens when tabbing from another text field, then endEditing: and
 	// controlTextDidEndEditing: will never be called. The bad side effects of this 
@@ -612,136 +367,244 @@
 	// and the text field will think it's still editing, so it will continue to draw
 	// the focus ring. So we call endEditing: manually if we detect this inconsistency,
 	// and the correct our internal impression of the focus state.
-
-	if ([self currentEditorForEitherField] == nil && [self currentEditor] != nil) {
-	    [[self cell] endEditing:[self currentEditor]];
+	if ([field _KWQ_currentEditor] == nil && [field currentEditor] != nil) {
+	    [[field cell] endEditing:[field currentEditor]];
 	    [self setHasFocus:NO];
 	}
     } else {
         lastSelectedRange = [self selectedRange];
-
+        
         QFocusEvent event(QEvent::FocusOut);
         const_cast<QObject *>(widget->eventFilterObject())->eventFilter(widget, &event);
     }
 }
 
+- (void)updateTextAttributes:(NSMutableDictionary *)attributes
+{
+    NSParagraphStyle *style = [attributes objectForKey:NSParagraphStyleAttributeName];
+    ASSERT(style != nil);
+    if ([style baseWritingDirection] != baseWritingDirection) {
+        NSMutableParagraphStyle *mutableStyle = [style mutableCopy];
+        [mutableStyle setBaseWritingDirection:baseWritingDirection];
+        [attributes setObject:mutableStyle forKey:NSParagraphStyleAttributeName];
+        [mutableStyle release];
+    }
+}
+
 @end
 
- at implementation KWQTextFieldCell
+ at implementation KWQTextField
 
-- (void)editWithFrame:(NSRect)frame inView:(NSView *)view editor:(NSText *)editor delegate:(id)delegate event:(NSEvent *)event
++ (Class)cellClass
 {
-    [super editWithFrame:frame inView:view editor:editor delegate:delegate event:event];
-    ASSERT([delegate isKindOfClass:[KWQTextField class]]);
-    [(KWQTextField *)delegate setHasFocus:YES];
+    return [KWQTextFieldCell class];
 }
 
-- (void)selectWithFrame:(NSRect)frame inView:(NSView *)view editor:(NSText *)editor delegate:(id)delegate start:(int)start length:(int)length
+- (id)initWithQLineEdit:(QLineEdit *)w 
 {
-    [super selectWithFrame:frame inView:view editor:editor delegate:delegate start:start length:length];
-    ASSERT([delegate isKindOfClass:[KWQTextField class]]);
-    [(KWQTextField *)delegate setHasFocus:YES];
+    [self init];
+    controller = [[KWQTextFieldController alloc] initWithTextField:self QLineEdit:w];
+    return self;
 }
 
-- (void)setBaseWritingDirection:(NSWritingDirection)direction
+- (void)dealloc
 {
-    baseWritingDirection = direction;
+    [controller release];
+    [super dealloc];
 }
 
-- (NSWritingDirection)baseWritingDirection
+- (KWQTextFieldController *)controller
 {
-    return baseWritingDirection;
+    return controller;
 }
 
-- (NSMutableDictionary *)_textAttributes
+- (QWidget *)widget
 {
-    NSMutableDictionary *attributes = [super _textAttributes];
-    NSParagraphStyle *style = [attributes objectForKey:NSParagraphStyleAttributeName];
-    ASSERT(style != nil);
-    if ([style baseWritingDirection] != baseWritingDirection) {
-        NSMutableParagraphStyle *mutableStyle = [style mutableCopy];
-        [mutableStyle setBaseWritingDirection:baseWritingDirection];
-        [attributes setObject:mutableStyle forKey:NSParagraphStyleAttributeName];
-        [mutableStyle release];
+    return [controller widget];
+}
+
+- (void)selectText:(id)sender
+{
+    // Don't call the NSTextField's selectText if the field is already first responder.
+    // If we do, we'll end up deactivating and then reactivating, which will send
+    // unwanted onBlur events.
+    NSText *editor = [self currentEditor];
+    if (editor) {
+        [editor setSelectedRange:NSMakeRange(0, [[editor string] length])];
+        return;
     }
-    return attributes;
+    
+    [super selectText:sender];
 }
 
- at end
+- (void)setStringValue:(NSString *)string
+{
+    int maxLength = [controller maximumLength];
+    string = [string _KWQ_truncateToNumComposedCharacterSequences:maxLength];
+    [super setStringValue:string];
+    [controller textChanged];
+}
 
- at implementation KWQTextFieldFormatter
+- (NSView *)nextKeyView
+{
+    if (!inNextValidKeyView)
+	return [super nextKeyView];
+    QWidget* widget = [controller widget];
+    if (!widget)
+	return [super nextKeyView];
+    return KWQKHTMLPart::nextKeyViewForWidget(widget, KWQSelectingNext);
+}
 
-- init
+- (NSView *)previousKeyView
 {
-    [super init];
-    maxLength = INT_MAX;
-    return self;
+    if (!inNextValidKeyView)
+	return [super nextKeyView];
+    QWidget* widget = [controller widget];
+    if (!widget)
+	return [super previousKeyView];
+    return KWQKHTMLPart::nextKeyViewForWidget(widget, KWQSelectingPrevious);
 }
 
-- (void)setMaximumLength:(int)len
+- (NSView *)nextValidKeyView
 {
-    maxLength = len;
+    inNextValidKeyView = YES;
+    NSView *view = [super nextValidKeyView];
+    inNextValidKeyView = NO;
+    return view;
 }
 
-- (int)maximumLength
+- (NSView *)previousValidKeyView
 {
-    return maxLength;
+    inNextValidKeyView = YES;
+    NSView *view = [super previousValidKeyView];
+    inNextValidKeyView = NO;
+    return view;
 }
 
-- (NSString *)stringForObjectValue:(id)object
+- (BOOL)acceptsFirstResponder
 {
-    return (NSString *)object;
+    return [self isEnabled];
 }
 
-- (BOOL)getObjectValue:(id *)object forString:(NSString *)string errorDescription:(NSString **)error
+- (void)display
 {
-    *object = string;
-    return YES;
+    // This is a workaround for Radar 2753974.
+    // Also, in the web page context, it's never OK to just display.
+    [self setNeedsDisplay:YES];
 }
 
-- (BOOL)isPartialStringValid:(NSString *)partialString newEditingString:(NSString **)newString errorDescription:(NSString **)error
+// This is the only one of the display family of calls that we use, and the way we do
+// displaying in WebCore means this is called on this NSView explicitly, so this catches
+// all cases where we are inside the normal display machinery. (Used only by the insertion
+// point method below.)
+- (void)displayRectIgnoringOpacity:(NSRect)rect
 {
-    if ([partialString _KWQ_numComposedCharacterSequences] > maxLength) {
-        *newString = nil;
-        return NO;
-    }
+    [controller setInDrawingMachinery:YES];
+    [super displayRectIgnoringOpacity:rect];
+    [controller setInDrawingMachinery:NO];
+}
 
-    return YES;
+// Use the "needs display" mechanism to do all insertion point drawing in the web view.
+- (BOOL)textView:(NSTextView *)view shouldDrawInsertionPointInRect:(NSRect)rect color:(NSColor *)color turnedOn:(BOOL)drawInsteadOfErase
+{
+    return [controller textView:view shouldDrawInsertionPointInRect:rect color:color turnedOn:drawInsteadOfErase];
 }
 
-- (NSAttributedString *)attributedStringForObjectValue:(id)anObject withDefaultAttributes:(NSDictionary *)attributes
+- (BOOL)textView:(NSTextView *)view shouldHandleEvent:(NSEvent *)event
 {
-    return nil;
+    return [controller textView:view shouldHandleEvent:event];
+}
+
+- (void)textView:(NSTextView *)view didHandleEvent:(NSEvent *)event
+{
+    [controller textView:view didHandleEvent:event];
 }
 
 @end
 
- at implementation KWQSecureTextField
+ at implementation KWQTextFieldCell
 
--(id)initWithQLineEdit:(QLineEdit *)w 
+- (void)editWithFrame:(NSRect)frame inView:(NSView *)view editor:(NSText *)editor delegate:(id)delegate event:(NSEvent *)event
 {
-    widget = w;
-    return [self init];
+    [super editWithFrame:frame inView:view editor:editor delegate:delegate event:event];
+    ASSERT([delegate isKindOfClass:[KWQTextField class]]);
+    [[(KWQTextField *)delegate controller] setHasFocus:YES];
+}
+
+- (void)selectWithFrame:(NSRect)frame inView:(NSView *)view editor:(NSText *)editor delegate:(id)delegate start:(int)start length:(int)length
+{
+    [super selectWithFrame:frame inView:view editor:editor delegate:delegate start:start length:length];
+    ASSERT([delegate isKindOfClass:[KWQTextField class]]);
+    [[(KWQTextField *)delegate controller] setHasFocus:YES];
 }
 
-// Can't use setCellClass: because NSSecureTextField won't let us (for no good reason).
+- (NSMutableDictionary *)_textAttributes
+{
+    ASSERT([[self controlView] isKindOfClass:[KWQTextField class]]);
+    NSMutableDictionary* attributes = [super _textAttributes];
+    [[(KWQTextField*)[self controlView] controller] updateTextAttributes:attributes];
+    return attributes;
+}
+
+ at end
+
+
+ at implementation KWQSecureTextField
+
 + (Class)cellClass
 {
     return [KWQSecureTextFieldCell class];
 }
 
+- (id)initWithQLineEdit:(QLineEdit *)w 
+{
+    [self init];
+    controller = [[KWQTextFieldController alloc] initWithTextField:self QLineEdit:w];
+    return self;
+}
+
+- (void)dealloc
+{
+    [controller release];
+    [super dealloc];
+}
+
+- (KWQTextFieldController *)controller
+{
+    return controller;
+}
+
+- (QWidget *)widget
+{
+    return [controller widget];
+}
+
+- (void)setStringValue:(NSString *)string
+{
+    int maxLength = [controller maximumLength];
+    string = [string _KWQ_truncateToNumComposedCharacterSequences:maxLength];
+    [super setStringValue:string];
+    [controller textChanged];
+}
+
 - (NSView *)nextKeyView
 {
-    return inNextValidKeyView
-        ? KWQKHTMLPart::nextKeyViewForWidget([self widget], KWQSelectingNext)
-        : [super nextKeyView];
+    if (!inNextValidKeyView)
+	return [super nextKeyView];
+    QWidget* widget = [controller widget];
+    if (!widget)
+	return [super nextKeyView];
+    return KWQKHTMLPart::nextKeyViewForWidget(widget, KWQSelectingNext);
 }
 
 - (NSView *)previousKeyView
 {
-   return inNextValidKeyView
-        ? KWQKHTMLPart::nextKeyViewForWidget([self widget], KWQSelectingPrevious)
-        : [super previousKeyView];
+    if (!inNextValidKeyView)
+	return [super nextKeyView];
+    QWidget* widget = [controller widget];
+    if (!widget)
+	return [super previousKeyView];
+    return KWQKHTMLPart::nextKeyViewForWidget(widget, KWQSelectingPrevious);
 }
 
 - (NSView *)nextValidKeyView
@@ -760,18 +623,43 @@
     return view;
 }
 
-// The currentEditor method does not work for secure text fields.
-// This works around that limitation.
-- (NSText *)currentEditorForSecureField
+- (BOOL)acceptsFirstResponder
 {
-    NSResponder *firstResponder = [[self window] firstResponder];
-    if ([firstResponder isKindOfClass:[NSText class]]) {
-        NSText *editor = (NSText *)firstResponder;
-        if ([editor delegate] == self) {
-            return editor;
-        }
-    }
-    return nil;
+    return [self isEnabled];
+}
+
+- (void)display
+{
+    // This is a workaround for Radar 2753974.
+    // Also, in the web page context, it's never OK to just display.
+    [self setNeedsDisplay:YES];
+}
+
+// This is the only one of the display family of calls that we use, and the way we do
+// displaying in WebCore means this is called on this NSView explicitly, so this catches
+// all cases where we are inside the normal display machinery. (Used only by the insertion
+// point method below.)
+- (void)displayRectIgnoringOpacity:(NSRect)rect
+{
+    [controller setInDrawingMachinery:YES];
+    [super displayRectIgnoringOpacity:rect];
+    [controller setInDrawingMachinery:NO];
+}
+
+// Use the "needs display" mechanism to do all insertion point drawing in the web view.
+- (BOOL)textView:(NSTextView *)view shouldDrawInsertionPointInRect:(NSRect)rect color:(NSColor *)color turnedOn:(BOOL)drawInsteadOfErase
+{
+    return [controller textView:view shouldDrawInsertionPointInRect:rect color:color turnedOn:drawInsteadOfErase];
+}
+
+- (BOOL)textView:(NSTextView *)view shouldHandleEvent:(NSEvent *)event
+{
+    return [controller textView:view shouldHandleEvent:event];
+}
+
+- (void)textView:(NSTextView *)view didHandleEvent:(NSEvent *)event
+{
+    [controller textView:view didHandleEvent:event];
 }
 
 // These next two methods are the workaround for bug 3024443.
@@ -788,7 +676,7 @@
     // If we do, we'll end up deactivating and then reactivating, which will send
     // unwanted onBlur events and wreak havoc in other ways as well by setting the focus
     // back to the window.
-    NSText *editor = [self currentEditorForSecureField];
+    NSText *editor = [self _KWQ_currentEditor];
     if (editor) {
         [editor setSelectedRange:NSMakeRange(0, [[editor string] length])];
         return;
@@ -804,19 +692,6 @@
     inSetFrameSize = NO;
 }
 
-- (void)display
-{
-    // This is a workaround for Radar 2753974.
-    // Also, in the web page context, it's never OK to just display.
-    [self setNeedsDisplay:YES];
-}
-
-- (QWidget *)widget
-{
-    ASSERT([[self delegate] isKindOfClass:[KWQTextField class]]);
-    return [(KWQTextField *)[self delegate] widget];
-}
-
 - (void)textDidEndEditing:(NSNotification *)notification
 {
     [super textDidEndEditing:notification];
@@ -838,66 +713,232 @@
     }
 }
 
-- (BOOL)textView:(NSTextView *)view shouldHandleEvent:(NSEvent *)event
+ at end
+
+ at implementation KWQSecureTextFieldCell
+
+- (void)editWithFrame:(NSRect)frame inView:(NSView *)view editor:(NSText *)editor delegate:(id)delegate event:(NSEvent *)event
 {
-    if (!widget) {
-	return YES;
-    }
+    [super editWithFrame:frame inView:view editor:editor delegate:delegate event:event];
+    ASSERT([delegate isKindOfClass:[KWQSecureTextField class]]);
+    [[(KWQSecureTextField *)delegate controller] setHasFocus:YES];
+}
 
-    if (([event type] == NSKeyDown || [event type] == NSKeyUp) &&
-	![[NSInputManager currentInputManager] hasMarkedText]) {
-        WebCoreBridge *bridge = KWQKHTMLPart::bridgeForWidget(widget);
-        return ![bridge interceptKeyEvent:event toView:view];
+- (void)selectWithFrame:(NSRect)frame inView:(NSView *)view editor:(NSText *)editor delegate:(id)delegate start:(int)start length:(int)length
+{
+    [super selectWithFrame:frame inView:view editor:editor delegate:delegate start:start length:length];
+    ASSERT([delegate isKindOfClass:[KWQSecureTextField class]]);
+    [[(KWQSecureTextField *)delegate controller] setHasFocus:YES];
+}
+
+- (NSMutableDictionary *)_textAttributes
+{
+    ASSERT([[self controlView] isKindOfClass:[KWQSecureTextField class]]);
+    NSMutableDictionary* attributes = [super _textAttributes];
+    [[(KWQSecureTextField*)[self controlView] controller] updateTextAttributes:attributes];
+    return attributes;
+}
+
+ at end
+
+ at implementation KWQSearchField
+
++ (Class)cellClass
+{
+    return [KWQSearchFieldCell class];
+}
+
+- (id)initWithQLineEdit:(QLineEdit *)w 
+{
+    [self init];
+    controller = [[KWQTextFieldController alloc] initWithTextField:self QLineEdit:w];
+    return self;
+}
+
+- (void)dealloc
+{
+    [controller release];
+    [super dealloc];
+}
+
+- (KWQTextFieldController *)controller
+{
+    return controller;
+}
+
+- (QWidget *)widget
+{
+    return [controller widget];
+}
+
+- (void)selectText:(id)sender
+{
+    // Don't call the NSTextField's selectText if the field is already first responder.
+    // If we do, we'll end up deactivating and then reactivating, which will send
+    // unwanted onBlur events.
+    NSText *editor = [self currentEditor];
+    if (editor) {
+        [editor setSelectedRange:NSMakeRange(0, [[editor string] length])];
+        return;
     }
-    return YES;
+    
+    [super selectText:sender];
+}
+
+- (void)setStringValue:(NSString *)string
+{
+    int maxLength = [controller maximumLength];
+    string = [string _KWQ_truncateToNumComposedCharacterSequences:maxLength];
+    [super setStringValue:string];
+    [controller textChanged];
+}
+
+- (NSView *)nextKeyView
+{
+    if (!inNextValidKeyView)
+	return [super nextKeyView];
+    QWidget* widget = [controller widget];
+    if (!widget)
+	return [super nextKeyView];
+    return KWQKHTMLPart::nextKeyViewForWidget(widget, KWQSelectingNext);
+}
+
+- (NSView *)previousKeyView
+{
+    if (!inNextValidKeyView)
+	return [super nextKeyView];
+    QWidget* widget = [controller widget];
+    if (!widget)
+	return [super previousKeyView];
+    return KWQKHTMLPart::nextKeyViewForWidget(widget, KWQSelectingPrevious);
+}
+
+- (NSView *)nextValidKeyView
+{
+    inNextValidKeyView = YES;
+    NSView *view = [super nextValidKeyView];
+    inNextValidKeyView = NO;
+    return view;
+}
+
+- (NSView *)previousValidKeyView
+{
+    inNextValidKeyView = YES;
+    NSView *view = [super previousValidKeyView];
+    inNextValidKeyView = NO;
+    return view;
+}
+
+- (BOOL)acceptsFirstResponder
+{
+    return [self isEnabled];
+}
+
+- (void)display
+{
+    // This is a workaround for Radar 2753974.
+    // Also, in the web page context, it's never OK to just display.
+    [self setNeedsDisplay:YES];
+}
+
+// This is the only one of the display family of calls that we use, and the way we do
+// displaying in WebCore means this is called on this NSView explicitly, so this catches
+// all cases where we are inside the normal display machinery. (Used only by the insertion
+// point method below.)
+- (void)displayRectIgnoringOpacity:(NSRect)rect
+{
+    [controller setInDrawingMachinery:YES];
+    [super displayRectIgnoringOpacity:rect];
+    [controller setInDrawingMachinery:NO];
+}
+
+// Use the "needs display" mechanism to do all insertion point drawing in the web view.
+- (BOOL)textView:(NSTextView *)view shouldDrawInsertionPointInRect:(NSRect)rect color:(NSColor *)color turnedOn:(BOOL)drawInsteadOfErase
+{
+    return [controller textView:view shouldDrawInsertionPointInRect:rect color:color turnedOn:drawInsteadOfErase];
+}
+
+- (BOOL)textView:(NSTextView *)view shouldHandleEvent:(NSEvent *)event
+{
+    return [controller textView:view shouldHandleEvent:event];
 }
 
 - (void)textView:(NSTextView *)view didHandleEvent:(NSEvent *)event
 {
-    if (!widget) {
-	return;
-    }
-    if ([event type] == NSLeftMouseUp) {
-        widget->sendConsumedMouseUp();
-        widget->clicked();
-    }
+    [controller textView:view didHandleEvent:event];
 }
 
 @end
 
- at implementation KWQSecureTextFieldCell
+ at implementation KWQSearchFieldCell
 
 - (void)editWithFrame:(NSRect)frame inView:(NSView *)view editor:(NSText *)editor delegate:(id)delegate event:(NSEvent *)event
 {
     [super editWithFrame:frame inView:view editor:editor delegate:delegate event:event];
-    ASSERT([[delegate delegate] isKindOfClass:[KWQTextField class]]);
-    [(KWQTextField *)[delegate delegate] setHasFocus:YES];
+    ASSERT([delegate isKindOfClass:[KWQSearchField class]]);
+    [[(KWQSearchField *)delegate controller] setHasFocus:YES];
 }
 
 - (void)selectWithFrame:(NSRect)frame inView:(NSView *)view editor:(NSText *)editor delegate:(id)delegate start:(int)start length:(int)length
 {
     [super selectWithFrame:frame inView:view editor:editor delegate:delegate start:start length:length];
-    ASSERT([[delegate delegate] isKindOfClass:[KWQTextField class]]);
-    [(KWQTextField *)[delegate delegate] setHasFocus:YES];
+    ASSERT([delegate isKindOfClass:[KWQSearchField class]]);
+    [[(KWQSearchField *)delegate controller] setHasFocus:YES];
 }
 
-- (void)setBaseWritingDirection:(NSWritingDirection)direction
+- (NSMutableDictionary *)_textAttributes
 {
-    baseWritingDirection = direction;
+    ASSERT([[self controlView] isKindOfClass:[KWQSearchField class]]);
+    NSMutableDictionary* attributes = [super _textAttributes];
+    [[(KWQSearchField*)[self controlView] controller] updateTextAttributes:attributes];
+    return attributes;
 }
 
-- (NSMutableDictionary *)_textAttributes
+ at end
+
+ at implementation KWQTextFieldFormatter
+
+- init
 {
-    NSMutableDictionary *attributes = [super _textAttributes];
-    NSParagraphStyle *style = [attributes objectForKey:NSParagraphStyleAttributeName];
-    ASSERT(style != nil);
-    if ([style baseWritingDirection] != baseWritingDirection) {
-        NSMutableParagraphStyle *mutableStyle = [style mutableCopy];
-        [mutableStyle setBaseWritingDirection:baseWritingDirection];
-        [attributes setObject:mutableStyle forKey:NSParagraphStyleAttributeName];
-        [mutableStyle release];
+    [super init];
+    maxLength = INT_MAX;
+    return self;
+}
+
+- (void)setMaximumLength:(int)len
+{
+    maxLength = len;
+}
+
+- (int)maximumLength
+{
+    return maxLength;
+}
+
+- (NSString *)stringForObjectValue:(id)object
+{
+    return (NSString *)object;
+}
+
+- (BOOL)getObjectValue:(id *)object forString:(NSString *)string errorDescription:(NSString **)error
+{
+    *object = string;
+    return YES;
+}
+
+- (BOOL)isPartialStringValid:(NSString *)partialString newEditingString:(NSString **)newString errorDescription:(NSString **)error
+{
+    if ([partialString _KWQ_numComposedCharacterSequences] > maxLength) {
+        *newString = nil;
+        return NO;
     }
-    return attributes;
+    
+    return YES;
+}
+
+- (NSAttributedString *)attributedStringForObjectValue:(id)anObject withDefaultAttributes:(NSDictionary *)attributes
+{
+    return nil;
 }
 
 @end
@@ -933,3 +974,21 @@
 }
 
 @end
+
+ at implementation NSTextField (KWQTextField)
+
+// The currentEditor method does not work for secure text fields.
+// This works around that limitation.
+- (NSText *)_KWQ_currentEditor
+{
+    NSResponder *firstResponder = [[self window] firstResponder];
+    if ([firstResponder isKindOfClass:[NSText class]]) {
+        NSText *editor = (NSText *)firstResponder;
+        id delegate = [editor delegate];
+        if (delegate == self)
+            return editor;
+    }
+    return nil;
+}
+
+ at end

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list