| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 95 |
| 96 PassRefPtr<HTMLTextAreaElement> HTMLTextAreaElement::create(const QualifiedName&
tagName, Document* document, HTMLFormElement* form) | 96 PassRefPtr<HTMLTextAreaElement> HTMLTextAreaElement::create(const QualifiedName&
tagName, Document* document, HTMLFormElement* form) |
| 97 { | 97 { |
| 98 RefPtr<HTMLTextAreaElement> textArea = adoptRef(new HTMLTextAreaElement(tagN
ame, document, form)); | 98 RefPtr<HTMLTextAreaElement> textArea = adoptRef(new HTMLTextAreaElement(tagN
ame, document, form)); |
| 99 textArea->ensureUserAgentShadowRoot(); | 99 textArea->ensureUserAgentShadowRoot(); |
| 100 return textArea.release(); | 100 return textArea.release(); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void HTMLTextAreaElement::didAddUserAgentShadowRoot(ShadowRoot* root) | 103 void HTMLTextAreaElement::didAddUserAgentShadowRoot(ShadowRoot* root) |
| 104 { | 104 { |
| 105 root->appendChild(TextControlInnerTextElement::create(document())); | 105 root->appendChild(TextControlInnerTextElement::create(&document())); |
| 106 } | 106 } |
| 107 | 107 |
| 108 const AtomicString& HTMLTextAreaElement::formControlType() const | 108 const AtomicString& HTMLTextAreaElement::formControlType() const |
| 109 { | 109 { |
| 110 DEFINE_STATIC_LOCAL(const AtomicString, textarea, ("textarea", AtomicString:
:ConstructFromLiteral)); | 110 DEFINE_STATIC_LOCAL(const AtomicString, textarea, ("textarea", AtomicString:
:ConstructFromLiteral)); |
| 111 return textarea; | 111 return textarea; |
| 112 } | 112 } |
| 113 | 113 |
| 114 FormControlState HTMLTextAreaElement::saveFormControlState() const | 114 FormControlState HTMLTextAreaElement::saveFormControlState() const |
| 115 { | 115 { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 RenderObject* HTMLTextAreaElement::createRenderer(RenderStyle*) | 204 RenderObject* HTMLTextAreaElement::createRenderer(RenderStyle*) |
| 205 { | 205 { |
| 206 return new RenderTextControlMultiLine(this); | 206 return new RenderTextControlMultiLine(this); |
| 207 } | 207 } |
| 208 | 208 |
| 209 bool HTMLTextAreaElement::appendFormData(FormDataList& encoding, bool) | 209 bool HTMLTextAreaElement::appendFormData(FormDataList& encoding, bool) |
| 210 { | 210 { |
| 211 if (name().isEmpty()) | 211 if (name().isEmpty()) |
| 212 return false; | 212 return false; |
| 213 | 213 |
| 214 document()->updateLayout(); | 214 document().updateLayout(); |
| 215 | 215 |
| 216 const String& text = (m_wrap == HardWrap) ? valueWithHardLineBreaks() : valu
e(); | 216 const String& text = (m_wrap == HardWrap) ? valueWithHardLineBreaks() : valu
e(); |
| 217 encoding.appendData(name(), text); | 217 encoding.appendData(name(), text); |
| 218 | 218 |
| 219 const AtomicString& dirnameAttrValue = fastGetAttribute(dirnameAttr); | 219 const AtomicString& dirnameAttrValue = fastGetAttribute(dirnameAttr); |
| 220 if (!dirnameAttrValue.isNull()) | 220 if (!dirnameAttrValue.isNull()) |
| 221 encoding.appendData(dirnameAttrValue, directionForFormData()); | 221 encoding.appendData(dirnameAttrValue, directionForFormData()); |
| 222 return true; | 222 return true; |
| 223 } | 223 } |
| 224 | 224 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 246 void HTMLTextAreaElement::updateFocusAppearance(bool restorePreviousSelection) | 246 void HTMLTextAreaElement::updateFocusAppearance(bool restorePreviousSelection) |
| 247 { | 247 { |
| 248 if (!restorePreviousSelection || !hasCachedSelection()) { | 248 if (!restorePreviousSelection || !hasCachedSelection()) { |
| 249 // If this is the first focus, set a caret at the beginning of the text. | 249 // If this is the first focus, set a caret at the beginning of the text. |
| 250 // This matches some browsers' behavior; see bug 11746 Comment #15. | 250 // This matches some browsers' behavior; see bug 11746 Comment #15. |
| 251 // http://bugs.webkit.org/show_bug.cgi?id=11746#c15 | 251 // http://bugs.webkit.org/show_bug.cgi?id=11746#c15 |
| 252 setSelectionRange(0, 0); | 252 setSelectionRange(0, 0); |
| 253 } else | 253 } else |
| 254 restoreCachedSelection(); | 254 restoreCachedSelection(); |
| 255 | 255 |
| 256 if (document()->frame()) | 256 if (document().frame()) |
| 257 document()->frame()->selection()->revealSelection(); | 257 document().frame()->selection()->revealSelection(); |
| 258 } | 258 } |
| 259 | 259 |
| 260 void HTMLTextAreaElement::defaultEventHandler(Event* event) | 260 void HTMLTextAreaElement::defaultEventHandler(Event* event) |
| 261 { | 261 { |
| 262 if (renderer() && (event->isMouseEvent() || event->isDragEvent() || event->h
asInterface(eventNames().interfaceForWheelEvent) || event->type() == eventNames(
).blurEvent)) | 262 if (renderer() && (event->isMouseEvent() || event->isDragEvent() || event->h
asInterface(eventNames().interfaceForWheelEvent) || event->type() == eventNames(
).blurEvent)) |
| 263 forwardEvent(event); | 263 forwardEvent(event); |
| 264 else if (renderer() && event->isBeforeTextInsertedEvent()) | 264 else if (renderer() && event->isBeforeTextInsertedEvent()) |
| 265 handleBeforeTextInsertedEvent(static_cast<BeforeTextInsertedEvent*>(even
t)); | 265 handleBeforeTextInsertedEvent(static_cast<BeforeTextInsertedEvent*>(even
t)); |
| 266 | 266 |
| 267 HTMLTextFormControlElement::defaultEventHandler(event); | 267 HTMLTextFormControlElement::defaultEventHandler(event); |
| 268 } | 268 } |
| 269 | 269 |
| 270 void HTMLTextAreaElement::handleFocusEvent(Element*, FocusDirection) | 270 void HTMLTextAreaElement::handleFocusEvent(Element*, FocusDirection) |
| 271 { | 271 { |
| 272 if (Frame* frame = document()->frame()) | 272 if (Frame* frame = document().frame()) |
| 273 frame->editor().textAreaOrTextFieldDidBeginEditing(this); | 273 frame->editor().textAreaOrTextFieldDidBeginEditing(this); |
| 274 } | 274 } |
| 275 | 275 |
| 276 void HTMLTextAreaElement::subtreeHasChanged() | 276 void HTMLTextAreaElement::subtreeHasChanged() |
| 277 { | 277 { |
| 278 setChangedSinceLastFormControlChangeEvent(true); | 278 setChangedSinceLastFormControlChangeEvent(true); |
| 279 setFormControlValueMatchesRenderer(false); | 279 setFormControlValueMatchesRenderer(false); |
| 280 setNeedsValidityCheck(); | 280 setNeedsValidityCheck(); |
| 281 | 281 |
| 282 if (!focused()) | 282 if (!focused()) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 298 const String& currentValue = innerTextValue(); | 298 const String& currentValue = innerTextValue(); |
| 299 unsigned currentLength = computeLengthForSubmission(currentValue); | 299 unsigned currentLength = computeLengthForSubmission(currentValue); |
| 300 if (currentLength + computeLengthForSubmission(event->text()) < unsignedMaxL
ength) | 300 if (currentLength + computeLengthForSubmission(event->text()) < unsignedMaxL
ength) |
| 301 return; | 301 return; |
| 302 | 302 |
| 303 // selectionLength represents the selection length of this text field to be | 303 // selectionLength represents the selection length of this text field to be |
| 304 // removed by this insertion. | 304 // removed by this insertion. |
| 305 // If the text field has no focus, we don't need to take account of the | 305 // If the text field has no focus, we don't need to take account of the |
| 306 // selection length. The selection is the source of text drag-and-drop in | 306 // selection length. The selection is the source of text drag-and-drop in |
| 307 // that case, and nothing in the text field will be removed. | 307 // that case, and nothing in the text field will be removed. |
| 308 unsigned selectionLength = focused() ? computeLengthForSubmission(plainText(
document()->frame()->selection()->selection().toNormalizedRange().get())) : 0; | 308 unsigned selectionLength = focused() ? computeLengthForSubmission(plainText(
document().frame()->selection()->selection().toNormalizedRange().get())) : 0; |
| 309 ASSERT(currentLength >= selectionLength); | 309 ASSERT(currentLength >= selectionLength); |
| 310 unsigned baseLength = currentLength - selectionLength; | 310 unsigned baseLength = currentLength - selectionLength; |
| 311 unsigned appendableLength = unsignedMaxLength > baseLength ? unsignedMaxLeng
th - baseLength : 0; | 311 unsigned appendableLength = unsignedMaxLength > baseLength ? unsignedMaxLeng
th - baseLength : 0; |
| 312 event->setText(sanitizeUserInputValue(event->text(), appendableLength)); | 312 event->setText(sanitizeUserInputValue(event->text(), appendableLength)); |
| 313 } | 313 } |
| 314 | 314 |
| 315 String HTMLTextAreaElement::sanitizeUserInputValue(const String& proposedValue,
unsigned maxLength) | 315 String HTMLTextAreaElement::sanitizeUserInputValue(const String& proposedValue,
unsigned maxLength) |
| 316 { | 316 { |
| 317 if (maxLength > 0 && U16_IS_LEAD(proposedValue[maxLength - 1])) | 317 if (maxLength > 0 && U16_IS_LEAD(proposedValue[maxLength - 1])) |
| 318 --maxLength; | 318 --maxLength; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 return; | 380 return; |
| 381 | 381 |
| 382 m_value = normalizedValue; | 382 m_value = normalizedValue; |
| 383 setInnerTextValue(m_value); | 383 setInnerTextValue(m_value); |
| 384 setLastChangeWasNotUserEdit(); | 384 setLastChangeWasNotUserEdit(); |
| 385 updatePlaceholderVisibility(false); | 385 updatePlaceholderVisibility(false); |
| 386 setNeedsStyleRecalc(); | 386 setNeedsStyleRecalc(); |
| 387 setFormControlValueMatchesRenderer(true); | 387 setFormControlValueMatchesRenderer(true); |
| 388 | 388 |
| 389 // Set the caret to the end of the text value. | 389 // Set the caret to the end of the text value. |
| 390 if (document()->focusedElement() == this) { | 390 if (document().focusedElement() == this) { |
| 391 unsigned endOfString = m_value.length(); | 391 unsigned endOfString = m_value.length(); |
| 392 setSelectionRange(endOfString, endOfString); | 392 setSelectionRange(endOfString, endOfString); |
| 393 } | 393 } |
| 394 | 394 |
| 395 notifyFormStateChanged(); | 395 notifyFormStateChanged(); |
| 396 setTextAsOfLastFormControlChangeEvent(normalizedValue); | 396 setTextAsOfLastFormControlChangeEvent(normalizedValue); |
| 397 } | 397 } |
| 398 | 398 |
| 399 String HTMLTextAreaElement::defaultValue() const | 399 String HTMLTextAreaElement::defaultValue() const |
| 400 { | 400 { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 421 } | 421 } |
| 422 size_t size = textNodes.size(); | 422 size_t size = textNodes.size(); |
| 423 for (size_t i = 0; i < size; ++i) | 423 for (size_t i = 0; i < size; ++i) |
| 424 removeChild(textNodes[i].get(), IGNORE_EXCEPTION); | 424 removeChild(textNodes[i].get(), IGNORE_EXCEPTION); |
| 425 | 425 |
| 426 // Normalize line endings. | 426 // Normalize line endings. |
| 427 String value = defaultValue; | 427 String value = defaultValue; |
| 428 value.replace("\r\n", "\n"); | 428 value.replace("\r\n", "\n"); |
| 429 value.replace('\r', '\n'); | 429 value.replace('\r', '\n'); |
| 430 | 430 |
| 431 insertBefore(document()->createTextNode(value), firstChild(), IGNORE_EXCEPTI
ON); | 431 insertBefore(document().createTextNode(value), firstChild(), IGNORE_EXCEPTIO
N); |
| 432 | 432 |
| 433 if (!m_isDirty) | 433 if (!m_isDirty) |
| 434 setNonDirtyValue(value); | 434 setNonDirtyValue(value); |
| 435 } | 435 } |
| 436 | 436 |
| 437 int HTMLTextAreaElement::maxLength() const | 437 int HTMLTextAreaElement::maxLength() const |
| 438 { | 438 { |
| 439 bool ok; | 439 bool ok; |
| 440 int value = getAttribute(maxlengthAttr).string().toInt(&ok); | 440 int value = getAttribute(maxlengthAttr).string().toInt(&ok); |
| 441 return ok && value >= 0 ? value : -1; | 441 return ok && value >= 0 ? value : -1; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 { | 533 { |
| 534 String placeholderText = strippedPlaceholder(); | 534 String placeholderText = strippedPlaceholder(); |
| 535 if (placeholderText.isEmpty()) { | 535 if (placeholderText.isEmpty()) { |
| 536 if (m_placeholder) { | 536 if (m_placeholder) { |
| 537 userAgentShadowRoot()->removeChild(m_placeholder); | 537 userAgentShadowRoot()->removeChild(m_placeholder); |
| 538 m_placeholder = 0; | 538 m_placeholder = 0; |
| 539 } | 539 } |
| 540 return; | 540 return; |
| 541 } | 541 } |
| 542 if (!m_placeholder) { | 542 if (!m_placeholder) { |
| 543 RefPtr<HTMLDivElement> placeholder = HTMLDivElement::create(document()); | 543 RefPtr<HTMLDivElement> placeholder = HTMLDivElement::create(&document())
; |
| 544 m_placeholder = placeholder.get(); | 544 m_placeholder = placeholder.get(); |
| 545 m_placeholder->setPart(AtomicString("-webkit-input-placeholder", AtomicS
tring::ConstructFromLiteral)); | 545 m_placeholder->setPart(AtomicString("-webkit-input-placeholder", AtomicS
tring::ConstructFromLiteral)); |
| 546 userAgentShadowRoot()->insertBefore(m_placeholder, innerTextElement()->n
extSibling()); | 546 userAgentShadowRoot()->insertBefore(m_placeholder, innerTextElement()->n
extSibling()); |
| 547 } | 547 } |
| 548 m_placeholder->setTextContent(placeholderText, ASSERT_NO_EXCEPTION); | 548 m_placeholder->setTextContent(placeholderText, ASSERT_NO_EXCEPTION); |
| 549 } | 549 } |
| 550 | 550 |
| 551 } | 551 } |
| OLD | NEW |