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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/html/HTMLSelectElement.h ('k') | Source/core/html/HTMLTextAreaElement.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLSelectElement.cpp
diff --git a/Source/core/html/HTMLSelectElement.cpp b/Source/core/html/HTMLSelectElement.cpp
index ed9942c1b431faf10bf5242adf2dab270549dd4b..36ffd1979a5936c729f4d514a2fc0c369bf0c58c 100644
--- a/Source/core/html/HTMLSelectElement.cpp
+++ b/Source/core/html/HTMLSelectElement.cpp
@@ -230,28 +230,33 @@ String HTMLSelectElement::value() const
return "";
}
-void HTMLSelectElement::setValue(const String &value)
+void HTMLSelectElement::setValue(const String &value, bool sendEvents)
{
// We clear the previously selected option(s) when needed, to guarantee calling setSelectedIndex() only once.
- if (value.isNull()) {
- setSelectedIndex(-1);
- return;
- }
-
- // Find the option with value() matching the given parameter and make it the current selection.
- const Vector<HTMLElement*>& items = listItems();
unsigned optionIndex = 0;
- for (unsigned i = 0; i < items.size(); i++) {
- if (isHTMLOptionElement(items[i])) {
- if (toHTMLOptionElement(items[i])->value() == value) {
- setSelectedIndex(optionIndex);
- return;
+ if (value.isNull()) {
+ optionIndex = -1;
+ } else {
+ // Find the option with value() matching the given parameter and make it the current selection.
+ const Vector<HTMLElement*>& items = listItems();
+ for (unsigned i = 0; i < items.size(); i++) {
+ if (isHTMLOptionElement(items[i])) {
+ if (toHTMLOptionElement(items[i])->value() == value)
+ break;
+ optionIndex++;
}
- optionIndex++;
}
+ if (optionIndex >= items.size())
+ optionIndex = -1;
}
+ setSelectedIndex(optionIndex);
- setSelectedIndex(-1);
+ if (sendEvents) {
+ if (usesMenuList())
+ dispatchInputAndChangeEventForMenuList(false);
+ else
+ listBoxOnChange();
+ }
}
String HTMLSelectElement::suggestedValue() const
@@ -672,12 +677,12 @@ void HTMLSelectElement::listBoxOnChange()
}
}
-void HTMLSelectElement::dispatchInputAndChangeEventForMenuList()
+void HTMLSelectElement::dispatchInputAndChangeEventForMenuList(bool requiresUserGesture)
{
ASSERT(usesMenuList());
int selected = selectedIndex();
- if (m_lastOnChangeIndex != selected && m_isProcessingUserDrivenChange) {
+ if (m_lastOnChangeIndex != selected && (!requiresUserGesture || m_isProcessingUserDrivenChange)) {
m_lastOnChangeIndex = selected;
m_isProcessingUserDrivenChange = false;
RefPtr<HTMLSelectElement> protector(this);
« 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