OLD | NEW |
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_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "base/i18n/char_iterator.h" | 9 #include "base/i18n/char_iterator.h" |
10 #include "content/common/date_time_suggestion.h" | 10 #include "content/common/date_time_suggestion.h" |
11 #include "content/common/view_messages.h" | 11 #include "content/common/view_messages.h" |
12 #include "content/public/browser/android/content_view_core.h" | |
13 #include "content/public/browser/render_view_host.h" | 12 #include "content/public/browser/render_view_host.h" |
14 #include "jni/DateTimeChooserAndroid_jni.h" | 13 #include "jni/DateTimeChooserAndroid_jni.h" |
15 #include "third_party/icu/source/common/unicode/uchar.h" | 14 #include "third_party/icu/source/common/unicode/uchar.h" |
16 #include "third_party/icu/source/common/unicode/unistr.h" | 15 #include "third_party/icu/source/common/unicode/unistr.h" |
| 16 #include "ui/base/android/window_android.h" |
17 | 17 |
18 using base::android::AttachCurrentThread; | 18 using base::android::AttachCurrentThread; |
19 using base::android::ConvertJavaStringToUTF16; | 19 using base::android::ConvertJavaStringToUTF16; |
20 using base::android::ConvertUTF8ToJavaString; | 20 using base::android::ConvertUTF8ToJavaString; |
21 using base::android::ConvertUTF16ToJavaString; | 21 using base::android::ConvertUTF16ToJavaString; |
22 | 22 |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 base::string16 SanitizeSuggestionString(const base::string16& string) { | 26 base::string16 SanitizeSuggestionString(const base::string16& string) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 jobject, | 66 jobject, |
67 jdouble value) { | 67 jdouble value) { |
68 host_->Send(new ViewMsg_ReplaceDateTime(host_->GetRoutingID(), value)); | 68 host_->Send(new ViewMsg_ReplaceDateTime(host_->GetRoutingID(), value)); |
69 } | 69 } |
70 | 70 |
71 void DateTimeChooserAndroid::CancelDialog(JNIEnv* env, jobject) { | 71 void DateTimeChooserAndroid::CancelDialog(JNIEnv* env, jobject) { |
72 host_->Send(new ViewMsg_CancelDateTimeDialog(host_->GetRoutingID())); | 72 host_->Send(new ViewMsg_CancelDateTimeDialog(host_->GetRoutingID())); |
73 } | 73 } |
74 | 74 |
75 void DateTimeChooserAndroid::ShowDialog( | 75 void DateTimeChooserAndroid::ShowDialog( |
76 ContentViewCore* content, | 76 gfx::NativeWindow native_window, |
77 RenderViewHost* host, | 77 RenderViewHost* host, |
78 ui::TextInputType dialog_type, | 78 ui::TextInputType dialog_type, |
79 double dialog_value, | 79 double dialog_value, |
80 double min, | 80 double min, |
81 double max, | 81 double max, |
82 double step, | 82 double step, |
83 const std::vector<DateTimeSuggestion>& suggestions) { | 83 const std::vector<DateTimeSuggestion>& suggestions) { |
84 host_ = host; | 84 host_ = host; |
85 | 85 |
86 JNIEnv* env = AttachCurrentThread(); | 86 JNIEnv* env = AttachCurrentThread(); |
(...skipping 10 matching lines...) Expand all Loading... |
97 ScopedJavaLocalRef<jstring> label = ConvertUTF16ToJavaString( | 97 ScopedJavaLocalRef<jstring> label = ConvertUTF16ToJavaString( |
98 env, SanitizeSuggestionString(suggestion.label)); | 98 env, SanitizeSuggestionString(suggestion.label)); |
99 Java_DateTimeChooserAndroid_setDateTimeSuggestionAt(env, | 99 Java_DateTimeChooserAndroid_setDateTimeSuggestionAt(env, |
100 suggestions_array.obj(), i, | 100 suggestions_array.obj(), i, |
101 suggestion.value, localized_value.obj(), label.obj()); | 101 suggestion.value, localized_value.obj(), label.obj()); |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 j_date_time_chooser_.Reset(Java_DateTimeChooserAndroid_createDateTimeChooser( | 105 j_date_time_chooser_.Reset(Java_DateTimeChooserAndroid_createDateTimeChooser( |
106 env, | 106 env, |
107 content->GetJavaObject().obj(), | 107 native_window->GetJavaObject().obj(), |
108 reinterpret_cast<intptr_t>(this), | 108 reinterpret_cast<intptr_t>(this), |
109 dialog_type, | 109 dialog_type, |
110 dialog_value, | 110 dialog_value, |
111 min, | 111 min, |
112 max, | 112 max, |
113 step, | 113 step, |
114 suggestions_array.obj())); | 114 suggestions_array.obj())); |
| 115 if (j_date_time_chooser_.is_null()) |
| 116 ReplaceDateTime(env, j_date_time_chooser_.obj(), dialog_value); |
115 } | 117 } |
116 | 118 |
117 // ---------------------------------------------------------------------------- | 119 // ---------------------------------------------------------------------------- |
118 // Native JNI methods | 120 // Native JNI methods |
119 // ---------------------------------------------------------------------------- | 121 // ---------------------------------------------------------------------------- |
120 bool RegisterDateTimeChooserAndroid(JNIEnv* env) { | 122 bool RegisterDateTimeChooserAndroid(JNIEnv* env) { |
121 bool registered = RegisterNativesImpl(env); | 123 bool registered = RegisterNativesImpl(env); |
122 if (registered) | 124 if (registered) |
123 DateTimeChooserAndroid::InitializeDateInputTypes( | 125 DateTimeChooserAndroid::InitializeDateInputTypes( |
124 ui::TEXT_INPUT_TYPE_DATE, | 126 ui::TEXT_INPUT_TYPE_DATE, |
125 ui::TEXT_INPUT_TYPE_DATE_TIME, | 127 ui::TEXT_INPUT_TYPE_DATE_TIME, |
126 ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL, | 128 ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL, |
127 ui::TEXT_INPUT_TYPE_MONTH, | 129 ui::TEXT_INPUT_TYPE_MONTH, |
128 ui::TEXT_INPUT_TYPE_TIME, | 130 ui::TEXT_INPUT_TYPE_TIME, |
129 ui::TEXT_INPUT_TYPE_WEEK); | 131 ui::TEXT_INPUT_TYPE_WEEK); |
130 return registered; | 132 return registered; |
131 } | 133 } |
132 | 134 |
133 } // namespace content | 135 } // namespace content |
OLD | NEW |