diff options
author | keishi@chromium.org <keishi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-07 02:56:17 +0000 |
---|---|---|
committer | keishi@chromium.org <keishi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-07 02:56:17 +0000 |
commit | 6e08bfb743b8dcf8b7ae3052c685b0ef284aa737 (patch) | |
tree | 0b3ecd219a0cf41f798afee689360ac630b965fa /content/browser/android | |
parent | 14e864b164494e7c3dae5a53d2956eef91b1f19f (diff) | |
download | chromium_src-6e08bfb743b8dcf8b7ae3052c685b0ef284aa737.zip chromium_src-6e08bfb743b8dcf8b7ae3052c685b0ef284aa737.tar.gz chromium_src-6e08bfb743b8dcf8b7ae3052c685b0ef284aa737.tar.bz2 |
Support datalist for date/time input types on Android
BUG=242455
Review URL: https://codereview.chromium.org/23623019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@239290 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/android')
-rw-r--r-- | content/browser/android/date_time_chooser_android.cc | 48 | ||||
-rw-r--r-- | content/browser/android/date_time_chooser_android.h | 5 |
2 files changed, 50 insertions, 3 deletions
diff --git a/content/browser/android/date_time_chooser_android.cc b/content/browser/android/date_time_chooser_android.cc index 87f02b9f..f6b50c9 100644 --- a/content/browser/android/date_time_chooser_android.cc +++ b/content/browser/android/date_time_chooser_android.cc @@ -4,17 +4,41 @@ #include "content/browser/android/date_time_chooser_android.h" +#include "base/android/jni_android.h" #include "base/android/jni_string.h" +#include "base/i18n/char_iterator.h" +#include "content/common/date_time_suggestion.h" #include "content/common/view_messages.h" #include "content/public/browser/android/content_view_core.h" #include "content/public/browser/render_view_host.h" #include "jni/DateTimeChooserAndroid_jni.h" +#include "third_party/icu/source/common/unicode/uchar.h" +#include "third_party/icu/source/common/unicode/unistr.h" using base::android::AttachCurrentThread; using base::android::ConvertJavaStringToUTF16; using base::android::ConvertUTF8ToJavaString; +using base::android::ConvertUTF16ToJavaString; +namespace { + +string16 SanitizeSuggestionString(const string16& string) { + string16 trimmed = string.substr(0, 255); + icu::UnicodeString sanitized; + base::i18n::UTF16CharIterator sanitized_iterator(&trimmed); + while (!sanitized_iterator.end()) { + UChar c = sanitized_iterator.get(); + if (u_isprint(c)) + sanitized.append(c); + sanitized_iterator.Advance(); + } + return string16(sanitized.getBuffer(), + static_cast<size_t>(sanitized.length())); +} + +} // namespace + namespace content { // DateTimeChooserAndroid implementation @@ -55,10 +79,29 @@ void DateTimeChooserAndroid::ShowDialog( double dialog_value, double min, double max, - double step) { + double step, + const std::vector<DateTimeSuggestion>& suggestions) { host_ = host; JNIEnv* env = AttachCurrentThread(); + ScopedJavaLocalRef<jobjectArray> suggestions_array; + + if (suggestions.size() > 0) { + suggestions_array = + Java_DateTimeChooserAndroid_createSuggestionsArray(env, + suggestions.size()); + for (size_t i = 0; i < suggestions.size(); ++i) { + const content::DateTimeSuggestion& suggestion = suggestions[i]; + ScopedJavaLocalRef<jstring> localized_value = ConvertUTF16ToJavaString( + env, SanitizeSuggestionString(suggestion.localized_value)); + ScopedJavaLocalRef<jstring> label = ConvertUTF16ToJavaString( + env, SanitizeSuggestionString(suggestion.label)); + Java_DateTimeChooserAndroid_setDateTimeSuggestionAt(env, + suggestions_array.obj(), i, + suggestion.value, localized_value.obj(), label.obj()); + } + } + j_date_time_chooser_.Reset(Java_DateTimeChooserAndroid_createDateTimeChooser( env, content->GetJavaObject().obj(), @@ -67,7 +110,8 @@ void DateTimeChooserAndroid::ShowDialog( dialog_value, min, max, - step)); + step, + suggestions_array.obj())); } // ---------------------------------------------------------------------------- diff --git a/content/browser/android/date_time_chooser_android.h b/content/browser/android/date_time_chooser_android.h index a04850f..c02ecf5 100644 --- a/content/browser/android/date_time_chooser_android.h +++ b/content/browser/android/date_time_chooser_android.h @@ -6,6 +6,7 @@ #define CONTENT_BROWSER_ANDROID_DATE_TIME_CHOOSER_ANDROID_H_ #include <string> +#include <vector> #include "base/android/jni_helper.h" #include "base/memory/scoped_ptr.h" @@ -15,6 +16,7 @@ namespace content { class ContentViewCore; class RenderViewHost; +struct DateTimeSuggestion; // Android implementation for DateTimeChooser dialogs. class DateTimeChooserAndroid { @@ -31,7 +33,8 @@ class DateTimeChooserAndroid { double dialog_value, double min, double max, - double step); + double step, + const std::vector<DateTimeSuggestion>& suggestions); // Replaces the current value void ReplaceDateTime(JNIEnv* env, jobject, jdouble value); |