OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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/renderer/renderer_date_time_picker.h" | |
6 | |
7 #include "content/common/view_messages.h" | |
8 #include "content/renderer/render_view_impl.h" | |
9 | |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDateTimeChooserCom pletion.h" | |
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDateTimeChooserPar ams.h" | |
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDateTimeInputType. h" | |
13 | |
14 namespace content { | |
15 | |
16 using WebKit::WebString; | |
17 | |
18 RendererDateTimePicker::RendererDateTimePicker( | |
19 RenderViewImpl* sender, | |
20 const WebKit::WebDateTimeChooserParams& params, | |
21 WebKit::WebDateTimeChooserCompletion* completion) | |
22 : RenderViewObserver(sender), | |
23 chooser_params_(params), | |
24 chooser_completion_(completion) { | |
25 } | |
26 | |
27 RendererDateTimePicker::~RendererDateTimePicker() { | |
28 } | |
29 | |
30 static ui::TextInputType ExtractType( | |
31 const WebKit::WebDateTimeChooserParams& source) { | |
32 | |
33 if (source.type == WebKit::WebDateTimeInputTypeDate) | |
34 return ui::TEXT_INPUT_TYPE_DATE; | |
35 if (source.type == WebKit::WebDateTimeInputTypeDateTime) | |
36 return ui::TEXT_INPUT_TYPE_DATE_TIME; | |
37 if (source.type == WebKit::WebDateTimeInputTypeDateTimeLocal) | |
38 return ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL; | |
39 if (source.type == WebKit::WebDateTimeInputTypeMonth) | |
40 return ui::TEXT_INPUT_TYPE_MONTH; | |
41 if (source.type == WebKit::WebDateTimeInputTypeTime) | |
42 return ui::TEXT_INPUT_TYPE_TIME; | |
43 if (source.type == WebKit::WebDateTimeInputTypeWeek) | |
44 return ui::TEXT_INPUT_TYPE_WEEK; | |
45 return ui::TEXT_INPUT_TYPE_NONE; | |
46 } | |
47 | |
48 bool RendererDateTimePicker::Open() { | |
49 ViewHostMsg_TextInputState_Params p; | |
50 p.type = ExtractType(chooser_params_); | |
51 p.value = chooser_params_.currentValue.utf8(); | |
52 p.show_ime_if_needed = true; | |
53 Send(new ViewHostMsg_TextInputStateChanged(routing_id(), p)); | |
bulach
2012/12/07 18:10:13
since it's changing this anyways, why not go ahead
Miguel Garcia
2012/12/07 19:04:35
I thought about it but in order to make it work ri
| |
54 return true; | |
55 } | |
56 | |
57 bool RendererDateTimePicker::OnMessageReceived( | |
58 const IPC::Message& message) { | |
59 bool handled = true; | |
60 IPC_BEGIN_MESSAGE_MAP(RendererDateTimePicker, message) | |
61 IPC_MESSAGE_HANDLER(ViewMsg_ReplaceDateTime, OnReplaceDateTime) | |
62 IPC_MESSAGE_HANDLER(ViewMsg_CancelDateTimeDialog, OnCancel) | |
63 IPC_MESSAGE_UNHANDLED(handled = false) | |
64 IPC_END_MESSAGE_MAP() | |
65 return handled; | |
66 } | |
67 | |
68 void RendererDateTimePicker::OnReplaceDateTime(const string16& new_date) { | |
69 if (chooser_completion_) | |
70 chooser_completion_->didChooseValue(new_date); | |
71 } | |
72 | |
73 void RendererDateTimePicker::OnCancel() { | |
74 if (chooser_completion_) | |
75 chooser_completion_->didCancelChooser(); | |
76 } | |
77 | |
78 } // namespace content | |
OLD | NEW |