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

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

Issue 1953913002: Revise accessibility for Date/TimeView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@skip_ancestor
Patch Set: Created 4 years, 7 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/shell.h" 7 #include "ash/shell.h"
8 #include "ash/system/tray/system_tray_delegate.h" 8 #include "ash/system/tray/system_tray_delegate.h"
9 #include "ash/system/tray/tray_constants.h" 9 #include "ash/system/tray/tray_constants.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"
20 #include "ui/accessibility/ax_view_state.h"
20 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
21 #include "ui/base/ui_base_switches_util.h" 22 #include "ui/base/ui_base_switches_util.h"
22 #include "ui/views/border.h" 23 #include "ui/views/border.h"
23 #include "ui/views/controls/label.h" 24 #include "ui/views/controls/label.h"
24 #include "ui/views/layout/box_layout.h" 25 #include "ui/views/layout/box_layout.h"
25 #include "ui/views/layout/grid_layout.h" 26 #include "ui/views/layout/grid_layout.h"
26 #include "ui/views/widget/widget.h" 27 #include "ui/views/widget/widget.h"
27 28
28 namespace ash { 29 namespace ash {
29 namespace tray { 30 namespace tray {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 timer_.Stop(); 86 timer_.Stop();
86 } 87 }
87 88
88 void BaseDateTimeView::UpdateText() { 89 void BaseDateTimeView::UpdateText() {
89 base::Time now = base::Time::Now(); 90 base::Time now = base::Time::Now();
90 UpdateTextInternal(now); 91 UpdateTextInternal(now);
91 SchedulePaint(); 92 SchedulePaint();
92 SetTimer(now); 93 SetTimer(now);
93 } 94 }
94 95
95 BaseDateTimeView::BaseDateTimeView() { 96 void BaseDateTimeView::GetAccessibleState(ui::AXViewState* state) {
97 ActionableView::GetAccessibleState(state);
98 state->role = ui::AX_ROLE_TIME;
dmazzoni 2016/05/06 15:53:14 FYI, there is a AX_ROLE_DATE_TIME, would that be b
David Tseng 2016/05/06 20:40:14 It's a toss up because this base class is really B
99 }
100
101 BaseDateTimeView::BaseDateTimeView()
102 : hour_type_(ash::Shell::GetInstance()
103 ->system_tray_delegate()
104 ->GetHourClockType()) {
96 SetTimer(base::Time::Now()); 105 SetTimer(base::Time::Now());
97 SetFocusBehavior(FocusBehavior::NEVER); 106 SetFocusBehavior(FocusBehavior::NEVER);
98 } 107 }
99 108
100 void BaseDateTimeView::SetTimer(const base::Time& now) { 109 void BaseDateTimeView::SetTimer(const base::Time& now) {
101 // Try to set the timer to go off at the next change of the minute. We don't 110 // Try to set the timer to go off at the next change of the minute. We don't
102 // want to have the timer go off more than necessary since that will cause 111 // want to have the timer go off more than necessary since that will cause
103 // the CPU to wake up and consume power. 112 // the CPU to wake up and consume power.
104 base::Time::Exploded exploded; 113 base::Time::Exploded exploded;
105 now.LocalExplode(&exploded); 114 now.LocalExplode(&exploded);
106 115
107 // Often this will be called at minute boundaries, and we'll actually want 116 // Often this will be called at minute boundaries, and we'll actually want
108 // 60 seconds from now. 117 // 60 seconds from now.
109 int seconds_left = 60 - exploded.second; 118 int seconds_left = 60 - exploded.second;
110 if (seconds_left == 0) 119 if (seconds_left == 0)
111 seconds_left = 60; 120 seconds_left = 60;
112 121
113 // Make sure that the timer fires on the next minute. Without this, if it is 122 // Make sure that the timer fires on the next minute. Without this, if it is
114 // called just a teeny bit early, then it will skip the next minute. 123 // called just a teeny bit early, then it will skip the next minute.
115 seconds_left += kTimerSlopSeconds; 124 seconds_left += kTimerSlopSeconds;
116 125
117 timer_.Stop(); 126 timer_.Stop();
118 timer_.Start( 127 timer_.Start(
119 FROM_HERE, base::TimeDelta::FromSeconds(seconds_left), 128 FROM_HERE, base::TimeDelta::FromSeconds(seconds_left),
120 this, &BaseDateTimeView::UpdateText); 129 this, &BaseDateTimeView::UpdateText);
121 } 130 }
122 131
132 void BaseDateTimeView::UpdateTextInternal(const base::Time& now) {
133 SetAccessibleName(base::TimeFormatTimeOfDayWithHourClockType(
134 now, hour_type_, base::kKeepAmPm) +
135 base::ASCIIToUTF16(", ") +
136 base::TimeFormatFriendlyDate(now));
137
138 NotifyAccessibilityEvent(ui::AX_EVENT_TEXT_CHANGED, true);
139 }
140
123 void BaseDateTimeView::ChildPreferredSizeChanged(views::View* child) { 141 void BaseDateTimeView::ChildPreferredSizeChanged(views::View* child) {
124 PreferredSizeChanged(); 142 PreferredSizeChanged();
125 } 143 }
126 144
127 void BaseDateTimeView::OnLocaleChanged() { 145 void BaseDateTimeView::OnLocaleChanged() {
128 UpdateText(); 146 UpdateText();
129 } 147 }
130 148
131 DateView::DateView() 149 DateView::DateView() : action_(TrayDate::NONE) {
132 : hour_type_(ash::Shell::GetInstance()->system_tray_delegate()->
133 GetHourClockType()),
134 action_(TrayDate::NONE) {
135 SetLayoutManager( 150 SetLayoutManager(
136 new views::BoxLayout( 151 new views::BoxLayout(
137 views::BoxLayout::kVertical, 0, 0, 0)); 152 views::BoxLayout::kVertical, 0, 0, 0));
138 date_label_ = CreateLabel(); 153 date_label_ = CreateLabel();
139 date_label_->SetEnabledColor(kHeaderTextColorNormal); 154 date_label_->SetEnabledColor(kHeaderTextColorNormal);
140 UpdateTextInternal(base::Time::Now()); 155 UpdateTextInternal(base::Time::Now());
141 AddChildView(date_label_); 156 AddChildView(date_label_);
142 } 157 }
143 158
144 DateView::~DateView() { 159 DateView::~DateView() {
(...skipping 23 matching lines...) Expand all
168 return hour_type_; 183 return hour_type_;
169 } 184 }
170 185
171 void DateView::SetActive(bool active) { 186 void DateView::SetActive(bool active) {
172 date_label_->SetEnabledColor(active ? kHeaderTextColorHover 187 date_label_->SetEnabledColor(active ? kHeaderTextColorHover
173 : kHeaderTextColorNormal); 188 : kHeaderTextColorNormal);
174 SchedulePaint(); 189 SchedulePaint();
175 } 190 }
176 191
177 void DateView::UpdateTextInternal(const base::Time& now) { 192 void DateView::UpdateTextInternal(const base::Time& now) {
178 SetAccessibleName( 193 BaseDateTimeView::UpdateTextInternal(now);
179 base::TimeFormatFriendlyDate(now) +
180 base::ASCIIToUTF16(", ") +
181 base::TimeFormatTimeOfDayWithHourClockType(
182 now, hour_type_, base::kKeepAmPm));
183 date_label_->SetText( 194 date_label_->SetText(
184 l10n_util::GetStringFUTF16( 195 l10n_util::GetStringFUTF16(
185 IDS_ASH_STATUS_TRAY_DATE, FormatDayOfWeek(now), FormatDate(now))); 196 IDS_ASH_STATUS_TRAY_DATE, FormatDayOfWeek(now), FormatDate(now)));
186 } 197 }
187 198
188 bool DateView::PerformAction(const ui::Event& event) { 199 bool DateView::PerformAction(const ui::Event& event) {
189 if (action_ == TrayDate::NONE) 200 if (action_ == TrayDate::NONE)
190 return false; 201 return false;
191 if (action_ == TrayDate::SHOW_DATE_SETTINGS) 202 if (action_ == TrayDate::SHOW_DATE_SETTINGS)
192 ash::Shell::GetInstance()->system_tray_delegate()->ShowDateSettings(); 203 ash::Shell::GetInstance()->system_tray_delegate()->ShowDateSettings();
(...skipping 21 matching lines...) Expand all
214 } else if (event->type() == ui::ET_GESTURE_TAP_CANCEL || 225 } else if (event->type() == ui::ET_GESTURE_TAP_CANCEL ||
215 event->type() == ui::ET_GESTURE_END) { 226 event->type() == ui::ET_GESTURE_END) {
216 SetActive(false); 227 SetActive(false);
217 } 228 }
218 } 229 }
219 BaseDateTimeView::OnGestureEvent(event); 230 BaseDateTimeView::OnGestureEvent(event);
220 } 231 }
221 232
222 /////////////////////////////////////////////////////////////////////////////// 233 ///////////////////////////////////////////////////////////////////////////////
223 234
224 TimeView::TimeView(TrayDate::ClockLayout clock_layout) 235 TimeView::TimeView(TrayDate::ClockLayout clock_layout) {
225 : hour_type_(ash::Shell::GetInstance()->system_tray_delegate()->
226 GetHourClockType()) {
227 SetupLabels(); 236 SetupLabels();
228 UpdateTextInternal(base::Time::Now()); 237 UpdateTextInternal(base::Time::Now());
229 UpdateClockLayout(clock_layout); 238 UpdateClockLayout(clock_layout);
230 } 239 }
231 240
232 TimeView::~TimeView() { 241 TimeView::~TimeView() {
233 } 242 }
234 243
235 void TimeView::UpdateTimeFormat() { 244 void TimeView::UpdateTimeFormat() {
236 hour_type_ = 245 hour_type_ =
237 ash::Shell::GetInstance()->system_tray_delegate()->GetHourClockType(); 246 ash::Shell::GetInstance()->system_tray_delegate()->GetHourClockType();
238 UpdateText(); 247 UpdateText();
239 } 248 }
240 249
241 base::HourClockType TimeView::GetHourTypeForTesting() const { 250 base::HourClockType TimeView::GetHourTypeForTesting() const {
242 return hour_type_; 251 return hour_type_;
243 } 252 }
244 253
245 void TimeView::UpdateTextInternal(const base::Time& now) { 254 void TimeView::UpdateTextInternal(const base::Time& now) {
246 // Just in case |now| is null, do NOT update time; otherwise, it will 255 // Just in case |now| is null, do NOT update time; otherwise, it will
247 // crash icu code by calling into base::TimeFormatTimeOfDayWithHourClockType, 256 // crash icu code by calling into base::TimeFormatTimeOfDayWithHourClockType,
248 // see details in crbug.com/147570. 257 // see details in crbug.com/147570.
249 if (now.is_null()) { 258 if (now.is_null()) {
250 LOG(ERROR) << "Received null value from base::Time |now| in argument"; 259 LOG(ERROR) << "Received null value from base::Time |now| in argument";
251 return; 260 return;
252 } 261 }
253 262
263 BaseDateTimeView::UpdateTextInternal(now);
254 base::string16 current_time = base::TimeFormatTimeOfDayWithHourClockType( 264 base::string16 current_time = base::TimeFormatTimeOfDayWithHourClockType(
255 now, hour_type_, base::kDropAmPm); 265 now, hour_type_, base::kDropAmPm);
256 horizontal_label_->SetText(current_time); 266 horizontal_label_->SetText(current_time);
257 horizontal_label_->SetTooltipText(base::TimeFormatFriendlyDate(now)); 267 horizontal_label_->SetTooltipText(base::TimeFormatFriendlyDate(now));
258 268
259 // Calculate vertical clock layout labels. 269 // Calculate vertical clock layout labels.
260 size_t colon_pos = current_time.find(base::ASCIIToUTF16(":")); 270 size_t colon_pos = current_time.find(base::ASCIIToUTF16(":"));
261 base::string16 hour = current_time.substr(0, colon_pos); 271 base::string16 hour = current_time.substr(0, colon_pos);
262 base::string16 minute = current_time.substr(colon_pos + 1); 272 base::string16 minute = current_time.substr(colon_pos + 1);
263 273
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 } 343 }
334 344
335 void TimeView::SetupLabel(views::Label* label) { 345 void TimeView::SetupLabel(views::Label* label) {
336 label->set_owned_by_client(); 346 label->set_owned_by_client();
337 SetupLabelForTray(label); 347 SetupLabelForTray(label);
338 label->SetElideBehavior(gfx::NO_ELIDE); 348 label->SetElideBehavior(gfx::NO_ELIDE);
339 } 349 }
340 350
341 } // namespace tray 351 } // namespace tray
342 } // namespace ash 352 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698