Changeset 97238 in webkit


Ignore:
Timestamp:
Oct 12, 2011 12:14:12 AM (13 years ago)
Author:
tkent@chromium.org
Message:

Move the content of SelectElementData into HTMLSelectElement, and remove SelectElement.{cpp,h}
https://bugs.webkit.org/show_bug.cgi?id=69828

Reviewed by Darin Adler.

  • Move all of the data members of SelectElementData to

HTMLSelectElement, and their accessor functions are not needed
anymore.

  • Move SelectElementData::useMenuList() to HTMLSelectElement.

No new tests, just a refactoring.

  • CMakeLists.txt: Remove SelectElement.cpp.
  • WebCore.gypi: Remove SelectElement.{cpp,h}.
  • WebCore.pro: ditto.
  • WebCore.vcproj/WebCore.vcproj: ditto.
  • WebCore.xcodeproj/project.pbxproj: ditto.
  • dom/OptionElement.cpp: Remove a reference to SelectElement.h.
  • dom/SelectElement.cpp: Removed.
  • dom/SelectElement.h: Removed.
  • html/HTMLSelectElement.cpp:

(WebCore::HTMLSelectElement::HTMLSelectElement):
Initializes the moved data members.
(WebCore::HTMLSelectElement::formControlType):
(WebCore::HTMLSelectElement::setSelectedIndexByUser):
(WebCore::HTMLSelectElement::activeSelectionStartListIndex):
(WebCore::HTMLSelectElement::activeSelectionEndListIndex):
(WebCore::HTMLSelectElement::parseMappedAttribute):
(WebCore::HTMLSelectElement::canSelectAll):
(WebCore::HTMLSelectElement::createRenderer):
(WebCore::HTMLSelectElement::setOption):
(WebCore::HTMLSelectElement::selectAll):
(WebCore::HTMLSelectElement::saveLastSelection):
(WebCore::HTMLSelectElement::setActiveSelectionAnchorIndex):
(WebCore::HTMLSelectElement::setActiveSelectionEndIndex):
(WebCore::HTMLSelectElement::updateListBoxSelection):
(WebCore::HTMLSelectElement::listBoxOnChange):
(WebCore::HTMLSelectElement::menuListOnChange):
(WebCore::HTMLSelectElement::scrollToSelection):
(WebCore::HTMLSelectElement::setOptionsChangedOnRenderer):
(WebCore::HTMLSelectElement::setRecalcListItems):
(WebCore::HTMLSelectElement::recalcListItemsInternal):
(WebCore::HTMLSelectElement::setSelectedIndexInternal):
(WebCore::HTMLSelectElement::dispatchFocusEvent):
(WebCore::HTMLSelectElement::dispatchBlurEvent):
(WebCore::HTMLSelectElement::parseMultipleAttribute):
(WebCore::HTMLSelectElement::reset):
(WebCore::HTMLSelectElement::menuListDefaultEventHandler):
(WebCore::HTMLSelectElement::updateSelectedState):
(WebCore::HTMLSelectElement::listBoxDefaultEventHandler):
(WebCore::HTMLSelectElement::defaultEventHandler):
(WebCore::HTMLSelectElement::typeAheadFind):
(WebCore::HTMLSelectElement::accessKeySetSelectedIndex):

  • html/HTMLSelectElement.h:

(WebCore::HTMLSelectElement::size):
(WebCore::HTMLSelectElement::multiple):
(WebCore::HTMLSelectElement::usesMenuList):

Location:
trunk/Source/WebCore
Files:
2 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/CMakeLists.txt

    r97227 r97238  
    581581    dom/ScriptExecutionContext.cpp
    582582    dom/ScriptRunner.cpp
    583     dom/SelectElement.cpp
    584583    dom/SelectorQuery.cpp
    585584    dom/ShadowContentElement.cpp
  • trunk/Source/WebCore/ChangeLog

    r97237 r97238  
     12011-10-12  Kent Tamura  <tkent@chromium.org>
     2
     3        Move the content of SelectElementData into HTMLSelectElement, and remove SelectElement.{cpp,h}
     4        https://bugs.webkit.org/show_bug.cgi?id=69828
     5
     6        Reviewed by Darin Adler.
     7
     8        - Move all of the data members of SelectElementData to
     9        HTMLSelectElement, and their accessor functions are not needed
     10        anymore.
     11        - Move SelectElementData::useMenuList() to HTMLSelectElement.
     12
     13        No new tests, just a refactoring.
     14
     15        * CMakeLists.txt: Remove SelectElement.cpp.
     16        * WebCore.gypi: Remove SelectElement.{cpp,h}.
     17        * WebCore.pro: ditto.
     18        * WebCore.vcproj/WebCore.vcproj: ditto.
     19        * WebCore.xcodeproj/project.pbxproj: ditto.
     20        * dom/OptionElement.cpp: Remove a reference to SelectElement.h.
     21        * dom/SelectElement.cpp: Removed.
     22        * dom/SelectElement.h: Removed.
     23        * html/HTMLSelectElement.cpp:
     24        (WebCore::HTMLSelectElement::HTMLSelectElement):
     25        Initializes the moved data members.
     26        (WebCore::HTMLSelectElement::formControlType):
     27        (WebCore::HTMLSelectElement::setSelectedIndexByUser):
     28        (WebCore::HTMLSelectElement::activeSelectionStartListIndex):
     29        (WebCore::HTMLSelectElement::activeSelectionEndListIndex):
     30        (WebCore::HTMLSelectElement::parseMappedAttribute):
     31        (WebCore::HTMLSelectElement::canSelectAll):
     32        (WebCore::HTMLSelectElement::createRenderer):
     33        (WebCore::HTMLSelectElement::setOption):
     34        (WebCore::HTMLSelectElement::selectAll):
     35        (WebCore::HTMLSelectElement::saveLastSelection):
     36        (WebCore::HTMLSelectElement::setActiveSelectionAnchorIndex):
     37        (WebCore::HTMLSelectElement::setActiveSelectionEndIndex):
     38        (WebCore::HTMLSelectElement::updateListBoxSelection):
     39        (WebCore::HTMLSelectElement::listBoxOnChange):
     40        (WebCore::HTMLSelectElement::menuListOnChange):
     41        (WebCore::HTMLSelectElement::scrollToSelection):
     42        (WebCore::HTMLSelectElement::setOptionsChangedOnRenderer):
     43        (WebCore::HTMLSelectElement::setRecalcListItems):
     44        (WebCore::HTMLSelectElement::recalcListItemsInternal):
     45        (WebCore::HTMLSelectElement::setSelectedIndexInternal):
     46        (WebCore::HTMLSelectElement::dispatchFocusEvent):
     47        (WebCore::HTMLSelectElement::dispatchBlurEvent):
     48        (WebCore::HTMLSelectElement::parseMultipleAttribute):
     49        (WebCore::HTMLSelectElement::reset):
     50        (WebCore::HTMLSelectElement::menuListDefaultEventHandler):
     51        (WebCore::HTMLSelectElement::updateSelectedState):
     52        (WebCore::HTMLSelectElement::listBoxDefaultEventHandler):
     53        (WebCore::HTMLSelectElement::defaultEventHandler):
     54        (WebCore::HTMLSelectElement::typeAheadFind):
     55        (WebCore::HTMLSelectElement::accessKeySetSelectedIndex):
     56        * html/HTMLSelectElement.h:
     57        (WebCore::HTMLSelectElement::size):
     58        (WebCore::HTMLSelectElement::multiple):
     59        (WebCore::HTMLSelectElement::usesMenuList):
     60
    1612011-10-12  Ryosuke Niwa  <rniwa@webkit.org>
    262
  • trunk/Source/WebCore/WebCore.gypi

    r97227 r97238  
    52885288            'dom/ScriptedAnimationController.cpp',
    52895289            'dom/ScriptedAnimationController.h',
    5290             'dom/SelectElement.cpp',
    5291             'dom/SelectElement.h',
    52925290            'dom/SelectorQuery.cpp',
    52935291            'dom/SelectorQuery.h',
  • trunk/Source/WebCore/WebCore.pro

    r97227 r97238  
    549549    dom/ScriptExecutionContext.cpp \
    550550    dom/ScriptRunner.cpp \
    551     dom/SelectElement.cpp \
    552551    dom/SelectorQuery.cpp \
    553552    dom/ShadowContentElement.cpp \
     
    15651564    dom/ScriptElement.h \
    15661565    dom/ScriptExecutionContext.h \
    1567     dom/SelectElement.h \
    15681566    dom/SelectorQuery.h \
    15691567    dom/ShadowContentElement.h \
  • trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj

    r97227 r97238  
    4877148771                        </File>
    4877248772                        <File
    48773                                 RelativePath="..\dom\SelectElement.cpp"
    48774                                 >
    48775                                 <FileConfiguration
    48776                                         Name="Debug|Win32"
    48777                                         ExcludedFromBuild="true"
    48778                                         >
    48779                                         <Tool
    48780                                                 Name="VCCLCompilerTool"
    48781                                         />
    48782                                 </FileConfiguration>
    48783                                 <FileConfiguration
    48784                                         Name="Release|Win32"
    48785                                         ExcludedFromBuild="true"
    48786                                         >
    48787                                         <Tool
    48788                                                 Name="VCCLCompilerTool"
    48789                                         />
    48790                                 </FileConfiguration>
    48791                                 <FileConfiguration
    48792                                         Name="Debug_Cairo_CFLite|Win32"
    48793                                         ExcludedFromBuild="true"
    48794                                         >
    48795                                         <Tool
    48796                                                 Name="VCCLCompilerTool"
    48797                                         />
    48798                                 </FileConfiguration>
    48799                                 <FileConfiguration
    48800                                         Name="Release_Cairo_CFLite|Win32"
    48801                                         ExcludedFromBuild="true"
    48802                                         >
    48803                                         <Tool
    48804                                                 Name="VCCLCompilerTool"
    48805                                         />
    48806                                 </FileConfiguration>
    48807                                 <FileConfiguration
    48808                                         Name="Debug_All|Win32"
    48809                                         ExcludedFromBuild="true"
    48810                                         >
    48811                                         <Tool
    48812                                                 Name="VCCLCompilerTool"
    48813                                         />
    48814                                 </FileConfiguration>
    48815                                 <FileConfiguration
    48816                                         Name="Production|Win32"
    48817                                         ExcludedFromBuild="true"
    48818                                         >
    48819                                         <Tool
    48820                                                 Name="VCCLCompilerTool"
    48821                                         />
    48822                                 </FileConfiguration>
    48823                         </File>
    48824                         <File
    48825                                 RelativePath="..\dom\SelectElement.h"
    48826                                 >
    48827                         </File>
    48828                         <File
    4882948773                                RelativePath="..\dom\SelectorQuery.cpp"
    4883048774                                >
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r97227 r97238  
    110110                0845680812B90DA600960A9F /* FontMetrics.h in Headers */ = {isa = PBXBuildFile; fileRef = 0845680712B90DA600960A9F /* FontMetrics.h */; settings = {ATTRIBUTES = (Private, ); }; };
    111111                084A0829128D7867002DB1F1 /* SVGPathSegListPropertyTearOff.h in Headers */ = {isa = PBXBuildFile; fileRef = 084A0828128D7867002DB1F1 /* SVGPathSegListPropertyTearOff.h */; };
    112                 084AEBE40FB505FA0038483E /* SelectElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 084AEBE20FB505FA0038483E /* SelectElement.cpp */; };
    113                 084AEBE50FB505FA0038483E /* SelectElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 084AEBE30FB505FA0038483E /* SelectElement.h */; };
    114112                084DB59B128008CC002A6D64 /* SVGAnimatedString.h in Headers */ = {isa = PBXBuildFile; fileRef = 084DB59A128008CC002A6D64 /* SVGAnimatedString.h */; settings = {ATTRIBUTES = (Private, ); }; };
    115113                08525E631278C00100A84778 /* SVGAnimatedStaticPropertyTearOff.h in Headers */ = {isa = PBXBuildFile; fileRef = 08525E621278C00100A84778 /* SVGAnimatedStaticPropertyTearOff.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    71227120                0845680712B90DA600960A9F /* FontMetrics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FontMetrics.h; sourceTree = "<group>"; };
    71237121                084A0828128D7867002DB1F1 /* SVGPathSegListPropertyTearOff.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGPathSegListPropertyTearOff.h; sourceTree = "<group>"; };
    7124                 084AEBE20FB505FA0038483E /* SelectElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SelectElement.cpp; sourceTree = "<group>"; };
    7125                 084AEBE30FB505FA0038483E /* SelectElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SelectElement.h; sourceTree = "<group>"; };
    71267122                084DB59A128008CC002A6D64 /* SVGAnimatedString.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGAnimatedString.h; sourceTree = "<group>"; };
    71277123                08525E621278C00100A84778 /* SVGAnimatedStaticPropertyTearOff.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVGAnimatedStaticPropertyTearOff.h; sourceTree = "<group>"; };
     
    2120121197                                8A413ADF1207BBA50082016E /* ScriptRunner.cpp */,
    2120221198                                8A413ADE1207BBA50082016E /* ScriptRunner.h */,
    21203                                 084AEBE20FB505FA0038483E /* SelectElement.cpp */,
    21204                                 084AEBE30FB505FA0038483E /* SelectElement.h */,
    2120521199                                E45322A9140CE267005A0F92 /* SelectorQuery.cpp */,
    2120621200                                E45322AA140CE267005A0F92 /* SelectorQuery.h */,
     
    2399023984                                371F4FFC0D25E7F300ECE0D5 /* SegmentedFontData.h in Headers */,
    2399123985                                B2C3DA2F0D006C1D00EF6F26 /* SegmentedString.h in Headers */,
    23992                                 084AEBE50FB505FA0038483E /* SelectElement.h in Headers */,
    2399323986                                A75E497610752ACB00C9B896 /* SerializedScriptValue.h in Headers */,
    2399423987                                93309E10099E64920056E581 /* SetNodeAttributeCommand.h in Headers */,
     
    2697526968                                371F4FFD0D25E7F300ECE0D5 /* SegmentedFontData.cpp in Sources */,
    2697626969                                B2C3DA2E0D006C1D00EF6F26 /* SegmentedString.cpp in Sources */,
    26977                                 084AEBE40FB505FA0038483E /* SelectElement.cpp in Sources */,
    2697826970                                A75E497710752ACB00C9B896 /* SerializedScriptValue.cpp in Sources */,
    2697926971                                93309E0F099E64920056E581 /* SetNodeAttributeCommand.cpp in Sources */,
  • trunk/Source/WebCore/dom/OptionElement.cpp

    r96907 r97238  
    3030#include "OptionGroupElement.h"
    3131#include "ScriptElement.h"
    32 #include "SelectElement.h"
    3332#include <wtf/Assertions.h>
    3433
  • trunk/Source/WebCore/html/HTMLSelectElement.cpp

    r97135 r97238  
    7777HTMLSelectElement::HTMLSelectElement(const QualifiedName& tagName, Document* document, HTMLFormElement* form)
    7878    : HTMLFormControlElementWithState(tagName, document, form)
     79    , m_lastCharTime(0)
     80    , m_size(0)
     81    , m_lastOnChangeIndex(-1)
     82    , m_activeSelectionAnchorIndex(-1)
     83    , m_activeSelectionEndIndex(-1)
     84    , m_repeatingChar(0)
     85    , m_userDrivenChange(false)
     86    , m_multiple(false)
     87    , m_activeSelectionState(false)
    7988    , m_recalcListItems(false)
    8089{
     
    92101    DEFINE_STATIC_LOCAL(const AtomicString, selectMultiple, ("select-multiple"));
    93102    DEFINE_STATIC_LOCAL(const AtomicString, selectOne, ("select-one"));
    94     return m_data.multiple() ? selectMultiple : selectOne;
     103    return m_multiple ? selectMultiple : selectOne;
    95104}
    96105
     
    110119    // List box selects can fire onchange events through user interaction, such as
    111120    // mousedown events. This allows that same behavior programmatically.
    112     if (!m_data.usesMenuList()) {
     121    if (!usesMenuList()) {
    113122        updateSelectedState(optionIndex, allowMultipleSelection, false);
    114123        setNeedsValidityCheck();
     
    177186int HTMLSelectElement::activeSelectionStartListIndex() const
    178187{
    179     if (m_data.activeSelectionAnchorIndex() >= 0)
    180         return m_data.activeSelectionAnchorIndex();
     188    if (m_activeSelectionAnchorIndex >= 0)
     189        return m_activeSelectionAnchorIndex;
    181190    return optionToListIndex(selectedIndex());
    182191}
     
    184193int HTMLSelectElement::activeSelectionEndListIndex() const
    185194{
    186     if (m_data.activeSelectionEndIndex() >= 0)
    187         return m_data.activeSelectionEndIndex();
     195    if (m_activeSelectionEndIndex >= 0)
     196        return m_activeSelectionEndIndex;
    188197    return lastSelectedListIndex();
    189198}
     
    251260{
    252261    if (attr->name() == sizeAttr) {
    253         int oldSize = m_data.size();
     262        int oldSize = m_size;
    254263        // Set the attribute value to a number.
    255264        // This is important since the style rules for this attribute can determine the appearance property.
     
    264273            recalcListItemsIfNeeded();
    265274
    266         m_data.setSize(size);
     275        m_size = size;
    267276        setNeedsValidityCheck();
    268         if (m_data.size() != oldSize && attached()) {
     277        if (m_size != oldSize && attached()) {
    269278            reattach();
    270279            setRecalcListItems();
     
    299308bool HTMLSelectElement::canSelectAll() const
    300309{
    301     return !m_data.usesMenuList();
     310    return !usesMenuList();
    302311}
    303312
    304313RenderObject* HTMLSelectElement::createRenderer(RenderArena* arena, RenderStyle*)
    305314{
    306     if (m_data.usesMenuList())
     315    if (usesMenuList())
    307316        return new (arena) RenderMenuList(this);
    308317    return new (arena) RenderListBox(this);
     
    387396        add(option, before, ec);
    388397        if (diff >= 0 && option->selected())
    389             setSelectedIndex(index, !m_data.multiple());
     398            setSelectedIndex(index, !m_multiple);
    390399    }
    391400}
     
    501510void HTMLSelectElement::selectAll()
    502511{
    503     ASSERT(!m_data.usesMenuList());
    504     if (!renderer() || !m_data.multiple())
     512    ASSERT(!usesMenuList());
     513    if (!renderer() || !m_multiple)
    505514        return;
    506515
     
    509518    saveLastSelection();
    510519
    511     m_data.setActiveSelectionState(true);
     520    m_activeSelectionState = true;
    512521    setActiveSelectionAnchorIndex(nextSelectableListIndex(-1));
    513522    setActiveSelectionEndIndex(previousSelectableListIndex(-1));
     
    520529void HTMLSelectElement::saveLastSelection()
    521530{
    522     if (m_data.usesMenuList()) {
    523         m_data.setLastOnChangeIndex(selectedIndex());
     531    if (usesMenuList()) {
     532        m_lastOnChangeIndex = selectedIndex();
    524533        return;
    525534    }
    526535
    527     Vector<bool>& lastOnChangeSelection = m_data.lastOnChangeSelection();
    528     lastOnChangeSelection.clear();
    529 
     536    m_lastOnChangeSelection.clear();
    530537    const Vector<Element*>& items = listItems();
    531538    for (unsigned i = 0; i < items.size(); ++i) {
    532539        OptionElement* optionElement = toOptionElement(items[i]);
    533         lastOnChangeSelection.append(optionElement && optionElement->selected());
     540        m_lastOnChangeSelection.append(optionElement && optionElement->selected());
    534541    }
    535542}
     
    537544void HTMLSelectElement::setActiveSelectionAnchorIndex(int index)
    538545{
    539     m_data.setActiveSelectionAnchorIndex(index);
     546    m_activeSelectionAnchorIndex = index;
    540547
    541548    // Cache the selection state so we can restore the old selection as the new
    542549    // selection pivots around this anchor index
    543     Vector<bool>& cachedStateForActiveSelection = m_data.cachedStateForActiveSelection();
    544     cachedStateForActiveSelection.clear();
     550    m_cachedStateForActiveSelection.clear();
    545551
    546552    const Vector<Element*>& items = listItems();
    547553    for (unsigned i = 0; i < items.size(); ++i) {
    548554        OptionElement* optionElement = toOptionElement(items[i]);
    549         cachedStateForActiveSelection.append(optionElement && optionElement->selected());
     555        m_cachedStateForActiveSelection.append(optionElement && optionElement->selected());
    550556    }
    551557}
     
    553559void HTMLSelectElement::setActiveSelectionEndIndex(int index)
    554560{
    555     m_data.setActiveSelectionEndIndex(index);
     561    m_activeSelectionEndIndex = index;
    556562}
    557563
    558564void HTMLSelectElement::updateListBoxSelection(bool deselectOtherOptions)
    559565{
    560     ASSERT(renderer() && (renderer()->isListBox() || m_data.multiple()));
    561     ASSERT(!listItems().size() || m_data.activeSelectionAnchorIndex() >= 0);
    562 
    563     unsigned start = min(m_data.activeSelectionAnchorIndex(), m_data.activeSelectionEndIndex());
    564     unsigned end = max(m_data.activeSelectionAnchorIndex(), m_data.activeSelectionEndIndex());
    565     Vector<bool>& cachedStateForActiveSelection = m_data.cachedStateForActiveSelection();
     566    ASSERT(renderer() && (renderer()->isListBox() || m_multiple));
     567    ASSERT(!listItems().size() || m_activeSelectionAnchorIndex >= 0);
     568
     569    unsigned start = min(m_activeSelectionAnchorIndex, m_activeSelectionEndIndex);
     570    unsigned end = max(m_activeSelectionAnchorIndex, m_activeSelectionEndIndex);
    566571
    567572    const Vector<Element*>& items = listItems();
     
    572577
    573578        if (i >= start && i <= end)
    574             optionElement->setSelectedState(m_data.activeSelectionState());
    575         else if (deselectOtherOptions || i >= cachedStateForActiveSelection.size())
     579            optionElement->setSelectedState(m_activeSelectionState);
     580        else if (deselectOtherOptions || i >= m_cachedStateForActiveSelection.size())
    576581            optionElement->setSelectedState(false);
    577582        else
    578             optionElement->setSelectedState(cachedStateForActiveSelection[i]);
     583            optionElement->setSelectedState(m_cachedStateForActiveSelection[i]);
    579584    }
    580585
     
    585590void HTMLSelectElement::listBoxOnChange()
    586591{
    587     ASSERT(!m_data.usesMenuList() || m_data.multiple());
    588 
    589     Vector<bool>& lastOnChangeSelection = m_data.lastOnChangeSelection();
     592    ASSERT(!usesMenuList() || m_multiple);
     593
    590594    const Vector<Element*>& items = listItems();
    591595
    592596    // If the cached selection list is empty, or the size has changed, then fire
    593597    // dispatchFormControlChangeEvent, and return early.
    594     if (lastOnChangeSelection.isEmpty() || lastOnChangeSelection.size() != items.size()) {
     598    if (m_lastOnChangeSelection.isEmpty() || m_lastOnChangeSelection.size() != items.size()) {
    595599        dispatchFormControlChangeEvent();
    596600        return;
     
    602606        OptionElement* optionElement = toOptionElement(items[i]);
    603607        bool selected = optionElement && optionElement->selected();
    604         if (selected != lastOnChangeSelection[i])
     608        if (selected != m_lastOnChangeSelection[i])
    605609            fireOnChange = true;
    606         lastOnChangeSelection[i] = selected;
     610        m_lastOnChangeSelection[i] = selected;
    607611    }
    608612
     
    613617void HTMLSelectElement::menuListOnChange()
    614618{
    615     ASSERT(m_data.usesMenuList());
     619    ASSERT(usesMenuList());
    616620
    617621    int selected = selectedIndex();
    618     if (m_data.lastOnChangeIndex() != selected && m_data.userDrivenChange()) {
    619         m_data.setLastOnChangeIndex(selected);
    620         m_data.setUserDrivenChange(false);
     622    if (m_lastOnChangeIndex != selected && m_userDrivenChange) {
     623        m_lastOnChangeIndex = selected;
     624        m_userDrivenChange = false;
    621625        dispatchFormControlChangeEvent();
    622626    }
     
    625629void HTMLSelectElement::scrollToSelection()
    626630{
    627     if (m_data.usesMenuList())
     631    if (usesMenuList())
    628632        return;
    629633
     
    635639{
    636640    if (RenderObject* renderer = this->renderer()) {
    637         if (m_data.usesMenuList())
     641        if (usesMenuList())
    638642            toRenderMenuList(renderer)->setOptionsChanged(true);
    639643        else
     
    665669    m_recalcListItems = true;
    666670    // Manual selection anchor is reset when manipulating the select programmatically.
    667     m_data.setActiveSelectionAnchorIndex(-1);
     671    m_activeSelectionAnchorIndex = -1;
    668672    setOptionsChangedOnRenderer();
    669673    setNeedsStyleRecalc();
     
    701705            m_listItems.append(current);
    702706
    703             if (updateSelectedStates && !m_data.multiple()) {
    704                 if (!foundSelected && (m_data.size() <= 1 || optionElement->selected())) {
     707            if (updateSelectedStates && !m_multiple) {
     708                if (!foundSelected && (m_size <= 1 || optionElement->selected())) {
    705709                    foundSelected = optionElement;
    706710                    foundSelected->setSelectedState(true);
     
    744748void HTMLSelectElement::setSelectedIndexInternal(int optionIndex, bool deselect, bool fireOnChangeNow, bool userDrivenChange)
    745749{
    746     if (optionIndex == -1 && !deselect && !m_data.multiple())
     750    if (optionIndex == -1 && !deselect && !m_multiple)
    747751        optionIndex = nextSelectableListIndex(-1);
    748     if (!m_data.multiple())
     752    if (!m_multiple)
    749753        deselect = true;
    750754
     
    755759    if (OptionElement* optionElement = (listIndex >= 0 ? toOptionElement(items[listIndex]) : 0)) {
    756760        excludeElement = items[listIndex];
    757         if (m_data.activeSelectionAnchorIndex() < 0 || deselect)
     761        if (m_activeSelectionAnchorIndex < 0 || deselect)
    758762            setActiveSelectionAnchorIndex(listIndex);
    759         if (m_data.activeSelectionEndIndex() < 0 || deselect)
     763        if (m_activeSelectionEndIndex < 0 || deselect)
    760764            setActiveSelectionEndIndex(listIndex);
    761765        optionElement->setSelectedState(true);
     
    772776
    773777    // This only gets called with fireOnChangeNow for menu lists.
    774     if (m_data.usesMenuList()) {
    775         m_data.setUserDrivenChange(userDrivenChange);
     778    if (usesMenuList()) {
     779        m_userDrivenChange = userDrivenChange;
    776780        if (fireOnChangeNow)
    777781            menuListOnChange();
    778782        RenderObject* renderer = this->renderer();
    779783        if (renderer) {
    780             if (m_data.usesMenuList())
     784            if (usesMenuList())
    781785                toRenderMenuList(renderer)->didSetSelectedIndex(listIndex);
    782786            else if (renderer->isListBox())
     
    829833    // Save the selection so it can be compared to the new selection when
    830834    // dispatching change events during blur event dispatchal
    831     if (m_data.usesMenuList())
     835    if (usesMenuList())
    832836        saveLastSelection();
    833837    HTMLFormControlElementWithState::dispatchFocusEvent(oldFocusedNode);
     
    839843    // change events for list boxes whenever the selection change is actually made.
    840844    // This matches other browsers' behavior.
    841     if (m_data.usesMenuList())
     845    if (usesMenuList())
    842846        menuListOnChange();
    843847    HTMLFormControlElementWithState::dispatchBlurEvent(newFocusedNode);
     
    891895void HTMLSelectElement::parseMultipleAttribute(const Attribute* attribute)
    892896{
    893     bool oldUsesMenuList = m_data.usesMenuList();
    894     m_data.setMultiple(!attribute->isNull());
     897    bool oldUsesMenuList = usesMenuList();
     898    m_multiple = !attribute->isNull();
    895899    updateValidity();
    896     if (oldUsesMenuList != m_data.usesMenuList())
     900    if (oldUsesMenuList != usesMenuList())
    897901        reattachIfAttached();
    898902}
     
    933937
    934938        if (items[i]->fastHasAttribute(selectedAttr)) {
    935             if (selectedOption && !m_data.multiple())
     939            if (selectedOption && !m_multiple)
    936940                selectedOption->setSelectedState(false);
    937941            optionElement->setSelectedState(true);
     
    944948    }
    945949
    946     if (!selectedOption && firstOption && !m_data.multiple() && m_data.size() <= 1)
     950    if (!selectedOption && firstOption && !m_multiple && m_size <= 1)
    947951        firstOption->setSelectedState(true);
    948952
     
    994998        // instead of changing the selection.
    995999        if (isSpatialNavigationEnabled(document()->frame())) {
    996             if (!m_data.activeSelectionState())
     1000            if (!m_activeSelectionState)
    9971001                return;
    9981002        }
     
    10361040        if (keyCode == ' ' && isSpatialNavigationEnabled(document()->frame())) {
    10371041            // Use space to toggle arrow key handling for selection change or spatial navigation.
    1038             m_data.setActiveSelectionState(!m_data.activeSelectionState());
     1042            m_activeSelectionState = !m_activeSelectionState;
    10391043            event->setDefaultHandled();
    10401044            return;
     
    11231127    saveLastSelection();
    11241128
    1125     m_data.setActiveSelectionState(true);
    1126 
    1127     bool shiftSelect = m_data.multiple() && shift;
    1128     bool multiSelect = m_data.multiple() && multi && !shift;
     1129    m_activeSelectionState = true;
     1130
     1131    bool shiftSelect = m_multiple && shift;
     1132    bool multiSelect = m_multiple && multi && !shift;
    11291133
    11301134    Element* clickedElement = listItems()[listIndex];
     
    11341138        // selection), should select or deselect
    11351139        if (option->selected() && multi)
    1136             m_data.setActiveSelectionState(false);
    1137 
    1138         if (!m_data.activeSelectionState())
     1140            m_activeSelectionState = false;
     1141
     1142        if (!m_activeSelectionState)
    11391143            option->setSelectedState(false);
    11401144    }
     
    11481152    // If the anchor hasn't been set, and we're doing a single selection or a
    11491153    // shift selection, then initialize the anchor to the first selected index.
    1150     if (m_data.activeSelectionAnchorIndex() < 0 && !multiSelect)
     1154    if (m_activeSelectionAnchorIndex < 0 && !multiSelect)
    11511155        setActiveSelectionAnchorIndex(selectedIndex());
    11521156
     
    11591163    // ctrl), then initialize the anchor index to the listIndex that just got
    11601164    // clicked.
    1161     if (m_data.activeSelectionAnchorIndex() < 0 || !shiftSelect)
     1165    if (m_activeSelectionAnchorIndex < 0 || !shiftSelect)
    11621166        setActiveSelectionAnchorIndex(listIndex);
    11631167
     
    12031207        bool handled = false;
    12041208        int endIndex = 0;
    1205         if (m_data.activeSelectionEndIndex() < 0) {
     1209        if (m_activeSelectionEndIndex < 0) {
    12061210            // Initialize the end index
    12071211            if (keyIdentifier == "Down" || keyIdentifier == "PageDown") {
     
    12231227            // Set the end index based on the current end index
    12241228            if (keyIdentifier == "Down") {
    1225                 endIndex = nextSelectableListIndex(m_data.activeSelectionEndIndex());
     1229                endIndex = nextSelectableListIndex(m_activeSelectionEndIndex);
    12261230                handled = true;
    12271231            } else if (keyIdentifier == "Up") {
    1228                 endIndex = previousSelectableListIndex(m_data.activeSelectionEndIndex());
     1232                endIndex = previousSelectableListIndex(m_activeSelectionEndIndex);
    12291233                handled = true;
    12301234            } else if (keyIdentifier == "PageDown") {
    1231                 endIndex = nextSelectableListIndexPageAway(m_data.activeSelectionEndIndex(), SkipForwards);
     1235                endIndex = nextSelectableListIndexPageAway(m_activeSelectionEndIndex, SkipForwards);
    12321236                handled = true;
    12331237            } else if (keyIdentifier == "PageUp") {
    1234                 endIndex = nextSelectableListIndexPageAway(m_data.activeSelectionEndIndex(), SkipBackwards);
     1238                endIndex = nextSelectableListIndexPageAway(m_activeSelectionEndIndex, SkipBackwards);
    12351239                handled = true;
    12361240            }
     
    12461250        if (isSpatialNavigationEnabled(document()->frame()))
    12471251            // Check if the selection moves to the boundary.
    1248             if (keyIdentifier == "Left" || keyIdentifier == "Right" || ((keyIdentifier == "Down" || keyIdentifier == "Up") && endIndex == m_data.activeSelectionEndIndex()))
     1252            if (keyIdentifier == "Left" || keyIdentifier == "Right" || ((keyIdentifier == "Down" || keyIdentifier == "Up") && endIndex == m_activeSelectionEndIndex))
    12491253                return;
    12501254
     
    12581262            setActiveSelectionEndIndex(endIndex);
    12591263
    1260             bool selectNewItem = !m_data.multiple() || static_cast<KeyboardEvent*>(event)->shiftKey() || !isSpatialNavigationEnabled(document()->frame());
     1264            bool selectNewItem = !m_multiple || static_cast<KeyboardEvent*>(event)->shiftKey() || !isSpatialNavigationEnabled(document()->frame());
    12611265            if (selectNewItem)
    1262                 m_data.setActiveSelectionState(true);
     1266                m_activeSelectionState = true;
    12631267            // If the anchor is unitialized, or if we're going to deselect all
    12641268            // other options, then set the anchor index equal to the end index.
    1265             bool deselectOthers = !m_data.multiple() || (!static_cast<KeyboardEvent*>(event)->shiftKey() && selectNewItem);
    1266             if (m_data.activeSelectionAnchorIndex() < 0 || deselectOthers) {
     1269            bool deselectOthers = !m_multiple || (!static_cast<KeyboardEvent*>(event)->shiftKey() && selectNewItem);
     1270            if (m_activeSelectionAnchorIndex < 0 || deselectOthers) {
    12671271                if (deselectOthers)
    12681272                    deselectItemsWithoutValidation();
    1269                 setActiveSelectionAnchorIndex(m_data.activeSelectionEndIndex());
     1273                setActiveSelectionAnchorIndex(m_activeSelectionEndIndex);
    12701274            }
    12711275
     
    12881292                form()->submitImplicitly(event, false);
    12891293            event->setDefaultHandled();
    1290         } else if (m_data.multiple() && keyCode == ' ' && isSpatialNavigationEnabled(document()->frame())) {
     1294        } else if (m_multiple && keyCode == ' ' && isSpatialNavigationEnabled(document()->frame())) {
    12911295            // Use space to toggle selection change.
    1292             m_data.setActiveSelectionState(!m_data.activeSelectionState());
    1293             updateSelectedState(listToOptionIndex(m_data.activeSelectionEndIndex()), true /*multi*/, false /*shift*/);
     1296            m_activeSelectionState = !m_activeSelectionState;
     1297            updateSelectedState(listToOptionIndex(m_activeSelectionEndIndex), true /*multi*/, false /*shift*/);
    12941298            listBoxOnChange();
    12951299            event->setDefaultHandled();
     
    13031307        return;
    13041308
    1305     if (m_data.usesMenuList())
     1309    if (usesMenuList())
    13061310        menuListDefaultEventHandler(event);
    13071311    else
     
    13541358void HTMLSelectElement::typeAheadFind(KeyboardEvent* event)
    13551359{
    1356     if (event->timeStamp() < m_data.lastCharTime())
     1360    if (event->timeStamp() < m_lastCharTime)
    13571361        return;
    13581362
    1359     DOMTimeStamp delta = event->timeStamp() - m_data.lastCharTime();
    1360     m_data.setLastCharTime(event->timeStamp());
     1363    DOMTimeStamp delta = event->timeStamp() - m_lastCharTime;
     1364    m_lastCharTime = event->timeStamp();
    13611365
    13621366    UChar c = event->charCode();
     
    13661370    if (delta > typeAheadTimeout) {
    13671371        prefix = String(&c, 1);
    1368         m_data.setTypedString(prefix);
    1369         m_data.setRepeatingChar(c);
     1372        m_typedString = prefix;
     1373        m_repeatingChar = c;
    13701374    } else {
    1371         m_data.typedString().append(c);
    1372 
    1373         if (c == m_data.repeatingChar()) {
     1375        m_typedString.append(c);
     1376
     1377        if (c == m_repeatingChar) {
    13741378            // The user is likely trying to cycle through all the items starting
    13751379            // with this character, so just search on the character
    13761380            prefix = String(&c, 1);
    13771381        } else {
    1378             m_data.setRepeatingChar(0);
    1379             prefix = m_data.typedString();
     1382            m_repeatingChar = 0;
     1383            prefix = m_typedString;
    13801384            searchStartOffset = 0;
    13811385        }
     
    14051409        if (stripLeadingWhiteSpace(text).foldCase().startsWith(prefixWithCaseFolded)) {
    14061410            setSelectedIndexInternal(listToOptionIndex(index));
    1407             if (!m_data.usesMenuList())
     1411            if (!usesMenuList())
    14081412                listBoxOnChange();
    14091413
     
    14401444    }
    14411445
    1442     if (m_data.usesMenuList())
     1446    if (usesMenuList())
    14431447        menuListOnChange();
    14441448    else
  • trunk/Source/WebCore/html/HTMLSelectElement.h

    r97135 r97238  
    3030#include "Event.h"
    3131#include "HTMLFormControlElement.h"
    32 #include "SelectElement.h"
    3332#include <wtf/Vector.h>
    3433
     
    5150    unsigned length() const;
    5251
    53     int size() const { return m_data.size(); }
    54     bool multiple() const { return m_data.multiple(); }
     52    int size() const { return m_size; }
     53    bool multiple() const { return m_multiple; }
    5554
    5655    void add(HTMLElement*, HTMLElement* beforeElement, ExceptionCode&);
     
    156155    void listBoxDefaultEventHandler(Event*);
    157156    void setOptionsChangedOnRenderer();
     157    bool usesMenuList() const;
    158158
    159159    enum SkipDirection {
     
    168168    int nextSelectableListIndexPageAway(int startIndex, SkipDirection) const;
    169169
    170     SelectElementData m_data;
    171170    CollectionCache m_collectionInfo;
    172171    Vector<Element*> m_listItems;
     172    Vector<bool> m_lastOnChangeSelection;
     173    Vector<bool> m_cachedStateForActiveSelection;
     174    DOMTimeStamp m_lastCharTime;
     175    String m_typedString;
     176    int m_size;
     177    int m_lastOnChangeIndex;
     178    int m_activeSelectionAnchorIndex;
     179    int m_activeSelectionEndIndex;
     180    UChar m_repeatingChar;
     181    bool m_userDrivenChange;
     182    bool m_multiple;
     183    bool m_activeSelectionState;
    173184    bool m_recalcListItems;
    174185};
     
    176187HTMLSelectElement* toSelectElement(Element*);
    177188
     189inline bool HTMLSelectElement::usesMenuList() const
     190{
     191#if ENABLE(NO_LISTBOX_RENDERING)
     192    return true;
     193#else
     194    return !m_multiple && m_size <= 1;
     195#endif
     196}
     197
    178198} // namespace
    179199
Note: See TracChangeset for help on using the changeset viewer.