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

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

Issue 2732813002: chromeos: Move files in //ash/common to //ash, part 1 (Closed)
Patch Set: rebase Created 3 years, 9 months 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
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ash/common/system/date/system_info_default_view.h"
6
7 #include "ash/common/system/chromeos/power/power_status.h"
8 #include "ash/common/system/chromeos/power/power_status_view.h"
9 #include "ash/common/system/date/date_view.h"
10 #include "ash/common/system/tray/tray_constants.h"
11 #include "ash/common/system/tray/tray_popup_utils.h"
12 #include "ash/common/system/tray/tri_view.h"
13 #include "base/memory/ptr_util.h"
14 #include "ui/views/controls/separator.h"
15 #include "ui/views/layout/box_layout.h"
16 #include "ui/views/layout/fill_layout.h"
17
18 namespace ash {
19
20 // The minimum number of menu button widths that the date view should span
21 // horizontally.
22 const int kMinNumTileWidths = 2;
23
24 // The maximum number of menu button widths that the date view should span
25 // horizontally.
26 const int kMaxNumTileWidths = 3;
27
28 SystemInfoDefaultView::SystemInfoDefaultView(SystemTrayItem* owner,
29 LoginStatus login)
30 : date_view_(nullptr),
31 tri_view_(TrayPopupUtils::CreateMultiTargetRowView()) {
32 tri_view_->SetMinHeight(kTrayPopupSystemInfoRowHeight);
33 AddChildView(tri_view_);
34 SetLayoutManager(new views::FillLayout);
35
36 date_view_ = new tray::DateView(owner);
37 tri_view_->AddView(TriView::Container::START, date_view_);
38
39 if (PowerStatus::Get()->IsBatteryPresent()) {
40 power_status_view_ = new ash::PowerStatusView(false);
41 std::unique_ptr<views::BoxLayout> box_layout =
42 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kHorizontal, 0, 0,
43 0);
44 box_layout->set_cross_axis_alignment(
45 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
46 box_layout->set_inside_border_insets(
47 gfx::Insets(0, 0, 0, kTrayPopupLabelRightPadding));
48 tri_view_->SetContainerLayout(TriView::Container::CENTER,
49 std::move(box_layout));
50
51 tri_view_->AddView(TriView::Container::CENTER,
52 TrayPopupUtils::CreateVerticalSeparator());
53 tri_view_->AddView(TriView::Container::CENTER, power_status_view_);
54 }
55 tri_view_->SetContainerVisible(TriView::Container::END, false);
56
57 if (TrayPopupUtils::CanOpenWebUISettings(login))
58 date_view_->SetAction(tray::DateView::DateAction::SHOW_DATE_SETTINGS);
59 }
60
61 SystemInfoDefaultView::~SystemInfoDefaultView() {}
62
63 tray::DateView* SystemInfoDefaultView::GetDateView() {
64 return date_view_;
65 }
66
67 const tray::DateView* SystemInfoDefaultView::GetDateView() const {
68 return date_view_;
69 }
70
71 void SystemInfoDefaultView::Layout() {
72 gfx::Size min_start_size = tri_view_->GetMinSize(TriView::Container::START);
73 min_start_size.set_width(
74 CalculateDateViewWidth(date_view_->GetPreferredSize().width()));
75 tri_view_->SetMinSize(TriView::Container::START, min_start_size);
76
77 views::View::Layout();
78 }
79
80 int SystemInfoDefaultView::CalculateDateViewWidth(int preferred_width) {
81 const float snap_to_width = kSeparatorWidth + kMenuButtonSize;
82 int num_extra_tile_widths = 0;
83 if (preferred_width > kMenuButtonSize) {
84 const float extra_width = preferred_width - kMenuButtonSize;
85 const float preferred_width_ratio = extra_width / snap_to_width;
86 num_extra_tile_widths = std::ceil(preferred_width_ratio);
87 }
88 num_extra_tile_widths =
89 std::max(kMinNumTileWidths - 1,
90 std::min(num_extra_tile_widths, kMaxNumTileWidths - 1));
91
92 return kMenuButtonSize + num_extra_tile_widths * snap_to_width;
93 }
94
95 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/date/system_info_default_view.h ('k') | ash/common/system/date/system_info_default_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698