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

Side by Side Diff: Source/core/html/HTMLTextAreaElement.cpp

Issue 1280423002: CSS4: Implement :placeholder-shown pseudo class (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Updated as per review comments Created 5 years, 3 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 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 return text.length() + numberOfLineBreaks(text); 77 return text.length() + numberOfLineBreaks(text);
78 } 78 }
79 79
80 HTMLTextAreaElement::HTMLTextAreaElement(Document& document, HTMLFormElement* fo rm) 80 HTMLTextAreaElement::HTMLTextAreaElement(Document& document, HTMLFormElement* fo rm)
81 : HTMLTextFormControlElement(textareaTag, document, form) 81 : HTMLTextFormControlElement(textareaTag, document, form)
82 , m_rows(defaultRows) 82 , m_rows(defaultRows)
83 , m_cols(defaultCols) 83 , m_cols(defaultCols)
84 , m_wrap(SoftWrap) 84 , m_wrap(SoftWrap)
85 , m_isDirty(false) 85 , m_isDirty(false)
86 , m_valueIsUpToDate(true) 86 , m_valueIsUpToDate(true)
87 , m_isPlaceholderVisible(false)
87 { 88 {
88 } 89 }
89 90
90 PassRefPtrWillBeRawPtr<HTMLTextAreaElement> HTMLTextAreaElement::create(Document & document, HTMLFormElement* form) 91 PassRefPtrWillBeRawPtr<HTMLTextAreaElement> HTMLTextAreaElement::create(Document & document, HTMLFormElement* form)
91 { 92 {
92 RefPtrWillBeRawPtr<HTMLTextAreaElement> textArea = adoptRefWillBeNoop(new HT MLTextAreaElement(document, form)); 93 RefPtrWillBeRawPtr<HTMLTextAreaElement> textArea = adoptRefWillBeNoop(new HT MLTextAreaElement(document, form));
93 textArea->ensureUserAgentShadowRoot(); 94 textArea->ensureUserAgentShadowRoot();
94 return textArea.release(); 95 return textArea.release();
95 } 96 }
96 97
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 if (LocalFrame* frame = document().frame()) 268 if (LocalFrame* frame = document().frame())
268 frame->spellChecker().didBeginEditing(this); 269 frame->spellChecker().didBeginEditing(this);
269 } 270 }
270 271
271 void HTMLTextAreaElement::subtreeHasChanged() 272 void HTMLTextAreaElement::subtreeHasChanged()
272 { 273 {
273 setChangedSinceLastFormControlChangeEvent(true); 274 setChangedSinceLastFormControlChangeEvent(true);
274 m_valueIsUpToDate = false; 275 m_valueIsUpToDate = false;
275 setNeedsValidityCheck(); 276 setNeedsValidityCheck();
276 setAutofilled(false); 277 setAutofilled(false);
277 updatePlaceholderVisibility(false); 278 updatePlaceholderVisibility();
278 279
279 if (!focused()) 280 if (!focused())
280 return; 281 return;
281 282
282 // When typing in a textarea, childrenChanged is not called, so we need to f orce the directionality check. 283 // When typing in a textarea, childrenChanged is not called, so we need to f orce the directionality check.
283 calculateAndAdjustDirectionality(); 284 calculateAndAdjustDirectionality();
284 285
285 ASSERT(document().isActive()); 286 ASSERT(document().isActive());
286 document().frameHost()->chromeClient().didChangeValueInTextField(*this); 287 document().frameHost()->chromeClient().didChangeValueInTextField(*this);
287 } 288 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 326
326 void HTMLTextAreaElement::updateValue() const 327 void HTMLTextAreaElement::updateValue() const
327 { 328 {
328 if (m_valueIsUpToDate) 329 if (m_valueIsUpToDate)
329 return; 330 return;
330 331
331 m_value = innerEditorValue(); 332 m_value = innerEditorValue();
332 const_cast<HTMLTextAreaElement*>(this)->m_valueIsUpToDate = true; 333 const_cast<HTMLTextAreaElement*>(this)->m_valueIsUpToDate = true;
333 const_cast<HTMLTextAreaElement*>(this)->notifyFormStateChanged(); 334 const_cast<HTMLTextAreaElement*>(this)->notifyFormStateChanged();
334 m_isDirty = true; 335 m_isDirty = true;
335 const_cast<HTMLTextAreaElement*>(this)->updatePlaceholderVisibility(false); 336 const_cast<HTMLTextAreaElement*>(this)->updatePlaceholderVisibility();
336 } 337 }
337 338
338 String HTMLTextAreaElement::value() const 339 String HTMLTextAreaElement::value() const
339 { 340 {
340 updateValue(); 341 updateValue();
341 return m_value; 342 return m_value;
342 } 343 }
343 344
344 void HTMLTextAreaElement::setValue(const String& value, TextFieldEventBehavior e ventBehavior) 345 void HTMLTextAreaElement::setValue(const String& value, TextFieldEventBehavior e ventBehavior)
345 { 346 {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 setSelectionRange(endOfString, endOfString, SelectionHasNoDirect ion, NotDispatchSelectEvent, ChangeSelectionIfFocused); 378 setSelectionRange(endOfString, endOfString, SelectionHasNoDirect ion, NotDispatchSelectEvent, ChangeSelectionIfFocused);
378 } 379 }
379 } 380 }
380 return; 381 return;
381 } 382 }
382 383
383 m_value = normalizedValue; 384 m_value = normalizedValue;
384 setInnerEditorValue(m_value); 385 setInnerEditorValue(m_value);
385 if (eventBehavior == DispatchNoEvent) 386 if (eventBehavior == DispatchNoEvent)
386 setLastChangeWasNotUserEdit(); 387 setLastChangeWasNotUserEdit();
387 updatePlaceholderVisibility(false); 388 updatePlaceholderVisibility();
388 setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::create( StyleChangeReason::ControlValue)); 389 setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::create( StyleChangeReason::ControlValue));
389 m_suggestedValue = String(); 390 m_suggestedValue = String();
390 setNeedsValidityCheck(); 391 setNeedsValidityCheck();
391 if (isFinishedParsingChildren()) { 392 if (isFinishedParsingChildren()) {
392 // Set the caret to the end of the text value except for initialize. 393 // Set the caret to the end of the text value except for initialize.
393 unsigned endOfString = m_value.length(); 394 unsigned endOfString = m_value.length();
394 setSelectionRange(endOfString, endOfString, SelectionHasNoDirection, Not DispatchSelectEvent, ChangeSelectionIfFocused); 395 setSelectionRange(endOfString, endOfString, SelectionHasNoDirection, Not DispatchSelectEvent, ChangeSelectionIfFocused);
395 } 396 }
396 397
397 notifyFormStateChanged(); 398 notifyFormStateChanged();
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 } 493 }
493 494
494 void HTMLTextAreaElement::setSuggestedValue(const String& value) 495 void HTMLTextAreaElement::setSuggestedValue(const String& value)
495 { 496 {
496 m_suggestedValue = value; 497 m_suggestedValue = value;
497 498
498 if (!value.isNull()) 499 if (!value.isNull())
499 setInnerEditorValue(m_suggestedValue); 500 setInnerEditorValue(m_suggestedValue);
500 else 501 else
501 setInnerEditorValue(m_value); 502 setInnerEditorValue(m_value);
502 updatePlaceholderVisibility(false); 503 updatePlaceholderVisibility();
503 setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::create( StyleChangeReason::ControlValue)); 504 setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::create( StyleChangeReason::ControlValue));
504 } 505 }
505 506
506 String HTMLTextAreaElement::validationMessage() const 507 String HTMLTextAreaElement::validationMessage() const
507 { 508 {
508 if (!willValidate()) 509 if (!willValidate())
509 return String(); 510 return String();
510 511
511 if (customError()) 512 if (customError())
512 return customValidationMessage(); 513 return customValidationMessage();
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 bool HTMLTextAreaElement::matchesReadOnlyPseudoClass() const 598 bool HTMLTextAreaElement::matchesReadOnlyPseudoClass() const
598 { 599 {
599 return isReadOnly(); 600 return isReadOnly();
600 } 601 }
601 602
602 bool HTMLTextAreaElement::matchesReadWritePseudoClass() const 603 bool HTMLTextAreaElement::matchesReadWritePseudoClass() const
603 { 604 {
604 return !isReadOnly(); 605 return !isReadOnly();
605 } 606 }
606 607
608 void HTMLTextAreaElement::setPlaceholderVisibility(bool visible)
609 {
610 m_isPlaceholderVisible = visible;
611 }
612
607 void HTMLTextAreaElement::updatePlaceholderText() 613 void HTMLTextAreaElement::updatePlaceholderText()
608 { 614 {
609 HTMLElement* placeholder = placeholderElement(); 615 HTMLElement* placeholder = placeholderElement();
610 const AtomicString& placeholderText = fastGetAttribute(placeholderAttr); 616 const AtomicString& placeholderText = fastGetAttribute(placeholderAttr);
611 if (placeholderText.isEmpty()) { 617 if (placeholderText.isEmpty()) {
612 if (placeholder) 618 if (placeholder)
613 userAgentShadowRoot()->removeChild(placeholder); 619 userAgentShadowRoot()->removeChild(placeholder);
614 return; 620 return;
615 } 621 }
616 if (!placeholder) { 622 if (!placeholder) {
617 RefPtrWillBeRawPtr<HTMLDivElement> newElement = HTMLDivElement::create(d ocument()); 623 RefPtrWillBeRawPtr<HTMLDivElement> newElement = HTMLDivElement::create(d ocument());
618 placeholder = newElement.get(); 624 placeholder = newElement.get();
619 placeholder->setShadowPseudoId(AtomicString("-webkit-input-placeholder", AtomicString::ConstructFromLiteral)); 625 placeholder->setShadowPseudoId(AtomicString("-webkit-input-placeholder", AtomicString::ConstructFromLiteral));
620 placeholder->setAttribute(idAttr, ShadowElementNames::placeholder()); 626 placeholder->setAttribute(idAttr, ShadowElementNames::placeholder());
627 placeholder->setInlineStyleProperty(CSSPropertyDisplay, isPlaceholderVis ible() ? CSSValueBlock : CSSValueNone, true);
621 userAgentShadowRoot()->insertBefore(placeholder, innerEditorElement()->n extSibling()); 628 userAgentShadowRoot()->insertBefore(placeholder, innerEditorElement()->n extSibling());
622 } 629 }
623 placeholder->setTextContent(placeholderText); 630 placeholder->setTextContent(placeholderText);
624 } 631 }
625 632
626 bool HTMLTextAreaElement::isInteractiveContent() const 633 bool HTMLTextAreaElement::isInteractiveContent() const
627 { 634 {
628 return true; 635 return true;
629 } 636 }
630 637
(...skipping 10 matching lines...) Expand all
641 648
642 void HTMLTextAreaElement::copyNonAttributePropertiesFromElement(const Element& s ource) 649 void HTMLTextAreaElement::copyNonAttributePropertiesFromElement(const Element& s ource)
643 { 650 {
644 const HTMLTextAreaElement& sourceElement = static_cast<const HTMLTextAreaEle ment&>(source); 651 const HTMLTextAreaElement& sourceElement = static_cast<const HTMLTextAreaEle ment&>(source);
645 setValueCommon(sourceElement.value(), DispatchNoEvent, SetSeletion); 652 setValueCommon(sourceElement.value(), DispatchNoEvent, SetSeletion);
646 m_isDirty = sourceElement.m_isDirty; 653 m_isDirty = sourceElement.m_isDirty;
647 HTMLTextFormControlElement::copyNonAttributePropertiesFromElement(source); 654 HTMLTextFormControlElement::copyNonAttributePropertiesFromElement(source);
648 } 655 }
649 656
650 } // namespace blink 657 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698