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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/android/date_time_chooser_android.h" 5 #include "content/browser/android/date_time_chooser_android.h"
6 6
7 #include "base/android/jni_android.h"
7 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/i18n/char_iterator.h"
10 #include "content/common/date_time_suggestion.h"
8 #include "content/common/view_messages.h" 11 #include "content/common/view_messages.h"
9 #include "content/public/browser/android/content_view_core.h" 12 #include "content/public/browser/android/content_view_core.h"
10 #include "content/public/browser/render_view_host.h" 13 #include "content/public/browser/render_view_host.h"
11 #include "jni/DateTimeChooserAndroid_jni.h" 14 #include "jni/DateTimeChooserAndroid_jni.h"
15 #include "third_party/icu/source/common/unicode/uchar.h"
16 #include "third_party/icu/source/common/unicode/unistr.h"
12 17
13 using base::android::AttachCurrentThread; 18 using base::android::AttachCurrentThread;
14 using base::android::ConvertJavaStringToUTF16; 19 using base::android::ConvertJavaStringToUTF16;
15 using base::android::ConvertUTF8ToJavaString; 20 using base::android::ConvertUTF8ToJavaString;
21 using base::android::ConvertUTF16ToJavaString;
16 22
17 23
24 namespace {
25
26 string16 SanitizeSuggestionString(const string16& string) {
27 string16 trimmed = string.substr(0, 255);
28 icu::UnicodeString sanitized;
29 base::i18n::UTF16CharIterator sanitized_iterator(&trimmed);
30 while (!sanitized_iterator.end()) {
31 UChar c = sanitized_iterator.get();
32 if (u_isprint(c))
33 sanitized.append(c);
34 sanitized_iterator.Advance();
35 }
36 return string16(sanitized.getBuffer(),
37 static_cast<size_t>(sanitized.length()));
38 }
39
40 } // namespace
41
18 namespace content { 42 namespace content {
19 43
20 // DateTimeChooserAndroid implementation 44 // DateTimeChooserAndroid implementation
21 DateTimeChooserAndroid::DateTimeChooserAndroid() 45 DateTimeChooserAndroid::DateTimeChooserAndroid()
22 : host_(NULL) { 46 : host_(NULL) {
23 } 47 }
24 48
25 DateTimeChooserAndroid::~DateTimeChooserAndroid() { 49 DateTimeChooserAndroid::~DateTimeChooserAndroid() {
26 } 50 }
27 51
(...skipping 20 matching lines...) Expand all
48 host_->Send(new ViewMsg_CancelDateTimeDialog(host_->GetRoutingID())); 72 host_->Send(new ViewMsg_CancelDateTimeDialog(host_->GetRoutingID()));
49 } 73 }
50 74
51 void DateTimeChooserAndroid::ShowDialog( 75 void DateTimeChooserAndroid::ShowDialog(
52 ContentViewCore* content, 76 ContentViewCore* content,
53 RenderViewHost* host, 77 RenderViewHost* host,
54 ui::TextInputType dialog_type, 78 ui::TextInputType dialog_type,
55 double dialog_value, 79 double dialog_value,
56 double min, 80 double min,
57 double max, 81 double max,
58 double step) { 82 double step,
83 const std::vector<DateTimeSuggestion>& suggestions) {
59 host_ = host; 84 host_ = host;
60 85
61 JNIEnv* env = AttachCurrentThread(); 86 JNIEnv* env = AttachCurrentThread();
87 ScopedJavaLocalRef<jobjectArray> suggestions_array;
88
89 if (suggestions.size() > 0) {
90 suggestions_array =
91 Java_DateTimeChooserAndroid_createSuggestionsArray(env,
92 suggestions.size());
93 for (size_t i = 0; i < suggestions.size(); ++i) {
94 const content::DateTimeSuggestion& suggestion = suggestions[i];
95 ScopedJavaLocalRef<jstring> localized_value = ConvertUTF16ToJavaString(
96 env, SanitizeSuggestionString(suggestion.localized_value));
97 ScopedJavaLocalRef<jstring> label = ConvertUTF16ToJavaString(
98 env, SanitizeSuggestionString(suggestion.label));
99 Java_DateTimeChooserAndroid_setDateTimeSuggestionAt(env,
100 suggestions_array.obj(), i,
101 suggestion.value, localized_value.obj(), label.obj());
102 }
103 }
104
62 j_date_time_chooser_.Reset(Java_DateTimeChooserAndroid_createDateTimeChooser( 105 j_date_time_chooser_.Reset(Java_DateTimeChooserAndroid_createDateTimeChooser(
63 env, 106 env,
64 content->GetJavaObject().obj(), 107 content->GetJavaObject().obj(),
65 reinterpret_cast<intptr_t>(this), 108 reinterpret_cast<intptr_t>(this),
66 dialog_type, 109 dialog_type,
67 dialog_value, 110 dialog_value,
68 min, 111 min,
69 max, 112 max,
70 step)); 113 step,
114 suggestions_array.obj()));
71 } 115 }
72 116
73 // ---------------------------------------------------------------------------- 117 // ----------------------------------------------------------------------------
74 // Native JNI methods 118 // Native JNI methods
75 // ---------------------------------------------------------------------------- 119 // ----------------------------------------------------------------------------
76 bool RegisterDateTimeChooserAndroid(JNIEnv* env) { 120 bool RegisterDateTimeChooserAndroid(JNIEnv* env) {
77 bool registered = RegisterNativesImpl(env); 121 bool registered = RegisterNativesImpl(env);
78 if (registered) 122 if (registered)
79 DateTimeChooserAndroid::InitializeDateInputTypes( 123 DateTimeChooserAndroid::InitializeDateInputTypes(
80 ui::TEXT_INPUT_TYPE_DATE, 124 ui::TEXT_INPUT_TYPE_DATE,
81 ui::TEXT_INPUT_TYPE_DATE_TIME, 125 ui::TEXT_INPUT_TYPE_DATE_TIME,
82 ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL, 126 ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL,
83 ui::TEXT_INPUT_TYPE_MONTH, 127 ui::TEXT_INPUT_TYPE_MONTH,
84 ui::TEXT_INPUT_TYPE_TIME, 128 ui::TEXT_INPUT_TYPE_TIME,
85 ui::TEXT_INPUT_TYPE_WEEK); 129 ui::TEXT_INPUT_TYPE_WEEK);
86 return registered; 130 return registered;
87 } 131 }
88 132
89 } // namespace content 133 } // namespace content
OLDNEW
« 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