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/i18n/time_formatting.h" | 10 #include "base/i18n/time_formatting.h" |
11 #include "base/time.h" | 11 #include "base/time.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "ui/views/controls/label.h" | 13 #include "ui/views/controls/label.h" |
14 #include "ui/views/layout/box_layout.h" | 14 #include "ui/views/layout/box_layout.h" |
| 15 #include "ui/views/layout/grid_layout.h" |
15 #include "ui/views/widget/widget.h" | 16 #include "ui/views/widget/widget.h" |
16 #include "unicode/datefmt.h" | 17 #include "unicode/datefmt.h" |
17 | 18 |
18 namespace ash { | 19 namespace ash { |
19 namespace internal { | 20 namespace internal { |
20 namespace tray { | 21 namespace tray { |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 // Amount of slop to add into the timer to make sure we're into the next minute | 25 // Amount of slop to add into the timer to make sure we're into the next minute |
25 // when the timer goes off. | 26 // when the timer goes off. |
26 const int kTimerSlopSeconds = 1; | 27 const int kTimerSlopSeconds = 1; |
27 | 28 |
| 29 // Top number text color of vertical clock. |
| 30 const SkColor kVerticalClockHourColor = SkColorSetRGB(0xBA, 0xBA, 0xBA); |
| 31 |
28 string16 FormatDate(const base::Time& time) { | 32 string16 FormatDate(const base::Time& time) { |
29 icu::UnicodeString date_string; | 33 icu::UnicodeString date_string; |
30 scoped_ptr<icu::DateFormat> formatter( | 34 scoped_ptr<icu::DateFormat> formatter( |
31 icu::DateFormat::createDateInstance(icu::DateFormat::kMedium)); | 35 icu::DateFormat::createDateInstance(icu::DateFormat::kMedium)); |
32 formatter->format(static_cast<UDate>(time.ToDoubleT() * 1000), date_string); | 36 formatter->format(static_cast<UDate>(time.ToDoubleT() * 1000), date_string); |
33 return string16(date_string.getBuffer(), | 37 return string16(date_string.getBuffer(), |
34 static_cast<size_t>(date_string.length())); | 38 static_cast<size_t>(date_string.length())); |
35 } | 39 } |
36 | 40 |
37 string16 FormatDayOfWeek(const base::Time& time) { | 41 string16 FormatDayOfWeek(const base::Time& time) { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 } | 151 } |
148 | 152 |
149 void DateView::OnMouseExited(const views::MouseEvent& event) { | 153 void DateView::OnMouseExited(const views::MouseEvent& event) { |
150 if (!actionable_) | 154 if (!actionable_) |
151 return; | 155 return; |
152 date_label_->SetEnabledColor(kHeaderTextColorNormal); | 156 date_label_->SetEnabledColor(kHeaderTextColorNormal); |
153 day_of_week_label_->SetEnabledColor(kHeaderTextColorNormal); | 157 day_of_week_label_->SetEnabledColor(kHeaderTextColorNormal); |
154 SchedulePaint(); | 158 SchedulePaint(); |
155 } | 159 } |
156 | 160 |
157 TimeView::TimeView() | 161 TimeView::TimeView(TrayDate::ClockLayout clock_layout) |
158 : hour_type_( | 162 : hour_type_( |
159 ash::Shell::GetInstance()->tray_delegate()->GetHourClockType()) { | 163 ash::Shell::GetInstance()->tray_delegate()->GetHourClockType()) { |
160 SetLayoutManager( | 164 SetupLabels(); |
161 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | |
162 label_.reset(CreateLabel()); | |
163 label_hour_.reset(CreateLabel()); | |
164 label_minute_.reset(CreateLabel()); | |
165 label_->set_owned_by_client(); | |
166 label_hour_->set_owned_by_client(); | |
167 label_minute_->set_owned_by_client(); | |
168 UpdateTextInternal(base::Time::Now()); | 165 UpdateTextInternal(base::Time::Now()); |
169 AddChildView(label_.get()); | 166 UpdateClockLayout(clock_layout); |
170 } | 167 } |
171 | 168 |
172 TimeView::~TimeView() { | 169 TimeView::~TimeView() { |
173 } | 170 } |
174 | 171 |
175 void TimeView::UpdateTimeFormat() { | 172 void TimeView::UpdateTimeFormat() { |
176 hour_type_ = ash::Shell::GetInstance()->tray_delegate()->GetHourClockType(); | 173 hour_type_ = ash::Shell::GetInstance()->tray_delegate()->GetHourClockType(); |
177 UpdateText(); | 174 UpdateText(); |
178 } | 175 } |
179 | 176 |
180 void TimeView::UpdateTextInternal(const base::Time& now) { | 177 void TimeView::UpdateTextInternal(const base::Time& now) { |
181 string16 current_time = base::TimeFormatTimeOfDayWithHourClockType( | 178 string16 current_time = base::TimeFormatTimeOfDayWithHourClockType( |
182 now, hour_type_, base::kDropAmPm); | 179 now, hour_type_, base::kDropAmPm); |
183 label_->SetText(current_time); | 180 label_->SetText(current_time); |
184 label_->SetTooltipText(base::TimeFormatFriendlyDate(now)); | 181 label_->SetTooltipText(base::TimeFormatFriendlyDate(now)); |
185 | 182 |
186 // Calculate vertical clock layout labels. | 183 // Calculate vertical clock layout labels. |
187 size_t colon_pos = current_time.find(ASCIIToUTF16(":")); | 184 size_t colon_pos = current_time.find(ASCIIToUTF16(":")); |
188 string16 hour = current_time.substr(0, colon_pos); | 185 string16 hour = current_time.substr(0, colon_pos); |
189 string16 minute = current_time.substr(colon_pos + 1); | 186 string16 minute = current_time.substr(colon_pos + 1); |
190 if (hour.length() == 2) { | 187 label_hour_left_->SetText(hour.substr(0, 1)); |
191 label_hour_->SetText(hour); | 188 label_hour_right_->SetText(hour.length() == 2 ? |
192 } else { | 189 hour.substr(1,1) : ASCIIToUTF16(":")); |
193 label_hour_->SetText(hour_type_ == base::k24HourClock ? | 190 label_minute_left_->SetText(minute.substr(0, 1)); |
194 ASCIIToUTF16("0") + hour : hour + ASCIIToUTF16(":")); | 191 label_minute_right_->SetText(minute.substr(1, 1)); |
195 } | 192 |
196 label_minute_->SetText(minute); | 193 Layout(); |
197 } | 194 } |
198 | 195 |
199 bool TimeView::PerformAction(const views::Event& event) { | 196 bool TimeView::PerformAction(const views::Event& event) { |
200 return false; | 197 return false; |
201 } | 198 } |
202 | 199 |
203 bool TimeView::OnMousePressed(const views::MouseEvent& event) { | 200 bool TimeView::OnMousePressed(const views::MouseEvent& event) { |
204 // Let the event fall through. | 201 // Let the event fall through. |
205 return false; | 202 return false; |
206 } | 203 } |
207 | 204 |
208 void TimeView::UpdateClockLayout(TrayDate::ClockLayout clock_layout){ | 205 void TimeView::UpdateClockLayout(TrayDate::ClockLayout clock_layout){ |
209 SetBorder(clock_layout); | 206 SetBorder(clock_layout); |
210 if (clock_layout == TrayDate::HORIZONTAL_CLOCK) { | 207 if (clock_layout == TrayDate::HORIZONTAL_CLOCK) { |
211 RemoveChildView(label_hour_.get()); | 208 RemoveChildView(label_hour_left_.get()); |
212 RemoveChildView(label_minute_.get()); | 209 RemoveChildView(label_hour_right_.get()); |
| 210 RemoveChildView(label_minute_left_.get()); |
| 211 RemoveChildView(label_minute_right_.get()); |
213 SetLayoutManager( | 212 SetLayoutManager( |
214 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | 213 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
215 AddChildView(label_.get()); | 214 AddChildView(label_.get()); |
216 } else { | 215 } else { |
217 RemoveChildView(label_.get()); | 216 RemoveChildView(label_.get()); |
218 SetLayoutManager( | 217 views::GridLayout* layout = new views::GridLayout(this); |
219 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 218 SetLayoutManager(layout); |
220 AddChildView(label_hour_.get()); | 219 views::ColumnSet* columns = layout->AddColumnSet(0); |
221 AddChildView(label_minute_.get()); | 220 columns->AddPaddingColumn(0, 6); |
| 221 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, |
| 222 0, views::GridLayout::USE_PREF, 0, 0); |
| 223 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, |
| 224 0, views::GridLayout::USE_PREF, 0, 0); |
| 225 layout->AddPaddingRow(0, 4); |
| 226 layout->StartRow(0, 0); |
| 227 layout->AddView(label_hour_left_.get()); |
| 228 layout->AddView(label_hour_right_.get()); |
| 229 layout->StartRow(0, 0); |
| 230 layout->AddView(label_minute_left_.get()); |
| 231 layout->AddView(label_minute_right_.get()); |
| 232 layout->AddPaddingRow(0, 4); |
222 } | 233 } |
| 234 Layout(); |
223 set_focusable(true); | 235 set_focusable(true); |
224 } | 236 } |
225 | 237 |
226 void TimeView::SetBorder(TrayDate::ClockLayout clock_layout) { | 238 void TimeView::SetBorder(TrayDate::ClockLayout clock_layout) { |
227 if (clock_layout == TrayDate::HORIZONTAL_CLOCK) | 239 if (clock_layout == TrayDate::HORIZONTAL_CLOCK) |
228 set_border(views::Border::CreateEmptyBorder(0, 10, 0, 7)); | 240 set_border(views::Border::CreateEmptyBorder(0, 10, 0, 7)); |
229 else | 241 else |
230 set_border(views::Border::CreateEmptyBorder(2, 12, 2, 2)); | 242 set_border(NULL); |
| 243 } |
| 244 |
| 245 void TimeView::SetupLabels() { |
| 246 label_.reset(CreateLabel()); |
| 247 SetupLabel(label_.get()); |
| 248 label_hour_left_.reset(CreateLabel()); |
| 249 SetupLabel(label_hour_left_.get()); |
| 250 label_hour_right_.reset(CreateLabel()); |
| 251 SetupLabel(label_hour_right_.get()); |
| 252 label_minute_left_.reset(CreateLabel()); |
| 253 SetupLabel(label_minute_left_.get()); |
| 254 label_minute_right_.reset(CreateLabel()); |
| 255 SetupLabel(label_minute_right_.get()); |
| 256 label_hour_left_->SetEnabledColor(kVerticalClockHourColor); |
| 257 label_hour_right_->SetEnabledColor(kVerticalClockHourColor); |
| 258 } |
| 259 |
| 260 void TimeView::SetupLabel(views::Label* label) { |
| 261 label->set_owned_by_client(); |
| 262 SetupLabelForTray(label); |
| 263 gfx::Font font = label->font(); |
| 264 label->SetFont(font.DeriveFont(0, font.GetStyle() & ~gfx::Font::BOLD)); |
231 } | 265 } |
232 | 266 |
233 } // namespace tray | 267 } // namespace tray |
234 } // namespace internal | 268 } // namespace internal |
235 } // namespace ash | 269 } // namespace ash |
OLD | NEW |