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

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: cleanup 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_delegate.h" 7 #include "ash/common/system/tray/system_tray_controller.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"
11 #include "base/i18n/rtl.h" 11 #include "base/i18n/rtl.h"
12 #include "base/i18n/time_formatting.h" 12 #include "base/i18n/time_formatting.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "grit/ash_strings.h" 15 #include "grit/ash_strings.h"
16 #include "third_party/icu/source/i18n/unicode/datefmt.h" 16 #include "third_party/icu/source/i18n/unicode/datefmt.h"
17 #include "third_party/icu/source/i18n/unicode/dtptngen.h" 17 #include "third_party/icu/source/i18n/unicode/dtptngen.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(SystemTrayItem* owner) 92 BaseDateTimeView::BaseDateTimeView(SystemTrayItem* owner)
93 : ActionableView(owner), 93 : ActionableView(owner),
94 hour_type_(WmShell::Get()->system_tray_delegate()->GetHourClockType()) { 94 hour_type_(WmShell::Get()->system_tray_controller()->GetHourClockType()) {
95 SetTimer(base::Time::Now()); 95 SetTimer(base::Time::Now());
96 SetFocusBehavior(FocusBehavior::NEVER); 96 SetFocusBehavior(FocusBehavior::NEVER);
97 } 97 }
98 98
99 void BaseDateTimeView::SetTimer(const base::Time& now) { 99 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 100 // 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 101 // want to have the timer go off more than necessary since that will cause
102 // the CPU to wake up and consume power. 102 // the CPU to wake up and consume power.
103 base::Time::Exploded exploded; 103 base::Time::Exploded exploded;
104 now.LocalExplode(&exploded); 104 now.LocalExplode(&exploded);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 ? kHeaderTextColorNormal 157 ? kHeaderTextColorNormal
158 : kHeaderTextColorHover); 158 : kHeaderTextColorHover);
159 SchedulePaint(); 159 SchedulePaint();
160 } 160 }
161 action_ = action; 161 action_ = action;
162 SetFocusBehavior(action_ != TrayDate::NONE ? FocusBehavior::ALWAYS 162 SetFocusBehavior(action_ != TrayDate::NONE ? FocusBehavior::ALWAYS
163 : FocusBehavior::NEVER); 163 : FocusBehavior::NEVER);
164 } 164 }
165 165
166 void DateView::UpdateTimeFormat() { 166 void DateView::UpdateTimeFormat() {
167 hour_type_ = WmShell::Get()->system_tray_delegate()->GetHourClockType(); 167 hour_type_ = WmShell::Get()->system_tray_controller()->GetHourClockType();
168 UpdateText(); 168 UpdateText();
169 } 169 }
170 170
171 base::HourClockType DateView::GetHourTypeForTesting() const { 171 base::HourClockType DateView::GetHourTypeForTesting() const {
172 return hour_type_; 172 return hour_type_;
173 } 173 }
174 174
175 void DateView::SetActive(bool active) { 175 void DateView::SetActive(bool active) {
176 date_label_->SetEnabledColor(active ? kHeaderTextColorHover 176 date_label_->SetEnabledColor(active ? kHeaderTextColorHover
177 : kHeaderTextColorNormal); 177 : kHeaderTextColorNormal);
178 SchedulePaint(); 178 SchedulePaint();
179 } 179 }
180 180
181 void DateView::UpdateTextInternal(const base::Time& now) { 181 void DateView::UpdateTextInternal(const base::Time& now) {
182 BaseDateTimeView::UpdateTextInternal(now); 182 BaseDateTimeView::UpdateTextInternal(now);
183 date_label_->SetText(l10n_util::GetStringFUTF16( 183 date_label_->SetText(l10n_util::GetStringFUTF16(
184 IDS_ASH_STATUS_TRAY_DATE, FormatDayOfWeek(now), FormatDate(now))); 184 IDS_ASH_STATUS_TRAY_DATE, FormatDayOfWeek(now), FormatDate(now)));
185 } 185 }
186 186
187 bool DateView::PerformAction(const ui::Event& event) { 187 bool DateView::PerformAction(const ui::Event& event) {
188 if (action_ == TrayDate::NONE) 188 if (action_ == TrayDate::NONE)
189 return false; 189 return false;
190 if (action_ == TrayDate::SHOW_DATE_SETTINGS) 190 if (action_ == TrayDate::SHOW_DATE_SETTINGS)
191 WmShell::Get()->system_tray_delegate()->ShowDateSettings(); 191 WmShell::Get()->system_tray_controller()->ShowDateSettings();
192 else if (action_ == TrayDate::SET_SYSTEM_TIME) 192 // HACK - would port ShowSetTimeDialog also
193 WmShell::Get()->system_tray_delegate()->ShowSetTimeDialog(); 193 // else if (action_ == TrayDate::SET_SYSTEM_TIME)
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)
202 return; 203 return;
203 SetActive(true); 204 SetActive(true);
(...skipping 20 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()->GetHourClockType();
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