Value set in onblur should not keep element in focus

Value set in onblur was resulting in element still in focus due to reset
of the layout called on setValue. This patch fixes on reset of layout to remove
focus.

R=tkent, keishi1
BUG=347684
TEST=Background color differ when on blur value is set.

Review URL: https://codereview.chromium.org/191293011

git-svn-id: svn://svn.chromium.org/blink/trunk@170441 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 175573f7
Setting value onBlur, should not keep element in focus.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS style.getPropertyValue("background-color") is "rgb(0, 0, 255)"
PASS style.getPropertyValue("background-color") is "rgb(255, 255, 255)"
PASS successfullyParsed is true
TEST COMPLETE
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<style>
input:focus {
background: blue;
}
</style>
<body>
<input id="test" type="date">
<a></a>
<script>
description('Setting value onBlur, should not keep element in focus.');
var testInput = document.getElementById('test');
testInput.addEventListener('blur', function() {
testInput.value = '';
});
testInput.value = '2012-02-01';
testInput.focus();
var style = window.getComputedStyle(testInput);
shouldBeEqualToString('style.getPropertyValue("background-color")', 'rgb(0, 0, 255)');
testInput.blur();
style = window.getComputedStyle(testInput);
shouldBeEqualToString('style.getPropertyValue("background-color")', 'rgb(255, 255, 255)');
</script>
</body>
</html>
......@@ -54,12 +54,6 @@ DateTimeFieldElement::DateTimeFieldElement(Document& document, FieldOwner& field
void DateTimeFieldElement::defaultEventHandler(Event* event)
{
if (event->type() == EventTypeNames::blur)
didBlur();
if (event->type() == EventTypeNames::focus)
didFocus();
if (event->isKeyboardEvent()) {
KeyboardEvent* keyboardEvent = toKeyboardEvent(event);
if (!isDisabled() && !isFieldOwnerDisabled() && !isFieldOwnerReadOnly()) {
......@@ -129,16 +123,11 @@ void DateTimeFieldElement::defaultKeyboardEventHandler(KeyboardEvent* keyboardEv
}
}
void DateTimeFieldElement::didBlur()
{
if (m_fieldOwner)
m_fieldOwner->didBlurFromField();
}
void DateTimeFieldElement::didFocus()
void DateTimeFieldElement::setFocus(bool value)
{
if (m_fieldOwner)
m_fieldOwner->didFocusOnField();
value ? m_fieldOwner->didFocusOnField() : m_fieldOwner->didBlurFromField();
ContainerNode::setFocus(value);
}
void DateTimeFieldElement::focusOnNextField()
......
......@@ -79,8 +79,6 @@ public:
protected:
DateTimeFieldElement(Document&, FieldOwner&);
virtual void didBlur();
virtual void didFocus();
void focusOnNextField();
virtual void handleKeyboardEvent(KeyboardEvent*) = 0;
void initialize(const AtomicString& pseudo, const String& axHelpText, int axMinimum, int axMaximum);
......@@ -90,6 +88,9 @@ protected:
virtual int valueAsInteger() const = 0;
virtual int valueForARIAValueNow() const;
// Node functions.
virtual void setFocus(bool) OVERRIDE;
private:
void defaultKeyboardEventHandler(KeyboardEvent*);
virtual bool isDateTimeFieldElement() const OVERRIDE FINAL;
......
......@@ -91,13 +91,15 @@ int DateTimeNumericFieldElement::defaultValueForStepUp() const
return m_range.minimum;
}
void DateTimeNumericFieldElement::didBlur()
void DateTimeNumericFieldElement::setFocus(bool value)
{
int value = typeAheadValue();
m_typeAheadBuffer.clear();
if (value >= 0)
setValueAsInteger(value, DispatchEvent);
DateTimeFieldElement::didBlur();
if (!value) {
int value = typeAheadValue();
m_typeAheadBuffer.clear();
if (value >= 0)
setValueAsInteger(value, DispatchEvent);
}
DateTimeFieldElement::setFocus(value);
}
String DateTimeNumericFieldElement::formatValue(int value) const
......
......@@ -80,13 +80,15 @@ protected:
private:
// DateTimeFieldElement functions.
virtual void didBlur() OVERRIDE FINAL;
virtual void handleKeyboardEvent(KeyboardEvent*) OVERRIDE FINAL;
virtual float maximumWidth(const Font&) OVERRIDE;
virtual void stepDown() OVERRIDE FINAL;
virtual void stepUp() OVERRIDE FINAL;
virtual String value() const OVERRIDE FINAL;
// Node functions.
virtual void setFocus(bool) OVERRIDE FINAL;
String formatValue(int) const;
int roundUp(int) const;
int roundDown(int) const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment