| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). | 2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
| 3 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 3 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 4 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 4 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 5 * (C) 2001 Dirk Mueller (mueller@kde.org) | 5 * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 6 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011 Apple Inc. All rights
reserved. | 6 * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010, 2011 Apple Inc. All rights
reserved. |
| 7 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) | 7 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) |
| 8 * Copyright (C) 2010 Google Inc. All rights reserved. | 8 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 9 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) | 9 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) |
| 10 * | 10 * |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 , m_activeSelectionState(false) | 89 , m_activeSelectionState(false) |
| 90 , m_shouldRecalcListItems(false) | 90 , m_shouldRecalcListItems(false) |
| 91 , m_suggestedIndex(-1) | 91 , m_suggestedIndex(-1) |
| 92 , m_isAutofilledByPreview(false) | 92 , m_isAutofilledByPreview(false) |
| 93 , m_indexToSelectOnCancel(-1) | 93 , m_indexToSelectOnCancel(-1) |
| 94 , m_popupIsVisible(false) | 94 , m_popupIsVisible(false) |
| 95 { | 95 { |
| 96 setHasCustomStyleCallbacks(); | 96 setHasCustomStyleCallbacks(); |
| 97 } | 97 } |
| 98 | 98 |
| 99 PassRefPtrWillBeRawPtr<HTMLSelectElement> HTMLSelectElement::create(Document& do
cument) | 99 RawPtr<HTMLSelectElement> HTMLSelectElement::create(Document& document) |
| 100 { | 100 { |
| 101 RefPtrWillBeRawPtr<HTMLSelectElement> select = adoptRefWillBeNoop(new HTMLSe
lectElement(document, 0)); | 101 RawPtr<HTMLSelectElement> select = new HTMLSelectElement(document, 0); |
| 102 select->ensureUserAgentShadowRoot(); | 102 select->ensureUserAgentShadowRoot(); |
| 103 return select.release(); | 103 return select.release(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 PassRefPtrWillBeRawPtr<HTMLSelectElement> HTMLSelectElement::create(Document& do
cument, HTMLFormElement* form) | 106 RawPtr<HTMLSelectElement> HTMLSelectElement::create(Document& document, HTMLForm
Element* form) |
| 107 { | 107 { |
| 108 RefPtrWillBeRawPtr<HTMLSelectElement> select = adoptRefWillBeNoop(new HTMLSe
lectElement(document, form)); | 108 RawPtr<HTMLSelectElement> select = new HTMLSelectElement(document, form); |
| 109 select->ensureUserAgentShadowRoot(); | 109 select->ensureUserAgentShadowRoot(); |
| 110 return select.release(); | 110 return select.release(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 HTMLSelectElement::~HTMLSelectElement() | 113 HTMLSelectElement::~HTMLSelectElement() |
| 114 { | 114 { |
| 115 } | 115 } |
| 116 | 116 |
| 117 const AtomicString& HTMLSelectElement::formControlType() const | 117 const AtomicString& HTMLSelectElement::formControlType() const |
| 118 { | 118 { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 | 236 |
| 237 HTMLOptionElement* HTMLSelectElement::activeSelectionEnd() const | 237 HTMLOptionElement* HTMLSelectElement::activeSelectionEnd() const |
| 238 { | 238 { |
| 239 if (m_activeSelectionEnd) | 239 if (m_activeSelectionEnd) |
| 240 return m_activeSelectionEnd.get(); | 240 return m_activeSelectionEnd.get(); |
| 241 return lastSelectedOption(); | 241 return lastSelectedOption(); |
| 242 } | 242 } |
| 243 | 243 |
| 244 void HTMLSelectElement::add(const HTMLOptionElementOrHTMLOptGroupElement& elemen
t, const HTMLElementOrLong& before, ExceptionState& exceptionState) | 244 void HTMLSelectElement::add(const HTMLOptionElementOrHTMLOptGroupElement& elemen
t, const HTMLElementOrLong& before, ExceptionState& exceptionState) |
| 245 { | 245 { |
| 246 RefPtrWillBeRawPtr<HTMLElement> elementToInsert; | 246 RawPtr<HTMLElement> elementToInsert; |
| 247 ASSERT(!element.isNull()); | 247 ASSERT(!element.isNull()); |
| 248 if (element.isHTMLOptionElement()) | 248 if (element.isHTMLOptionElement()) |
| 249 elementToInsert = element.getAsHTMLOptionElement(); | 249 elementToInsert = element.getAsHTMLOptionElement(); |
| 250 else | 250 else |
| 251 elementToInsert = element.getAsHTMLOptGroupElement(); | 251 elementToInsert = element.getAsHTMLOptGroupElement(); |
| 252 | 252 |
| 253 RefPtrWillBeRawPtr<HTMLElement> beforeElement; | 253 RawPtr<HTMLElement> beforeElement; |
| 254 if (before.isHTMLElement()) | 254 if (before.isHTMLElement()) |
| 255 beforeElement = before.getAsHTMLElement(); | 255 beforeElement = before.getAsHTMLElement(); |
| 256 else if (before.isLong()) | 256 else if (before.isLong()) |
| 257 beforeElement = options()->item(before.getAsLong()); | 257 beforeElement = options()->item(before.getAsLong()); |
| 258 else | 258 else |
| 259 beforeElement = nullptr; | 259 beforeElement = nullptr; |
| 260 | 260 |
| 261 insertBefore(elementToInsert, beforeElement.get(), exceptionState); | 261 insertBefore(elementToInsert, beforeElement.get(), exceptionState); |
| 262 setNeedsValidityCheck(); | 262 setNeedsValidityCheck(); |
| 263 } | 263 } |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 return !usesMenuList(); | 401 return !usesMenuList(); |
| 402 } | 402 } |
| 403 | 403 |
| 404 LayoutObject* HTMLSelectElement::createLayoutObject(const ComputedStyle&) | 404 LayoutObject* HTMLSelectElement::createLayoutObject(const ComputedStyle&) |
| 405 { | 405 { |
| 406 if (usesMenuList()) | 406 if (usesMenuList()) |
| 407 return new LayoutMenuList(this); | 407 return new LayoutMenuList(this); |
| 408 return new LayoutListBox(this); | 408 return new LayoutListBox(this); |
| 409 } | 409 } |
| 410 | 410 |
| 411 PassRefPtrWillBeRawPtr<HTMLCollection> HTMLSelectElement::selectedOptions() | 411 RawPtr<HTMLCollection> HTMLSelectElement::selectedOptions() |
| 412 { | 412 { |
| 413 return ensureCachedCollection<HTMLCollection>(SelectedOptions); | 413 return ensureCachedCollection<HTMLCollection>(SelectedOptions); |
| 414 } | 414 } |
| 415 | 415 |
| 416 PassRefPtrWillBeRawPtr<HTMLOptionsCollection> HTMLSelectElement::options() | 416 RawPtr<HTMLOptionsCollection> HTMLSelectElement::options() |
| 417 { | 417 { |
| 418 return ensureCachedCollection<HTMLOptionsCollection>(SelectOptions); | 418 return ensureCachedCollection<HTMLOptionsCollection>(SelectOptions); |
| 419 } | 419 } |
| 420 | 420 |
| 421 void HTMLSelectElement::childrenChanged(const ChildrenChange& change) | 421 void HTMLSelectElement::childrenChanged(const ChildrenChange& change) |
| 422 { | 422 { |
| 423 setRecalcListItems(); | 423 setRecalcListItems(); |
| 424 setNeedsValidityCheck(); | 424 setNeedsValidityCheck(); |
| 425 m_lastOnChangeSelection.clear(); | 425 m_lastOnChangeSelection.clear(); |
| 426 | 426 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 if (diff < 0) { // Add dummy elements. | 512 if (diff < 0) { // Add dummy elements. |
| 513 do { | 513 do { |
| 514 appendChild(document().createElement(optionTag, false), exceptionSta
te); | 514 appendChild(document().createElement(optionTag, false), exceptionSta
te); |
| 515 if (exceptionState.hadException()) | 515 if (exceptionState.hadException()) |
| 516 break; | 516 break; |
| 517 } while (++diff); | 517 } while (++diff); |
| 518 } else { | 518 } else { |
| 519 // Removing children fires mutation events, which might mutate the DOM | 519 // Removing children fires mutation events, which might mutate the DOM |
| 520 // further, so we first copy out a list of elements that we intend to | 520 // further, so we first copy out a list of elements that we intend to |
| 521 // remove then attempt to remove them one at a time. | 521 // remove then attempt to remove them one at a time. |
| 522 WillBeHeapVector<RefPtrWillBeMember<Element>> itemsToRemove; | 522 HeapVector<Member<Element>> itemsToRemove; |
| 523 size_t optionIndex = 0; | 523 size_t optionIndex = 0; |
| 524 for (auto& item : listItems()) { | 524 for (auto& item : listItems()) { |
| 525 if (isHTMLOptionElement(item) && optionIndex++ >= newLen) { | 525 if (isHTMLOptionElement(item) && optionIndex++ >= newLen) { |
| 526 ASSERT(item->parentNode()); | 526 ASSERT(item->parentNode()); |
| 527 itemsToRemove.append(item.get()); | 527 itemsToRemove.append(item.get()); |
| 528 } | 528 } |
| 529 } | 529 } |
| 530 | 530 |
| 531 for (auto& item : itemsToRemove) { | 531 for (auto& item : itemsToRemove) { |
| 532 if (item->parentNode()) | 532 if (item->parentNode()) |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 bool fireOnChange = false; | 723 bool fireOnChange = false; |
| 724 for (unsigned i = 0; i < items.size(); ++i) { | 724 for (unsigned i = 0; i < items.size(); ++i) { |
| 725 HTMLElement* element = items[i]; | 725 HTMLElement* element = items[i]; |
| 726 bool selected = isHTMLOptionElement(*element) && toHTMLOptionElement(ele
ment)->selected(); | 726 bool selected = isHTMLOptionElement(*element) && toHTMLOptionElement(ele
ment)->selected(); |
| 727 if (selected != m_lastOnChangeSelection[i]) | 727 if (selected != m_lastOnChangeSelection[i]) |
| 728 fireOnChange = true; | 728 fireOnChange = true; |
| 729 m_lastOnChangeSelection[i] = selected; | 729 m_lastOnChangeSelection[i] = selected; |
| 730 } | 730 } |
| 731 | 731 |
| 732 if (fireOnChange) { | 732 if (fireOnChange) { |
| 733 RefPtrWillBeRawPtr<HTMLSelectElement> protector(this); | 733 RawPtr<HTMLSelectElement> protector(this); |
| 734 dispatchInputEvent(); | 734 dispatchInputEvent(); |
| 735 dispatchFormControlChangeEvent(); | 735 dispatchFormControlChangeEvent(); |
| 736 } | 736 } |
| 737 } | 737 } |
| 738 | 738 |
| 739 void HTMLSelectElement::dispatchInputAndChangeEventForMenuList() | 739 void HTMLSelectElement::dispatchInputAndChangeEventForMenuList() |
| 740 { | 740 { |
| 741 ASSERT(usesMenuList()); | 741 ASSERT(usesMenuList()); |
| 742 | 742 |
| 743 HTMLOptionElement* selectedOption = this->selectedOption(); | 743 HTMLOptionElement* selectedOption = this->selectedOption(); |
| 744 if (m_lastOnChangeOption.get() != selectedOption) { | 744 if (m_lastOnChangeOption.get() != selectedOption) { |
| 745 m_lastOnChangeOption = selectedOption; | 745 m_lastOnChangeOption = selectedOption; |
| 746 RefPtrWillBeRawPtr<HTMLSelectElement> protector(this); | 746 RawPtr<HTMLSelectElement> protector(this); |
| 747 dispatchInputEvent(); | 747 dispatchInputEvent(); |
| 748 dispatchFormControlChangeEvent(); | 748 dispatchFormControlChangeEvent(); |
| 749 } | 749 } |
| 750 } | 750 } |
| 751 | 751 |
| 752 void HTMLSelectElement::scrollToSelection() | 752 void HTMLSelectElement::scrollToSelection() |
| 753 { | 753 { |
| 754 if (!isFinishedParsingChildren()) | 754 if (!isFinishedParsingChildren()) |
| 755 return; | 755 return; |
| 756 if (usesMenuList()) | 756 if (usesMenuList()) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 767 toLayoutMenuList(layoutObject)->setOptionsChanged(true); | 767 toLayoutMenuList(layoutObject)->setOptionsChanged(true); |
| 768 } | 768 } |
| 769 } | 769 } |
| 770 | 770 |
| 771 const HTMLSelectElement::ListItems& HTMLSelectElement::listItems() const | 771 const HTMLSelectElement::ListItems& HTMLSelectElement::listItems() const |
| 772 { | 772 { |
| 773 if (m_shouldRecalcListItems) { | 773 if (m_shouldRecalcListItems) { |
| 774 recalcListItems(); | 774 recalcListItems(); |
| 775 } else { | 775 } else { |
| 776 #if ENABLE(ASSERT) | 776 #if ENABLE(ASSERT) |
| 777 WillBeHeapVector<RawPtrWillBeMember<HTMLElement>> items = m_listItems; | 777 HeapVector<Member<HTMLElement>> items = m_listItems; |
| 778 recalcListItems(); | 778 recalcListItems(); |
| 779 ASSERT(items == m_listItems); | 779 ASSERT(items == m_listItems); |
| 780 #endif | 780 #endif |
| 781 } | 781 } |
| 782 | 782 |
| 783 return m_listItems; | 783 return m_listItems; |
| 784 } | 784 } |
| 785 | 785 |
| 786 void HTMLSelectElement::invalidateSelectedItems() | 786 void HTMLSelectElement::invalidateSelectedItems() |
| 787 { | 787 { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 945 if (!option) | 945 if (!option) |
| 946 return; | 946 return; |
| 947 if (usesMenuList()) | 947 if (usesMenuList()) |
| 948 return; | 948 return; |
| 949 bool hasPendingTask = m_optionToScrollTo; | 949 bool hasPendingTask = m_optionToScrollTo; |
| 950 // We'd like to keep an HTMLOptionElement reference rather than the index of | 950 // We'd like to keep an HTMLOptionElement reference rather than the index of |
| 951 // the option because the task should work even if unselected option is | 951 // the option because the task should work even if unselected option is |
| 952 // inserted before executing scrollToOptionTask(). | 952 // inserted before executing scrollToOptionTask(). |
| 953 m_optionToScrollTo = option; | 953 m_optionToScrollTo = option; |
| 954 if (!hasPendingTask) | 954 if (!hasPendingTask) |
| 955 document().postTask(BLINK_FROM_HERE, createSameThreadTask(&HTMLSelectEle
ment::scrollToOptionTask, PassRefPtrWillBeRawPtr<HTMLSelectElement>(this))); | 955 document().postTask(BLINK_FROM_HERE, createSameThreadTask(&HTMLSelectEle
ment::scrollToOptionTask, RawPtr<HTMLSelectElement>(this))); |
| 956 } | 956 } |
| 957 | 957 |
| 958 void HTMLSelectElement::scrollToOptionTask() | 958 void HTMLSelectElement::scrollToOptionTask() |
| 959 { | 959 { |
| 960 RefPtrWillBeRawPtr<HTMLOptionElement> option = m_optionToScrollTo.release(); | 960 RawPtr<HTMLOptionElement> option = m_optionToScrollTo.release(); |
| 961 if (!option || !inDocument()) | 961 if (!option || !inDocument()) |
| 962 return; | 962 return; |
| 963 // optionRemoved() makes sure m_optionToScrollTo doesn't have an option with | 963 // optionRemoved() makes sure m_optionToScrollTo doesn't have an option with |
| 964 // another owner. | 964 // another owner. |
| 965 ASSERT(option->ownerSelectElement() == this); | 965 ASSERT(option->ownerSelectElement() == this); |
| 966 document().updateLayoutIgnorePendingStylesheets(); | 966 document().updateLayoutIgnorePendingStylesheets(); |
| 967 if (!layoutObject() || !layoutObject()->isListBox()) | 967 if (!layoutObject() || !layoutObject()->isListBox()) |
| 968 return; | 968 return; |
| 969 LayoutRect bounds = option->boundingBox(); | 969 LayoutRect bounds = option->boundingBox(); |
| 970 toLayoutListBox(layoutObject())->scrollToRect(bounds); | 970 toLayoutListBox(layoutObject())->scrollToRect(bounds); |
| (...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1787 void HTMLSelectElement::finishParsingChildren() | 1787 void HTMLSelectElement::finishParsingChildren() |
| 1788 { | 1788 { |
| 1789 HTMLFormControlElementWithState::finishParsingChildren(); | 1789 HTMLFormControlElementWithState::finishParsingChildren(); |
| 1790 if (usesMenuList()) | 1790 if (usesMenuList()) |
| 1791 return; | 1791 return; |
| 1792 scrollToOption(selectedOption()); | 1792 scrollToOption(selectedOption()); |
| 1793 if (AXObjectCache* cache = document().existingAXObjectCache()) | 1793 if (AXObjectCache* cache = document().existingAXObjectCache()) |
| 1794 cache->listboxActiveIndexChanged(this); | 1794 cache->listboxActiveIndexChanged(this); |
| 1795 } | 1795 } |
| 1796 | 1796 |
| 1797 bool HTMLSelectElement::anonymousIndexedSetter(unsigned index, PassRefPtrWillBeR
awPtr<HTMLOptionElement> value, ExceptionState& exceptionState) | 1797 bool HTMLSelectElement::anonymousIndexedSetter(unsigned index, RawPtr<HTMLOption
Element> value, ExceptionState& exceptionState) |
| 1798 { | 1798 { |
| 1799 if (!value) { // undefined or null | 1799 if (!value) { // undefined or null |
| 1800 remove(index); | 1800 remove(index); |
| 1801 return true; | 1801 return true; |
| 1802 } | 1802 } |
| 1803 setOption(index, value.get(), exceptionState); | 1803 setOption(index, value.get(), exceptionState); |
| 1804 return true; | 1804 return true; |
| 1805 } | 1805 } |
| 1806 | 1806 |
| 1807 bool HTMLSelectElement::isInteractiveContent() const | 1807 bool HTMLSelectElement::isInteractiveContent() const |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1827 visitor->trace(m_lastOnChangeOption); | 1827 visitor->trace(m_lastOnChangeOption); |
| 1828 visitor->trace(m_activeSelectionAnchor); | 1828 visitor->trace(m_activeSelectionAnchor); |
| 1829 visitor->trace(m_activeSelectionEnd); | 1829 visitor->trace(m_activeSelectionEnd); |
| 1830 visitor->trace(m_optionToScrollTo); | 1830 visitor->trace(m_optionToScrollTo); |
| 1831 visitor->trace(m_popup); | 1831 visitor->trace(m_popup); |
| 1832 HTMLFormControlElementWithState::trace(visitor); | 1832 HTMLFormControlElementWithState::trace(visitor); |
| 1833 } | 1833 } |
| 1834 | 1834 |
| 1835 void HTMLSelectElement::didAddUserAgentShadowRoot(ShadowRoot& root) | 1835 void HTMLSelectElement::didAddUserAgentShadowRoot(ShadowRoot& root) |
| 1836 { | 1836 { |
| 1837 RefPtrWillBeRawPtr<HTMLContentElement> content = HTMLContentElement::create(
document()); | 1837 RawPtr<HTMLContentElement> content = HTMLContentElement::create(document()); |
| 1838 content->setAttribute(selectAttr, "option,optgroup,hr"); | 1838 content->setAttribute(selectAttr, "option,optgroup,hr"); |
| 1839 root.appendChild(content); | 1839 root.appendChild(content); |
| 1840 } | 1840 } |
| 1841 | 1841 |
| 1842 HTMLOptionElement* HTMLSelectElement::spatialNavigationFocusedOption() | 1842 HTMLOptionElement* HTMLSelectElement::spatialNavigationFocusedOption() |
| 1843 { | 1843 { |
| 1844 if (!isSpatialNavigationEnabled(document().frame())) | 1844 if (!isSpatialNavigationEnabled(document().frame())) |
| 1845 return nullptr; | 1845 return nullptr; |
| 1846 HTMLOptionElement* focusedOption = activeSelectionEnd(); | 1846 HTMLOptionElement* focusedOption = activeSelectionEnd(); |
| 1847 if (!focusedOption) | 1847 if (!focusedOption) |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1987 m_popupIsVisible = false; | 1987 m_popupIsVisible = false; |
| 1988 m_popup = nullptr; | 1988 m_popup = nullptr; |
| 1989 } | 1989 } |
| 1990 | 1990 |
| 1991 void HTMLSelectElement::resetTypeAheadSessionForTesting() | 1991 void HTMLSelectElement::resetTypeAheadSessionForTesting() |
| 1992 { | 1992 { |
| 1993 m_typeAhead.resetSession(); | 1993 m_typeAhead.resetSession(); |
| 1994 } | 1994 } |
| 1995 | 1995 |
| 1996 } // namespace blink | 1996 } // namespace blink |
| OLD | NEW |