| 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/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_controller.h" | 8 #include "ash/common/system/tray/system_tray_controller.h" |
| 8 #include "ash/common/system/tray/system_tray_delegate.h" | 9 #include "ash/common/system/tray/system_tray_delegate.h" |
| 9 #include "ash/common/system/tray/tray_constants.h" | 10 #include "ash/common/system/tray/tray_constants.h" |
| 10 #include "ash/common/system/tray/tray_utils.h" | 11 #include "ash/common/system/tray/tray_utils.h" |
| 11 #include "ash/common/wm_shell.h" | 12 #include "ash/common/wm_shell.h" |
| 12 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
| 13 #include "base/i18n/time_formatting.h" | 14 #include "base/i18n/time_formatting.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 16 #include "grit/ash_strings.h" | 17 #include "grit/ash_strings.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 36 // Text color of the vertical clock minutes. | 37 // Text color of the vertical clock minutes. |
| 37 const SkColor kVerticalClockMinuteColor = SkColorSetRGB(0xBA, 0xBA, 0xBA); | 38 const SkColor kVerticalClockMinuteColor = SkColorSetRGB(0xBA, 0xBA, 0xBA); |
| 38 | 39 |
| 39 // Padding between the left edge of the shelf and the left edge of the vertical | 40 // Padding between the left edge of the shelf and the left edge of the vertical |
| 40 // clock. | 41 // clock. |
| 41 const int kVerticalClockLeftPadding = 9; | 42 const int kVerticalClockLeftPadding = 9; |
| 42 | 43 |
| 43 // Offset used to bring the minutes line closer to the hours line in the | 44 // Offset used to bring the minutes line closer to the hours line in the |
| 44 // vertical clock. | 45 // vertical clock. |
| 45 const int kVerticalClockMinutesTopOffset = -4; | 46 const int kVerticalClockMinutesTopOffset = -4; |
| 47 const int kVerticalClockMinutesTopOffsetMD = -2; |
| 48 |
| 49 // Leading padding used to draw the tray background to the left of the clock |
| 50 // when the shelf is horizontally aligned, and on the top when the shelf is |
| 51 // vertically aligned. |
| 52 const int kClockLeadingPadding = 8; |
| 46 | 53 |
| 47 base::string16 FormatDate(const base::Time& time) { | 54 base::string16 FormatDate(const base::Time& time) { |
| 48 icu::UnicodeString date_string; | 55 icu::UnicodeString date_string; |
| 49 std::unique_ptr<icu::DateFormat> formatter( | 56 std::unique_ptr<icu::DateFormat> formatter( |
| 50 icu::DateFormat::createDateInstance(icu::DateFormat::kMedium)); | 57 icu::DateFormat::createDateInstance(icu::DateFormat::kMedium)); |
| 51 formatter->format(static_cast<UDate>(time.ToDoubleT() * 1000), date_string); | 58 formatter->format(static_cast<UDate>(time.ToDoubleT() * 1000), date_string); |
| 52 return base::string16(date_string.getBuffer(), | 59 return base::string16(date_string.getBuffer(), |
| 53 static_cast<size_t>(date_string.length())); | 60 static_cast<size_t>(date_string.length())); |
| 54 } | 61 } |
| 55 | 62 |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 | 288 |
| 282 void TimeView::UpdateClockLayout(TrayDate::ClockLayout clock_layout) { | 289 void TimeView::UpdateClockLayout(TrayDate::ClockLayout clock_layout) { |
| 283 SetBorderFromLayout(clock_layout); | 290 SetBorderFromLayout(clock_layout); |
| 284 if (clock_layout == TrayDate::HORIZONTAL_CLOCK) { | 291 if (clock_layout == TrayDate::HORIZONTAL_CLOCK) { |
| 285 RemoveChildView(vertical_label_hours_.get()); | 292 RemoveChildView(vertical_label_hours_.get()); |
| 286 RemoveChildView(vertical_label_minutes_.get()); | 293 RemoveChildView(vertical_label_minutes_.get()); |
| 287 SetLayoutManager( | 294 SetLayoutManager( |
| 288 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | 295 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
| 289 AddChildView(horizontal_label_.get()); | 296 AddChildView(horizontal_label_.get()); |
| 290 } else { | 297 } else { |
| 298 const bool is_material_design = MaterialDesignController::IsShelfMaterial(); |
| 291 RemoveChildView(horizontal_label_.get()); | 299 RemoveChildView(horizontal_label_.get()); |
| 292 views::GridLayout* layout = new views::GridLayout(this); | 300 views::GridLayout* layout = new views::GridLayout(this); |
| 293 SetLayoutManager(layout); | 301 SetLayoutManager(layout); |
| 294 const int kColumnId = 0; | 302 const int kColumnId = 0; |
| 295 views::ColumnSet* columns = layout->AddColumnSet(kColumnId); | 303 views::ColumnSet* columns = layout->AddColumnSet(kColumnId); |
| 296 columns->AddPaddingColumn(0, kVerticalClockLeftPadding); | 304 columns->AddPaddingColumn(0, kVerticalClockLeftPadding); |
| 297 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, | 305 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, |
| 298 0, views::GridLayout::USE_PREF, 0, 0); | 306 0, views::GridLayout::USE_PREF, 0, 0); |
| 299 layout->AddPaddingRow(0, kTrayLabelItemVerticalPaddingVerticalAlignment); | 307 layout->AddPaddingRow( |
| 308 0, is_material_design ? kClockLeadingPadding |
| 309 : kTrayLabelItemVerticalPaddingVerticalAlignment); |
| 300 layout->StartRow(0, kColumnId); | 310 layout->StartRow(0, kColumnId); |
| 301 layout->AddView(vertical_label_hours_.get()); | 311 layout->AddView(vertical_label_hours_.get()); |
| 302 layout->StartRow(0, kColumnId); | 312 layout->StartRow(0, kColumnId); |
| 303 layout->AddView(vertical_label_minutes_.get()); | 313 layout->AddView(vertical_label_minutes_.get()); |
| 304 layout->AddPaddingRow(0, kTrayLabelItemVerticalPaddingVerticalAlignment); | 314 layout->AddPaddingRow(0, |
| 315 is_material_design |
| 316 ? GetTrayConstant(TRAY_IMAGE_ITEM_PADDING) + |
| 317 kVerticalClockMinutesTopOffsetMD |
| 318 : kTrayLabelItemVerticalPaddingVerticalAlignment); |
| 305 } | 319 } |
| 306 Layout(); | 320 Layout(); |
| 307 } | 321 } |
| 308 | 322 |
| 309 void TimeView::SetBorderFromLayout(TrayDate::ClockLayout clock_layout) { | 323 void TimeView::SetBorderFromLayout(TrayDate::ClockLayout clock_layout) { |
| 310 if (clock_layout == TrayDate::HORIZONTAL_CLOCK) | 324 if (clock_layout == TrayDate::HORIZONTAL_CLOCK) { |
| 311 SetBorder(views::Border::CreateEmptyBorder( | 325 bool is_material_design = MaterialDesignController::IsShelfMaterial(); |
| 312 0, kTrayLabelItemHorizontalPaddingBottomAlignment, 0, | 326 const int time_view_left_padding = |
| 313 kTrayLabelItemHorizontalPaddingBottomAlignment)); | 327 is_material_design ? kClockLeadingPadding |
| 314 else | 328 : kTrayLabelItemHorizontalPaddingBottomAlignment; |
| 329 const int time_view_right_padding = |
| 330 is_material_design ? GetTrayConstant(TRAY_IMAGE_ITEM_PADDING) |
| 331 : kTrayLabelItemHorizontalPaddingBottomAlignment; |
| 332 SetBorder(views::Border::CreateEmptyBorder(0, time_view_left_padding, 0, |
| 333 time_view_right_padding)); |
| 334 } else { |
| 315 SetBorder(views::Border::NullBorder()); | 335 SetBorder(views::Border::NullBorder()); |
| 336 } |
| 316 } | 337 } |
| 317 | 338 |
| 318 void TimeView::SetupLabels() { | 339 void TimeView::SetupLabels() { |
| 319 horizontal_label_.reset(new views::Label()); | 340 horizontal_label_.reset(new views::Label()); |
| 320 SetupLabel(horizontal_label_.get()); | 341 SetupLabel(horizontal_label_.get()); |
| 321 vertical_label_hours_.reset(new views::Label()); | 342 vertical_label_hours_.reset(new views::Label()); |
| 322 SetupLabel(vertical_label_hours_.get()); | 343 SetupLabel(vertical_label_hours_.get()); |
| 323 vertical_label_minutes_.reset(new views::Label()); | 344 vertical_label_minutes_.reset(new views::Label()); |
| 324 SetupLabel(vertical_label_minutes_.get()); | 345 SetupLabel(vertical_label_minutes_.get()); |
| 325 // TODO(estade): this should use the NativeTheme's secondary text color. | 346 // TODO(estade): this should use the NativeTheme's secondary text color. |
| 326 vertical_label_minutes_->SetEnabledColor(kVerticalClockMinuteColor); | 347 vertical_label_minutes_->SetEnabledColor(kVerticalClockMinuteColor); |
| 327 // Pull the minutes up closer to the hours by using a negative top border. | 348 // Pull the minutes up closer to the hours by using a negative top border. |
| 328 vertical_label_minutes_->SetBorder(views::Border::CreateEmptyBorder( | 349 vertical_label_minutes_->SetBorder(views::Border::CreateEmptyBorder( |
| 329 kVerticalClockMinutesTopOffset, 0, 0, 0)); | 350 MaterialDesignController::IsShelfMaterial() |
| 351 ? kVerticalClockMinutesTopOffsetMD |
| 352 : kVerticalClockMinutesTopOffset, |
| 353 0, 0, 0)); |
| 330 } | 354 } |
| 331 | 355 |
| 332 void TimeView::SetupLabel(views::Label* label) { | 356 void TimeView::SetupLabel(views::Label* label) { |
| 333 label->set_owned_by_client(); | 357 label->set_owned_by_client(); |
| 334 SetupLabelForTray(label); | 358 SetupLabelForTray(label); |
| 335 label->SetElideBehavior(gfx::NO_ELIDE); | 359 label->SetElideBehavior(gfx::NO_ELIDE); |
| 336 } | 360 } |
| 337 | 361 |
| 338 } // namespace tray | 362 } // namespace tray |
| 339 } // namespace ash | 363 } // namespace ash |
| OLD | NEW |