Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2396)

Side by Side Diff: athena/system/time_view.cc

Issue 863033002: Delete athena/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « athena/system/time_view.h ('k') | athena/test/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "athena/system/time_view.h"
6
7 #include "base/i18n/time_formatting.h"
8 #include "third_party/skia/include/core/SkColor.h"
9 #include "ui/views/border.h"
10
11 namespace athena {
12 namespace {
13
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;
17
18 } // namespace
19
20 TimeView::TimeView(SystemUI::ColorScheme color_scheme) {
21 SetHorizontalAlignment(gfx::ALIGN_LEFT);
22 SetEnabledColor((color_scheme == SystemUI::COLOR_SCHEME_LIGHT)
23 ? SK_ColorWHITE
24 : SK_ColorDKGRAY);
25 SetAutoColorReadabilityEnabled(false);
26 SetFontList(gfx::FontList().DeriveWithStyle(gfx::Font::BOLD));
27 SetSubpixelRenderingEnabled(false);
28
29 const int kHorizontalSpacing = 10;
30 const int kVerticalSpacing = 3;
31 SetBorder(views::Border::CreateEmptyBorder(kVerticalSpacing,
32 kHorizontalSpacing,
33 kVerticalSpacing,
34 kHorizontalSpacing));
35
36 UpdateText();
37 }
38
39 TimeView::~TimeView() {
40 }
41
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);
48
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)
53 seconds_left = 60;
54
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;
58
59 timer_.Stop();
60 timer_.Start(
61 FROM_HERE, base::TimeDelta::FromSeconds(seconds_left),
62 this, &TimeView::UpdateText);
63 }
64
65 void TimeView::UpdateText() {
66 base::Time now = base::Time::Now();
67 SetText(base::TimeFormatTimeOfDayWithHourClockType(
68 now, base::k12HourClock, base::kKeepAmPm));
69 SetTimer(now);
70 }
71
72 } // namespace athena
OLDNEW
« no previous file with comments | « athena/system/time_view.h ('k') | athena/test/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698