Commit aff3c93e authored by tkent@chromium.org's avatar tkent@chromium.org
Browse files

Make time input lang attribute aware for testing

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

Patch by Keishi Hattori <keishi@webkit.org> on 2012-09-14
Reviewed by Kent Tamura.

Source/WebCore:

This patch implements partial lang attribute support for input type=time
that turns on only when enabled through InternalSettings.

Test: fast/forms/time-multiple-fields/time-multiple-fields-localization.html

* dom/Document.cpp:
(WebCore::Document::getLocalizer): Returns a localizer for a given locale. Localizers are cached for repeated use.
(WebCore):
* dom/Document.h:
(WebCore):
(Document):
* html/TimeInputType.cpp:
(WebCore::TimeInputType::updateInnerTextValue): Use the locale for the input element.
* html/shadow/DateTimeEditElement.cpp:
(DateTimeEditBuilder):
(WebCore::DateTimeEditBuilder::DateTimeEditBuilder):
(WebCore::DateTimeEditBuilder::visitField):
(WebCore::DateTimeEditElement::layout):
(WebCore::DateTimeEditElement::setValueAsDate):
(WebCore::DateTimeEditElement::setEmptyValue):
* html/shadow/DateTimeEditElement.h:
(WebCore):
(DateTimeEditElement):

Source/WebKit/chromium:

* tests/LocalizedDateICUTest.cpp:
(LocalizedDateICUTest::localizedDateFormatText):
(LocalizedDateICUTest::localizedShortDateFormatText):

LayoutTests:

* fast/forms/resources/common.js:
(getUserAgentShadowTextContent): Used to get the text inside an input element.
* fast/forms/time-multiple-fields/time-multiple-fields-localization.html: Added.
* platform/chromium-mac/fast/forms/time-multiple-fields/time-multiple-fields-localization-expected.txt: Added.
* platform/chromium/TestExpectations:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@128594 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent c6f0943c
2012-09-14 Keishi Hattori <keishi@webkit.org>
Make time input lang attribute aware for testing
https://bugs.webkit.org/show_bug.cgi?id=96728
Reviewed by Kent Tamura.
* fast/forms/resources/common.js:
(getUserAgentShadowTextContent): Used to get the text inside an input element.
* fast/forms/time-multiple-fields/time-multiple-fields-localization.html: Added.
* platform/chromium-mac/fast/forms/time-multiple-fields/time-multiple-fields-localization-expected.txt: Added.
* platform/chromium/TestExpectations:
2012-09-14 Yoshifumi Inoue <yosin@chromium.org>
 
REGRESSION(r128575): fast/forms/time-multiple-fields/time-multiple-fields-preserve-value-after-history-back.html is failed on Chromium-Win
......@@ -115,3 +115,7 @@ function mouseMoveToIndexInListbox(index, listboxId) {
if (window.eventSender)
eventSender.mouseMoveTo(listbox.offsetLeft + border, listbox.offsetTop + y - window.pageYOffset);
}
function getUserAgentShadowTextContent(element) {
return internals.youngestShadowRoot(element).textContent;
};
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="../../js/resources/js-test-pre.js"></script>
<script src="../resources/common.js"></script>
<script>
if (window.internals)
internals.settings.setLangAttributeAwareFormControlUIEnabled(true);
</script>
</head>
<body>
<div id=console></div>
<input type="time" value="13:23:45.1" lang="en" /><br>
<input type="time" value="13:23:45.1" lang="ar" /><br>
<input type="time" value="13:23:45.1" lang="fr" /><br>
<input type="time" value="13:23:45.1" lang="ja" /><br>
<input type="time" value="13:23:45.1" lang="ko" /><br>
<input type="time" value="13:23:45.1" lang="cn" />
<script>
description("Tests the time format for various locales.", true);
debug("The following lines depend on the locale data in the system.");
var inputs = document.getElementsByTagName("input");
for (var i = 0; i < inputs.length; ++i) {
debug(inputs[i].lang + ': ' + getUserAgentShadowTextContent(inputs[i]));
}
</script>
<script src="../../js/resources/js-test-post.js"></script>
</body>
</html>
Tests the time format for various locales.
On success, you will see no "FAIL" messages, followed by "TEST COMPLETE".
The following lines depend on the locale data in the system.
en: 01:23:45.100 PM
ar: 01:23:45٫100 م
fr: 13:23:45,100
ja: 13:23:45.100
ko: 오후 01:23:45.100
cn: 01:23:45.100 PM
PASS successfullyParsed is true
TEST COMPLETE
......@@ -187,6 +187,8 @@ BUGWK94916 SNOWLEOPARD WIN LINUX : fast/forms/datalist/input-appearance-range-wi
BUGWK94916 SNOWLEOPARD WIN LINUX : fast/forms/datalist/input-appearance-range-with-transform.html = MISSING IMAGE
BUGWK94916 SNOWLEOPARD WIN LINUX : fast/forms/datalist/input-appearance-range-with-datalist-zoomed.html = IMAGE
BUGWK96751 WIN LINUX : fast/forms/time-multiple-fields/time-multiple-fields-localization.html = MISSING TEXT
// Proximity Events is not supported.
BUGWK92942 SKIP : fast/dom/Proximity = PASS
BUGWK92942 SKIP : fast/events/constructors/device-proximity-event-constructor.html = PASS
......
2012-09-14 Keishi Hattori <keishi@webkit.org>
Make time input lang attribute aware for testing
https://bugs.webkit.org/show_bug.cgi?id=96728
Reviewed by Kent Tamura.
This patch implements partial lang attribute support for input type=time
that turns on only when enabled through InternalSettings.
Test: fast/forms/time-multiple-fields/time-multiple-fields-localization.html
* dom/Document.cpp:
(WebCore::Document::getLocalizer): Returns a localizer for a given locale. Localizers are cached for repeated use.
(WebCore):
* dom/Document.h:
(WebCore):
(Document):
* html/TimeInputType.cpp:
(WebCore::TimeInputType::updateInnerTextValue): Use the locale for the input element.
* html/shadow/DateTimeEditElement.cpp:
(DateTimeEditBuilder):
(WebCore::DateTimeEditBuilder::DateTimeEditBuilder):
(WebCore::DateTimeEditBuilder::visitField):
(WebCore::DateTimeEditElement::layout):
(WebCore::DateTimeEditElement::setValueAsDate):
(WebCore::DateTimeEditElement::setEmptyValue):
* html/shadow/DateTimeEditElement.h:
(WebCore):
(DateTimeEditElement):
2012-09-14 Sheriff Bot <webkit.review.bot@gmail.com>
 
Unreviewed, rolling out r128566.
......@@ -105,6 +105,8 @@
#include "ImageLoader.h"
#include "InspectorCounters.h"
#include "InspectorInstrumentation.h"
#include "Language.h"
#include "Localizer.h"
#include "Logging.h"
#include "MediaQueryList.h"
#include "MediaQueryMatcher.h"
......@@ -131,6 +133,7 @@
#include "RenderTextControl.h"
#include "RenderView.h"
#include "RenderWidget.h"
#include "RuntimeEnabledFeatures.h"
#include "SchemeRegistry.h"
#include "ScopedEventQueue.h"
#include "ScriptCallStack.h"
......@@ -6362,4 +6365,15 @@ PassRefPtr<ElementAttributeData> Document::cachedImmutableAttributeData(const El
return attributeData.release();
}
Localizer& Document::getLocalizer(const AtomicString& locale)
{
AtomicString localeKey = locale;
if (locale.isEmpty() || !RuntimeEnabledFeatures::langAttributeAwareFormControlUIEnabled())
localeKey = defaultLanguage();
LocaleToLocalizerMap::AddResult result = m_localizerCache.add(localeKey, nullptr);
if (result.isNewEntry)
result.iterator->second = Localizer::create(localeKey);
return *(result.iterator->second);
}
} // namespace WebCore
......@@ -108,6 +108,7 @@ class HitTestResult;
class IntPoint;
class DOMWrapperWorld;
class JSNode;
class Localizer;
class MediaCanStartListener;
class MediaQueryList;
class MediaQueryMatcher;
......@@ -1192,6 +1193,8 @@ public:
PassRefPtr<ElementAttributeData> cachedImmutableAttributeData(const Element*, const Vector<Attribute>&);
Localizer& getLocalizer(const AtomicString& locale);
protected:
Document(Frame*, const KURL&, bool isXHTML, bool isHTML);
......@@ -1582,6 +1585,9 @@ private:
#ifndef NDEBUG
bool m_didDispatchViewportPropertiesChanged;
#endif
typedef HashMap<AtomicString, OwnPtr<Localizer> > LocaleToLocalizerMap;
LocaleToLocalizerMap m_localizerCache;
};
inline void Document::notifyRemovePendingSheetIfNeeded()
......
......@@ -302,13 +302,14 @@ void TimeInputType::updateInnerTextValue()
if (!m_dateTimeEditElement)
return;
Localizer& localizer = element()->document()->getLocalizer(element()->computeInheritedLanguage());
const StepRange stepRange(createStepRange(AnyIsDefaultStep));
DateComponents date;
if (parseToDateComponents(element()->value(), &date))
m_dateTimeEditElement->setValueAsDate(stepRange, date);
m_dateTimeEditElement->setValueAsDate(stepRange, date, localizer);
else {
setMillisecondToDateComponents(stepRange.minimum().toDouble(), &date);
m_dateTimeEditElement->setEmptyValue(stepRange, date);
m_dateTimeEditElement->setEmptyValue(stepRange, date, localizer);
}
}
#else
......
......@@ -37,6 +37,7 @@
#include "KeyboardEvent.h"
#include "LocalizedDate.h"
#include "LocalizedNumber.h"
#include "Localizer.h"
#include "MouseEvent.h"
#include "StepRange.h"
#include "Text.h"
......@@ -51,7 +52,7 @@ class DateTimeEditBuilder : private DateTimeFormat::TokenHandler {
WTF_MAKE_NONCOPYABLE(DateTimeEditBuilder);
public:
DateTimeEditBuilder(DateTimeEditElement&, const StepRange&, const DateComponents&);
DateTimeEditBuilder(DateTimeEditElement&, const StepRange&, const DateComponents&, Localizer&);
bool build(const String&);
bool needSecondField() const;
......@@ -70,12 +71,14 @@ private:
DateTimeEditElement& m_editElement;
const DateComponents& m_dateValue;
const StepRange& m_stepRange;
Localizer& m_localizer;
};
DateTimeEditBuilder::DateTimeEditBuilder(DateTimeEditElement& elemnt, const StepRange& stepRange, const DateComponents& dateValue)
DateTimeEditBuilder::DateTimeEditBuilder(DateTimeEditElement& elemnt, const StepRange& stepRange, const DateComponents& dateValue, Localizer& localizer)
: m_editElement(elemnt)
, m_dateValue(dateValue)
, m_stepRange(stepRange)
, m_localizer(localizer)
{
}
......@@ -136,7 +139,7 @@ void DateTimeEditBuilder::visitField(DateTimeFormat::FieldType fieldType, int)
}
case DateTimeFormat::FieldTypePeriod:
m_editElement.addField(DateTimeAMPMFieldElement::create(document, m_editElement, timeAMPMLabels()));
m_editElement.addField(DateTimeAMPMFieldElement::create(document, m_editElement, m_localizer.timeAMPMLabels()));
return;
case DateTimeFormat::FieldTypeSecond: {
......@@ -146,7 +149,7 @@ void DateTimeEditBuilder::visitField(DateTimeFormat::FieldType fieldType, int)
field->setReadOnly();
if (needMillisecondField()) {
visitLiteral(localizedDecimalSeparator());
visitLiteral(m_localizer.localizedDecimalSeparator());
visitField(DateTimeFormat::FieldTypeFractionalSecond, 3);
}
return;
......@@ -337,14 +340,14 @@ bool DateTimeEditElement::isReadOnly() const
return m_editControlOwner && m_editControlOwner->isEditControlOwnerReadOnly();
}
void DateTimeEditElement::layout(const StepRange& stepRange, const DateComponents& dateValue)
void DateTimeEditElement::layout(const StepRange& stepRange, const DateComponents& dateValue, Localizer& localizer)
{
size_t focusedFieldIndex = this->focusedFieldIndex();
DateTimeFieldElement* const focusedField = fieldAt(focusedFieldIndex);
const AtomicString focusedFieldId = focusedField ? focusedField->shadowPseudoId() : nullAtom;
DateTimeEditBuilder builder(*this, stepRange, dateValue);
const String dateTimeFormat = builder.needSecondField() ? localizedTimeFormatText() : localizedShortTimeFormatText();
DateTimeEditBuilder builder(*this, stepRange, dateValue, localizer);
const String dateTimeFormat = builder.needSecondField() ? localizer.timeFormat() : localizer.shortTimeFormat();
Node* lastChildToBeRemoved = lastChild();
if (!builder.build(dateTimeFormat) || m_fields.isEmpty()) {
lastChildToBeRemoved = lastChild();
......@@ -404,9 +407,9 @@ void DateTimeEditElement::defaultEventHandler(Event* event)
HTMLDivElement::defaultEventHandler(event);
}
void DateTimeEditElement::setValueAsDate(const StepRange& stepRange, const DateComponents& date)
void DateTimeEditElement::setValueAsDate(const StepRange& stepRange, const DateComponents& date, Localizer& localizer)
{
layout(stepRange, date);
layout(stepRange, date, localizer);
for (size_t fieldIndex = 0; fieldIndex < m_fields.size(); ++fieldIndex)
m_fields[fieldIndex]->setValueAsDate(date);
}
......@@ -417,9 +420,9 @@ void DateTimeEditElement::setValueAsDateTimeFieldsState(const DateTimeFieldsStat
m_fields[fieldIndex]->setValueAsDateTimeFieldsState(dateTimeFieldsState, dateForReadOnlyField);
}
void DateTimeEditElement::setEmptyValue(const StepRange& stepRange, const DateComponents& dateForReadOnlyField)
void DateTimeEditElement::setEmptyValue(const StepRange& stepRange, const DateComponents& dateForReadOnlyField, Localizer& localizer)
{
layout(stepRange, dateForReadOnlyField);
layout(stepRange, dateForReadOnlyField, localizer);
for (size_t fieldIndex = 0; fieldIndex < m_fields.size(); ++fieldIndex)
m_fields[fieldIndex]->setEmptyValue(dateForReadOnlyField, DateTimeFieldElement::DispatchNoEvent);
}
......
......@@ -36,6 +36,7 @@ class DateComponents;
class DateTimeEditLayouter;
class DateTimeFieldsState;
class KeyboardEvent;
class Localizer;
class MouseEvent;
class StepRange;
......@@ -70,8 +71,8 @@ public:
void readOnlyStateChanged();
void removeEditControlOwner() { m_editControlOwner = 0; }
void resetFields();
void setEmptyValue(const StepRange&, const DateComponents& dateForReadOnlyField);
void setValueAsDate(const StepRange&, const DateComponents&);
void setEmptyValue(const StepRange&, const DateComponents& dateForReadOnlyField, Localizer&);
void setValueAsDate(const StepRange&, const DateComponents&, Localizer&);
void setValueAsDateTimeFieldsState(const DateTimeFieldsState&, const DateComponents& dateForReadOnlyField);
DateTimeFieldsState valueAsDateTimeFieldsState() const;
double valueAsDouble() const;
......@@ -98,7 +99,7 @@ private:
size_t focusedFieldIndex() const;
bool isDisabled() const;
bool isReadOnly() const;
void layout(const StepRange&, const DateComponents&);
void layout(const StepRange&, const DateComponents&, Localizer&);
void updateUIState();
// DateTimeFieldElement::FieldOwner functions.
......
2012-09-14 Keishi Hattori <keishi@webkit.org>
Make time input lang attribute aware for testing
https://bugs.webkit.org/show_bug.cgi?id=96728
Reviewed by Kent Tamura.
* tests/LocalizedDateICUTest.cpp:
(LocalizedDateICUTest::localizedDateFormatText):
(LocalizedDateICUTest::localizedShortDateFormatText):
2012-09-14 Keishi Hattori <keishi@webkit.org>
 
Refactor time format related methods on LocaleWin/Mac/ICU so that they override Localizer methods
......
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