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/system/date/date_view.h" | 5 #include "ash/system/date/date_view.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/system/tray/system_tray_delegate.h" | 8 #include "ash/system/tray/system_tray_delegate.h" |
9 #include "ash/system/tray/tray_constants.h" | 9 #include "ash/system/tray/tray_constants.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 } | 53 } |
54 | 54 |
55 } // namespace | 55 } // namespace |
56 | 56 |
57 BaseDateTimeView::~BaseDateTimeView() { | 57 BaseDateTimeView::~BaseDateTimeView() { |
58 timer_.Stop(); | 58 timer_.Stop(); |
59 } | 59 } |
60 | 60 |
61 void BaseDateTimeView::UpdateText() { | 61 void BaseDateTimeView::UpdateText() { |
62 base::Time now = base::Time::Now(); | 62 base::Time now = base::Time::Now(); |
63 gfx::Size old_size = GetPreferredSize(); | |
64 UpdateTextInternal(now); | 63 UpdateTextInternal(now); |
65 SchedulePaint(); | 64 SchedulePaint(); |
| 65 SetTimer(now); |
| 66 } |
66 | 67 |
| 68 BaseDateTimeView::BaseDateTimeView() { |
| 69 SetTimer(base::Time::Now()); |
| 70 } |
| 71 |
| 72 void BaseDateTimeView::SetTimer(const base::Time& now) { |
67 // Try to set the timer to go off at the next change of the minute. We don't | 73 // Try to set the timer to go off at the next change of the minute. We don't |
68 // want to have the timer go off more than necessary since that will cause | 74 // want to have the timer go off more than necessary since that will cause |
69 // the CPU to wake up and consume power. | 75 // the CPU to wake up and consume power. |
70 base::Time::Exploded exploded; | 76 base::Time::Exploded exploded; |
71 now.LocalExplode(&exploded); | 77 now.LocalExplode(&exploded); |
72 | 78 |
73 // Often this will be called at minute boundaries, and we'll actually want | 79 // Often this will be called at minute boundaries, and we'll actually want |
74 // 60 seconds from now. | 80 // 60 seconds from now. |
75 int seconds_left = 60 - exploded.second; | 81 int seconds_left = 60 - exploded.second; |
76 if (seconds_left == 0) | 82 if (seconds_left == 0) |
77 seconds_left = 60; | 83 seconds_left = 60; |
78 | 84 |
79 // Make sure that the timer fires on the next minute. Without this, if it is | 85 // Make sure that the timer fires on the next minute. Without this, if it is |
80 // called just a teeny bit early, then it will skip the next minute. | 86 // called just a teeny bit early, then it will skip the next minute. |
81 seconds_left += kTimerSlopSeconds; | 87 seconds_left += kTimerSlopSeconds; |
82 | 88 |
83 timer_.Stop(); | 89 timer_.Stop(); |
84 timer_.Start( | 90 timer_.Start( |
85 FROM_HERE, base::TimeDelta::FromSeconds(seconds_left), | 91 FROM_HERE, base::TimeDelta::FromSeconds(seconds_left), |
86 this, &BaseDateTimeView::UpdateText); | 92 this, &BaseDateTimeView::UpdateText); |
87 } | 93 } |
88 | 94 |
89 BaseDateTimeView::BaseDateTimeView() { | |
90 } | |
91 | |
92 void BaseDateTimeView::ChildPreferredSizeChanged(views::View* child) { | 95 void BaseDateTimeView::ChildPreferredSizeChanged(views::View* child) { |
93 views::View::PreferredSizeChanged(); | 96 views::View::PreferredSizeChanged(); |
94 if (GetWidget()) | 97 if (GetWidget()) |
95 GetWidget()->SetSize(GetWidget()->GetContentsView()->GetPreferredSize()); | 98 GetWidget()->SetSize(GetWidget()->GetContentsView()->GetPreferredSize()); |
96 } | 99 } |
97 | 100 |
98 void BaseDateTimeView::OnLocaleChanged() { | 101 void BaseDateTimeView::OnLocaleChanged() { |
99 UpdateText(); | 102 UpdateText(); |
100 } | 103 } |
101 | 104 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 } | 162 } |
160 | 163 |
161 bool TimeView::PerformAction(const views::Event& event) { | 164 bool TimeView::PerformAction(const views::Event& event) { |
162 return false; | 165 return false; |
163 } | 166 } |
164 | 167 |
165 | 168 |
166 } // namespace tray | 169 } // namespace tray |
167 } // namespace internal | 170 } // namespace internal |
168 } // namespace ash | 171 } // namespace ash |
OLD | NEW |