| 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/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_popup_item_style.h" | 10 #include "ash/common/system/tray/tray_popup_item_style.h" |
| 11 #include "ash/common/system/tray/tray_popup_utils.h" | 11 #include "ash/common/system/tray/tray_popup_utils.h" |
| 12 #include "ash/common/system/tray/tray_utils.h" | 12 #include "ash/common/system/tray/tray_utils.h" |
| 13 #include "ash/common/wm_shell.h" | 13 #include "ash/shell.h" |
| 14 #include "ash/strings/grit/ash_strings.h" | 14 #include "ash/strings/grit/ash_strings.h" |
| 15 #include "base/i18n/rtl.h" | 15 #include "base/i18n/rtl.h" |
| 16 #include "base/i18n/time_formatting.h" | 16 #include "base/i18n/time_formatting.h" |
| 17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 18 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 19 #include "third_party/icu/source/i18n/unicode/datefmt.h" | 19 #include "third_party/icu/source/i18n/unicode/datefmt.h" |
| 20 #include "third_party/icu/source/i18n/unicode/dtptngen.h" | 20 #include "third_party/icu/source/i18n/unicode/dtptngen.h" |
| 21 #include "third_party/icu/source/i18n/unicode/smpdtfmt.h" | 21 #include "third_party/icu/source/i18n/unicode/smpdtfmt.h" |
| 22 #include "ui/accessibility/ax_node_data.h" | 22 #include "ui/accessibility/ax_node_data.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 SetTimer(now); | 109 SetTimer(now); |
| 110 } | 110 } |
| 111 | 111 |
| 112 void BaseDateTimeView::GetAccessibleNodeData(ui::AXNodeData* node_data) { | 112 void BaseDateTimeView::GetAccessibleNodeData(ui::AXNodeData* node_data) { |
| 113 ActionableView::GetAccessibleNodeData(node_data); | 113 ActionableView::GetAccessibleNodeData(node_data); |
| 114 node_data->role = ui::AX_ROLE_TIME; | 114 node_data->role = ui::AX_ROLE_TIME; |
| 115 } | 115 } |
| 116 | 116 |
| 117 BaseDateTimeView::BaseDateTimeView(SystemTrayItem* owner) | 117 BaseDateTimeView::BaseDateTimeView(SystemTrayItem* owner) |
| 118 : ActionableView(owner, TrayPopupInkDropStyle::INSET_BOUNDS), | 118 : ActionableView(owner, TrayPopupInkDropStyle::INSET_BOUNDS), |
| 119 hour_type_(WmShell::Get()->system_tray_controller()->hour_clock_type()) { | 119 hour_type_(Shell::Get()->system_tray_controller()->hour_clock_type()) { |
| 120 SetTimer(base::Time::Now()); | 120 SetTimer(base::Time::Now()); |
| 121 SetFocusBehavior(FocusBehavior::NEVER); | 121 SetFocusBehavior(FocusBehavior::NEVER); |
| 122 } | 122 } |
| 123 | 123 |
| 124 void BaseDateTimeView::SetTimer(const base::Time& now) { | 124 void BaseDateTimeView::SetTimer(const base::Time& now) { |
| 125 // Try to set the timer to go off at the next change of the minute. We don't | 125 // Try to set the timer to go off at the next change of the minute. We don't |
| 126 // want to have the timer go off more than necessary since that will cause | 126 // want to have the timer go off more than necessary since that will cause |
| 127 // the CPU to wake up and consume power. | 127 // the CPU to wake up and consume power. |
| 128 base::Time::Exploded exploded; | 128 base::Time::Exploded exploded; |
| 129 now.LocalExplode(&exploded); | 129 now.LocalExplode(&exploded); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 // Disable |this| when not clickable so that the material design ripple is | 206 // Disable |this| when not clickable so that the material design ripple is |
| 207 // not shown. | 207 // not shown. |
| 208 if (UseMd()) { | 208 if (UseMd()) { |
| 209 SetEnabled(action_ != DateAction::NONE); | 209 SetEnabled(action_ != DateAction::NONE); |
| 210 if (action_ != DateAction::NONE) | 210 if (action_ != DateAction::NONE) |
| 211 SetInkDropMode(views::InkDropHostView::InkDropMode::ON); | 211 SetInkDropMode(views::InkDropHostView::InkDropMode::ON); |
| 212 } | 212 } |
| 213 } | 213 } |
| 214 | 214 |
| 215 void DateView::UpdateTimeFormat() { | 215 void DateView::UpdateTimeFormat() { |
| 216 hour_type_ = WmShell::Get()->system_tray_controller()->hour_clock_type(); | 216 hour_type_ = Shell::Get()->system_tray_controller()->hour_clock_type(); |
| 217 UpdateText(); | 217 UpdateText(); |
| 218 } | 218 } |
| 219 | 219 |
| 220 base::HourClockType DateView::GetHourTypeForTesting() const { | 220 base::HourClockType DateView::GetHourTypeForTesting() const { |
| 221 return hour_type_; | 221 return hour_type_; |
| 222 } | 222 } |
| 223 | 223 |
| 224 void DateView::SetActive(bool active) { | 224 void DateView::SetActive(bool active) { |
| 225 if (UseMd()) | 225 if (UseMd()) |
| 226 return; | 226 return; |
| 227 | 227 |
| 228 date_label_->SetEnabledColor(active ? kHeaderTextColorHover | 228 date_label_->SetEnabledColor(active ? kHeaderTextColorHover |
| 229 : kHeaderTextColorNormal); | 229 : kHeaderTextColorNormal); |
| 230 SchedulePaint(); | 230 SchedulePaint(); |
| 231 } | 231 } |
| 232 | 232 |
| 233 void DateView::UpdateTextInternal(const base::Time& now) { | 233 void DateView::UpdateTextInternal(const base::Time& now) { |
| 234 BaseDateTimeView::UpdateTextInternal(now); | 234 BaseDateTimeView::UpdateTextInternal(now); |
| 235 date_label_->SetText(l10n_util::GetStringFUTF16( | 235 date_label_->SetText(l10n_util::GetStringFUTF16( |
| 236 IDS_ASH_STATUS_TRAY_DATE, FormatDayOfWeek(now), FormatDate(now))); | 236 IDS_ASH_STATUS_TRAY_DATE, FormatDayOfWeek(now), FormatDate(now))); |
| 237 } | 237 } |
| 238 | 238 |
| 239 bool DateView::PerformAction(const ui::Event& event) { | 239 bool DateView::PerformAction(const ui::Event& event) { |
| 240 if (action_ == DateAction::NONE) | 240 if (action_ == DateAction::NONE) |
| 241 return false; | 241 return false; |
| 242 if (action_ == DateAction::SHOW_DATE_SETTINGS) | 242 if (action_ == DateAction::SHOW_DATE_SETTINGS) |
| 243 WmShell::Get()->system_tray_controller()->ShowDateSettings(); | 243 Shell::Get()->system_tray_controller()->ShowDateSettings(); |
| 244 else if (action_ == DateAction::SET_SYSTEM_TIME) | 244 else if (action_ == DateAction::SET_SYSTEM_TIME) |
| 245 WmShell::Get()->system_tray_controller()->ShowSetTimeDialog(); | 245 Shell::Get()->system_tray_controller()->ShowSetTimeDialog(); |
| 246 else | 246 else |
| 247 return false; | 247 return false; |
| 248 CloseSystemBubble(); | 248 CloseSystemBubble(); |
| 249 return true; | 249 return true; |
| 250 } | 250 } |
| 251 | 251 |
| 252 void DateView::OnMouseEntered(const ui::MouseEvent& event) { | 252 void DateView::OnMouseEntered(const ui::MouseEvent& event) { |
| 253 if (action_ == DateAction::NONE) | 253 if (action_ == DateAction::NONE) |
| 254 return; | 254 return; |
| 255 SetActive(true); | 255 SetActive(true); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 275 | 275 |
| 276 TimeView::TimeView(ClockLayout clock_layout) : BaseDateTimeView(nullptr) { | 276 TimeView::TimeView(ClockLayout clock_layout) : BaseDateTimeView(nullptr) { |
| 277 SetupLabels(); | 277 SetupLabels(); |
| 278 UpdateTextInternal(base::Time::Now()); | 278 UpdateTextInternal(base::Time::Now()); |
| 279 UpdateClockLayout(clock_layout); | 279 UpdateClockLayout(clock_layout); |
| 280 } | 280 } |
| 281 | 281 |
| 282 TimeView::~TimeView() {} | 282 TimeView::~TimeView() {} |
| 283 | 283 |
| 284 void TimeView::UpdateTimeFormat() { | 284 void TimeView::UpdateTimeFormat() { |
| 285 hour_type_ = WmShell::Get()->system_tray_controller()->hour_clock_type(); | 285 hour_type_ = Shell::Get()->system_tray_controller()->hour_clock_type(); |
| 286 UpdateText(); | 286 UpdateText(); |
| 287 } | 287 } |
| 288 | 288 |
| 289 base::HourClockType TimeView::GetHourTypeForTesting() const { | 289 base::HourClockType TimeView::GetHourTypeForTesting() const { |
| 290 return hour_type_; | 290 return hour_type_; |
| 291 } | 291 } |
| 292 | 292 |
| 293 void TimeView::UpdateTextInternal(const base::Time& now) { | 293 void TimeView::UpdateTextInternal(const base::Time& now) { |
| 294 // Just in case |now| is null, do NOT update time; otherwise, it will | 294 // Just in case |now| is null, do NOT update time; otherwise, it will |
| 295 // crash icu code by calling into base::TimeFormatTimeOfDayWithHourClockType, | 295 // crash icu code by calling into base::TimeFormatTimeOfDayWithHourClockType, |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 } | 399 } |
| 400 | 400 |
| 401 void TimeView::SetupLabel(views::Label* label) { | 401 void TimeView::SetupLabel(views::Label* label) { |
| 402 label->set_owned_by_client(); | 402 label->set_owned_by_client(); |
| 403 SetupLabelForTray(label); | 403 SetupLabelForTray(label); |
| 404 label->SetElideBehavior(gfx::NO_ELIDE); | 404 label->SetElideBehavior(gfx::NO_ELIDE); |
| 405 } | 405 } |
| 406 | 406 |
| 407 } // namespace tray | 407 } // namespace tray |
| 408 } // namespace ash | 408 } // namespace ash |
| OLD | NEW |