Skip to content
This repository has been archived by the owner on Jun 16, 2018. It is now read-only.

Commit

Permalink
INPUT_MULTIPLE_FIELDS_UI: Refactoring: Do not call updateInnerTextVal…
Browse files Browse the repository at this point in the history
…ue if only read-only sub-fields have values

https://bugs.webkit.org/show_bug.cgi?id=103033

Reviewed by Kentaro Hara.

Source/WebCore:

input[type=time] can have read-only sub fields. If only read-only fields
have values, we don't need to call updateInnerTextValue when
HTMLInputElement::value is set to "".

Tests: this patch doesn't change any visible behavior, but we add test cases to
fast/forms/time-multiple-fields/time-multiple-fields-value-set-empty.html
just in case.

* html/shadow/DateTimeEditElement.h:
(DateTimeEditElement): Declare anyEditableFieldsHaveValues.
* html/shadow/DateTimeEditElement.cpp:
(WebCore::DateTimeEditElement::anyEditableFieldsHaveValues):
Added. This function checks value existence against only editable sub-fields.
* html/BaseMultipleFieldsDateAndTimeInputType.cpp:
(WebCore::BaseMultipleFieldsDateAndTimeInputType::setValue):
Call DateTimeEditElement::anyEditableFieldsHaveValues() instead of
DateTimeFieldsState::hasAnyValue().
* html/DateTimeFieldsState.h: Remove hasAnyValue.

LayoutTests:

* fast/forms/time-multiple-fields/time-multiple-fields-value-set-empty-expected.txt:
* fast/forms/time-multiple-fields/time-multiple-fields-value-set-empty.html:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@135510 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
[email protected] committed Nov 22, 2012
1 parent 6244f03 commit 9c670fb
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 2 deletions.
10 changes: 10 additions & 0 deletions LayoutTests/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
2012-11-22 Kent Tamura <[email protected]>

INPUT_MULTIPLE_FIELDS_UI: Refactoring: Do not call updateInnerTextValue if only read-only sub-fields have values
https://bugs.webkit.org/show_bug.cgi?id=103033

Reviewed by Kentaro Hara.

* fast/forms/time-multiple-fields/time-multiple-fields-value-set-empty-expected.txt:
* fast/forms/time-multiple-fields/time-multiple-fields-value-set-empty.html:

2012-11-22 Keishi Hattori <[email protected]>

Add week-multiple-fields tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE
Empty text: --:-- --
PASS eventSender.keyDown("upArrow"); getUserAgentShadowTextContent(input) is not emptyText
PASS input.value = ""; getUserAgentShadowTextContent(input) is emptyText

Initial text: --:--:45 --
Empty value should not clear read-only fields.
PASS input.value = ""; getUserAgentShadowTextContent(input) is "--:--:45 --"
Empty value should clear only editable fields.
PASS eventSender.keyDown("upArrow"); getUserAgentShadowTextContent(input) is "01:--:45 --"
PASS input.value = ""; getUserAgentShadowTextContent(input) is "--:--:45 --"
PASS successfullyParsed is true

TEST COMPLETE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@
<script src="../resources/multiple-fields-value-set-empty.js"></script>
<script>
testSettingEmptyStringClearsSubFields('time');

debug('');
input = document.createElement('input');
input.type = 'time';
input.min = '11:23:45';
input.step = '60';
// Because the step value is 60 seconds, the seconds fields is read-only.
document.body.appendChild(input);
debug('Initial text: ' + getUserAgentShadowTextContent(input));
debug('Empty value should not clear read-only fields.');
shouldBeEqualToString('input.value = ""; getUserAgentShadowTextContent(input)', '--:--:45 --');

debug('Empty value should clear only editable fields.');
input.focus();
shouldBeEqualToString('eventSender.keyDown("upArrow"); getUserAgentShadowTextContent(input)', '01:--:45 --');
shouldBeEqualToString('input.value = ""; getUserAgentShadowTextContent(input)', '--:--:45 --');

</script>
<script src="../../js/resources/js-test-post.js"></script>
</body>
26 changes: 26 additions & 0 deletions Source/WebCore/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
2012-11-22 Kent Tamura <[email protected]>

INPUT_MULTIPLE_FIELDS_UI: Refactoring: Do not call updateInnerTextValue if only read-only sub-fields have values
https://bugs.webkit.org/show_bug.cgi?id=103033

Reviewed by Kentaro Hara.

input[type=time] can have read-only sub fields. If only read-only fields
have values, we don't need to call updateInnerTextValue when
HTMLInputElement::value is set to "".

Tests: this patch doesn't change any visible behavior, but we add test cases to
fast/forms/time-multiple-fields/time-multiple-fields-value-set-empty.html
just in case.

* html/shadow/DateTimeEditElement.h:
(DateTimeEditElement): Declare anyEditableFieldsHaveValues.
* html/shadow/DateTimeEditElement.cpp:
(WebCore::DateTimeEditElement::anyEditableFieldsHaveValues):
Added. This function checks value existence against only editable sub-fields.
* html/BaseMultipleFieldsDateAndTimeInputType.cpp:
(WebCore::BaseMultipleFieldsDateAndTimeInputType::setValue):
Call DateTimeEditElement::anyEditableFieldsHaveValues() instead of
DateTimeFieldsState::hasAnyValue().
* html/DateTimeFieldsState.h: Remove hasAnyValue.

2012-11-22 Allan Sandfeld Jensen <[email protected]>

[Qt] Lookup mimetypes using QMimeDatabase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ FormControlState BaseMultipleFieldsDateAndTimeInputType::saveFormControlState()
void BaseMultipleFieldsDateAndTimeInputType::setValue(const String& sanitizedValue, bool valueChanged, TextFieldEventBehavior eventBehavior)
{
InputType::setValue(sanitizedValue, valueChanged, eventBehavior);
if (valueChanged || (sanitizedValue.isEmpty() && m_dateTimeEditElement && m_dateTimeEditElement->valueAsDateTimeFieldsState().hasAnyValue()))
if (valueChanged || (sanitizedValue.isEmpty() && m_dateTimeEditElement && m_dateTimeEditElement->anyEditableFieldsHaveValues()))
updateInnerTextValue();
}

Expand Down
1 change: 0 additions & 1 deletion Source/WebCore/html/DateTimeFieldsState.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ class DateTimeFieldsState {
bool hasSecond() const { return m_second != emptyValue; }
bool hasWeekOfYear() const { return m_weekOfYear != emptyValue; }
bool hasYear() const { return m_year != emptyValue; }
bool hasAnyValue() const { return hasAMPM() || hasDayOfMonth() || hasHour() || hasMillisecond() || hasMinute() || hasMonth() || hasSecond() || hasWeekOfYear() || hasYear(); }

void setAMPM(AMPMValue ampm) { m_ampm = ampm; }
void setDayOfMonth(unsigned dayOfMonth) { m_dayOfMonth = dayOfMonth; }
Expand Down
9 changes: 9 additions & 0 deletions Source/WebCore/html/shadow/DateTimeEditElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,15 @@ void DateTimeEditElement::addField(PassRefPtr<DateTimeFieldElement> field)
appendChild(field);
}

bool DateTimeEditElement::anyEditableFieldsHaveValues() const
{
for (size_t fieldIndex = 0; fieldIndex < m_fields.size(); ++fieldIndex) {
if (!m_fields[fieldIndex]->isReadOnly() && m_fields[fieldIndex]->hasValue())
return true;
}
return false;
}

void DateTimeEditElement::blurByOwner()
{
if (DateTimeFieldElement* field = focusedField())
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/html/shadow/DateTimeEditElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class DateTimeEditElement : public HTMLDivElement, public DateTimeFieldElement::

virtual ~DateTimeEditElement();
void addField(PassRefPtr<DateTimeFieldElement>);
bool anyEditableFieldsHaveValues() const;
void blurByOwner();
virtual void defaultEventHandler(Event*) OVERRIDE;
void disabledStateChanged();
Expand Down

0 comments on commit 9c670fb

Please sign in to comment.