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 1021 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1032 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& items = listItems( ); | 1032 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& items = listItems( ); |
1033 size_t length = items.size(); | 1033 size_t length = items.size(); |
1034 FormControlState state; | 1034 FormControlState state; |
1035 for (unsigned i = 0; i < length; ++i) { | 1035 for (unsigned i = 0; i < length; ++i) { |
1036 if (!isHTMLOptionElement(*items[i])) | 1036 if (!isHTMLOptionElement(*items[i])) |
1037 continue; | 1037 continue; |
1038 HTMLOptionElement* option = toHTMLOptionElement(items[i]); | 1038 HTMLOptionElement* option = toHTMLOptionElement(items[i]); |
1039 if (!option->selected()) | 1039 if (!option->selected()) |
1040 continue; | 1040 continue; |
1041 state.append(option->value()); | 1041 state.append(option->value()); |
1042 state.append(String::number(i)); | |
1042 if (!multiple()) | 1043 if (!multiple()) |
1043 break; | 1044 break; |
1044 } | 1045 } |
1045 return state; | 1046 return state; |
1046 } | 1047 } |
1047 | 1048 |
1048 size_t HTMLSelectElement::searchOptionsForValue(const String& value, size_t list IndexStart, size_t listIndexEnd) const | 1049 size_t HTMLSelectElement::searchOptionsForValue(const String& value, size_t list IndexStart, size_t listIndexEnd) const |
1049 { | 1050 { |
1050 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& items = listItems( ); | 1051 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& items = listItems( ); |
1051 size_t loopEndIndex = std::min(items.size(), listIndexEnd); | 1052 size_t loopEndIndex = std::min(items.size(), listIndexEnd); |
1052 for (size_t i = listIndexStart; i < loopEndIndex; ++i) { | 1053 for (size_t i = listIndexStart; i < loopEndIndex; ++i) { |
1053 if (!isHTMLOptionElement(items[i])) | 1054 if (!isHTMLOptionElement(items[i])) |
1054 continue; | 1055 continue; |
1055 if (toHTMLOptionElement(items[i])->value() == value) | 1056 if (toHTMLOptionElement(items[i])->value() == value) |
1056 return i; | 1057 return i; |
1057 } | 1058 } |
1058 return kNotFound; | 1059 return kNotFound; |
1059 } | 1060 } |
1060 | 1061 |
1062 String HTMLSelectElement::valueAtIndex(size_t index) const | |
1063 { | |
1064 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& items = listItems( ); | |
1065 return index < items.size() && isHTMLOptionElement(items[index]) ? toHTMLOpt ionElement(items[index])->value() : WTF::emptyString(); | |
1066 } | |
1067 | |
1061 void HTMLSelectElement::restoreFormControlState(const FormControlState& state) | 1068 void HTMLSelectElement::restoreFormControlState(const FormControlState& state) |
1062 { | 1069 { |
1063 recalcListItems(); | 1070 recalcListItems(); |
1064 | 1071 |
1065 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& items = listItems( ); | 1072 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& items = listItems( ); |
1066 size_t itemsSize = items.size(); | 1073 size_t itemsSize = items.size(); |
1067 if (!itemsSize) | 1074 if (!itemsSize) |
1068 return; | 1075 return; |
1069 | 1076 |
1070 for (size_t i = 0; i < itemsSize; ++i) { | 1077 for (size_t i = 0; i < itemsSize; ++i) { |
1071 if (!isHTMLOptionElement(items[i])) | 1078 if (!isHTMLOptionElement(items[i])) |
1072 continue; | 1079 continue; |
1073 toHTMLOptionElement(items[i])->setSelectedState(false); | 1080 toHTMLOptionElement(items[i])->setSelectedState(false); |
1074 } | 1081 } |
1075 | 1082 |
1083 // The saved state should have at least one value and an index. | |
1084 ASSERT(state.valueSize() >= 2); | |
1076 if (!multiple()) { | 1085 if (!multiple()) { |
1077 size_t foundIndex = searchOptionsForValue(state[0], 0, itemsSize); | 1086 size_t index = state[1].toUInt(); |
1078 if (foundIndex != kNotFound) | 1087 if (index < itemsSize && isHTMLOptionElement(items[index]) && valueAtInd ex(index) == state[0]) { |
tkent
2014/09/10 23:35:50
|index < items.size() && isHTMLOptionElement(items
spartha
2014/09/12 05:46:08
Done.
| |
1079 toHTMLOptionElement(items[foundIndex])->setSelectedState(true); | 1088 toHTMLOptionElement(items[index])->setSelectedState(true); |
1089 } else { | |
1090 size_t foundIndex = searchOptionsForValue(state[0], 0, itemsSize); | |
1091 if (foundIndex != kNotFound) | |
1092 toHTMLOptionElement(items[foundIndex])->setSelectedState(true); | |
1093 } | |
1080 } else { | 1094 } else { |
1081 size_t startIndex = 0; | 1095 size_t startIndex = 0; |
1082 for (size_t i = 0; i < state.valueSize(); ++i) { | 1096 for (size_t i = 0; i < state.valueSize(); i+= 2) { |
1083 const String& value = state[i]; | 1097 const String& value = state[i]; |
1084 size_t foundIndex = searchOptionsForValue(value, startIndex, itemsSi ze); | 1098 const size_t index = state[i + 1].toUInt(); |
1085 if (foundIndex == kNotFound) | 1099 if (index < itemsSize && isHTMLOptionElement(items[index]) && valueA tIndex(index) == value) { |
1086 foundIndex = searchOptionsForValue(value, 0, startIndex); | 1100 toHTMLOptionElement(items[index])->setSelectedState(true); |
1087 if (foundIndex == kNotFound) | 1101 startIndex = index + 1; |
1088 continue; | 1102 } else { |
1089 toHTMLOptionElement(items[foundIndex])->setSelectedState(true); | 1103 size_t foundIndex = searchOptionsForValue(value, startIndex, ite msSize); |
1090 startIndex = foundIndex + 1; | 1104 if (foundIndex == kNotFound) |
1105 foundIndex = searchOptionsForValue(value, 0, startIndex); | |
1106 if (foundIndex == kNotFound) | |
1107 continue; | |
1108 toHTMLOptionElement(items[foundIndex])->setSelectedState(true); | |
1109 startIndex = foundIndex + 1; | |
1110 } | |
1091 } | 1111 } |
1092 } | 1112 } |
1093 | 1113 |
1094 setOptionsChangedOnRenderer(); | 1114 setOptionsChangedOnRenderer(); |
1095 setNeedsValidityCheck(); | 1115 setNeedsValidityCheck(); |
1096 } | 1116 } |
1097 | 1117 |
1098 void HTMLSelectElement::parseMultipleAttribute(const AtomicString& value) | 1118 void HTMLSelectElement::parseMultipleAttribute(const AtomicString& value) |
1099 { | 1119 { |
1100 m_multiple = !value.isNull(); | 1120 m_multiple = !value.isNull(); |
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1740 int focusedIndex = activeSelectionEndListIndex(); | 1760 int focusedIndex = activeSelectionEndListIndex(); |
1741 if (focusedIndex < 0) | 1761 if (focusedIndex < 0) |
1742 focusedIndex = firstSelectableListIndex(); | 1762 focusedIndex = firstSelectableListIndex(); |
1743 if (focusedIndex < 0) | 1763 if (focusedIndex < 0) |
1744 return nullptr; | 1764 return nullptr; |
1745 HTMLElement* focused = listItems()[focusedIndex]; | 1765 HTMLElement* focused = listItems()[focusedIndex]; |
1746 return isHTMLOptionElement(focused) ? toHTMLOptionElement(focused) : nullptr ; | 1766 return isHTMLOptionElement(focused) ? toHTMLOptionElement(focused) : nullptr ; |
1747 } | 1767 } |
1748 | 1768 |
1749 } // namespace | 1769 } // namespace |
OLD | NEW |