Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: ash/common/system/date/date_view.cc

Issue 2455183002: Simplify layout of tray items and fix spacing for MD. (Closed)
Patch Set: more fixes Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/common/system/chromeos/power/tray_power.cc ('k') | ash/common/system/date/tray_date.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/material_design/material_design_controller.h"
8 #include "ash/common/system/tray/system_tray_controller.h" 8 #include "ash/common/system/tray/system_tray_controller.h"
9 #include "ash/common/system/tray/tray_constants.h" 9 #include "ash/common/system/tray/tray_constants.h"
10 #include "ash/common/system/tray/tray_utils.h" 10 #include "ash/common/system/tray/tray_utils.h"
11 #include "ash/common/wm_shell.h" 11 #include "ash/common/wm_shell.h"
12 #include "base/i18n/rtl.h" 12 #include "base/i18n/rtl.h"
13 #include "base/i18n/time_formatting.h" 13 #include "base/i18n/time_formatting.h"
14 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
15 #include "base/time/time.h" 15 #include "base/time/time.h"
16 #include "grit/ash_strings.h" 16 #include "grit/ash_strings.h"
17 #include "third_party/icu/source/i18n/unicode/datefmt.h" 17 #include "third_party/icu/source/i18n/unicode/datefmt.h"
18 #include "third_party/icu/source/i18n/unicode/dtptngen.h" 18 #include "third_party/icu/source/i18n/unicode/dtptngen.h"
19 #include "third_party/icu/source/i18n/unicode/smpdtfmt.h" 19 #include "third_party/icu/source/i18n/unicode/smpdtfmt.h"
20 #include "ui/accessibility/ax_view_state.h" 20 #include "ui/accessibility/ax_view_state.h"
21 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
22 #include "ui/views/background.h"
22 #include "ui/views/border.h" 23 #include "ui/views/border.h"
23 #include "ui/views/controls/label.h" 24 #include "ui/views/controls/label.h"
24 #include "ui/views/layout/box_layout.h" 25 #include "ui/views/layout/box_layout.h"
26 #include "ui/views/layout/fill_layout.h"
25 #include "ui/views/layout/grid_layout.h" 27 #include "ui/views/layout/grid_layout.h"
26 #include "ui/views/widget/widget.h" 28 #include "ui/views/widget/widget.h"
27 29
28 namespace ash { 30 namespace ash {
29 namespace tray { 31 namespace tray {
30 namespace { 32 namespace {
31 33
32 // Amount of slop to add into the timer to make sure we're into the next minute 34 // Amount of slop to add into the timer to make sure we're into the next minute
33 // when the timer goes off. 35 // when the timer goes off.
34 const int kTimerSlopSeconds = 1; 36 const int kTimerSlopSeconds = 1;
35 37
36 // Text color of the vertical clock minutes. 38 // Text color of the vertical clock minutes.
37 const SkColor kVerticalClockMinuteColor = SkColorSetRGB(0xBA, 0xBA, 0xBA); 39 const SkColor kVerticalClockMinuteColor = SkColorSetRGB(0xBA, 0xBA, 0xBA);
38 40
39 // Padding between the left edge of the shelf and the left edge of the vertical 41 // Padding between the left edge of the shelf and the left edge of the vertical
40 // clock. 42 // clock.
41 const int kVerticalClockLeftPadding = 9; 43 const int kVerticalClockLeftPadding = 9;
42 44
43 // Offset used to bring the minutes line closer to the hours line in the 45 // Offset used to bring the minutes line closer to the hours line in the
44 // vertical clock. 46 // vertical clock.
45 const int kVerticalClockMinutesTopOffset = -4; 47 const int kVerticalClockMinutesTopOffset = -4;
46 const int kVerticalClockMinutesTopOffsetMD = -2; 48 const int kVerticalClockMinutesTopOffsetMD = -2;
47 49
48 // Leading padding used to draw the tray background to the left of the clock
49 // when the shelf is horizontally aligned, and on the top when the shelf is 50 // when the shelf is horizontally aligned, and on the top when the shelf is
tdanderson 2016/10/27 23:58:41 Looks like you deleted some of this comment by mis
Evan Stade 2016/10/28 18:07:49 Done.
50 // vertically aligned. 51 // vertically aligned.
51 const int kClockLeadingPadding = 8; 52 const int kClockLeadingPadding = 8;
52 53
53 base::string16 FormatDate(const base::Time& time) { 54 base::string16 FormatDate(const base::Time& time) {
54 icu::UnicodeString date_string; 55 icu::UnicodeString date_string;
55 std::unique_ptr<icu::DateFormat> formatter( 56 std::unique_ptr<icu::DateFormat> formatter(
56 icu::DateFormat::createDateInstance(icu::DateFormat::kMedium)); 57 icu::DateFormat::createDateInstance(icu::DateFormat::kMedium));
57 formatter->format(static_cast<UDate>(time.ToDoubleT() * 1000), date_string); 58 formatter->format(static_cast<UDate>(time.ToDoubleT() * 1000), date_string);
58 return base::string16(date_string.getBuffer(), 59 return base::string16(date_string.getBuffer(),
59 static_cast<size_t>(date_string.length())); 60 static_cast<size_t>(date_string.length()));
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 bool TimeView::OnMousePressed(const ui::MouseEvent& event) { 284 bool TimeView::OnMousePressed(const ui::MouseEvent& event) {
284 // Let the event fall through. 285 // Let the event fall through.
285 return false; 286 return false;
286 } 287 }
287 288
288 void TimeView::UpdateClockLayout(TrayDate::ClockLayout clock_layout) { 289 void TimeView::UpdateClockLayout(TrayDate::ClockLayout clock_layout) {
289 SetBorderFromLayout(clock_layout); 290 SetBorderFromLayout(clock_layout);
290 if (clock_layout == TrayDate::HORIZONTAL_CLOCK) { 291 if (clock_layout == TrayDate::HORIZONTAL_CLOCK) {
291 RemoveChildView(vertical_label_hours_.get()); 292 RemoveChildView(vertical_label_hours_.get());
292 RemoveChildView(vertical_label_minutes_.get()); 293 RemoveChildView(vertical_label_minutes_.get());
293 SetLayoutManager(
294 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0));
295 AddChildView(horizontal_label_.get()); 294 AddChildView(horizontal_label_.get());
295 SetLayoutManager(new views::FillLayout());
296 } else { 296 } else {
297 const bool is_material_design = MaterialDesignController::IsShelfMaterial(); 297 const bool is_material_design = MaterialDesignController::IsShelfMaterial();
298 RemoveChildView(horizontal_label_.get()); 298 RemoveChildView(horizontal_label_.get());
299 views::GridLayout* layout = new views::GridLayout(this); 299 views::GridLayout* layout = new views::GridLayout(this);
300 SetLayoutManager(layout); 300 SetLayoutManager(layout);
301 const int kColumnId = 0; 301 const int kColumnId = 0;
302 views::ColumnSet* columns = layout->AddColumnSet(kColumnId); 302 views::ColumnSet* columns = layout->AddColumnSet(kColumnId);
303 columns->AddPaddingColumn(0, kVerticalClockLeftPadding); 303 columns->AddPaddingColumn(0, kVerticalClockLeftPadding);
304 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, 304 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER,
305 0, views::GridLayout::USE_PREF, 0, 0); 305 0, views::GridLayout::USE_PREF, 0, 0);
306 layout->AddPaddingRow( 306 layout->AddPaddingRow(
307 0, is_material_design ? kClockLeadingPadding 307 0, is_material_design ? kClockLeadingPadding
308 : kTrayLabelItemVerticalPaddingVerticalAlignment); 308 : kTrayLabelItemVerticalPaddingVerticalAlignment);
309 layout->StartRow(0, kColumnId); 309 layout->StartRow(0, kColumnId);
310 layout->AddView(vertical_label_hours_.get()); 310 layout->AddView(vertical_label_hours_.get());
311 layout->StartRow(0, kColumnId); 311 layout->StartRow(0, kColumnId);
312 layout->AddView(vertical_label_minutes_.get()); 312 layout->AddView(vertical_label_minutes_.get());
313 layout->AddPaddingRow(0, 313 layout->AddPaddingRow(0,
314 is_material_design 314 is_material_design
315 ? GetTrayConstant(TRAY_IMAGE_ITEM_PADDING) + 315 ? GetTrayConstant(TRAY_IMAGE_ITEM_PADDING) +
316 kVerticalClockMinutesTopOffsetMD 316 kVerticalClockMinutesTopOffsetMD
317 : kTrayLabelItemVerticalPaddingVerticalAlignment); 317 : kTrayLabelItemVerticalPaddingVerticalAlignment);
318 } 318 }
319 Layout(); 319 Layout();
320 } 320 }
321 321
322 void TimeView::SetBorderFromLayout(TrayDate::ClockLayout clock_layout) { 322 void TimeView::SetBorderFromLayout(TrayDate::ClockLayout clock_layout) {
323 if (clock_layout == TrayDate::HORIZONTAL_CLOCK) { 323 if (!MaterialDesignController::IsShelfMaterial() &&
324 bool is_material_design = MaterialDesignController::IsShelfMaterial(); 324 clock_layout == TrayDate::HORIZONTAL_CLOCK) {
325 const int time_view_left_padding = 325 SetBorder(views::Border::CreateEmptyBorder(
326 is_material_design ? kClockLeadingPadding 326 0, kTrayLabelItemHorizontalPaddingBottomAlignment, 0,
327 : kTrayLabelItemHorizontalPaddingBottomAlignment; 327 kTrayLabelItemHorizontalPaddingBottomAlignment));
328 const int time_view_right_padding =
329 is_material_design ? GetTrayConstant(TRAY_IMAGE_ITEM_PADDING)
330 : kTrayLabelItemHorizontalPaddingBottomAlignment;
331 SetBorder(views::Border::CreateEmptyBorder(0, time_view_left_padding, 0,
332 time_view_right_padding));
333 } else { 328 } else {
334 SetBorder(views::Border::NullBorder()); 329 SetBorder(views::Border::NullBorder());
tdanderson 2016/10/27 23:58:41 Double-checking: this will set a null border if MD
Evan Stade 2016/10/28 18:07:49 It's not harmful, but I guess it's not really nece
335 } 330 }
336 } 331 }
337 332
338 void TimeView::SetupLabels() { 333 void TimeView::SetupLabels() {
339 horizontal_label_.reset(new views::Label()); 334 horizontal_label_.reset(new views::Label());
340 SetupLabel(horizontal_label_.get()); 335 SetupLabel(horizontal_label_.get());
341 vertical_label_hours_.reset(new views::Label()); 336 vertical_label_hours_.reset(new views::Label());
342 SetupLabel(vertical_label_hours_.get()); 337 SetupLabel(vertical_label_hours_.get());
343 vertical_label_minutes_.reset(new views::Label()); 338 vertical_label_minutes_.reset(new views::Label());
344 SetupLabel(vertical_label_minutes_.get()); 339 SetupLabel(vertical_label_minutes_.get());
345 // TODO(estade): this should use the NativeTheme's secondary text color. 340 // TODO(estade): this should use the NativeTheme's secondary text color.
346 vertical_label_minutes_->SetEnabledColor(kVerticalClockMinuteColor); 341 vertical_label_minutes_->SetEnabledColor(kVerticalClockMinuteColor);
347 // Pull the minutes up closer to the hours by using a negative top border. 342 // Pull the minutes up closer to the hours by using a negative top border.
348 vertical_label_minutes_->SetBorder(views::Border::CreateEmptyBorder( 343 vertical_label_minutes_->SetBorder(views::Border::CreateEmptyBorder(
349 MaterialDesignController::IsShelfMaterial() 344 MaterialDesignController::IsShelfMaterial()
350 ? kVerticalClockMinutesTopOffsetMD 345 ? kVerticalClockMinutesTopOffsetMD
351 : kVerticalClockMinutesTopOffset, 346 : kVerticalClockMinutesTopOffset,
352 0, 0, 0)); 347 0, 0, 0));
353 } 348 }
354 349
355 void TimeView::SetupLabel(views::Label* label) { 350 void TimeView::SetupLabel(views::Label* label) {
356 label->set_owned_by_client(); 351 label->set_owned_by_client();
357 SetupLabelForTray(label); 352 SetupLabelForTray(label);
358 label->SetElideBehavior(gfx::NO_ELIDE); 353 label->SetElideBehavior(gfx::NO_ELIDE);
359 } 354 }
360 355
361 } // namespace tray 356 } // namespace tray
362 } // namespace ash 357 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/power/tray_power.cc ('k') | ash/common/system/date/tray_date.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698