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

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 testcase 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 089cee6f743ad112f2c10b97127bd081ec9e4466..1c24d783f696324f14f365d4c6ea26a4530d851e 100644
--- a/Source/core/html/HTMLTextFormControlElement.cpp
+++ b/Source/core/html/HTMLTextFormControlElement.cpp
@@ -63,6 +63,7 @@ HTMLTextFormControlElement::HTMLTextFormControlElement(const QualifiedName& tagN
, m_cachedSelectionStart(0)
, m_cachedSelectionEnd(0)
, m_cachedSelectionDirection(SelectionHasNoDirection)
+ , m_isPlaceholderVisible(false)
esprehn 2015/08/21 10:18:10 remove
ramya.v 2015/08/25 10:24:45 Done.
{
}
@@ -83,7 +84,7 @@ Node::InsertionNotificationRequest HTMLTextFormControlElement::insertedInto(Cont
void HTMLTextFormControlElement::dispatchFocusEvent(Element* oldFocusedElement, WebFocusType type, InputDevice* sourceDevice)
{
if (supportsPlaceholder())
- updatePlaceholderVisibility(false);
+ updatePlaceholderVisibility();
handleFocusEvent(oldFocusedElement, type);
HTMLFormControlElementWithState::dispatchFocusEvent(oldFocusedElement, type, sourceDevice);
}
@@ -91,7 +92,7 @@ void HTMLTextFormControlElement::dispatchFocusEvent(Element* oldFocusedElement,
void HTMLTextFormControlElement::dispatchBlurEvent(Element* newFocusedElement, WebFocusType type, InputDevice* sourceDevice)
{
if (supportsPlaceholder())
- updatePlaceholderVisibility(false);
+ updatePlaceholderVisibility();
handleBlurEvent();
HTMLFormControlElementWithState::dispatchBlurEvent(newFocusedElement, type, sourceDevice);
}
@@ -147,8 +148,7 @@ bool HTMLTextFormControlElement::placeholderShouldBeVisible() const
return supportsPlaceholder()
&& isEmptyValue()
&& isEmptySuggestedValue()
- && !isPlaceholderEmpty()
- && (!layoutObject() || layoutObject()->style()->visibility() == VISIBLE);
+ && !isPlaceholderEmpty();
esprehn 2015/08/21 10:18:10 This is a behavior change, can you explain why you
ramya.v 2015/08/25 10:24:45 In Webkit patch, below point is mentioned. Remove
}
HTMLElement* HTMLTextFormControlElement::placeholderElement() const
@@ -156,17 +156,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 = m_isPlaceholderVisible;
+ m_isPlaceholderVisible = placeholderShouldBeVisible();
+ if (placeHolderWasVisible == m_isPlaceholderVisible)
+ return;
+
+ setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::create(StyleChangeReason::PseudoClass));
esprehn 2015/08/21 10:18:10 This should use the StyleInvalidator, you need to
ramya.v 2015/08/25 10:24:45 Done.
+ placeholder->setInlineStyleProperty(CSSPropertyDisplay, m_isPlaceholderVisible ? CSSValueBlock : CSSValueNone, true);
}
void HTMLTextFormControlElement::setSelectionStart(int start)
@@ -607,7 +611,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