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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 , m_size(0) | 77 , m_size(0) |
78 , m_lastOnChangeIndex(-1) | 78 , m_lastOnChangeIndex(-1) |
79 , m_activeSelectionAnchorIndex(-1) | 79 , m_activeSelectionAnchorIndex(-1) |
80 , m_activeSelectionEndIndex(-1) | 80 , m_activeSelectionEndIndex(-1) |
81 , m_isProcessingUserDrivenChange(false) | 81 , m_isProcessingUserDrivenChange(false) |
82 , m_multiple(false) | 82 , m_multiple(false) |
83 , m_activeSelectionState(false) | 83 , m_activeSelectionState(false) |
84 , m_shouldRecalcListItems(false) | 84 , m_shouldRecalcListItems(false) |
85 , m_suggestedIndex(-1) | 85 , m_suggestedIndex(-1) |
86 , m_isAutofilledByPreview(false) | 86 , m_isAutofilledByPreview(false) |
| 87 , m_scrollToSelectionLater(false) |
87 { | 88 { |
88 } | 89 } |
89 | 90 |
90 PassRefPtrWillBeRawPtr<HTMLSelectElement> HTMLSelectElement::create(Document& do
cument) | 91 PassRefPtrWillBeRawPtr<HTMLSelectElement> HTMLSelectElement::create(Document& do
cument) |
91 { | 92 { |
92 RefPtrWillBeRawPtr<HTMLSelectElement> select = adoptRefWillBeNoop(new HTMLSe
lectElement(document, 0)); | 93 RefPtrWillBeRawPtr<HTMLSelectElement> select = adoptRefWillBeNoop(new HTMLSe
lectElement(document, 0)); |
93 select->ensureUserAgentShadowRoot(); | 94 select->ensureUserAgentShadowRoot(); |
94 return select.release(); | 95 return select.release(); |
95 } | 96 } |
96 | 97 |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 setNeedsValidityCheck(); | 412 setNeedsValidityCheck(); |
412 } | 413 } |
413 | 414 |
414 void HTMLSelectElement::childrenChanged(const ChildrenChange& change) | 415 void HTMLSelectElement::childrenChanged(const ChildrenChange& change) |
415 { | 416 { |
416 setRecalcListItems(); | 417 setRecalcListItems(); |
417 setNeedsValidityCheck(); | 418 setNeedsValidityCheck(); |
418 m_lastOnChangeSelection.clear(); | 419 m_lastOnChangeSelection.clear(); |
419 | 420 |
420 HTMLFormControlElementWithState::childrenChanged(change); | 421 HTMLFormControlElementWithState::childrenChanged(change); |
| 422 |
| 423 if (m_scrollToSelectionLater) { |
| 424 m_scrollToSelectionLater = false; |
| 425 scrollToSelection(); |
| 426 } |
421 } | 427 } |
422 | 428 |
423 void HTMLSelectElement::optionElementChildrenChanged() | 429 void HTMLSelectElement::optionElementChildrenChanged() |
424 { | 430 { |
425 setRecalcListItems(); | 431 setRecalcListItems(); |
426 setNeedsValidityCheck(); | 432 setNeedsValidityCheck(); |
427 | 433 |
428 if (renderer()) { | 434 if (renderer()) { |
429 if (AXObjectCache* cache = renderer()->document().existingAXObjectCache(
)) | 435 if (AXObjectCache* cache = renderer()->document().existingAXObjectCache(
)) |
430 cache->childrenChanged(this); | 436 cache->childrenChanged(this); |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
911 { | 917 { |
912 ASSERT(option->ownerSelectElement() == this); | 918 ASSERT(option->ownerSelectElement() == this); |
913 if (optionIsSelected) | 919 if (optionIsSelected) |
914 selectOption(option->index()); | 920 selectOption(option->index()); |
915 else if (!usesMenuList() || multiple()) | 921 else if (!usesMenuList() || multiple()) |
916 selectOption(-1); | 922 selectOption(-1); |
917 else | 923 else |
918 selectOption(nextSelectableListIndex(-1)); | 924 selectOption(nextSelectableListIndex(-1)); |
919 } | 925 } |
920 | 926 |
| 927 void HTMLSelectElement::optionInserted(const HTMLOptionElement& option, bool opt
ionIsSelected) |
| 928 { |
| 929 ASSERT(option.ownerSelectElement() == this); |
| 930 if (optionIsSelected) |
| 931 selectOption(option.index(), DelayScrollToSelection); |
| 932 } |
| 933 |
921 void HTMLSelectElement::optionRemoved(const HTMLOptionElement& option) | 934 void HTMLSelectElement::optionRemoved(const HTMLOptionElement& option) |
922 { | 935 { |
923 if (m_activeSelectionAnchorIndex < 0 && m_activeSelectionEndIndex < 0) | 936 if (m_activeSelectionAnchorIndex < 0 && m_activeSelectionEndIndex < 0) |
924 return; | 937 return; |
925 int listIndex = optionToListIndex(option.index()); | 938 int listIndex = optionToListIndex(option.index()); |
926 if (listIndex <= m_activeSelectionAnchorIndex) | 939 if (listIndex <= m_activeSelectionAnchorIndex) |
927 m_activeSelectionAnchorIndex--; | 940 m_activeSelectionAnchorIndex--; |
928 if (listIndex <= m_activeSelectionEndIndex) | 941 if (listIndex <= m_activeSelectionEndIndex) |
929 m_activeSelectionEndIndex--; | 942 m_activeSelectionEndIndex--; |
930 if (listIndex == selectedIndex()) | 943 if (listIndex == selectedIndex()) |
(...skipping 22 matching lines...) Expand all Loading... |
953 } | 966 } |
954 } | 967 } |
955 | 968 |
956 if (shouldDeselect) | 969 if (shouldDeselect) |
957 deselectItemsWithoutValidation(element); | 970 deselectItemsWithoutValidation(element); |
958 | 971 |
959 // For the menu list case, this is what makes the selected element appear. | 972 // For the menu list case, this is what makes the selected element appear. |
960 if (RenderObject* renderer = this->renderer()) | 973 if (RenderObject* renderer = this->renderer()) |
961 renderer->updateFromElement(); | 974 renderer->updateFromElement(); |
962 | 975 |
963 scrollToSelection(); | 976 if (flags & DelayScrollToSelection) |
| 977 m_scrollToSelectionLater = true; |
| 978 else |
| 979 scrollToSelection(); |
964 | 980 |
965 setNeedsValidityCheck(); | 981 setNeedsValidityCheck(); |
966 | 982 |
967 if (usesMenuList()) { | 983 if (usesMenuList()) { |
968 m_isProcessingUserDrivenChange = flags & UserDriven; | 984 m_isProcessingUserDrivenChange = flags & UserDriven; |
969 if (flags & DispatchInputAndChangeEvent) | 985 if (flags & DispatchInputAndChangeEvent) |
970 dispatchInputAndChangeEventForMenuList(); | 986 dispatchInputAndChangeEventForMenuList(); |
971 if (RenderObject* renderer = this->renderer()) { | 987 if (RenderObject* renderer = this->renderer()) { |
972 if (usesMenuList()) { | 988 if (usesMenuList()) { |
973 toRenderMenuList(renderer)->didSetSelectedIndex(listIndex); | 989 toRenderMenuList(renderer)->didSetSelectedIndex(listIndex); |
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1648 return listItems().size(); | 1664 return listItems().size(); |
1649 } | 1665 } |
1650 | 1666 |
1651 String HTMLSelectElement::optionAtIndex(int index) const | 1667 String HTMLSelectElement::optionAtIndex(int index) const |
1652 { | 1668 { |
1653 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement>>& items = listItems()
; | 1669 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement>>& items = listItems()
; |
1654 | 1670 |
1655 HTMLElement* element = items[index]; | 1671 HTMLElement* element = items[index]; |
1656 if (!isHTMLOptionElement(*element) || toHTMLOptionElement(element)->isDisabl
edFormControl()) | 1672 if (!isHTMLOptionElement(*element) || toHTMLOptionElement(element)->isDisabl
edFormControl()) |
1657 return String(); | 1673 return String(); |
1658 return toHTMLOptionElement(element)->textIndentedToRespectGroupLabel(); | 1674 return toHTMLOptionElement(element)->text(); |
1659 } | 1675 } |
1660 | 1676 |
1661 void HTMLSelectElement::typeAheadFind(KeyboardEvent* event) | 1677 void HTMLSelectElement::typeAheadFind(KeyboardEvent* event) |
1662 { | 1678 { |
1663 int index = m_typeAhead.handleEvent(event, TypeAhead::MatchPrefix | TypeAhea
d::CycleFirstChar); | 1679 int index = m_typeAhead.handleEvent(event, TypeAhead::MatchPrefix | TypeAhea
d::CycleFirstChar); |
1664 if (index < 0) | 1680 if (index < 0) |
1665 return; | 1681 return; |
1666 selectOption(listToOptionIndex(index), DeselectOtherOptions | DispatchInputA
ndChangeEvent | UserDriven); | 1682 selectOption(listToOptionIndex(index), DeselectOtherOptions | DispatchInputA
ndChangeEvent | UserDriven); |
1667 if (!usesMenuList()) | 1683 if (!usesMenuList()) |
1668 listBoxOnChange(); | 1684 listBoxOnChange(); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1773 int focusedIndex = activeSelectionEndListIndex(); | 1789 int focusedIndex = activeSelectionEndListIndex(); |
1774 if (focusedIndex < 0) | 1790 if (focusedIndex < 0) |
1775 focusedIndex = firstSelectableListIndex(); | 1791 focusedIndex = firstSelectableListIndex(); |
1776 if (focusedIndex < 0) | 1792 if (focusedIndex < 0) |
1777 return nullptr; | 1793 return nullptr; |
1778 HTMLElement* focused = listItems()[focusedIndex]; | 1794 HTMLElement* focused = listItems()[focusedIndex]; |
1779 return isHTMLOptionElement(focused) ? toHTMLOptionElement(focused) : nullptr
; | 1795 return isHTMLOptionElement(focused) ? toHTMLOptionElement(focused) : nullptr
; |
1780 } | 1796 } |
1781 | 1797 |
1782 } // namespace | 1798 } // namespace |
OLD | NEW |