| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/renderer/renderer_date_time_picker.h" | 5 #include "content/renderer/renderer_date_time_picker.h" |
| 6 | 6 |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "content/common/view_messages.h" | 8 #include "content/common/view_messages.h" |
| 9 #include "content/renderer/date_time_formatter.h" |
| 9 #include "content/renderer/render_view_impl.h" | 10 #include "content/renderer/render_view_impl.h" |
| 10 | 11 |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDateTimeChooserCom
pletion.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDateTimeChooserCom
pletion.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDateTimeChooserPar
ams.h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDateTimeChooserPar
ams.h" |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDateTimeInputType.
h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDateTimeInputType.
h" |
| 14 | 15 |
| 16 using WebKit::WebString; |
| 17 |
| 15 namespace content { | 18 namespace content { |
| 16 | 19 |
| 17 using WebKit::WebString; | |
| 18 | |
| 19 RendererDateTimePicker::RendererDateTimePicker( | 20 RendererDateTimePicker::RendererDateTimePicker( |
| 20 RenderViewImpl* sender, | 21 RenderViewImpl* sender, |
| 21 const WebKit::WebDateTimeChooserParams& params, | 22 const WebKit::WebDateTimeChooserParams& params, |
| 22 WebKit::WebDateTimeChooserCompletion* completion) | 23 WebKit::WebDateTimeChooserCompletion* completion) |
| 23 : RenderViewObserver(sender), | 24 : RenderViewObserver(sender), |
| 24 chooser_params_(params), | 25 chooser_params_(params), |
| 25 chooser_completion_(completion) { | 26 chooser_completion_(completion){ |
| 26 } | 27 } |
| 27 | 28 |
| 28 RendererDateTimePicker::~RendererDateTimePicker() { | 29 RendererDateTimePicker::~RendererDateTimePicker() { |
| 29 } | 30 } |
| 30 | 31 |
| 31 static ui::TextInputType ExtractType( | 32 bool RendererDateTimePicker::Open() { |
| 32 const WebKit::WebDateTimeChooserParams& source) { | 33 DateTimeFormatter parser(chooser_params_); |
| 34 std::string test_s = chooser_params_.currentValue.utf8(); |
| 33 | 35 |
| 34 if (source.type == WebKit::WebDateTimeInputTypeDate) | 36 ViewHostMsg_DateTimeDialogValue_Params message; |
| 35 return ui::TEXT_INPUT_TYPE_DATE; | 37 message.year = parser.GetYear(); |
| 36 if (source.type == WebKit::WebDateTimeInputTypeDateTime) | 38 message.month = parser.GetMonth(); |
| 37 return ui::TEXT_INPUT_TYPE_DATE_TIME; | 39 message.day = parser.GetDay(); |
| 38 if (source.type == WebKit::WebDateTimeInputTypeDateTimeLocal) | 40 message.hour = parser.GetHour(); |
| 39 return ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL; | 41 message.minute = parser.GetMinute(); |
| 40 if (source.type == WebKit::WebDateTimeInputTypeMonth) | 42 message.second = parser.GetSecond(); |
| 41 return ui::TEXT_INPUT_TYPE_MONTH; | 43 message.dialog_type = parser.GetType(); |
| 42 if (source.type == WebKit::WebDateTimeInputTypeTime) | |
| 43 return ui::TEXT_INPUT_TYPE_TIME; | |
| 44 if (source.type == WebKit::WebDateTimeInputTypeWeek) | |
| 45 return ui::TEXT_INPUT_TYPE_WEEK; | |
| 46 return ui::TEXT_INPUT_TYPE_NONE; | |
| 47 } | |
| 48 | 44 |
| 49 bool RendererDateTimePicker::Open() { | 45 Send(new ViewHostMsg_OpenDateTimeDialog(routing_id(), message)); |
| 50 Send(new ViewHostMsg_OpenDateTimeDialog( | |
| 51 routing_id(), ExtractType(chooser_params_), | |
| 52 chooser_params_.currentValue.utf8())); | |
| 53 return true; | 46 return true; |
| 54 } | 47 } |
| 55 | 48 |
| 56 bool RendererDateTimePicker::OnMessageReceived( | 49 bool RendererDateTimePicker::OnMessageReceived( |
| 57 const IPC::Message& message) { | 50 const IPC::Message& message) { |
| 58 bool handled = true; | 51 bool handled = true; |
| 59 IPC_BEGIN_MESSAGE_MAP(RendererDateTimePicker, message) | 52 IPC_BEGIN_MESSAGE_MAP(RendererDateTimePicker, message) |
| 60 IPC_MESSAGE_HANDLER(ViewMsg_ReplaceDateTime, OnReplaceDateTime) | 53 IPC_MESSAGE_HANDLER(ViewMsg_ReplaceDateTime, OnReplaceDateTime) |
| 61 IPC_MESSAGE_HANDLER(ViewMsg_CancelDateTimeDialog, OnCancel) | 54 IPC_MESSAGE_HANDLER(ViewMsg_CancelDateTimeDialog, OnCancel) |
| 62 IPC_MESSAGE_UNHANDLED(handled = false) | 55 IPC_MESSAGE_UNHANDLED(handled = false) |
| 63 IPC_END_MESSAGE_MAP() | 56 IPC_END_MESSAGE_MAP() |
| 64 return handled; | 57 return handled; |
| 65 } | 58 } |
| 66 | 59 |
| 67 void RendererDateTimePicker::OnReplaceDateTime(const string16& new_date) { | 60 void RendererDateTimePicker::OnReplaceDateTime( |
| 61 const ViewHostMsg_DateTimeDialogValue_Params& value) { |
| 62 |
| 63 DateTimeFormatter formatter( |
| 64 static_cast<ui::TextInputType>(value.dialog_type), |
| 65 value.year, value.month, value.day, |
| 66 value.hour, value.minute, value.second); |
| 67 |
| 68 if (chooser_completion_) | 68 if (chooser_completion_) |
| 69 chooser_completion_->didChooseValue(new_date); | 69 chooser_completion_->didChooseValue(WebString::fromUTF8( |
| 70 formatter.GetFormattedValue().c_str())); |
| 70 } | 71 } |
| 71 | 72 |
| 72 void RendererDateTimePicker::OnCancel() { | 73 void RendererDateTimePicker::OnCancel() { |
| 73 if (chooser_completion_) | 74 if (chooser_completion_) |
| 74 chooser_completion_->didCancelChooser(); | 75 chooser_completion_->didCancelChooser(); |
| 75 } | 76 } |
| 76 | 77 |
| 77 } // namespace content | 78 } // namespace content |
| OLD | NEW |