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" | |
8 #include "ash/common/system/tray/system_tray_controller.h" | 7 #include "ash/common/system/tray/system_tray_controller.h" |
9 #include "ash/common/system/tray/tray_constants.h" | 8 #include "ash/common/system/tray/tray_constants.h" |
10 #include "ash/common/system/tray/tray_popup_item_style.h" | 9 #include "ash/common/system/tray/tray_popup_item_style.h" |
11 #include "ash/common/system/tray/tray_popup_utils.h" | 10 #include "ash/common/system/tray/tray_popup_utils.h" |
12 #include "ash/common/system/tray/tray_utils.h" | 11 #include "ash/common/system/tray/tray_utils.h" |
13 #include "ash/shell.h" | 12 #include "ash/shell.h" |
14 #include "ash/strings/grit/ash_strings.h" | 13 #include "ash/strings/grit/ash_strings.h" |
15 #include "base/i18n/rtl.h" | 14 #include "base/i18n/rtl.h" |
16 #include "base/i18n/time_formatting.h" | 15 #include "base/i18n/time_formatting.h" |
17 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
(...skipping 21 matching lines...) Expand all Loading... |
39 | 38 |
40 // Text color of the vertical clock minutes. | 39 // Text color of the vertical clock minutes. |
41 const SkColor kVerticalClockMinuteColor = SkColorSetRGB(0xBA, 0xBA, 0xBA); | 40 const SkColor kVerticalClockMinuteColor = SkColorSetRGB(0xBA, 0xBA, 0xBA); |
42 | 41 |
43 // Padding between the left edge of the shelf and the left edge of the vertical | 42 // Padding between the left edge of the shelf and the left edge of the vertical |
44 // clock. | 43 // clock. |
45 const int kVerticalClockLeftPadding = 9; | 44 const int kVerticalClockLeftPadding = 9; |
46 | 45 |
47 // Offset used to bring the minutes line closer to the hours line in the | 46 // Offset used to bring the minutes line closer to the hours line in the |
48 // vertical clock. | 47 // vertical clock. |
49 const int kVerticalClockMinutesTopOffset = -4; | 48 const int kVerticalClockMinutesTopOffset = -2; |
50 const int kVerticalClockMinutesTopOffsetMD = -2; | |
51 | 49 |
52 // Leading padding used to draw the tray background to the left of the clock | 50 // Leading padding used to draw the tray background to the left of the clock |
53 // when the shelf is vertically aligned. | 51 // when the shelf is vertically aligned. |
54 const int kClockLeadingPadding = 8; | 52 const int kClockLeadingPadding = 8; |
55 | 53 |
56 bool UseMd() { | |
57 return MaterialDesignController::IsSystemTrayMenuMaterial(); | |
58 } | |
59 | |
60 base::string16 FormatDate(const base::Time& time) { | 54 base::string16 FormatDate(const base::Time& time) { |
61 if (UseMd()) { | 55 // Use 'short' month format (e.g., "Oct") followed by non-padded day of |
62 // Use 'short' month format (e.g., "Oct") followed by non-padded day of | 56 // month (e.g., "2", "10"). |
63 // month (e.g., "2", "10"). | 57 return base::TimeFormatWithPattern(time, "LLLd"); |
64 return base::TimeFormatWithPattern(time, "LLLd"); | |
65 } else { | |
66 return base::TimeFormatShortDate(time); | |
67 } | |
68 } | 58 } |
69 | 59 |
70 base::string16 FormatDayOfWeek(const base::Time& time) { | 60 base::string16 FormatDayOfWeek(const base::Time& time) { |
71 // Use 'short' day of week format (e.g., "Wed"). | 61 // Use 'short' day of week format (e.g., "Wed"). |
72 return base::TimeFormatWithPattern(time, "EEE"); | 62 return base::TimeFormatWithPattern(time, "EEE"); |
73 } | 63 } |
74 | 64 |
75 } // namespace | 65 } // namespace |
76 | 66 |
77 BaseDateTimeView::~BaseDateTimeView() { | 67 BaseDateTimeView::~BaseDateTimeView() { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 } | 123 } |
134 | 124 |
135 void BaseDateTimeView::OnLocaleChanged() { | 125 void BaseDateTimeView::OnLocaleChanged() { |
136 UpdateText(); | 126 UpdateText(); |
137 } | 127 } |
138 | 128 |
139 /////////////////////////////////////////////////////////////////////////////// | 129 /////////////////////////////////////////////////////////////////////////////// |
140 | 130 |
141 DateView::DateView(SystemTrayItem* owner) | 131 DateView::DateView(SystemTrayItem* owner) |
142 : BaseDateTimeView(owner), action_(DateAction::NONE) { | 132 : BaseDateTimeView(owner), action_(DateAction::NONE) { |
143 if (UseMd()) { | 133 // TODO(tdanderson): Tweak spacing and layout for material design. |
144 // TODO(tdanderson): Tweak spacing and layout for material design. | 134 views::BoxLayout* box_layout = |
145 views::BoxLayout* box_layout = | 135 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); |
146 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0); | 136 box_layout->set_inside_border_insets(gfx::Insets(0, 12, 0, 0)); |
147 box_layout->set_inside_border_insets(gfx::Insets(0, 12, 0, 0)); | 137 box_layout->set_main_axis_alignment( |
148 box_layout->set_main_axis_alignment( | 138 views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); |
149 views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); | 139 box_layout->set_cross_axis_alignment( |
150 box_layout->set_cross_axis_alignment( | 140 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); |
151 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); | 141 SetLayoutManager(box_layout); |
152 SetLayoutManager(box_layout); | |
153 } else { | |
154 SetLayoutManager( | |
155 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | |
156 } | |
157 date_label_ = TrayPopupUtils::CreateDefaultLabel(); | 142 date_label_ = TrayPopupUtils::CreateDefaultLabel(); |
158 date_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 143 date_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
159 if (!UseMd()) | |
160 date_label_->SetEnabledColor(kHeaderTextColorNormal); | |
161 UpdateTextInternal(base::Time::Now()); | 144 UpdateTextInternal(base::Time::Now()); |
162 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::SYSTEM_INFO); | 145 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::SYSTEM_INFO); |
163 style.SetupLabel(date_label_); | 146 style.SetupLabel(date_label_); |
164 AddChildView(date_label_); | 147 AddChildView(date_label_); |
165 } | 148 } |
166 | 149 |
167 DateView::~DateView() {} | 150 DateView::~DateView() {} |
168 | 151 |
169 void DateView::SetAction(DateAction action) { | 152 void DateView::SetAction(DateAction action) { |
170 if (action == action_) | 153 if (action == action_) |
171 return; | 154 return; |
172 if (IsMouseHovered() && !UseMd()) { | |
173 date_label_->SetEnabledColor(action == DateAction::NONE | |
174 ? kHeaderTextColorNormal | |
175 : kHeaderTextColorHover); | |
176 SchedulePaint(); | |
177 } | |
178 action_ = action; | 155 action_ = action; |
179 SetFocusBehavior(action_ != DateAction::NONE ? FocusBehavior::ALWAYS | 156 SetFocusBehavior(action_ != DateAction::NONE ? FocusBehavior::ALWAYS |
180 : FocusBehavior::NEVER); | 157 : FocusBehavior::NEVER); |
181 | 158 |
182 // Disable |this| when not clickable so that the material design ripple is | 159 // Disable |this| when not clickable so that the ripple is not shown. |
183 // not shown. | 160 SetEnabled(action_ != DateAction::NONE); |
184 if (UseMd()) { | 161 if (action_ != DateAction::NONE) |
185 SetEnabled(action_ != DateAction::NONE); | 162 SetInkDropMode(views::InkDropHostView::InkDropMode::ON); |
186 if (action_ != DateAction::NONE) | |
187 SetInkDropMode(views::InkDropHostView::InkDropMode::ON); | |
188 } | |
189 } | 163 } |
190 | 164 |
191 void DateView::UpdateTimeFormat() { | 165 void DateView::UpdateTimeFormat() { |
192 hour_type_ = Shell::Get()->system_tray_controller()->hour_clock_type(); | 166 hour_type_ = Shell::Get()->system_tray_controller()->hour_clock_type(); |
193 UpdateText(); | 167 UpdateText(); |
194 } | 168 } |
195 | 169 |
196 base::HourClockType DateView::GetHourTypeForTesting() const { | 170 base::HourClockType DateView::GetHourTypeForTesting() const { |
197 return hour_type_; | 171 return hour_type_; |
198 } | 172 } |
199 | 173 |
200 void DateView::SetActive(bool active) { | |
201 if (UseMd()) | |
202 return; | |
203 | |
204 date_label_->SetEnabledColor(active ? kHeaderTextColorHover | |
205 : kHeaderTextColorNormal); | |
206 SchedulePaint(); | |
207 } | |
208 | |
209 void DateView::UpdateTextInternal(const base::Time& now) { | 174 void DateView::UpdateTextInternal(const base::Time& now) { |
210 BaseDateTimeView::UpdateTextInternal(now); | 175 BaseDateTimeView::UpdateTextInternal(now); |
211 date_label_->SetText(l10n_util::GetStringFUTF16( | 176 date_label_->SetText(l10n_util::GetStringFUTF16( |
212 IDS_ASH_STATUS_TRAY_DATE, FormatDayOfWeek(now), FormatDate(now))); | 177 IDS_ASH_STATUS_TRAY_DATE, FormatDayOfWeek(now), FormatDate(now))); |
213 } | 178 } |
214 | 179 |
215 bool DateView::PerformAction(const ui::Event& event) { | 180 bool DateView::PerformAction(const ui::Event& event) { |
216 if (action_ == DateAction::NONE) | 181 switch (action_) { |
217 return false; | 182 case DateAction::SHOW_DATE_SETTINGS: |
218 if (action_ == DateAction::SHOW_DATE_SETTINGS) | 183 Shell::Get()->system_tray_controller()->ShowDateSettings(); |
219 Shell::Get()->system_tray_controller()->ShowDateSettings(); | 184 break; |
220 else if (action_ == DateAction::SET_SYSTEM_TIME) | 185 case DateAction::SET_SYSTEM_TIME: |
221 Shell::Get()->system_tray_controller()->ShowSetTimeDialog(); | 186 Shell::Get()->system_tray_controller()->ShowSetTimeDialog(); |
222 else | 187 break; |
223 return false; | 188 case DateAction::NONE: |
| 189 return false; |
| 190 } |
224 CloseSystemBubble(); | 191 CloseSystemBubble(); |
225 return true; | 192 return true; |
226 } | 193 } |
227 | 194 |
228 void DateView::OnMouseEntered(const ui::MouseEvent& event) { | |
229 if (action_ == DateAction::NONE) | |
230 return; | |
231 SetActive(true); | |
232 } | |
233 | |
234 void DateView::OnMouseExited(const ui::MouseEvent& event) { | |
235 if (action_ == DateAction::NONE) | |
236 return; | |
237 SetActive(false); | |
238 } | |
239 | |
240 void DateView::OnGestureEvent(ui::GestureEvent* event) { | |
241 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { | |
242 SetActive(true); | |
243 } else if (event->type() == ui::ET_GESTURE_TAP_CANCEL || | |
244 event->type() == ui::ET_GESTURE_END) { | |
245 SetActive(false); | |
246 } | |
247 BaseDateTimeView::OnGestureEvent(event); | |
248 } | |
249 | |
250 /////////////////////////////////////////////////////////////////////////////// | 195 /////////////////////////////////////////////////////////////////////////////// |
251 | 196 |
252 TimeView::TimeView(ClockLayout clock_layout) : BaseDateTimeView(nullptr) { | 197 TimeView::TimeView(ClockLayout clock_layout) : BaseDateTimeView(nullptr) { |
253 SetupLabels(); | 198 SetupLabels(); |
254 UpdateTextInternal(base::Time::Now()); | 199 UpdateTextInternal(base::Time::Now()); |
255 UpdateClockLayout(clock_layout); | 200 UpdateClockLayout(clock_layout); |
256 } | 201 } |
257 | 202 |
258 TimeView::~TimeView() {} | 203 TimeView::~TimeView() {} |
259 | 204 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 } | 259 } |
315 | 260 |
316 void TimeView::UpdateClockLayout(ClockLayout clock_layout) { | 261 void TimeView::UpdateClockLayout(ClockLayout clock_layout) { |
317 SetBorderFromLayout(clock_layout); | 262 SetBorderFromLayout(clock_layout); |
318 if (clock_layout == ClockLayout::HORIZONTAL_CLOCK) { | 263 if (clock_layout == ClockLayout::HORIZONTAL_CLOCK) { |
319 RemoveChildView(vertical_label_hours_.get()); | 264 RemoveChildView(vertical_label_hours_.get()); |
320 RemoveChildView(vertical_label_minutes_.get()); | 265 RemoveChildView(vertical_label_minutes_.get()); |
321 SetLayoutManager(new views::FillLayout()); | 266 SetLayoutManager(new views::FillLayout()); |
322 AddChildView(horizontal_label_.get()); | 267 AddChildView(horizontal_label_.get()); |
323 } else { | 268 } else { |
324 const bool is_material_design = MaterialDesignController::IsShelfMaterial(); | |
325 RemoveChildView(horizontal_label_.get()); | 269 RemoveChildView(horizontal_label_.get()); |
326 views::GridLayout* layout = new views::GridLayout(this); | 270 views::GridLayout* layout = new views::GridLayout(this); |
327 SetLayoutManager(layout); | 271 SetLayoutManager(layout); |
328 const int kColumnId = 0; | 272 const int kColumnId = 0; |
329 views::ColumnSet* columns = layout->AddColumnSet(kColumnId); | 273 views::ColumnSet* columns = layout->AddColumnSet(kColumnId); |
330 columns->AddPaddingColumn(0, kVerticalClockLeftPadding); | 274 columns->AddPaddingColumn(0, kVerticalClockLeftPadding); |
331 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, | 275 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::CENTER, |
332 0, views::GridLayout::USE_PREF, 0, 0); | 276 0, views::GridLayout::USE_PREF, 0, 0); |
333 layout->AddPaddingRow( | 277 layout->AddPaddingRow(0, kClockLeadingPadding); |
334 0, is_material_design ? kClockLeadingPadding | |
335 : kTrayLabelItemVerticalPaddingVerticalAlignment); | |
336 layout->StartRow(0, kColumnId); | 278 layout->StartRow(0, kColumnId); |
337 layout->AddView(vertical_label_hours_.get()); | 279 layout->AddView(vertical_label_hours_.get()); |
338 layout->StartRow(0, kColumnId); | 280 layout->StartRow(0, kColumnId); |
339 layout->AddView(vertical_label_minutes_.get()); | 281 layout->AddView(vertical_label_minutes_.get()); |
340 layout->AddPaddingRow( | 282 layout->AddPaddingRow( |
341 0, | 283 0, kTrayImageItemPadding + kVerticalClockMinutesTopOffset); |
342 is_material_design | |
343 ? kTrayImageItemPadding + kVerticalClockMinutesTopOffsetMD | |
344 : kTrayLabelItemVerticalPaddingVerticalAlignment); | |
345 } | 284 } |
346 Layout(); | 285 Layout(); |
347 } | 286 } |
348 | 287 |
349 void TimeView::SetBorderFromLayout(ClockLayout clock_layout) { | 288 void TimeView::SetBorderFromLayout(ClockLayout clock_layout) { |
350 if (clock_layout == ClockLayout::HORIZONTAL_CLOCK) { | 289 if (clock_layout == ClockLayout::HORIZONTAL_CLOCK) |
351 SetBorder(views::CreateEmptyBorder( | 290 SetBorder(views::CreateEmptyBorder(gfx::Insets(0, kTrayImageItemPadding))); |
352 gfx::Insets(0, | 291 else |
353 UseMd() ? kTrayImageItemPadding | |
354 : kTrayLabelItemHorizontalPaddingBottomAlignment))); | |
355 } else { | |
356 SetBorder(views::NullBorder()); | 292 SetBorder(views::NullBorder()); |
357 } | |
358 } | 293 } |
359 | 294 |
360 void TimeView::SetupLabels() { | 295 void TimeView::SetupLabels() { |
361 horizontal_label_.reset(new views::Label()); | 296 horizontal_label_.reset(new views::Label()); |
362 SetupLabel(horizontal_label_.get()); | 297 SetupLabel(horizontal_label_.get()); |
363 vertical_label_hours_.reset(new views::Label()); | 298 vertical_label_hours_.reset(new views::Label()); |
364 SetupLabel(vertical_label_hours_.get()); | 299 SetupLabel(vertical_label_hours_.get()); |
365 vertical_label_minutes_.reset(new views::Label()); | 300 vertical_label_minutes_.reset(new views::Label()); |
366 SetupLabel(vertical_label_minutes_.get()); | 301 SetupLabel(vertical_label_minutes_.get()); |
367 // TODO(estade): this should use the NativeTheme's secondary text color. | 302 // TODO(estade): this should use the NativeTheme's secondary text color. See |
| 303 // crbug.com/687791 |
368 vertical_label_minutes_->SetEnabledColor(kVerticalClockMinuteColor); | 304 vertical_label_minutes_->SetEnabledColor(kVerticalClockMinuteColor); |
369 // Pull the minutes up closer to the hours by using a negative top border. | 305 // Pull the minutes up closer to the hours by using a negative top border. |
370 vertical_label_minutes_->SetBorder( | 306 vertical_label_minutes_->SetBorder( |
371 views::CreateEmptyBorder(MaterialDesignController::IsShelfMaterial() | 307 views::CreateEmptyBorder(kVerticalClockMinutesTopOffset, 0, 0, 0)); |
372 ? kVerticalClockMinutesTopOffsetMD | |
373 : kVerticalClockMinutesTopOffset, | |
374 0, 0, 0)); | |
375 } | 308 } |
376 | 309 |
377 void TimeView::SetupLabel(views::Label* label) { | 310 void TimeView::SetupLabel(views::Label* label) { |
378 label->set_owned_by_client(); | 311 label->set_owned_by_client(); |
379 SetupLabelForTray(label); | 312 SetupLabelForTray(label); |
380 label->SetElideBehavior(gfx::NO_ELIDE); | 313 label->SetElideBehavior(gfx::NO_ELIDE); |
381 } | 314 } |
382 | 315 |
383 } // namespace tray | 316 } // namespace tray |
384 } // namespace ash | 317 } // namespace ash |
OLD | NEW |