1 // Copyright 2014 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.
5 #include "athena/system/time_view.h"
7 #include "base/i18n/time_formatting.h"
8 #include "third_party/skia/include/core/SkColor.h"
9 #include "ui/views/border.h"
14 // Amount of slop to add into the timer to make sure we're into the next minute
15 // when the timer goes off.
16 const int kTimerSlopSeconds
= 1;
20 TimeView::TimeView(SystemUI::ColorScheme color_scheme
) {
21 SetHorizontalAlignment(gfx::ALIGN_LEFT
);
22 SetEnabledColor((color_scheme
== SystemUI::COLOR_SCHEME_LIGHT
)
25 SetAutoColorReadabilityEnabled(false);
26 SetFontList(gfx::FontList().DeriveWithStyle(gfx::Font::BOLD
));
27 SetSubpixelRenderingEnabled(false);
29 const int kHorizontalSpacing
= 10;
30 const int kVerticalSpacing
= 3;
31 SetBorder(views::Border::CreateEmptyBorder(kVerticalSpacing
,
39 TimeView::~TimeView() {
42 void TimeView::SetTimer(base::Time now
) {
43 // Try to set the timer to go off at the next change of the minute. We don't
44 // want to have the timer go off more than necessary since that will cause
45 // the CPU to wake up and consume power.
46 base::Time::Exploded exploded
;
47 now
.LocalExplode(&exploded
);
49 // Often this will be called at minute boundaries, and we'll actually want
50 // 60 seconds from now.
51 int seconds_left
= 60 - exploded
.second
;
52 if (seconds_left
== 0)
55 // Make sure that the timer fires on the next minute. Without this, if it is
56 // called just a teeny bit early, then it will skip the next minute.
57 seconds_left
+= kTimerSlopSeconds
;
61 FROM_HERE
, base::TimeDelta::FromSeconds(seconds_left
),
62 this, &TimeView::UpdateText
);
65 void TimeView::UpdateText() {
66 base::Time now
= base::Time::Now();
67 SetText(base::TimeFormatTimeOfDayWithHourClockType(
68 now
, base::k12HourClock
, base::kKeepAmPm
));