Title: [136808] trunk
Revision
136808
Author
[email protected]
Date
2012-12-05 23:10:22 -0800 (Wed, 05 Dec 2012)

Log Message

INPUT_MULTIPLE_FIELDS_UI doesn't show digits well in RTL locales
https://bugs.webkit.org/show_bug.cgi?id=103869

Reviewed by Hajime Morita.

Source/WebCore:

We need to use display:inline elements to wrap sub-fields and static
text in DateTimeEditElement children to apply the Unicode Bidi
Algorithm.

Because we can't use display:inline-block for them, we can't specify
min-width CSS property for them. We stop using customStyleForRenderer of
sub-fields to specify each of their widths, and use
customStyleForRenderer of DateTimeEditElement to specify the total
required width. A sub-field width shrink and grow so that the width fits
to the field value, and a DateTimeEditElement doesn't.

No new tests. Coverred by existing tests, especially
fast/forms/datetime/datetime-appearance-l10n.html shows "23:59"
correctly.

* css/html.css:
(input::-webkit-datetime-edit-year-field):
- Make this display:inline to apply the Unicode Bidi Algorithm.
- Use padding instead of margin because of ease of width computation.
  Also, the focus apparance gets better by padding.
- Don't allow to specify font property here because of ease of width
  computation.
- Remove text-align:center. It doesn't work for display:inline.
(input::-webkit-datetime-edit-text):
- Make this display:inline to apply the Unicode Bidi Algorithm.
- Don't allow to specify font property here because of ease of width
  computation.

* html/shadow/DateTimeEditElement.h:
(DateTimeEditElement): Declare customStyleForRenderer.
* html/shadow/DateTimeEditElement.cpp:
(WebCore::DateTimeEditElement::DateTimeEditElement):
Enable customStyleForRenderer.
(WebCore::DateTimeEditElement::customStyleForRenderer):
Compute required width with a font for this element and child maximum
widths, and set it to min-width style.
The resultant width value can be inaccurate if a page author specifies
padding, border, margin, etc. to ::-webkit-datetime-edit-*-field or
::-webkit-datetime-edit-text. In such case, the page author should specify
wider width to <input>.

* dom/Element.h:
(Element): Add isDateTimeFieldElement to do static_cast<DateTimeFieldElement> safely.
* dom/Element.cpp:
(WebCore::Element::isDateTimeFieldElement): Added.

* html/shadow/DateTimeFieldElement.h:
(DateTimeFieldElement): Declare isDateTimeFieldElement and maximumWidth.
* html/shadow/DateTimeFieldElement.cpp:
(WebCore::DateTimeFieldElement::isDateTimeFieldElement):
Added. Returns true.
(WebCore::DateTimeFieldElement::maximumWidth):
Added. Returns padding width.

* html/shadow/DateTimeSymbolicFieldElement.h:
(DateTimeSymbolicFieldElement):
Remove customStyleForRenderer, and declare maximumWidth.
* html/shadow/DateTimeSymbolicFieldElement.cpp:
(WebCore::DateTimeSymbolicFieldElement::DateTimeSymbolicFieldElement):
Disable customStyleForRenderer.
(WebCore::DateTimeSymbolicFieldElement::maximumWidth):
Added. Returns the expected maximum width with the specified font.

* html/shadow/DateTimeNumericFieldElement.h:
(DateTimeNumericFieldElement):
Remove customStyleForRenderer, declare maximumWidth, and make m_placeholder
non-const because it is updated in the constructor.
* html/shadow/DateTimeNumericFieldElement.cpp:
(WebCore::DateTimeNumericFieldElement::DateTimeNumericFieldElement):
Disable customStyleForRenderer.
If a numeric value for this field is LTR and the whole direction is RTL,
wrap the placeholder string with left-to-right-mark and
right-to-left-mark so that it is handled as LTR. Without this,
sub-fields order would be changed when the content of a field is changed
from a placeholder to a numeric value.
(WebCore::DateTimeNumericFieldElement::maximumWidth):
Added. Returns the expected maximum width with the specified font.

LayoutTests:

- Year fields and month fields are shrunk because we stop specifying
  min-width.
- Focus rectangle for sub-fields get larger.

* fast/forms/date-multiple-fields/date-multiple-fields-mouse-events.html:
Need to update mouse click positions because we have some position/width
changes in sub-fields.
* fast/forms/datetimelocal-multiple-fields/datetimelocal-multiple-fields-mouse-events.html:
Ditto.
* fast/forms/month-multiple-fields/month-multiple-fields-mouse-events.html:
Ditto.
* platform/chromium-mac/fast/forms/date/date-appearance-basic-expected.png:
* platform/chromium-mac/fast/forms/datetime/datetime-l10n-expected.png:
* platform/chromium-mac/fast/forms/month/month-appearance-basic-expected.png:
* platform/chromium-mac/fast/forms/time/time-appearance-basic-expected.png:
* platform/chromium-mac/fast/forms/week/week-appearance-basic-expected.png:
* platform/chromium/TestExpectations:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (136807 => 136808)


--- trunk/LayoutTests/ChangeLog	2012-12-06 06:36:23 UTC (rev 136807)
+++ trunk/LayoutTests/ChangeLog	2012-12-06 07:10:22 UTC (rev 136808)
@@ -1,3 +1,28 @@
+2012-12-03  Kent Tamura  <[email protected]>
+
+        INPUT_MULTIPLE_FIELDS_UI doesn't show digits well in RTL locales
+        https://bugs.webkit.org/show_bug.cgi?id=103869
+
+        Reviewed by Hajime Morita.
+
+        - Year fields and month fields are shrunk because we stop specifying
+          min-width.
+        - Focus rectangle for sub-fields get larger.
+
+        * fast/forms/date-multiple-fields/date-multiple-fields-mouse-events.html:
+        Need to update mouse click positions because we have some position/width
+        changes in sub-fields.
+        * fast/forms/datetimelocal-multiple-fields/datetimelocal-multiple-fields-mouse-events.html:
+        Ditto.
+        * fast/forms/month-multiple-fields/month-multiple-fields-mouse-events.html:
+        Ditto.
+        * platform/chromium-mac/fast/forms/date/date-appearance-basic-expected.png:
+        * platform/chromium-mac/fast/forms/datetime/datetime-l10n-expected.png:
+        * platform/chromium-mac/fast/forms/month/month-appearance-basic-expected.png:
+        * platform/chromium-mac/fast/forms/time/time-appearance-basic-expected.png:
+        * platform/chromium-mac/fast/forms/week/week-appearance-basic-expected.png:
+        * platform/chromium/TestExpectations:
+
 2012-12-05  Shinya Kawanaka  <[email protected]>
 
         [Chromium] DRT on Windows crashes when a testcase has a progress element in indeterminate state

Modified: trunk/LayoutTests/fast/forms/date-multiple-fields/date-multiple-fields-mouse-events.html (136807 => 136808)


--- trunk/LayoutTests/fast/forms/date-multiple-fields/date-multiple-fields-mouse-events.html	2012-12-06 06:36:23 UTC (rev 136807)
+++ trunk/LayoutTests/fast/forms/date-multiple-fields/date-multiple-fields-mouse-events.html	2012-12-06 07:10:22 UTC (rev 136808)
@@ -62,7 +62,7 @@
 
 debug('');
 debug('==> Focus on the year field.');
-mouseClickOn(input.offsetWidth - 64, center);
+mouseClickOn(input.offsetWidth - 100, center);
 keyDown('upArrow');
 shouldBeEqualToString('input.value', '2346-08-20');
 mouseClickOn(input.offsetWidth - spinButtonOffset, center - 1);

Modified: trunk/LayoutTests/fast/forms/datetimelocal-multiple-fields/datetimelocal-multiple-fields-mouse-events.html (136807 => 136808)


--- trunk/LayoutTests/fast/forms/datetimelocal-multiple-fields/datetimelocal-multiple-fields-mouse-events.html	2012-12-06 06:36:23 UTC (rev 136807)
+++ trunk/LayoutTests/fast/forms/datetimelocal-multiple-fields/datetimelocal-multiple-fields-mouse-events.html	2012-12-06 07:10:22 UTC (rev 136808)
@@ -73,7 +73,7 @@
 
 debug('');
 debug('==> Focus on the hour field.');
-mouseClickOn(input.offsetWidth - 156, center);
+mouseClickOn(190, center);
 keyDown('upArrow');
 shouldBeEqualToString('input.value', '2346-08-20T11:00');
 mouseClickOn(input.offsetWidth - spinButtonOffset, center - 1);
@@ -84,7 +84,7 @@
 
 debug('');
 debug('==> Focus on the minute field.');
-mouseClickOn(input.offsetWidth - 108, center);
+mouseClickOn(240, center);
 keyDown('upArrow');
 shouldBeEqualToString('input.value', '2346-08-20T11:01');
 mouseClickOn(input.offsetWidth - spinButtonOffset, center - 1);

Modified: trunk/LayoutTests/fast/forms/month-multiple-fields/month-multiple-fields-mouse-events.html (136807 => 136808)


--- trunk/LayoutTests/fast/forms/month-multiple-fields/month-multiple-fields-mouse-events.html	2012-12-06 06:36:23 UTC (rev 136807)
+++ trunk/LayoutTests/fast/forms/month-multiple-fields/month-multiple-fields-mouse-events.html	2012-12-06 07:10:22 UTC (rev 136808)
@@ -40,7 +40,7 @@
 var spinButtonOffset = 26;
 
 debug('==> Focus on the month field.');
-mouseClickOn(100, center);
+mouseClickOn(16, center);
 keyDown('upArrow');
 shouldBeEqualToString('input.value', '2345-08');
 mouseClickOn(input.offsetWidth - spinButtonOffset, center - 1);
@@ -51,7 +51,7 @@
 
 debug('');
 debug('==> Focus on the year field.');
-mouseClickOn(220, center);
+mouseClickOn(170, center);
 keyDown('upArrow');
 shouldBeEqualToString('input.value', '2346-08');
 mouseClickOn(input.offsetWidth - spinButtonOffset, center - 1);

Modified: trunk/LayoutTests/platform/chromium/TestExpectations (136807 => 136808)


--- trunk/LayoutTests/platform/chromium/TestExpectations	2012-12-06 06:36:23 UTC (rev 136807)
+++ trunk/LayoutTests/platform/chromium/TestExpectations	2012-12-06 07:10:22 UTC (rev 136808)
@@ -2826,6 +2826,34 @@
 
 crbug.com/84032 [ Win ] fast/dom/object-plugin-hides-properties.html [ Pass Timeout ]
 
+# Need rebaseline
+webkit.org/b/103869 fast/forms/date/date-appearance-basic.html [ ImageOnlyFailure ]
+webkit.org/b/103869 fast/forms/date/date-appearance-l10n.html [ ImageOnlyFailure ]
+webkit.org/b/103869 fast/forms/date/date-appearance-pseudo-elements.html [ ImageOnlyFailure ]
+webkit.org/b/103869 fast/forms/datetime/datetime-appearance-l10n.html [ ImageOnlyFailure ]
+webkit.org/b/103869 fast/forms/month/month-appearance-basic.html [ ImageOnlyFailure ]
+webkit.org/b/103869 fast/forms/month/month-appearance-l10n.html [ ImageOnlyFailure ]
+webkit.org/b/103869 fast/forms/month/month-appearance-pseudo-elements.html [ ImageOnlyFailure ]
+webkit.org/b/103869 fast/forms/time/time-appearance-basic.html [ ImageOnlyFailure ]
+webkit.org/b/103869 fast/forms/time/time-appearance-pseudo-elements.html [ ImageOnlyFailure ]
+webkit.org/b/103869 fast/forms/week/week-appearance-basic.html [ ImageOnlyFailure ]
+webkit.org/b/103869 fast/forms/week/week-appearance-pseudo-elements.html [ ImageOnlyFailure ]
+webkit.org/b/103869 platform/chromium/fast/forms/suggestion-picker/date-suggestion-picker-appearance-rtl.html [ ImageOnlyFailure ]
+webkit.org/b/103869 platform/chromium/fast/forms/suggestion-picker/date-suggestion-picker-appearance-with-scroll-bar.html [ ImageOnlyFailure ]
+webkit.org/b/103869 platform/chromium/fast/forms/suggestion-picker/date-suggestion-picker-appearance.html [ ImageOnlyFailure ]
+webkit.org/b/103869 platform/chromium/fast/forms/suggestion-picker/datetime-suggestion-picker-appearance-rtl.html [ ImageOnlyFailure ]
+webkit.org/b/103869 platform/chromium/fast/forms/suggestion-picker/datetime-suggestion-picker-appearance-with-scroll-bar.html [ ImageOnlyFailure ]
+webkit.org/b/103869 platform/chromium/fast/forms/suggestion-picker/datetime-suggestion-picker-appearance.html [ ImageOnlyFailure ]
+webkit.org/b/103869 platform/chromium/fast/forms/suggestion-picker/datetimelocal-suggestion-picker-appearance-rtl.html [ ImageOnlyFailure ]
+webkit.org/b/103869 platform/chromium/fast/forms/suggestion-picker/datetimelocal-suggestion-picker-appearance-with-scroll-bar.html [ ImageOnlyFailure ]
+webkit.org/b/103869 platform/chromium/fast/forms/suggestion-picker/datetimelocal-suggestion-picker-appearance.html [ ImageOnlyFailure ]
+webkit.org/b/103869 platform/chromium/fast/forms/suggestion-picker/month-suggestion-picker-appearance-rtl.html [ ImageOnlyFailure ]
+webkit.org/b/103869 platform/chromium/fast/forms/suggestion-picker/month-suggestion-picker-appearance-with-scroll-bar.html [ ImageOnlyFailure ]
+webkit.org/b/103869 platform/chromium/fast/forms/suggestion-picker/month-suggestion-picker-appearance.html [ ImageOnlyFailure ]
+webkit.org/b/103869 platform/chromium/fast/forms/suggestion-picker/week-suggestion-picker-appearance-rtl.html [ ImageOnlyFailure ]
+webkit.org/b/103869 platform/chromium/fast/forms/suggestion-picker/week-suggestion-picker-appearance-with-scroll-bar.html [ ImageOnlyFailure ]
+webkit.org/b/103869 platform/chromium/fast/forms/suggestion-picker/week-suggestion-picker-appearance.html [ ImageOnlyFailure ]
+
 #new test added. Still fails on chrome
 webkit.org/b/98315 css3/compositing/blend-mode-property.html [ Failure ]
 webkit.org/b/98315 css3/compositing/should-have-compositing-layer.html [ Failure ]

Modified: trunk/LayoutTests/platform/chromium-mac/fast/forms/date/date-appearance-basic-expected.png


(Binary files differ)

Modified: trunk/LayoutTests/platform/chromium-mac/fast/forms/datetime/datetime-appearance-l10n-expected.png


(Binary files differ)

Modified: trunk/LayoutTests/platform/chromium-mac/fast/forms/month/month-appearance-basic-expected.png


(Binary files differ)

Modified: trunk/LayoutTests/platform/chromium-mac/fast/forms/time/time-appearance-basic-expected.png


(Binary files differ)

Modified: trunk/LayoutTests/platform/chromium-mac/fast/forms/week/week-appearance-basic-expected.png


(Binary files differ)

Modified: trunk/Source/WebCore/ChangeLog (136807 => 136808)


--- trunk/Source/WebCore/ChangeLog	2012-12-06 06:36:23 UTC (rev 136807)
+++ trunk/Source/WebCore/ChangeLog	2012-12-06 07:10:22 UTC (rev 136808)
@@ -1,3 +1,88 @@
+2012-12-03  Kent Tamura  <[email protected]>
+
+        INPUT_MULTIPLE_FIELDS_UI doesn't show digits well in RTL locales
+        https://bugs.webkit.org/show_bug.cgi?id=103869
+
+        Reviewed by Hajime Morita.
+
+        We need to use display:inline elements to wrap sub-fields and static
+        text in DateTimeEditElement children to apply the Unicode Bidi
+        Algorithm.
+
+        Because we can't use display:inline-block for them, we can't specify
+        min-width CSS property for them. We stop using customStyleForRenderer of
+        sub-fields to specify each of their widths, and use
+        customStyleForRenderer of DateTimeEditElement to specify the total
+        required width. A sub-field width shrink and grow so that the width fits
+        to the field value, and a DateTimeEditElement doesn't.
+
+        No new tests. Coverred by existing tests, especially
+        fast/forms/datetime/datetime-appearance-l10n.html shows "23:59"
+        correctly.
+
+        * css/html.css:
+        (input::-webkit-datetime-edit-year-field):
+        - Make this display:inline to apply the Unicode Bidi Algorithm.
+        - Use padding instead of margin because of ease of width computation.
+          Also, the focus apparance gets better by padding.
+        - Don't allow to specify font property here because of ease of width
+          computation.
+        - Remove text-align:center. It doesn't work for display:inline.
+        (input::-webkit-datetime-edit-text):
+        - Make this display:inline to apply the Unicode Bidi Algorithm.
+        - Don't allow to specify font property here because of ease of width
+          computation.
+
+        * html/shadow/DateTimeEditElement.h:
+        (DateTimeEditElement): Declare customStyleForRenderer.
+        * html/shadow/DateTimeEditElement.cpp:
+        (WebCore::DateTimeEditElement::DateTimeEditElement):
+        Enable customStyleForRenderer.
+        (WebCore::DateTimeEditElement::customStyleForRenderer):
+        Compute required width with a font for this element and child maximum
+        widths, and set it to min-width style.
+        The resultant width value can be inaccurate if a page author specifies
+        padding, border, margin, etc. to ::-webkit-datetime-edit-*-field or
+        ::-webkit-datetime-edit-text. In such case, the page author should specify
+        wider width to <input>.
+
+        * dom/Element.h:
+        (Element): Add isDateTimeFieldElement to do static_cast<DateTimeFieldElement> safely.
+        * dom/Element.cpp:
+        (WebCore::Element::isDateTimeFieldElement): Added.
+
+        * html/shadow/DateTimeFieldElement.h:
+        (DateTimeFieldElement): Declare isDateTimeFieldElement and maximumWidth.
+        * html/shadow/DateTimeFieldElement.cpp:
+        (WebCore::DateTimeFieldElement::isDateTimeFieldElement):
+        Added. Returns true.
+        (WebCore::DateTimeFieldElement::maximumWidth):
+        Added. Returns padding width.
+
+        * html/shadow/DateTimeSymbolicFieldElement.h:
+        (DateTimeSymbolicFieldElement):
+        Remove customStyleForRenderer, and declare maximumWidth.
+        * html/shadow/DateTimeSymbolicFieldElement.cpp:
+        (WebCore::DateTimeSymbolicFieldElement::DateTimeSymbolicFieldElement):
+        Disable customStyleForRenderer.
+        (WebCore::DateTimeSymbolicFieldElement::maximumWidth):
+        Added. Returns the expected maximum width with the specified font.
+
+        * html/shadow/DateTimeNumericFieldElement.h:
+        (DateTimeNumericFieldElement):
+        Remove customStyleForRenderer, declare maximumWidth, and make m_placeholder
+        non-const because it is updated in the constructor.
+        * html/shadow/DateTimeNumericFieldElement.cpp:
+        (WebCore::DateTimeNumericFieldElement::DateTimeNumericFieldElement):
+        Disable customStyleForRenderer.
+        If a numeric value for this field is LTR and the whole direction is RTL,
+        wrap the placeholder string with left-to-right-mark and
+        right-to-left-mark so that it is handled as LTR. Without this,
+        sub-fields order would be changed when the content of a field is changed
+        from a placeholder to a numeric value.
+        (WebCore::DateTimeNumericFieldElement::maximumWidth):
+        Added. Returns the expected maximum width with the specified font.
+
 2012-12-05  Kent Tamura  <[email protected]>
 
         INPUT_MULTIPLE_FIELDS_UI: The hour, am/pm, millisecond fields should support read-only state correctly

Modified: trunk/Source/WebCore/css/html.css (136807 => 136808)


--- trunk/Source/WebCore/css/html.css	2012-12-06 06:36:23 UTC (rev 136807)
+++ trunk/Source/WebCore/css/html.css	2012-12-06 07:10:22 UTC (rev 136808)
@@ -540,6 +540,8 @@
     white-space: pre;
 }
 
+/* If you update padding, border, or margin in the following ruleset, update
+   DateTimeFieldElement::maximumWidth too. */
 input::-webkit-datetime-edit-ampm-field,
 input::-webkit-datetime-edit-day-field,
 input::-webkit-datetime-edit-hour-field,
@@ -551,9 +553,9 @@
 input::-webkit-datetime-edit-year-field {
     -webkit-user-modify: read-only !important;
     border: none;
-    display: inline-block;
-    margin: 1px;
-    text-align: center;
+    display: inline;
+    font: inherit !important;
+    padding: 1px;
 }
 
 /* Remove focus ring from fields and use highlight color */
@@ -579,9 +581,12 @@
     color: GrayText;
 }
 
+/* If you update padding, border, or margin in the following ruleset, update
+   DateTimeEditElement::customStyelForRenderer too. */
 input::-webkit-datetime-edit-text {
     -webkit-user-modify: read-only !important;
-    display: inline-block;
+    display: inline;
+    font: inherit !important;
 }
 
 input::-webkit-date-and-time-container {

Modified: trunk/Source/WebCore/dom/Element.cpp (136807 => 136808)


--- trunk/Source/WebCore/dom/Element.cpp	2012-12-06 06:36:23 UTC (rev 136807)
+++ trunk/Source/WebCore/dom/Element.cpp	2012-12-06 07:10:22 UTC (rev 136808)
@@ -1068,6 +1068,13 @@
     return RenderObject::createObject(this, style);
 }
 
+#if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
+bool Element::isDateTimeFieldElement() const
+{
+    return false;
+}
+#endif
+
 bool Element::wasChangedSinceLastFormControlChangeEvent() const
 {
     return false;

Modified: trunk/Source/WebCore/dom/Element.h (136807 => 136808)


--- trunk/Source/WebCore/dom/Element.h	2012-12-06 06:36:23 UTC (rev 136807)
+++ trunk/Source/WebCore/dom/Element.h	2012-12-06 07:10:22 UTC (rev 136808)
@@ -398,6 +398,9 @@
 #if ENABLE(INPUT_SPEECH)
     virtual bool isInputFieldSpeechButtonElement() const { return false; }
 #endif
+#if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
+    virtual bool isDateTimeFieldElement() const;
+#endif
 
     virtual bool isFormControlElement() const { return false; }
     virtual bool isEnabledFormControl() const { return true; }

Modified: trunk/Source/WebCore/html/shadow/DateTimeEditElement.cpp (136807 => 136808)


--- trunk/Source/WebCore/html/shadow/DateTimeEditElement.cpp	2012-12-06 06:36:23 UTC (rev 136807)
+++ trunk/Source/WebCore/html/shadow/DateTimeEditElement.cpp	2012-12-06 07:10:22 UTC (rev 136808)
@@ -33,10 +33,13 @@
 #include "DateTimeFormat.h"
 #include "DateTimeSymbolicFieldElement.h"
 #include "EventHandler.h"
+#include "FontCache.h"
 #include "HTMLNames.h"
 #include "KeyboardEvent.h"
 #include "MouseEvent.h"
 #include "PlatformLocale.h"
+#include "RenderStyle.h"
+#include "StyleResolver.h"
 #include "Text.h"
 #include <wtf/DateMath.h>
 #include <wtf/text/StringBuilder.h>
@@ -301,6 +304,7 @@
 {
     DEFINE_STATIC_LOCAL(AtomicString, dateTimeEditPseudoId, ("-webkit-datetime-edit", AtomicString::ConstructFromLiteral));
     setPseudo(dateTimeEditPseudoId);
+    setHasCustomCallbacks();
 }
 
 DateTimeEditElement::~DateTimeEditElement()
@@ -338,6 +342,31 @@
     return container.release();
 }
 
+PassRefPtr<RenderStyle> DateTimeEditElement::customStyleForRenderer()
+{
+    // FIXME: This is a kind of layout. We might want to introduce new renderer.
+    FontCachePurgePreventer fontCachePurgePreventer;
+    RefPtr<RenderStyle> originalStyle = document()->styleResolver()->styleForElement(this);
+    RefPtr<RenderStyle> style = RenderStyle::clone(originalStyle.get());
+    float width = 0;
+    for (Node* child = firstChild(); child; child = child->nextSibling()) {
+        if (!child->isElementNode())
+            continue;
+        Element* childElement = toElement(child);
+        if (childElement->isDateTimeFieldElement()) {
+            // We need to pass the Font of this element because child elements
+            // can't resolve inherited style at this timing.
+            width += static_cast<DateTimeFieldElement*>(childElement)->maximumWidth(style->font());
+        } else {
+            // ::-webkit-datetime-edit-text case. It has no
+            // border/padding/margin in html.css.
+            width += style->font().width(childElement->textContent());
+        }
+    }
+    style->setMinWidth(Length(ceilf(width), Fixed));
+    return style.release();
+}
+
 void DateTimeEditElement::didBlurFromField()
 {
     if (m_editControlOwner)

Modified: trunk/Source/WebCore/html/shadow/DateTimeEditElement.h (136807 => 136808)


--- trunk/Source/WebCore/html/shadow/DateTimeEditElement.h	2012-12-06 06:36:23 UTC (rev 136807)
+++ trunk/Source/WebCore/html/shadow/DateTimeEditElement.h	2012-12-06 07:10:22 UTC (rev 136808)
@@ -130,6 +130,9 @@
     void layout(const LayoutParameters&, const DateComponents&);
     void updateUIState();
 
+    // Element function.
+    virtual PassRefPtr<RenderStyle> customStyleForRenderer() OVERRIDE;
+
     // DateTimeFieldElement::FieldOwner functions.
     virtual void didBlurFromField() OVERRIDE FINAL;
     virtual void didFocusOnField() OVERRIDE FINAL;

Modified: trunk/Source/WebCore/html/shadow/DateTimeFieldElement.cpp (136807 => 136808)


--- trunk/Source/WebCore/html/shadow/DateTimeFieldElement.cpp	2012-12-06 06:36:23 UTC (rev 136807)
+++ trunk/Source/WebCore/html/shadow/DateTimeFieldElement.cpp	2012-12-06 07:10:22 UTC (rev 136808)
@@ -144,6 +144,11 @@
     appendChild(Text::create(document(), visibleValue()));
 }
 
+bool DateTimeFieldElement::isDateTimeFieldElement() const
+{
+    return true;
+}
+
 bool DateTimeFieldElement::isFocusable() const
 {
     if (isReadOnly())
@@ -168,6 +173,12 @@
     return m_fieldOwner ? m_fieldOwner->localeIdentifier() : nullAtom;
 }
 
+float DateTimeFieldElement::maximumWidth(const Font&)
+{
+    const float paddingLeftAndRight = 2; // This should match to html.css.
+    return paddingLeftAndRight;
+}
+
 void DateTimeFieldElement::setReadOnly()
 {
     // Set HTML attribute readonly to change apperance.

Modified: trunk/Source/WebCore/html/shadow/DateTimeFieldElement.h (136807 => 136808)


--- trunk/Source/WebCore/html/shadow/DateTimeFieldElement.h	2012-12-06 06:36:23 UTC (rev 136807)
+++ trunk/Source/WebCore/html/shadow/DateTimeFieldElement.h	2012-12-06 07:10:22 UTC (rev 136808)
@@ -34,6 +34,7 @@
 
 class DateComponents;
 class DateTimeFieldsState;
+class Font;
 
 // DateTimeFieldElement is base class of date time field element.
 class DateTimeFieldElement : public HTMLElement {
@@ -62,6 +63,7 @@
     virtual void defaultEventHandler(Event*) OVERRIDE;
     virtual bool hasValue() const = 0;
     bool isReadOnly() const;
+    virtual float maximumWidth(const Font&);
     virtual void populateDateTimeFieldsState(DateTimeFieldsState&) = 0;
     void removeEventHandler() { m_fieldOwner = 0; }
     void setReadOnly();
@@ -89,6 +91,7 @@
 
 private:
     void defaultKeyboardEventHandler(KeyboardEvent*);
+    virtual bool isDateTimeFieldElement() const OVERRIDE;
     virtual bool isFocusable() const OVERRIDE FINAL;
     bool isRTL() const;
     virtual bool supportsFocus() const OVERRIDE FINAL;

Modified: trunk/Source/WebCore/html/shadow/DateTimeNumericFieldElement.cpp (136807 => 136808)


--- trunk/Source/WebCore/html/shadow/DateTimeNumericFieldElement.cpp	2012-12-06 06:36:23 UTC (rev 136807)
+++ trunk/Source/WebCore/html/shadow/DateTimeNumericFieldElement.cpp	2012-12-06 07:10:22 UTC (rev 136808)
@@ -27,14 +27,13 @@
 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
 #include "DateTimeNumericFieldElement.h"
 
-#include "FontCache.h"
+#include "Font.h"
 #include "KeyboardEvent.h"
 #include "PlatformLocale.h"
-#include "RenderStyle.h"
-#include "StyleResolver.h"
-#include "TextRun.h"
 #include <wtf/text/StringBuilder.h>
 
+using namespace WTF::Unicode;
+
 namespace WebCore {
 
 static const DOMTimeStamp typeAheadTimeout = 1000;
@@ -66,7 +65,19 @@
     , m_value(0)
     , m_hasValue(false)
 {
-    setHasCustomCallbacks();
+    // We show a direction-neutral string such as "--" as a placeholder. It
+    // should follow the direction of numeric values.
+    if (localeForOwner().isRTL()) {
+        Direction dir = direction(formatValue(this->maximum())[0]);
+        if (dir == LeftToRight || dir == EuropeanNumber || dir == ArabicNumber) {
+            StringBuilder builder;
+            builder.reserveCapacity(m_placeholder.length() + 2);
+            builder.append(leftToRightMark);
+            builder.append(m_placeholder);
+            builder.append(rightToLeftMark);
+            m_placeholder = builder.toString();
+        }
+    }
 }
 
 int DateTimeNumericFieldElement::clampValueForHardLimits(int value) const
@@ -74,16 +85,12 @@
     return clampValue(value);
 }
 
-PassRefPtr<RenderStyle> DateTimeNumericFieldElement::customStyleForRenderer()
+float DateTimeNumericFieldElement::maximumWidth(const Font& font)
 {
-    FontCachePurgePreventer fontCachePurgePreventer;
-    RefPtr<RenderStyle> originalStyle = document()->styleResolver()->styleForElement(this);
-    RefPtr<RenderStyle> style = RenderStyle::clone(originalStyle.get());
-    float maximumWidth = style->font().width(m_placeholder);
-    maximumWidth = std::max(maximumWidth, style->font().width(formatValue(maximum())));
-    maximumWidth = std::max(maximumWidth, style->font().width(value()));
-    style->setMinWidth(Length(maximumWidth, Fixed));
-    return style.release();
+    float maximumWidth = font.width(m_placeholder);
+    maximumWidth = std::max(maximumWidth, font.width(formatValue(maximum())));
+    maximumWidth = std::max(maximumWidth, font.width(value()));
+    return maximumWidth + DateTimeFieldElement::maximumWidth(font);
 }
 
 int DateTimeNumericFieldElement::defaultValueForStepDown() const

Modified: trunk/Source/WebCore/html/shadow/DateTimeNumericFieldElement.h (136807 => 136808)


--- trunk/Source/WebCore/html/shadow/DateTimeNumericFieldElement.h	2012-12-06 06:36:23 UTC (rev 136807)
+++ trunk/Source/WebCore/html/shadow/DateTimeNumericFieldElement.h	2012-12-06 07:10:22 UTC (rev 136808)
@@ -68,12 +68,10 @@
     virtual String visibleValue() const OVERRIDE FINAL;
 
 private:
-    // Element function.
-    virtual PassRefPtr<RenderStyle> customStyleForRenderer() OVERRIDE;
-
     // DateTimeFieldElement functions.
     virtual void didBlur() OVERRIDE FINAL;
     virtual void handleKeyboardEvent(KeyboardEvent*) OVERRIDE FINAL;
+    virtual float maximumWidth(const Font&) OVERRIDE;
     virtual int minimum() const OVERRIDE FINAL;
     virtual void stepDown() OVERRIDE FINAL;
     virtual void stepUp() OVERRIDE FINAL;
@@ -83,7 +81,7 @@
     Locale& localeForOwner() const;
 
     DOMTimeStamp m_lastDigitCharTime;
-    const String m_placeholder;
+    String m_placeholder;
     const Range m_range;
     int m_value;
     bool m_hasValue;

Modified: trunk/Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.cpp (136807 => 136808)


--- trunk/Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.cpp	2012-12-06 06:36:23 UTC (rev 136807)
+++ trunk/Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.cpp	2012-12-06 07:10:22 UTC (rev 136808)
@@ -27,12 +27,9 @@
 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
 #include "DateTimeSymbolicFieldElement.h"
 
-#include "FontCache.h"
+#include "Font.h"
 #include "KeyboardEvent.h"
-#include "RenderStyle.h"
-#include "StyleResolver.h"
 #include "TextBreakIterator.h"
-#include "TextRun.h"
 #include <wtf/text/StringBuilder.h>
 #include <wtf/unicode/Unicode.h>
 
@@ -58,19 +55,14 @@
     , m_typeAhead(this)
 {
     ASSERT(!symbols.isEmpty());
-    setHasCustomCallbacks();
 }
 
-PassRefPtr<RenderStyle> DateTimeSymbolicFieldElement::customStyleForRenderer()
+float DateTimeSymbolicFieldElement::maximumWidth(const Font& font)
 {
-    FontCachePurgePreventer fontCachePurgePreventer;
-    RefPtr<RenderStyle> originalStyle = document()->styleResolver()->styleForElement(this);
-    RefPtr<RenderStyle> style = RenderStyle::clone(originalStyle.get());
-    float maximumWidth = style->font().width(visibleEmptyValue());
+    float maximumWidth = font.width(visibleEmptyValue());
     for (unsigned index = 0; index < m_symbols.size(); ++index)
-        maximumWidth = std::max(maximumWidth, style->font().width(m_symbols[index]));
-    style->setMinWidth(Length(maximumWidth, Fixed));
-    return style.release();
+        maximumWidth = std::max(maximumWidth, font.width(m_symbols[index]));
+    return maximumWidth + DateTimeFieldElement::maximumWidth(font);
 }
 
 void DateTimeSymbolicFieldElement::handleKeyboardEvent(KeyboardEvent* keyboardEvent)

Modified: trunk/Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.h (136807 => 136808)


--- trunk/Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.h	2012-12-06 06:36:23 UTC (rev 136807)
+++ trunk/Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.h	2012-12-06 07:10:22 UTC (rev 136808)
@@ -48,12 +48,12 @@
 private:
     static const int invalidIndex = -1;
 
-    virtual PassRefPtr<RenderStyle> customStyleForRenderer() OVERRIDE FINAL;
     String visibleEmptyValue() const;
 
     // DateTimeFieldElement functions.
     virtual void handleKeyboardEvent(KeyboardEvent*) OVERRIDE FINAL;
     virtual int maximum() const OVERRIDE FINAL;
+    virtual float maximumWidth(const Font&) OVERRIDE;
     virtual int minimum() const OVERRIDE FINAL;
     virtual void stepDown() OVERRIDE FINAL;
     virtual void stepUp() OVERRIDE FINAL;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to