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 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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 | 329 |
330 String HTMLTextAreaElement::value() const | 330 String HTMLTextAreaElement::value() const |
331 { | 331 { |
332 updateValue(); | 332 updateValue(); |
333 return m_value; | 333 return m_value; |
334 } | 334 } |
335 | 335 |
336 void HTMLTextAreaElement::setValue(const String& value, TextFieldEventBehavior e
ventBehavior) | 336 void HTMLTextAreaElement::setValue(const String& value, TextFieldEventBehavior e
ventBehavior) |
337 { | 337 { |
338 RefPtrWillBeRawPtr<HTMLTextAreaElement> protector(this); | 338 RefPtrWillBeRawPtr<HTMLTextAreaElement> protector(this); |
339 setValueCommon(value, eventBehavior); | 339 bool isUpdated = setValueCommon(value, eventBehavior); |
340 m_isDirty = true; | 340 m_isDirty = true; |
341 setNeedsValidityCheck(); | 341 setNeedsValidityCheck(); |
| 342 |
| 343 if (isUpdated) { |
| 344 // Set the caret to the end of the text value. |
| 345 unsigned endOfString = m_value.length(); |
| 346 setSelectionRange(endOfString, endOfString); |
| 347 } |
| 348 |
342 if (document().focusedElement() == this) | 349 if (document().focusedElement() == this) |
343 document().frameHost()->chrome().client().didUpdateTextOfFocusedElementB
yNonUserInput(); | 350 document().frameHost()->chrome().client().didUpdateTextOfFocusedElementB
yNonUserInput(); |
344 } | 351 } |
345 | 352 |
346 void HTMLTextAreaElement::setNonDirtyValue(const String& value) | 353 void HTMLTextAreaElement::setNonDirtyValue(const String& value) |
347 { | 354 { |
348 setValueCommon(value, DispatchNoEvent); | 355 setValueCommon(value, DispatchNoEvent); |
349 m_isDirty = false; | 356 m_isDirty = false; |
350 setNeedsValidityCheck(); | 357 setNeedsValidityCheck(); |
351 } | 358 } |
352 | 359 |
353 void HTMLTextAreaElement::setValueCommon(const String& newValue, TextFieldEventB
ehavior eventBehavior) | 360 bool HTMLTextAreaElement::setValueCommon(const String& newValue, TextFieldEventB
ehavior eventBehavior) |
354 { | 361 { |
355 // Code elsewhere normalizes line endings added by the user via the keyboard
or pasting. | 362 // Code elsewhere normalizes line endings added by the user via the keyboard
or pasting. |
356 // We normalize line endings coming from JavaScript here. | 363 // We normalize line endings coming from JavaScript here. |
357 String normalizedValue = newValue.isNull() ? "" : newValue; | 364 String normalizedValue = newValue.isNull() ? "" : newValue; |
358 normalizedValue.replace("\r\n", "\n"); | 365 normalizedValue.replace("\r\n", "\n"); |
359 normalizedValue.replace('\r', '\n'); | 366 normalizedValue.replace('\r', '\n'); |
360 | 367 |
361 // Return early because we don't want to move the caret or trigger other sid
e effects | 368 // Return early because we don't want to move the caret or trigger other sid
e effects |
362 // when the value isn't changing. This matches Firefox behavior, at least. | 369 // when the value isn't changing. This matches Firefox behavior, at least. |
363 if (normalizedValue == value()) | 370 if (normalizedValue == value()) |
364 return; | 371 return false; |
365 | 372 |
366 m_value = normalizedValue; | 373 m_value = normalizedValue; |
367 setInnerEditorValue(m_value); | 374 setInnerEditorValue(m_value); |
368 if (eventBehavior == DispatchNoEvent) | 375 if (eventBehavior == DispatchNoEvent) |
369 setLastChangeWasNotUserEdit(); | 376 setLastChangeWasNotUserEdit(); |
370 updatePlaceholderVisibility(false); | 377 updatePlaceholderVisibility(false); |
371 setNeedsStyleRecalc(SubtreeStyleChange); | 378 setNeedsStyleRecalc(SubtreeStyleChange); |
372 m_suggestedValue = String(); | 379 m_suggestedValue = String(); |
373 | 380 |
374 // Set the caret to the end of the text value. | |
375 if (document().focusedElement() == this) { | |
376 unsigned endOfString = m_value.length(); | |
377 setSelectionRange(endOfString, endOfString); | |
378 } | |
379 | |
380 notifyFormStateChanged(); | 381 notifyFormStateChanged(); |
381 if (eventBehavior == DispatchNoEvent) { | 382 if (eventBehavior == DispatchNoEvent) { |
382 setTextAsOfLastFormControlChangeEvent(normalizedValue); | 383 setTextAsOfLastFormControlChangeEvent(normalizedValue); |
383 } else { | 384 } else { |
384 if (eventBehavior == DispatchInputAndChangeEvent) | 385 if (eventBehavior == DispatchInputAndChangeEvent) |
385 dispatchFormControlInputEvent(); | 386 dispatchFormControlInputEvent(); |
386 dispatchFormControlChangeEvent(); | 387 dispatchFormControlChangeEvent(); |
387 } | 388 } |
| 389 return true; |
388 } | 390 } |
389 | 391 |
390 void HTMLTextAreaElement::setInnerEditorValue(const String& value) | 392 void HTMLTextAreaElement::setInnerEditorValue(const String& value) |
391 { | 393 { |
392 HTMLTextFormControlElement::setInnerEditorValue(value); | 394 HTMLTextFormControlElement::setInnerEditorValue(value); |
393 m_valueIsUpToDate = true; | 395 m_valueIsUpToDate = true; |
394 } | 396 } |
395 | 397 |
396 String HTMLTextAreaElement::defaultValue() const | 398 String HTMLTextAreaElement::defaultValue() const |
397 { | 399 { |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 { | 563 { |
562 return true; | 564 return true; |
563 } | 565 } |
564 | 566 |
565 bool HTMLTextAreaElement::supportsAutofocus() const | 567 bool HTMLTextAreaElement::supportsAutofocus() const |
566 { | 568 { |
567 return true; | 569 return true; |
568 } | 570 } |
569 | 571 |
570 } | 572 } |
OLD | NEW |