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

Unified Diff: third_party/WebKit/Source/core/html/TextControlElement.cpp

Issue 2796853002: Update text field 'change' event logic to match to Firefox. (Closed)
Patch Set: . Created 3 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/html/TextControlElement.cpp
diff --git a/third_party/WebKit/Source/core/html/TextControlElement.cpp b/third_party/WebKit/Source/core/html/TextControlElement.cpp
index 4c1e9485990b81c8fd48faf53abffaa89be1e518..2599972ced8fc5c7e2c9c0884a5fff23fa7867d4 100644
--- a/third_party/WebKit/Source/core/html/TextControlElement.cpp
+++ b/third_party/WebKit/Source/core/html/TextControlElement.cpp
@@ -74,17 +74,6 @@ TextControlElement::TextControlElement(const QualifiedName& tagName,
TextControlElement::~TextControlElement() {}
-Node::InsertionNotificationRequest TextControlElement::insertedInto(
- ContainerNode* insertionPoint) {
- HTMLFormControlElementWithState::insertedInto(insertionPoint);
- if (!insertionPoint->isConnected())
- return InsertionDone;
- String initialValue = value();
- setTextAsOfLastFormControlChangeEvent(initialValue.isNull() ? emptyString
- : initialValue);
- return InsertionDone;
-}
-
void TextControlElement::dispatchFocusEvent(
Element* oldFocusedElement,
WebFocusType type,
@@ -204,24 +193,30 @@ void TextControlElement::select() {
restoreCachedSelection();
}
-void TextControlElement::setChangedSinceLastFormControlChangeEvent(
- bool changed) {
- m_wasChangedSinceLastFormControlChangeEvent = changed;
+void TextControlElement::setValueBeforeFirstUserEditIfNotSet() {
+ if (!m_valueBeforeFirstUserEdit.isNull())
+ return;
+ String value = this->value();
+ m_valueBeforeFirstUserEdit = value.isNull() ? emptyString : value;
+}
+
+void TextControlElement::checkIfValueWasReverted(const String& value) {
+ DCHECK(!m_valueBeforeFirstUserEdit.isNull())
+ << "setValueBeforeFirstUserEditIfNotSet should be called beforehand.";
+ String nonNullValue = value.isNull() ? emptyString : value;
+ if (m_valueBeforeFirstUserEdit == nonNullValue)
+ clearValueBeforeFirstUserEdit();
+}
+
+void TextControlElement::clearValueBeforeFirstUserEdit() {
+ m_valueBeforeFirstUserEdit = String();
}
void TextControlElement::setFocused(bool flag) {
HTMLFormControlElementWithState::setFocused(flag);
- if (!flag) {
- if (wasChangedSinceLastFormControlChangeEvent()) {
- dispatchFormControlChangeEvent();
- } else {
- // |value| IDL attribute setter haven't updated
- // textAsOfLastFormControlChangeEvent while this is focused. So we
- // synchronize now.
- setTextAsOfLastFormControlChangeEvent(value());
- }
- }
+ if (!flag)
+ dispatchFormControlChangeEvent();
}
bool TextControlElement::shouldDispatchFormControlChangeEvent(
@@ -232,28 +227,30 @@ bool TextControlElement::shouldDispatchFormControlChangeEvent(
void TextControlElement::dispatchFormControlChangeEvent() {
String newValue = value();
- if (shouldDispatchFormControlChangeEvent(m_textAsOfLastFormControlChangeEvent,
+ if (!m_valueBeforeFirstUserEdit.isNull() &&
+ shouldDispatchFormControlChangeEvent(m_valueBeforeFirstUserEdit,
newValue)) {
- setTextAsOfLastFormControlChangeEvent(newValue);
+ clearValueBeforeFirstUserEdit();
dispatchChangeEvent();
+ } else {
+ clearValueBeforeFirstUserEdit();
}
- setChangedSinceLastFormControlChangeEvent(false);
}
void TextControlElement::enqueueChangeEvent() {
String newValue = value();
- if (shouldDispatchFormControlChangeEvent(m_textAsOfLastFormControlChangeEvent,
+ if (!m_valueBeforeFirstUserEdit.isNull() &&
+ shouldDispatchFormControlChangeEvent(m_valueBeforeFirstUserEdit,
newValue)) {
- setTextAsOfLastFormControlChangeEvent(newValue);
Event* event = Event::createBubble(EventTypeNames::change);
event->setTarget(this);
document().enqueueAnimationFrameEvent(event);
}
- setChangedSinceLastFormControlChangeEvent(false);
+ clearValueBeforeFirstUserEdit();
}
+// TODO(tkent): Remove this function.
void TextControlElement::dispatchFormControlInputEvent() {
- setChangedSinceLastFormControlChangeEvent(true);
HTMLFormControlElementWithState::dispatchInputEvent();
}
« no previous file with comments | « third_party/WebKit/Source/core/html/TextControlElement.h ('k') | third_party/WebKit/Source/core/html/forms/FileInputType.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698