Bug 45730

Summary: API to support localized numbers for <input type=number>
Product: WebKit Reporter: Kent Tamura <tkent>
Component: FormsAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: adele, ap, darin, dglazkov, eric
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Bug Depends on:    
Bug Blocks: 42484    
Attachments:
Description Flags
Patch
none
Patch 2 (Fix Mac build)
none
Patch 2 (comment update, rebased)
none
Patch rev.4
none
Patch 5 (rebased)
none
Patch 6 (rebased)
none
Patch 7 (rebased)
none
Patch 8 (rebased) none

Description Kent Tamura 2010-09-13 20:30:38 PDT
API to support localized numbers for <input type=number>
Comment 1 Kent Tamura 2010-09-13 20:37:32 PDT
Created attachment 67514 [details]
Patch
Comment 2 Eric Seidel (no email) 2010-09-13 21:01:52 PDT
Attachment 67514 [details] did not build on mac:
Build output: http://queues.webkit.org/results/4042003
Comment 3 Kent Tamura 2010-09-13 21:13:14 PDT
Created attachment 67518 [details]
Patch 2 (Fix Mac build)
Comment 4 Alexey Proskuryakov 2010-09-13 22:08:30 PDT
+// Returns true if the input character can be used to represent a
+// localized number. For example, this should return true for 0-9 . , +
+// - for en-US locale.
+bool isLocalizedNumberCharacter(UChar32);

Should this depend on browser locale, or on page language?
Comment 5 Kent Tamura 2010-09-13 22:46:48 PDT
(In reply to comment #4)
> +// Returns true if the input character can be used to represent a
> +// localized number. For example, this should return true for 0-9 . , +
> +// - for en-US locale.
> +bool isLocalizedNumberCharacter(UChar32);
> 
> Should this depend on browser locale, or on page language?

It should be the same as other functions in this file.  So, it's browser locale.
I'll update the comment.
Comment 6 Kent Tamura 2010-09-13 23:35:01 PDT
Note that I'll add LocalizedNumberICU.cpp after this patch.  Probably Qt needs LocalizedNumberQt.cpp, which uses QLocale, and Mac needs LocalizedNumberMac.mm for NSNumberFormatter?
Comment 7 Kent Tamura 2010-10-08 01:44:54 PDT
Created attachment 70209 [details]
Patch 2 (comment update, rebased)
Comment 8 Dimitri Glazkov (Google) 2010-10-08 09:54:16 PDT
Comment on attachment 70209 [details]
Patch 2 (comment update, rebased)

ok.
Comment 9 Alexey Proskuryakov 2010-10-08 10:27:38 PDT
 static bool isNumberCharacter(UChar ch)
 {
-    return ch == '+' || ch == '-' || ch == '.' || ch == 'e' || ch == 'E'
-        || (ch >= '0' && ch <= '9');
+    return isLocalizedNumberCharacter(ch) || ch == '+' || ch == '-' || ch == '.' || ch == 'e' || ch == 'E' || (ch >= '0' && ch <= '9');
 }

This is confusing. Where does the definition come from? For example, a comment before isLocalizedNumberCharacter() says that it includes both period and comma for U.S. locale. But this only forces period. Why?

+++ b/WebCore/rendering/RenderTextControlSingleLine.cpp
@@ -693,7 +693,7 @@ void RenderTextControlSingleLine::updateFromElement()
                 shouldUpdateValue = static_cast<HTMLTextFormControlElement*>(node())->supportsPlaceholder() || !static_cast<HTMLInputElement*>(node())->formControlValueMatchesRenderer();
             }
             if (shouldUpdateValue)
-                setInnerTextValue(inputElement()->value());
+                setInnerTextValue(inputElement()->visibleValue());
         }

What is this change expected to provide? It seems out of place in a bug that adds an API. ChangeLog comment doesn't explain the reason for this change.

The concept of "visibleValue" in general seems unclear. How is one supposed to perform DOM manipulation if rendered value is different from DOM value? E.g. what if JS code want to select part of the number in the input field?
Comment 10 Alexey Proskuryakov 2010-10-08 10:28:10 PDT
Comment on attachment 70209 [details]
Patch 2 (comment update, rebased)

Marking r- for the sake of ongoing discussion.
Comment 11 Kent Tamura 2010-10-12 00:17:17 PDT
Created attachment 70515 [details]
Patch rev.4
Comment 12 Kent Tamura 2010-10-12 00:23:03 PDT
Thank you for the comments.

(In reply to comment #9)
>  static bool isNumberCharacter(UChar ch)
>  {
> -    return ch == '+' || ch == '-' || ch == '.' || ch == 'e' || ch == 'E'
> -        || (ch >= '0' && ch <= '9');
> +    return isLocalizedNumberCharacter(ch) || ch == '+' || ch == '-' || ch == '.' || ch == 'e' || ch == 'E' || (ch >= '0' && ch <= '9');
>  }
> 
> This is confusing. Where does the definition come from? For example, a comment before isLocalizedNumberCharacter() says that it includes both period and comma for U.S. locale. But this only forces period. Why?

We try to parse a value in a localized number format, and try to parse it in the HTML5 format if the parsing in the localized number format fails.  I added a comment about this to HTMLInputElement::sanitizeValue() and ChangeLog.

> +++ b/WebCore/rendering/RenderTextControlSingleLine.cpp
> @@ -693,7 +693,7 @@ void RenderTextControlSingleLine::updateFromElement()
>                  shouldUpdateValue = static_cast<HTMLTextFormControlElement*>(node())->supportsPlaceholder() || !static_cast<HTMLInputElement*>(node())->formControlValueMatchesRenderer();
>              }
>              if (shouldUpdateValue)
> -                setInnerTextValue(inputElement()->value());
> +                setInnerTextValue(inputElement()->visibleValue());
>          }
> 
> What is this change expected to provide? It seems out of place in a bug that adds an API. ChangeLog comment doesn't explain the reason for this change.
> 
> The concept of "visibleValue" in general seems unclear. How is one supposed to perform DOM manipulation if rendered value is different from DOM value? 

ok, I added an explanation of visibleValue() to ChangeLog.
visibleValue() is a localized representation of a number, and value() (DOM manipulation) is the HTML5 number representation.

> E.g. what if JS code want to select part of the number in the input field?

We can't do it.  HTML5 doesn't provide selection API for type=number.
Comment 13 Kent Tamura 2010-11-01 23:16:57 PDT
Created attachment 72631 [details]
Patch 5 (rebased)
Comment 14 Kent Tamura 2010-11-15 21:31:16 PST
Created attachment 73959 [details]
Patch 6 (rebased)
Comment 15 Kent Tamura 2010-12-06 20:09:02 PST
Created attachment 75777 [details]
Patch 7 (rebased)
Comment 16 WebKit Review Bot 2010-12-06 20:11:54 PST
Attachment 75777 [details] did not pass style-queue:

Failed to run "[u'git', u'reset', u'--hard', u'HEAD']" exit_code: 128
error: git checkout-index: unable to write file LayoutTests/ChangeLog
error: git checkout-index: unable to write file LayoutTests/fast/css/custom-font-xheight.html
error: git checkout-index: unable to write file WebCore/ChangeLog
fatal: Could not reset index file to revision 'HEAD'.


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 17 WebKit Review Bot 2010-12-07 08:27:40 PST
Attachment 75777 [details] did not pass style-queue:

Failed to run "[u'git', u'reset', u'--hard', u'refs/remotes/trunk']" exit_code: 128
error: Could not write new index file.
fatal: Could not reset index file to revision 'refs/remotes/trunk'.


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 18 WebKit Review Bot 2010-12-07 09:29:17 PST
Attachment 75777 [details] did not pass style-queue:

Failed to run "[u'git', u'reset', u'--hard', u'refs/remotes/trunk']" exit_code: 128
error: Could not write new index file.
fatal: Could not reset index file to revision 'refs/remotes/trunk'.


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 19 WebKit Review Bot 2010-12-07 10:30:22 PST
Attachment 75777 [details] did not pass style-queue:

Failed to run "[u'git', u'reset', u'--hard', u'refs/remotes/trunk']" exit_code: 128
error: Could not write new index file.
fatal: Could not reset index file to revision 'refs/remotes/trunk'.


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 20 WebKit Review Bot 2010-12-07 11:31:30 PST
Attachment 75777 [details] did not pass style-queue:

Failed to run "[u'git', u'reset', u'--hard', u'refs/remotes/trunk']" exit_code: 128
error: Could not write new index file.
fatal: Could not reset index file to revision 'refs/remotes/trunk'.


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 21 WebKit Review Bot 2010-12-07 12:32:56 PST
Attachment 75777 [details] did not pass style-queue:

Failed to run "[u'git', u'reset', u'--hard', u'refs/remotes/trunk']" exit_code: 128
error: Could not write new index file.
fatal: Could not reset index file to revision 'refs/remotes/trunk'.


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 22 WebKit Review Bot 2010-12-07 21:29:41 PST
Attachment 75777 [details] did not pass style-queue:

Failed to run "['WebKitTools/Scripts/update-webkit']" exit_code: 2
Updating OpenSource
Incomplete data: Delta source ended unexpectedly at /usr/lib/git-core/git-svn line 5061

Died at WebKitTools/Scripts/update-webkit line 132.


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 23 Kent Tamura 2010-12-14 15:49:16 PST
Ping.
ap, dglazkov, would you take a look at the patch please?
Comment 24 Kent Tamura 2011-01-05 23:29:45 PST
Created attachment 78100 [details]
Patch 8 (rebased)
Comment 25 Dimitri Glazkov (Google) 2011-01-25 18:26:25 PST
Comment on attachment 78100 [details]
Patch 8 (rebased)

ok.
Comment 26 Kent Tamura 2011-01-25 19:47:05 PST
Landed: http://trac.webkit.org/changeset/76661