Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(739)

Side by Side Diff: Source/core/html/HTMLSelectElement.cpp

Issue 566913002: Revert of HTMLSelectElement does not include selected index/indices while saving state (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/core.gypi ('k') | Source/core/html/HTMLSelectElementTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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));
1043 if (!multiple()) 1042 if (!multiple())
1044 break; 1043 break;
1045 } 1044 }
1046 return state; 1045 return state;
1047 } 1046 }
1048 1047
1049 size_t HTMLSelectElement::searchOptionsForValue(const String& value, size_t list IndexStart, size_t listIndexEnd) const 1048 size_t HTMLSelectElement::searchOptionsForValue(const String& value, size_t list IndexStart, size_t listIndexEnd) const
1050 { 1049 {
1051 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& items = listItems( ); 1050 const WillBeHeapVector<RawPtrWillBeMember<HTMLElement> >& items = listItems( );
1052 size_t loopEndIndex = std::min(items.size(), listIndexEnd); 1051 size_t loopEndIndex = std::min(items.size(), listIndexEnd);
(...skipping 14 matching lines...) Expand all
1067 size_t itemsSize = items.size(); 1066 size_t itemsSize = items.size();
1068 if (!itemsSize) 1067 if (!itemsSize)
1069 return; 1068 return;
1070 1069
1071 for (size_t i = 0; i < itemsSize; ++i) { 1070 for (size_t i = 0; i < itemsSize; ++i) {
1072 if (!isHTMLOptionElement(items[i])) 1071 if (!isHTMLOptionElement(items[i]))
1073 continue; 1072 continue;
1074 toHTMLOptionElement(items[i])->setSelectedState(false); 1073 toHTMLOptionElement(items[i])->setSelectedState(false);
1075 } 1074 }
1076 1075
1077 // The saved state should have at least one value and an index.
1078 ASSERT(state.valueSize() >= 2);
1079 if (!multiple()) { 1076 if (!multiple()) {
1080 size_t index = state[1].toUInt(); 1077 size_t foundIndex = searchOptionsForValue(state[0], 0, itemsSize);
1081 if (index < itemsSize && isHTMLOptionElement(items[index]) && toHTMLOpti onElement(items[index])->value() == state[0]) { 1078 if (foundIndex != kNotFound)
1082 toHTMLOptionElement(items[index])->setSelectedState(true); 1079 toHTMLOptionElement(items[foundIndex])->setSelectedState(true);
1083 } else {
1084 size_t foundIndex = searchOptionsForValue(state[0], 0, itemsSize);
1085 if (foundIndex != kNotFound)
1086 toHTMLOptionElement(items[foundIndex])->setSelectedState(true);
1087 }
1088 } else { 1080 } else {
1089 size_t startIndex = 0; 1081 size_t startIndex = 0;
1090 for (size_t i = 0; i < state.valueSize(); i+= 2) { 1082 for (size_t i = 0; i < state.valueSize(); ++i) {
1091 const String& value = state[i]; 1083 const String& value = state[i];
1092 const size_t index = state[i + 1].toUInt(); 1084 size_t foundIndex = searchOptionsForValue(value, startIndex, itemsSi ze);
1093 if (index < itemsSize && isHTMLOptionElement(items[index]) && toHTML OptionElement(items[index])->value() == value) { 1085 if (foundIndex == kNotFound)
1094 toHTMLOptionElement(items[index])->setSelectedState(true); 1086 foundIndex = searchOptionsForValue(value, 0, startIndex);
1095 startIndex = index + 1; 1087 if (foundIndex == kNotFound)
1096 } else { 1088 continue;
1097 size_t foundIndex = searchOptionsForValue(value, startIndex, ite msSize); 1089 toHTMLOptionElement(items[foundIndex])->setSelectedState(true);
1098 if (foundIndex == kNotFound) 1090 startIndex = foundIndex + 1;
1099 foundIndex = searchOptionsForValue(value, 0, startIndex);
1100 if (foundIndex == kNotFound)
1101 continue;
1102 toHTMLOptionElement(items[foundIndex])->setSelectedState(true);
1103 startIndex = foundIndex + 1;
1104 }
1105 } 1091 }
1106 } 1092 }
1107 1093
1108 setOptionsChangedOnRenderer(); 1094 setOptionsChangedOnRenderer();
1109 setNeedsValidityCheck(); 1095 setNeedsValidityCheck();
1110 } 1096 }
1111 1097
1112 void HTMLSelectElement::parseMultipleAttribute(const AtomicString& value) 1098 void HTMLSelectElement::parseMultipleAttribute(const AtomicString& value)
1113 { 1099 {
1114 m_multiple = !value.isNull(); 1100 m_multiple = !value.isNull();
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
1754 int focusedIndex = activeSelectionEndListIndex(); 1740 int focusedIndex = activeSelectionEndListIndex();
1755 if (focusedIndex < 0) 1741 if (focusedIndex < 0)
1756 focusedIndex = firstSelectableListIndex(); 1742 focusedIndex = firstSelectableListIndex();
1757 if (focusedIndex < 0) 1743 if (focusedIndex < 0)
1758 return nullptr; 1744 return nullptr;
1759 HTMLElement* focused = listItems()[focusedIndex]; 1745 HTMLElement* focused = listItems()[focusedIndex];
1760 return isHTMLOptionElement(focused) ? toHTMLOptionElement(focused) : nullptr ; 1746 return isHTMLOptionElement(focused) ? toHTMLOptionElement(focused) : nullptr ;
1761 } 1747 }
1762 1748
1763 } // namespace 1749 } // namespace
OLDNEW
« no previous file with comments | « Source/core/core.gypi ('k') | Source/core/html/HTMLSelectElementTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698