| 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 "jni/DateTimeChooserAndroid_jni.h" | 11 #include "jni/DateTimeChooserAndroid_jni.h" |
| 12 | 12 |
| 13 using base::android::AttachCurrentThread; | 13 using base::android::AttachCurrentThread; |
| 14 using base::android::ConvertJavaStringToUTF16; | 14 using base::android::ConvertJavaStringToUTF16; |
| 15 using base::android::ConvertUTF8ToJavaString; | 15 using base::android::ConvertUTF8ToJavaString; |
| 16 | 16 |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 | 19 |
| 20 // Updates date/time via IPC to the RenderView | 20 // Updates date/time via IPC to the RenderView |
| 21 class DateTimeChooserAndroid::DateTimeIPCSender : | 21 class DateTimeChooserAndroid::DateTimeIPCSender : |
| 22 public RenderViewHostObserver { | 22 public RenderViewHostObserver { |
| 23 public: | 23 public: |
| 24 explicit DateTimeIPCSender(RenderViewHost* sender); | 24 explicit DateTimeIPCSender(RenderViewHost* sender); |
| 25 virtual ~DateTimeIPCSender() {} | 25 virtual ~DateTimeIPCSender() {} |
| 26 void ReplaceDateTime(int dialog_type, | 26 void ReplaceDateTime(int dialog_type, |
| 27 int year, int month, int day, int hour, int minute, int second); | 27 int year, int month, int day, int hour, int minute, int second, |
| 28 int week_year, int week); |
| 28 void CancelDialog(); | 29 void CancelDialog(); |
| 29 | 30 |
| 30 private: | 31 private: |
| 31 DISALLOW_COPY_AND_ASSIGN(DateTimeIPCSender); | 32 DISALLOW_COPY_AND_ASSIGN(DateTimeIPCSender); |
| 32 }; | 33 }; |
| 33 | 34 |
| 34 DateTimeChooserAndroid::DateTimeIPCSender::DateTimeIPCSender( | 35 DateTimeChooserAndroid::DateTimeIPCSender::DateTimeIPCSender( |
| 35 RenderViewHost* sender) | 36 RenderViewHost* sender) |
| 36 : RenderViewHostObserver(sender) { | 37 : RenderViewHostObserver(sender) { |
| 37 } | 38 } |
| 38 | 39 |
| 39 void DateTimeChooserAndroid::DateTimeIPCSender::ReplaceDateTime( | 40 void DateTimeChooserAndroid::DateTimeIPCSender::ReplaceDateTime( |
| 40 int dialog_type, | 41 int dialog_type, |
| 41 int year, int month, int day, int hour, int minute, int second) { | 42 int year, int month, int day, int hour, int minute, int second, |
| 43 int week_year, int week) { |
| 42 ViewHostMsg_DateTimeDialogValue_Params value; | 44 ViewHostMsg_DateTimeDialogValue_Params value; |
| 43 value.year = year; | 45 value.year = year; |
| 44 value.month = month; | 46 value.month = month; |
| 45 value.day = day; | 47 value.day = day; |
| 46 value.hour = hour; | 48 value.hour = hour; |
| 47 value.minute = minute; | 49 value.minute = minute; |
| 48 value.second = second; | 50 value.second = second; |
| 51 value.week_year = week_year; |
| 52 value.week = week; |
| 49 value.dialog_type = dialog_type; | 53 value.dialog_type = dialog_type; |
| 50 Send(new ViewMsg_ReplaceDateTime(routing_id(), value)); | 54 Send(new ViewMsg_ReplaceDateTime(routing_id(), value)); |
| 51 } | 55 } |
| 52 | 56 |
| 53 void DateTimeChooserAndroid::DateTimeIPCSender::CancelDialog() { | 57 void DateTimeChooserAndroid::DateTimeIPCSender::CancelDialog() { |
| 54 Send(new ViewMsg_CancelDateTimeDialog(routing_id())); | 58 Send(new ViewMsg_CancelDateTimeDialog(routing_id())); |
| 55 } | 59 } |
| 56 | 60 |
| 57 // DateTimeChooserAndroid implementation | 61 // DateTimeChooserAndroid implementation |
| 58 DateTimeChooserAndroid::DateTimeChooserAndroid() | 62 DateTimeChooserAndroid::DateTimeChooserAndroid() |
| 59 : sender_(NULL) { | 63 : sender_(NULL) { |
| 60 } | 64 } |
| 61 | 65 |
| 62 DateTimeChooserAndroid::~DateTimeChooserAndroid() { | 66 DateTimeChooserAndroid::~DateTimeChooserAndroid() { |
| 63 } | 67 } |
| 64 | 68 |
| 65 // static | 69 // static |
| 66 void DateTimeChooserAndroid::InitializeDateInputTypes( | 70 void DateTimeChooserAndroid::InitializeDateInputTypes( |
| 67 int text_input_type_date, int text_input_type_date_time, | 71 int text_input_type_date, int text_input_type_date_time, |
| 68 int text_input_type_date_time_local, int text_input_type_month, | 72 int text_input_type_date_time_local, int text_input_type_month, |
| 69 int text_input_type_time) { | 73 int text_input_type_time, int text_input_type_week) { |
| 70 JNIEnv* env = AttachCurrentThread(); | 74 JNIEnv* env = AttachCurrentThread(); |
| 71 Java_DateTimeChooserAndroid_initializeDateInputTypes( | 75 Java_DateTimeChooserAndroid_initializeDateInputTypes( |
| 72 env, | 76 env, |
| 73 text_input_type_date, text_input_type_date_time, | 77 text_input_type_date, text_input_type_date_time, |
| 74 text_input_type_date_time_local, text_input_type_month, | 78 text_input_type_date_time_local, text_input_type_month, |
| 75 text_input_type_time); | 79 text_input_type_time, text_input_type_week); |
| 76 } | 80 } |
| 77 | 81 |
| 78 void DateTimeChooserAndroid::ReplaceDateTime( | 82 void DateTimeChooserAndroid::ReplaceDateTime( |
| 79 JNIEnv* env, jobject, int dialog_type, | 83 JNIEnv* env, jobject, int dialog_type, |
| 80 int year, int month, int day, int hour, int minute, int second) { | 84 int year, int month, int day, int hour, int minute, int second, |
| 85 int weekYear, int week) { |
| 81 sender_->ReplaceDateTime( | 86 sender_->ReplaceDateTime( |
| 82 dialog_type, year, month, day, hour, minute, second); | 87 dialog_type, year, month, day, hour, minute, second, weekYear, week); |
| 83 } | 88 } |
| 84 | 89 |
| 85 void DateTimeChooserAndroid::CancelDialog(JNIEnv* env, jobject) { | 90 void DateTimeChooserAndroid::CancelDialog(JNIEnv* env, jobject) { |
| 86 sender_->CancelDialog(); | 91 sender_->CancelDialog(); |
| 87 } | 92 } |
| 88 | 93 |
| 89 void DateTimeChooserAndroid::ShowDialog( | 94 void DateTimeChooserAndroid::ShowDialog( |
| 90 ContentViewCore* content, RenderViewHost* sender, | 95 ContentViewCore* content, RenderViewHost* sender, |
| 91 int type, int year, int month, int day, | 96 int type, int year, int month, int day, |
| 92 int hour, int minute, int second) { | 97 int hour, int minute, int second, |
| 98 int week_year, int week) { |
| 93 if (sender_) | 99 if (sender_) |
| 94 delete sender_; | 100 delete sender_; |
| 95 sender_ = new DateTimeIPCSender(sender); | 101 sender_ = new DateTimeIPCSender(sender); |
| 96 | 102 |
| 97 JNIEnv* env = AttachCurrentThread(); | 103 JNIEnv* env = AttachCurrentThread(); |
| 98 j_date_time_chooser_.Reset(Java_DateTimeChooserAndroid_createDateTimeChooser( | 104 j_date_time_chooser_.Reset(Java_DateTimeChooserAndroid_createDateTimeChooser( |
| 99 env, content->GetJavaObject().obj(), | 105 env, content->GetJavaObject().obj(), |
| 100 reinterpret_cast<intptr_t>(this), | 106 reinterpret_cast<intptr_t>(this), |
| 101 type, year, month, day, hour, minute, second)); | 107 type, year, month, day, hour, minute, second, week_year, week)); |
| 102 } | 108 } |
| 103 | 109 |
| 104 // ---------------------------------------------------------------------------- | 110 // ---------------------------------------------------------------------------- |
| 105 // Native JNI methods | 111 // Native JNI methods |
| 106 // ---------------------------------------------------------------------------- | 112 // ---------------------------------------------------------------------------- |
| 107 bool RegisterDateTimeChooserAndroid(JNIEnv* env) { | 113 bool RegisterDateTimeChooserAndroid(JNIEnv* env) { |
| 108 bool registered = RegisterNativesImpl(env); | 114 bool registered = RegisterNativesImpl(env); |
| 109 if (registered) | 115 if (registered) |
| 110 DateTimeChooserAndroid::InitializeDateInputTypes( | 116 DateTimeChooserAndroid::InitializeDateInputTypes( |
| 111 ui::TEXT_INPUT_TYPE_DATE, | 117 ui::TEXT_INPUT_TYPE_DATE, |
| 112 ui::TEXT_INPUT_TYPE_DATE_TIME, | 118 ui::TEXT_INPUT_TYPE_DATE_TIME, |
| 113 ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL, | 119 ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL, |
| 114 ui::TEXT_INPUT_TYPE_MONTH, | 120 ui::TEXT_INPUT_TYPE_MONTH, |
| 115 ui::TEXT_INPUT_TYPE_TIME); | 121 ui::TEXT_INPUT_TYPE_TIME, |
| 122 ui::TEXT_INPUT_TYPE_WEEK); |
| 116 return registered; | 123 return registered; |
| 117 } | 124 } |
| 118 | 125 |
| 119 } // namespace content | 126 } // namespace content |
| OLD | NEW |