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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) 6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com)
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 doc.frame() 67 doc.frame()
68 ->editor() 68 ->editor()
69 .behavior() 69 .behavior()
70 .shouldConsiderSelectionAsDirectional() 70 .shouldConsiderSelectionAsDirectional()
71 ? SelectionHasForwardDirection 71 ? SelectionHasForwardDirection
72 : SelectionHasNoDirection; 72 : SelectionHasNoDirection;
73 } 73 }
74 74
75 TextControlElement::~TextControlElement() {} 75 TextControlElement::~TextControlElement() {}
76 76
77 Node::InsertionNotificationRequest TextControlElement::insertedInto(
78 ContainerNode* insertionPoint) {
79 HTMLFormControlElementWithState::insertedInto(insertionPoint);
80 if (!insertionPoint->isConnected())
81 return InsertionDone;
82 String initialValue = value();
83 setTextAsOfLastFormControlChangeEvent(initialValue.isNull() ? emptyString
84 : initialValue);
85 return InsertionDone;
86 }
87
88 void TextControlElement::dispatchFocusEvent( 77 void TextControlElement::dispatchFocusEvent(
89 Element* oldFocusedElement, 78 Element* oldFocusedElement,
90 WebFocusType type, 79 WebFocusType type,
91 InputDeviceCapabilities* sourceCapabilities) { 80 InputDeviceCapabilities* sourceCapabilities) {
92 if (supportsPlaceholder()) 81 if (supportsPlaceholder())
93 updatePlaceholderVisibility(); 82 updatePlaceholderVisibility();
94 handleFocusEvent(oldFocusedElement, type); 83 handleFocusEvent(oldFocusedElement, type);
95 HTMLFormControlElementWithState::dispatchFocusEvent(oldFocusedElement, type, 84 HTMLFormControlElementWithState::dispatchFocusEvent(oldFocusedElement, type,
96 sourceCapabilities); 85 sourceCapabilities);
97 } 86 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 186 }
198 187
199 void TextControlElement::select() { 188 void TextControlElement::select() {
200 setSelectionRangeForBinding(0, std::numeric_limits<unsigned>::max()); 189 setSelectionRangeForBinding(0, std::numeric_limits<unsigned>::max());
201 // Avoid SelectionBehaviorOnFocus::Restore, which scrolls containers to show 190 // Avoid SelectionBehaviorOnFocus::Restore, which scrolls containers to show
202 // the selection. 191 // the selection.
203 focus(FocusParams(SelectionBehaviorOnFocus::None, WebFocusTypeNone, nullptr)); 192 focus(FocusParams(SelectionBehaviorOnFocus::None, WebFocusTypeNone, nullptr));
204 restoreCachedSelection(); 193 restoreCachedSelection();
205 } 194 }
206 195
207 void TextControlElement::setChangedSinceLastFormControlChangeEvent( 196 void TextControlElement::setValueBeforeFirstUserEditIfNotSet() {
208 bool changed) { 197 if (!m_valueBeforeFirstUserEdit.isNull())
209 m_wasChangedSinceLastFormControlChangeEvent = changed; 198 return;
199 String value = this->value();
200 m_valueBeforeFirstUserEdit = value.isNull() ? emptyString : value;
201 }
202
203 void TextControlElement::checkIfValueWasReverted(const String& value) {
204 DCHECK(!m_valueBeforeFirstUserEdit.isNull())
205 << "setValueBeforeFirstUserEditIfNotSet should be called beforehand.";
206 String nonNullValue = value.isNull() ? emptyString : value;
207 if (m_valueBeforeFirstUserEdit == nonNullValue)
208 clearValueBeforeFirstUserEdit();
209 }
210
211 void TextControlElement::clearValueBeforeFirstUserEdit() {
212 m_valueBeforeFirstUserEdit = String();
210 } 213 }
211 214
212 void TextControlElement::setFocused(bool flag) { 215 void TextControlElement::setFocused(bool flag) {
213 HTMLFormControlElementWithState::setFocused(flag); 216 HTMLFormControlElementWithState::setFocused(flag);
214 217
215 if (!flag) { 218 if (!flag)
216 if (wasChangedSinceLastFormControlChangeEvent()) { 219 dispatchFormControlChangeEvent();
217 dispatchFormControlChangeEvent();
218 } else {
219 // |value| IDL attribute setter haven't updated
220 // textAsOfLastFormControlChangeEvent while this is focused. So we
221 // synchronize now.
222 setTextAsOfLastFormControlChangeEvent(value());
223 }
224 }
225 } 220 }
226 221
227 bool TextControlElement::shouldDispatchFormControlChangeEvent( 222 bool TextControlElement::shouldDispatchFormControlChangeEvent(
228 String& oldValue, 223 String& oldValue,
229 String& newValue) { 224 String& newValue) {
230 return !equalIgnoringNullity(oldValue, newValue); 225 return !equalIgnoringNullity(oldValue, newValue);
231 } 226 }
232 227
233 void TextControlElement::dispatchFormControlChangeEvent() { 228 void TextControlElement::dispatchFormControlChangeEvent() {
234 String newValue = value(); 229 String newValue = value();
235 if (shouldDispatchFormControlChangeEvent(m_textAsOfLastFormControlChangeEvent, 230 if (!m_valueBeforeFirstUserEdit.isNull() &&
231 shouldDispatchFormControlChangeEvent(m_valueBeforeFirstUserEdit,
236 newValue)) { 232 newValue)) {
237 setTextAsOfLastFormControlChangeEvent(newValue); 233 clearValueBeforeFirstUserEdit();
238 dispatchChangeEvent(); 234 dispatchChangeEvent();
235 } else {
236 clearValueBeforeFirstUserEdit();
239 } 237 }
240 setChangedSinceLastFormControlChangeEvent(false);
241 } 238 }
242 239
243 void TextControlElement::enqueueChangeEvent() { 240 void TextControlElement::enqueueChangeEvent() {
244 String newValue = value(); 241 String newValue = value();
245 if (shouldDispatchFormControlChangeEvent(m_textAsOfLastFormControlChangeEvent, 242 if (!m_valueBeforeFirstUserEdit.isNull() &&
243 shouldDispatchFormControlChangeEvent(m_valueBeforeFirstUserEdit,
246 newValue)) { 244 newValue)) {
247 setTextAsOfLastFormControlChangeEvent(newValue);
248 Event* event = Event::createBubble(EventTypeNames::change); 245 Event* event = Event::createBubble(EventTypeNames::change);
249 event->setTarget(this); 246 event->setTarget(this);
250 document().enqueueAnimationFrameEvent(event); 247 document().enqueueAnimationFrameEvent(event);
251 } 248 }
252 setChangedSinceLastFormControlChangeEvent(false); 249 clearValueBeforeFirstUserEdit();
253 } 250 }
254 251
252 // TODO(tkent): Remove this function.
255 void TextControlElement::dispatchFormControlInputEvent() { 253 void TextControlElement::dispatchFormControlInputEvent() {
256 setChangedSinceLastFormControlChangeEvent(true);
257 HTMLFormControlElementWithState::dispatchInputEvent(); 254 HTMLFormControlElementWithState::dispatchInputEvent();
258 } 255 }
259 256
260 void TextControlElement::setRangeText(const String& replacement, 257 void TextControlElement::setRangeText(const String& replacement,
261 ExceptionState& exceptionState) { 258 ExceptionState& exceptionState) {
262 setRangeText(replacement, selectionStart(), selectionEnd(), "preserve", 259 setRangeText(replacement, selectionStart(), selectionEnd(), "preserve",
263 exceptionState); 260 exceptionState);
264 } 261 }
265 262
266 void TextControlElement::setRangeText(const String& replacement, 263 void TextControlElement::setRangeText(const String& replacement,
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 968
972 void TextControlElement::copyNonAttributePropertiesFromElement( 969 void TextControlElement::copyNonAttributePropertiesFromElement(
973 const Element& source) { 970 const Element& source) {
974 const TextControlElement& sourceElement = 971 const TextControlElement& sourceElement =
975 static_cast<const TextControlElement&>(source); 972 static_cast<const TextControlElement&>(source);
976 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit; 973 m_lastChangeWasUserEdit = sourceElement.m_lastChangeWasUserEdit;
977 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source); 974 HTMLFormControlElement::copyNonAttributePropertiesFromElement(source);
978 } 975 }
979 976
980 } // namespace blink 977 } // namespace blink
OLDNEW
« 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