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

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

Issue 2381753002: Use mojo SystemTray interfaces for both mash and classic ash (Closed)
Patch Set: review comments Created 4 years, 2 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/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_controller.h"
7 #include "ash/common/system/tray/system_tray_delegate.h" 8 #include "ash/common/system/tray/system_tray_delegate.h"
8 #include "ash/common/system/tray/tray_constants.h" 9 #include "ash/common/system/tray/tray_constants.h"
9 #include "ash/common/system/tray/tray_utils.h" 10 #include "ash/common/system/tray/tray_utils.h"
10 #include "ash/common/wm_shell.h" 11 #include "ash/common/wm_shell.h"
11 #include "base/i18n/rtl.h" 12 #include "base/i18n/rtl.h"
12 #include "base/i18n/time_formatting.h" 13 #include "base/i18n/time_formatting.h"
13 #include "base/strings/utf_string_conversions.h" 14 #include "base/strings/utf_string_conversions.h"
14 #include "base/time/time.h" 15 #include "base/time/time.h"
15 #include "grit/ash_strings.h" 16 #include "grit/ash_strings.h"
16 #include "third_party/icu/source/i18n/unicode/datefmt.h" 17 #include "third_party/icu/source/i18n/unicode/datefmt.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 SetTimer(now); 85 SetTimer(now);
85 } 86 }
86 87
87 void BaseDateTimeView::GetAccessibleState(ui::AXViewState* state) { 88 void BaseDateTimeView::GetAccessibleState(ui::AXViewState* state) {
88 ActionableView::GetAccessibleState(state); 89 ActionableView::GetAccessibleState(state);
89 state->role = ui::AX_ROLE_TIME; 90 state->role = ui::AX_ROLE_TIME;
90 } 91 }
91 92
92 BaseDateTimeView::BaseDateTimeView(SystemTrayItem* owner) 93 BaseDateTimeView::BaseDateTimeView(SystemTrayItem* owner)
93 : ActionableView(owner), 94 : ActionableView(owner),
94 hour_type_(WmShell::Get()->system_tray_delegate()->GetHourClockType()) { 95 hour_type_(WmShell::Get()->system_tray_controller()->hour_clock_type()) {
95 SetTimer(base::Time::Now()); 96 SetTimer(base::Time::Now());
96 SetFocusBehavior(FocusBehavior::NEVER); 97 SetFocusBehavior(FocusBehavior::NEVER);
97 } 98 }
98 99
99 void BaseDateTimeView::SetTimer(const base::Time& now) { 100 void BaseDateTimeView::SetTimer(const base::Time& now) {
100 // Try to set the timer to go off at the next change of the minute. We don't 101 // Try to set the timer to go off at the next change of the minute. We don't
101 // want to have the timer go off more than necessary since that will cause 102 // want to have the timer go off more than necessary since that will cause
102 // the CPU to wake up and consume power. 103 // the CPU to wake up and consume power.
103 base::Time::Exploded exploded; 104 base::Time::Exploded exploded;
104 now.LocalExplode(&exploded); 105 now.LocalExplode(&exploded);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 ? kHeaderTextColorNormal 158 ? kHeaderTextColorNormal
158 : kHeaderTextColorHover); 159 : kHeaderTextColorHover);
159 SchedulePaint(); 160 SchedulePaint();
160 } 161 }
161 action_ = action; 162 action_ = action;
162 SetFocusBehavior(action_ != TrayDate::NONE ? FocusBehavior::ALWAYS 163 SetFocusBehavior(action_ != TrayDate::NONE ? FocusBehavior::ALWAYS
163 : FocusBehavior::NEVER); 164 : FocusBehavior::NEVER);
164 } 165 }
165 166
166 void DateView::UpdateTimeFormat() { 167 void DateView::UpdateTimeFormat() {
167 hour_type_ = WmShell::Get()->system_tray_delegate()->GetHourClockType(); 168 hour_type_ = WmShell::Get()->system_tray_controller()->hour_clock_type();
168 UpdateText(); 169 UpdateText();
169 } 170 }
170 171
171 base::HourClockType DateView::GetHourTypeForTesting() const { 172 base::HourClockType DateView::GetHourTypeForTesting() const {
172 return hour_type_; 173 return hour_type_;
173 } 174 }
174 175
175 void DateView::SetActive(bool active) { 176 void DateView::SetActive(bool active) {
176 date_label_->SetEnabledColor(active ? kHeaderTextColorHover 177 date_label_->SetEnabledColor(active ? kHeaderTextColorHover
177 : kHeaderTextColorNormal); 178 : kHeaderTextColorNormal);
178 SchedulePaint(); 179 SchedulePaint();
179 } 180 }
180 181
181 void DateView::UpdateTextInternal(const base::Time& now) { 182 void DateView::UpdateTextInternal(const base::Time& now) {
182 BaseDateTimeView::UpdateTextInternal(now); 183 BaseDateTimeView::UpdateTextInternal(now);
183 date_label_->SetText(l10n_util::GetStringFUTF16( 184 date_label_->SetText(l10n_util::GetStringFUTF16(
184 IDS_ASH_STATUS_TRAY_DATE, FormatDayOfWeek(now), FormatDate(now))); 185 IDS_ASH_STATUS_TRAY_DATE, FormatDayOfWeek(now), FormatDate(now)));
185 } 186 }
186 187
187 bool DateView::PerformAction(const ui::Event& event) { 188 bool DateView::PerformAction(const ui::Event& event) {
188 if (action_ == TrayDate::NONE) 189 if (action_ == TrayDate::NONE)
189 return false; 190 return false;
190 if (action_ == TrayDate::SHOW_DATE_SETTINGS) 191 if (action_ == TrayDate::SHOW_DATE_SETTINGS)
191 WmShell::Get()->system_tray_delegate()->ShowDateSettings(); 192 WmShell::Get()->system_tray_controller()->ShowDateSettings();
192 else if (action_ == TrayDate::SET_SYSTEM_TIME) 193 else if (action_ == TrayDate::SET_SYSTEM_TIME)
193 WmShell::Get()->system_tray_delegate()->ShowSetTimeDialog(); 194 WmShell::Get()->system_tray_delegate()->ShowSetTimeDialog();
194 else 195 else
195 return false; 196 return false;
196 CloseSystemBubble(); 197 CloseSystemBubble();
197 return true; 198 return true;
198 } 199 }
199 200
200 void DateView::OnMouseEntered(const ui::MouseEvent& event) { 201 void DateView::OnMouseEntered(const ui::MouseEvent& event) {
201 if (action_ == TrayDate::NONE) 202 if (action_ == TrayDate::NONE)
(...skipping 22 matching lines...) Expand all
224 TimeView::TimeView(TrayDate::ClockLayout clock_layout) 225 TimeView::TimeView(TrayDate::ClockLayout clock_layout)
225 : BaseDateTimeView(nullptr) { 226 : BaseDateTimeView(nullptr) {
226 SetupLabels(); 227 SetupLabels();
227 UpdateTextInternal(base::Time::Now()); 228 UpdateTextInternal(base::Time::Now());
228 UpdateClockLayout(clock_layout); 229 UpdateClockLayout(clock_layout);
229 } 230 }
230 231
231 TimeView::~TimeView() {} 232 TimeView::~TimeView() {}
232 233
233 void TimeView::UpdateTimeFormat() { 234 void TimeView::UpdateTimeFormat() {
234 hour_type_ = WmShell::Get()->system_tray_delegate()->GetHourClockType(); 235 hour_type_ = WmShell::Get()->system_tray_controller()->hour_clock_type();
235 UpdateText(); 236 UpdateText();
236 } 237 }
237 238
238 base::HourClockType TimeView::GetHourTypeForTesting() const { 239 base::HourClockType TimeView::GetHourTypeForTesting() const {
239 return hour_type_; 240 return hour_type_;
240 } 241 }
241 242
242 void TimeView::UpdateTextInternal(const base::Time& now) { 243 void TimeView::UpdateTextInternal(const base::Time& now) {
243 // Just in case |now| is null, do NOT update time; otherwise, it will 244 // Just in case |now| is null, do NOT update time; otherwise, it will
244 // crash icu code by calling into base::TimeFormatTimeOfDayWithHourClockType, 245 // crash icu code by calling into base::TimeFormatTimeOfDayWithHourClockType,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 } 330 }
330 331
331 void TimeView::SetupLabel(views::Label* label) { 332 void TimeView::SetupLabel(views::Label* label) {
332 label->set_owned_by_client(); 333 label->set_owned_by_client();
333 SetupLabelForTray(label); 334 SetupLabelForTray(label);
334 label->SetElideBehavior(gfx::NO_ELIDE); 335 label->SetElideBehavior(gfx::NO_ELIDE);
335 } 336 }
336 337
337 } // namespace tray 338 } // namespace tray
338 } // namespace ash 339 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698