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

Side by Side Diff: Source/core/html/HTMLTextAreaElement.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: add back dispatchFormControlChangeEvent() temporarily to not break chrome when blink gets rolled in 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/HTMLTextAreaElement.h ('k') | Source/web/WebFormControlElement.cpp » ('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) 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 reserv ed. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Apple Inc. All rights reserv ed.
6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com) 6 * (C) 2006 Alexey Proskuryakov (ap@nypop.com)
7 * Copyright (C) 2007 Samuel Weinig (sam@webkit.org) 7 * Copyright (C) 2007 Samuel Weinig (sam@webkit.org)
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 m_isDirty = true; 330 m_isDirty = true;
331 const_cast<HTMLTextAreaElement*>(this)->updatePlaceholderVisibility(false); 331 const_cast<HTMLTextAreaElement*>(this)->updatePlaceholderVisibility(false);
332 } 332 }
333 333
334 String HTMLTextAreaElement::value() const 334 String HTMLTextAreaElement::value() const
335 { 335 {
336 updateValue(); 336 updateValue();
337 return m_value; 337 return m_value;
338 } 338 }
339 339
340 void HTMLTextAreaElement::setValue(const String& value) 340 void HTMLTextAreaElement::setValue(const String& value, TextFieldEventBehavior e ventBehavior)
341 { 341 {
342 setValueCommon(value); 342 setValueCommon(value, eventBehavior);
tkent 2014/03/28 04:58:48 This function needs "RefPtr<HTMLTextAreaElement> p
Dan Beam 2014/03/28 05:03:48 Done.
343 m_isDirty = true; 343 m_isDirty = true;
344 setNeedsValidityCheck(); 344 setNeedsValidityCheck();
345 } 345 }
346 346
347 void HTMLTextAreaElement::setNonDirtyValue(const String& value) 347 void HTMLTextAreaElement::setNonDirtyValue(const String& value)
348 { 348 {
349 setValueCommon(value); 349 setValueCommon(value, DispatchNoEvent);
350 m_isDirty = false; 350 m_isDirty = false;
351 setNeedsValidityCheck(); 351 setNeedsValidityCheck();
352 } 352 }
353 353
354 void HTMLTextAreaElement::setValueCommon(const String& newValue) 354 void HTMLTextAreaElement::setValueCommon(const String& newValue, TextFieldEventB ehavior eventBehavior)
355 { 355 {
356 // Code elsewhere normalizes line endings added by the user via the keyboard or pasting. 356 // Code elsewhere normalizes line endings added by the user via the keyboard or pasting.
357 // We normalize line endings coming from JavaScript here. 357 // We normalize line endings coming from JavaScript here.
358 String normalizedValue = newValue.isNull() ? "" : newValue; 358 String normalizedValue = newValue.isNull() ? "" : newValue;
359 normalizedValue.replace("\r\n", "\n"); 359 normalizedValue.replace("\r\n", "\n");
360 normalizedValue.replace('\r', '\n'); 360 normalizedValue.replace('\r', '\n');
361 361
362 // Return early because we don't want to move the caret or trigger other sid e effects 362 // Return early because we don't want to move the caret or trigger other sid e effects
363 // when the value isn't changing. This matches Firefox behavior, at least. 363 // when the value isn't changing. This matches Firefox behavior, at least.
364 if (normalizedValue == value()) 364 if (normalizedValue == value())
365 return; 365 return;
366 366
367 RefPtr<HTMLTextAreaElement> protector(this);
tkent 2014/03/28 04:58:48 This is unnecessary because we need it in setValue
Dan Beam 2014/03/28 05:03:48 Done.
367 m_value = normalizedValue; 368 m_value = normalizedValue;
368 setInnerTextValue(m_value); 369 setInnerTextValue(m_value);
369 setLastChangeWasNotUserEdit(); 370 if (eventBehavior == DispatchNoEvent)
371 setLastChangeWasNotUserEdit();
370 updatePlaceholderVisibility(false); 372 updatePlaceholderVisibility(false);
371 setNeedsStyleRecalc(SubtreeStyleChange); 373 setNeedsStyleRecalc(SubtreeStyleChange);
372 setFormControlValueMatchesRenderer(true); 374 setFormControlValueMatchesRenderer(true);
373 m_suggestedValue = String(); 375 m_suggestedValue = String();
374 376
375 // Set the caret to the end of the text value. 377 // Set the caret to the end of the text value.
376 if (document().focusedElement() == this) { 378 if (document().focusedElement() == this) {
377 unsigned endOfString = m_value.length(); 379 unsigned endOfString = m_value.length();
378 setSelectionRange(endOfString, endOfString); 380 setSelectionRange(endOfString, endOfString);
379 } 381 }
380 382
381 notifyFormStateChanged(); 383 notifyFormStateChanged();
382 setTextAsOfLastFormControlChangeEvent(normalizedValue); 384 if (eventBehavior == DispatchNoEvent) {
385 setTextAsOfLastFormControlChangeEvent(normalizedValue);
386 } else {
387 if (eventBehavior == DispatchInputAndChangeEvent)
388 dispatchFormControlInputEvent();
389 dispatchFormControlChangeEvent();
390 }
383 } 391 }
384 392
385 String HTMLTextAreaElement::defaultValue() const 393 String HTMLTextAreaElement::defaultValue() const
386 { 394 {
387 StringBuilder value; 395 StringBuilder value;
388 396
389 // Since there may be comments, ignore nodes other than text nodes. 397 // Since there may be comments, ignore nodes other than text nodes.
390 for (Node* n = firstChild(); n; n = n->nextSibling()) { 398 for (Node* n = firstChild(); n; n = n->nextSibling()) {
391 if (n->isTextNode()) 399 if (n->isTextNode())
392 value.append(toText(n)->data()); 400 value.append(toText(n)->data());
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 { 558 {
551 return true; 559 return true;
552 } 560 }
553 561
554 bool HTMLTextAreaElement::supportsAutofocus() const 562 bool HTMLTextAreaElement::supportsAutofocus() const
555 { 563 {
556 return true; 564 return true;
557 } 565 }
558 566
559 } 567 }
OLDNEW
« no previous file with comments | « Source/core/html/HTMLTextAreaElement.h ('k') | Source/web/WebFormControlElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698