Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
|
tdanderson
2016/10/05 21:34:28
As discussed in person, can you please file a bug
yiyix
2016/10/05 22:46:47
Done, I also included a todo in the file.
| |
| 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/common/system/date/date_view.h" | 5 #include "ash/common/system/date/date_view.h" |
| 6 | 6 |
| 7 #include "ash/common/material_design/material_design_controller.h" | |
| 7 #include "ash/common/system/tray/system_tray_delegate.h" | 8 #include "ash/common/system/tray/system_tray_delegate.h" |
| 8 #include "ash/common/system/tray/tray_constants.h" | 9 #include "ash/common/system/tray/tray_constants.h" |
| 9 #include "ash/common/system/tray/tray_utils.h" | 10 #include "ash/common/system/tray/tray_utils.h" |
| 10 #include "ash/common/wm_shell.h" | 11 #include "ash/common/wm_shell.h" |
| 11 #include "base/i18n/rtl.h" | 12 #include "base/i18n/rtl.h" |
| 12 #include "base/i18n/time_formatting.h" | 13 #include "base/i18n/time_formatting.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 15 #include "grit/ash_strings.h" | 16 #include "grit/ash_strings.h" |
| 16 #include "third_party/icu/source/i18n/unicode/datefmt.h" | 17 #include "third_party/icu/source/i18n/unicode/datefmt.h" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 34 | 35 |
| 35 // Text color of the vertical clock minutes. | 36 // Text color of the vertical clock minutes. |
| 36 const SkColor kVerticalClockMinuteColor = SkColorSetRGB(0xBA, 0xBA, 0xBA); | 37 const SkColor kVerticalClockMinuteColor = SkColorSetRGB(0xBA, 0xBA, 0xBA); |
| 37 | 38 |
| 38 // Padding between the left edge of the shelf and the left edge of the vertical | 39 // Padding between the left edge of the shelf and the left edge of the vertical |
| 39 // clock. | 40 // clock. |
| 40 const int kVerticalClockLeftPadding = 9; | 41 const int kVerticalClockLeftPadding = 9; |
| 41 | 42 |
| 42 // Offset used to bring the minutes line closer to the hours line in the | 43 // Offset used to bring the minutes line closer to the hours line in the |
| 43 // vertical clock. | 44 // vertical clock. |
| 44 const int kVerticalClockMinutesTopOffset = -4; | 45 const int kVerticalClockMinutesTopOffset = -2; |
|
tdanderson
2016/10/05 21:34:29
This constant is used on line 346 which can be exe
yiyix
2016/10/05 22:46:47
You are right. I forget about the non-md path.
| |
| 46 | |
| 47 // Padding used to draw the tray background around the clock. | |
| 48 const int kClockOnTrayBackgroundPadding = 8; | |
|
tdanderson
2016/10/05 21:34:28
Since this is only used for a vertical shelf, can
yiyix
2016/10/05 22:46:47
It is used for both horizontal and vertical aligne
| |
| 45 | 49 |
| 46 base::string16 FormatDate(const base::Time& time) { | 50 base::string16 FormatDate(const base::Time& time) { |
| 47 icu::UnicodeString date_string; | 51 icu::UnicodeString date_string; |
| 48 std::unique_ptr<icu::DateFormat> formatter( | 52 std::unique_ptr<icu::DateFormat> formatter( |
| 49 icu::DateFormat::createDateInstance(icu::DateFormat::kMedium)); | 53 icu::DateFormat::createDateInstance(icu::DateFormat::kMedium)); |
| 50 formatter->format(static_cast<UDate>(time.ToDoubleT() * 1000), date_string); | 54 formatter->format(static_cast<UDate>(time.ToDoubleT() * 1000), date_string); |
| 51 return base::string16(date_string.getBuffer(), | 55 return base::string16(date_string.getBuffer(), |
| 52 static_cast<size_t>(date_string.length())); | 56 static_cast<size_t>(date_string.length())); |
| 53 } | 57 } |
| 54 | 58 |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 | 284 |
| 281 void TimeView::UpdateClockLayout(TrayDate::ClockLayout clock_layout) { | 285 void TimeView::UpdateClockLayout(TrayDate::ClockLayout clock_layout) { |
| 282 SetBorderFromLayout(clock_layout); | 286 SetBorderFromLayout(clock_layout); |
| 283 if (clock_layout == TrayDate::HORIZONTAL_CLOCK) { | 287 if (clock_layout == TrayDate::HORIZONTAL_CLOCK) { |
| 284 RemoveChildView(vertical_label_hours_.get()); | 288 RemoveChildView(vertical_label_hours_.get()); |
| 285 RemoveChildView(vertical_label_minutes_.get()); | 289 RemoveChildView(vertical_label_minutes_.get()); |
| 286 SetLayoutManager( | 290 SetLayoutManager( |
| 287 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | 291 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
| 288 AddChildView(horizontal_label_.get()); | 292 AddChildView(horizontal_label_.get()); |
| 289 } else { | 293 } else { |
| 294 bool is_material_design = MaterialDesignController::IsShelfMaterial(); | |
|
tdanderson
2016/10/05 21:34:28
nit: const
yiyix
2016/10/05 22:46:47
Done.
| |
| 290 RemoveChildView(horizontal_label_.get()); | 295 RemoveChildView(horizontal_label_.get()); |
| 291 views::GridLayout* layout = new views::GridLayout(this); | 296 views::GridLayout* layout = new views::GridLayout(this); |
| 292 SetLayoutManager(layout); | 297 SetLayoutManager(layout); |
| 293 const int kColumnId = 0; | 298 const int kColumnId = 0; |
| 294 views::ColumnSet* columns = layout->AddColumnSet(kColumnId); | 299 views::ColumnSet* columns = layout->AddColumnSet(kColumnId); |
| 295 columns->AddPaddingColumn(0, kVerticalClockLeftPadding); | 300 columns->AddPaddingColumn(0, kVerticalClockLeftPadding); |
| 296 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, | 301 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, |
| 297 0, views::GridLayout::USE_PREF, 0, 0); | 302 0, views::GridLayout::USE_PREF, 0, 0); |
| 298 layout->AddPaddingRow(0, kTrayLabelItemVerticalPaddingVerticalAlignment); | 303 layout->AddPaddingRow( |
| 304 0, is_material_design ? kClockOnTrayBackgroundPadding | |
| 305 : kTrayLabelItemVerticalPaddingVerticalAlignment); | |
| 299 layout->StartRow(0, kColumnId); | 306 layout->StartRow(0, kColumnId); |
| 300 layout->AddView(vertical_label_hours_.get()); | 307 layout->AddView(vertical_label_hours_.get()); |
| 301 layout->StartRow(0, kColumnId); | 308 layout->StartRow(0, kColumnId); |
| 302 layout->AddView(vertical_label_minutes_.get()); | 309 layout->AddView(vertical_label_minutes_.get()); |
| 303 layout->AddPaddingRow(0, kTrayLabelItemVerticalPaddingVerticalAlignment); | 310 layout->AddPaddingRow(0, |
| 311 is_material_design | |
| 312 ? GetTrayConstant(TRAY_IMAGE_ITEM_PADDING) + | |
| 313 kVerticalClockMinutesTopOffset | |
| 314 : kTrayLabelItemVerticalPaddingVerticalAlignment); | |
| 304 } | 315 } |
| 305 Layout(); | 316 Layout(); |
| 306 } | 317 } |
| 307 | 318 |
| 308 void TimeView::SetBorderFromLayout(TrayDate::ClockLayout clock_layout) { | 319 void TimeView::SetBorderFromLayout(TrayDate::ClockLayout clock_layout) { |
| 309 if (clock_layout == TrayDate::HORIZONTAL_CLOCK) | 320 if (clock_layout == TrayDate::HORIZONTAL_CLOCK) { |
| 310 SetBorder(views::Border::CreateEmptyBorder( | 321 bool is_material_design = MaterialDesignController::IsShelfMaterial(); |
| 311 0, kTrayLabelItemHorizontalPaddingBottomAlignment, 0, | 322 const int time_view_left_padding = |
| 312 kTrayLabelItemHorizontalPaddingBottomAlignment)); | 323 is_material_design ? kClockOnTrayBackgroundPadding |
| 313 else | 324 : kTrayLabelItemHorizontalPaddingBottomAlignment; |
| 325 const int time_view_right_padding = | |
| 326 is_material_design ? GetTrayConstant(TRAY_IMAGE_ITEM_PADDING) | |
| 327 : kTrayLabelItemHorizontalPaddingBottomAlignment; | |
| 328 SetBorder(views::Border::CreateEmptyBorder(0, time_view_left_padding, 0, | |
| 329 time_view_right_padding)); | |
| 330 } else { | |
|
tdanderson
2016/10/05 21:34:28
Thanks for adding the {} !
yiyix
2016/10/05 22:46:47
:)
| |
| 314 SetBorder(views::Border::NullBorder()); | 331 SetBorder(views::Border::NullBorder()); |
| 332 } | |
| 315 } | 333 } |
| 316 | 334 |
| 317 void TimeView::SetupLabels() { | 335 void TimeView::SetupLabels() { |
| 318 horizontal_label_.reset(new views::Label()); | 336 horizontal_label_.reset(new views::Label()); |
| 319 SetupLabel(horizontal_label_.get()); | 337 SetupLabel(horizontal_label_.get()); |
| 320 vertical_label_hours_.reset(new views::Label()); | 338 vertical_label_hours_.reset(new views::Label()); |
| 321 SetupLabel(vertical_label_hours_.get()); | 339 SetupLabel(vertical_label_hours_.get()); |
| 322 vertical_label_minutes_.reset(new views::Label()); | 340 vertical_label_minutes_.reset(new views::Label()); |
| 323 SetupLabel(vertical_label_minutes_.get()); | 341 SetupLabel(vertical_label_minutes_.get()); |
| 324 // TODO(estade): this should use the NativeTheme's secondary text color. | 342 // TODO(estade): this should use the NativeTheme's secondary text color. |
| 325 vertical_label_minutes_->SetEnabledColor(kVerticalClockMinuteColor); | 343 vertical_label_minutes_->SetEnabledColor(kVerticalClockMinuteColor); |
| 326 // Pull the minutes up closer to the hours by using a negative top border. | 344 // Pull the minutes up closer to the hours by using a negative top border. |
| 327 vertical_label_minutes_->SetBorder(views::Border::CreateEmptyBorder( | 345 vertical_label_minutes_->SetBorder(views::Border::CreateEmptyBorder( |
| 328 kVerticalClockMinutesTopOffset, 0, 0, 0)); | 346 kVerticalClockMinutesTopOffset, 0, 0, 0)); |
| 329 } | 347 } |
| 330 | 348 |
| 331 void TimeView::SetupLabel(views::Label* label) { | 349 void TimeView::SetupLabel(views::Label* label) { |
| 332 label->set_owned_by_client(); | 350 label->set_owned_by_client(); |
| 333 SetupLabelForTray(label); | 351 SetupLabelForTray(label); |
| 334 label->SetElideBehavior(gfx::NO_ELIDE); | 352 label->SetElideBehavior(gfx::NO_ELIDE); |
| 335 } | 353 } |
| 336 | 354 |
| 337 } // namespace tray | 355 } // namespace tray |
| 338 } // namespace ash | 356 } // namespace ash |
| OLD | NEW |