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

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLTextAreaElement.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, 2008, 2010 Apple Inc. All rights 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights
6 * reserved. 6 * reserved.
7 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) 7 * (C) 2006 Alexey Proskuryakov (ap@nypop.com)
8 * Copyright (C) 2007 Samuel Weinig (sam@webkit.org) 8 * Copyright (C) 2007 Samuel Weinig (sam@webkit.org)
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 // fix it. 278 // fix it.
279 Element* innerEditor = innerEditorElement(); 279 Element* innerEditor = innerEditorElement();
280 for (Node& node : NodeTraversal::descendantsOf(*innerEditor)) { 280 for (Node& node : NodeTraversal::descendantsOf(*innerEditor)) {
281 if (node.isTextNode()) 281 if (node.isTextNode())
282 continue; 282 continue;
283 DCHECK(isHTMLBRElement(node)); 283 DCHECK(isHTMLBRElement(node));
284 DCHECK_EQ(&node, innerEditor->lastChild()); 284 DCHECK_EQ(&node, innerEditor->lastChild());
285 } 285 }
286 #endif 286 #endif
287 addPlaceholderBreakElementIfNecessary(); 287 addPlaceholderBreakElementIfNecessary();
288 setChangedSinceLastFormControlChangeEvent(true); 288 setValueBeforeFirstUserEditIfNotSet();
289 updateValue(); 289 updateValue();
290 checkIfValueWasReverted(value());
290 setNeedsValidityCheck(); 291 setNeedsValidityCheck();
291 setAutofilled(false); 292 setAutofilled(false);
292 updatePlaceholderVisibility(); 293 updatePlaceholderVisibility();
293 294
294 if (!isFocused()) 295 if (!isFocused())
295 return; 296 return;
296 297
297 // When typing in a textarea, childrenChanged is not called, so we need to 298 // When typing in a textarea, childrenChanged is not called, so we need to
298 // force the directionality check. 299 // force the directionality check.
299 calculateAndAdjustDirectionality(); 300 calculateAndAdjustDirectionality();
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 normalizedValue.replace("\r\n", "\n"); 394 normalizedValue.replace("\r\n", "\n");
394 normalizedValue.replace('\r', '\n'); 395 normalizedValue.replace('\r', '\n');
395 396
396 // Return early because we don't want to trigger other side effects when the 397 // Return early because we don't want to trigger other side effects when the
397 // value isn't changing. This is interoperable though the specification 398 // value isn't changing. This is interoperable though the specification
398 // doesn't define so. 399 // doesn't define so.
399 // https://github.com/whatwg/html/issues/2412 400 // https://github.com/whatwg/html/issues/2412
400 if (normalizedValue == value()) 401 if (normalizedValue == value())
401 return; 402 return;
402 403
404 if (eventBehavior != DispatchNoEvent)
405 setValueBeforeFirstUserEditIfNotSet();
403 m_value = normalizedValue; 406 m_value = normalizedValue;
404 setInnerEditorValue(m_value); 407 setInnerEditorValue(m_value);
405 if (eventBehavior == DispatchNoEvent) 408 if (eventBehavior == DispatchNoEvent)
406 setLastChangeWasNotUserEdit(); 409 setLastChangeWasNotUserEdit();
410 else
411 checkIfValueWasReverted(m_value);
407 updatePlaceholderVisibility(); 412 updatePlaceholderVisibility();
408 setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::create( 413 setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::create(
409 StyleChangeReason::ControlValue)); 414 StyleChangeReason::ControlValue));
410 m_suggestedValue = String(); 415 m_suggestedValue = String();
411 setNeedsValidityCheck(); 416 setNeedsValidityCheck();
412 if (isFinishedParsingChildren() && 417 if (isFinishedParsingChildren() &&
413 selection == TextControlSetValueSelection::kSetSelectionToEnd) { 418 selection == TextControlSetValueSelection::kSetSelectionToEnd) {
414 // Set the caret to the end of the text value except for initialize. 419 // Set the caret to the end of the text value except for initialize.
415 unsigned endOfString = m_value.length(); 420 unsigned endOfString = m_value.length();
416 setSelectionRange(endOfString, endOfString); 421 setSelectionRange(endOfString, endOfString);
417 } 422 }
418 423
419 notifyFormStateChanged(); 424 notifyFormStateChanged();
420 switch (eventBehavior) { 425 switch (eventBehavior) {
421 case DispatchChangeEvent: 426 case DispatchChangeEvent:
422 dispatchFormControlChangeEvent(); 427 dispatchFormControlChangeEvent();
423 break; 428 break;
424 429
425 case DispatchInputAndChangeEvent: 430 case DispatchInputAndChangeEvent:
426 dispatchFormControlInputEvent(); 431 dispatchFormControlInputEvent();
427 dispatchFormControlChangeEvent(); 432 dispatchFormControlChangeEvent();
428 break; 433 break;
429 434
430 case DispatchNoEvent: 435 case DispatchNoEvent:
431 // We need to update textAsOfLastFormControlChangeEvent for |value| IDL
432 // setter without focus because input-assist features use setValue("...",
433 // DispatchChangeEvent) without setting focus.
434 if (!isFocused())
435 setTextAsOfLastFormControlChangeEvent(normalizedValue);
436 break; 436 break;
437 } 437 }
438 } 438 }
439 439
440 String HTMLTextAreaElement::defaultValue() const { 440 String HTMLTextAreaElement::defaultValue() const {
441 StringBuilder value; 441 StringBuilder value;
442 442
443 // Since there may be comments, ignore nodes other than text nodes. 443 // Since there may be comments, ignore nodes other than text nodes.
444 for (Node* n = firstChild(); n; n = n->nextSibling()) { 444 for (Node* n = firstChild(); n; n = n->nextSibling()) {
445 if (n->isTextNode()) 445 if (n->isTextNode())
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 const Element& source) { 626 const Element& source) {
627 const HTMLTextAreaElement& sourceElement = 627 const HTMLTextAreaElement& sourceElement =
628 static_cast<const HTMLTextAreaElement&>(source); 628 static_cast<const HTMLTextAreaElement&>(source);
629 setValueCommon(sourceElement.value(), DispatchNoEvent, 629 setValueCommon(sourceElement.value(), DispatchNoEvent,
630 TextControlSetValueSelection::kSetSelectionToEnd); 630 TextControlSetValueSelection::kSetSelectionToEnd);
631 m_isDirty = sourceElement.m_isDirty; 631 m_isDirty = sourceElement.m_isDirty;
632 TextControlElement::copyNonAttributePropertiesFromElement(source); 632 TextControlElement::copyNonAttributePropertiesFromElement(source);
633 } 633 }
634 634
635 } // namespace blink 635 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLInputElement.cpp ('k') | third_party/WebKit/Source/core/html/TextControlElement.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698