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

Unified Diff: Source/core/html/HTMLTextFormControlElement.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, 4 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/html/HTMLTextFormControlElement.cpp
diff --git a/Source/core/html/HTMLTextFormControlElement.cpp b/Source/core/html/HTMLTextFormControlElement.cpp
index 5e180c36bcb567e2f04dc97a2c729b88ba700cea..7cf1d85f7da3796e79f49ad481b216fc135b96a5 100644
--- a/Source/core/html/HTMLTextFormControlElement.cpp
+++ b/Source/core/html/HTMLTextFormControlElement.cpp
@@ -83,7 +83,7 @@ Node::InsertionNotificationRequest HTMLTextFormControlElement::insertedInto(Cont
void HTMLTextFormControlElement::dispatchFocusEvent(Element* oldFocusedElement, WebFocusType type, InputDeviceCapabilities* sourceCapabilities)
{
if (supportsPlaceholder())
- updatePlaceholderVisibility(false);
+ updatePlaceholderVisibility();
handleFocusEvent(oldFocusedElement, type);
HTMLFormControlElementWithState::dispatchFocusEvent(oldFocusedElement, type, sourceCapabilities);
}
@@ -91,7 +91,7 @@ void HTMLTextFormControlElement::dispatchFocusEvent(Element* oldFocusedElement,
void HTMLTextFormControlElement::dispatchBlurEvent(Element* newFocusedElement, WebFocusType type, InputDeviceCapabilities* sourceCapabilities)
{
if (supportsPlaceholder())
- updatePlaceholderVisibility(false);
+ updatePlaceholderVisibility();
handleBlurEvent();
HTMLFormControlElementWithState::dispatchBlurEvent(newFocusedElement, type, sourceCapabilities);
}
@@ -147,8 +147,7 @@ bool HTMLTextFormControlElement::placeholderShouldBeVisible() const
return supportsPlaceholder()
&& isEmptyValue()
&& isEmptySuggestedValue()
- && !isPlaceholderEmpty()
- && (!layoutObject() || layoutObject()->style()->visibility() == VISIBLE);
+ && !isPlaceholderEmpty();
}
HTMLElement* HTMLTextFormControlElement::placeholderElement() const
@@ -156,17 +155,21 @@ HTMLElement* HTMLTextFormControlElement::placeholderElement() const
return toHTMLElement(userAgentShadowRoot()->getElementById(ShadowElementNames::placeholder()));
}
-void HTMLTextFormControlElement::updatePlaceholderVisibility(bool placeholderValueChanged)
+void HTMLTextFormControlElement::updatePlaceholderVisibility()
{
- if (!supportsPlaceholder())
- return;
- if (!placeholderElement() || placeholderValueChanged)
- updatePlaceholderText();
HTMLElement* placeholder = placeholderElement();
- if (!placeholder)
+ if (!placeholder) {
+ updatePlaceholderText();
return;
+ }
- placeholder->setInlineStyleProperty(CSSPropertyDisplay, placeholderShouldBeVisible() ? CSSValueBlock : CSSValueNone);
+ bool placeHolderWasVisible = isPlaceholderVisible();
+ setPlaceholderVisibility(placeholderShouldBeVisible());
+ if (placeHolderWasVisible == isPlaceholderVisible())
+ return;
+
+ pseudoStateChanged(CSSSelector::PseudoPlaceholderShown);
+ placeholder->setInlineStyleProperty(CSSPropertyDisplay, isPlaceholderVisible() ? CSSValueBlock : CSSValueNone, true);
}
void HTMLTextFormControlElement::setSelectionStart(int start)
@@ -607,7 +610,8 @@ void HTMLTextFormControlElement::parseAttribute(const QualifiedName& name, const
UseCounter::count(document(), UseCounter::AutocapitalizeAttribute);
if (name == placeholderAttr) {
- updatePlaceholderVisibility(true);
+ updatePlaceholderText();
+ updatePlaceholderVisibility();
UseCounter::count(document(), UseCounter::PlaceholderAttribute);
} else {
HTMLFormControlElementWithState::parseAttribute(name, value);

Powered by Google App Engine
This is Rietveld 408576698