Changeset 14931 in webkit
- Timestamp:
- Jun 20, 2006, 5:10:31 PM (19 years ago)
- Location:
- trunk
- Files:
-
- 8 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r14924 r14931 1 2006-06-20 Adele Peterson <adele@apple.com> 2 3 Reviewed by Maciej. 4 5 Tests for: 6 http://bugzilla.opendarwin.org/show_bug.cgi?id=8724 7 REGRESSION: onSelect handler doesn't work for text fields 8 9 http://bugzilla.opendarwin.org/show_bug.cgi?id=7676 10 REGRESSION: Selection methods on new text fields don't work if text field is hidden 11 12 http://bugzilla.opendarwin.org/show_bug.cgi?id=8867 13 REGRESSION: selectionStart/End return 0 for input element once it no longer has focus 14 15 * fast/forms/double-focus-expected.txt: 16 * fast/forms/input-selection-hidden-expected.txt: Added. 17 * fast/forms/input-selection-hidden.html: Added. 18 * fast/forms/input-selection-restore-expected.txt: Added. 19 * fast/forms/input-selection-restore.html: Added. 20 * fast/forms/input-text-paste-maxlength-expected.txt: 21 * fast/forms/onselect-textarea-expected.txt: Added. 22 * fast/forms/onselect-textarea.html: Added. 23 * fast/forms/onselect-textfield-expected.txt: Added. 24 * fast/forms/onselect-textfield.html: Added. 25 * fast/forms/selection-functions-expected.txt: 26 1 27 2006-06-20 Anders Carlsson <acarlsson@apple.com> 2 28 -
trunk/LayoutTests/fast/forms/double-focus-expected.txt
r14301 r14931 1 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 1 2 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 2 3 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification -
trunk/LayoutTests/fast/forms/input-text-paste-maxlength-expected.txt
r14684 r14931 4 4 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification 5 5 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 6 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 7 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 6 8 EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV to 0 of DIV toDOMRange:range from 5 of #text > DIV to 5 of #text > DIV affinity:NSSelectionAffinityDownstream stillSelecting:FALSE 7 9 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 8 10 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification 9 11 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 10 EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV to 0 of DIV toDOMRange:range from 3 of #text > DIV to 3 of #text > DIV affinity:NSSelectionAffinityDownstream stillSelecting:FALSE 11 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 12 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification 12 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 13 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 14 EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV to 0 of DIV toDOMRange:range from 3 of #text > DIV to 3 of #text > DIV affinity:NSSelectionAffinityDownstream stillSelecting:FALSE 15 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 16 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification 17 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 18 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 13 19 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 14 20 EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV to 0 of DIV toDOMRange:range from 3 of #text > DIV to 3 of #text > DIV affinity:NSSelectionAffinityDownstream stillSelecting:FALSE … … 21 27 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification 22 28 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 29 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 30 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 23 31 EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV to 0 of DIV toDOMRange:range from 7 of #text > DIV to 7 of #text > DIV affinity:NSSelectionAffinityDownstream stillSelecting:FALSE 24 32 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 25 33 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification 26 34 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 27 EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV to 0 of DIV toDOMRange:range from 3 of #text > DIV to 3 of #text > DIV affinity:NSSelectionAffinityDownstream stillSelecting:FALSE 28 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 29 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification 35 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 36 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 37 EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV to 0 of DIV toDOMRange:range from 3 of #text > DIV to 3 of #text > DIV affinity:NSSelectionAffinityDownstream stillSelecting:FALSE 38 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 39 EDITING DELEGATE: webViewDidChange:WebViewDidChangeNotification 40 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 41 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 30 42 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 31 43 EDITING DELEGATE: shouldChangeSelectedDOMRange:range from 0 of DIV to 0 of DIV toDOMRange:range from 3 of #text > DIV to 3 of #text > DIV affinity:NSSelectionAffinityDownstream stillSelecting:FALSE -
trunk/LayoutTests/fast/forms/selection-functions-expected.txt
r13567 r14931 1 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 1 2 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification 2 3 EDITING DELEGATE: webViewDidChangeSelection:WebViewDidChangeSelectionNotification -
trunk/WebCore/ChangeLog
r14930 r14931 1 2006-06-20 Adele Peterson <adele@apple.com> 2 3 Reviewed by Maciej. 4 5 Fixes for: 6 http://bugzilla.opendarwin.org/show_bug.cgi?id=8724 7 REGRESSION: onSelect handler doesn't work for text fields 8 9 http://bugzilla.opendarwin.org/show_bug.cgi?id=7676 10 REGRESSION: Selection methods on new text fields don't work if text field is hidden 11 12 http://bugzilla.opendarwin.org/show_bug.cgi?id=8867 13 REGRESSION: selectionStart/End return 0 for input element once it no longer has focus 14 15 Implemented onSelect for new text fields and textareas. Also fixed selection restore 16 behavior to better match other browsers and Safari 2.0 behavior. 17 18 Tests: 19 * fast/forms/input-selection-restore.html 20 * fast/forms/input-selection-hidden.html 21 * fast/forms/onselect-textarea.html 22 * fast/forms/onselect-textfield.html 23 24 * html/HTMLInputElement.h: (WebCore::HTMLInputElement::cacheSelection): Added. 25 * html/HTMLInputElement.cpp: 26 (WebCore::HTMLInputElement::init): Initializes cached selection. 27 (WebCore::HTMLInputElement::selectionStart): If this element doesn't have focus, return the cached selection value. 28 (WebCore::HTMLInputElement::selectionEnd): ditto. 29 (WebCore::HTMLInputElement::setValue): Restore a caret at the starting point of the old selection. Matches Safari 2.0 behavior. 30 31 * html/HTMLTextAreaElement.h: (WebCore::HTMLTextAreaElement::cacheSelection): Added. 32 * html/HTMLTextAreaElement.cpp: 33 (WebCore::HTMLTextAreaElement::HTMLTextAreaElement): Initializes cached selection. 34 (WebCore::HTMLTextAreaElement::selectionStart): If this element doesn't have focus, return the cached selection value. 35 (WebCore::HTMLTextAreaElement::selectionEnd): ditto. 36 (WebCore::HTMLTextAreaElement::focus): If this is the first focus, set a caret at the end of the text. Otherwise, 37 restore the cached selection. This matches other browsers' behavior. 38 (WebCore::HTMLTextAreaElement::setValue): Restore a caret at the starting point of the old selection. Matches Safari 2.0 behavior. 39 40 * page/Frame.h: Added notifyRendererOfSelectionChange method. 41 * page/Frame.cpp: 42 (WebCore::Frame::notifyRendererOfSelectionChange): Added. Calls selectionChanged for text fields and textareas. Forwards a userTriggered 43 argument so selectionChanged knows whether or not to fire onSelect. 44 (WebCore::Frame::setSelection): Calls notifyRendererOfSelectionChange(false). This gets called for all selection changes, so the renderer 45 can always update its cached selection values. 46 (WebCore::Frame::handleMouseReleaseEvent): Calls notifyRendererOfSelectionChange(true) so onSelect will get fired when the user is done 47 making a selection with the mouse. 48 * bridge/mac/WebCoreFrameBridge.mm: 49 (-[WebCoreFrameBridge alterCurrentSelection:direction:granularity:]): Calls notifyRendererOfSelectionChange(true) so onSelect gets 50 fired when the user makes a selection with the keyboard. 51 (-[WebCoreFrameBridge alterCurrentSelection:verticalDistance:]): ditto. 52 53 * rendering/RenderTextField.h: Add userTriggered parameter to selectionChanged. 54 * rendering/RenderTextField.cpp: 55 (WebCore::RenderTextField::setSelectionRange): For visibility:hidden, cache the selection and 56 return early since we won't be able to actually set the selection. 57 (WebCore::RenderTextField::selectionChanged): Caches the selection. 58 If the selection is a range, and its triggered by user action, then fire the onSelect event. 59 1 60 2006-06-21 Anders Carlsson <acarlsson@apple.com> 2 61 -
trunk/WebCore/bridge/mac/WebCoreFrameBridge.mm
r14834 r14931 1647 1647 1648 1648 m_frame->selectFrameElementInParentIfFullySelected(); 1649 1650 m_frame->notifyRendererOfSelectionChange(true); 1649 1651 1650 1652 [self ensureSelectionVisible]; … … 1676 1678 1677 1679 m_frame->selectFrameElementInParentIfFullySelected(); 1680 1681 m_frame->notifyRendererOfSelectionChange(true); 1678 1682 1679 1683 [self ensureSelectionVisible]; -
trunk/WebCore/html/HTMLInputElement.cpp
r14916 r14931 112 112 xPos = 0; 113 113 yPos = 0; 114 115 cachedSelStart = -1; 116 cachedSelEnd = -1; 114 117 115 118 m_maxResults = -1; … … 444 447 return static_cast<RenderLineEdit*>(renderer())->selectionStart(); 445 448 case TEXT: 449 if (document()->focusNode() != this && cachedSelStart >= 0) 450 return cachedSelStart; 446 451 return static_cast<RenderTextField*>(renderer())->selectionStart(); 447 452 } … … 470 475 return static_cast<RenderLineEdit*>(renderer())->selectionEnd(); 471 476 case TEXT: 477 if (document()->focusNode() != this && cachedSelEnd >= 0) 478 return cachedSelEnd; 472 479 return static_cast<RenderTextField*>(renderer())->selectionEnd(); 473 480 } … … 1064 1071 } else 1065 1072 setAttribute(valueAttr, constrainValue(value)); 1073 1074 // Restore a caret at the starting point of the old selection. 1075 // This matches Safari 2.0 behavior. 1076 if (isNonWidgetTextField() && document()->focusNode() == this && cachedSelStart >= 0) { 1077 ASSERT(cachedSelEnd >= 0); 1078 setSelectionRange(cachedSelStart, cachedSelStart); 1079 } 1066 1080 } 1067 1081 -
trunk/WebCore/html/HTMLInputElement.h
r14451 r14931 176 176 bool autofilled() const { return m_autofilled; } 177 177 void setAutofilled(bool b = true) { m_autofilled = b; } 178 179 void cacheSelection(int s, int e) { cachedSelStart = s; cachedSelEnd = e; }; 178 180 179 181 protected: … … 207 209 bool m_autofilled : 1; 208 210 bool m_inited : 1; 211 212 int cachedSelStart; 213 int cachedSelEnd; 209 214 }; 210 215 -
trunk/WebCore/html/HTMLTextAreaElement.cpp
r14916 r14931 49 49 , m_cols(20) 50 50 , m_wrap(ta_Virtual) 51 , cachedSelStart(-1) 52 , cachedSelEnd(-1) 51 53 { 52 54 setValueMatchesRenderer(); … … 78 80 { 79 81 if (renderer()) { 80 if (renderer()->style()->appearance() == TextAreaAppearance) 82 if (renderer()->style()->appearance() == TextAreaAppearance) { 83 if (document()->focusNode() != this && cachedSelStart >= 0) 84 return cachedSelStart; 81 85 return static_cast<RenderTextField *>(renderer())->selectionStart(); 86 } 82 87 return static_cast<RenderTextArea*>(renderer())->selectionStart(); 83 88 } … … 88 93 { 89 94 if (renderer()) { 90 if (renderer()->style()->appearance() == TextAreaAppearance) 95 if (renderer()->style()->appearance() == TextAreaAppearance) { 96 if (document()->focusNode() != this && cachedSelEnd >= 0) 97 return cachedSelEnd; 91 98 return static_cast<RenderTextField *>(renderer())->selectionEnd(); 99 } 92 100 return static_cast<RenderTextArea*>(renderer())->selectionEnd(); 93 101 } … … 230 238 return; 231 239 doc->setFocusNode(this); 232 select(); 240 241 if (cachedSelStart == -1) { 242 ASSERT(cachedSelEnd == -1); 243 // If this is the first focus, set a caret at the end of the text. 244 // This matches other browsers' behavior. 245 int max; 246 if (renderer()->style()->appearance() == TextAreaAppearance) 247 max = static_cast<RenderTextField*>(renderer())->text().length(); 248 else 249 max = static_cast<RenderTextArea*>(renderer())->text().length(); 250 setSelectionRange(max, max); 251 } else 252 // Restore the cached selection. This matches other browsers' behavior. 253 setSelectionRange(cachedSelStart, cachedSelEnd); 254 233 255 if (doc->frame()) 234 256 doc->frame()->revealSelection(); … … 281 303 if (renderer()) 282 304 renderer()->updateFromElement(); 305 306 // Restore a caret at the starting point of the old selection. 307 // This matches Safari 2.0 behavior. 308 if (document()->focusNode() == this && cachedSelStart >= 0 && renderer() && renderer()->style()->appearance() == TextAreaAppearance) { 309 ASSERT(cachedSelEnd >= 0); 310 setSelectionRange(cachedSelStart, cachedSelStart); 311 } 283 312 setChanged(true); 284 313 } -
trunk/WebCore/html/HTMLTextAreaElement.h
r14451 r14931 91 91 void setCols(int); 92 92 void setRows(int); 93 94 void cacheSelection(int s, int e) { cachedSelStart = s; cachedSelEnd = e; }; 93 95 94 96 private: … … 99 101 WrapMethod m_wrap; 100 102 mutable String m_value; 103 int cachedSelStart; 104 int cachedSelEnd; 101 105 }; 102 106 -
trunk/WebCore/page/Frame.cpp
r14920 r14931 63 63 #include "RenderPart.h" 64 64 #include "RenderTheme.h" 65 #include "RenderTextField.h" 65 66 #include "RenderView.h" 66 67 #include "SegmentedString.h" … … 1199 1200 clearTypingStyle(); 1200 1201 1202 notifyRendererOfSelectionChange(false); 1203 1201 1204 respondToChangedSelection(oldSelection, closeTyping); 1205 } 1206 1207 void Frame::notifyRendererOfSelectionChange(bool userTriggered) 1208 { 1209 RenderObject* renderer = 0; 1210 if (d->m_selection.rootEditableElement()) 1211 renderer = d->m_selection.rootEditableElement()->shadowAncestorNode()->renderer(); 1212 1213 // If the current selection is in a textfield or textarea, notify the renderer that the selection has changed 1214 if (renderer && (renderer->isTextArea() || renderer->isTextField())) 1215 static_cast<RenderTextField*>(renderer)->selectionChanged(userTriggered); 1202 1216 } 1203 1217 … … 1929 1943 setSelection(selection); 1930 1944 } 1945 1946 notifyRendererOfSelectionChange(true); 1947 1931 1948 selectFrameElementInParentIfFullySelected(); 1932 1949 } -
trunk/WebCore/page/Frame.h
r14920 r14931 327 327 void setSelection(const SelectionController&, bool closeTyping = true, bool keepTypingStyle = false); 328 328 bool shouldChangeSelection(const SelectionController&) const; 329 330 void notifyRendererOfSelectionChange(bool userTriggered); 329 331 330 332 /** -
trunk/WebCore/rendering/RenderTextField.cpp
r14916 r14931 194 194 195 195 document()->updateLayout(); 196 196 197 if (style()->visibility() == HIDDEN) { 198 if (m_multiLine) 199 static_cast<HTMLTextAreaElement*>(node())->cacheSelection(start, end); 200 else 201 static_cast<HTMLInputElement*>(node())->cacheSelection(start, end); 202 return; 203 } 197 204 VisiblePosition startPosition = visiblePositionForIndex(start); 198 205 VisiblePosition endPosition; … … 387 394 } 388 395 389 void RenderTextField::selectionChanged() 390 { 391 // FIXME: Implement this, and find the right place to detect a selection change to call this method. 392 // We also want to retain more information about selection for text controls, so this would be the place 393 // to store that info. 394 } 395 396 } 396 void RenderTextField::selectionChanged(bool userTriggered) 397 { 398 HTMLGenericFormElement* element = static_cast<HTMLGenericFormElement*>(node()); 399 if (m_multiLine) 400 static_cast<HTMLTextAreaElement*>(element)->cacheSelection(selectionStart(), selectionEnd()); 401 else 402 static_cast<HTMLInputElement*>(element)->cacheSelection(selectionStart(), selectionEnd()); 403 if (document()->frame()->selection().isRange() && userTriggered) 404 element->onSelect(); 405 } 406 407 } -
trunk/WebCore/rendering/RenderTextField.h
r14451 r14931 60 60 String textWithHardLineBreaks(); 61 61 void forwardEvent(Event*); 62 void selectionChanged( );62 void selectionChanged(bool userTriggered); 63 63 64 64 private:
Note:
See TracChangeset
for help on using the changeset viewer.