Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(182)

Unified Diff: content/browser/android/date_time_chooser_android.cc

Issue 23623019: Support datalist for date/time input types on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/android/date_time_chooser_android.cc
diff --git a/content/browser/android/date_time_chooser_android.cc b/content/browser/android/date_time_chooser_android.cc
index 87f02b9f72960de9e72c916663917a99b7cdc703..f6b50c9da4b6b8cf97e45bbf03fcc77713562bd3 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()));
}
// ----------------------------------------------------------------------------
« no previous file with comments | « content/browser/android/date_time_chooser_android.h ('k') | content/browser/web_contents/web_contents_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698