diff options
author | tkent@chromium.org <tkent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-25 05:37:37 +0000 |
---|---|---|
committer | tkent@chromium.org <tkent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-25 05:37:37 +0000 |
commit | 8ef5716c097776a9ae5c93e895c0effe7695a985 (patch) | |
tree | 197a96d2fdcf0ffcd0e90f205222b877b14506e5 | |
parent | 7fb865207d11400bc69b15fef20c5e4826c221c2 (diff) | |
download | chromium_src-8ef5716c097776a9ae5c93e895c0effe7695a985.zip chromium_src-8ef5716c097776a9ae5c93e895c0effe7695a985.tar.gz chromium_src-8ef5716c097776a9ae5c93e895c0effe7695a985.tar.bz2 |
Add form validation message strings.
* webkit/glue/
- Add overloads of queryLocalizedString() functions
They will be added to WebKit::WebKitClient later.
- Add implementations for WebLocalizedString::Validation*
- Add message strings
The English strings are different from WebKit's to avoid the brusque
WebKit's strings.
Port some messages from Mozilla.
* webkit/tools/test_shell/ and webkit/support/
Hook queryLocalizedString() functions in order to return messages same as
WebKit in layout test.
BUG=28264
TEST=LayoutTests/fast/forms/validationMessage.html
Review URL: http://codereview.chromium.org/4678006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67382 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | webkit/glue/webkit_strings.grd | 87 | ||||
-rw-r--r-- | webkit/glue/webkitclient_impl.cc | 58 | ||||
-rw-r--r-- | webkit/glue/webkitclient_impl.h | 5 | ||||
-rw-r--r-- | webkit/support/test_webkit_client.cc | 52 | ||||
-rw-r--r-- | webkit/support/test_webkit_client.h | 7 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_webkit_init.cc | 51 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_webkit_init.h | 7 |
7 files changed, 260 insertions, 7 deletions
diff --git a/webkit/glue/webkit_strings.grd b/webkit/glue/webkit_strings.grd index 9335199..651acf0 100644 --- a/webkit/glue/webkit_strings.grd +++ b/webkit/glue/webkit_strings.grd @@ -297,6 +297,93 @@ below: 1024 (Medium Grade) </message> + <message name="IDS_FORM_VALIDATION_VALUE_MISSING_MULTIPLE_FILE" desc="Heading or short sentence shown when a file upload control in a web page requires one or more files selected, but the user didn't specify any files."> + Please select one or more files. + </message> + <message name="IDS_FORM_VALIDATION_TYPE_MISMATCH" desc="Heading or short sentence shown when a form control in a web page requires specific type such as email address or URL, but the specified value does not comform to the type."> + Invalid value. + </message> + <message name="IDS_FORM_VALIDATION_TYPE_MISMATCH_MULTIPLE_EMAIL" desc="Heading or short sentence shown there is a field which accepts multiple e-mail addresses and a user specified a value which is not a comma-separated e-mail addresses."> + Please enter a comma separated list of email addresses. + </message> + <message name="IDS_FORM_VALIDATION_RANGE_UNDERFLOW" desc="Heading or short sentence shown when a form control value in a web page needs to be larger than or equal to a minimum value specified by the page author, but a user specified a too small value."> + Value must be greater than or equal to <ph name="MINIMUM">$1<ex>0</ex></ph>. + </message> + <message name="IDS_FORM_VALIDATION_RANGE_OVERFLOW" desc="Heading or short sentence shown when a form control value in a web page needs to be smaller than or equal to a maximum value specified by the page author, but a user specified a too large value."> + Value must be less than or equal to <ph name="MAXIMUM">$1<ex>100</ex></ph>. + </message> + <message name="IDS_FORM_VALIDATION_STEP_MISMATCH" desc="Heading or short sentence shown when a form control value in a web page should be aligned to a step value specified by the page author, but a user speficified non-aligned value. e.g. A number type field, minimum value is 0, and step value is 4. If A user-specified value is not a multiple of 4, this warning message is shown."> + Invalid value. + </message> + +<!-- The following IDS_FORM_VALIDATION_* messages were taken from Mozilla's dom.properties file. + +# ***** BEGIN LICENSE BLOCK ***** +# Version: MPL 1.1/GPL 2.0/LGPL 2.1 +# +# The contents of this file are subject to the Mozilla Public License Version +# 1.1 (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +# for the specific language governing rights and limitations under the +# License. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is +# Netscape Communications Corporation. +# Portions created by the Initial Developer are Copyright (C) 2001 +# the Initial Developer. All Rights Reserved. +# +# Contributor(s): +# Mitch <mstoltz@netscape.com> (original author) +# Ehsan Akhgari <ehsan.akhgari@gmail.com> +# +# Alternatively, the contents of this file may be used under the terms of +# either of the GNU General Public License Version 2 or later (the "GPL"), +# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), +# in which case the provisions of the GPL or the LGPL are applicable instead +# of those above. If you wish to allow use of your version of this file only +# under the terms of either the GPL or the LGPL, and not to allow others to +# use your version of this file under the terms of the MPL, indicate your +# decision by deleting the provisions above and replace them with the notice +# and other provisions required by the GPL or the LGPL. If you do not delete +# the provisions above, a recipient may use your version of this file under +# the terms of any one of the MPL, the GPL or the LGPL. +# +# ***** END LICENSE BLOCK ***** +--> + <message name="IDS_FORM_VALIDATION_VALUE_MISSING" desc="Heading or short sentence shown when a text form control in a web page requires a value, but the user didn't specify any value."> + Please fill out this field. + </message> + <message name="IDS_FORM_VALIDATION_VALUE_MISSING_CHECKBOX" desc="Heading or short sentence shown when a checkbox control in a web page requires to be checked, but the user didn't check it."> + Please check this box if you want to proceed. + </message> + <message name="IDS_FORM_VALIDATION_VALUE_MISSING_FILE" desc="Heading or short sentence shown when a file upload control in a web page requires a file selected, but the user didn't specify any file."> + Please select a file. + </message> + <message name="IDS_FORM_VALIDATION_VALUE_MISSING_RADIO" desc="Heading or short sentence shown when a radio button of a radio button group in a web page requires to be selected, but the user selected nothing."> + Please select one of these options. + </message> + <message name="IDS_FORM_VALIDATION_VALUE_MISSING_SELECT" desc="Heading or short sentence shown when a value of a menu-list control in a web page requires to be selected, but the user selected nothing."> + Please select an item in the list. + </message> + <message name="IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL" desc="Heading or short sentence shown when there is an email field in a form and a user specified a value which doesn't look like an e-mail address."> + Please enter an email address. + </message> + <message name="IDS_FORM_VALIDATION_TYPE_MISMATCH_URL" desc="Heading or short sentence shown when there is a URL field in a form and a user specified a value which doesn't look like a URL."> + Please enter a URL. + </message> + <message name="IDS_FORM_VALIDATION_PATTERN_MISMATCH" desc="Heading or short sentence shown when a form control value needs to satisfy a pattern specified by the page author, but a user specified unmatched value."> + Please match the requested format. + </message> + <message name="IDS_FORM_VALIDATION_TOO_LONG" desc="Heading or short sentence shown when a form control in a web page needs to be shoter than a length specified by the page author, but a user specified long value."> + Please shorten this text to <ph name="MAX_CHARACTERS">$2<ex>100</ex></ph> characters or less (you are currently using <ph name="CURRENT_LENGTH">$1<ex>101</ex></ph> characters). + </message> + <message name="IDS_DEFAULT_PLUGIN_GET_PLUGIN_MSG" desc="Message displayed by the default plugin in its main window"> <ph name="PLUGIN">$1<ex>Realplayer</ex></ph> plug-in is not installed </message> diff --git a/webkit/glue/webkitclient_impl.cc b/webkit/glue/webkitclient_impl.cc index 0c5766a..a992355 100644 --- a/webkit/glue/webkitclient_impl.cc +++ b/webkit/glue/webkitclient_impl.cc @@ -156,10 +156,36 @@ static int ToMessageID(WebLocalizedString::Name name) { return IDS_KEYGEN_HIGH_GRADE_KEY; case WebLocalizedString::KeygenMenuMediumGradeKeySize: return IDS_KEYGEN_MED_GRADE_KEY; - // TODO(tkent): Remove default: when we merge the next - // WebLocalizedString.h change. - default: - break; + case WebLocalizedString::ValidationValueMissing: + return IDS_FORM_VALIDATION_VALUE_MISSING; + case WebLocalizedString::ValidationValueMissingForCheckbox: + return IDS_FORM_VALIDATION_VALUE_MISSING_CHECKBOX; + case WebLocalizedString::ValidationValueMissingForFile: + return IDS_FORM_VALIDATION_VALUE_MISSING_FILE; + case WebLocalizedString::ValidationValueMissingForMultipleFile: + return IDS_FORM_VALIDATION_VALUE_MISSING_MULTIPLE_FILE; + case WebLocalizedString::ValidationValueMissingForRadio: + return IDS_FORM_VALIDATION_VALUE_MISSING_RADIO; + case WebLocalizedString::ValidationValueMissingForSelect: + return IDS_FORM_VALIDATION_VALUE_MISSING_SELECT; + case WebLocalizedString::ValidationTypeMismatch: + return IDS_FORM_VALIDATION_TYPE_MISMATCH; + case WebLocalizedString::ValidationTypeMismatchForEmail: + return IDS_FORM_VALIDATION_TYPE_MISMATCH_EMAIL; + case WebLocalizedString::ValidationTypeMismatchForMultipleEmail: + return IDS_FORM_VALIDATION_TYPE_MISMATCH_MULTIPLE_EMAIL; + case WebLocalizedString::ValidationTypeMismatchForURL: + return IDS_FORM_VALIDATION_TYPE_MISMATCH_URL; + case WebLocalizedString::ValidationPatternMismatch: + return IDS_FORM_VALIDATION_PATTERN_MISMATCH; + case WebLocalizedString::ValidationTooLong: + return IDS_FORM_VALIDATION_TOO_LONG; + case WebLocalizedString::ValidationRangeUnderflow: + return IDS_FORM_VALIDATION_RANGE_UNDERFLOW; + case WebLocalizedString::ValidationRangeOverflow: + return IDS_FORM_VALIDATION_RANGE_OVERFLOW; + case WebLocalizedString::ValidationStepMismatch: + return IDS_FORM_VALIDATION_STEP_MISMATCH; } return -1; } @@ -311,12 +337,30 @@ WebString WebKitClientImpl::queryLocalizedString( WebString WebKitClientImpl::queryLocalizedString( WebLocalizedString::Name name, int numeric_value) { + return queryLocalizedString(name, base::IntToString16(numeric_value)); +} + +WebString WebKitClientImpl::queryLocalizedString( + WebLocalizedString::Name name, const WebString& value) { + int message_id = ToMessageID(name); + if (message_id < 0) + return WebString(); + return ReplaceStringPlaceholders(GetLocalizedString(message_id), value, NULL); +} + +WebString WebKitClientImpl::queryLocalizedString( + WebLocalizedString::Name name, + const WebString& value1, + const WebString& value2) { int message_id = ToMessageID(name); if (message_id < 0) return WebString(); - return ReplaceStringPlaceholders(GetLocalizedString(message_id), - base::IntToString16(numeric_value), - NULL); + std::vector<string16> values; + values.reserve(2); + values.push_back(value1); + values.push_back(value2); + return ReplaceStringPlaceholders( + GetLocalizedString(message_id), values, NULL); } double WebKitClientImpl::currentTime() { diff --git a/webkit/glue/webkitclient_impl.h b/webkit/glue/webkitclient_impl.h index 68d0eaf..3061548 100644 --- a/webkit/glue/webkitclient_impl.h +++ b/webkit/glue/webkitclient_impl.h @@ -52,6 +52,11 @@ class WebKitClientImpl : public WebKit::WebKitClient { WebKit::WebLocalizedString::Name name); virtual WebKit::WebString queryLocalizedString( WebKit::WebLocalizedString::Name name, int numeric_value); + virtual WebKit::WebString queryLocalizedString( + WebKit::WebLocalizedString::Name name, const WebKit::WebString& value); + virtual WebKit::WebString queryLocalizedString( + WebKit::WebLocalizedString::Name name, + const WebKit::WebString& value1, const WebKit::WebString& value2); virtual void suddenTerminationChanged(bool enabled) { } virtual double currentTime(); virtual void setSharedTimerFiredFunction(void (*func)()); diff --git a/webkit/support/test_webkit_client.cc b/webkit/support/test_webkit_client.cc index 5c46cf8..e45c263 100644 --- a/webkit/support/test_webkit_client.cc +++ b/webkit/support/test_webkit_client.cc @@ -247,6 +247,58 @@ WebKit::WebData TestWebKitClient::loadResource(const char* name) { return webkit_glue::WebKitClientImpl::loadResource(name); } +WebKit::WebString TestWebKitClient::queryLocalizedString( + WebKit::WebLocalizedString::Name name) { + // Returns messages same as WebKit's in DRT. + // We use different strings for form validation messages. + switch (name) { + case WebKit::WebLocalizedString::ValidationValueMissing: + case WebKit::WebLocalizedString::ValidationValueMissingForCheckbox: + case WebKit::WebLocalizedString::ValidationValueMissingForFile: + case WebKit::WebLocalizedString::ValidationValueMissingForMultipleFile: + case WebKit::WebLocalizedString::ValidationValueMissingForRadio: + case WebKit::WebLocalizedString::ValidationValueMissingForSelect: + return ASCIIToUTF16("value missing"); + case WebKit::WebLocalizedString::ValidationTypeMismatch: + case WebKit::WebLocalizedString::ValidationTypeMismatchForEmail: + case WebKit::WebLocalizedString::ValidationTypeMismatchForMultipleEmail: + case WebKit::WebLocalizedString::ValidationTypeMismatchForURL: + return ASCIIToUTF16("type mismatch"); + case WebKit::WebLocalizedString::ValidationPatternMismatch: + return ASCIIToUTF16("pattern mismatch"); + case WebKit::WebLocalizedString::ValidationTooLong: + return ASCIIToUTF16("too long"); + case WebKit::WebLocalizedString::ValidationRangeUnderflow: + return ASCIIToUTF16("range underflow"); + case WebKit::WebLocalizedString::ValidationRangeOverflow: + return ASCIIToUTF16("range overflow"); + case WebKit::WebLocalizedString::ValidationStepMismatch: + return ASCIIToUTF16("step mismatch"); + default: + return WebKitClientImpl::queryLocalizedString(name); + } +} + +WebKit::WebString TestWebKitClient::queryLocalizedString( + WebKit::WebLocalizedString::Name name, const WebKit::WebString& value) { + if (name == WebKit::WebLocalizedString::ValidationRangeUnderflow) + return ASCIIToUTF16("range underflow"); + if (name == WebKit::WebLocalizedString::ValidationRangeOverflow) + return ASCIIToUTF16("range overflow"); + return WebKitClientImpl::queryLocalizedString(name, value); +} + +WebKit::WebString TestWebKitClient::queryLocalizedString( + WebKit::WebLocalizedString::Name name, + const WebKit::WebString& value1, + const WebKit::WebString& value2) { + if (name == WebKit::WebLocalizedString::ValidationTooLong) + return ASCIIToUTF16("too long"); + if (name == WebKit::WebLocalizedString::ValidationStepMismatch) + return ASCIIToUTF16("step mismatch"); + return WebKitClientImpl::queryLocalizedString(name, value1, value2); +} + WebKit::WebString TestWebKitClient::defaultLocale() { return ASCIIToUTF16("en-US"); } diff --git a/webkit/support/test_webkit_client.h b/webkit/support/test_webkit_client.h index 6f1d28d..07beae7 100644 --- a/webkit/support/test_webkit_client.h +++ b/webkit/support/test_webkit_client.h @@ -47,6 +47,13 @@ class TestWebKitClient : public webkit_glue::WebKitClientImpl { virtual void prefetchHostName(const WebKit::WebString&); virtual WebKit::WebURLLoader* createURLLoader(); virtual WebKit::WebData loadResource(const char* name); + virtual WebKit::WebString queryLocalizedString( + WebKit::WebLocalizedString::Name name); + virtual WebKit::WebString queryLocalizedString( + WebKit::WebLocalizedString::Name name, const WebKit::WebString& value); + virtual WebKit::WebString queryLocalizedString( + WebKit::WebLocalizedString::Name name, + const WebKit::WebString& value1, const WebKit::WebString& value2); virtual WebKit::WebString defaultLocale(); virtual WebKit::WebStorageNamespace* createLocalStorageNamespace( const WebKit::WebString& path, unsigned quota); diff --git a/webkit/tools/test_shell/test_shell_webkit_init.cc b/webkit/tools/test_shell/test_shell_webkit_init.cc index ba56202..f08c86a 100644 --- a/webkit/tools/test_shell/test_shell_webkit_init.cc +++ b/webkit/tools/test_shell/test_shell_webkit_init.cc @@ -119,3 +119,54 @@ WebKit::WebData TestShellWebKitInit::loadResource(const char* name) { } return webkit_glue::WebKitClientImpl::loadResource(name); } + +WebKit::WebString TestShellWebKitInit::queryLocalizedString( + WebKit::WebLocalizedString::Name name) { + switch (name) { + case WebKit::WebLocalizedString::ValidationValueMissing: + case WebKit::WebLocalizedString::ValidationValueMissingForCheckbox: + case WebKit::WebLocalizedString::ValidationValueMissingForFile: + case WebKit::WebLocalizedString::ValidationValueMissingForMultipleFile: + case WebKit::WebLocalizedString::ValidationValueMissingForRadio: + case WebKit::WebLocalizedString::ValidationValueMissingForSelect: + return ASCIIToUTF16("value missing"); + case WebKit::WebLocalizedString::ValidationTypeMismatch: + case WebKit::WebLocalizedString::ValidationTypeMismatchForEmail: + case WebKit::WebLocalizedString::ValidationTypeMismatchForMultipleEmail: + case WebKit::WebLocalizedString::ValidationTypeMismatchForURL: + return ASCIIToUTF16("type mismatch"); + case WebKit::WebLocalizedString::ValidationPatternMismatch: + return ASCIIToUTF16("pattern mismatch"); + case WebKit::WebLocalizedString::ValidationTooLong: + return ASCIIToUTF16("too long"); + case WebKit::WebLocalizedString::ValidationRangeUnderflow: + return ASCIIToUTF16("range underflow"); + case WebKit::WebLocalizedString::ValidationRangeOverflow: + return ASCIIToUTF16("range overflow"); + case WebKit::WebLocalizedString::ValidationStepMismatch: + return ASCIIToUTF16("step mismatch"); + default: + return WebKitClientImpl::queryLocalizedString(name); + } +} + +WebKit::WebString TestShellWebKitInit::queryLocalizedString( + WebKit::WebLocalizedString::Name name, const WebKit::WebString& value) { + if (name == WebKit::WebLocalizedString::ValidationRangeUnderflow) + return ASCIIToUTF16("range underflow"); + if (name == WebKit::WebLocalizedString::ValidationRangeOverflow) + return ASCIIToUTF16("range overflow"); + return WebKitClientImpl::queryLocalizedString(name, value); +} + +WebKit::WebString TestShellWebKitInit::queryLocalizedString( + WebKit::WebLocalizedString::Name name, + const WebKit::WebString& value1, + const WebKit::WebString& value2) { + if (name == WebKit::WebLocalizedString::ValidationTooLong) + return ASCIIToUTF16("too long"); + if (name == WebKit::WebLocalizedString::ValidationStepMismatch) + return ASCIIToUTF16("step mismatch"); + return WebKitClientImpl::queryLocalizedString(name, value1, value2); +} + diff --git a/webkit/tools/test_shell/test_shell_webkit_init.h b/webkit/tools/test_shell/test_shell_webkit_init.h index 7b1f196..0909b7f 100644 --- a/webkit/tools/test_shell/test_shell_webkit_init.h +++ b/webkit/tools/test_shell/test_shell_webkit_init.h @@ -104,6 +104,13 @@ class TestShellWebKitInit : public webkit_glue::WebKitClientImpl { } virtual WebKit::WebData loadResource(const char* name); + virtual WebKit::WebString queryLocalizedString( + WebKit::WebLocalizedString::Name name); + virtual WebKit::WebString queryLocalizedString( + WebKit::WebLocalizedString::Name name, const WebKit::WebString& value); + virtual WebKit::WebString queryLocalizedString( + WebKit::WebLocalizedString::Name name, + const WebKit::WebString& value1, const WebKit::WebString& value2); virtual WebKit::WebString defaultLocale() { return ASCIIToUTF16("en-US"); |