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

Unified Diff: athena/system/time_view.cc

Issue 483363003: [Athena] Add status icons and system time to the desktop background (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« athena/system/time_view.h ('K') | « athena/system/time_view.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: athena/system/time_view.cc
diff --git a/athena/system/time_view.cc b/athena/system/time_view.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2a3d1309d3290f3d4f2aa21c42ffa71b0c9019f5
--- /dev/null
+++ b/athena/system/time_view.cc
@@ -0,0 +1,69 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "athena/system/time_view.h"
+
+#include "base/i18n/time_formatting.h"
+#include "third_party/skia/include/core/SkColor.h"
+#include "ui/views/border.h"
+
+namespace athena {
+namespace {
+
+// Amount of slop to add into the timer to make sure we're into the next minute
+// when the timer goes off.
+const int kTimerSlopSeconds = 1;
+
+} // namespace
+
+TimeView::TimeView() {
+ SetHorizontalAlignment(gfx::ALIGN_LEFT);
+ SetEnabledColor(SK_ColorWHITE);
+ SetAutoColorReadabilityEnabled(false);
+ SetFontList(gfx::FontList().DeriveWithStyle(gfx::Font::BOLD));
+
+ const int kHorizontalSpacing = 10;
+ const int kVerticalSpacing = 3;
+ SetBorder(views::Border::CreateEmptyBorder(kVerticalSpacing,
+ kHorizontalSpacing,
+ kVerticalSpacing,
+ kHorizontalSpacing));
+
+ UpdateText();
+}
+
+TimeView::~TimeView() {
+}
+
+void TimeView::SetTimer(const base::Time& now) {
+ // Try to set the timer to go off at the next change of the minute. We don't
+ // want to have the timer go off more than necessary since that will cause
+ // the CPU to wake up and consume power.
+ base::Time::Exploded exploded;
+ now.LocalExplode(&exploded);
+
+ // Often this will be called at minute boundaries, and we'll actually want
+ // 60 seconds from now.
+ int seconds_left = 60 - exploded.second;
+ if (seconds_left == 0)
+ seconds_left = 60;
+
+ // Make sure that the timer fires on the next minute. Without this, if it is
+ // called just a teeny bit early, then it will skip the next minute.
+ seconds_left += kTimerSlopSeconds;
+
+ timer_.Stop();
+ timer_.Start(
+ FROM_HERE, base::TimeDelta::FromSeconds(seconds_left),
+ this, &TimeView::UpdateText);
+}
+
+void TimeView::UpdateText() {
+ base::Time now = base::Time::Now();
+ SetText(base::TimeFormatTimeOfDayWithHourClockType(
+ now, base::k12HourClock, base::kKeepAmPm));
+ SetTimer(now);
+}
+
+} // namespace athena
« athena/system/time_view.h ('K') | « athena/system/time_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698