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

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

Issue 2058173002: mash: Move SystemTrayDelegate ownership to WmShell (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review feedback Created 4 years, 6 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
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/system/date/date_view.h" 5 #include "ash/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/shell.h" 9 #include "ash/common/wm_shell.h"
10 #include "ash/system/tray/tray_utils.h" 10 #include "ash/system/tray/tray_utils.h"
11 #include "base/command_line.h" 11 #include "base/command_line.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"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 SchedulePaint(); 92 SchedulePaint();
93 SetTimer(now); 93 SetTimer(now);
94 } 94 }
95 95
96 void BaseDateTimeView::GetAccessibleState(ui::AXViewState* state) { 96 void BaseDateTimeView::GetAccessibleState(ui::AXViewState* state) {
97 ActionableView::GetAccessibleState(state); 97 ActionableView::GetAccessibleState(state);
98 state->role = ui::AX_ROLE_TIME; 98 state->role = ui::AX_ROLE_TIME;
99 } 99 }
100 100
101 BaseDateTimeView::BaseDateTimeView() 101 BaseDateTimeView::BaseDateTimeView()
102 : hour_type_(ash::Shell::GetInstance() 102 : hour_type_(WmShell::Get()->system_tray_delegate()->GetHourClockType()) {
103 ->system_tray_delegate()
104 ->GetHourClockType()) {
105 SetTimer(base::Time::Now()); 103 SetTimer(base::Time::Now());
106 SetFocusBehavior(FocusBehavior::NEVER); 104 SetFocusBehavior(FocusBehavior::NEVER);
107 } 105 }
108 106
109 void BaseDateTimeView::SetTimer(const base::Time& now) { 107 void BaseDateTimeView::SetTimer(const base::Time& now) {
110 // Try to set the timer to go off at the next change of the minute. We don't 108 // Try to set the timer to go off at the next change of the minute. We don't
111 // want to have the timer go off more than necessary since that will cause 109 // want to have the timer go off more than necessary since that will cause
112 // the CPU to wake up and consume power. 110 // the CPU to wake up and consume power.
113 base::Time::Exploded exploded; 111 base::Time::Exploded exploded;
114 now.LocalExplode(&exploded); 112 now.LocalExplode(&exploded);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 action == TrayDate::NONE ? kHeaderTextColorNormal : 165 action == TrayDate::NONE ? kHeaderTextColorNormal :
168 kHeaderTextColorHover); 166 kHeaderTextColorHover);
169 SchedulePaint(); 167 SchedulePaint();
170 } 168 }
171 action_ = action; 169 action_ = action;
172 SetFocusBehavior(action_ != TrayDate::NONE ? FocusBehavior::ALWAYS 170 SetFocusBehavior(action_ != TrayDate::NONE ? FocusBehavior::ALWAYS
173 : FocusBehavior::NEVER); 171 : FocusBehavior::NEVER);
174 } 172 }
175 173
176 void DateView::UpdateTimeFormat() { 174 void DateView::UpdateTimeFormat() {
177 hour_type_ = 175 hour_type_ = WmShell::Get()->system_tray_delegate()->GetHourClockType();
178 ash::Shell::GetInstance()->system_tray_delegate()->GetHourClockType();
179 UpdateText(); 176 UpdateText();
180 } 177 }
181 178
182 base::HourClockType DateView::GetHourTypeForTesting() const { 179 base::HourClockType DateView::GetHourTypeForTesting() const {
183 return hour_type_; 180 return hour_type_;
184 } 181 }
185 182
186 void DateView::SetActive(bool active) { 183 void DateView::SetActive(bool active) {
187 date_label_->SetEnabledColor(active ? kHeaderTextColorHover 184 date_label_->SetEnabledColor(active ? kHeaderTextColorHover
188 : kHeaderTextColorNormal); 185 : kHeaderTextColorNormal);
189 SchedulePaint(); 186 SchedulePaint();
190 } 187 }
191 188
192 void DateView::UpdateTextInternal(const base::Time& now) { 189 void DateView::UpdateTextInternal(const base::Time& now) {
193 BaseDateTimeView::UpdateTextInternal(now); 190 BaseDateTimeView::UpdateTextInternal(now);
194 date_label_->SetText( 191 date_label_->SetText(
195 l10n_util::GetStringFUTF16( 192 l10n_util::GetStringFUTF16(
196 IDS_ASH_STATUS_TRAY_DATE, FormatDayOfWeek(now), FormatDate(now))); 193 IDS_ASH_STATUS_TRAY_DATE, FormatDayOfWeek(now), FormatDate(now)));
197 } 194 }
198 195
199 bool DateView::PerformAction(const ui::Event& event) { 196 bool DateView::PerformAction(const ui::Event& event) {
200 if (action_ == TrayDate::NONE) 197 if (action_ == TrayDate::NONE)
201 return false; 198 return false;
202 if (action_ == TrayDate::SHOW_DATE_SETTINGS) 199 if (action_ == TrayDate::SHOW_DATE_SETTINGS)
203 ash::Shell::GetInstance()->system_tray_delegate()->ShowDateSettings(); 200 WmShell::Get()->system_tray_delegate()->ShowDateSettings();
204 else if (action_ == TrayDate::SET_SYSTEM_TIME) 201 else if (action_ == TrayDate::SET_SYSTEM_TIME)
205 ash::Shell::GetInstance()->system_tray_delegate()->ShowSetTimeDialog(); 202 WmShell::Get()->system_tray_delegate()->ShowSetTimeDialog();
206 return true; 203 return true;
207 } 204 }
208 205
209 void DateView::OnMouseEntered(const ui::MouseEvent& event) { 206 void DateView::OnMouseEntered(const ui::MouseEvent& event) {
210 if (action_ == TrayDate::NONE) 207 if (action_ == TrayDate::NONE)
211 return; 208 return;
212 SetActive(true); 209 SetActive(true);
213 } 210 }
214 211
215 void DateView::OnMouseExited(const ui::MouseEvent& event) { 212 void DateView::OnMouseExited(const ui::MouseEvent& event) {
(...skipping 19 matching lines...) Expand all
235 TimeView::TimeView(TrayDate::ClockLayout clock_layout) { 232 TimeView::TimeView(TrayDate::ClockLayout clock_layout) {
236 SetupLabels(); 233 SetupLabels();
237 UpdateTextInternal(base::Time::Now()); 234 UpdateTextInternal(base::Time::Now());
238 UpdateClockLayout(clock_layout); 235 UpdateClockLayout(clock_layout);
239 } 236 }
240 237
241 TimeView::~TimeView() { 238 TimeView::~TimeView() {
242 } 239 }
243 240
244 void TimeView::UpdateTimeFormat() { 241 void TimeView::UpdateTimeFormat() {
245 hour_type_ = 242 hour_type_ = WmShell::Get()->system_tray_delegate()->GetHourClockType();
246 ash::Shell::GetInstance()->system_tray_delegate()->GetHourClockType();
247 UpdateText(); 243 UpdateText();
248 } 244 }
249 245
250 base::HourClockType TimeView::GetHourTypeForTesting() const { 246 base::HourClockType TimeView::GetHourTypeForTesting() const {
251 return hour_type_; 247 return hour_type_;
252 } 248 }
253 249
254 void TimeView::UpdateTextInternal(const base::Time& now) { 250 void TimeView::UpdateTextInternal(const base::Time& now) {
255 // Just in case |now| is null, do NOT update time; otherwise, it will 251 // Just in case |now| is null, do NOT update time; otherwise, it will
256 // crash icu code by calling into base::TimeFormatTimeOfDayWithHourClockType, 252 // crash icu code by calling into base::TimeFormatTimeOfDayWithHourClockType,
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 } 339 }
344 340
345 void TimeView::SetupLabel(views::Label* label) { 341 void TimeView::SetupLabel(views::Label* label) {
346 label->set_owned_by_client(); 342 label->set_owned_by_client();
347 SetupLabelForTray(label); 343 SetupLabelForTray(label);
348 label->SetElideBehavior(gfx::NO_ELIDE); 344 label->SetElideBehavior(gfx::NO_ELIDE);
349 } 345 }
350 346
351 } // namespace tray 347 } // namespace tray
352 } // namespace ash 348 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698