Changeset 53761 in webkit


Ignore:
Timestamp:
Jan 22, 2010 10:19:10 PM (14 years ago)
Author:
eric@webkit.org
Message:

2010-01-22 James Robinson <jamesr@chromium.org>

Reviewed by Alexey Proskuryakov.

Adds tests for the 'selected' attribute of <option>s
https://bugs.webkit.org/show_bug.cgi?id=32641

HTMLOptionElement_selected2 checks that the selected attribute is up to date immediately after the <select>
parsed. HTMLOptionElement_selected3 does the same, but checks immediately prior to the </select>.

Also changes the expectation for add-remove-option-modification-event to reflect that we now pass.

  • fast/forms/HTMLOptionElement_selected-expected.txt:
  • fast/forms/HTMLOptionElement_selected.html:
  • fast/forms/HTMLOptionElement_selected2-expected.txt: Added.
  • fast/forms/HTMLOptionElement_selected2.html: Added.
  • fast/forms/HTMLOptionElement_selected3-expected.txt: Added.
  • fast/forms/HTMLOptionElement_selected3.html: Added.
  • fast/forms/add-remove-option-modification-event-expected.txt:

2010-01-22 James Robinson <jamesr@chromium.org>

Reviewed by Alexey Proskuryakov.

Ensures that the 'selected' attribute of an <option> is correct
https://bugs.webkit.org/show_bug.cgi?id=32641

Adds a check in OptionElement::selected() that checks if list items need to be recalculated and does so if needed,
so the attribute is up to date more often. Also gets rid of most of the recalcStyle() side effects.

Our behavior now matches Firefox 3.5 and IE8 after the </select> is parsed.

Tests: fast/forms/HTMLOptionElement_selected2.html

fast/forms/HTMLOptionElement_selected3.html

  • dom/SelectElement.cpp: (WebCore::SelectElement::setOptionsChangedOnRenderer): (WebCore::SelectElement::setRecalcListItems): (WebCore::SelectElement::recalcListItems): (WebCore::SelectElement::restoreFormControlState): (WebCore::SelectElement::reset): (WebCore::SelectElement::typeAheadFind):
  • dom/SelectElement.h:
  • html/HTMLOptionElement.cpp: (WebCore::HTMLOptionElement::selected): (WebCore::HTMLOptionElement::insertedIntoTree):
  • html/HTMLSelectElement.cpp: (WebCore::HTMLSelectElement::recalcStyle): (WebCore::HTMLSelectElement::recalcListItemsIfNeeded):
  • html/HTMLSelectElement.h:
  • wml/WMLSelectElement.cpp: (WebCore::WMLSelectElement::recalcStyle):
Location:
trunk
Files:
4 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r53758 r53761  
     12010-01-22  James Robinson  <jamesr@chromium.org>
     2
     3        Reviewed by Alexey Proskuryakov.
     4
     5        Adds tests for the 'selected' attribute of <option>s
     6        https://bugs.webkit.org/show_bug.cgi?id=32641
     7
     8        HTMLOptionElement_selected2 checks that the selected attribute is up to date immediately after the <select>
     9        parsed.  HTMLOptionElement_selected3 does the same, but checks immediately prior to the </select>.
     10
     11        Also changes the expectation for add-remove-option-modification-event to reflect that we now pass.
     12
     13        * fast/forms/HTMLOptionElement_selected-expected.txt:
     14        * fast/forms/HTMLOptionElement_selected.html:
     15        * fast/forms/HTMLOptionElement_selected2-expected.txt: Added.
     16        * fast/forms/HTMLOptionElement_selected2.html: Added.
     17        * fast/forms/HTMLOptionElement_selected3-expected.txt: Added.
     18        * fast/forms/HTMLOptionElement_selected3.html: Added.
     19        * fast/forms/add-remove-option-modification-event-expected.txt:
     20
    1212010-01-22  Steve VanDeBogart  <vandebo@chromium.org>
    222
  • trunk/LayoutTests/fast/forms/HTMLOptionElement_selected-expected.txt

    r53252 r53761  
    22
    33true
     40
    45true
    56
  • trunk/LayoutTests/fast/forms/HTMLOptionElement_selected.html

    r53252 r53761  
    1111            var theOption = document.getElementById('theOption');
    1212            console.innerHTML += theOption.selected + "<br>";
    13             theOption.parentNode.selectedIndex;
     13            console.innerHTML += theOption.parentNode.selectedIndex + "<br>";
    1414            console.innerHTML += theOption.selected + "<br>";
    1515        }
  • trunk/LayoutTests/fast/forms/add-remove-option-modification-event-expected.txt

    r53252 r53761  
    33 
    44
    5 Failed
    6      Expected: true
    7      Actual: false
    8 
    95Passed
    106Passed
     7Passed
  • trunk/WebCore/ChangeLog

    r53760 r53761  
     12010-01-22  James Robinson  <jamesr@chromium.org>
     2
     3        Reviewed by Alexey Proskuryakov.
     4
     5        Ensures that the 'selected' attribute of an <option> is correct
     6        https://bugs.webkit.org/show_bug.cgi?id=32641
     7
     8        Adds a check in OptionElement::selected() that checks if list items need to be recalculated and does so if needed,
     9        so the attribute is up to date more often.  Also gets rid of most of the recalcStyle() side effects.
     10
     11         Our behavior now matches Firefox 3.5 and IE8 after the </select> is parsed.
     12
     13         Tests: fast/forms/HTMLOptionElement_selected2.html
     14                fast/forms/HTMLOptionElement_selected3.html
     15
     16        * dom/SelectElement.cpp:
     17        (WebCore::SelectElement::setOptionsChangedOnRenderer):
     18        (WebCore::SelectElement::setRecalcListItems):
     19        (WebCore::SelectElement::recalcListItems):
     20        (WebCore::SelectElement::restoreFormControlState):
     21        (WebCore::SelectElement::reset):
     22        (WebCore::SelectElement::typeAheadFind):
     23        * dom/SelectElement.h:
     24        * html/HTMLOptionElement.cpp:
     25        (WebCore::HTMLOptionElement::selected):
     26        (WebCore::HTMLOptionElement::insertedIntoTree):
     27        * html/HTMLSelectElement.cpp:
     28        (WebCore::HTMLSelectElement::recalcStyle):
     29        (WebCore::HTMLSelectElement::recalcListItemsIfNeeded):
     30        * html/HTMLSelectElement.h:
     31        * wml/WMLSelectElement.cpp:
     32        (WebCore::WMLSelectElement::recalcStyle):
     33
    1342010-01-22  Chris Rogers  <crogers@google.com>
    235
  • trunk/WebCore/dom/SelectElement.cpp

    r53252 r53761  
    223223}
    224224
    225 void SelectElement::recalcStyle(SelectElementData& data, Element* element)
    226 {
    227     RenderObject* renderer = element->renderer();
    228     if (element->childNeedsStyleRecalc() && renderer) {
    229         if (data.usesMenuList())
    230             toRenderMenuList(renderer)->setOptionsChanged(true);
    231         else
    232             toRenderListBox(renderer)->setOptionsChanged(true);
    233     } else if (data.shouldRecalcListItems())
    234         recalcListItems(data, element);
    235 }
    236 
    237 void SelectElement::setRecalcListItems(SelectElementData& data, Element* element)
    238 {
    239     data.setShouldRecalcListItems(true);
    240     data.setActiveSelectionAnchorIndex(-1); // Manual selection anchor is reset when manipulating the select programmatically.
     225void SelectElement::setOptionsChangedOnRenderer(SelectElementData& data, Element* element)
     226{
    241227    if (RenderObject* renderer = element->renderer()) {
    242228        if (data.usesMenuList())
     
    245231            toRenderListBox(renderer)->setOptionsChanged(true);
    246232    }
     233}
     234
     235void SelectElement::setRecalcListItems(SelectElementData& data, Element* element)
     236{
     237    data.setShouldRecalcListItems(true);
     238    data.setActiveSelectionAnchorIndex(-1); // Manual selection anchor is reset when manipulating the select programmatically.
     239    setOptionsChangedOnRenderer(data, element);
    247240    element->setNeedsStyleRecalc();
    248241}
     
    252245    Vector<Element*>& listItems = data.rawListItems();
    253246    listItems.clear();
     247
     248    data.setShouldRecalcListItems(false);
    254249
    255250    OptionElement* foundSelected = 0;
     
    298293        currentNode = currentNode->traverseNextSibling(element);
    299294    }
    300 
    301     data.setShouldRecalcListItems(false);
    302295}
    303296
     
    448441    }
    449442
    450     element->setNeedsStyleRecalc();
     443    setOptionsChangedOnRenderer(data, element);
    451444}
    452445
     
    522515        firstOption->setSelectedState(true);
    523516
     517    setOptionsChangedOnRenderer(data, element);
    524518    element->setNeedsStyleRecalc();
    525519}
     
    896890            if (!data.usesMenuList())
    897891                listBoxOnChange(data, element);
     892
     893            setOptionsChangedOnRenderer(data, element);
    898894            element->setNeedsStyleRecalc();
    899895            return;
  • trunk/WebCore/dom/SelectElement.h

    r53252 r53761  
    7676    static void menuListOnChange(SelectElementData&, Element*);
    7777    static void scrollToSelection(SelectElementData&, Element*);
    78     static void recalcStyle(SelectElementData&, Element*);
    7978    static void setRecalcListItems(SelectElementData&, Element*);
    8079    static void recalcListItems(SelectElementData&, const Element*, bool updateSelectedStates = true);
     
    101100    static void menuListDefaultEventHandler(SelectElementData&, Element*, Event*, HTMLFormElement*);
    102101    static void listBoxDefaultEventHandler(SelectElementData&, Element*, Event*, HTMLFormElement*);
     102    static void setOptionsChangedOnRenderer(SelectElementData&, Element*);
    103103};
    104104
  • trunk/WebCore/html/HTMLOptionElement.cpp

    r53512 r53761  
    138138bool HTMLOptionElement::selected() const
    139139{
     140    if (HTMLSelectElement* select = ownerSelectElement())
     141        select->recalcListItemsIfNeeded();
    140142    return m_data.selected();
    141143}
     
    221223    if (HTMLSelectElement* select = ownerSelectElement()) {
    222224        select->setRecalcListItems();
    223         if (selected())
     225        // Avoid our selected() getter since it will recalculate list items incorrectly for us.
     226        if (m_data.selected())
    224227            select->setSelectedIndex(index(), false);
    225228        select->scrollToSelection();
  • trunk/WebCore/html/HTMLSelectElement.cpp

    r53252 r53761  
    55 * Copyright (C) 2004, 2005, 2006, 2007, 2009 Apple Inc. All rights reserved.
    66 *           (C) 2006 Alexey Proskuryakov (ap@nypop.com)
     7 * Copyright (C) 2010 Google Inc. All rights reserved.
    78 *
    89 * This library is free software; you can redistribute it and/or
     
    6061void HTMLSelectElement::recalcStyle(StyleChange change)
    6162{
    62     SelectElement::recalcStyle(m_data, this);
    6363    HTMLFormControlElementWithState::recalcStyle(change);
    6464}
     
    262262}
    263263
     264void HTMLSelectElement::recalcListItemsIfNeeded()
     265{
     266    if (m_data.shouldRecalcListItems())
     267        recalcListItems();
     268}
     269
    264270void HTMLSelectElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
    265271{
  • trunk/WebCore/html/HTMLSelectElement.h

    r53252 r53761  
    44 *           (C) 2000 Dirk Mueller (mueller@kde.org)
    55 * Copyright (C) 2004, 2005, 2006, 2007, 2009 Apple Inc. All rights reserved.
     6 * Copyright (C) 2010 Google Inc. All rights reserved.
    67 *
    78 * This library is free software; you can redistribute it and/or
     
    5960
    6061    void setRecalcListItems();
     62    void recalcListItemsIfNeeded();
    6163
    6264    virtual const Vector<Element*>& listItems() const { return m_data.listItems(this); }
  • trunk/WebCore/wml/WMLSelectElement.cpp

    r53252 r53761  
    8484void WMLSelectElement::recalcStyle(StyleChange change)
    8585{
    86     SelectElement::recalcStyle(m_data, this);
    8786    WMLFormControlElement::recalcStyle(change);
    8887}
Note: See TracChangeset for help on using the changeset viewer.