Title: [127398] trunk/Source/WebCore
Revision
127398
Author
[email protected]
Date
2012-09-02 21:03:19 -0700 (Sun, 02 Sep 2012)

Log Message

[Forms] AM/PM field of multiple fields time input UI should be fixed width
https://bugs.webkit.org/show_bug.cgi?id=95542

Reviewed by Kent Tamura.

This patch changes width of AM/PM field of multiple field time input
UI fixed as maximum width of labels or "--".

This patch affects ports which enable both ENABLE_INPUT_TYPE_TIME and
ENABLE_INPUT_TYPE_TIME_MULTIPLE_FIELDS.

No new tests. Once multiple field time input UI uses "lang" HTML
attribute to take time format, we can write a test for this patch.

* css/html.css:
(input::-webkit-datetime-edit-ampm-field): Added "display" property to "inline-block" for setting width.
Added "text-align" property to "center".
* html/shadow/DateTimeSymbolicFieldElement.cpp:
(WebCore::DateTimeSymbolicFieldElement::DateTimeSymbolicFieldElement): Changed to call setHasCustomCallback().
(WebCore::DateTimeSymbolicFieldElement::customStyleForRenderer): Added for setting field with from maximum width of labels.
* html/shadow/DateTimeSymbolicFieldElement.h:
(WebCore::DateTimeSymbolicFieldElement::visibleEmptyValue): Added for using visible empty value in customStyleForRenderer() and visibleValue().
(WebCore::DateTimeSymbolicFieldElement::visibleValue): Changed to call visibleEmptyValue() instead of using literal "--".
(DateTimeSymbolicFieldElement): Added a declaration of customStyleForRenderer().

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (127397 => 127398)


--- trunk/Source/WebCore/ChangeLog	2012-09-03 02:04:14 UTC (rev 127397)
+++ trunk/Source/WebCore/ChangeLog	2012-09-03 04:03:19 UTC (rev 127398)
@@ -1,3 +1,30 @@
+2012-09-02  Yoshifumi Inoue  <[email protected]>
+
+        [Forms] AM/PM field of multiple fields time input UI should be fixed width
+        https://bugs.webkit.org/show_bug.cgi?id=95542
+
+        Reviewed by Kent Tamura.
+
+        This patch changes width of AM/PM field of multiple field time input
+        UI fixed as maximum width of labels or "--".
+
+        This patch affects ports which enable both ENABLE_INPUT_TYPE_TIME and
+        ENABLE_INPUT_TYPE_TIME_MULTIPLE_FIELDS.
+
+        No new tests. Once multiple field time input UI uses "lang" HTML
+        attribute to take time format, we can write a test for this patch.
+
+        * css/html.css:
+        (input::-webkit-datetime-edit-ampm-field): Added "display" property to "inline-block" for setting width.
+        Added "text-align" property to "center".
+        * html/shadow/DateTimeSymbolicFieldElement.cpp:
+        (WebCore::DateTimeSymbolicFieldElement::DateTimeSymbolicFieldElement): Changed to call setHasCustomCallback().
+        (WebCore::DateTimeSymbolicFieldElement::customStyleForRenderer): Added for setting field with from maximum width of labels.
+        * html/shadow/DateTimeSymbolicFieldElement.h:
+        (WebCore::DateTimeSymbolicFieldElement::visibleEmptyValue): Added for using visible empty value in customStyleForRenderer() and visibleValue().
+        (WebCore::DateTimeSymbolicFieldElement::visibleValue): Changed to call visibleEmptyValue() instead of using literal "--".
+        (DateTimeSymbolicFieldElement): Added a declaration of customStyleForRenderer().
+
 2012-09-02  Benjamin Poulain  <[email protected]>
 
         Improve the way we use convertedSpaceString() in convertHTMLTextToInterchangeFormat()

Modified: trunk/Source/WebCore/css/html.css (127397 => 127398)


--- trunk/Source/WebCore/css/html.css	2012-09-03 02:04:14 UTC (rev 127397)
+++ trunk/Source/WebCore/css/html.css	2012-09-03 04:03:19 UTC (rev 127398)
@@ -491,6 +491,8 @@
     -webkit-user-modify: read-only !important;
     border: none;
     padding: 0.15em;
+    display: inline-block;
+    text-align: center;
 }
 
 input::-webkit-datetime-edit-hour-field {

Modified: trunk/Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.cpp (127397 => 127398)


--- trunk/Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.cpp	2012-09-03 02:04:14 UTC (rev 127397)
+++ trunk/Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.cpp	2012-09-03 04:03:19 UTC (rev 127398)
@@ -27,7 +27,11 @@
 #if ENABLE(INPUT_TYPE_TIME_MULTIPLE_FIELDS)
 #include "DateTimeSymbolicFieldElement.h"
 
+#include "FontCache.h"
 #include "KeyboardEvent.h"
+#include "RenderStyle.h"
+#include "StyleResolver.h"
+#include "TextRun.h"
 #include <wtf/unicode/Unicode.h>
 
 namespace WebCore {
@@ -38,8 +42,21 @@
     , m_selectedIndex(-1)
 {
     ASSERT(!symbols.isEmpty());
+    setHasCustomCallbacks();
 }
 
+PassRefPtr<RenderStyle> DateTimeSymbolicFieldElement::customStyleForRenderer()
+{
+    FontCachePurgePreventer fontCachePurgePreventer;
+    RefPtr<RenderStyle> originalStyle = document()->styleResolver()->styleForElement(this);
+    RefPtr<RenderStyle> style = RenderStyle::clone(originalStyle.get());
+    float maxiumWidth = style->font().width(visibleEmptyValue());
+    for (unsigned index = 0; index < m_symbols.size(); ++index)
+        maxiumWidth = std::max(maxiumWidth, style->font().width(m_symbols[index]));
+    style->setWidth(Length(maxiumWidth, Fixed));
+    return style.release();
+}
+
 void DateTimeSymbolicFieldElement::handleKeyboardEvent(KeyboardEvent* keyboardEvent)
 {
     if (keyboardEvent->type() != eventNames().keypressEvent)
@@ -98,9 +115,15 @@
     return m_selectedIndex;
 }
 
+String DateTimeSymbolicFieldElement::visibleEmptyValue() const
+{
+    // FIXME: Number of dashs should be maximum length of labels.
+    return "--";
+}
+
 String DateTimeSymbolicFieldElement::visibleValue() const
 {
-    return hasValue() ? m_symbols[m_selectedIndex] : "--";
+    return hasValue() ? m_symbols[m_selectedIndex] : visibleEmptyValue();
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.h (127397 => 127398)


--- trunk/Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.h	2012-09-03 02:04:14 UTC (rev 127397)
+++ trunk/Source/WebCore/html/shadow/DateTimeSymbolicFieldElement.h	2012-09-03 04:03:19 UTC (rev 127398)
@@ -43,6 +43,9 @@
 private:
     static const int invalidIndex = -1;
 
+    virtual PassRefPtr<RenderStyle> customStyleForRenderer() OVERRIDE FINAL;
+    String visibleEmptyValue() const;
+
     // DateTimeFieldElement functions.
     virtual void handleKeyboardEvent(KeyboardEvent*) OVERRIDE FINAL;
     virtual bool hasValue() const OVERRIDE FINAL;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to