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

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

Issue 215903003: Autofill/rAc: dispatch "input" events when changing text contents of <textarea>, (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: protecting protectors everywhere Created 6 years, 9 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/html/HTMLSelectElement.h ('k') | Source/core/html/HTMLTextAreaElement.h » ('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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 String HTMLSelectElement::value() const 223 String HTMLSelectElement::value() const
224 { 224 {
225 const Vector<HTMLElement*>& items = listItems(); 225 const Vector<HTMLElement*>& items = listItems();
226 for (unsigned i = 0; i < items.size(); i++) { 226 for (unsigned i = 0; i < items.size(); i++) {
227 if (isHTMLOptionElement(items[i]) && toHTMLOptionElement(items[i])->sele cted()) 227 if (isHTMLOptionElement(items[i]) && toHTMLOptionElement(items[i])->sele cted())
228 return toHTMLOptionElement(items[i])->value(); 228 return toHTMLOptionElement(items[i])->value();
229 } 229 }
230 return ""; 230 return "";
231 } 231 }
232 232
233 void HTMLSelectElement::setValue(const String &value) 233 void HTMLSelectElement::setValue(const String &value, bool sendEvents)
234 { 234 {
235 // We clear the previously selected option(s) when needed, to guarantee call ing setSelectedIndex() only once. 235 // We clear the previously selected option(s) when needed, to guarantee call ing setSelectedIndex() only once.
236 unsigned optionIndex = 0;
236 if (value.isNull()) { 237 if (value.isNull()) {
237 setSelectedIndex(-1); 238 optionIndex = -1;
238 return; 239 } else {
240 // Find the option with value() matching the given parameter and make it the current selection.
241 const Vector<HTMLElement*>& items = listItems();
242 for (unsigned i = 0; i < items.size(); i++) {
243 if (isHTMLOptionElement(items[i])) {
244 if (toHTMLOptionElement(items[i])->value() == value)
245 break;
246 optionIndex++;
247 }
248 }
249 if (optionIndex >= items.size())
250 optionIndex = -1;
239 } 251 }
252 setSelectedIndex(optionIndex);
240 253
241 // Find the option with value() matching the given parameter and make it the current selection. 254 if (sendEvents) {
242 const Vector<HTMLElement*>& items = listItems(); 255 if (usesMenuList())
243 unsigned optionIndex = 0; 256 dispatchInputAndChangeEventForMenuList(false);
244 for (unsigned i = 0; i < items.size(); i++) { 257 else
245 if (isHTMLOptionElement(items[i])) { 258 listBoxOnChange();
246 if (toHTMLOptionElement(items[i])->value() == value) {
247 setSelectedIndex(optionIndex);
248 return;
249 }
250 optionIndex++;
251 }
252 } 259 }
253
254 setSelectedIndex(-1);
255 } 260 }
256 261
257 String HTMLSelectElement::suggestedValue() const 262 String HTMLSelectElement::suggestedValue() const
258 { 263 {
259 const Vector<HTMLElement*>& items = listItems(); 264 const Vector<HTMLElement*>& items = listItems();
260 for (unsigned i = 0; i < items.size(); ++i) { 265 for (unsigned i = 0; i < items.size(); ++i) {
261 if (isHTMLOptionElement(items[i]) && m_suggestedIndex >= 0) { 266 if (isHTMLOptionElement(items[i]) && m_suggestedIndex >= 0) {
262 if (i == static_cast<unsigned>(m_suggestedIndex)) 267 if (i == static_cast<unsigned>(m_suggestedIndex))
263 return toHTMLOptionElement(items[i])->value(); 268 return toHTMLOptionElement(items[i])->value();
264 } 269 }
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 m_lastOnChangeSelection[i] = selected; 670 m_lastOnChangeSelection[i] = selected;
666 } 671 }
667 672
668 if (fireOnChange) { 673 if (fireOnChange) {
669 RefPtr<HTMLSelectElement> protector(this); 674 RefPtr<HTMLSelectElement> protector(this);
670 dispatchInputEvent(); 675 dispatchInputEvent();
671 dispatchFormControlChangeEvent(); 676 dispatchFormControlChangeEvent();
672 } 677 }
673 } 678 }
674 679
675 void HTMLSelectElement::dispatchInputAndChangeEventForMenuList() 680 void HTMLSelectElement::dispatchInputAndChangeEventForMenuList(bool requiresUser Gesture)
676 { 681 {
677 ASSERT(usesMenuList()); 682 ASSERT(usesMenuList());
678 683
679 int selected = selectedIndex(); 684 int selected = selectedIndex();
680 if (m_lastOnChangeIndex != selected && m_isProcessingUserDrivenChange) { 685 if (m_lastOnChangeIndex != selected && (!requiresUserGesture || m_isProcessi ngUserDrivenChange)) {
681 m_lastOnChangeIndex = selected; 686 m_lastOnChangeIndex = selected;
682 m_isProcessingUserDrivenChange = false; 687 m_isProcessingUserDrivenChange = false;
683 RefPtr<HTMLSelectElement> protector(this); 688 RefPtr<HTMLSelectElement> protector(this);
684 dispatchInputEvent(); 689 dispatchInputEvent();
685 dispatchFormControlChangeEvent(); 690 dispatchFormControlChangeEvent();
686 } 691 }
687 } 692 }
688 693
689 void HTMLSelectElement::scrollToSelection() 694 void HTMLSelectElement::scrollToSelection()
690 { 695 {
(...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after
1618 { 1623 {
1619 return true; 1624 return true;
1620 } 1625 }
1621 1626
1622 bool HTMLSelectElement::supportsAutofocus() const 1627 bool HTMLSelectElement::supportsAutofocus() const
1623 { 1628 {
1624 return true; 1629 return true;
1625 } 1630 }
1626 1631
1627 } // namespace 1632 } // namespace
OLDNEW
« no previous file with comments | « Source/core/html/HTMLSelectElement.h ('k') | Source/core/html/HTMLTextAreaElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698