OLD | NEW |
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 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 m_isDirty = true; | 370 m_isDirty = true; |
371 const_cast<HTMLTextAreaElement*>(this)->updatePlaceholderVisibility(); | 371 const_cast<HTMLTextAreaElement*>(this)->updatePlaceholderVisibility(); |
372 } | 372 } |
373 | 373 |
374 String HTMLTextAreaElement::value() const { | 374 String HTMLTextAreaElement::value() const { |
375 updateValue(); | 375 updateValue(); |
376 return m_value; | 376 return m_value; |
377 } | 377 } |
378 | 378 |
379 void HTMLTextAreaElement::setValue(const String& value, | 379 void HTMLTextAreaElement::setValue(const String& value, |
380 TextFieldEventBehavior eventBehavior) { | 380 TextFieldEventBehavior eventBehavior, |
381 setValueCommon(value, eventBehavior); | 381 TextControlSetValueSelection selection) { |
| 382 setValueCommon(value, eventBehavior, selection); |
382 m_isDirty = true; | 383 m_isDirty = true; |
383 } | 384 } |
384 | 385 |
385 void HTMLTextAreaElement::setNonDirtyValue(const String& value) { | 386 void HTMLTextAreaElement::setNonDirtyValue(const String& value) { |
386 setValueCommon(value, DispatchNoEvent); | 387 setValueCommon(value, DispatchNoEvent, |
| 388 TextControlSetValueSelection::kSetSelectionToEnd); |
387 m_isDirty = false; | 389 m_isDirty = false; |
388 } | 390 } |
389 | 391 |
390 void HTMLTextAreaElement::setValueCommon(const String& newValue, | 392 void HTMLTextAreaElement::setValueCommon( |
391 TextFieldEventBehavior eventBehavior) { | 393 const String& newValue, |
| 394 TextFieldEventBehavior eventBehavior, |
| 395 TextControlSetValueSelection selection) { |
392 // Code elsewhere normalizes line endings added by the user via the keyboard | 396 // Code elsewhere normalizes line endings added by the user via the keyboard |
393 // or pasting. We normalize line endings coming from JavaScript here. | 397 // or pasting. We normalize line endings coming from JavaScript here. |
394 String normalizedValue = newValue.isNull() ? "" : newValue; | 398 String normalizedValue = newValue.isNull() ? "" : newValue; |
395 normalizedValue.replace("\r\n", "\n"); | 399 normalizedValue.replace("\r\n", "\n"); |
396 normalizedValue.replace('\r', '\n'); | 400 normalizedValue.replace('\r', '\n'); |
397 | 401 |
398 // Return early because we don't want to trigger other side effects when the | 402 // Return early because we don't want to trigger other side effects when the |
399 // value isn't changing. This is interoperable though the specification | 403 // value isn't changing. This is interoperable though the specification |
400 // doesn't define so. | 404 // doesn't define so. |
401 // https://github.com/whatwg/html/issues/2412 | 405 // https://github.com/whatwg/html/issues/2412 |
402 if (normalizedValue == value()) | 406 if (normalizedValue == value()) |
403 return; | 407 return; |
404 | 408 |
405 m_value = normalizedValue; | 409 m_value = normalizedValue; |
406 setInnerEditorValue(m_value); | 410 setInnerEditorValue(m_value); |
407 if (eventBehavior == DispatchNoEvent) | 411 if (eventBehavior == DispatchNoEvent) |
408 setLastChangeWasNotUserEdit(); | 412 setLastChangeWasNotUserEdit(); |
409 updatePlaceholderVisibility(); | 413 updatePlaceholderVisibility(); |
410 setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::create( | 414 setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::create( |
411 StyleChangeReason::ControlValue)); | 415 StyleChangeReason::ControlValue)); |
412 m_suggestedValue = String(); | 416 m_suggestedValue = String(); |
413 setNeedsValidityCheck(); | 417 setNeedsValidityCheck(); |
414 if (isFinishedParsingChildren()) { | 418 if (isFinishedParsingChildren() && |
| 419 selection == TextControlSetValueSelection::kSetSelectionToEnd) { |
415 // Set the caret to the end of the text value except for initialize. | 420 // Set the caret to the end of the text value except for initialize. |
416 unsigned endOfString = m_value.length(); | 421 unsigned endOfString = m_value.length(); |
417 setSelectionRange(endOfString, endOfString); | 422 setSelectionRange(endOfString, endOfString); |
418 } | 423 } |
419 | 424 |
420 notifyFormStateChanged(); | 425 notifyFormStateChanged(); |
421 switch (eventBehavior) { | 426 switch (eventBehavior) { |
422 case DispatchChangeEvent: | 427 case DispatchChangeEvent: |
423 dispatchFormControlChangeEvent(); | 428 dispatchFormControlChangeEvent(); |
424 break; | 429 break; |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 | 630 |
626 const AtomicString& HTMLTextAreaElement::defaultAutocapitalize() const { | 631 const AtomicString& HTMLTextAreaElement::defaultAutocapitalize() const { |
627 DEFINE_STATIC_LOCAL(const AtomicString, sentences, ("sentences")); | 632 DEFINE_STATIC_LOCAL(const AtomicString, sentences, ("sentences")); |
628 return sentences; | 633 return sentences; |
629 } | 634 } |
630 | 635 |
631 void HTMLTextAreaElement::copyNonAttributePropertiesFromElement( | 636 void HTMLTextAreaElement::copyNonAttributePropertiesFromElement( |
632 const Element& source) { | 637 const Element& source) { |
633 const HTMLTextAreaElement& sourceElement = | 638 const HTMLTextAreaElement& sourceElement = |
634 static_cast<const HTMLTextAreaElement&>(source); | 639 static_cast<const HTMLTextAreaElement&>(source); |
635 setValueCommon(sourceElement.value(), DispatchNoEvent); | 640 setValueCommon(sourceElement.value(), DispatchNoEvent, |
| 641 TextControlSetValueSelection::kSetSelectionToEnd); |
636 m_isDirty = sourceElement.m_isDirty; | 642 m_isDirty = sourceElement.m_isDirty; |
637 TextControlElement::copyNonAttributePropertiesFromElement(source); | 643 TextControlElement::copyNonAttributePropertiesFromElement(source); |
638 } | 644 } |
639 | 645 |
640 } // namespace blink | 646 } // namespace blink |
OLD | NEW |