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

darin darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 07:38:04 UTC 2009


The following commit has been merged in the debian/unstable branch:
commit f16840ee47951348d501bc0fbf690886ee7a75b4
Author: darin <darin at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Apr 22 18:30:09 2003 +0000

            Reviewed by John.
    
    	- fixed 3144966 -- problems typing in form at http://www.mobile.att.net/messagecenter
    
            The bug was that doing a focus would always select the entire contents of the field.
            While this behavior does match Mozilla's behavior for text fields, it doesn't match
            WinIE; we're going to imitate WinIE and not do it. Also fix the same issue for text areas.
    
            * kwq/KWQTextField.h: Add lastSelectedRange field.
            * kwq/KWQTextField.mm:
            (-[KWQTextField initWithFrame:]): Initialize lastSelectedRange (to nothing).
            (-[KWQTextField initWithQLineEdit:]): Use [self init] instead of [super init]. The same
            thing, but you should never call [super xxx] where xxx is a non-designated initializer
            of the superclass.
            (-[KWQTextField currentEditorForEitherField]): Added. Returns the current editor of either
            the text field or the secure text field.
            (-[KWQTextField selectedRange]): Added.
            (-[KWQTextField setSelectedRange:]): Added.
            (-[KWQTextField controlTextDidEndEditing:]): Store the selected text range in the
            lastSelectedRange variable, so it can be used later. Also move the code that sends the
            FocusOut event here.
            (-[KWQTextField control:textShouldBeginEditing:]): Do the "scroll frame into view" here
            isntead of in becomeFirstResponder so it can be shared.
            (-[KWQTextField control:textShouldEndEditing:]): Moved FocusOut to controlTextDidEndEditing:.
            (-[KWQTextField didBecomeFirstResponder]): Added. Sets the selected range back to what it
            was in textShouldEndEditing, but only if we are not tabbing into the field. If we don't set
            the selected range, then we inherit the behavior from NSTextField, all text selected.
            We can't do the selected range work in textDidEndEditing because that's called too early.
            (-[KWQTextField becomeFirstResponder]): Call didBecomeFirstResponder.
            (-[KWQSecureTextField currentEditorForSecureField]): Added. Factored out of selectText:.
            (-[KWQSecureTextField selectText:]): Use currentEditorForSecureField for clarity.
            (-[KWQSecureTextField becomeFirstResponder]): Call didBecomeFirstResponder.
    
            * kwq/KWQTextArea.mm:
            (-[KWQTextArea _createTextView]): Rearrange a bit.
            (-[KWQTextArea setWordWrap:]): Ditto.
            (-[KWQTextAreaTextView becomeFirstResponder]): Only do the selectAll: operation here
            if we are tabbing into the field. Otherwise keep the selection from last time.
    
            * khtml/rendering/render_form.cpp: (RenderTextArea::updateFromElement): Don't do the
            whole "save cursor position, set text, restore cursor position" dance for the case
            where the field already has the correct contents. Without this change, selections can be
            collapsed to an insertion point at the start of the selection at seemingly random times.
    
            * khtml/khtmlview.cpp: (KHTMLView::dispatchMouseEvent): Don't deselect the currently
            focused node on mouse down. This created a symptom where a text field would lose
            focus when you clicked on a button.
    
            * kwq/KWQLineEdit.h: Remove unused frame() method.
            * kwq/KWQLineEdit.mm: Remove unused, unimplemented frame() method.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@4152 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog-2003-10-25 b/WebCore/ChangeLog-2003-10-25
index 7f46469..c337a6c 100644
--- a/WebCore/ChangeLog-2003-10-25
+++ b/WebCore/ChangeLog-2003-10-25
@@ -1,3 +1,56 @@
+2003-04-22  Darin Adler  <darin at apple.com>
+
+        Reviewed by John.
+
+	- fixed 3144966 -- problems typing in form at http://www.mobile.att.net/messagecenter
+
+        The bug was that doing a focus would always select the entire contents of the field.
+        While this behavior does match Mozilla's behavior for text fields, it doesn't match
+        WinIE; we're going to imitate WinIE and not do it. Also fix the same issue for text areas.
+
+        * kwq/KWQTextField.h: Add lastSelectedRange field.
+        * kwq/KWQTextField.mm:
+        (-[KWQTextField initWithFrame:]): Initialize lastSelectedRange (to nothing).
+        (-[KWQTextField initWithQLineEdit:]): Use [self init] instead of [super init]. The same
+        thing, but you should never call [super xxx] where xxx is a non-designated initializer
+        of the superclass.
+        (-[KWQTextField currentEditorForEitherField]): Added. Returns the current editor of either
+        the text field or the secure text field.
+        (-[KWQTextField selectedRange]): Added.
+        (-[KWQTextField setSelectedRange:]): Added.
+        (-[KWQTextField controlTextDidEndEditing:]): Store the selected text range in the
+        lastSelectedRange variable, so it can be used later. Also move the code that sends the
+        FocusOut event here.
+        (-[KWQTextField control:textShouldBeginEditing:]): Do the "scroll frame into view" here
+        isntead of in becomeFirstResponder so it can be shared.
+        (-[KWQTextField control:textShouldEndEditing:]): Moved FocusOut to controlTextDidEndEditing:.
+        (-[KWQTextField didBecomeFirstResponder]): Added. Sets the selected range back to what it
+        was in textShouldEndEditing, but only if we are not tabbing into the field. If we don't set
+        the selected range, then we inherit the behavior from NSTextField, all text selected.
+        We can't do the selected range work in textDidEndEditing because that's called too early.
+        (-[KWQTextField becomeFirstResponder]): Call didBecomeFirstResponder.
+        (-[KWQSecureTextField currentEditorForSecureField]): Added. Factored out of selectText:.
+        (-[KWQSecureTextField selectText:]): Use currentEditorForSecureField for clarity.
+        (-[KWQSecureTextField becomeFirstResponder]): Call didBecomeFirstResponder.
+
+        * kwq/KWQTextArea.mm:
+        (-[KWQTextArea _createTextView]): Rearrange a bit.
+        (-[KWQTextArea setWordWrap:]): Ditto.
+        (-[KWQTextAreaTextView becomeFirstResponder]): Only do the selectAll: operation here
+        if we are tabbing into the field. Otherwise keep the selection from last time.
+        
+        * khtml/rendering/render_form.cpp: (RenderTextArea::updateFromElement): Don't do the
+        whole "save cursor position, set text, restore cursor position" dance for the case
+        where the field already has the correct contents. Without this change, selections can be
+        collapsed to an insertion point at the start of the selection at seemingly random times.
+        
+        * khtml/khtmlview.cpp: (KHTMLView::dispatchMouseEvent): Don't deselect the currently
+        focused node on mouse down. This created a symptom where a text field would lose
+        focus when you clicked on a button.
+        
+        * kwq/KWQLineEdit.h: Remove unused frame() method.
+        * kwq/KWQLineEdit.mm: Remove unused, unimplemented frame() method.
+
 2003-04-21  Darin Adler  <darin at apple.com>
 
         Reviewed by Maciej.
diff --git a/WebCore/ChangeLog-2005-08-23 b/WebCore/ChangeLog-2005-08-23
index 7f46469..c337a6c 100644
--- a/WebCore/ChangeLog-2005-08-23
+++ b/WebCore/ChangeLog-2005-08-23
@@ -1,3 +1,56 @@
+2003-04-22  Darin Adler  <darin at apple.com>
+
+        Reviewed by John.
+
+	- fixed 3144966 -- problems typing in form at http://www.mobile.att.net/messagecenter
+
+        The bug was that doing a focus would always select the entire contents of the field.
+        While this behavior does match Mozilla's behavior for text fields, it doesn't match
+        WinIE; we're going to imitate WinIE and not do it. Also fix the same issue for text areas.
+
+        * kwq/KWQTextField.h: Add lastSelectedRange field.
+        * kwq/KWQTextField.mm:
+        (-[KWQTextField initWithFrame:]): Initialize lastSelectedRange (to nothing).
+        (-[KWQTextField initWithQLineEdit:]): Use [self init] instead of [super init]. The same
+        thing, but you should never call [super xxx] where xxx is a non-designated initializer
+        of the superclass.
+        (-[KWQTextField currentEditorForEitherField]): Added. Returns the current editor of either
+        the text field or the secure text field.
+        (-[KWQTextField selectedRange]): Added.
+        (-[KWQTextField setSelectedRange:]): Added.
+        (-[KWQTextField controlTextDidEndEditing:]): Store the selected text range in the
+        lastSelectedRange variable, so it can be used later. Also move the code that sends the
+        FocusOut event here.
+        (-[KWQTextField control:textShouldBeginEditing:]): Do the "scroll frame into view" here
+        isntead of in becomeFirstResponder so it can be shared.
+        (-[KWQTextField control:textShouldEndEditing:]): Moved FocusOut to controlTextDidEndEditing:.
+        (-[KWQTextField didBecomeFirstResponder]): Added. Sets the selected range back to what it
+        was in textShouldEndEditing, but only if we are not tabbing into the field. If we don't set
+        the selected range, then we inherit the behavior from NSTextField, all text selected.
+        We can't do the selected range work in textDidEndEditing because that's called too early.
+        (-[KWQTextField becomeFirstResponder]): Call didBecomeFirstResponder.
+        (-[KWQSecureTextField currentEditorForSecureField]): Added. Factored out of selectText:.
+        (-[KWQSecureTextField selectText:]): Use currentEditorForSecureField for clarity.
+        (-[KWQSecureTextField becomeFirstResponder]): Call didBecomeFirstResponder.
+
+        * kwq/KWQTextArea.mm:
+        (-[KWQTextArea _createTextView]): Rearrange a bit.
+        (-[KWQTextArea setWordWrap:]): Ditto.
+        (-[KWQTextAreaTextView becomeFirstResponder]): Only do the selectAll: operation here
+        if we are tabbing into the field. Otherwise keep the selection from last time.
+        
+        * khtml/rendering/render_form.cpp: (RenderTextArea::updateFromElement): Don't do the
+        whole "save cursor position, set text, restore cursor position" dance for the case
+        where the field already has the correct contents. Without this change, selections can be
+        collapsed to an insertion point at the start of the selection at seemingly random times.
+        
+        * khtml/khtmlview.cpp: (KHTMLView::dispatchMouseEvent): Don't deselect the currently
+        focused node on mouse down. This created a symptom where a text field would lose
+        focus when you clicked on a button.
+        
+        * kwq/KWQLineEdit.h: Remove unused frame() method.
+        * kwq/KWQLineEdit.mm: Remove unused, unimplemented frame() method.
+
 2003-04-21  Darin Adler  <darin at apple.com>
 
         Reviewed by Maciej.
diff --git a/WebCore/khtml/khtmlview.cpp b/WebCore/khtml/khtmlview.cpp
index f6618b0..3380851 100644
--- a/WebCore/khtml/khtmlview.cpp
+++ b/WebCore/khtml/khtmlview.cpp
@@ -1408,14 +1408,21 @@ bool KHTMLView::dispatchMouseEvent(int eventId, DOM::NodeImpl *targetNode, bool
             if (me->defaultHandled() || me->defaultPrevented())
                 swallowEvent = true;
 	    me->deref();
-    }
-    else if (eventId == EventImpl::MOUSEDOWN_EVENT) {
-        // Focus should be shifted on mouse down, not on a click.  -dwh
-        if (targetNode->isSelectable())
+        }
+        else if (eventId == EventImpl::MOUSEDOWN_EVENT) {
+            // Focus should be shifted on mouse down, not on a click.  -dwh
+            if (targetNode->isSelectable())
                 m_part->xmlDocImpl()->setFocusNode(targetNode);
+#if !APPLE_CHANGES
+            // In Safari we don't want to take the focus away from a text field
+            // when we click on, say, a form button. But I suspect this could be
+            // something specific to Macintosh, so I am leaving this code here inside
+            // !APPLE_CHANGES. This will probably change when we do more of the keyboard
+            // navigation work.
             else
                 m_part->xmlDocImpl()->setFocusNode(0);
-    }
+#endif
+        }
     }
 
     return swallowEvent;
diff --git a/WebCore/khtml/rendering/render_form.cpp b/WebCore/khtml/rendering/render_form.cpp
index efa578e..21ef6ce 100644
--- a/WebCore/khtml/rendering/render_form.cpp
+++ b/WebCore/khtml/rendering/render_form.cpp
@@ -1186,12 +1186,15 @@ void RenderTextArea::updateFromElement()
 {
     TextAreaWidget* w = static_cast<TextAreaWidget*>(m_widget);
     w->setReadOnly(element()->readOnly());
-    w->blockSignals(true);
-    int line, col;
-    w->getCursorPosition( &line, &col );
-    w->setText(element()->value().string());
-    w->setCursorPosition( line, col );
-    w->blockSignals(false);
+    QString text = element()->value().string();
+    if (w->text() != text) {
+        w->blockSignals(true);
+        int line, col;
+        w->getCursorPosition( &line, &col );
+        w->setText(text);
+        w->setCursorPosition( line, col );
+        w->blockSignals(false);
+    }
     element()->m_dirtyvalue = false;
 
     RenderFormElement::updateFromElement();
diff --git a/WebCore/kwq/KWQLineEdit.h b/WebCore/kwq/KWQLineEdit.h
index aee84ac..cf9cb37 100644
--- a/WebCore/kwq/KWQLineEdit.h
+++ b/WebCore/kwq/KWQLineEdit.h
@@ -26,10 +26,8 @@
 #ifndef QLINEEDIT_H_
 #define QLINEEDIT_H_
 
-#include "KWQWidget.h"
-#include "KWQEvent.h"
 #include "KWQString.h"
-#include "KWQSignal.h"
+#include "KWQWidget.h"
 
 class QLineEdit : public QWidget {
 public:
@@ -45,7 +43,6 @@ public:
 
     bool isReadOnly() const;
     void setReadOnly(bool);
-    bool frame() const;
     int cursorPosition() const;
     int maxLength() const;
     void selectAll();
diff --git a/WebCore/kwq/KWQLineEdit.mm b/WebCore/kwq/KWQLineEdit.mm
index deea636..1a62cda 100644
--- a/WebCore/kwq/KWQLineEdit.mm
+++ b/WebCore/kwq/KWQLineEdit.mm
@@ -99,12 +99,6 @@ void QLineEdit::setReadOnly(bool flag)
     return [textField setEditable:!flag];
 }
 
-bool QLineEdit::frame() const
-{
-    ERROR("not yet implemented");
-    return FALSE;
-}
-
 int QLineEdit::maxLength() const
 {
     KWQTextField *textField = (KWQTextField *)getView();
diff --git a/WebCore/kwq/KWQTextArea.mm b/WebCore/kwq/KWQTextArea.mm
index c7f3565..4e1870c 100644
--- a/WebCore/kwq/KWQTextArea.mm
+++ b/WebCore/kwq/KWQTextArea.mm
@@ -61,15 +61,11 @@ const float LargeNumberForText = 1.0e7;
 
 - (void)_createTextView
 {
-    NSDictionary *attr;
-    NSMutableParagraphStyle *style = [[[NSMutableParagraphStyle alloc] init] autorelease];
-    NSRect frame, textFrame;
-
-    frame = [self frame];
-    
+    NSSize size = [self frame].size;
+    NSRect textFrame;
     textFrame.origin.x = textFrame.origin.y = 0;
-    if (frame.size.width > 0 && frame.size.height > 0)
-        textFrame.size = [NSScrollView contentSizeForFrameSize:frame.size
+    if (size.width > 0 && size.height > 0)
+        textFrame.size = [NSScrollView contentSizeForFrameSize:size
             hasHorizontalScroller:NO hasVerticalScroller:YES borderType:[self borderType]];
     else {
         textFrame.size.width = LargeNumberForText;
@@ -77,15 +73,18 @@ const float LargeNumberForText = 1.0e7;
     }
         
     textView = [[KWQTextAreaTextView alloc] initWithFrame:textFrame];
-    [[textView textContainer] setWidthTracksTextView:YES];
     [textView setRichText:NO];
+    [[textView textContainer] setWidthTracksTextView:YES];
 
-    // Setup attributes for default cases WRAP=SOFT|VIRTUAL and WRAP=HARD|PHYSICAL.
+    // Set up attributes for default case, WRAP=SOFT|VIRTUAL or WRAP=HARD|PHYSICAL.
     // If WRAP=OFF we reset many of these attributes.
+
+    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
     [style setLineBreakMode:NSLineBreakByWordWrapping];
     [style setAlignment:NSLeftTextAlignment];
-    attr = [NSDictionary dictionaryWithObject:style forKey:NSParagraphStyleAttributeName];
-    [textView setTypingAttributes:attr];
+    [textView setTypingAttributes:[NSDictionary dictionaryWithObject:style forKey:NSParagraphStyleAttributeName]];
+    [style release];
+    
     [textView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
 
     [textView setDelegate:self];
@@ -133,15 +132,19 @@ const float LargeNumberForText = 1.0e7;
     if (f == wrap) {
         return;
     }
-        
+    
     // This widget may have issues toggling back and forth between WRAP=YES and WRAP=NO.
-    NSDictionary *attr;
-    NSMutableParagraphStyle *style = [[[NSMutableParagraphStyle alloc] init] autorelease];
+    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
     
     if (f) {
         [self setHasHorizontalScroller:NO];
-        [textView setHorizontallyResizable:NO];
+
         [[textView textContainer] setWidthTracksTextView:NO];
+
+        // FIXME: Same as else below. Is this right?
+        [textView setMaxSize:NSMakeSize(LargeNumberForText, LargeNumberForText)];
+        [textView setHorizontallyResizable:NO];
+
         [style setLineBreakMode:NSLineBreakByWordWrapping];
     } else {
         [self setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
@@ -160,10 +163,9 @@ const float LargeNumberForText = 1.0e7;
     }
     
     [style setAlignment:NSLeftTextAlignment];
-    attr = [NSDictionary dictionaryWithObject:style forKey:NSParagraphStyleAttributeName];
     
-    [textView setMaxSize:NSMakeSize(LargeNumberForText, LargeNumberForText)];
-    [textView setTypingAttributes:attr];
+    [textView setTypingAttributes:[NSDictionary dictionaryWithObject:style forKey:NSParagraphStyleAttributeName]];
+    [style release];
     
     wrap = f;
 }
@@ -445,7 +447,11 @@ static NSRange RangeOfParagraph(NSString *text, int paragraph)
     BOOL become = [super becomeFirstResponder];
 
     if (become) {
-	[self selectAll:nil];
+        // 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) {
+            [self selectAll:nil];
+        }
 	[self _KWQ_setKeyboardFocusRingNeedsDisplay];
 	QFocusEvent event(QEvent::FocusIn);
 	const_cast<QObject *>(widget->eventFilterObject())->eventFilter(widget, &event);
diff --git a/WebCore/kwq/KWQTextField.h b/WebCore/kwq/KWQTextField.h
index 1022174..ac3329e 100644
--- a/WebCore/kwq/KWQTextField.h
+++ b/WebCore/kwq/KWQTextField.h
@@ -37,6 +37,7 @@ class QLineEdit;
     KWQTextFieldFormatter *formatter;
     BOOL edited;
     BOOL inNextValidKeyView;
+    NSRange lastSelectedRange;
 }
 
 - initWithQLineEdit:(QLineEdit *)widget;
@@ -45,7 +46,7 @@ class QLineEdit;
 - (BOOL)passwordMode;
 - (void)setMaximumLength:(int)len;
 - (int)maximumLength;
-- (BOOL)edited;
 - (void)setEdited:(BOOL)edited;
+- (BOOL)edited;
 
 @end
diff --git a/WebCore/kwq/KWQTextField.mm b/WebCore/kwq/KWQTextField.mm
index c7e8ae8..b42667f 100644
--- a/WebCore/kwq/KWQTextField.mm
+++ b/WebCore/kwq/KWQTextField.mm
@@ -32,6 +32,10 @@
 #import "WebCoreFirstResponderChanges.h"
 #import "WebCoreBridge.h"
 
+ at interface KWQTextField (KWQInternal)
+- (void)didBecomeFirstResponder;
+ at end
+
 // KWQTextFieldFormatter enforces a maximum length.
 
 @interface KWQTextFieldFormatter : NSFormatter
@@ -80,13 +84,14 @@
     [super initWithFrame:frame];
     formatter = [[KWQTextFieldFormatter alloc] init];
     [self setUpTextField:self];
+    lastSelectedRange.location = NSNotFound;
     return self;
 }
 
 - initWithQLineEdit:(QLineEdit *)w 
 {
     widget = w;
-    return [super init];
+    return [self init];
 }
 
 - (void)action:sender
@@ -201,50 +206,80 @@
     edited = ed;
 }
 
-- (void)controlTextDidBeginEditing:(NSNotification *)obj
+- (NSText *)currentEditorForEitherField
+{
+    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;
+}
+
+- (NSRange)selectedRange
+{
+    NSText *editor = [self currentEditorForEitherField];
+    return editor ? [editor selectedRange] : NSMakeRange(NSNotFound, 0);
+}
+
+- (void)setSelectedRange:(NSRange)range
+{
+    // 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];    
+    if (NSMaxRange(range) <= [[editor string] length]) {
+        [editor setSelectedRange:range];
+    }
+}
+
+- (void)controlTextDidBeginEditing:(NSNotification *)notification
 {
     WebCoreBridge *bridge = KWQKHTMLPart::bridgeForWidget(widget);
-    [bridge controlTextDidBeginEditing:obj];
+    [bridge controlTextDidBeginEditing:notification];
 }
 
-- (void)controlTextDidEndEditing:(NSNotification *)obj
+- (void)controlTextDidEndEditing:(NSNotification *)notification
 {
+    lastSelectedRange = [self selectedRange];
+
+    QFocusEvent event(QEvent::FocusOut);
+    const_cast<QObject *>(widget->eventFilterObject())->eventFilter(widget, &event);
+
     WebCoreBridge *bridge = KWQKHTMLPart::bridgeForWidget(widget);
-    [bridge controlTextDidEndEditing:obj];
+    [bridge controlTextDidEndEditing:notification];
 }
 
-- (void)controlTextDidChange:(NSNotification *)obj
+- (void)controlTextDidChange:(NSNotification *)notification
 {
     WebCoreBridge *bridge = KWQKHTMLPart::bridgeForWidget(widget);
-    [bridge controlTextDidChange:obj];
-    edited = true;
+    [bridge controlTextDidChange:notification];
+    edited = YES;
     widget->textChanged();
 }
 
 - (BOOL)control:(NSControl *)control textShouldBeginEditing:(NSText *)fieldEditor
 {
     WebCoreBridge *bridge = KWQKHTMLPart::bridgeForWidget(widget);
-    BOOL should = [bridge control:control textShouldBeginEditing:fieldEditor];
-
-    if (should) {
-	QFocusEvent event(QEvent::FocusIn);
-	(const_cast<QObject *>(widget->eventFilterObject()))->eventFilter(widget, &event);
+    if (![bridge control:control textShouldBeginEditing:fieldEditor]) {
+        return NO;
     }
+    
+    [self _KWQ_scrollFrameToVisible];
+
+    QFocusEvent event(QEvent::FocusIn);
+    const_cast<QObject *>(widget->eventFilterObject())->eventFilter(widget, &event);
 
-    return should;
+    return YES;
 }
 
 - (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor
 {
     WebCoreBridge *bridge = KWQKHTMLPart::bridgeForWidget(widget);
-    BOOL should = [bridge control:control textShouldEndEditing:fieldEditor];
-
-    if (should) {
-	QFocusEvent event(QEvent::FocusOut);
-	(const_cast<QObject *>(widget->eventFilterObject()))->eventFilter(widget, &event);
-    }
-
-    return should;
+    return [bridge control:control textShouldEndEditing:fieldEditor];
 }
 
 - (BOOL)control:(NSControl *)control didFailToFormatString:(NSString *)string errorDescription:(NSString *)error
@@ -326,14 +361,31 @@
     return view;
 }
 
+- (void)didBecomeFirstResponder
+{
+    // Select all the text if we are tabbing in, but otherwise preserve/remember
+    // the selection from last time we had focus (to match WinIE).
+    // This has to be done after [super becomeFirstResponder] is done, which is why
+    // we can't just do this in textShouldBeginEditing.
+    if ([[self window] keyViewSelectionDirection] != NSDirectSelection) {
+        lastSelectedRange.location = NSNotFound;
+    }
+    if (lastSelectedRange.location != NSNotFound) {
+        [self setSelectedRange:lastSelectedRange];
+    }
+}
+
 - (BOOL)becomeFirstResponder
 {
     if ([self passwordMode]) {
         return [[self window] makeFirstResponder:secureField];
     }
     KWQKHTMLPart::setDocumentFocus(widget);
-    [self _KWQ_scrollFrameToVisible];
-    return [super becomeFirstResponder];
+    if (![super becomeFirstResponder]) {
+        return NO;
+    }
+    [self didBecomeFirstResponder];
+    return YES;
 }
 
 - (void)display
@@ -441,6 +493,20 @@
     return view;
 }
 
+// The currentEditor method does not work for secure text fields.
+// This works around that limitation.
+- (NSText *)currentEditorForSecureField
+{
+    NSResponder *firstResponder = [[self window] firstResponder];
+    if ([firstResponder isKindOfClass:[NSText class]]) {
+        NSText *editor = (NSText *)firstResponder;
+        if ([editor delegate] == self) {
+            return editor;
+        }
+    }
+    return nil;
+}
+
 // These next two methods are the workaround for bug 3024443.
 // Basically, setFrameSize ends up calling an inappropriate selectText, so we just ignore
 // calls to selectText while setFrameSize is running.
@@ -455,13 +521,10 @@
     // 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.
-    NSResponder *firstResponder = [[self window] firstResponder];
-    if ([firstResponder isKindOfClass:[NSTextView class]]) {
-        NSTextView *textView = (NSTextView *)firstResponder;
-        if ([textView delegate] == self) {
-            [textView setSelectedRange:NSMakeRange(0, [[textView string] length])];
-            return;
-        }
+    NSText *editor = [self currentEditorForSecureField];
+    if (editor) {
+        [editor setSelectedRange:NSMakeRange(0, [[editor string] length])];
+        return;
     }
 
     [super selectText:sender];
@@ -477,8 +540,11 @@
 - (BOOL)becomeFirstResponder
 {
     KWQKHTMLPart::setDocumentFocus(widget);
-    [self _KWQ_scrollFrameToVisible];
-    return [super becomeFirstResponder];
+    if (![super becomeFirstResponder]) {
+        return NO;
+    }
+    [(KWQTextField *)[self delegate] didBecomeFirstResponder];
+    return YES;
 }
 
 - (void)display

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list