[webkit-changes] cvs commit: WebCore/manual-tests select_hr.html

Adele adele at opensource.apple.com
Thu Sep 1 10:40:15 PDT 2005


adele       05/09/01 10:40:14

  Modified:    .        ChangeLog
               khtml/html html_formimpl.cpp html_formimpl.h
               khtml/rendering render_form.cpp
               kwq      KWQComboBox.h KWQComboBox.mm KWQListBox.h
                        KWQListBox.mm
  Added:       manual-tests select_hr.html
  Log:
          Reviewed by Dave Hyatt.
  
          - fixed <rdar://problem/4229189> add a way to get a separator into a <select>
  
          This will allow an <hr> within a select element to display a separator in a popup menu.
          These extra elements are added to our listItems array, which we use internally.  But this should not
          affect JavaScript operations, such as getting an index of an option element, or getting the length of the select,
          or getting the selected index.  In these cases, the <hr>s will be ignored.
  
          Test cases added:
          * manual-tests/select_hr.html: Added.
  
          * khtml/html/html_formimpl.h:
          (DOM::HTMLSelectElementImpl::listItems): Now that our listItems can also contain <hr>s,
          I've changed listItems to be a QMemArray<HTMLElementImpl*> instead of QMemArray<HTMLGenericFormElementImpl*>
          (DOM::HTMLOptGroupElementImpl::checkDTD): Added check for <hr>
  
          * khtml/html/html_formimpl.cpp:
          (DOM::HTMLSelectElementImpl::checkDTD): Added check for <hr>
          (DOM::HTMLSelectElementImpl::add): Added check for <hr> so these elements can be added through Javascript.
          (DOM::HTMLSelectElementImpl::recalcListItems): Added case for <hr> to add the element to the listItems array.
          (DOM::HTMLSelectElementImpl::selectedIndex): Updated type for array of listItems.
          (DOM::HTMLSelectElementImpl::setSelectedIndex): ditto.
          (DOM::HTMLSelectElementImpl::length): ditto.
          (DOM::HTMLSelectElementImpl::remove): ditto.
          (DOM::HTMLSelectElementImpl::value): ditto.
          (DOM::HTMLSelectElementImpl::setValue): ditto.
          (DOM::HTMLSelectElementImpl::state): ditto.
          (DOM::HTMLSelectElementImpl::restoreState): ditto.
          (DOM::HTMLSelectElementImpl::appendFormData): ditto.
          (DOM::HTMLSelectElementImpl::optionToListIndex): ditto.
          (DOM::HTMLSelectElementImpl::listToOptionIndex): ditto.
          (DOM::HTMLSelectElementImpl::reset): ditto.
          (DOM::HTMLSelectElementImpl::notifyOptionSelected): ditto.
          (DOM::HTMLOptionElementImpl::index): ditto.
  
          * khtml/rendering/render_form.cpp:
          (RenderSelect::updateFromElement): If the list item is an <hr>, and we're not using a ListBox, then we call appendSeparator on the widget.
          (RenderSelect::layout): Updated type for array of listItems.
          (RenderSelect::slotSelected): ditto.
          (RenderSelect::slotSelectionChanged): ditto.
          (RenderSelect::updateSelection): ditto.
  
          * kwq/KWQListBox.h: Added ItemType enum with the following values: Option, GroupLabel, and Separator.
          (KWQListBoxItem::KWQListBoxItem): Updated to use ItemType instead of old isGroupLabel bool.
          (QListBox::appendItem): ditto.
          (QListBox::appendGroupLabel): ditto.
  
          * kwq/KWQComboBox.h:
          (QComboBox::appendItem): the private version of appendItem used to take isLabel as a parameter.  Now it takes an ItemType.
          (QComboBox::appendGroupLabel): calls appendItem with an ItemType of GroupLabel
          (QComboBox::appendSeparator): calls appendItem with an ItemType of Separator
  
          * kwq/KWQComboBox.mm:
          (QComboBox::setTitle): Updated to check for the ItemType instead of the old isGroupLabel bool.
          (QComboBox::appendItem): If the new item is a Separator, then we add a separatorItem to the popup menu.
          (QComboBox::sizeHint): Updated to check for the ItemType instead of the old isGroupLabel bool.
          (QComboBox::populateMenu): If the new item is a Separator, then we add a separatorItem to the popup menu.
  
          * kwq/KWQListBox.mm:
          (QListBox::appendItem): Updated to use the ItemType instead of the old isLabel bool.
          (QListBox::sizeForNumberOfLines): ditto.
          (-[KWQTableView tableView:shouldSelectRow:]): ditto.
          (-[KWQTableView drawRow:clipRect:]): ditto.
  
  Revision  Changes    Path
  1.70      +67 -0     WebCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebCore/ChangeLog,v
  retrieving revision 1.69
  retrieving revision 1.70
  diff -u -r1.69 -r1.70
  --- ChangeLog	1 Sep 2005 16:21:04 -0000	1.69
  +++ ChangeLog	1 Sep 2005 17:40:12 -0000	1.70
  @@ -1,3 +1,70 @@
  +2005-08-31  Adele Peterson  <adele at apple.com>
  +
  +        Reviewed by Dave Hyatt.
  +
  +        - fixed <rdar://problem/4229189> add a way to get a separator into a <select>
  +
  +        This will allow an <hr> within a select element to display a separator in a popup menu.
  +        These extra elements are added to our listItems array, which we use internally.  But this should not
  +        affect JavaScript operations, such as getting an index of an option element, or getting the length of the select,
  +        or getting the selected index.  In these cases, the <hr>s will be ignored.
  +
  +        Test cases added:
  +        * manual-tests/select_hr.html: Added.
  +
  +        * khtml/html/html_formimpl.h: 
  +        (DOM::HTMLSelectElementImpl::listItems): Now that our listItems can also contain <hr>s, 
  +        I've changed listItems to be a QMemArray<HTMLElementImpl*> instead of QMemArray<HTMLGenericFormElementImpl*>
  +        (DOM::HTMLOptGroupElementImpl::checkDTD): Added check for <hr>
  +
  +        * khtml/html/html_formimpl.cpp:
  +        (DOM::HTMLSelectElementImpl::checkDTD): Added check for <hr>
  +        (DOM::HTMLSelectElementImpl::add): Added check for <hr> so these elements can be added through Javascript.
  +        (DOM::HTMLSelectElementImpl::recalcListItems): Added case for <hr> to add the element to the listItems array.
  +        (DOM::HTMLSelectElementImpl::selectedIndex): Updated type for array of listItems.
  +        (DOM::HTMLSelectElementImpl::setSelectedIndex): ditto.
  +        (DOM::HTMLSelectElementImpl::length): ditto.
  +        (DOM::HTMLSelectElementImpl::remove): ditto.
  +        (DOM::HTMLSelectElementImpl::value): ditto.
  +        (DOM::HTMLSelectElementImpl::setValue): ditto.
  +        (DOM::HTMLSelectElementImpl::state): ditto.
  +        (DOM::HTMLSelectElementImpl::restoreState): ditto.
  +        (DOM::HTMLSelectElementImpl::appendFormData): ditto.
  +        (DOM::HTMLSelectElementImpl::optionToListIndex): ditto.
  +        (DOM::HTMLSelectElementImpl::listToOptionIndex): ditto.
  +        (DOM::HTMLSelectElementImpl::reset): ditto.
  +        (DOM::HTMLSelectElementImpl::notifyOptionSelected): ditto.
  +        (DOM::HTMLOptionElementImpl::index): ditto.
  +
  +        * khtml/rendering/render_form.cpp:
  +        (RenderSelect::updateFromElement): If the list item is an <hr>, and we're not using a ListBox, then we call appendSeparator on the widget.  
  +        (RenderSelect::layout): Updated type for array of listItems.
  +        (RenderSelect::slotSelected): ditto.
  +        (RenderSelect::slotSelectionChanged): ditto.
  +        (RenderSelect::updateSelection): ditto.
  +
  +        * kwq/KWQListBox.h: Added ItemType enum with the following values: Option, GroupLabel, and Separator.
  +        (KWQListBoxItem::KWQListBoxItem): Updated to use ItemType instead of old isGroupLabel bool.
  +        (QListBox::appendItem): ditto.
  +        (QListBox::appendGroupLabel): ditto.
  +
  +        * kwq/KWQComboBox.h:
  +        (QComboBox::appendItem): the private version of appendItem used to take isLabel as a parameter.  Now it takes an ItemType.
  +        (QComboBox::appendGroupLabel): calls appendItem with an ItemType of GroupLabel
  +        (QComboBox::appendSeparator): calls appendItem with an ItemType of Separator
  +
  +        * kwq/KWQComboBox.mm:
  +        (QComboBox::setTitle): Updated to check for the ItemType instead of the old isGroupLabel bool.
  +        (QComboBox::appendItem): If the new item is a Separator, then we add a separatorItem to the popup menu.
  +        (QComboBox::sizeHint): Updated to check for the ItemType instead of the old isGroupLabel bool.
  +        (QComboBox::populateMenu): If the new item is a Separator, then we add a separatorItem to the popup menu.
  +
  +        * kwq/KWQListBox.mm:
  +        (QListBox::appendItem): Updated to use the ItemType instead of the old isLabel bool.
  +        (QListBox::sizeForNumberOfLines): ditto.
  +        (-[KWQTableView tableView:shouldSelectRow:]): ditto.
  +        (-[KWQTableView drawRow:clipRect:]): ditto.
  +
   2005-09-01  Mitz Pettel  <opendarwin.org at mitzpettel.com>
   
           Reviewed and landed by Darin.
  
  
  
  1.191     +22 -18    WebCore/khtml/html/html_formimpl.cpp
  
  Index: html_formimpl.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/html/html_formimpl.cpp,v
  retrieving revision 1.190
  retrieving revision 1.191
  diff -u -r1.190 -r1.191
  --- html_formimpl.cpp	31 Aug 2005 15:36:12 -0000	1.190
  +++ html_formimpl.cpp	1 Sep 2005 17:40:12 -0000	1.191
  @@ -2740,7 +2740,7 @@
   
   bool HTMLSelectElementImpl::checkDTD(const NodeImpl* newChild)
   {
  -    return newChild->isTextNode() || newChild->hasTagName(optionTag) || newChild->hasTagName(optgroupTag) ||
  +    return newChild->isTextNode() || newChild->hasTagName(optionTag) || newChild->hasTagName(optgroupTag) || newChild->hasTagName(hrTag) ||
              newChild->hasTagName(scriptTag);
   }
   
  @@ -2763,7 +2763,7 @@
   {
       // return the number of the first option selected
       uint o = 0;
  -    QMemArray<HTMLGenericFormElementImpl*> items = listItems();
  +    QMemArray<HTMLElementImpl*> items = listItems();
       for (unsigned int i = 0; i < items.size(); i++) {
           if (items[i]->hasLocalName(optionTag)) {
               if (static_cast<HTMLOptionElementImpl*>(items[i])->selected())
  @@ -2778,7 +2778,7 @@
   void HTMLSelectElementImpl::setSelectedIndex( long  index )
   {
       // deselect all other options and select only the new one
  -    QMemArray<HTMLGenericFormElementImpl*> items = listItems();
  +    QMemArray<HTMLElementImpl*> items = listItems();
       int listIndex;
       for (listIndex = 0; listIndex < int(items.size()); listIndex++) {
           if (items[listIndex]->hasLocalName(optionTag))
  @@ -2795,7 +2795,7 @@
   {
       int len = 0;
       uint i;
  -    QMemArray<HTMLGenericFormElementImpl*> items = listItems();
  +    QMemArray<HTMLElementImpl*> items = listItems();
       for (i = 0; i < items.size(); i++) {
           if (items[i]->hasLocalName(optionTag))
               len++;
  @@ -2807,7 +2807,7 @@
   {
       SharedPtr<HTMLElementImpl> protectNewChild(element); // make sure the element is ref'd and deref'd so we don't leak it
   
  -    if (!element || !element->hasLocalName(optionTag))
  +    if (!element || !(element->hasLocalName(optionTag) || element->hasLocalName(hrTag)))
           return;
   
       insertBefore(element, before, exceptioncode);
  @@ -2820,7 +2820,7 @@
       int exceptioncode = 0;
       int listIndex = optionToListIndex(index);
   
  -    QMemArray<HTMLGenericFormElementImpl*> items = listItems();
  +    QMemArray<HTMLElementImpl*> items = listItems();
       if(listIndex < 0 || index >= int(items.size()))
           return; // ### what should we do ? remove the last item?
   
  @@ -2846,7 +2846,7 @@
   DOMString HTMLSelectElementImpl::value()
   {
       uint i;
  -    QMemArray<HTMLGenericFormElementImpl*> items = listItems();
  +    QMemArray<HTMLElementImpl*> items = listItems();
       for (i = 0; i < items.size(); i++) {
           if (items[i]->hasLocalName(optionTag) && static_cast<HTMLOptionElementImpl*>(items[i])->selected())
               return static_cast<HTMLOptionElementImpl*>(items[i])->value();
  @@ -2860,7 +2860,7 @@
           return;
       // find the option with value() matching the given parameter
       // and make it the current selection.
  -    QMemArray<HTMLGenericFormElementImpl*> items = listItems();
  +    QMemArray<HTMLElementImpl*> items = listItems();
       for (unsigned i = 0; i < items.size(); i++)
           if (items[i]->hasLocalName(optionTag) && static_cast<HTMLOptionElementImpl*>(items[i])->value() == value) {
               static_cast<HTMLOptionElementImpl*>(items[i])->setSelected(true);
  @@ -2873,7 +2873,7 @@
   #if !APPLE_CHANGES
       QString state;
   #endif
  -    QMemArray<HTMLGenericFormElementImpl*> items = listItems();
  +    QMemArray<HTMLElementImpl*> items = listItems();
   
       int l = items.count();
   
  @@ -2914,7 +2914,7 @@
   #endif
       }
   
  -    QMemArray<HTMLGenericFormElementImpl*> items = listItems();
  +    QMemArray<HTMLElementImpl*> items = listItems();
   
       int l = items.count();
       for(int i = 0; i < l; i++) {
  @@ -2996,7 +2996,7 @@
   bool HTMLSelectElementImpl::appendFormData(FormDataList& encoded_values, bool)
   {
       bool successful = false;
  -    QMemArray<HTMLGenericFormElementImpl*> items = listItems();
  +    QMemArray<HTMLElementImpl*> items = listItems();
   
       uint i;
       for (i = 0; i < items.size(); i++) {
  @@ -3027,7 +3027,7 @@
   
   int HTMLSelectElementImpl::optionToListIndex(int optionIndex) const
   {
  -    QMemArray<HTMLGenericFormElementImpl*> items = listItems();
  +    QMemArray<HTMLElementImpl*> items = listItems();
       if (optionIndex < 0 || optionIndex >= int(items.size()))
           return -1;
   
  @@ -3045,7 +3045,7 @@
   
   int HTMLSelectElementImpl::listToOptionIndex(int listIndex) const
   {
  -    QMemArray<HTMLGenericFormElementImpl*> items = listItems();
  +    QMemArray<HTMLElementImpl*> items = listItems();
       if (listIndex < 0 || listIndex >= int(items.size()) ||
           !items[listIndex]->hasLocalName(optionTag))
           return -1;
  @@ -3084,12 +3084,12 @@
           if (current->hasTagName(optgroupTag) && current->firstChild()) {
               // ### what if optgroup contains just comments? don't want one of no options in it...
               m_listItems.resize(m_listItems.size()+1);
  -            m_listItems[m_listItems.size()-1] = static_cast<HTMLGenericFormElementImpl*>(current);
  +            m_listItems[m_listItems.size()-1] = static_cast<HTMLElementImpl*>(current);
               current = current->firstChild();
           }
           if (current->hasTagName(optionTag)) {
               m_listItems.resize(m_listItems.size()+1);
  -            m_listItems[m_listItems.size()-1] = static_cast<HTMLGenericFormElementImpl*>(current);
  +            m_listItems[m_listItems.size()-1] = static_cast<HTMLElementImpl*>(current);
               if (!foundSelected && !m_multiple && m_size <= 1) {
                   foundSelected = static_cast<HTMLOptionElementImpl*>(current);
                   foundSelected->m_selected = true;
  @@ -3099,6 +3099,10 @@
                   foundSelected = static_cast<HTMLOptionElementImpl*>(current);
               }
           }
  +        if (current->hasTagName(hrTag)) {
  +            m_listItems.resize(m_listItems.size()+1);
  +            m_listItems[m_listItems.size()-1] = static_cast<HTMLElementImpl*>(current);
  +        }
           NodeImpl *parent = current->parentNode();
           current = current->nextSibling();
           if (!current) {
  @@ -3126,7 +3130,7 @@
   
   void HTMLSelectElementImpl::reset()
   {
  -    QMemArray<HTMLGenericFormElementImpl*> items = listItems();
  +    QMemArray<HTMLElementImpl*> items = listItems();
       uint i;
       for (i = 0; i < items.size(); i++) {
           if (items[i]->hasLocalName(optionTag)) {
  @@ -3144,7 +3148,7 @@
   {
       if (selected && !m_multiple) {
           // deselect all other options
  -        QMemArray<HTMLGenericFormElementImpl*> items = listItems();
  +        QMemArray<HTMLElementImpl*> items = listItems();
           uint i;
           for (i = 0; i < items.size(); i++) {
               if (items[i]->hasLocalName(optionTag))
  @@ -3390,7 +3394,7 @@
   {
       // Let's do this dynamically. Might be a bit slow, but we're sure
       // we won't forget to update a member variable in some cases...
  -    QMemArray<HTMLGenericFormElementImpl*> items = getSelect()->listItems();
  +    QMemArray<HTMLElementImpl*> items = getSelect()->listItems();
       int l = items.count();
       int optionIndex = 0;
       for(int i = 0; i < l; i++) {
  
  
  
  1.87      +3 -3      WebCore/khtml/html/html_formimpl.h
  
  Index: html_formimpl.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/html/html_formimpl.h,v
  retrieving revision 1.86
  retrieving revision 1.87
  diff -u -r1.86 -r1.87
  --- html_formimpl.h	14 Aug 2005 08:07:23 -0000	1.86
  +++ html_formimpl.h	1 Sep 2005 17:40:12 -0000	1.87
  @@ -598,7 +598,7 @@
   
       void setRecalcListItems();
   
  -    QMemArray<HTMLGenericFormElementImpl*> listItems() const
  +    QMemArray<HTMLElementImpl*> listItems() const
        {
            if (m_recalcListItems) const_cast<HTMLSelectElementImpl*>(this)->recalcListItems();
            return m_listItems;
  @@ -617,7 +617,7 @@
       void recalcListItems();
   
   protected:
  -    mutable QMemArray<HTMLGenericFormElementImpl*> m_listItems;
  +    mutable QMemArray<HTMLElementImpl*> m_listItems;
       HTMLOptionsCollectionImpl *m_options;
       short m_minwidth;
       short m_size;
  @@ -654,7 +654,7 @@
       HTMLOptGroupElementImpl(DocumentPtr *doc, HTMLFormElementImpl *f = 0);
       virtual ~HTMLOptGroupElementImpl();
   
  -    virtual bool checkDTD(const NodeImpl* newChild) { return newChild->hasTagName(HTMLNames::optionTag); }
  +    virtual bool checkDTD(const NodeImpl* newChild) { return newChild->hasTagName(HTMLNames::optionTag) || newChild->hasTagName(HTMLNames::hrTag); }
   
       DOMString type() const;
   
  
  
  
  1.119     +10 -5     WebCore/khtml/rendering/render_form.cpp
  
  Index: render_form.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/rendering/render_form.cpp,v
  retrieving revision 1.118
  retrieving revision 1.119
  diff -u -r1.118 -r1.119
  --- render_form.cpp	31 Aug 2005 04:38:39 -0000	1.118
  +++ render_form.cpp	1 Sep 2005 17:40:13 -0000	1.119
  @@ -1093,7 +1093,7 @@
       if ( m_optionsChanged ) {
           if (element()->m_recalcListItems)
               element()->recalcListItems();
  -        QMemArray<HTMLGenericFormElementImpl*> listItems = element()->listItems();
  +        QMemArray<HTMLElementImpl*> listItems = element()->listItems();
           int listIndex;
   
           if (m_useListBox)
  @@ -1148,6 +1148,11 @@
                       static_cast<KComboBox*>(m_widget)->insertItem(itemText, listIndex);
   #endif
               }
  +            else if (listItems[listIndex]->hasTagName(hrTag)) {
  +                if (!m_useListBox) {
  +                    static_cast<KComboBox*>(m_widget)->appendSeparator();
  +                }
  +            }
               else
                   KHTMLAssert(false);
               m_selectionChanged = true;
  @@ -1255,7 +1260,7 @@
       RenderFormElement::layout();
   
       // and now disable the widget in case there is no <option> given
  -    QMemArray<HTMLGenericFormElementImpl*> listItems = element()->listItems();
  +    QMemArray<HTMLElementImpl*> listItems = element()->listItems();
   
       bool foundOption = false;
       for (uint i = 0; i < listItems.size() && !foundOption; i++)
  @@ -1270,7 +1275,7 @@
   
       KHTMLAssert( !m_useListBox );
   
  -    QMemArray<HTMLGenericFormElementImpl*> listItems = element()->listItems();
  +    QMemArray<HTMLElementImpl*> listItems = element()->listItems();
       if(index >= 0 && index < int(listItems.size()))
       {
           bool found = (listItems[index]->hasTagName(optionTag));
  @@ -1318,7 +1323,7 @@
   
       // don't use listItems() here as we have to avoid recalculations - changing the
       // option list will make use update options not in the way the user expects them
  -    QMemArray<HTMLGenericFormElementImpl*> listItems = element()->m_listItems;
  +    QMemArray<HTMLElementImpl*> listItems = element()->m_listItems;
       for ( unsigned i = 0; i < listItems.count(); i++ )
           // don't use setSelected() here because it will cause us to be called
           // again with updateSelection.
  @@ -1358,7 +1363,7 @@
   
   void RenderSelect::updateSelection()
   {
  -    QMemArray<HTMLGenericFormElementImpl*> listItems = element()->listItems();
  +    QMemArray<HTMLElementImpl*> listItems = element()->listItems();
       int i;
       if (m_useListBox) {
           // if multi-select, we select only the new selected index
  
  
  
  1.36      +5 -4      WebCore/kwq/KWQComboBox.h
  
  Index: KWQComboBox.h
  ===================================================================
  RCS file: /cvs/root/WebCore/kwq/KWQComboBox.h,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- KWQComboBox.h	27 Apr 2004 17:38:07 -0000	1.35
  +++ KWQComboBox.h	1 Sep 2005 17:40:13 -0000	1.36
  @@ -36,13 +36,14 @@
   #endif
   
   class QComboBox : public QWidget {
  -public:
  +public:  
       QComboBox();
       ~QComboBox();
       
       void clear();
  -    void appendItem(const QString &text) { appendItem(text, false); }
  -    void appendGroupLabel(const QString &text) { appendItem(text, true); }
  +    void appendItem(const QString &text) { appendItem(text, Option); }
  +    void appendGroupLabel(const QString &text) { appendItem(text, GroupLabel); }
  +    void appendSeparator() { appendItem(QString(""), Separator); }
   
       int currentItem() const { return _currentItem; }
       void setCurrentItem(int);
  @@ -66,7 +67,7 @@
       void populateMenu();
       
   private:
  -    void appendItem(const QString &, bool isLabel);
  +    void appendItem(const QString &, ItemType type);
       const int *dimensions() const;
       NSFont *labelFont() const;
       void setTitle(NSMenuItem *, const KWQListBoxItem &);
  
  
  
  1.64      +25 -15    WebCore/kwq/KWQComboBox.mm
  
  Index: KWQComboBox.mm
  ===================================================================
  RCS file: /cvs/root/WebCore/kwq/KWQComboBox.mm,v
  retrieving revision 1.63
  retrieving revision 1.64
  diff -u -r1.63 -r1.64
  --- KWQComboBox.mm	16 Aug 2005 19:03:19 -0000	1.63
  +++ KWQComboBox.mm	1 Sep 2005 17:40:13 -0000	1.64
  @@ -113,7 +113,7 @@
   
   void QComboBox::setTitle(NSMenuItem *menuItem, const KWQListBoxItem &title)
   {
  -    if (title.isGroupLabel) {
  +    if (title.type == GroupLabel) {
           NSDictionary *attributes = [[NSDictionary alloc] initWithObjectsAndKeys:labelFont(), NSFontAttributeName, nil];
           NSAttributedString *string = [[NSAttributedString alloc] initWithString:title.string.getNSString() attributes:attributes];
           [menuItem setAttributedTitle:string];
  @@ -125,21 +125,26 @@
       }
   }
   
  -void QComboBox::appendItem(const QString &text, bool isLabel)
  +void QComboBox::appendItem(const QString &text, ItemType type)
   {
  -    const KWQListBoxItem listItem(text, isLabel);
  +    const KWQListBoxItem listItem(text, type);
       _items.append(listItem);
       if (_menuPopulated) {
           KWQPopUpButton *button = (KWQPopUpButton *)getView();
           if (![[button cell] isHighlighted]) {
               _menuPopulated = false;
           } else {
  -            // We must add the item with no title and then set the title because
  -            // addItemWithTitle does not allow duplicate titles.
               KWQ_BLOCK_EXCEPTIONS;
  -            [button addItemWithTitle:@""];
  -            NSMenuItem *menuItem = [button lastItem];
  -            setTitle(menuItem, listItem);
  +            if (type == Separator) {
  +                NSMenuItem *separator = [NSMenuItem separatorItem];
  +                [[button menu] addItem:separator];
  +            } else {
  +                // We must add the item with no title and then set the title because
  +                // addItemWithTitle does not allow duplicate titles.
  +                [button addItemWithTitle:@""];
  +                NSMenuItem *menuItem = [button lastItem];
  +                setTitle(menuItem, listItem);
  +            }
               KWQ_UNBLOCK_EXCEPTIONS;
           }
       }
  @@ -167,7 +172,7 @@
               style.applyWordRounding = NO;
               do {
                   const QString &s = (*i).string;
  -                bool isLabel = (*i).isGroupLabel;
  +                bool isGroupLabel = ((*i).type == GroupLabel);
                   ++i;
   
                   WebCoreTextRun run;
  @@ -175,7 +180,7 @@
                   WebCoreInitializeTextRun(&run, reinterpret_cast<const UniChar *>(s.unicode()), length, 0, length);
   
                   id <WebCoreTextRenderer> renderer;
  -                if (isLabel) {
  +                if (isGroupLabel) {
                       if (labelRenderer == nil) {
                           labelRenderer = [[WebCoreTextRendererFactory sharedFactory]
                               rendererWithFont:labelFont()
  @@ -359,11 +364,16 @@
           QValueListConstIterator<KWQListBoxItem> i = const_cast<const QValueList<KWQListBoxItem> &>(_items).begin();
           QValueListConstIterator<KWQListBoxItem> e = const_cast<const QValueList<KWQListBoxItem> &>(_items).end();
           for (; i != e; ++i) {
  -            // We must add the item with no title and then set the title because
  -            // addItemWithTitle does not allow duplicate titles.
  -            [button addItemWithTitle:@""];
  -            NSMenuItem *menuItem = [button lastItem];
  -            setTitle(menuItem, *i);
  +            if ((*i).type == Separator) {
  +                NSMenuItem *separator = [NSMenuItem separatorItem];
  +                [[button menu] addItem:separator];
  +            } else {
  +                // We must add the item with no title and then set the title because
  +                // addItemWithTitle does not allow duplicate titles.
  +                [button addItemWithTitle:@""];
  +                NSMenuItem *menuItem = [button lastItem];
  +                setTitle(menuItem, *i);
  +            }
           }
           [button selectItemAtIndex:_currentItem];
   	[button setPopulatingMenu:NO];
  
  
  
  1.25      +12 -6     WebCore/kwq/KWQListBox.h
  
  Index: KWQListBox.h
  ===================================================================
  RCS file: /cvs/root/WebCore/kwq/KWQListBox.h,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- KWQListBox.h	30 Aug 2005 09:30:24 -0000	1.24
  +++ KWQListBox.h	1 Sep 2005 17:40:13 -0000	1.25
  @@ -29,12 +29,18 @@
   #include "KWQScrollView.h"
   #include "KWQPainter.h"
   
  +enum ItemType {
  +    Option,
  +    GroupLabel,
  +    Separator
  +};
  +
   struct KWQListBoxItem
   {
       QString string;
  -    bool isGroupLabel;
  -
  -    KWQListBoxItem(const QString &s, bool isLabel) : string(s), isGroupLabel(isLabel) { }
  +    ItemType type;
  +    
  +    KWQListBoxItem(const QString &s, ItemType t) : string(s), type(t) { }
   };
   
   class QListBox : public QScrollView {
  @@ -51,8 +57,8 @@
       void setSelectionMode(SelectionMode);
   
       void clear();
  -    void appendItem(const QString &s) { appendItem(s, false); }
  -    void appendGroupLabel(const QString &s) { appendItem(s, true); }
  +    void appendItem(const QString &s) { appendItem(s, Option); }
  +    void appendGroupLabel(const QString &s) { appendItem(s, GroupLabel); }
       void doneAppendingItems();
   
       void setSelected(int, bool);
  @@ -76,7 +82,7 @@
       void setFont(const QFont &font);
   
   private:
  -    void appendItem(const QString &, bool isLabel);
  +    void appendItem(const QString &, ItemType type);
   
       // A vector<KWQListBoxItem> or QValueVector<KWQListBoxItem> might be more efficient for large lists.
       QValueList<KWQListBoxItem> _items;
  
  
  
  1.56      +6 -6      WebCore/kwq/KWQListBox.mm
  
  Index: KWQListBox.mm
  ===================================================================
  RCS file: /cvs/root/WebCore/kwq/KWQListBox.mm,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- KWQListBox.mm	23 Aug 2005 18:32:51 -0000	1.55
  +++ KWQListBox.mm	1 Sep 2005 17:40:13 -0000	1.56
  @@ -183,9 +183,9 @@
       KWQ_UNBLOCK_EXCEPTIONS;
   }
   
  -void QListBox::appendItem(const QString &text, bool isLabel)
  +void QListBox::appendItem(const QString &text, ItemType type)
   {
  -    _items.append(KWQListBoxItem(text, isLabel));
  +    _items.append(KWQListBoxItem(text, type));
       _widthGood = false;
   }
   
  @@ -306,7 +306,7 @@
                   int length = s.length();
                   WebCoreInitializeTextRun(&run, reinterpret_cast<const UniChar *>(s.unicode()), length, 0, length);
   
  -                float textWidth = [((*i).isGroupLabel ? groupLabelRenderer : renderer) floatWidthForRun:&run style:&style widths:0];
  +                float textWidth = [(((*i).type == GroupLabel) ? groupLabelRenderer : renderer) floatWidthForRun:&run style:&style widths:0];
                   width = kMax(width, textWidth);
                   
                   ++i;
  @@ -599,7 +599,7 @@
   
   - (BOOL)tableView:(NSTableView *)tableView shouldSelectRow:(int)row
   {
  -    return _box && !_box->itemAtIndex(row).isGroupLabel;
  +    return _box && (_box->itemAtIndex(row).type != GroupLabel);
   }
   
   - (BOOL)selectionShouldChangeInTableView:(NSTableView *)aTableView
  @@ -632,9 +632,9 @@
       
       id <WebCoreTextRenderer> renderer;
       if (isSystemFont) {
  -        renderer = item.isGroupLabel ? groupLabelTextRenderer() : itemTextRenderer();
  +        renderer = (item.type == GroupLabel) ? groupLabelTextRenderer() : itemTextRenderer();
       } else {
  -        if (item.isGroupLabel) {
  +        if (item.type == GroupLabel) {
               QFont boldFont = _box->font();
               boldFont.setWeight(QFont::Bold);
               font = boldFont.getNSFont();
  
  
  
  1.1                  WebCore/manual-tests/select_hr.html
  
  Index: select_hr.html
  ===================================================================
  <html>
  <body>
  These are some tests to make sure that adding an hr element in a select works properly.
  <br>Other good select & option tests are included in the W3C DOM tests.
  
  <br><br>Expected results:  A disabled popup menu.
  <br><select id = "s1">
  <hr>
  </select>
  <input type="button" onclick="alert(document.getElementById('s1').length)" value ="Check length = 0"></input>
  
  <br>Expected results:  A popup menu - separator, option, separator.
  <br><select id = "s2">
  <hr>
  <option>opt 1</option>
  <hr>
  </select>
  <input type="button" onclick="alert(document.getElementById('s2').length)" value="Check length = 1"></input>
  
  <br>Expected results:  A popup menu - option, separator, option.
  <br><select id = "s3">
  <option>opt 1</option>
  <hr>
  <option>opt 2</option>
  </select>
  <input type="button" onclick="alert(document.getElementById('s3').length)" value="Check length = 2"></input>
  
  <br>Expected results:  A popup menu - option, four separators, two options, separator, option.
  <br><select id = "s4">
  <option>opt 1</option>
  <hr>
  <hr>
  <hr>
  <hr>
  <option>opt 2</option>
  <option>opt 3</option>
  <hr>
  <option>opt 4</option>
  </select>
  <input type="button" onclick="alert(document.getElementById('s4').length)" value="Check length = 4"></input>
  
  <br>Expected results:  A popup menu - group label, option, separator (incl. in group).
  <br><select id = "s5">
  <optgroup label="Group 1">
  <option>opt 1</option>
  <hr>
  </optgroup>
  </select>
  <input type="button" onclick="alert(document.getElementById('s5').length)" value="Check length = 1"></input>
  
  <br>Expected results:  A popup menu - separator, group label, option.
  <br><select id = "s6">
  <hr>
  <optgroup label="Group 1">
  <option>opt 1</option>
  </optgroup>
  </select>
  <input type="button" onclick="alert(document.getElementById('s6').length)" value="Check length = 1"></input>
  
  <br>Expected results:  A popup menu - group label, option, separator, option, separator, option, two separators, (end of group), one option.
  <br><select id = "s7">
  <optgroup label="Group 1">
  <option>opt 1</option>
  <hr>
  <option>opt 2</option>
  <hr>
  <option>opt 3</option>
  <hr>
  <hr>
  </optgroup>
  <option>opt 4</option>
  </select>
  <input type="button" onclick="alert(document.getElementById('s7').length)" value="Check length = 4"></input>
  
  <br>Expected results:  A popup menu - group label, one option two separators, (end of group), separator, group label, separator, two options, separator, (end of group), option.
  <br><select id = "s8">
  <optgroup label="Group 1">
  <option>opt 1</option>
  <hr>
  <hr>
  </optgroup>
  <hr>
  <optgroup label="Group 2">
  <hr>
  <option>opt 2</option>
  <option>opt 3</option>
  <hr>
  </optgroup>
  <option>opt 4</option>
  </select>
  <input type="button" onclick="alert(document.getElementById('s8').length)" value="Check length = 4"></input>
  
  <br>Expected results:  A disabled popup menu.
  <br><select id = "s9">
  <optgroup label="Group 1">
  <hr>
  </optgroup>
  </select>
  <input type="button" onclick="alert(document.getElementById('s9').length)" value="Check length = 0"></input>
  
  <br>Expected results:  A list box - 4 options.
  <br><select id = "s10" multiple>
  <option value="test">opt 1</option>
  <hr>
  <hr>
  <hr>
  <hr>
  <option>opt 2</option>
  <option>opt 3</option>
  <hr>
  <option>opt 4</option>
  </select>
  <input type="button" onclick="alert(document.getElementById('s10').length)" value="Check length = 4"></input>
  
  <br>Expected results:  A list box - one option, group label, 3 options.
  <br><select id = "s11" multiple>
  <option value="test">opt 1</option>
  <hr>
  <hr>
  <optgroup label="Group 1">
  <hr>
  <hr>
  <option>opt 2</option>
  <option>opt 3</option>
  <hr>
  <option>opt 4</option>
  </optgroup>
  </select>
  <input type="button" onclick="alert(document.getElementById('s11').length)" value="Check length = 4"></input>
  
  <body>
  </html>
  
  
  
  



More information about the webkit-changes mailing list