Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/android/date_time_chooser_android.h" | |
| 6 | |
| 7 #include "base/android/jni_string.h" | |
| 8 #include "content/common/view_messages.h" | |
| 9 #include "content/public/browser/android/content_view_core.h" | |
| 10 #include "content/public/browser/render_view_host_observer.h" | |
| 11 #include "jni/DateTimeChooserAndroid_jni.h" | |
| 12 | |
| 13 using base::android::AttachCurrentThread; | |
| 14 using base::android::ConvertJavaStringToUTF16; | |
| 15 using base::android::ConvertUTF8ToJavaString; | |
| 16 | |
| 17 | |
| 18 namespace content { | |
| 19 | |
| 20 // 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.
| |
| 21 // changes on a given date/time dialog. | |
| 22 class DateTimeCommunicator : public RenderViewHostObserver { | |
| 23 public: | |
| 24 explicit DateTimeCommunicator(RenderViewHost* sender); | |
| 25 virtual ~DateTimeCommunicator() {} | |
| 26 void ReplaceDateTime(string16 text); | |
| 27 void CancelDialog(); | |
| 28 | |
| 29 private: | |
| 30 DISALLOW_COPY_AND_ASSIGN(DateTimeCommunicator); | |
| 31 }; | |
| 32 | |
| 33 DateTimeCommunicator::DateTimeCommunicator(RenderViewHost* sender) | |
| 34 : RenderViewHostObserver(sender) { | |
| 35 } | |
| 36 | |
| 37 void DateTimeCommunicator::ReplaceDateTime(string16 text) { | |
| 38 Send(new ViewMsg_ReplaceDateTime(routing_id(), text)); | |
| 39 } | |
| 40 | |
| 41 void DateTimeCommunicator::CancelDialog() { | |
| 42 Send(new ViewMsg_CancelDateTimeDialog(routing_id())); | |
| 43 } | |
| 44 | |
| 45 | |
| 46 // DateTimeChooserAndroid implementation | |
| 47 | |
|
bulach
2013/01/10 15:58:35
nit: remove extra \n
Miguel Garcia
2013/01/11 14:59:37
Done.
| |
| 48 DateTimeChooserAndroid::DateTimeChooserAndroid() { | |
| 49 } | |
| 50 | |
| 51 DateTimeChooserAndroid::~DateTimeChooserAndroid() { | |
| 52 } | |
| 53 | |
| 54 // 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.
| |
| 55 DateTimeChooser* DateTimeChooser::Create() { | |
| 56 // 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!
| |
| 57 DateTimeChooserAndroid::InitializeDateInputTypes( | |
| 58 ui::TEXT_INPUT_TYPE_DATE, | |
| 59 ui::TEXT_INPUT_TYPE_DATE_TIME, | |
| 60 ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL, | |
| 61 ui::TEXT_INPUT_TYPE_MONTH, | |
| 62 ui::TEXT_INPUT_TYPE_TIME); | |
| 63 return new DateTimeChooserAndroid(); | |
| 64 } | |
| 65 | |
| 66 // static | |
| 67 void DateTimeChooserAndroid::InitializeDateInputTypes( | |
| 68 int textInputTypeDate, int textInputTypeDateTime, | |
|
bulach
2013/01/10 15:58:35
nit: hacker_style
Miguel Garcia
2013/01/11 14:59:37
Done.
| |
| 69 int textInputTypeDateTimeLocal, int textInputTypeMonth, | |
| 70 int textInputTypeTime) { | |
| 71 JNIEnv* env = AttachCurrentThread(); | |
| 72 Java_DateTimeChooserAndroid_initializeDateInputTypes(env, | |
| 73 textInputTypeDate, textInputTypeDateTime, | |
| 74 textInputTypeDateTimeLocal, textInputTypeMonth, | |
| 75 textInputTypeTime); | |
| 76 } | |
| 77 | |
| 78 void DateTimeChooserAndroid::ReplaceDateTime( | |
| 79 JNIEnv* env, jobject, jstring text) { | |
| 80 string16 text16 = ConvertJavaStringToUTF16(env, text); | |
| 81 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.
| |
| 82 communicator_->ReplaceDateTime(text16); | |
| 83 } | |
| 84 | |
| 85 void DateTimeChooserAndroid::CancelDialog(JNIEnv* env, jobject) { | |
| 86 if (communicator_) | |
| 87 communicator_->CancelDialog(); | |
| 88 } | |
| 89 | |
| 90 void DateTimeChooserAndroid::ShowDialog( | |
| 91 ContentViewCore* content, RenderViewHost* sender, | |
| 92 int type, const std::string& value) { | |
| 93 communicator_.reset(new DateTimeCommunicator(sender)); | |
| 94 JNIEnv* env = AttachCurrentThread(); | |
| 95 base::android::ScopedJavaLocalRef<jstring> java_value = | |
| 96 ConvertUTF8ToJavaString(env, value); | |
| 97 j_date_time_chooser_.Reset(Java_DateTimeChooserAndroid_createDateTimeChooser( | |
| 98 env, content->GetJavaObject().obj(), | |
| 99 reinterpret_cast<intptr_t>(this), java_value.obj(), type)); | |
| 100 } | |
| 101 | |
| 102 // ---------------------------------------------------------------------------- | |
| 103 // Native JNI methods | |
| 104 // ---------------------------------------------------------------------------- | |
| 105 bool RegisterDateTimeChooserAndroid(JNIEnv* env) { | |
| 106 return RegisterNativesImpl(env); | |
| 107 } | |
| 108 | |
| 109 } // namespace content | |
| OLD | NEW |