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 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& items = listItems(
); | 1033 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& items = listItems(
); |
1034 size_t length = items.size(); | 1034 size_t length = items.size(); |
1035 FormControlState state; | 1035 FormControlState state; |
1036 for (unsigned i = 0; i < length; ++i) { | 1036 for (unsigned i = 0; i < length; ++i) { |
1037 if (!isHTMLOptionElement(*items[i])) | 1037 if (!isHTMLOptionElement(*items[i])) |
1038 continue; | 1038 continue; |
1039 HTMLOptionElement* option = toHTMLOptionElement(items[i]); | 1039 HTMLOptionElement* option = toHTMLOptionElement(items[i]); |
1040 if (!option->selected()) | 1040 if (!option->selected()) |
1041 continue; | 1041 continue; |
1042 state.append(option->value()); | 1042 state.append(option->value()); |
| 1043 state.append(String::number(i)); |
1043 if (!multiple()) | 1044 if (!multiple()) |
1044 break; | 1045 break; |
1045 } | 1046 } |
1046 return state; | 1047 return state; |
1047 } | 1048 } |
1048 | 1049 |
1049 size_t HTMLSelectElement::searchOptionsForValue(const String& value, size_t list
IndexStart, size_t listIndexEnd) const | 1050 size_t HTMLSelectElement::searchOptionsForValue(const String& value, size_t list
IndexStart, size_t listIndexEnd) const |
1050 { | 1051 { |
1051 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& items = listItems(
); | 1052 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& items = listItems(
); |
1052 size_t loopEndIndex = std::min(items.size(), listIndexEnd); | 1053 size_t loopEndIndex = std::min(items.size(), listIndexEnd); |
(...skipping 14 matching lines...) Expand all Loading... |
1067 size_t itemsSize = items.size(); | 1068 size_t itemsSize = items.size(); |
1068 if (!itemsSize) | 1069 if (!itemsSize) |
1069 return; | 1070 return; |
1070 | 1071 |
1071 for (size_t i = 0; i < itemsSize; ++i) { | 1072 for (size_t i = 0; i < itemsSize; ++i) { |
1072 if (!isHTMLOptionElement(items[i])) | 1073 if (!isHTMLOptionElement(items[i])) |
1073 continue; | 1074 continue; |
1074 toHTMLOptionElement(items[i])->setSelectedState(false); | 1075 toHTMLOptionElement(items[i])->setSelectedState(false); |
1075 } | 1076 } |
1076 | 1077 |
| 1078 // The saved state should have at least one value and an index. |
| 1079 ASSERT(state.valueSize() >= 2); |
1077 if (!multiple()) { | 1080 if (!multiple()) { |
1078 size_t foundIndex = searchOptionsForValue(state[0], 0, itemsSize); | 1081 size_t index = state[1].toUInt(); |
1079 if (foundIndex != kNotFound) | 1082 if (index < itemsSize && isHTMLOptionElement(items[index]) && toHTMLOpti
onElement(items[index])->value() == state[0]) { |
1080 toHTMLOptionElement(items[foundIndex])->setSelectedState(true); | 1083 toHTMLOptionElement(items[index])->setSelectedState(true); |
| 1084 } else { |
| 1085 size_t foundIndex = searchOptionsForValue(state[0], 0, itemsSize); |
| 1086 if (foundIndex != kNotFound) |
| 1087 toHTMLOptionElement(items[foundIndex])->setSelectedState(true); |
| 1088 } |
1081 } else { | 1089 } else { |
1082 size_t startIndex = 0; | 1090 size_t startIndex = 0; |
1083 for (size_t i = 0; i < state.valueSize(); ++i) { | 1091 for (size_t i = 0; i < state.valueSize(); i+= 2) { |
1084 const String& value = state[i]; | 1092 const String& value = state[i]; |
1085 size_t foundIndex = searchOptionsForValue(value, startIndex, itemsSi
ze); | 1093 const size_t index = state[i + 1].toUInt(); |
1086 if (foundIndex == kNotFound) | 1094 if (index < itemsSize && isHTMLOptionElement(items[index]) && toHTML
OptionElement(items[index])->value() == value) { |
1087 foundIndex = searchOptionsForValue(value, 0, startIndex); | 1095 toHTMLOptionElement(items[index])->setSelectedState(true); |
1088 if (foundIndex == kNotFound) | 1096 startIndex = index + 1; |
1089 continue; | 1097 } else { |
1090 toHTMLOptionElement(items[foundIndex])->setSelectedState(true); | 1098 size_t foundIndex = searchOptionsForValue(value, startIndex, ite
msSize); |
1091 startIndex = foundIndex + 1; | 1099 if (foundIndex == kNotFound) |
| 1100 foundIndex = searchOptionsForValue(value, 0, startIndex); |
| 1101 if (foundIndex == kNotFound) |
| 1102 continue; |
| 1103 toHTMLOptionElement(items[foundIndex])->setSelectedState(true); |
| 1104 startIndex = foundIndex + 1; |
| 1105 } |
1092 } | 1106 } |
1093 } | 1107 } |
1094 | 1108 |
1095 setOptionsChangedOnRenderer(); | 1109 setOptionsChangedOnRenderer(); |
1096 setNeedsValidityCheck(); | 1110 setNeedsValidityCheck(); |
1097 } | 1111 } |
1098 | 1112 |
1099 void HTMLSelectElement::parseMultipleAttribute(const AtomicString& value) | 1113 void HTMLSelectElement::parseMultipleAttribute(const AtomicString& value) |
1100 { | 1114 { |
1101 m_multiple = !value.isNull(); | 1115 m_multiple = !value.isNull(); |
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1741 int focusedIndex = activeSelectionEndListIndex(); | 1755 int focusedIndex = activeSelectionEndListIndex(); |
1742 if (focusedIndex < 0) | 1756 if (focusedIndex < 0) |
1743 focusedIndex = firstSelectableListIndex(); | 1757 focusedIndex = firstSelectableListIndex(); |
1744 if (focusedIndex < 0) | 1758 if (focusedIndex < 0) |
1745 return nullptr; | 1759 return nullptr; |
1746 HTMLElement* focused = listItems()[focusedIndex]; | 1760 HTMLElement* focused = listItems()[focusedIndex]; |
1747 return isHTMLOptionElement(focused) ? toHTMLOptionElement(focused) : nullptr
; | 1761 return isHTMLOptionElement(focused) ? toHTMLOptionElement(focused) : nullptr
; |
1748 } | 1762 } |
1749 | 1763 |
1750 } // namespace | 1764 } // namespace |
OLD | NEW |