| 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 "ash/common/system/date/date_view.h" | 5 #include "ash/common/system/date/date_view.h" |
| 6 | 6 |
| 7 #include "ash/common/material_design/material_design_controller.h" | 7 #include "ash/common/material_design/material_design_controller.h" |
| 8 #include "ash/common/system/tray/system_tray_controller.h" | 8 #include "ash/common/system/tray/system_tray_controller.h" |
| 9 #include "ash/common/system/tray/tray_constants.h" | 9 #include "ash/common/system/tray/tray_constants.h" |
| 10 #include "ash/common/system/tray/tray_popup_item_style.h" | 10 #include "ash/common/system/tray/tray_popup_item_style.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 const int kVerticalClockMinutesTopOffsetMD = -2; | 50 const int kVerticalClockMinutesTopOffsetMD = -2; |
| 51 | 51 |
| 52 // Leading padding used to draw the tray background to the left of the clock | 52 // Leading padding used to draw the tray background to the left of the clock |
| 53 // when the shelf is vertically aligned. | 53 // when the shelf is vertically aligned. |
| 54 const int kClockLeadingPadding = 8; | 54 const int kClockLeadingPadding = 8; |
| 55 | 55 |
| 56 bool UseMd() { | 56 bool UseMd() { |
| 57 return MaterialDesignController::IsSystemTrayMenuMaterial(); | 57 return MaterialDesignController::IsSystemTrayMenuMaterial(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 base::string16 FormatDateWithPattern(const base::Time& time, | |
| 61 const char* pattern) { | |
| 62 UErrorCode status = U_ZERO_ERROR; | |
| 63 std::unique_ptr<icu::DateTimePatternGenerator> generator( | |
| 64 icu::DateTimePatternGenerator::createInstance(status)); | |
| 65 DCHECK(U_SUCCESS(status)); | |
| 66 icu::UnicodeString generated_pattern = | |
| 67 generator->getBestPattern(icu::UnicodeString(pattern), status); | |
| 68 DCHECK(U_SUCCESS(status)); | |
| 69 icu::SimpleDateFormat simple_formatter(generated_pattern, status); | |
| 70 DCHECK(U_SUCCESS(status)); | |
| 71 icu::UnicodeString date_string; | |
| 72 simple_formatter.format(static_cast<UDate>(time.ToDoubleT() * 1000), | |
| 73 date_string, status); | |
| 74 DCHECK(U_SUCCESS(status)); | |
| 75 return base::string16(date_string.getBuffer(), | |
| 76 static_cast<size_t>(date_string.length())); | |
| 77 } | |
| 78 | |
| 79 base::string16 FormatDate(const base::Time& time) { | 60 base::string16 FormatDate(const base::Time& time) { |
| 80 if (UseMd()) { | 61 if (UseMd()) { |
| 81 // Use 'short' month format (e.g., "Oct") followed by non-padded day of | 62 // Use 'short' month format (e.g., "Oct") followed by non-padded day of |
| 82 // month (e.g., "2", "10"). | 63 // month (e.g., "2", "10"). |
| 83 return FormatDateWithPattern(time, "LLLd"); | 64 return base::i18n::TimeFormatWithPattern(time, "LLLd"); |
| 84 } else { | 65 } else { |
| 85 icu::UnicodeString date_string; | 66 return base::i18n::TimeFormatShortDate(time); |
| 86 std::unique_ptr<icu::DateFormat> formatter( | |
| 87 icu::DateFormat::createDateInstance(icu::DateFormat::kMedium)); | |
| 88 formatter->format(static_cast<UDate>(time.ToDoubleT() * 1000), date_string); | |
| 89 return base::string16(date_string.getBuffer(), | |
| 90 static_cast<size_t>(date_string.length())); | |
| 91 } | 67 } |
| 92 } | 68 } |
| 93 | 69 |
| 94 base::string16 FormatDayOfWeek(const base::Time& time) { | 70 base::string16 FormatDayOfWeek(const base::Time& time) { |
| 95 // Use 'short' day of week format (e.g., "Wed"). | 71 // Use 'short' day of week format (e.g., "Wed"). |
| 96 return FormatDateWithPattern(time, "EEE"); | 72 return base::i18n::TimeFormatWithPattern(time, "EEE"); |
| 97 } | 73 } |
| 98 | 74 |
| 99 } // namespace | 75 } // namespace |
| 100 | 76 |
| 101 BaseDateTimeView::~BaseDateTimeView() { | 77 BaseDateTimeView::~BaseDateTimeView() { |
| 102 timer_.Stop(); | 78 timer_.Stop(); |
| 103 } | 79 } |
| 104 | 80 |
| 105 void BaseDateTimeView::UpdateText() { | 81 void BaseDateTimeView::UpdateText() { |
| 106 base::Time now = base::Time::Now(); | 82 base::Time now = base::Time::Now(); |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 } | 375 } |
| 400 | 376 |
| 401 void TimeView::SetupLabel(views::Label* label) { | 377 void TimeView::SetupLabel(views::Label* label) { |
| 402 label->set_owned_by_client(); | 378 label->set_owned_by_client(); |
| 403 SetupLabelForTray(label); | 379 SetupLabelForTray(label); |
| 404 label->SetElideBehavior(gfx::NO_ELIDE); | 380 label->SetElideBehavior(gfx::NO_ELIDE); |
| 405 } | 381 } |
| 406 | 382 |
| 407 } // namespace tray | 383 } // namespace tray |
| 408 } // namespace ash | 384 } // namespace ash |
| OLD | NEW |