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 |
new file mode 100644 |
index 0000000000000000000000000000000000000000..fce52121b970dcc038baa954d2bd51e2ba2c7894 |
--- /dev/null |
+++ b/content/browser/android/date_time_chooser_android.cc |
@@ -0,0 +1,109 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/browser/android/date_time_chooser_android.h" |
+ |
+#include "base/android/jni_string.h" |
+#include "content/common/view_messages.h" |
+#include "content/public/browser/android/content_view_core.h" |
+#include "content/public/browser/render_view_host_observer.h" |
+#include "jni/DateTimeChooserAndroid_jni.h" |
+ |
+using base::android::AttachCurrentThread; |
+using base::android::ConvertJavaStringToUTF16; |
+using base::android::ConvertUTF8ToJavaString; |
+ |
+ |
+namespace content { |
+ |
+// Internal communicator class, talks back to the renderer and communicate |
bulach
2013/01/10 15:58:35
how about "Updates date/time via IPC to the Render
Miguel Garcia
2013/01/11 14:59:37
Done.
|
+// changes on a given date/time dialog. |
+class DateTimeCommunicator : public RenderViewHostObserver { |
+ public: |
+ explicit DateTimeCommunicator(RenderViewHost* sender); |
+ virtual ~DateTimeCommunicator() {} |
+ void ReplaceDateTime(string16 text); |
+ void CancelDialog(); |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(DateTimeCommunicator); |
+}; |
+ |
+DateTimeCommunicator::DateTimeCommunicator(RenderViewHost* sender) |
+ : RenderViewHostObserver(sender) { |
+} |
+ |
+void DateTimeCommunicator::ReplaceDateTime(string16 text) { |
+ Send(new ViewMsg_ReplaceDateTime(routing_id(), text)); |
+} |
+ |
+void DateTimeCommunicator::CancelDialog() { |
+ Send(new ViewMsg_CancelDateTimeDialog(routing_id())); |
+} |
+ |
+ |
+// DateTimeChooserAndroid implementation |
+ |
bulach
2013/01/10 15:58:35
nit: remove extra \n
Miguel Garcia
2013/01/11 14:59:37
Done.
|
+DateTimeChooserAndroid::DateTimeChooserAndroid() { |
+} |
+ |
+DateTimeChooserAndroid::~DateTimeChooserAndroid() { |
+} |
+ |
+// static |
bulach
2013/01/10 15:58:35
since this is for DateTimeChooser rather than Date
Miguel Garcia
2013/01/11 14:59:37
Done.
|
+DateTimeChooser* DateTimeChooser::Create() { |
+ // Initialize platform specific type values date/time value forms. |
bulach
2013/01/10 15:58:35
I suppose 56-62 could be moved to 106, after regis
Miguel Garcia
2013/01/11 14:59:37
Great idea!
|
+ DateTimeChooserAndroid::InitializeDateInputTypes( |
+ ui::TEXT_INPUT_TYPE_DATE, |
+ ui::TEXT_INPUT_TYPE_DATE_TIME, |
+ ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL, |
+ ui::TEXT_INPUT_TYPE_MONTH, |
+ ui::TEXT_INPUT_TYPE_TIME); |
+ return new DateTimeChooserAndroid(); |
+} |
+ |
+// static |
+void DateTimeChooserAndroid::InitializeDateInputTypes( |
+ int textInputTypeDate, int textInputTypeDateTime, |
bulach
2013/01/10 15:58:35
nit: hacker_style
Miguel Garcia
2013/01/11 14:59:37
Done.
|
+ int textInputTypeDateTimeLocal, int textInputTypeMonth, |
+ int textInputTypeTime) { |
+ JNIEnv* env = AttachCurrentThread(); |
+ Java_DateTimeChooserAndroid_initializeDateInputTypes(env, |
+ textInputTypeDate, textInputTypeDateTime, |
+ textInputTypeDateTimeLocal, textInputTypeMonth, |
+ textInputTypeTime); |
+} |
+ |
+void DateTimeChooserAndroid::ReplaceDateTime( |
+ JNIEnv* env, jobject, jstring text) { |
+ string16 text16 = ConvertJavaStringToUTF16(env, text); |
+ if (communicator_) |
bulach
2013/01/10 15:58:35
nit: at this point, communicator_ has got to be se
Miguel Garcia
2013/01/11 14:59:37
Done.
|
+ communicator_->ReplaceDateTime(text16); |
+} |
+ |
+void DateTimeChooserAndroid::CancelDialog(JNIEnv* env, jobject) { |
+ if (communicator_) |
+ communicator_->CancelDialog(); |
+} |
+ |
+void DateTimeChooserAndroid::ShowDialog( |
+ ContentViewCore* content, RenderViewHost* sender, |
+ int type, const std::string& value) { |
+ communicator_.reset(new DateTimeCommunicator(sender)); |
+ JNIEnv* env = AttachCurrentThread(); |
+ base::android::ScopedJavaLocalRef<jstring> java_value = |
+ ConvertUTF8ToJavaString(env, value); |
+ j_date_time_chooser_.Reset(Java_DateTimeChooserAndroid_createDateTimeChooser( |
+ env, content->GetJavaObject().obj(), |
+ reinterpret_cast<intptr_t>(this), java_value.obj(), type)); |
+} |
+ |
+// ---------------------------------------------------------------------------- |
+// Native JNI methods |
+// ---------------------------------------------------------------------------- |
+bool RegisterDateTimeChooserAndroid(JNIEnv* env) { |
+ return RegisterNativesImpl(env); |
+} |
+ |
+} // namespace content |