[webkit-changes] cvs commit: WebCore/layout-tests/fast/forms selection-functions-expected.txt selection-functions.html textarea-crlf-expected.txt textarea-crlf.html

Darin darin at opensource.apple.com
Thu Jun 23 22:53:32 PDT 2005


darin       05/06/23 22:53:31

  Modified:    .        ChangeLog
               khtml/ecma kjs_html.cpp kjs_html.h
               khtml/html html_formimpl.cpp html_formimpl.h
               khtml/rendering render_form.cpp render_form.h
               kwq      KWQLineEdit.h KWQLineEdit.mm KWQTextArea.h
                        KWQTextArea.mm KWQTextEdit.h KWQTextEdit.mm
                        KWQTextField.h KWQTextField.mm
  Added:       layout-tests/fast/forms selection-functions-expected.txt
                        selection-functions.html textarea-crlf-expected.txt
                        textarea-crlf.html
  Log:
          Reviewed and landed by Darin Adler.
  
          Test cases added:
          * layout-tests/fast/forms/selection-functions-expected.txt: Added.
          * layout-tests/fast/forms/selection-functions.html: Added.
          * layout-tests/fast/forms/textarea-crlf-expected.txt: Added.
          * layout-tests/fast/forms/textarea-crlf.html: Added.
  
          - Fixes bug <http://bugzilla.opendarwin.org/show_bug.cgi?id=3401>.
            Also fixes issue where setting text of a textarea in code and then
            retrieving it would leave the \r\n sequences in the text, despite
            the textarea translating to \n in all other cases.
  
          * khtml/ecma/kjs_html.h:
          * khtml/ecma/kjs_html.cpp:
          (KJS::getInputSelectionStart):
          (KJS::getInputSelectionEnd):
          (KJS::KJS::HTMLElement::getValueProperty):
          (KJS::KJS::HTMLElement::hasProperty):
          (KJS::KJS::HTMLElementFunction::tryCall):
          (KJS::HTMLElement::putValue):
          * khtml/html/html_formimpl.cpp:
          (DOM::HTMLInputElementImpl::canHaveSelection):
          (DOM::HTMLInputElementImpl::selectionStart):
          (DOM::HTMLInputElementImpl::selectionEnd):
          (DOM::HTMLInputElementImpl::setSelectionStart):
          (DOM::HTMLInputElementImpl::setSelectionEnd):
          (DOM::HTMLInputElementImpl::setSelectionRange):
          (DOM::HTMLInputElementImpl::setValue):
          (DOM::HTMLTextAreaElementImpl::selectionStart):
          (DOM::HTMLTextAreaElementImpl::selectionEnd):
          (DOM::HTMLTextAreaElementImpl::setSelectionStart):
          (DOM::HTMLTextAreaElementImpl::setSelectionEnd):
          (DOM::HTMLTextAreaElementImpl::setSelectionRange):
          (DOM::HTMLTextAreaElementImpl::setValue):
          * khtml/html/html_formimpl.h:
          * khtml/rendering/render_form.cpp:
          (RenderLineEdit::selectionStart):
          (RenderLineEdit::selectionEnd):
          (RenderLineEdit::setSelectionStart):
          (RenderLineEdit::setSelectionEnd):
          (RenderLineEdit::setSelectionRange):
          (RenderTextArea::selectionStart):
          (RenderTextArea::selectionEnd):
          (RenderTextArea::setSelectionStart):
          (RenderTextArea::setSelectionEnd):
          (RenderTextArea::select):
          (RenderTextArea::setSelectionRange):
          * khtml/rendering/render_form.h:
          * kwq/KWQLineEdit.h:
          * kwq/KWQLineEdit.mm:
          (QLineEdit::setCursorPosition):
          (QLineEdit::cursorPosition):
          (QLineEdit::selectAll):
          (QLineEdit::selectionStart):
          (QLineEdit::selectedText):
          (QLineEdit::setSelection):
          * kwq/KWQTextArea.h:
          * kwq/KWQTextArea.mm:
          (-[KWQTextArea setSelectedRange:]):
          (-[KWQTextArea selectedRange]):
          (-[KWQTextArea getCursorPositionAsIndex:inParagraph:]):
          (RangeOfParagraph):
          * kwq/KWQTextEdit.h:
          * kwq/KWQTextEdit.mm:
          (QTextEdit::getCursorPosition):
          (QTextEdit::selectionStart):
          (QTextEdit::selectionEnd):
          (QTextEdit::setSelectionStart):
          (QTextEdit::setSelectionEnd):
          (QTextEdit::selectAll):
          (QTextEdit::setSelectionRange):
          * kwq/KWQTextField.h:
          * kwq/KWQTextField.mm:
          (-[KWQTextFieldController selectedRange]):
          (-[KWQTextFieldController setSelectedRange:]):
  
  Revision  Changes    Path
  1.4310    +79 -0     WebCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebCore/ChangeLog,v
  retrieving revision 1.4309
  retrieving revision 1.4310
  diff -u -r1.4309 -r1.4310
  --- ChangeLog	23 Jun 2005 21:52:14 -0000	1.4309
  +++ ChangeLog	24 Jun 2005 05:53:21 -0000	1.4310
  @@ -1,3 +1,82 @@
  +2005-06-23  Kevin Ballard  <kevin at sb.org>
  +
  +        Reviewed and landed by Darin Adler.
  +
  +        Test cases added:
  +        * layout-tests/fast/forms/selection-functions-expected.txt: Added.
  +        * layout-tests/fast/forms/selection-functions.html: Added.
  +        * layout-tests/fast/forms/textarea-crlf-expected.txt: Added.
  +        * layout-tests/fast/forms/textarea-crlf.html: Added.
  +
  +        - Fixes bug <http://bugzilla.opendarwin.org/show_bug.cgi?id=3401>.
  +          Also fixes issue where setting text of a textarea in code and then
  +          retrieving it would leave the \r\n sequences in the text, despite
  +          the textarea translating to \n in all other cases.
  +
  +        * khtml/ecma/kjs_html.h:
  +        * khtml/ecma/kjs_html.cpp:
  +        (KJS::getInputSelectionStart):
  +        (KJS::getInputSelectionEnd):
  +        (KJS::KJS::HTMLElement::getValueProperty):
  +        (KJS::KJS::HTMLElement::hasProperty):
  +        (KJS::KJS::HTMLElementFunction::tryCall):
  +        (KJS::HTMLElement::putValue):
  +        * khtml/html/html_formimpl.cpp:
  +        (DOM::HTMLInputElementImpl::canHaveSelection):
  +        (DOM::HTMLInputElementImpl::selectionStart):
  +        (DOM::HTMLInputElementImpl::selectionEnd):
  +        (DOM::HTMLInputElementImpl::setSelectionStart):
  +        (DOM::HTMLInputElementImpl::setSelectionEnd):
  +        (DOM::HTMLInputElementImpl::setSelectionRange):
  +        (DOM::HTMLInputElementImpl::setValue):
  +        (DOM::HTMLTextAreaElementImpl::selectionStart):
  +        (DOM::HTMLTextAreaElementImpl::selectionEnd):
  +        (DOM::HTMLTextAreaElementImpl::setSelectionStart):
  +        (DOM::HTMLTextAreaElementImpl::setSelectionEnd):
  +        (DOM::HTMLTextAreaElementImpl::setSelectionRange):
  +        (DOM::HTMLTextAreaElementImpl::setValue):
  +        * khtml/html/html_formimpl.h:
  +        * khtml/rendering/render_form.cpp:
  +        (RenderLineEdit::selectionStart):
  +        (RenderLineEdit::selectionEnd):
  +        (RenderLineEdit::setSelectionStart):
  +        (RenderLineEdit::setSelectionEnd):
  +        (RenderLineEdit::setSelectionRange):
  +        (RenderTextArea::selectionStart):
  +        (RenderTextArea::selectionEnd):
  +        (RenderTextArea::setSelectionStart):
  +        (RenderTextArea::setSelectionEnd):
  +        (RenderTextArea::select):
  +        (RenderTextArea::setSelectionRange):
  +        * khtml/rendering/render_form.h:
  +        * kwq/KWQLineEdit.h:
  +        * kwq/KWQLineEdit.mm:
  +        (QLineEdit::setCursorPosition):
  +        (QLineEdit::cursorPosition):
  +        (QLineEdit::selectAll):
  +        (QLineEdit::selectionStart):
  +        (QLineEdit::selectedText):
  +        (QLineEdit::setSelection):
  +        * kwq/KWQTextArea.h:
  +        * kwq/KWQTextArea.mm:
  +        (-[KWQTextArea setSelectedRange:]):
  +        (-[KWQTextArea selectedRange]):
  +        (-[KWQTextArea getCursorPositionAsIndex:inParagraph:]):
  +        (RangeOfParagraph):
  +        * kwq/KWQTextEdit.h:
  +        * kwq/KWQTextEdit.mm:
  +        (QTextEdit::getCursorPosition):
  +        (QTextEdit::selectionStart):
  +        (QTextEdit::selectionEnd):
  +        (QTextEdit::setSelectionStart):
  +        (QTextEdit::setSelectionEnd):
  +        (QTextEdit::selectAll):
  +        (QTextEdit::setSelectionRange):
  +        * kwq/KWQTextField.h:
  +        * kwq/KWQTextField.mm:
  +        (-[KWQTextFieldController selectedRange]):
  +        (-[KWQTextFieldController setSelectedRange:]):
  +
   2005-06-23  Justin Garcia  <justin.garcia at apple.com>
   
           Patch by Eric Seidel <macdome at opendarwin.org>
  
  
  
  1.119     +55 -1     WebCore/khtml/ecma/kjs_html.cpp
  
  Index: kjs_html.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/ecma/kjs_html.cpp,v
  retrieving revision 1.118
  retrieving revision 1.119
  diff -u -r1.118 -r1.119
  --- kjs_html.cpp	22 Jun 2005 00:48:44 -0000	1.118
  +++ kjs_html.cpp	24 Jun 2005 05:53:25 -0000	1.119
  @@ -838,6 +838,8 @@
     maxLength	KJS::HTMLElement::InputMaxLength	DontDelete
     name		KJS::HTMLElement::InputName		DontDelete
     readOnly	KJS::HTMLElement::InputReadOnly		DontDelete
  +  selectionStart	KJS::HTMLElement::InputSelectionStart	DontDelete
  +  selectionEnd	KJS::HTMLElement::InputSelectionEnd	DontDelete
     size		KJS::HTMLElement::InputSize		DontDelete
     src		KJS::HTMLElement::InputSrc		DontDelete
     tabIndex	KJS::HTMLElement::InputTabIndex		DontDelete
  @@ -848,8 +850,9 @@
     focus		KJS::HTMLElement::InputFocus		DontDelete|Function 0
     select	KJS::HTMLElement::InputSelect		DontDelete|Function 0
     click		KJS::HTMLElement::InputClick		DontDelete|Function 0
  +  setSelectionRange	KJS::HTMLElement::InputSetSelectionRange	DontDelete|Function 2
   @end
  - at begin HTMLTextAreaElementTable 13
  + at begin HTMLTextAreaElementTable 17
     defaultValue	KJS::HTMLElement::TextAreaDefaultValue	DontDelete
     form		KJS::HTMLElement::TextAreaForm		DontDelete|ReadOnly
     accessKey	KJS::HTMLElement::TextAreaAccessKey	DontDelete
  @@ -858,12 +861,15 @@
     name		KJS::HTMLElement::TextAreaName		DontDelete
     readOnly	KJS::HTMLElement::TextAreaReadOnly	DontDelete
     rows		KJS::HTMLElement::TextAreaRows		DontDelete
  +  selectionStart	KJS::HTMLElement::TextAreaSelectionStart	DontDelete
  +  selectionEnd	KJS::HTMLElement::TextAreaSelectionEnd	DontDelete
     tabIndex	KJS::HTMLElement::TextAreaTabIndex	DontDelete
     type		KJS::HTMLElement::TextAreaType		DontDelete|ReadOnly
     value		KJS::HTMLElement::TextAreaValue		DontDelete
     blur		KJS::HTMLElement::TextAreaBlur		DontDelete|Function 0
     focus		KJS::HTMLElement::TextAreaFocus		DontDelete|Function 0
     select	KJS::HTMLElement::TextAreaSelect	DontDelete|Function 0
  +  setSelectionRange	KJS::HTMLElement::TextAreaSetSelectionRange	DontDelete|Function 2
   @end
   @begin HTMLButtonElementTable 7
     form		KJS::HTMLElement::ButtonForm		DontDelete|ReadOnly
  @@ -1320,6 +1326,22 @@
       return Undefined();
   }
   
  +static Value getInputSelectionStart(HTMLInputElementImpl &input)
  +{
  +  if (input.canHaveSelection()) {
  +    return Number(input.selectionStart());
  +  }
  +  return Undefined();
  +}
  +
  +static Value getInputSelectionEnd(HTMLInputElementImpl &input)
  +{
  +  if (input.canHaveSelection()) {
  +    return Number(input.selectionEnd());
  +  }
  +  return Undefined();
  +}
  +
   Value KJS::HTMLElement::getValueProperty(ExecState *exec, int token) const
   {
     HTMLElementImpl &element = *static_cast<HTMLElementImpl *>(impl());
  @@ -1488,6 +1510,8 @@
       case InputMaxLength:       return Number(input.maxLength());
       case InputName:            return String(input.name());
       case InputReadOnly:        return Boolean(input.readOnly());
  +    case InputSelectionStart:  return getInputSelectionStart(input);
  +    case InputSelectionEnd:    return getInputSelectionEnd(input);
       case InputSize:            return String(input.sizeDOM());
       case InputSrc:             return String(input.src());
       case InputTabIndex:        return Number(input.tabIndex());
  @@ -1508,6 +1532,8 @@
       case TextAreaName:            return String(textarea.name());
       case TextAreaReadOnly:        return Boolean(textarea.readOnly());
       case TextAreaRows:            return Number(textarea.rows());
  +    case TextAreaSelectionStart:  return Number(textarea.selectionStart());
  +    case TextAreaSelectionEnd:    return Number(textarea.selectionEnd());
       case TextAreaTabIndex:        return Number(textarea.tabIndex());
       case TextAreaType:            return String(textarea.type());
       case TextAreaValue:           return String(textarea.value());
  @@ -2052,6 +2078,22 @@
           return true;
         break;
       }
  +    case ID_INPUT: {
  +      HTMLInputElementImpl &input = static_cast<HTMLInputElementImpl &>(element);
  +      const HashTable* table = classInfo()->propHashTable;
  +      const HashEntry* entry = Lookup::findEntry(table, propertyName);
  +      if (entry) {
  +        switch(entry->value) {
  +          case InputSelectionStart:
  +          case InputSelectionEnd:
  +          case InputSetSelectionRange:
  +            return input.canHaveSelection();
  +          default:
  +            break;
  +        }
  +      }
  +      break;
  +    }
       default:
         break;
     }
  @@ -2179,6 +2221,10 @@
           input.click();
           return Undefined();
         }
  +      else if (id == KJS::HTMLElement::InputSetSelectionRange) {
  +        input.setSelectionRange(args[0].toInt32(exec), args[1].toInt32(exec));
  +        return Undefined();
  +      }
       }
       break;
       case ID_LABEL: {
  @@ -2226,6 +2272,10 @@
           textarea.select();
           return Undefined();
         }
  +      else if (id == KJS::HTMLElement::TextAreaSetSelectionRange) {
  +        textarea.setSelectionRange(args[0].toInt32(exec), args[1].toInt32(exec));
  +        return Undefined();
  +      }
       }
       break;
       case ID_A: {
  @@ -2564,6 +2614,8 @@
         case InputMaxLength:       { input.setMaxLength(value.toInt32(exec)); return; }
         case InputName:            { input.setName(str); return; }
         case InputReadOnly:        { input.setReadOnly(value.toBoolean(exec)); return; }
  +      case InputSelectionStart:  { input.setSelectionStart(value.toInt32(exec)); return; }
  +      case InputSelectionEnd:    { input.setSelectionEnd(value.toInt32(exec)); return; }
         case InputSize:            { input.setSize(str); return; }
         case InputSrc:             { input.setSrc(str); return; }
         case InputTabIndex:        { input.setTabIndex(value.toInt32(exec)); return; }
  @@ -2584,6 +2636,8 @@
         case TextAreaName:            { textarea.setName(str); return; }
         case TextAreaReadOnly:        { textarea.setReadOnly(value.toBoolean(exec)); return; }
         case TextAreaRows:            { textarea.setRows(value.toInt32(exec)); return; }
  +      case TextAreaSelectionStart:  { textarea.setSelectionStart(value.toInt32(exec)); return; }
  +      case TextAreaSelectionEnd:    { textarea.setSelectionEnd(value.toInt32(exec)); return; }
         case TextAreaTabIndex:        { textarea.setTabIndex(value.toInt32(exec)); return; }
         // read-only: type
         case TextAreaValue:           { textarea.setValue(str); return; }
  
  
  
  1.48      +3 -1      WebCore/khtml/ecma/kjs_html.h
  
  Index: kjs_html.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/ecma/kjs_html.h,v
  retrieving revision 1.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- kjs_html.h	22 Jun 2005 00:48:44 -0000	1.47
  +++ kjs_html.h	24 Jun 2005 05:53:26 -0000	1.48
  @@ -103,9 +103,11 @@
              InputFocus, InputMaxLength, InputDefaultChecked, InputDisabled,
              InputChecked, InputForm, InputAccessKey, InputAlign, InputAlt,
              InputName, InputSrc, InputUseMap, InputSelect, InputClick,
  -           TextAreaAccessKey, TextAreaName, TextAreaDefaultValue, TextAreaSelect,
  +           InputSelectionStart, InputSelectionEnd, InputSetSelectionRange,
  +           TextAreaAccessKey, TextAreaName, TextAreaDefaultValue, TextAreaSelect, TextAreaSetSelectionRange,
              TextAreaCols, TextAreaDisabled, TextAreaForm, TextAreaType,
              TextAreaTabIndex, TextAreaReadOnly, TextAreaRows, TextAreaValue,
  +           TextAreaSelectionStart, TextAreaSelectionEnd,
              TextAreaBlur, TextAreaFocus, ButtonBlur, ButtonFocus, ButtonForm, ButtonTabIndex, ButtonName,
              ButtonDisabled, ButtonAccessKey, ButtonType, ButtonValue, LabelHtmlFor,
              LabelForm, LabelFocus, LabelAccessKey, FieldSetForm, LegendForm, LegendAccessKey,
  
  
  
  1.168     +138 -2    WebCore/khtml/html/html_formimpl.cpp
  
  Index: html_formimpl.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/html/html_formimpl.cpp,v
  retrieving revision 1.167
  retrieving revision 1.168
  diff -u -r1.167 -r1.168
  --- html_formimpl.cpp	20 Jun 2005 05:52:16 -0000	1.167
  +++ html_formimpl.cpp	24 Jun 2005 05:53:26 -0000	1.168
  @@ -1508,6 +1508,89 @@
       }
   }
   
  +bool HTMLInputElementImpl::canHaveSelection()
  +{
  +    switch (m_type) {
  +        case TEXT:
  +        case PASSWORD:
  +#if APPLE_CHANGES
  +        case SEARCH:
  +#endif
  +            return true;
  +        default:
  +            break;
  +    }
  +    return false;
  +}
  +
  +long HTMLInputElementImpl::selectionStart()
  +{
  +    if (!m_render) return 0;
  +    
  +    switch (m_type) {
  +        case PASSWORD:
  +#if APPLE_CHANGES
  +        case SEARCH:
  +#endif
  +        case TEXT:
  +            return static_cast<RenderLineEdit *>(m_render)->selectionStart();
  +        default:
  +            break;
  +    }
  +    return 0;
  +}
  +
  +long HTMLInputElementImpl::selectionEnd()
  +{
  +    if (!m_render) return 0;
  +    
  +    switch (m_type) {
  +        case PASSWORD:
  +#if APPLE_CHANGES
  +        case SEARCH:
  +#endif
  +        case TEXT:
  +            return static_cast<RenderLineEdit *>(m_render)->selectionEnd();
  +        default:
  +            break;
  +    }
  +    return 0;
  +}
  +
  +void HTMLInputElementImpl::setSelectionStart(long start)
  +{
  +    if (!m_render) return;
  +    
  +    switch (m_type) {
  +        case PASSWORD:
  +#if APPLE_CHANGES
  +        case SEARCH:
  +#endif
  +        case TEXT:
  +            static_cast<RenderLineEdit *>(m_render)->setSelectionStart(start);
  +            break;
  +        default:
  +            break;
  +    }
  +}
  +
  +void HTMLInputElementImpl::setSelectionEnd(long end)
  +{
  +    if (!m_render) return;
  +    
  +    switch (m_type) {
  +        case PASSWORD:
  +#if APPLE_CHANGES
  +        case SEARCH:
  +#endif
  +        case TEXT:
  +            static_cast<RenderLineEdit *>(m_render)->setSelectionEnd(end);
  +            break;
  +        default:
  +            break;
  +    }
  +}
  +
   void HTMLInputElementImpl::select(  )
   {
       if(!m_render) return;
  @@ -1538,6 +1621,23 @@
       }
   }
   
  +void HTMLInputElementImpl::setSelectionRange(long start, long end)
  +{
  +    if (!m_render) return;
  +    
  +    switch (m_type) {
  +        case PASSWORD:
  +#if APPLE_CHANGES
  +        case SEARCH:
  +#endif
  +        case TEXT:
  +            static_cast<RenderLineEdit *>(m_render)->setSelectionRange(start, end);
  +            break;
  +        default:
  +            break;
  +    }
  +}
  +
   void HTMLInputElementImpl::click(bool sendMouseEvents)
   {
       switch (inputType()) {
  @@ -2094,13 +2194,15 @@
   {
       if (m_type == FILE) return;
   
  +    m_valueMatchesRenderer = false;
       if (storesValueSeparateFromAttribute()) {
           m_value = value;
  +        if (m_render)
  +            m_render->updateFromElement();
           setChanged();
       } else {
           setAttribute(ATTR_VALUE, value);
       }
  -    m_valueMatchesRenderer = false;
   }
   
   void HTMLInputElementImpl::setValueFromRenderer(const DOMString &value)
  @@ -3380,12 +3482,44 @@
       // the close() in the rendertree will take care of transferring defaultvalue to 'value'
   }
   
  +long HTMLTextAreaElementImpl::selectionStart()
  +{
  +    if (m_render)
  +        return static_cast<RenderTextArea *>(m_render)->selectionStart();
  +    return 0;
  +}
  +
  +long HTMLTextAreaElementImpl::selectionEnd()
  +{
  +    if (m_render)
  +        return static_cast<RenderTextArea *>(m_render)->selectionEnd();
  +    return 0;
  +}
  +
  +void HTMLTextAreaElementImpl::setSelectionStart(long start)
  +{
  +    if (m_render)
  +        static_cast<RenderTextArea *>(m_render)->setSelectionStart(start);
  +}
  +
  +void HTMLTextAreaElementImpl::setSelectionEnd(long end)
  +{
  +    if (m_render)
  +        static_cast<RenderTextArea *>(m_render)->setSelectionEnd(end);
  +}
  +
   void HTMLTextAreaElementImpl::select(  )
   {
       if (m_render)
           static_cast<RenderTextArea*>(m_render)->select();
   }
   
  +void HTMLTextAreaElementImpl::setSelectionRange(long start, long end)
  +{
  +    if (m_render)
  +        static_cast<RenderTextArea *>(m_render)->setSelectionRange(start, end);
  +}
  +
   void HTMLTextAreaElementImpl::childrenChanged()
   {
       setValue(defaultValue());
  @@ -3483,8 +3617,10 @@
   void HTMLTextAreaElementImpl::setValue(const DOMString &value)
   {
       m_value = value.string();
  -    m_valueIsValid = true;
       m_valueMatchesRenderer = false;
  +    if (m_render)
  +        static_cast<RenderTextArea *>(m_render)->updateFromElement();
  +    m_valueIsValid = false; // force the next access to fetch from the renderer
       setChanged(true);
   }
   
  
  
  
  1.75      +15 -0     WebCore/khtml/html/html_formimpl.h
  
  Index: html_formimpl.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/html/html_formimpl.h,v
  retrieving revision 1.74
  retrieving revision 1.75
  diff -u -r1.74 -r1.75
  --- html_formimpl.h	20 Jun 2005 05:52:16 -0000	1.74
  +++ html_formimpl.h	24 Jun 2005 05:53:27 -0000	1.75
  @@ -357,7 +357,15 @@
       virtual QString state();
       virtual void restoreState(QStringList &);
   
  +    bool canHaveSelection();
  +
  +    long selectionStart();
  +    long selectionEnd();
  +    void setSelectionStart(long);
  +    void setSelectionEnd(long);
  +
       void select();
  +    void setSelectionRange(long, long);
       
       virtual void click(bool sendMouseEvents = false);
       virtual void accessKeyAction(bool sendToAnyElement);
  @@ -722,7 +730,14 @@
       virtual QString state();
       virtual void restoreState(QStringList &);
   
  +    long selectionStart();
  +    long selectionEnd();
  +
  +    void setSelectionStart(long);
  +    void setSelectionEnd(long);
  +
       void select (  );
  +    void setSelectionRange(long, long);
   
       virtual void childrenChanged();
       virtual void parseMappedAttribute(MappedAttributeImpl *attr);
  
  
  
  1.108     +104 -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.107
  retrieving revision 1.108
  diff -u -r1.107 -r1.108
  --- render_form.cpp	20 Jun 2005 05:24:26 -0000	1.107
  +++ render_form.cpp	24 Jun 2005 05:53:28 -0000	1.108
  @@ -718,11 +718,55 @@
       element()->setValueFromRenderer(newText);
   }
   
  +long RenderLineEdit::selectionStart()
  +{
  +    KLineEdit *lineEdit = static_cast<KLineEdit *>(m_widget);
  +    int start = lineEdit->selectionStart();
  +    if (start == -1)
  +        start = lineEdit->cursorPosition();
  +    return start;
  +}
  +
  +long RenderLineEdit::selectionEnd()
  +{
  +    KLineEdit *lineEdit = static_cast<KLineEdit *>(m_widget);
  +    int start = lineEdit->selectionStart();
  +    if (start == -1)
  +        return lineEdit->cursorPosition();
  +    return start + (int)lineEdit->selectedText().length();
  +}
  +
  +void RenderLineEdit::setSelectionStart(long start)
  +{
  +    int realStart = MAX(start, 0);
  +    int length = MAX(selectionEnd() - realStart, 0);
  +    static_cast<KLineEdit *>(m_widget)->setSelection(realStart, length);
  +}
  +
  +void RenderLineEdit::setSelectionEnd(long end)
  +{
  +    int start = selectionStart();
  +    int realEnd = MAX(end, 0);
  +    int length = realEnd - start;
  +    if (length < 0) {
  +        start = realEnd;
  +        length = 0;
  +    }
  +    static_cast<KLineEdit *>(m_widget)->setSelection(start, length);
  +}
  +
   void RenderLineEdit::select()
   {
       static_cast<KLineEdit*>(m_widget)->selectAll();
   }
   
  +void RenderLineEdit::setSelectionRange(long start, long end)
  +{
  +    int realStart = MAX(start, 0);
  +    int length = MAX(end - realStart, 0);
  +    static_cast<KLineEdit *>(m_widget)->setSelection(realStart, length);
  +}
  +
   // ---------------------------------------------------------------------------
   
   RenderFieldset::RenderFieldset(HTMLGenericFormElementImpl *element)
  @@ -1641,11 +1685,71 @@
       m_dirty = true;
   }
   
  +long RenderTextArea::selectionStart()
  +{
  +    QTextEdit *textEdit = static_cast<QTextEdit *>(m_widget);
  +#if APPLE_CHANGES
  +    return textEdit->selectionStart();
  +#else
  +    // FIXME: I have no way to test Qt, so I'll
  +    // leave this alone for now
  +#error Unimplemented method
  +#endif
  +}
  +
  +long RenderTextArea::selectionEnd()
  +{
  +    QTextEdit *textEdit = static_cast<QTextEdit *>(m_widget);
  +#if APPLE_CHANGES
  +    return textEdit->selectionEnd();
  +#else
  +    // FIXME: I have no way to test Qt, so I'll
  +    // leave this alone for now
  +#error Unimplemented method
  +#endif
  +}
  +
  +void RenderTextArea::setSelectionStart(long start)
  +{
  +    QTextEdit *textEdit = static_cast<QTextEdit *>(m_widget);
  +#if APPLE_CHANGES
  +    textEdit->setSelectionStart(start);
  +#else
  +    // FIXME: I have no way to test Qt, so I'll
  +    // leave this alone for now
  +#error Unimplemented method
  +#endif
  +}
  +
  +void RenderTextArea::setSelectionEnd(long end)
  +{
  +    QTextEdit *textEdit = static_cast<QTextEdit *>(m_widget);
  +#if APPLE_CHANGES
  +    textEdit->setSelectionEnd(end);
  +#else
  +    // FIXME: I have no way to test Qt, so I'll
  +    // leave this alone for now
  +#error Unimplemented method
  +#endif
  +}
  +
   void RenderTextArea::select()
   {
       static_cast<QTextEdit *>(m_widget)->selectAll();
   }
   
  +void RenderTextArea::setSelectionRange(long start, long end)
  +{
  +    QTextEdit *textEdit = static_cast<QTextEdit *>(m_widget);
  +#if APPLE_CHANGES
  +    textEdit->setSelectionRange(start, end-start);
  +#else
  +    // FIXME: I have no way to test Qt, so I'll
  +    // leave this alone for now
  +#error Unimplemented method
  +#endif
  +}
  +
   void RenderTextArea::slotSelectionChanged()
   {
       QTextEdit* w = static_cast<QTextEdit*>(m_widget);
  
  
  
  1.52      +13 -1     WebCore/khtml/rendering/render_form.h
  
  Index: render_form.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/rendering/render_form.h,v
  retrieving revision 1.51
  retrieving revision 1.52
  diff -u -r1.51 -r1.52
  --- render_form.h	20 Jun 2005 05:24:26 -0000	1.51
  +++ render_form.h	24 Jun 2005 05:53:28 -0000	1.52
  @@ -248,7 +248,13 @@
       virtual void updateFromElement();
       virtual void setStyle(RenderStyle *);
   
  +    long selectionStart();
  +    long selectionEnd();
  +    void setSelectionStart(long);
  +    void setSelectionEnd(long);
  +    
       void select();
  +    void setSelectionRange(long, long);
   
       KLineEdit *widget() const { return static_cast<KLineEdit*>(m_widget); }
       DOM::HTMLInputElementImpl* element() const
  @@ -469,8 +475,14 @@
   
       QString text();
   
  +    long selectionStart();
  +    long selectionEnd();
  +    void setSelectionStart(long);
  +    void setSelectionEnd(long);
  +    
       void select();
  -
  +    void setSelectionRange(long, long);
  +    
   #if APPLE_CHANGES
       virtual bool canHaveIntrinsicMargins() const { return true; }
   #endif
  
  
  
  1.33      +4 -0      WebCore/kwq/KWQLineEdit.h
  
  Index: KWQLineEdit.h
  ===================================================================
  RCS file: /cvs/root/WebCore/kwq/KWQLineEdit.h,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- KWQLineEdit.h	20 Jun 2005 05:24:26 -0000	1.32
  +++ KWQLineEdit.h	24 Jun 2005 05:53:28 -0000	1.33
  @@ -68,6 +68,10 @@
       void selectAll();
       bool hasSelectedText() const;
       
  +    int selectionStart() const;
  +    QString selectedText() const;
  +    void setSelection(int, int);
  +    
       QSize sizeForCharacterWidth(int numCharacters) const;
       int baselinePosition(int height) const;
       
  
  
  
  1.67      +35 -3     WebCore/kwq/KWQLineEdit.mm
  
  Index: KWQLineEdit.mm
  ===================================================================
  RCS file: /cvs/root/WebCore/kwq/KWQLineEdit.mm,v
  retrieving revision 1.66
  retrieving revision 1.67
  diff -u -r1.66 -r1.67
  --- KWQLineEdit.mm	20 Jun 2005 05:24:26 -0000	1.66
  +++ KWQLineEdit.mm	24 Jun 2005 05:53:29 -0000	1.67
  @@ -76,14 +76,18 @@
       KWQ_UNBLOCK_EXCEPTIONS;
   }
   
  -void QLineEdit::setCursorPosition(int)
  +void QLineEdit::setCursorPosition(int pos)
   {
  -    // Don't do anything here.
  +    KWQ_BLOCK_EXCEPTIONS;
  +    [m_controller setSelectedRange:NSMakeRange(pos, 0)];
  +    KWQ_UNBLOCK_EXCEPTIONS;
   }
   
   int QLineEdit::cursorPosition() const
   {
  -    // Not needed.  We ignore setCursorPosition().
  +    KWQ_BLOCK_EXCEPTIONS;
  +    return [m_controller selectedRange].location;
  +    KWQ_UNBLOCK_EXCEPTIONS;
       return 0;
   }
   
  @@ -172,6 +176,7 @@
       return [m_controller maximumLength];
   }
   
  +
   void QLineEdit::selectAll()
   {
       if (!hasFocus()) {
  @@ -186,6 +191,33 @@
       }
   }
   
  +int QLineEdit::selectionStart() const
  +{
  +    KWQ_BLOCK_EXCEPTIONS;
  +    if ([m_controller hasSelection]) {
  +        return [m_controller selectedRange].location;
  +    }
  +    KWQ_UNBLOCK_EXCEPTIONS;
  +    return -1;
  +}
  +
  +QString QLineEdit::selectedText() const
  +{
  +    KWQ_BLOCK_EXCEPTIONS;
  +    NSRange range = [m_controller selectedRange];
  +    NSString *str = [m_controller string];
  +    return QString::fromNSString([str substringWithRange:range]);
  +    KWQ_UNBLOCK_EXCEPTIONS;
  +    return QString();
  +}
  +
  +void QLineEdit::setSelection(int start, int length)
  +{
  +    KWQ_BLOCK_EXCEPTIONS;
  +    [m_controller setSelectedRange:NSMakeRange(start, length)];
  +    KWQ_UNBLOCK_EXCEPTIONS;
  +}
  +
   bool QLineEdit::hasSelectedText() const
   {
       return [m_controller hasSelection];
  
  
  
  1.22      +2 -0      WebCore/kwq/KWQTextArea.h
  
  Index: KWQTextArea.h
  ===================================================================
  RCS file: /cvs/root/WebCore/kwq/KWQTextArea.h,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- KWQTextArea.h	20 Jun 2005 05:24:26 -0000	1.21
  +++ KWQTextArea.h	24 Jun 2005 05:53:29 -0000	1.22
  @@ -67,6 +67,8 @@
   - (BOOL)wordWrap;
   
   - (void)selectAll;
  +- (void)setSelectedRange:(NSRange)aRange;
  +- (NSRange)selectedRange;
   - (BOOL)hasSelection;
   
   - (NSSize)sizeWithColumns:(int)columns rows:(int)rows;
  
  
  
  1.83      +69 -9     WebCore/kwq/KWQTextArea.mm
  
  Index: KWQTextArea.mm
  ===================================================================
  RCS file: /cvs/root/WebCore/kwq/KWQTextArea.mm,v
  retrieving revision 1.82
  retrieving revision 1.83
  diff -u -r1.82 -r1.83
  --- KWQTextArea.mm	20 Jun 2005 05:24:27 -0000	1.82
  +++ KWQTextArea.mm	24 Jun 2005 05:53:29 -0000	1.83
  @@ -288,6 +288,66 @@
       [textView selectAll:nil];
   }
   
  +- (void)setSelectedRange:(NSRange)aRange
  +{
  +    NSString *text = [textView string];
  +    // Ok, the selection has to match up with the string returned by -text
  +    // and since -text translates \r\n to \n, we have to modify our selection
  +    // if a \r\n sequence is anywhere in or before the selection
  +    unsigned count = 0;
  +    NSRange foundRange, searchRange = NSMakeRange(0, aRange.location);
  +    while (foundRange = [text rangeOfString:@"\r\n" options:NSLiteralSearch range:searchRange],
  +           foundRange.location != NSNotFound) {
  +        count++;
  +        searchRange.location = NSMaxRange(foundRange);
  +        if (searchRange.location >= aRange.location) break;
  +        searchRange.length = aRange.location - searchRange.location;
  +    }
  +    aRange.location += count;
  +    count = 0;
  +    searchRange = NSMakeRange(aRange.location, aRange.length);
  +    while (foundRange = [text rangeOfString:@"\r\n" options:NSLiteralSearch range:searchRange],
  +           foundRange.location != NSNotFound) {
  +        count++;
  +        searchRange.location = NSMaxRange(foundRange);
  +        if (searchRange.location >= NSMaxRange(aRange)) break;
  +        searchRange.length = NSMaxRange(aRange) - searchRange.location;
  +    }
  +    aRange.length += count;
  +    [textView setSelectedRange:aRange];
  +}
  +
  +- (NSRange)selectedRange
  +{
  +    NSRange aRange = [textView selectedRange];
  +    if (aRange.location == NSNotFound) {
  +        return aRange;
  +    }
  +    // Same issue as with -setSelectedRange: regarding \r\n sequences
  +    unsigned count = 0;
  +    NSRange foundRange, searchRange = NSMakeRange(0, aRange.location);
  +    NSString *text = [textView string];
  +    while (foundRange = [text rangeOfString:@"\r\n" options:NSLiteralSearch range:searchRange],
  +           foundRange.location != NSNotFound) {
  +        count++;
  +        searchRange.location = NSMaxRange(foundRange);
  +        if (searchRange.location >= aRange.location) break;
  +        searchRange.length = aRange.location - searchRange.location;
  +    }
  +    aRange.location -= count;
  +    count = 0;
  +    searchRange = NSMakeRange(aRange.location, aRange.length);
  +    while (foundRange = [text rangeOfString:@"\r\n" options:NSLiteralSearch range:searchRange],
  +           foundRange.location != NSNotFound) {
  +        count++;
  +        searchRange.location = NSMaxRange(foundRange);
  +        if (searchRange.location >= NSMaxRange(aRange)) break;
  +        searchRange.length = NSMaxRange(aRange) - searchRange.location;
  +    }
  +    aRange.length -= count;
  +    return aRange;
  +}
  +
   - (BOOL)hasSelection
   {
       return [textView selectedRange].length > 0;
  @@ -394,7 +454,7 @@
       
       int paragraphSoFar = 0;
       NSRange searchRange = NSMakeRange(0, [text length]);
  -
  +    
       while (true) {
           // FIXME: Doesn't work for CR-separated or CRLF-separated text.
   	NSRange newlineRange = [text rangeOfString:@"\n" options:NSLiteralSearch range:searchRange];
  @@ -403,13 +463,13 @@
   	}
           
   	paragraphSoFar++;
  -
  +        
           unsigned advance = newlineRange.location + 1 - searchRange.location;
  -
  +        
   	searchRange.length -= advance;
   	searchRange.location += advance;
       }
  -
  +    
       *paragraph = paragraphSoFar;
       *index = selectedRange.location - searchRange.location;
   }
  @@ -418,7 +478,7 @@
   {
       int paragraphSoFar = 0;
       NSRange searchRange = NSMakeRange(0, [text length]);
  -
  +    
       NSRange newlineRange;
       while (true) {
           // FIXME: Doesn't work for CR-separated or CRLF-separated text.
  @@ -426,13 +486,13 @@
   	if (newlineRange.location == NSNotFound) {
   	    break;
   	}
  -
  +        
   	if (paragraphSoFar == paragraph) {
   	    break;
   	}
  -
  +        
   	paragraphSoFar++;
  -
  +        
           unsigned advance = newlineRange.location + 1 - searchRange.location;
   	if (searchRange.length <= advance) {
   	    searchRange.location = NSNotFound;
  @@ -443,7 +503,7 @@
   	searchRange.length -= advance;
   	searchRange.location += advance;
       }
  -
  +    
       if (paragraphSoFar < paragraph) {
           return NSMakeRange(NSNotFound, 0);
       }
  
  
  
  1.25      +6 -0      WebCore/kwq/KWQTextEdit.h
  
  Index: KWQTextEdit.h
  ===================================================================
  RCS file: /cvs/root/WebCore/kwq/KWQTextEdit.h,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- KWQTextEdit.h	20 Jun 2005 05:24:27 -0000	1.24
  +++ KWQTextEdit.h	24 Jun 2005 05:53:29 -0000	1.25
  @@ -74,8 +74,14 @@
       void setScrollBarModes(ScrollBarMode hMode, ScrollBarMode vMode);
   
       void setWritingDirection(QPainter::TextDirection);
  +
  +    long selectionStart();
  +    long selectionEnd();
  +    void setSelectionStart(long);
  +    void setSelectionEnd(long);
       
       void selectAll();
  +    void setSelectionRange(long, long);
   
       QSize sizeWithColumnsAndRows(int numColumns, int numRows) const;
   
  
  
  
  1.46      +122 -3    WebCore/kwq/KWQTextEdit.mm
  
  Index: KWQTextEdit.mm
  ===================================================================
  RCS file: /cvs/root/WebCore/kwq/KWQTextEdit.mm,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- KWQTextEdit.mm	20 Jun 2005 05:24:27 -0000	1.45
  +++ KWQTextEdit.mm	24 Jun 2005 05:53:29 -0000	1.46
  @@ -82,10 +82,10 @@
   {
       KWQTextArea *textView = (KWQTextArea *)getView();
       if (index)
  -	*index = 0;
  +        *index = 0;
       if (paragraph)
  -	*paragraph = 0;
  -
  +        *paragraph = 0;
  +    
       KWQ_BLOCK_EXCEPTIONS;
       [textView getCursorPositionAsIndex:index inParagraph:paragraph];
       KWQ_UNBLOCK_EXCEPTIONS;
  @@ -186,6 +186,99 @@
       KWQ_UNBLOCK_EXCEPTIONS;
   }
   
  +long QTextEdit::selectionStart()
  +{
  +    KWQTextArea *textView = (KWQTextArea *)getView();
  +    
  +    KWQ_BLOCK_EXCEPTIONS;
  +    NSRange range = [textView selectedRange];
  +    if (range.location == NSNotFound)
  +        return 0;
  +    return range.location;
  +    KWQ_UNBLOCK_EXCEPTIONS;
  +    
  +    return 0;
  +}
  +
  +long QTextEdit::selectionEnd()
  +{
  +    KWQTextArea *textView = (KWQTextArea *)getView();
  +    
  +    KWQ_BLOCK_EXCEPTIONS;
  +    NSRange range = [textView selectedRange];
  +    if (range.location == NSNotFound)
  +        return 0;
  +    return NSMaxRange(range);
  +    KWQ_UNBLOCK_EXCEPTIONS;
  +    
  +    return 0;
  +}
  +
  +void QTextEdit::setSelectionStart(long start)
  +{
  +    KWQTextArea *textView = (KWQTextArea *)getView();
  +    
  +    KWQ_BLOCK_EXCEPTIONS;
  +    NSRange range = [textView selectedRange];
  +    if (range.location == NSNotFound) {
  +        range.location = 0;
  +        range.length = 0;
  +    }
  +    
  +    // coerce start to a valid value
  +    long maxLength = [[textView text] length];
  +    long newStart = start;
  +    if (newStart < 0)
  +        newStart = 0;
  +    if (newStart > maxLength)
  +        newStart = maxLength;
  +    
  +    if ((unsigned)newStart < range.location + range.length) {
  +        // If we're expanding or contracting, but not collapsing the selection
  +        range.length += range.location - newStart;
  +        range.location = newStart;
  +    } else {
  +        // ok, we're collapsing the selection
  +        range.location = newStart;
  +        range.length = 0;
  +    }
  +    
  +    [textView setSelectedRange:range];
  +    KWQ_UNBLOCK_EXCEPTIONS;
  +}
  +
  +void QTextEdit::setSelectionEnd(long end)
  +{
  +    KWQTextArea *textView = (KWQTextArea *)getView();
  +    
  +    KWQ_BLOCK_EXCEPTIONS;
  +    NSRange range = [textView selectedRange];
  +    if (range.location == NSNotFound) {
  +        range.location = 0;
  +        range.length = 0;
  +    }
  +    
  +    // coerce end to a valid value
  +    long maxLength = [[textView text] length];
  +    long newEnd = end;
  +    if (newEnd < 0)
  +        newEnd = 0;
  +    if (newEnd > maxLength)
  +        newEnd = maxLength;
  +    
  +    if ((unsigned)newEnd >= range.location) {
  +        // If we're just changing the selection length, but not location..
  +        range.length = newEnd - range.location;
  +    } else {
  +        // ok, we've collapsed the selection and are moving it
  +        range.location = newEnd;
  +        range.length = 0;
  +    }
  +    
  +    [textView setSelectedRange:range];
  +    KWQ_UNBLOCK_EXCEPTIONS;
  +}
  +
   bool QTextEdit::hasSelectedText() const
   {
       KWQTextArea *textView = (KWQTextArea *)getView();
  @@ -206,6 +299,32 @@
       KWQ_UNBLOCK_EXCEPTIONS;
   }
   
  +void QTextEdit::setSelectionRange(long start, long length)
  +{
  +    KWQTextArea *textView = (KWQTextArea *)getView();
  +
  +    KWQ_BLOCK_EXCEPTIONS;
  +    long newStart = start;
  +    long newLength = length;
  +    if (newStart < 0) {
  +        // truncate the length by the negative start
  +        newLength = length + newStart;
  +        newStart = 0;
  +    }
  +    if (newLength < 0) {
  +        newLength = 0;
  +    }
  +    int maxlen = [[textView text] length];
  +    if (newStart > maxlen) {
  +        newStart = maxlen;
  +    }
  +    if (newStart + newLength > maxlen) {
  +        newLength = maxlen - newStart;
  +    }
  +    [textView setSelectedRange:NSMakeRange(newStart, newLength)];
  +    KWQ_UNBLOCK_EXCEPTIONS;
  +}
  +
   void QTextEdit::setFont(const QFont &font)
   {
       QWidget::setFont(font);
  
  
  
  1.22      +3 -0      WebCore/kwq/KWQTextField.h
  
  Index: KWQTextField.h
  ===================================================================
  RCS file: /cvs/root/WebCore/kwq/KWQTextField.h,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- KWQTextField.h	20 Jun 2005 05:24:27 -0000	1.21
  +++ KWQTextField.h	24 Jun 2005 05:53:29 -0000	1.22
  @@ -56,6 +56,9 @@
   - (void)setBaseWritingDirection:(NSWritingDirection)direction;
   - (NSWritingDirection)baseWritingDirection;
   
  +- (NSRange)selectedRange;
  +- (void)setSelectedRange:(NSRange)range;
  +
   - (NSString *)string;
   
   @end
  
  
  
  1.79      +24 -3     WebCore/kwq/KWQTextField.mm
  
  Index: KWQTextField.mm
  ===================================================================
  RCS file: /cvs/root/WebCore/kwq/KWQTextField.mm,v
  retrieving revision 1.78
  retrieving revision 1.79
  diff -u -r1.78 -r1.79
  --- KWQTextField.mm	20 Jun 2005 05:24:27 -0000	1.78
  +++ KWQTextField.mm	24 Jun 2005 05:53:29 -0000	1.79
  @@ -357,7 +357,7 @@
   - (NSRange)selectedRange
   {
       NSText *editor = [field _KWQ_currentEditor];
  -    return editor ? [editor selectedRange] : NSMakeRange(NSNotFound, 0);
  +    return editor ? [editor selectedRange] : lastSelectedRange;
   }
   
   - (void)setSelectedRange:(NSRange)range
  @@ -365,9 +365,30 @@
       // 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 = [field _KWQ_currentEditor];    
  -    if (NSMaxRange(range) <= [[editor string] length]) {
  +    NSText *editor = [field _KWQ_currentEditor];
  +    if (editor) { // if we have no focus, we don't have a current editor
  +        unsigned len = [[editor string] length];
  +        if (NSMaxRange(range) > len) {
  +            if (range.location > len) {
  +                range.location = len;
  +                range.length = 0;
  +            } else {
  +                range.length = len - range.location;
  +            }
  +        }
           [editor setSelectedRange:range];
  +    } else {
  +        // set the lastSavedRange, so it will be used when given focus
  +        unsigned len = [[field stringValue] length];
  +        if (NSMaxRange(range) > len) {
  +            if (range.location > len) {
  +                range.location = len;
  +                range.length = 0;
  +            } else {
  +                range.length = len - range.location;
  +            }
  +        }
  +        lastSelectedRange = range;
       }
   }
   
  
  
  
  1.1                  WebCore/layout-tests/fast/forms/selection-functions-expected.txt
  
  Index: selection-functions-expected.txt
  ===================================================================
  This test checks if setSelectionRange(), selectionStart, and selectionEnd on a textarea and input work as expected. This includes checking edge cases such as out-of-bound values.
  
  If this test passed you'll see a bunch of correct selection ranges below. Check the expected file for the correct ranges.
  
      
  ===textarea===
  setSelectionRange():
  3, 7
  0, 5
  42, 48
  5, 5
  
  selectionStart:
  3, 5
  7, 7
  0, 7
  48, 48
  3, 48
  
  selectionEnd:
  3, 5
  2, 2
  0, 0
  0, 48
  7, 7
  
  ===input===
  setSelectionRange():
  3, 7
  0, 5
  42, 48
  5, 5
  
  selectionStart:
  3, 5
  7, 7
  0, 7
  48, 48
  3, 48
  
  selectionEnd:
  3, 5
  2, 2
  0, 0
  0, 48
  7, 7
  
  
  
  
  
  
  1.1                  WebCore/layout-tests/fast/forms/selection-functions.html
  
  Index: selection-functions.html
  ===================================================================
  <html>
      <head>
          <script type="text/javascript">
              function print(message)
              {
                  var paragraph = document.createElement("div");
                  if (message == "") {
                      paragraph.appendChild(document.createElement("br"));
                  } else {
                      paragraph.appendChild(document.createTextNode(message));
                  }
                  document.getElementById("console").appendChild(paragraph);
              }
              function test()
              {
                  if (window.layoutTestController) {
                      layoutTestController.dumpAsText();
                  }
                  var elt = document.getElementById("text");
                  print("===textarea===");
                  testElt(elt);
                  
                  elt = document.getElementById("input");
                  print("");
                  print("===input===");
                  testElt(elt);
                  
                  print("");
                  // test to make sure the selection stuff doesn't show up
                  // when iterating over a button's properties
                  elt = document.getElementById("button");
                  for (key in elt) {
                      if (key == "selectionStart" || key == "selectionEnd" || key == "setSelectionRange") {
                          print("Failed button iteration");
                      }
                  }
                  
                  // Make sure selectionStart and selectionEnd are undefined on the button
                  if (elt.selectionStart != undefined) {
                      print("Button.selectionStart defined");
                  }
                  if (elt.selectionEnd != undefined) {
                      print("Button.selectionStart defined");
                  }
              }
              function testElt(elt)
              {
                  // make sure that setSelectionRange is defined
                  if (elt.setSelectionRange == undefined) {
                      print("Failed: no setSelectionRange");
                      return;
                  }
                  elt.value = "This is a test value. Just filling in some text.";
                  // the value is 48 characters long
                  print("setSelectionRange():");
                  elt.setSelectionRange(3,7);
                  display(elt);
                  elt.setSelectionRange(-2,5);
                  display(elt);
                  elt.setSelectionRange(42,54);
                  display(elt);
                  elt.setSelectionRange(5,2);
                  display(elt);
                  
                  print("");
                  print("selectionStart:");
                  elt.selectionStart = 3;
                  display(elt);
                  elt.selectionStart = 7;
                  display(elt);
                  elt.selectionStart = -1;
                  display(elt);
                  elt.selectionStart = 54;
                  display(elt);
                  elt.selectionStart = 3;
                  display(elt);
                  
                  print("");
                  print("selectionEnd:");
                  elt.selectionEnd = 5;
                  display(elt);
                  elt.selectionEnd = 2;
                  display(elt);
                  elt.selectionEnd = -1;
                  display(elt);
                  elt.selectionEnd = 54;
                  display(elt);
                  elt.selectionStart = 7;
                  elt.selectionEnd = 7;
                  display(elt);
                  
                  elt.value = "";
              }
              function display(elt)
              {
                  var actStart = elt.selectionStart;
                  var actEnd = elt.selectionEnd;
                  var txt = actStart.toString() + ", " + actEnd.toString();
                  print(txt);
              }
          </script>
      </head>
      <body onload="test();">
          <p>This test checks if setSelectionRange(), selectionStart, and selectionEnd on a textarea and input work as expected. This includes checking edge cases such as out-of-bound values.</p>
          <p>If this test passed you'll see a bunch of correct selection ranges below. Check the expected file for the correct ranges.</p>
          <hr />
          <form>
              <textarea id="text"></textarea>
              <input type="text" id="input" />
              <input type="button" id="button" />
          </form>
          <hr />
          <p id="console"></p>
      </body>
  </html>
  
  
  1.1                  WebCore/layout-tests/fast/forms/textarea-crlf-expected.txt
  
  Index: textarea-crlf-expected.txt
  ===================================================================
  This test attempts to set non-standard line endings in a text area and reads them back. The line endings should all come back as linefeeds.
  
  If the test passes, you should see three lines saying "Passed" below.
  
  
  Passed
  Passed
  Passed
  
  
  
  
  1.1                  WebCore/layout-tests/fast/forms/textarea-crlf.html
  
  Index: textarea-crlf.html
  ===================================================================
  <html>
      <head>
          <script type="text/javascript">
              function print(message)
              {
                  var paragraph = document.createElement("li");
                  paragraph.appendChild(document.createTextNode(message));
                  document.getElementById("console").appendChild(paragraph);
              }
              function test()
              {
                  if (window.layoutTestController) {
                      layoutTestController.dumpAsText();
                  }
                  var elt = document.getElementById("text");
                  elt.value = "This\ris\ra\rtest";
                  compare(elt.value, "This\nis\na\ntest");
                  elt.value = "And\r\nhere\r\nis\r\ntest\r\ntwo";
                  compare(elt.value, "And\nhere\nis\ntest\ntwo");
                  elt.value = "And\nlastly,\ntest\nthree";
                  compare(elt.value, "And\nlastly,\ntest\nthree");
                  elt.value = "";
              }
              function compare(val, exp)
              {
                  if (val == exp) {
                      print("Passed");
                  } else {
                      print("Failed");
                  }
              }
          </script>
      </head>
      <body onload="test();">
          <p>This test attempts to set non-standard line endings in a text area and reads them back. The line endings should all come back as linefeeds.</p>
          <p>If the test passes, you should see three lines saying "Passed" below.</p>
          <hr />
          <form>
              <textarea id="text"></textarea>
          </form>
          <hr />
          <p><ol id="console"></ol></p>
      </body>
  </html>
  
  
  



More information about the webkit-changes mailing list