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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(); | 63 gfx::Size old_size = GetPreferredSize(); |
64 UpdateTextInternal(now); | 64 UpdateTextInternal(now); |
65 if (GetWidget() && GetPreferredSize() != old_size) { | |
66 // Forcing the widget to the new size is sufficient. The positioning is | |
67 // taken care of by the layout manager (ShelfLayoutManager). | |
68 GetWidget()->SetSize(GetPreferredSize()); | |
69 } | |
70 SchedulePaint(); | 65 SchedulePaint(); |
71 | 66 |
72 // Try to set the timer to go off at the next change of the minute. We don't | 67 // Try to set the timer to go off at the next change of the minute. We don't |
73 // want to have the timer go off more than necessary since that will cause | 68 // want to have the timer go off more than necessary since that will cause |
74 // the CPU to wake up and consume power. | 69 // the CPU to wake up and consume power. |
75 base::Time::Exploded exploded; | 70 base::Time::Exploded exploded; |
76 now.LocalExplode(&exploded); | 71 now.LocalExplode(&exploded); |
77 | 72 |
78 // Often this will be called at minute boundaries, and we'll actually want | 73 // Often this will be called at minute boundaries, and we'll actually want |
79 // 60 seconds from now. | 74 // 60 seconds from now. |
80 int seconds_left = 60 - exploded.second; | 75 int seconds_left = 60 - exploded.second; |
81 if (seconds_left == 0) | 76 if (seconds_left == 0) |
82 seconds_left = 60; | 77 seconds_left = 60; |
83 | 78 |
84 // Make sure that the timer fires on the next minute. Without this, if it is | 79 // Make sure that the timer fires on the next minute. Without this, if it is |
85 // called just a teeny bit early, then it will skip the next minute. | 80 // called just a teeny bit early, then it will skip the next minute. |
86 seconds_left += kTimerSlopSeconds; | 81 seconds_left += kTimerSlopSeconds; |
87 | 82 |
88 timer_.Stop(); | 83 timer_.Stop(); |
89 timer_.Start( | 84 timer_.Start( |
90 FROM_HERE, base::TimeDelta::FromSeconds(seconds_left), | 85 FROM_HERE, base::TimeDelta::FromSeconds(seconds_left), |
91 this, &BaseDateTimeView::UpdateText); | 86 this, &BaseDateTimeView::UpdateText); |
92 } | 87 } |
93 | 88 |
94 BaseDateTimeView::BaseDateTimeView() { | 89 BaseDateTimeView::BaseDateTimeView() { |
95 } | 90 } |
96 | 91 |
| 92 void BaseDateTimeView::ChildPreferredSizeChanged(views::View* child) { |
| 93 views::View::PreferredSizeChanged(); |
| 94 if (GetWidget()) |
| 95 GetWidget()->SetSize(GetWidget()->GetContentsView()->GetPreferredSize()); |
| 96 } |
| 97 |
97 void BaseDateTimeView::OnLocaleChanged() { | 98 void BaseDateTimeView::OnLocaleChanged() { |
98 UpdateText(); | 99 UpdateText(); |
99 } | 100 } |
100 | 101 |
101 DateView::DateView() : actionable_(false) { | 102 DateView::DateView() : actionable_(false) { |
102 SetLayoutManager( | 103 SetLayoutManager( |
103 new views::BoxLayout( | 104 new views::BoxLayout( |
104 views::BoxLayout::kVertical, 0, 0, kTrayPopupTextSpacingVertical)); | 105 views::BoxLayout::kVertical, 0, 0, kTrayPopupTextSpacingVertical)); |
105 date_label_ = CreateLabel(); | 106 date_label_ = CreateLabel(); |
106 day_of_week_label_ = CreateLabel(); | 107 day_of_week_label_ = CreateLabel(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 } | 159 } |
159 | 160 |
160 bool TimeView::PerformAction(const views::Event& event) { | 161 bool TimeView::PerformAction(const views::Event& event) { |
161 return false; | 162 return false; |
162 } | 163 } |
163 | 164 |
164 | 165 |
165 } // namespace tray | 166 } // namespace tray |
166 } // namespace internal | 167 } // namespace internal |
167 } // namespace ash | 168 } // namespace ash |
OLD | NEW |