Title: [128594] trunk
Revision
128594
Author
tk...@chromium.org
Date
2012-09-14 05:40:27 -0700 (Fri, 14 Sep 2012)

Log Message

Make time input lang attribute aware for testing
https://bugs.webkit.org/show_bug.cgi?id=96728

Patch by Keishi Hattori <kei...@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:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (128593 => 128594)


--- trunk/LayoutTests/ChangeLog	2012-09-14 12:34:26 UTC (rev 128593)
+++ trunk/LayoutTests/ChangeLog	2012-09-14 12:40:27 UTC (rev 128594)
@@ -1,3 +1,16 @@
+2012-09-14  Keishi Hattori  <kei...@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  <yo...@chromium.org>
 
         REGRESSION(r128575): fast/forms/time-multiple-fields/time-multiple-fields-preserve-value-after-history-back.html is failed on Chromium-Win

Modified: trunk/LayoutTests/fast/forms/resources/common.js (128593 => 128594)


--- trunk/LayoutTests/fast/forms/resources/common.js	2012-09-14 12:34:26 UTC (rev 128593)
+++ trunk/LayoutTests/fast/forms/resources/common.js	2012-09-14 12:40:27 UTC (rev 128594)
@@ -115,3 +115,7 @@
     if (window.eventSender)
         eventSender.mouseMoveTo(listbox.offsetLeft + border, listbox.offsetTop + y - window.pageYOffset);
 }
+
+function getUserAgentShadowTextContent(element) {
+    return internals.youngestShadowRoot(element).textContent;
+};

Added: trunk/LayoutTests/fast/forms/time-multiple-fields/time-multiple-fields-localization.html (0 => 128594)


--- trunk/LayoutTests/fast/forms/time-multiple-fields/time-multiple-fields-localization.html	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/time-multiple-fields/time-multiple-fields-localization.html	2012-09-14 12:40:27 UTC (rev 128594)
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<script src=""
+<script src=""
+<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=""
+</body>
+</html>
Property changes on: trunk/LayoutTests/fast/forms/time-multiple-fields/time-multiple-fields-localization.html
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/LayoutTests/platform/chromium/TestExpectations (128593 => 128594)


--- trunk/LayoutTests/platform/chromium/TestExpectations	2012-09-14 12:34:26 UTC (rev 128593)
+++ trunk/LayoutTests/platform/chromium/TestExpectations	2012-09-14 12:40:27 UTC (rev 128594)
@@ -187,6 +187,8 @@
 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

Added: trunk/LayoutTests/platform/chromium-mac/fast/forms/time-multiple-fields/time-multiple-fields-localization-expected.txt (0 => 128594)


--- trunk/LayoutTests/platform/chromium-mac/fast/forms/time-multiple-fields/time-multiple-fields-localization-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/chromium-mac/fast/forms/time-multiple-fields/time-multiple-fields-localization-expected.txt	2012-09-14 12:40:27 UTC (rev 128594)
@@ -0,0 +1,21 @@
+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
+
+
+
+
+
+
Property changes on: trunk/LayoutTests/platform/chromium-mac/fast/forms/time-multiple-fields/time-multiple-fields-localization-expected.txt
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/Source/WebCore/ChangeLog (128593 => 128594)


--- trunk/Source/WebCore/ChangeLog	2012-09-14 12:34:26 UTC (rev 128593)
+++ trunk/Source/WebCore/ChangeLog	2012-09-14 12:40:27 UTC (rev 128594)
@@ -1,3 +1,34 @@
+2012-09-14  Keishi Hattori  <kei...@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....@gmail.com>
 
         Unreviewed, rolling out r128566.

Modified: trunk/Source/WebCore/dom/Document.cpp (128593 => 128594)


--- trunk/Source/WebCore/dom/Document.cpp	2012-09-14 12:34:26 UTC (rev 128593)
+++ trunk/Source/WebCore/dom/Document.cpp	2012-09-14 12:40:27 UTC (rev 128594)
@@ -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 @@
     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

Modified: trunk/Source/WebCore/dom/Document.h (128593 => 128594)


--- trunk/Source/WebCore/dom/Document.h	2012-09-14 12:34:26 UTC (rev 128593)
+++ trunk/Source/WebCore/dom/Document.h	2012-09-14 12:40:27 UTC (rev 128594)
@@ -108,6 +108,7 @@
 class IntPoint;
 class DOMWrapperWorld;
 class JSNode;
+class Localizer;
 class MediaCanStartListener;
 class MediaQueryList;
 class MediaQueryMatcher;
@@ -1192,6 +1193,8 @@
 
     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 @@
 #ifndef NDEBUG
     bool m_didDispatchViewportPropertiesChanged;
 #endif
+
+    typedef HashMap<AtomicString, OwnPtr<Localizer> > LocaleToLocalizerMap;
+    LocaleToLocalizerMap m_localizerCache;
 };
 
 inline void Document::notifyRemovePendingSheetIfNeeded()

Modified: trunk/Source/WebCore/html/TimeInputType.cpp (128593 => 128594)


--- trunk/Source/WebCore/html/TimeInputType.cpp	2012-09-14 12:34:26 UTC (rev 128593)
+++ trunk/Source/WebCore/html/TimeInputType.cpp	2012-09-14 12:40:27 UTC (rev 128594)
@@ -302,13 +302,14 @@
     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

Modified: trunk/Source/WebCore/html/shadow/DateTimeEditElement.cpp (128593 => 128594)


--- trunk/Source/WebCore/html/shadow/DateTimeEditElement.cpp	2012-09-14 12:34:26 UTC (rev 128593)
+++ trunk/Source/WebCore/html/shadow/DateTimeEditElement.cpp	2012-09-14 12:40:27 UTC (rev 128594)
@@ -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 @@
     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 @@
     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 @@
     }
 
     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 @@
             field->setReadOnly();
 
         if (needMillisecondField()) {
-            visitLiteral(localizedDecimalSeparator());
+            visitLiteral(m_localizer.localizedDecimalSeparator());
             visitField(DateTimeFormat::FieldTypeFractionalSecond, 3);
         }
         return;
@@ -337,14 +340,14 @@
     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 @@
     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 @@
         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);
 }

Modified: trunk/Source/WebCore/html/shadow/DateTimeEditElement.h (128593 => 128594)


--- trunk/Source/WebCore/html/shadow/DateTimeEditElement.h	2012-09-14 12:34:26 UTC (rev 128593)
+++ trunk/Source/WebCore/html/shadow/DateTimeEditElement.h	2012-09-14 12:40:27 UTC (rev 128594)
@@ -36,6 +36,7 @@
 class DateTimeEditLayouter;
 class DateTimeFieldsState;
 class KeyboardEvent;
+class Localizer;
 class MouseEvent;
 class StepRange;
 
@@ -70,8 +71,8 @@
     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 @@
     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.

Modified: trunk/Source/WebKit/chromium/ChangeLog (128593 => 128594)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-09-14 12:34:26 UTC (rev 128593)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-09-14 12:40:27 UTC (rev 128594)
@@ -1,5 +1,16 @@
 2012-09-14  Keishi Hattori  <kei...@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  <kei...@webkit.org>
+
         Refactor time format related methods on LocaleWin/Mac/ICU so that they override Localizer methods
         https://bugs.webkit.org/show_bug.cgi?id=96726
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to