[webkit-changes] cvs commit: WebCore/kwq KWQLineEdit.h
KWQLineEdit.mm KWQSlot.mm KWQTextArea.h KWQTextArea.mm
KWQTextEdit.h KWQTextEdit.mm KWQTextField.h KWQTextField.mm
Darin
darin at opensource.apple.com
Sun Jun 19 22:24:28 PDT 2005
darin 05/06/19 22:24:28
Modified: . ChangeLog
khtml/html html_formimpl.cpp
khtml/rendering render_form.cpp render_form.h
kwq KWQLineEdit.h KWQLineEdit.mm KWQSlot.mm
KWQTextArea.h KWQTextArea.mm KWQTextEdit.h
KWQTextEdit.mm KWQTextField.h KWQTextField.mm
Log:
Changes by Anders Carlsson and me.
Reviewed by Maciej and me.
Test cases added: None. Could not figure out how to automate a test without
making enhancements to DumpRenderTree.
- fixed <rdar://problem/4141141> Onselect event is ignored with TEXTAREA and INPUT
also <http://bugzilla.opendarwin.org/show_bug.cgi?id=3256>
* khtml/html/html_formimpl.cpp: (DOM::HTMLTextAreaElementImpl::select):
Remove unneeded explicit call to onSelect() here -- now handled by the renderer.
* khtml/rendering/render_form.h: Added declarations as needed below.
* khtml/rendering/render_form.cpp:
(RenderFormElement::slotSelectionChanged): Add base class implementation that does nothing.
(RenderLineEdit::RenderLineEdit): Connect the selection changed signal to our slot.
(RenderLineEdit::slotSelectionChanged): Call onSelect when selection changes to something
that's a selection (not a caret).
(RenderTextArea::RenderTextArea): Connect as above.
(RenderTextArea::slotSelectionChanged): Call as above.
* kwq/KWQLineEdit.h: Added declarations as needed below.
* kwq/KWQLineEdit.mm:
(QLineEdit::QLineEdit): Added selectionChanged signal.
(QLineEdit::hasSelectedText): Added.
* kwq/KWQSlot.mm:
(KWQSlot::KWQSlot): Make selectionChanged work on any form element.
(KWQSlot::call): ditto.
* kwq/KWQTextArea.h: Added hasSelection method.
* kwq/KWQTextArea.mm:
(-[KWQTextArea textViewDidChangeSelection:]): Added. Sends selectionChanged signal, except if
we're in the middle of gaining or losing first responder.
(-[KWQTextArea hasSelection]): Added.
(-[KWQTextAreaTextView becomeFirstResponder]): Added. Sets flag to tell us we're in a responder
change (using a count to avoid trouble if we reenter).
(-[KWQTextAreaTextView resignFirstResponder]): Ditto.
(-[KWQTextAreaTextView inResponderChange]): Added.
* kwq/KWQTextEdit.h: Added declarations as needed below.
* kwq/KWQTextEdit.mm:
(QTextEdit::QTextEdit): Added selectionChanged signal.
(QTextEdit::hasSelectedText): Added.
* kwq/KWQTextField.h: Added declarations as needed below.
* kwq/KWQTextField.mm:
(-[KWQTextFieldController initWithTextField:QLineEdit:]): Fixed up to do the right
thing with the result of the init function we call.
(-[KWQTextFieldController controlTextDidEndEditing:]): Removed call to setHasFocus:NO
since it's a little too late by the time the control is called; now handled by the
text view delegate methods below.
(-[KWQTextFieldController hasSelection]): Added.
(-[KWQTextFieldController setHasFocus:]): Sets the new hasFocusAndSelectionSet after
new focus and selection are both set up.
(-[KWQTextFieldController textViewDidChangeSelection:]): Added. Sends the selection
changed signal.
(-[KWQTextField initWithQLineEdit:]): Fixed up to do the right thing with the result
of the init function we call.
(-[KWQTextField textViewDidChangeSelection:]): Added. Calls super and then calls the
controller.
(-[KWQTextField textDidEndEditing:]): Added. Calls setHasFocus:NO and then calls super.
(-[KWQSecureTextField initWithQLineEdit:]): Same as above, but for secure text fields.
(-[KWQSecureTextField textViewDidChangeSelection:]): Ditto.
(-[KWQSecureTextField textDidEndEditing:]): Ditto.
(-[KWQSearchField initWithQLineEdit:]): Same as above, but for search fields.
(-[KWQSearchField textViewDidChangeSelection:]): Ditto.
(-[KWQSearchField textDidEndEditing:]): Ditto.
(-[KWQTextFieldFormatter init]): Fixed up to do the right thing with the result of
the init function we call.
Revision Changes Path
1.4285 +76 -1 WebCore/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /cvs/root/WebCore/ChangeLog,v
retrieving revision 1.4284
retrieving revision 1.4285
diff -u -r1.4284 -r1.4285
--- ChangeLog 19 Jun 2005 06:38:04 -0000 1.4284
+++ ChangeLog 20 Jun 2005 05:24:22 -0000 1.4285
@@ -1,3 +1,76 @@
+2005-06-19 Darin Adler <darin at apple.com>
+
+ Changes by Anders Carlsson and me.
+ Reviewed by Maciej and me.
+
+ Test cases added: None. Could not figure out how to automate a test without
+ making enhancements to DumpRenderTree.
+
+ - fixed <rdar://problem/4141141> Onselect event is ignored with TEXTAREA and INPUT
+ also <http://bugzilla.opendarwin.org/show_bug.cgi?id=3256>
+
+ * khtml/html/html_formimpl.cpp: (DOM::HTMLTextAreaElementImpl::select):
+ Remove unneeded explicit call to onSelect() here -- now handled by the renderer.
+
+ * khtml/rendering/render_form.h: Added declarations as needed below.
+ * khtml/rendering/render_form.cpp:
+ (RenderFormElement::slotSelectionChanged): Add base class implementation that does nothing.
+ (RenderLineEdit::RenderLineEdit): Connect the selection changed signal to our slot.
+ (RenderLineEdit::slotSelectionChanged): Call onSelect when selection changes to something
+ that's a selection (not a caret).
+ (RenderTextArea::RenderTextArea): Connect as above.
+ (RenderTextArea::slotSelectionChanged): Call as above.
+
+ * kwq/KWQLineEdit.h: Added declarations as needed below.
+ * kwq/KWQLineEdit.mm:
+ (QLineEdit::QLineEdit): Added selectionChanged signal.
+ (QLineEdit::hasSelectedText): Added.
+
+ * kwq/KWQSlot.mm:
+ (KWQSlot::KWQSlot): Make selectionChanged work on any form element.
+ (KWQSlot::call): ditto.
+
+ * kwq/KWQTextArea.h: Added hasSelection method.
+ * kwq/KWQTextArea.mm:
+ (-[KWQTextArea textViewDidChangeSelection:]): Added. Sends selectionChanged signal, except if
+ we're in the middle of gaining or losing first responder.
+ (-[KWQTextArea hasSelection]): Added.
+ (-[KWQTextAreaTextView becomeFirstResponder]): Added. Sets flag to tell us we're in a responder
+ change (using a count to avoid trouble if we reenter).
+ (-[KWQTextAreaTextView resignFirstResponder]): Ditto.
+ (-[KWQTextAreaTextView inResponderChange]): Added.
+
+ * kwq/KWQTextEdit.h: Added declarations as needed below.
+ * kwq/KWQTextEdit.mm:
+ (QTextEdit::QTextEdit): Added selectionChanged signal.
+ (QTextEdit::hasSelectedText): Added.
+
+ * kwq/KWQTextField.h: Added declarations as needed below.
+ * kwq/KWQTextField.mm:
+ (-[KWQTextFieldController initWithTextField:QLineEdit:]): Fixed up to do the right
+ thing with the result of the init function we call.
+ (-[KWQTextFieldController controlTextDidEndEditing:]): Removed call to setHasFocus:NO
+ since it's a little too late by the time the control is called; now handled by the
+ text view delegate methods below.
+ (-[KWQTextFieldController hasSelection]): Added.
+ (-[KWQTextFieldController setHasFocus:]): Sets the new hasFocusAndSelectionSet after
+ new focus and selection are both set up.
+ (-[KWQTextFieldController textViewDidChangeSelection:]): Added. Sends the selection
+ changed signal.
+ (-[KWQTextField initWithQLineEdit:]): Fixed up to do the right thing with the result
+ of the init function we call.
+ (-[KWQTextField textViewDidChangeSelection:]): Added. Calls super and then calls the
+ controller.
+ (-[KWQTextField textDidEndEditing:]): Added. Calls setHasFocus:NO and then calls super.
+ (-[KWQSecureTextField initWithQLineEdit:]): Same as above, but for secure text fields.
+ (-[KWQSecureTextField textViewDidChangeSelection:]): Ditto.
+ (-[KWQSecureTextField textDidEndEditing:]): Ditto.
+ (-[KWQSearchField initWithQLineEdit:]): Same as above, but for search fields.
+ (-[KWQSearchField textViewDidChangeSelection:]): Ditto.
+ (-[KWQSearchField textDidEndEditing:]): Ditto.
+ (-[KWQTextFieldFormatter init]): Fixed up to do the right thing with the result of
+ the init function we call.
+
2005-06-18 Darin Adler <darin at apple.com>
Changes by Anders Carlsson.
@@ -168,7 +241,9 @@
2005-06-17 Justin Garcia <justin.garcia at apple.com>
Fix for rdar://3756860, (also listed as) http://bugzilla.opendarwin.org/show_bug.cgi?id=3295
- The cellIndex property for HTMLTableCellElement was always zero because the method to support it was just a stub. KHTML fix was to simply call nodeIndex(), but this is incorrect because a table row can have as children <script>s and <form>s (and perhaps others).
+ The cellIndex property for HTMLTableCellElement was always zero because the method to support it was just a stub.
+ KHTML fix was to simply call nodeIndex(), but this is incorrect because a table row can have as children <script>s
+ and <form>s (and perhaps others).
Reviewed by hyatt and john
1.166 +0 -1 WebCore/khtml/html/html_formimpl.cpp
Index: html_formimpl.cpp
===================================================================
RCS file: /cvs/root/WebCore/khtml/html/html_formimpl.cpp,v
retrieving revision 1.165
retrieving revision 1.166
diff -u -r1.165 -r1.166
--- html_formimpl.cpp 19 Jun 2005 06:03:41 -0000 1.165
+++ html_formimpl.cpp 20 Jun 2005 05:24:25 -0000 1.166
@@ -3355,7 +3355,6 @@
{
if (m_render)
static_cast<RenderTextArea*>(m_render)->select();
- onSelect();
}
void HTMLTextAreaElementImpl::childrenChanged()
1.107 +29 -0 WebCore/khtml/rendering/render_form.cpp
Index: render_form.cpp
===================================================================
RCS file: /cvs/root/WebCore/khtml/rendering/render_form.cpp,v
retrieving revision 1.106
retrieving revision 1.107
diff -u -r1.106 -r1.107
--- render_form.cpp 17 Jun 2005 23:02:48 -0000 1.106
+++ render_form.cpp 20 Jun 2005 05:24:26 -0000 1.107
@@ -256,6 +256,11 @@
// do nothing
}
+void RenderFormElement::slotSelectionChanged()
+{
+ // do nothing
+}
+
#endif
// -------------------------------------------------------------------------
@@ -538,6 +543,7 @@
LineEditWidget *edit = new LineEditWidget(view()->viewport());
#endif
connect(edit,SIGNAL(returnPressed()), this, SLOT(slotReturnPressed()));
+ connect(edit, SIGNAL(selectionChanged()), this, SLOT(slotSelectionChanged()));
connect(edit,SIGNAL(textChanged(const QString &)),this,SLOT(slotTextChanged(const QString &)));
connect(edit,SIGNAL(clicked()),this,SLOT(slotClicked()));
@@ -561,6 +567,17 @@
setQWidget(edit);
}
+void RenderLineEdit::slotSelectionChanged()
+{
+ QLineEdit* w = static_cast<QLineEdit*>(m_widget);
+
+ // We only want to call onselect if there actually is a selection
+ if (!w->hasSelectedText())
+ return;
+
+ element()->onSelect();
+}
+
void RenderLineEdit::slotReturnPressed()
{
#if !APPLE_CHANGES
@@ -1476,6 +1493,7 @@
connect(edit,SIGNAL(textChanged()),this,SLOT(slotTextChanged()));
connect(edit,SIGNAL(clicked()),this,SLOT(slotClicked()));
+ connect(edit,SIGNAL(selectionChanged()),this,SLOT(slotSelectionChanged()));
}
void RenderTextArea::detach()
@@ -1628,6 +1646,17 @@
static_cast<QTextEdit *>(m_widget)->selectAll();
}
+void RenderTextArea::slotSelectionChanged()
+{
+ QTextEdit* w = static_cast<QTextEdit*>(m_widget);
+
+ // We only want to call onselect if there actually is a selection
+ if (!w->hasSelectedText())
+ return;
+
+ element()->onSelect();
+}
+
// ---------------------------------------------------------------------------
#if APPLE_CHANGES
1.51 +5 -2 WebCore/khtml/rendering/render_form.h
Index: render_form.h
===================================================================
RCS file: /cvs/root/WebCore/khtml/rendering/render_form.h,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -r1.50 -r1.51
--- render_form.h 18 May 2005 21:10:24 -0000 1.50
+++ render_form.h 20 Jun 2005 05:24:26 -0000 1.51
@@ -104,7 +104,8 @@
public slots:
virtual void slotClicked();
-
+ virtual void slotSelectionChanged();
+
#if APPLE_CHANGES
// Hack to make KWQSlot code work.
virtual void slotTextChanged(const QString &string);
@@ -256,6 +257,7 @@
public slots:
void slotReturnPressed();
void slotTextChanged(const QString &string);
+ void slotSelectionChanged();
#if APPLE_CHANGES
void slotPerformSearch();
public:
@@ -475,7 +477,8 @@
protected slots:
void slotTextChanged();
-
+ void slotSelectionChanged();
+
protected:
virtual void handleFocusOut();
1.32 +5 -1 WebCore/kwq/KWQLineEdit.h
Index: KWQLineEdit.h
===================================================================
RCS file: /cvs/root/WebCore/kwq/KWQLineEdit.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- KWQLineEdit.h 20 Oct 2004 19:01:16 -0000 1.31
+++ KWQLineEdit.h 20 Jun 2005 05:24:26 -0000 1.32
@@ -66,6 +66,7 @@
void setWritingDirection(QPainter::TextDirection);
void selectAll();
+ bool hasSelectedText() const;
QSize sizeForCharacterWidth(int numCharacters) const;
int baselinePosition(int height) const;
@@ -73,7 +74,8 @@
void returnPressed() { m_returnPressed.call(); }
void textChanged() { m_textChanged.call(text()); }
void performSearch() { m_performSearch.call(); }
-
+ void selectionChanged() { m_selectionChanged.call(); }
+
void clicked();
virtual FocusPolicy focusPolicy() const;
@@ -92,6 +94,8 @@
KWQSignal m_textChanged;
KWQSignal m_clicked;
KWQSignal m_performSearch;
+ KWQSignal m_selectionChanged;
+
Type m_type;
KWQTextFieldController *m_controller;
};
1.66 +6 -0 WebCore/kwq/KWQLineEdit.mm
Index: KWQLineEdit.mm
===================================================================
RCS file: /cvs/root/WebCore/kwq/KWQLineEdit.mm,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -r1.65 -r1.66
--- KWQLineEdit.mm 28 Jan 2005 01:16:20 -0000 1.65
+++ KWQLineEdit.mm 20 Jun 2005 05:24:26 -0000 1.66
@@ -44,6 +44,7 @@
, m_textChanged(this, SIGNAL(textChanged(const QString &)))
, m_clicked(this, SIGNAL(clicked()))
, m_performSearch(this, SIGNAL(performSearch()))
+ , m_selectionChanged(this, SIGNAL(selectionChanged()))
, m_type(type)
{
KWQ_BLOCK_EXCEPTIONS;
@@ -185,6 +186,11 @@
}
}
+bool QLineEdit::hasSelectedText() const
+{
+ return [m_controller hasSelection];
+}
+
bool QLineEdit::edited() const
{
return [m_controller edited];
1.29 +2 -2 WebCore/kwq/KWQSlot.mm
Index: KWQSlot.mm
===================================================================
RCS file: /cvs/root/WebCore/kwq/KWQSlot.mm,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- KWQSlot.mm 18 May 2005 21:10:26 -0000 1.28
+++ KWQSlot.mm 20 Jun 2005 05:24:26 -0000 1.29
@@ -104,7 +104,7 @@
CASE(slotRedirect, (), KHTMLPart)
CASE(slotReturnPressed, (), RenderLineEdit)
CASE(slotSelected, (int), RenderSelect)
- CASE(slotSelectionChanged, (), RenderSelect)
+ CASE(slotSelectionChanged, (), RenderFormElement)
CASE(slotSliderValueChanged, (), RenderSlider)
CASE(slotStateChanged, (int), RenderCheckBox)
CASE(slotTextChanged, (), RenderTextArea)
@@ -175,7 +175,7 @@
CASE(slotPerformSearch, RenderLineEdit, slotPerformSearch)
CASE(slotRedirect, KHTMLPart, slotRedirect)
CASE(slotReturnPressed, RenderLineEdit, slotReturnPressed)
- CASE(slotSelectionChanged, RenderSelect, slotSelectionChanged)
+ CASE(slotSelectionChanged, RenderFormElement, slotSelectionChanged)
CASE(slotSliderValueChanged, RenderSlider, slotSliderValueChanged)
CASE(slotSubmitFormAgain, KHTMLPart, submitFormAgain)
CASE(slotTextChanged, RenderTextArea, slotTextChanged)
1.21 +1 -0 WebCore/kwq/KWQTextArea.h
Index: KWQTextArea.h
===================================================================
RCS file: /cvs/root/WebCore/kwq/KWQTextArea.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- KWQTextArea.h 24 May 2005 23:49:24 -0000 1.20
+++ KWQTextArea.h 20 Jun 2005 05:24:26 -0000 1.21
@@ -67,6 +67,7 @@
- (BOOL)wordWrap;
- (void)selectAll;
+- (BOOL)hasSelection;
- (NSSize)sizeWithColumns:(int)columns rows:(int)rows;
1.82 +32 -2 WebCore/kwq/KWQTextArea.mm
Index: KWQTextArea.mm
===================================================================
RCS file: /cvs/root/WebCore/kwq/KWQTextArea.mm,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -r1.81 -r1.82
--- KWQTextArea.mm 31 May 2005 03:08:35 -0000 1.81
+++ KWQTextArea.mm 20 Jun 2005 05:24:27 -0000 1.82
@@ -86,6 +86,7 @@
BOOL disabled;
BOOL editableIfEnabled;
BOOL inCut;
+ int inResponderChange;
}
- (void)setWidget:(QTextEdit *)widget;
@@ -98,6 +99,8 @@
- (void)updateTextColor;
+- (BOOL)inResponderChange;
+
@end
@implementation KWQTextArea
@@ -199,6 +202,12 @@
[super dealloc];
}
+- (void)textViewDidChangeSelection:(NSNotification *)notification
+{
+ if (widget && ![textView inResponderChange])
+ widget->selectionChanged();
+}
+
- (void)textDidChange:(NSNotification *)notification
{
if (widget)
@@ -279,6 +288,11 @@
[textView selectAll:nil];
}
+- (BOOL)hasSelection
+{
+ return [textView selectedRange].length > 0;
+}
+
- (void)setEditable:(BOOL)flag
{
[textView setEditableIfEnabled:flag];
@@ -813,6 +827,8 @@
if (disabled)
return NO;
+ ++inResponderChange;
+
BOOL become = [super becomeFirstResponder];
if (become) {
@@ -821,11 +837,15 @@
if ([[self window] keyViewSelectionDirection] != NSDirectSelection) {
[self selectAll:nil];
}
+ }
+
+ --inResponderChange;
+
+ if (become) {
if (!KWQKHTMLPart::currentEventIsMouseDownInWidget(widget)) {
[[self enclosingScrollView] _KWQ_scrollFrameToVisible];
}
[self _KWQ_setKeyboardFocusRingNeedsDisplay];
-
if (widget) {
QFocusEvent event(QEvent::FocusIn);
const_cast<QObject *>(widget->eventFilterObject())->eventFilter(widget, &event);
@@ -837,8 +857,12 @@
- (BOOL)resignFirstResponder
{
+ ++inResponderChange;
+
BOOL resign = [super resignFirstResponder];
+ --inResponderChange;
+
if (resign) {
[self _KWQ_setKeyboardFocusRingNeedsDisplay];
@@ -906,7 +930,8 @@
return NSMakeRect(NSMaxX(visibleRect) - imageSize.width - 1, NSMaxY(visibleRect) - imageSize.height - 1, imageSize.width + 1, imageSize.height + 1);
}
-- (void)resetCursorRects {
+- (void)resetCursorRects
+{
[super resetCursorRects];
// FIXME Radar 4118575: This is intended to change the cursor to the arrow cursor whenever it is
@@ -1092,6 +1117,11 @@
[self dispatchHTMLEvent:EventImpl::PASTE_EVENT];
}
+- (BOOL)inResponderChange
+{
+ return inResponderChange != 0;
+}
+
@end
@implementation NSView (KWQTextArea)
1.24 +4 -0 WebCore/kwq/KWQTextEdit.h
Index: KWQTextEdit.h
===================================================================
RCS file: /cvs/root/WebCore/kwq/KWQTextEdit.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- KWQTextEdit.h 10 Dec 2004 22:15:59 -0000 1.23
+++ KWQTextEdit.h 20 Jun 2005 05:24:27 -0000 1.24
@@ -60,6 +60,8 @@
void setDisabled(bool);
bool isDisabled() const;
+ bool hasSelectedText() const;
+
void setText(const QString &);
QString text() const;
QString textWithHardLineBreaks() const;
@@ -79,6 +81,7 @@
void textChanged() { _textChanged.call(); }
+ void selectionChanged() { _selectionChanged.call(); }
void clicked();
virtual FocusPolicy focusPolicy() const;
@@ -87,6 +90,7 @@
private:
KWQSignal _clicked;
KWQSignal _textChanged;
+ KWQSignal _selectionChanged;
};
#endif /* QTEXTEDIT_H_ */
1.45 +12 -0 WebCore/kwq/KWQTextEdit.mm
Index: KWQTextEdit.mm
===================================================================
RCS file: /cvs/root/WebCore/kwq/KWQTextEdit.mm,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- KWQTextEdit.mm 21 Feb 2005 21:55:42 -0000 1.44
+++ KWQTextEdit.mm 20 Jun 2005 05:24:27 -0000 1.45
@@ -33,6 +33,7 @@
QTextEdit::QTextEdit(QWidget *parent)
: _clicked(this, SIGNAL(clicked()))
, _textChanged(this, SIGNAL(textChanged()))
+ , _selectionChanged(this, SIGNAL(selectionChanged()))
{
KWQ_BLOCK_EXCEPTIONS;
KWQTextArea *textView = [[KWQTextArea alloc] initWithQTextEdit:this];
@@ -185,6 +186,17 @@
KWQ_UNBLOCK_EXCEPTIONS;
}
+bool QTextEdit::hasSelectedText() const
+{
+ KWQTextArea *textView = (KWQTextArea *)getView();
+
+ KWQ_BLOCK_EXCEPTIONS;
+ return [textView hasSelection];
+ KWQ_UNBLOCK_EXCEPTIONS;
+
+ return false;
+}
+
void QTextEdit::selectAll()
{
KWQTextArea *textView = (KWQTextArea *)getView();
1.21 +2 -1 WebCore/kwq/KWQTextField.h
Index: KWQTextField.h
===================================================================
RCS file: /cvs/root/WebCore/kwq/KWQTextField.h,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- KWQTextField.h 24 Jan 2005 20:48:25 -0000 1.20
+++ KWQTextField.h 20 Jun 2005 05:24:27 -0000 1.21
@@ -36,6 +36,7 @@
QLineEdit *widget;
KWQTextFieldFormatter *formatter;
BOOL hasFocus;
+ BOOL hasFocusAndSelectionSet;
BOOL edited;
NSRange lastSelectedRange;
BOOL inDrawingMachinery;
@@ -44,7 +45,7 @@
- (void)detachQLineEdit;
-- (void)setHasFocus:(BOOL)hasFocus;
+- (BOOL)hasSelection;
- (void)setMaximumLength:(int)len;
- (int)maximumLength;
1.78 +63 -8 WebCore/kwq/KWQTextField.mm
Index: KWQTextField.mm
===================================================================
RCS file: /cvs/root/WebCore/kwq/KWQTextField.mm,v
retrieving revision 1.77
retrieving revision 1.78
diff -u -r1.77 -r1.78
--- KWQTextField.mm 3 Mar 2005 00:58:35 -0000 1.77
+++ KWQTextField.mm 20 Jun 2005 05:24:27 -0000 1.78
@@ -72,15 +72,19 @@
- (BOOL)textView:(NSTextView *)view shouldHandleEvent:(NSEvent *)event;
- (void)textView:(NSTextView *)view didHandleEvent:(NSEvent *)event;
- (BOOL)textView:(NSTextView *)view shouldChangeTextInRange:(NSRange)range replacementString:(NSString *)string;
+- (void)textViewDidChangeSelection:(NSNotification *)notification;
- (void)updateTextAttributes:(NSMutableDictionary *)attributes;
- (NSString *)preprocessString:(NSString *)string;
+- (void)setHasFocus:(BOOL)hasFocus;
@end
@implementation KWQTextFieldController
- (id)initWithTextField:(NSTextField *)f QLineEdit:(QLineEdit *)w
{
- [self init];
+ self = [self init];
+ if (!self)
+ return nil;
// This is initialization that's shared by all types of text fields.
widget = w;
@@ -166,8 +170,6 @@
WebCoreBridge *bridge = KWQKHTMLPart::bridgeForWidget(widget);
[bridge controlTextDidEndEditing:notification];
- [self setHasFocus:NO];
-
if (widget && [[[notification userInfo] objectForKey:@"NSTextMovement"] intValue] == NSReturnTextMovement)
widget->returnPressed();
}
@@ -369,12 +371,18 @@
}
}
+- (BOOL)hasSelection
+{
+ return [self selectedRange].length > 0;
+}
+
- (void)setHasFocus:(BOOL)nowHasFocus
{
if (!widget || nowHasFocus == hasFocus)
return;
hasFocus = nowHasFocus;
+ hasFocusAndSelectionSet = NO;
if (nowHasFocus) {
// Select all the text if we are tabbing in, but otherwise preserve/remember
@@ -385,6 +393,8 @@
if (lastSelectedRange.location != NSNotFound)
[self setSelectedRange:lastSelectedRange];
+ hasFocusAndSelectionSet = YES;
+
if (!KWQKHTMLPart::currentEventIsMouseDownInWidget(widget))
[field _KWQ_scrollFrameToVisible];
@@ -434,7 +444,7 @@
// with the side effect of ending International inline input for these
// password fields on Panther only, since it's fixed in Tiger.
if ([field isKindOfClass:[NSSecureTextField class]]) {
- return [field stringValue];
+ return [field stringValue];
}
#endif
// Calling stringValue can have a side effect of ending International inline input.
@@ -469,6 +479,12 @@
return [result _KWQ_truncateToNumComposedCharacterSequences:[formatter maximumLength]];
}
+- (void)textViewDidChangeSelection:(NSNotification *)notification
+{
+ if (widget && hasFocusAndSelectionSet)
+ widget->selectionChanged();
+}
+
@end
@implementation KWQTextField
@@ -480,7 +496,9 @@
- (id)initWithQLineEdit:(QLineEdit *)w
{
- [self init];
+ self = [self init];
+ if (!self)
+ return nil;
controller = [[KWQTextFieldController alloc] initWithTextField:self QLineEdit:w];
return self;
}
@@ -601,6 +619,18 @@
&& [super textView:view shouldChangeTextInRange:range replacementString:string];
}
+- (void)textViewDidChangeSelection:(NSNotification *)notification
+{
+ [super textViewDidChangeSelection:notification];
+ [controller textViewDidChangeSelection:notification];
+}
+
+- (void)textDidEndEditing:(NSNotification *)notification
+{
+ [controller setHasFocus:NO];
+ [super textDidEndEditing:notification];
+}
+
@end
@implementation KWQTextFieldCell
@@ -646,7 +676,9 @@
- (id)initWithQLineEdit:(QLineEdit *)w
{
- [self init];
+ self = [self init];
+ if (!self)
+ return nil;
controller = [[KWQTextFieldController alloc] initWithTextField:self QLineEdit:w];
return self;
}
@@ -753,6 +785,12 @@
&& [super textView:view shouldChangeTextInRange:range replacementString:string];
}
+- (void)textViewDidChangeSelection:(NSNotification *)notification
+{
+ [super textViewDidChangeSelection:notification];
+ [controller textViewDidChangeSelection:notification];
+}
+
// 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.
@@ -785,6 +823,7 @@
- (void)textDidEndEditing:(NSNotification *)notification
{
+ [controller setHasFocus:NO];
[super textDidEndEditing:notification];
// When tabbing from one secure text field to another, the super
@@ -851,7 +890,9 @@
- (id)initWithQLineEdit:(QLineEdit *)w
{
- [self init];
+ self = [self init];
+ if (!self)
+ return nil;
controller = [[KWQTextFieldController alloc] initWithTextField:self QLineEdit:w];
return self;
}
@@ -972,6 +1013,18 @@
&& [super textView:view shouldChangeTextInRange:range replacementString:string];
}
+- (void)textViewDidChangeSelection:(NSNotification *)notification
+{
+ [super textViewDidChangeSelection:notification];
+ [controller textViewDidChangeSelection:notification];
+}
+
+- (void)textDidEndEditing:(NSNotification *)notification
+{
+ [controller setHasFocus:NO];
+ [super textDidEndEditing:notification];
+}
+
@end
@implementation KWQSearchFieldCell
@@ -1011,7 +1064,9 @@
- init
{
- [super init];
+ self = [super init];
+ if (!self)
+ return nil;
maxLength = INT_MAX;
return self;
}
More information about the webkit-changes
mailing list