| 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_string.h" | 7 #include "base/android/jni_string.h" |
| 8 #include "content/common/view_messages.h" | 8 #include "content/common/view_messages.h" |
| 9 #include "content/public/browser/android/content_view_core.h" | 9 #include "content/public/browser/android/content_view_core.h" |
| 10 #include "content/public/browser/render_view_host_observer.h" | 10 #include "content/public/browser/render_view_host_observer.h" |
| 11 #include "content/public/common/date_time_suggestion.h" |
| 11 #include "jni/DateTimeChooserAndroid_jni.h" | 12 #include "jni/DateTimeChooserAndroid_jni.h" |
| 12 | 13 |
| 13 using base::android::AttachCurrentThread; | 14 using base::android::AttachCurrentThread; |
| 14 using base::android::ConvertJavaStringToUTF16; | 15 using base::android::ConvertJavaStringToUTF16; |
| 15 using base::android::ConvertUTF8ToJavaString; | 16 using base::android::ConvertUTF8ToJavaString; |
| 17 using base::android::ConvertUTF16ToJavaString; |
| 16 | 18 |
| 17 | 19 |
| 18 namespace content { | 20 namespace content { |
| 19 | 21 |
| 20 // Updates date/time via IPC to the RenderView | 22 // Updates date/time via IPC to the RenderView |
| 21 class DateTimeChooserAndroid::DateTimeIPCSender : | 23 class DateTimeChooserAndroid::DateTimeIPCSender : |
| 22 public RenderViewHostObserver { | 24 public RenderViewHostObserver { |
| 23 public: | 25 public: |
| 24 explicit DateTimeIPCSender(RenderViewHost* sender); | 26 explicit DateTimeIPCSender(RenderViewHost* sender); |
| 25 virtual ~DateTimeIPCSender() {} | 27 virtual ~DateTimeIPCSender() {} |
| 26 void ReplaceDateTime(int dialog_type, | 28 void ReplaceDateTime(int dialog_type, |
| 27 int year, | 29 int year, |
| 28 int month, | 30 int month, |
| 29 int day, | 31 int day, |
| 30 int hour, | 32 int hour, |
| 31 int minute, | 33 int minute, |
| 32 int second, | 34 int second, |
| 33 int milli, | 35 int milli, |
| 34 int week); | 36 int week); |
| 35 void CancelDialog(); | 37 void CancelDialog(); |
| 38 void AcceptDataListSuggestion(const string16& value); |
| 36 | 39 |
| 37 private: | 40 private: |
| 38 DISALLOW_COPY_AND_ASSIGN(DateTimeIPCSender); | 41 DISALLOW_COPY_AND_ASSIGN(DateTimeIPCSender); |
| 39 }; | 42 }; |
| 40 | 43 |
| 41 DateTimeChooserAndroid::DateTimeIPCSender::DateTimeIPCSender( | 44 DateTimeChooserAndroid::DateTimeIPCSender::DateTimeIPCSender( |
| 42 RenderViewHost* sender) | 45 RenderViewHost* sender) |
| 43 : RenderViewHostObserver(sender) { | 46 : RenderViewHostObserver(sender) { |
| 44 } | 47 } |
| 45 | 48 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 62 value.milli = milli; | 65 value.milli = milli; |
| 63 value.week = week; | 66 value.week = week; |
| 64 value.dialog_type = dialog_type; | 67 value.dialog_type = dialog_type; |
| 65 Send(new ViewMsg_ReplaceDateTime(routing_id(), value)); | 68 Send(new ViewMsg_ReplaceDateTime(routing_id(), value)); |
| 66 } | 69 } |
| 67 | 70 |
| 68 void DateTimeChooserAndroid::DateTimeIPCSender::CancelDialog() { | 71 void DateTimeChooserAndroid::DateTimeIPCSender::CancelDialog() { |
| 69 Send(new ViewMsg_CancelDateTimeDialog(routing_id())); | 72 Send(new ViewMsg_CancelDateTimeDialog(routing_id())); |
| 70 } | 73 } |
| 71 | 74 |
| 75 void DateTimeChooserAndroid::DateTimeIPCSender::AcceptDataListSuggestion( |
| 76 const string16& value) { |
| 77 Send(new ViewMsg_AcceptDataListSuggestion(routing_id(), value)); |
| 78 } |
| 79 |
| 72 // DateTimeChooserAndroid implementation | 80 // DateTimeChooserAndroid implementation |
| 73 DateTimeChooserAndroid::DateTimeChooserAndroid() | 81 DateTimeChooserAndroid::DateTimeChooserAndroid() |
| 74 : sender_(NULL) { | 82 : sender_(NULL) { |
| 75 } | 83 } |
| 76 | 84 |
| 77 DateTimeChooserAndroid::~DateTimeChooserAndroid() { | 85 DateTimeChooserAndroid::~DateTimeChooserAndroid() { |
| 78 } | 86 } |
| 79 | 87 |
| 80 // static | 88 // static |
| 81 void DateTimeChooserAndroid::InitializeDateInputTypes( | 89 void DateTimeChooserAndroid::InitializeDateInputTypes( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 102 int milli, | 110 int milli, |
| 103 int week) { | 111 int week) { |
| 104 sender_->ReplaceDateTime( | 112 sender_->ReplaceDateTime( |
| 105 dialog_type, year, month, day, hour, minute, second, milli, week); | 113 dialog_type, year, month, day, hour, minute, second, milli, week); |
| 106 } | 114 } |
| 107 | 115 |
| 108 void DateTimeChooserAndroid::CancelDialog(JNIEnv* env, jobject) { | 116 void DateTimeChooserAndroid::CancelDialog(JNIEnv* env, jobject) { |
| 109 sender_->CancelDialog(); | 117 sender_->CancelDialog(); |
| 110 } | 118 } |
| 111 | 119 |
| 112 void DateTimeChooserAndroid::ShowDialog(ContentViewCore* content, | 120 void DateTimeChooserAndroid::AcceptDataListSuggestion(JNIEnv* env, |
| 113 RenderViewHost* sender, | 121 jobject, |
| 114 int type, | 122 jstring value) { |
| 115 int year, | 123 sender_->AcceptDataListSuggestion(ConvertJavaStringToUTF16(env, value)); |
| 116 int month, | 124 } |
| 117 int day, | 125 |
| 118 int hour, | 126 void DateTimeChooserAndroid::ShowDialog( |
| 119 int minute, | 127 ContentViewCore* content, |
| 120 int second, | 128 RenderViewHost* sender, |
| 121 int milli, | 129 int type, |
| 122 int week, | 130 int year, |
| 123 double min, | 131 int month, |
| 124 double max, | 132 int day, |
| 125 double step) { | 133 int hour, |
| 134 int minute, |
| 135 int second, |
| 136 int milli, |
| 137 int week, |
| 138 double min, |
| 139 double max, |
| 140 double step, |
| 141 std::vector<DateTimeSuggestion> suggestions) { |
| 126 if (sender_) | 142 if (sender_) |
| 127 delete sender_; | 143 delete sender_; |
| 128 sender_ = new DateTimeIPCSender(sender); | 144 sender_ = new DateTimeIPCSender(sender); |
| 129 | 145 |
| 130 JNIEnv* env = AttachCurrentThread(); | 146 JNIEnv* env = AttachCurrentThread(); |
| 147 ScopedJavaLocalRef<jobjectArray> suggestions_array; |
| 148 |
| 149 if (suggestions.size() > 0) { |
| 150 suggestions_array = |
| 151 Java_DateTimeChooserAndroid_createDateTimeSuggestionArray( |
| 152 env, |
| 153 suggestions.size()); |
| 154 |
| 155 for (size_t i = 0; i < suggestions.size(); ++i) { |
| 156 const content::DateTimeSuggestion& suggestion = suggestions[i]; |
| 157 ScopedJavaLocalRef<jstring> value = ConvertUTF16ToJavaString( |
| 158 env, suggestion.value); |
| 159 ScopedJavaLocalRef<jstring> localizedValue = ConvertUTF16ToJavaString( |
| 160 env, suggestion.localizedValue); |
| 161 ScopedJavaLocalRef<jstring> label = ConvertUTF16ToJavaString( |
| 162 env, suggestion.label); |
| 163 Java_DateTimeChooserAndroid_addToDateTimeSuggestionArray( |
| 164 env, |
| 165 suggestions_array.obj(), |
| 166 i, |
| 167 value.obj(), |
| 168 localizedValue.obj(), |
| 169 label.obj()); |
| 170 } |
| 171 } |
| 172 |
| 131 j_date_time_chooser_.Reset(Java_DateTimeChooserAndroid_createDateTimeChooser( | 173 j_date_time_chooser_.Reset(Java_DateTimeChooserAndroid_createDateTimeChooser( |
| 132 env, | 174 env, |
| 133 content->GetJavaObject().obj(), | 175 content->GetJavaObject().obj(), |
| 134 reinterpret_cast<intptr_t>(this), | 176 reinterpret_cast<intptr_t>(this), |
| 135 type, | 177 type, |
| 136 year, | 178 year, |
| 137 month, | 179 month, |
| 138 day, | 180 day, |
| 139 hour, | 181 hour, |
| 140 minute, | 182 minute, |
| 141 second, | 183 second, |
| 142 milli, | 184 milli, |
| 143 week, | 185 week, |
| 144 min, | 186 min, |
| 145 max, | 187 max, |
| 146 step)); | 188 step, |
| 189 suggestions_array.obj())); |
| 147 } | 190 } |
| 148 | 191 |
| 149 // ---------------------------------------------------------------------------- | 192 // ---------------------------------------------------------------------------- |
| 150 // Native JNI methods | 193 // Native JNI methods |
| 151 // ---------------------------------------------------------------------------- | 194 // ---------------------------------------------------------------------------- |
| 152 bool RegisterDateTimeChooserAndroid(JNIEnv* env) { | 195 bool RegisterDateTimeChooserAndroid(JNIEnv* env) { |
| 153 bool registered = RegisterNativesImpl(env); | 196 bool registered = RegisterNativesImpl(env); |
| 154 if (registered) | 197 if (registered) |
| 155 DateTimeChooserAndroid::InitializeDateInputTypes( | 198 DateTimeChooserAndroid::InitializeDateInputTypes( |
| 156 ui::TEXT_INPUT_TYPE_DATE, | 199 ui::TEXT_INPUT_TYPE_DATE, |
| 157 ui::TEXT_INPUT_TYPE_DATE_TIME, | 200 ui::TEXT_INPUT_TYPE_DATE_TIME, |
| 158 ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL, | 201 ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL, |
| 159 ui::TEXT_INPUT_TYPE_MONTH, | 202 ui::TEXT_INPUT_TYPE_MONTH, |
| 160 ui::TEXT_INPUT_TYPE_TIME, | 203 ui::TEXT_INPUT_TYPE_TIME, |
| 161 ui::TEXT_INPUT_TYPE_WEEK); | 204 ui::TEXT_INPUT_TYPE_WEEK); |
| 162 return registered; | 205 return registered; |
| 163 } | 206 } |
| 164 | 207 |
| 165 } // namespace content | 208 } // namespace content |
| OLD | NEW |