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, int week); |
28 void CancelDialog(); | 28 void CancelDialog(); |
29 | 29 |
30 private: | 30 private: |
31 DISALLOW_COPY_AND_ASSIGN(DateTimeIPCSender); | 31 DISALLOW_COPY_AND_ASSIGN(DateTimeIPCSender); |
32 }; | 32 }; |
33 | 33 |
34 DateTimeChooserAndroid::DateTimeIPCSender::DateTimeIPCSender( | 34 DateTimeChooserAndroid::DateTimeIPCSender::DateTimeIPCSender( |
35 RenderViewHost* sender) | 35 RenderViewHost* sender) |
36 : RenderViewHostObserver(sender) { | 36 : RenderViewHostObserver(sender) { |
37 } | 37 } |
38 | 38 |
39 void DateTimeChooserAndroid::DateTimeIPCSender::ReplaceDateTime( | 39 void DateTimeChooserAndroid::DateTimeIPCSender::ReplaceDateTime( |
40 int dialog_type, | 40 int dialog_type, |
41 int year, int month, int day, int hour, int minute, int second) { | 41 int year, int month, int day, int hour, int minute, int second, int week) { |
42 ViewHostMsg_DateTimeDialogValue_Params value; | 42 ViewHostMsg_DateTimeDialogValue_Params value; |
43 value.year = year; | 43 value.year = year; |
44 value.month = month; | 44 value.month = month; |
45 value.day = day; | 45 value.day = day; |
46 value.hour = hour; | 46 value.hour = hour; |
47 value.minute = minute; | 47 value.minute = minute; |
48 value.second = second; | 48 value.second = second; |
| 49 value.week = week; |
49 value.dialog_type = dialog_type; | 50 value.dialog_type = dialog_type; |
50 Send(new ViewMsg_ReplaceDateTime(routing_id(), value)); | 51 Send(new ViewMsg_ReplaceDateTime(routing_id(), value)); |
51 } | 52 } |
52 | 53 |
53 void DateTimeChooserAndroid::DateTimeIPCSender::CancelDialog() { | 54 void DateTimeChooserAndroid::DateTimeIPCSender::CancelDialog() { |
54 Send(new ViewMsg_CancelDateTimeDialog(routing_id())); | 55 Send(new ViewMsg_CancelDateTimeDialog(routing_id())); |
55 } | 56 } |
56 | 57 |
57 // DateTimeChooserAndroid implementation | 58 // DateTimeChooserAndroid implementation |
58 DateTimeChooserAndroid::DateTimeChooserAndroid() | 59 DateTimeChooserAndroid::DateTimeChooserAndroid() |
59 : sender_(NULL) { | 60 : sender_(NULL) { |
60 } | 61 } |
61 | 62 |
62 DateTimeChooserAndroid::~DateTimeChooserAndroid() { | 63 DateTimeChooserAndroid::~DateTimeChooserAndroid() { |
63 } | 64 } |
64 | 65 |
65 // static | 66 // static |
66 void DateTimeChooserAndroid::InitializeDateInputTypes( | 67 void DateTimeChooserAndroid::InitializeDateInputTypes( |
67 int text_input_type_date, int text_input_type_date_time, | 68 int text_input_type_date, int text_input_type_date_time, |
68 int text_input_type_date_time_local, int text_input_type_month, | 69 int text_input_type_date_time_local, int text_input_type_month, |
69 int text_input_type_time) { | 70 int text_input_type_time, int text_input_type_week) { |
70 JNIEnv* env = AttachCurrentThread(); | 71 JNIEnv* env = AttachCurrentThread(); |
71 Java_DateTimeChooserAndroid_initializeDateInputTypes( | 72 Java_DateTimeChooserAndroid_initializeDateInputTypes( |
72 env, | 73 env, |
73 text_input_type_date, text_input_type_date_time, | 74 text_input_type_date, text_input_type_date_time, |
74 text_input_type_date_time_local, text_input_type_month, | 75 text_input_type_date_time_local, text_input_type_month, |
75 text_input_type_time); | 76 text_input_type_time, text_input_type_week); |
76 } | 77 } |
77 | 78 |
78 void DateTimeChooserAndroid::ReplaceDateTime( | 79 void DateTimeChooserAndroid::ReplaceDateTime( |
79 JNIEnv* env, jobject, int dialog_type, | 80 JNIEnv* env, jobject, int dialog_type, |
80 int year, int month, int day, int hour, int minute, int second) { | 81 int year, int month, int day, int hour, int minute, int second, int week) { |
81 sender_->ReplaceDateTime( | 82 sender_->ReplaceDateTime( |
82 dialog_type, year, month, day, hour, minute, second); | 83 dialog_type, year, month, day, hour, minute, second, week); |
83 } | 84 } |
84 | 85 |
85 void DateTimeChooserAndroid::CancelDialog(JNIEnv* env, jobject) { | 86 void DateTimeChooserAndroid::CancelDialog(JNIEnv* env, jobject) { |
86 sender_->CancelDialog(); | 87 sender_->CancelDialog(); |
87 } | 88 } |
88 | 89 |
89 void DateTimeChooserAndroid::ShowDialog( | 90 void DateTimeChooserAndroid::ShowDialog( |
90 ContentViewCore* content, RenderViewHost* sender, | 91 ContentViewCore* content, RenderViewHost* sender, |
91 int type, int year, int month, int day, | 92 int type, int year, int month, int day, |
92 int hour, int minute, int second, double min, double max) { | 93 int hour, int minute, int second, int week, double min, double max) { |
93 if (sender_) | 94 if (sender_) |
94 delete sender_; | 95 delete sender_; |
95 sender_ = new DateTimeIPCSender(sender); | 96 sender_ = new DateTimeIPCSender(sender); |
96 | 97 |
97 JNIEnv* env = AttachCurrentThread(); | 98 JNIEnv* env = AttachCurrentThread(); |
98 j_date_time_chooser_.Reset(Java_DateTimeChooserAndroid_createDateTimeChooser( | 99 j_date_time_chooser_.Reset(Java_DateTimeChooserAndroid_createDateTimeChooser( |
99 env, content->GetJavaObject().obj(), | 100 env, content->GetJavaObject().obj(), |
100 reinterpret_cast<intptr_t>(this), | 101 reinterpret_cast<intptr_t>(this), |
101 type, year, month, day, hour, minute, second, min, max)); | 102 type, year, month, day, hour, minute, second, week, min, max)); |
102 } | 103 } |
103 | 104 |
104 // ---------------------------------------------------------------------------- | 105 // ---------------------------------------------------------------------------- |
105 // Native JNI methods | 106 // Native JNI methods |
106 // ---------------------------------------------------------------------------- | 107 // ---------------------------------------------------------------------------- |
107 bool RegisterDateTimeChooserAndroid(JNIEnv* env) { | 108 bool RegisterDateTimeChooserAndroid(JNIEnv* env) { |
108 bool registered = RegisterNativesImpl(env); | 109 bool registered = RegisterNativesImpl(env); |
109 if (registered) | 110 if (registered) |
110 DateTimeChooserAndroid::InitializeDateInputTypes( | 111 DateTimeChooserAndroid::InitializeDateInputTypes( |
111 ui::TEXT_INPUT_TYPE_DATE, | 112 ui::TEXT_INPUT_TYPE_DATE, |
112 ui::TEXT_INPUT_TYPE_DATE_TIME, | 113 ui::TEXT_INPUT_TYPE_DATE_TIME, |
113 ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL, | 114 ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL, |
114 ui::TEXT_INPUT_TYPE_MONTH, | 115 ui::TEXT_INPUT_TYPE_MONTH, |
115 ui::TEXT_INPUT_TYPE_TIME); | 116 ui::TEXT_INPUT_TYPE_TIME, |
| 117 ui::TEXT_INPUT_TYPE_WEEK); |
116 return registered; | 118 return registered; |
117 } | 119 } |
118 | 120 |
119 } // namespace content | 121 } // namespace content |
OLD | NEW |