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

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

Issue 1838183003: Fix problems on changing 'multiple' state SELECT element to 'single' state. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix a typo in a comment Created 4 years, 8 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
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 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 cache->childrenChanged(this); 437 cache->childrenChanged(this);
438 } 438 }
439 } 439 }
440 440
441 void HTMLSelectElement::accessKeyAction(bool sendMouseEvents) 441 void HTMLSelectElement::accessKeyAction(bool sendMouseEvents)
442 { 442 {
443 focus(); 443 focus();
444 dispatchSimulatedClick(nullptr, sendMouseEvents ? SendMouseUpDownEvents : Se ndNoEvents); 444 dispatchSimulatedClick(nullptr, sendMouseEvents ? SendMouseUpDownEvents : Se ndNoEvents);
445 } 445 }
446 446
447 void HTMLSelectElement::setMultiple(bool multiple)
448 {
449 bool oldMultiple = this->multiple();
450 int oldSelectedIndex = selectedIndex();
451 setAttribute(multipleAttr, multiple ? emptyAtom : nullAtom);
452
453 // Restore selectedIndex after changing the multiple flag to preserve
454 // selection as single-line and multi-line has different defaults.
455 if (oldMultiple != this->multiple())
456 selectOption(oldSelectedIndex, DeselectOtherOptions);
457 }
458
459 void HTMLSelectElement::setSize(unsigned size) 447 void HTMLSelectElement::setSize(unsigned size)
460 { 448 {
461 setUnsignedIntegralAttribute(sizeAttr, size); 449 setUnsignedIntegralAttribute(sizeAttr, size);
462 } 450 }
463 451
464 Element* HTMLSelectElement::namedItem(const AtomicString& name) 452 Element* HTMLSelectElement::namedItem(const AtomicString& name)
465 { 453 {
466 return options()->namedItem(name); 454 return options()->namedItem(name);
467 } 455 }
468 456
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 } 1215 }
1228 } 1216 }
1229 } 1217 }
1230 1218
1231 setOptionsChangedOnLayoutObject(); 1219 setOptionsChangedOnLayoutObject();
1232 setNeedsValidityCheck(); 1220 setNeedsValidityCheck();
1233 } 1221 }
1234 1222
1235 void HTMLSelectElement::parseMultipleAttribute(const AtomicString& value) 1223 void HTMLSelectElement::parseMultipleAttribute(const AtomicString& value)
1236 { 1224 {
1225 bool oldMultiple = m_multiple;
1226 int oldSelectedIndex = selectedIndex();
1237 m_multiple = !value.isNull(); 1227 m_multiple = !value.isNull();
1238 setNeedsValidityCheck(); 1228 setNeedsValidityCheck();
1239
1240 lazyReattachIfAttached(); 1229 lazyReattachIfAttached();
1230 // Restore selectedIndex after changing the multiple flag to preserve
1231 // selection as single-line and multi-line has different defaults.
1232 if (oldMultiple != m_multiple) {
1233 // Preserving the first selection is compatible with Firefox and
1234 // WebKit. However Edge seems to "ask for a reset" simply. As of 2016
1235 // March, the HTML specification says nothing about this.
1236 if (oldSelectedIndex >= 0)
1237 selectOption(oldSelectedIndex, DeselectOtherOptions);
1238 else
1239 resetToDefaultSelection();
1240 }
1241 } 1241 }
1242 1242
1243 void HTMLSelectElement::appendToFormData(FormData& formData) 1243 void HTMLSelectElement::appendToFormData(FormData& formData)
1244 { 1244 {
1245 const AtomicString& name = this->name(); 1245 const AtomicString& name = this->name();
1246 if (name.isEmpty()) 1246 if (name.isEmpty())
1247 return; 1247 return;
1248 1248
1249 for (auto& element : listItems()) { 1249 for (auto& element : listItems()) {
1250 if (isHTMLOptionElement(*element) && toHTMLOptionElement(*element).selec ted() && !toHTMLOptionElement(*element).isDisabledFormControl()) 1250 if (isHTMLOptionElement(*element) && toHTMLOptionElement(*element).selec ted() && !toHTMLOptionElement(*element).isDisabledFormControl())
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLSelectElement.h ('k') | third_party/WebKit/Source/core/html/HTMLSelectElement.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698