| 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/system/tray/system_tray_delegate.h" | 7 #include "ash/common/system/tray/system_tray_delegate.h" |
| 8 #include "ash/common/system/tray/tray_constants.h" | 8 #include "ash/common/system/tray/tray_constants.h" |
| 9 #include "ash/common/system/tray/tray_utils.h" | 9 #include "ash/common/system/tray/tray_utils.h" |
| 10 #include "ash/common/wm_shell.h" | 10 #include "ash/common/wm_shell.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 UpdateTextInternal(now); | 82 UpdateTextInternal(now); |
| 83 SchedulePaint(); | 83 SchedulePaint(); |
| 84 SetTimer(now); | 84 SetTimer(now); |
| 85 } | 85 } |
| 86 | 86 |
| 87 void BaseDateTimeView::GetAccessibleState(ui::AXViewState* state) { | 87 void BaseDateTimeView::GetAccessibleState(ui::AXViewState* state) { |
| 88 ActionableView::GetAccessibleState(state); | 88 ActionableView::GetAccessibleState(state); |
| 89 state->role = ui::AX_ROLE_TIME; | 89 state->role = ui::AX_ROLE_TIME; |
| 90 } | 90 } |
| 91 | 91 |
| 92 BaseDateTimeView::BaseDateTimeView() | 92 BaseDateTimeView::BaseDateTimeView(SystemTrayItem* owner) |
| 93 : hour_type_(WmShell::Get()->system_tray_delegate()->GetHourClockType()) { | 93 : ActionableView(owner), |
| 94 hour_type_(WmShell::Get()->system_tray_delegate()->GetHourClockType()) { |
| 94 SetTimer(base::Time::Now()); | 95 SetTimer(base::Time::Now()); |
| 95 SetFocusBehavior(FocusBehavior::NEVER); | 96 SetFocusBehavior(FocusBehavior::NEVER); |
| 96 } | 97 } |
| 97 | 98 |
| 98 void BaseDateTimeView::SetTimer(const base::Time& now) { | 99 void BaseDateTimeView::SetTimer(const base::Time& now) { |
| 99 // Try to set the timer to go off at the next change of the minute. We don't | 100 // Try to set the timer to go off at the next change of the minute. We don't |
| 100 // want to have the timer go off more than necessary since that will cause | 101 // want to have the timer go off more than necessary since that will cause |
| 101 // the CPU to wake up and consume power. | 102 // the CPU to wake up and consume power. |
| 102 base::Time::Exploded exploded; | 103 base::Time::Exploded exploded; |
| 103 now.LocalExplode(&exploded); | 104 now.LocalExplode(&exploded); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 129 void BaseDateTimeView::ChildPreferredSizeChanged(views::View* child) { | 130 void BaseDateTimeView::ChildPreferredSizeChanged(views::View* child) { |
| 130 PreferredSizeChanged(); | 131 PreferredSizeChanged(); |
| 131 } | 132 } |
| 132 | 133 |
| 133 void BaseDateTimeView::OnLocaleChanged() { | 134 void BaseDateTimeView::OnLocaleChanged() { |
| 134 UpdateText(); | 135 UpdateText(); |
| 135 } | 136 } |
| 136 | 137 |
| 137 /////////////////////////////////////////////////////////////////////////////// | 138 /////////////////////////////////////////////////////////////////////////////// |
| 138 | 139 |
| 139 DateView::DateView() : action_(TrayDate::NONE) { | 140 DateView::DateView(SystemTrayItem* owner) |
| 141 : BaseDateTimeView(owner), action_(TrayDate::NONE) { |
| 140 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 142 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 141 date_label_ = new views::Label(); | 143 date_label_ = new views::Label(); |
| 142 date_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 144 date_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 143 date_label_->SetEnabledColor(kHeaderTextColorNormal); | 145 date_label_->SetEnabledColor(kHeaderTextColorNormal); |
| 144 UpdateTextInternal(base::Time::Now()); | 146 UpdateTextInternal(base::Time::Now()); |
| 145 AddChildView(date_label_); | 147 AddChildView(date_label_); |
| 146 } | 148 } |
| 147 | 149 |
| 148 DateView::~DateView() {} | 150 DateView::~DateView() {} |
| 149 | 151 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 IDS_ASH_STATUS_TRAY_DATE, FormatDayOfWeek(now), FormatDate(now))); | 184 IDS_ASH_STATUS_TRAY_DATE, FormatDayOfWeek(now), FormatDate(now))); |
| 183 } | 185 } |
| 184 | 186 |
| 185 bool DateView::PerformAction(const ui::Event& event) { | 187 bool DateView::PerformAction(const ui::Event& event) { |
| 186 if (action_ == TrayDate::NONE) | 188 if (action_ == TrayDate::NONE) |
| 187 return false; | 189 return false; |
| 188 if (action_ == TrayDate::SHOW_DATE_SETTINGS) | 190 if (action_ == TrayDate::SHOW_DATE_SETTINGS) |
| 189 WmShell::Get()->system_tray_delegate()->ShowDateSettings(); | 191 WmShell::Get()->system_tray_delegate()->ShowDateSettings(); |
| 190 else if (action_ == TrayDate::SET_SYSTEM_TIME) | 192 else if (action_ == TrayDate::SET_SYSTEM_TIME) |
| 191 WmShell::Get()->system_tray_delegate()->ShowSetTimeDialog(); | 193 WmShell::Get()->system_tray_delegate()->ShowSetTimeDialog(); |
| 194 else |
| 195 return false; |
| 196 CloseSystemBubble(); |
| 192 return true; | 197 return true; |
| 193 } | 198 } |
| 194 | 199 |
| 195 void DateView::OnMouseEntered(const ui::MouseEvent& event) { | 200 void DateView::OnMouseEntered(const ui::MouseEvent& event) { |
| 196 if (action_ == TrayDate::NONE) | 201 if (action_ == TrayDate::NONE) |
| 197 return; | 202 return; |
| 198 SetActive(true); | 203 SetActive(true); |
| 199 } | 204 } |
| 200 | 205 |
| 201 void DateView::OnMouseExited(const ui::MouseEvent& event) { | 206 void DateView::OnMouseExited(const ui::MouseEvent& event) { |
| 202 if (action_ == TrayDate::NONE) | 207 if (action_ == TrayDate::NONE) |
| 203 return; | 208 return; |
| 204 SetActive(false); | 209 SetActive(false); |
| 205 } | 210 } |
| 206 | 211 |
| 207 void DateView::OnGestureEvent(ui::GestureEvent* event) { | 212 void DateView::OnGestureEvent(ui::GestureEvent* event) { |
| 208 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { | 213 if (event->type() == ui::ET_GESTURE_TAP_DOWN) { |
| 209 SetActive(true); | 214 SetActive(true); |
| 210 } else if (event->type() == ui::ET_GESTURE_TAP_CANCEL || | 215 } else if (event->type() == ui::ET_GESTURE_TAP_CANCEL || |
| 211 event->type() == ui::ET_GESTURE_END) { | 216 event->type() == ui::ET_GESTURE_END) { |
| 212 SetActive(false); | 217 SetActive(false); |
| 213 } | 218 } |
| 214 BaseDateTimeView::OnGestureEvent(event); | 219 BaseDateTimeView::OnGestureEvent(event); |
| 215 } | 220 } |
| 216 | 221 |
| 217 /////////////////////////////////////////////////////////////////////////////// | 222 /////////////////////////////////////////////////////////////////////////////// |
| 218 | 223 |
| 219 TimeView::TimeView(TrayDate::ClockLayout clock_layout) { | 224 TimeView::TimeView(TrayDate::ClockLayout clock_layout) |
| 225 : BaseDateTimeView(nullptr) { |
| 220 SetupLabels(); | 226 SetupLabels(); |
| 221 UpdateTextInternal(base::Time::Now()); | 227 UpdateTextInternal(base::Time::Now()); |
| 222 UpdateClockLayout(clock_layout); | 228 UpdateClockLayout(clock_layout); |
| 223 } | 229 } |
| 224 | 230 |
| 225 TimeView::~TimeView() {} | 231 TimeView::~TimeView() {} |
| 226 | 232 |
| 227 void TimeView::UpdateTimeFormat() { | 233 void TimeView::UpdateTimeFormat() { |
| 228 hour_type_ = WmShell::Get()->system_tray_delegate()->GetHourClockType(); | 234 hour_type_ = WmShell::Get()->system_tray_delegate()->GetHourClockType(); |
| 229 UpdateText(); | 235 UpdateText(); |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 } | 329 } |
| 324 | 330 |
| 325 void TimeView::SetupLabel(views::Label* label) { | 331 void TimeView::SetupLabel(views::Label* label) { |
| 326 label->set_owned_by_client(); | 332 label->set_owned_by_client(); |
| 327 SetupLabelForTray(label); | 333 SetupLabelForTray(label); |
| 328 label->SetElideBehavior(gfx::NO_ELIDE); | 334 label->SetElideBehavior(gfx::NO_ELIDE); |
| 329 } | 335 } |
| 330 | 336 |
| 331 } // namespace tray | 337 } // namespace tray |
| 332 } // namespace ash | 338 } // namespace ash |
| OLD | NEW |