| 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_string.h" | 8 #include "base/android/jni_string.h" |
| 8 #include "content/common/view_messages.h" | 9 #include "content/common/view_messages.h" |
| 9 #include "content/public/browser/android/content_view_core.h" | 10 #include "content/public/browser/android/content_view_core.h" |
| 10 #include "content/public/browser/render_view_host_observer.h" | 11 #include "content/public/browser/render_view_host_observer.h" |
| 12 #include "content/public/common/date_time_suggestion.h" |
| 11 #include "jni/DateTimeChooserAndroid_jni.h" | 13 #include "jni/DateTimeChooserAndroid_jni.h" |
| 12 | 14 |
| 13 using base::android::AttachCurrentThread; | 15 using base::android::AttachCurrentThread; |
| 14 using base::android::ConvertJavaStringToUTF16; | 16 using base::android::ConvertJavaStringToUTF16; |
| 15 using base::android::ConvertUTF8ToJavaString; | 17 using base::android::ConvertUTF8ToJavaString; |
| 18 using base::android::ConvertUTF16ToJavaString; |
| 16 | 19 |
| 17 | 20 |
| 18 namespace content { | 21 namespace content { |
| 19 | 22 |
| 20 // Updates date/time via IPC to the RenderView | 23 // Updates date/time via IPC to the RenderView |
| 21 class DateTimeChooserAndroid::DateTimeIPCSender : | 24 class DateTimeChooserAndroid::DateTimeIPCSender : |
| 22 public RenderViewHostObserver { | 25 public RenderViewHostObserver { |
| 23 public: | 26 public: |
| 24 explicit DateTimeIPCSender(RenderViewHost* sender); | 27 explicit DateTimeIPCSender(RenderViewHost* sender); |
| 25 virtual ~DateTimeIPCSender() {} | 28 virtual ~DateTimeIPCSender() {} |
| 26 void ReplaceDateTime(int dialog_type, | 29 void ReplaceDateTime(double value); |
| 27 int year, | |
| 28 int month, | |
| 29 int day, | |
| 30 int hour, | |
| 31 int minute, | |
| 32 int second, | |
| 33 int milli, | |
| 34 int week); | |
| 35 void CancelDialog(); | 30 void CancelDialog(); |
| 36 | 31 |
| 37 private: | 32 private: |
| 38 DISALLOW_COPY_AND_ASSIGN(DateTimeIPCSender); | 33 DISALLOW_COPY_AND_ASSIGN(DateTimeIPCSender); |
| 39 }; | 34 }; |
| 40 | 35 |
| 41 DateTimeChooserAndroid::DateTimeIPCSender::DateTimeIPCSender( | 36 DateTimeChooserAndroid::DateTimeIPCSender::DateTimeIPCSender( |
| 42 RenderViewHost* sender) | 37 RenderViewHost* sender) |
| 43 : RenderViewHostObserver(sender) { | 38 : RenderViewHostObserver(sender) { |
| 44 } | 39 } |
| 45 | 40 |
| 46 void DateTimeChooserAndroid::DateTimeIPCSender::ReplaceDateTime(int dialog_type, | 41 void DateTimeChooserAndroid::DateTimeIPCSender::ReplaceDateTime(double value) { |
| 47 int year, | |
| 48 int month, | |
| 49 int day, | |
| 50 int hour, | |
| 51 int minute, | |
| 52 int second, | |
| 53 int milli, | |
| 54 int week) { | |
| 55 ViewHostMsg_DateTimeDialogValue_Params value; | |
| 56 value.year = year; | |
| 57 value.month = month; | |
| 58 value.day = day; | |
| 59 value.hour = hour; | |
| 60 value.minute = minute; | |
| 61 value.second = second; | |
| 62 value.milli = milli; | |
| 63 value.week = week; | |
| 64 value.dialog_type = dialog_type; | |
| 65 Send(new ViewMsg_ReplaceDateTime(routing_id(), value)); | 42 Send(new ViewMsg_ReplaceDateTime(routing_id(), value)); |
| 66 } | 43 } |
| 67 | 44 |
| 68 void DateTimeChooserAndroid::DateTimeIPCSender::CancelDialog() { | 45 void DateTimeChooserAndroid::DateTimeIPCSender::CancelDialog() { |
| 69 Send(new ViewMsg_CancelDateTimeDialog(routing_id())); | 46 Send(new ViewMsg_CancelDateTimeDialog(routing_id())); |
| 70 } | 47 } |
| 71 | 48 |
| 72 // DateTimeChooserAndroid implementation | 49 // DateTimeChooserAndroid implementation |
| 73 DateTimeChooserAndroid::DateTimeChooserAndroid() | 50 DateTimeChooserAndroid::DateTimeChooserAndroid() |
| 74 : sender_(NULL) { | 51 : sender_(NULL) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 85 JNIEnv* env = AttachCurrentThread(); | 62 JNIEnv* env = AttachCurrentThread(); |
| 86 Java_DateTimeChooserAndroid_initializeDateInputTypes( | 63 Java_DateTimeChooserAndroid_initializeDateInputTypes( |
| 87 env, | 64 env, |
| 88 text_input_type_date, text_input_type_date_time, | 65 text_input_type_date, text_input_type_date_time, |
| 89 text_input_type_date_time_local, text_input_type_month, | 66 text_input_type_date_time_local, text_input_type_month, |
| 90 text_input_type_time, text_input_type_week); | 67 text_input_type_time, text_input_type_week); |
| 91 } | 68 } |
| 92 | 69 |
| 93 void DateTimeChooserAndroid::ReplaceDateTime(JNIEnv* env, | 70 void DateTimeChooserAndroid::ReplaceDateTime(JNIEnv* env, |
| 94 jobject, | 71 jobject, |
| 95 int dialog_type, | 72 jdouble value) { |
| 96 int year, | 73 sender_->ReplaceDateTime(value); |
| 97 int month, | |
| 98 int day, | |
| 99 int hour, | |
| 100 int minute, | |
| 101 int second, | |
| 102 int milli, | |
| 103 int week) { | |
| 104 sender_->ReplaceDateTime( | |
| 105 dialog_type, year, month, day, hour, minute, second, milli, week); | |
| 106 } | 74 } |
| 107 | 75 |
| 108 void DateTimeChooserAndroid::CancelDialog(JNIEnv* env, jobject) { | 76 void DateTimeChooserAndroid::CancelDialog(JNIEnv* env, jobject) { |
| 109 sender_->CancelDialog(); | 77 sender_->CancelDialog(); |
| 110 } | 78 } |
| 111 | 79 |
| 112 void DateTimeChooserAndroid::ShowDialog(ContentViewCore* content, | 80 void DateTimeChooserAndroid::ShowDialog( |
| 113 RenderViewHost* sender, | 81 ContentViewCore* content, |
| 114 int type, | 82 RenderViewHost* sender, |
| 115 int year, | 83 int dialog_type, |
| 116 int month, | 84 double current_value, |
| 117 int day, | 85 double min, |
| 118 int hour, | 86 double max, |
| 119 int minute, | 87 double step, |
| 120 int second, | 88 std::vector<DateTimeSuggestion> suggestions) { |
| 121 int milli, | |
| 122 int week, | |
| 123 double min, | |
| 124 double max, | |
| 125 double step) { | |
| 126 if (sender_) | 89 if (sender_) |
| 127 delete sender_; | 90 delete sender_; |
| 128 sender_ = new DateTimeIPCSender(sender); | 91 sender_ = new DateTimeIPCSender(sender); |
| 129 | 92 |
| 130 JNIEnv* env = AttachCurrentThread(); | 93 JNIEnv* env = AttachCurrentThread(); |
| 94 ScopedJavaLocalRef<jobjectArray> suggestions_array; |
| 95 |
| 96 if (suggestions.size() > 0) { |
| 97 ScopedJavaLocalRef<jclass> suggestion_class = base::android::GetClass( |
| 98 env, |
| 99 "org/chromium/content/browser/input/DateTimeSuggestion"); |
| 100 suggestions_array.Reset(env, env->NewObjectArray(suggestions.size(), |
| 101 suggestion_class.obj(), |
| 102 NULL)); |
| 103 for (size_t i = 0; i < suggestions.size(); ++i) { |
| 104 const content::DateTimeSuggestion& suggestion = suggestions[i]; |
| 105 ScopedJavaLocalRef<jstring> localizedValue = ConvertUTF16ToJavaString( |
| 106 env, suggestion.localizedValue); |
| 107 ScopedJavaLocalRef<jstring> label = ConvertUTF16ToJavaString( |
| 108 env, suggestion.label); |
| 109 env->SetObjectArrayElement( |
| 110 suggestions_array.obj(), |
| 111 i, |
| 112 Java_DateTimeChooserAndroid_createDateTimeSuggestion( |
| 113 env, |
| 114 suggestion.value, |
| 115 localizedValue.obj(), |
| 116 label.obj()).obj()); |
| 117 } |
| 118 } |
| 119 |
| 131 j_date_time_chooser_.Reset(Java_DateTimeChooserAndroid_createDateTimeChooser( | 120 j_date_time_chooser_.Reset(Java_DateTimeChooserAndroid_createDateTimeChooser( |
| 132 env, | 121 env, |
| 133 content->GetJavaObject().obj(), | 122 content->GetJavaObject().obj(), |
| 134 reinterpret_cast<intptr_t>(this), | 123 reinterpret_cast<intptr_t>(this), |
| 135 type, | 124 dialog_type, |
| 136 year, | 125 current_value, |
| 137 month, | |
| 138 day, | |
| 139 hour, | |
| 140 minute, | |
| 141 second, | |
| 142 milli, | |
| 143 week, | |
| 144 min, | 126 min, |
| 145 max, | 127 max, |
| 146 step)); | 128 step, |
| 129 suggestions_array.obj())); |
| 147 } | 130 } |
| 148 | 131 |
| 149 // ---------------------------------------------------------------------------- | 132 // ---------------------------------------------------------------------------- |
| 150 // Native JNI methods | 133 // Native JNI methods |
| 151 // ---------------------------------------------------------------------------- | 134 // ---------------------------------------------------------------------------- |
| 152 bool RegisterDateTimeChooserAndroid(JNIEnv* env) { | 135 bool RegisterDateTimeChooserAndroid(JNIEnv* env) { |
| 153 bool registered = RegisterNativesImpl(env); | 136 bool registered = RegisterNativesImpl(env); |
| 154 if (registered) | 137 if (registered) |
| 155 DateTimeChooserAndroid::InitializeDateInputTypes( | 138 DateTimeChooserAndroid::InitializeDateInputTypes( |
| 156 ui::TEXT_INPUT_TYPE_DATE, | 139 ui::TEXT_INPUT_TYPE_DATE, |
| 157 ui::TEXT_INPUT_TYPE_DATE_TIME, | 140 ui::TEXT_INPUT_TYPE_DATE_TIME, |
| 158 ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL, | 141 ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL, |
| 159 ui::TEXT_INPUT_TYPE_MONTH, | 142 ui::TEXT_INPUT_TYPE_MONTH, |
| 160 ui::TEXT_INPUT_TYPE_TIME, | 143 ui::TEXT_INPUT_TYPE_TIME, |
| 161 ui::TEXT_INPUT_TYPE_WEEK); | 144 ui::TEXT_INPUT_TYPE_WEEK); |
| 162 return registered; | 145 return registered; |
| 163 } | 146 } |
| 164 | 147 |
| 165 } // namespace content | 148 } // namespace content |
| OLD | NEW |