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

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

Issue 560473003: DateView Touch Feedback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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/ash_switches.h"
7 #include "ash/shell.h" 8 #include "ash/shell.h"
8 #include "ash/system/tray/system_tray_delegate.h" 9 #include "ash/system/tray/system_tray_delegate.h"
9 #include "ash/system/tray/tray_constants.h" 10 #include "ash/system/tray/tray_constants.h"
10 #include "ash/system/tray/tray_utils.h" 11 #include "ash/system/tray/tray_utils.h"
12 #include "base/command_line.h"
11 #include "base/i18n/rtl.h" 13 #include "base/i18n/rtl.h"
12 #include "base/i18n/time_formatting.h" 14 #include "base/i18n/time_formatting.h"
13 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
14 #include "base/time/time.h" 16 #include "base/time/time.h"
15 #include "grit/ash_strings.h" 17 #include "grit/ash_strings.h"
16 #include "third_party/icu/source/i18n/unicode/datefmt.h" 18 #include "third_party/icu/source/i18n/unicode/datefmt.h"
17 #include "third_party/icu/source/i18n/unicode/dtptngen.h" 19 #include "third_party/icu/source/i18n/unicode/dtptngen.h"
18 #include "third_party/icu/source/i18n/unicode/smpdtfmt.h" 20 #include "third_party/icu/source/i18n/unicode/smpdtfmt.h"
19 #include "ui/base/l10n/l10n_util.h" 21 #include "ui/base/l10n/l10n_util.h"
20 #include "ui/views/border.h" 22 #include "ui/views/border.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 121
120 void BaseDateTimeView::ChildPreferredSizeChanged(views::View* child) { 122 void BaseDateTimeView::ChildPreferredSizeChanged(views::View* child) {
121 PreferredSizeChanged(); 123 PreferredSizeChanged();
122 } 124 }
123 125
124 void BaseDateTimeView::OnLocaleChanged() { 126 void BaseDateTimeView::OnLocaleChanged() {
125 UpdateText(); 127 UpdateText();
126 } 128 }
127 129
128 DateView::DateView() 130 DateView::DateView()
129 : hour_type_(ash::Shell::GetInstance()->system_tray_delegate()-> 131 : active_(false),
132 touch_feedback_enabled_(false),
133 hour_type_(ash::Shell::GetInstance()->system_tray_delegate()->
130 GetHourClockType()), 134 GetHourClockType()),
131 action_(TrayDate::NONE) { 135 action_(TrayDate::NONE) {
132 SetLayoutManager( 136 SetLayoutManager(
133 new views::BoxLayout( 137 new views::BoxLayout(
134 views::BoxLayout::kVertical, 0, 0, 0)); 138 views::BoxLayout::kVertical, 0, 0, 0));
135 date_label_ = CreateLabel(); 139 date_label_ = CreateLabel();
136 date_label_->SetEnabledColor(kHeaderTextColorNormal); 140 date_label_->SetEnabledColor(kHeaderTextColorNormal);
137 UpdateTextInternal(base::Time::Now()); 141 UpdateTextInternal(base::Time::Now());
138 AddChildView(date_label_); 142 AddChildView(date_label_);
139 SetFocusable(false); 143 SetFocusable(false);
144
145 if (CommandLine::ForCurrentProcess()->
146 HasSwitch(switches::kAshEnableTouchViewTouchFeedback)) {
147 touch_feedback_enabled_ = true;
flackr 2014/09/17 18:30:06 Sorry for only recognizing this now but you can cr
jonross 2014/09/30 18:31:33 Done.
148 }
140 } 149 }
141 150
142 DateView::~DateView() { 151 DateView::~DateView() {
143 } 152 }
144 153
145 void DateView::SetAction(TrayDate::DateAction action) { 154 void DateView::SetAction(TrayDate::DateAction action) {
146 if (action == action_) 155 if (action == action_)
147 return; 156 return;
148 if (IsMouseHovered()) { 157 if (IsMouseHovered()) {
149 date_label_->SetEnabledColor( 158 date_label_->SetEnabledColor(
150 action == TrayDate::NONE ? kHeaderTextColorNormal : 159 action == TrayDate::NONE ? kHeaderTextColorNormal :
151 kHeaderTextColorHover); 160 kHeaderTextColorHover);
152 SchedulePaint(); 161 SchedulePaint();
153 } 162 }
154 action_ = action; 163 action_ = action;
155 SetFocusable(action_ != TrayDate::NONE); 164 SetFocusable(action_ != TrayDate::NONE);
156 } 165 }
157 166
158 void DateView::UpdateTimeFormat() { 167 void DateView::UpdateTimeFormat() {
159 hour_type_ = 168 hour_type_ =
160 ash::Shell::GetInstance()->system_tray_delegate()->GetHourClockType(); 169 ash::Shell::GetInstance()->system_tray_delegate()->GetHourClockType();
161 UpdateText(); 170 UpdateText();
162 } 171 }
163 172
164 base::HourClockType DateView::GetHourTypeForTesting() const { 173 base::HourClockType DateView::GetHourTypeForTesting() const {
165 return hour_type_; 174 return hour_type_;
166 } 175 }
167 176
177 void DateView::SetActive(bool active) {
178 if (active_ == active)
179 return;
180 active_ = active;
181 if (active_)
182 date_label_->SetEnabledColor(kHeaderTextColorHover);
183 else
184 date_label_->SetEnabledColor(kHeaderTextColorNormal);
185 SchedulePaint();
186 }
187
168 void DateView::UpdateTextInternal(const base::Time& now) { 188 void DateView::UpdateTextInternal(const base::Time& now) {
169 SetAccessibleName( 189 SetAccessibleName(
170 base::TimeFormatFriendlyDate(now) + 190 base::TimeFormatFriendlyDate(now) +
171 base::ASCIIToUTF16(", ") + 191 base::ASCIIToUTF16(", ") +
172 base::TimeFormatTimeOfDayWithHourClockType( 192 base::TimeFormatTimeOfDayWithHourClockType(
173 now, hour_type_, base::kKeepAmPm)); 193 now, hour_type_, base::kKeepAmPm));
174 date_label_->SetText( 194 date_label_->SetText(
175 l10n_util::GetStringFUTF16( 195 l10n_util::GetStringFUTF16(
176 IDS_ASH_STATUS_TRAY_DATE, FormatDayOfWeek(now), FormatDate(now))); 196 IDS_ASH_STATUS_TRAY_DATE, FormatDayOfWeek(now), FormatDate(now)));
177 } 197 }
178 198
179 bool DateView::PerformAction(const ui::Event& event) { 199 bool DateView::PerformAction(const ui::Event& event) {
180 if (action_ == TrayDate::NONE) 200 if (action_ == TrayDate::NONE)
181 return false; 201 return false;
182 if (action_ == TrayDate::SHOW_DATE_SETTINGS) 202 if (action_ == TrayDate::SHOW_DATE_SETTINGS)
183 ash::Shell::GetInstance()->system_tray_delegate()->ShowDateSettings(); 203 ash::Shell::GetInstance()->system_tray_delegate()->ShowDateSettings();
184 else if (action_ == TrayDate::SET_SYSTEM_TIME) 204 else if (action_ == TrayDate::SET_SYSTEM_TIME)
185 ash::Shell::GetInstance()->system_tray_delegate()->ShowSetTimeDialog(); 205 ash::Shell::GetInstance()->system_tray_delegate()->ShowSetTimeDialog();
186 return true; 206 return true;
187 } 207 }
188 208
189 void DateView::OnMouseEntered(const ui::MouseEvent& event) { 209 void DateView::OnMouseEntered(const ui::MouseEvent& event) {
190 if (action_ == TrayDate::NONE) 210 if (action_ == TrayDate::NONE)
191 return; 211 return;
192 date_label_->SetEnabledColor(kHeaderTextColorHover); 212 SetActive(true);
193 SchedulePaint();
194 } 213 }
195 214
196 void DateView::OnMouseExited(const ui::MouseEvent& event) { 215 void DateView::OnMouseExited(const ui::MouseEvent& event) {
197 if (action_ == TrayDate::NONE) 216 if (action_ == TrayDate::NONE)
198 return; 217 return;
199 date_label_->SetEnabledColor(kHeaderTextColorNormal); 218 SetActive(false);
200 SchedulePaint(); 219 }
220
221 void DateView::OnGestureEvent(ui::GestureEvent* event) {
222 if (touch_feedback_enabled_) {
223 if (event->type() == ui::ET_GESTURE_TAP_DOWN) {
224 SetActive(true);
225 } else if (event->type() == ui::ET_GESTURE_TAP_CANCEL ||
226 event->type() == ui::ET_GESTURE_END) {
227 SetActive(false);
228 }
229 }
230 BaseDateTimeView::OnGestureEvent(event);
201 } 231 }
202 232
203 /////////////////////////////////////////////////////////////////////////////// 233 ///////////////////////////////////////////////////////////////////////////////
204 234
205 TimeView::TimeView(TrayDate::ClockLayout clock_layout) 235 TimeView::TimeView(TrayDate::ClockLayout clock_layout)
206 : hour_type_(ash::Shell::GetInstance()->system_tray_delegate()-> 236 : hour_type_(ash::Shell::GetInstance()->system_tray_delegate()->
207 GetHourClockType()) { 237 GetHourClockType()) {
208 SetupLabels(); 238 SetupLabels();
209 UpdateTextInternal(base::Time::Now()); 239 UpdateTextInternal(base::Time::Now());
210 UpdateClockLayout(clock_layout); 240 UpdateClockLayout(clock_layout);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 286
257 bool TimeView::PerformAction(const ui::Event& event) { 287 bool TimeView::PerformAction(const ui::Event& event) {
258 return false; 288 return false;
259 } 289 }
260 290
261 bool TimeView::OnMousePressed(const ui::MouseEvent& event) { 291 bool TimeView::OnMousePressed(const ui::MouseEvent& event) {
262 // Let the event fall through. 292 // Let the event fall through.
263 return false; 293 return false;
264 } 294 }
265 295
266 void TimeView::UpdateClockLayout(TrayDate::ClockLayout clock_layout){ 296 void TimeView::UpdateClockLayout(TrayDate::ClockLayout clock_layout) {
267 SetBorderFromLayout(clock_layout); 297 SetBorderFromLayout(clock_layout);
268 if (clock_layout == TrayDate::HORIZONTAL_CLOCK) { 298 if (clock_layout == TrayDate::HORIZONTAL_CLOCK) {
269 RemoveChildView(vertical_label_hours_.get()); 299 RemoveChildView(vertical_label_hours_.get());
270 RemoveChildView(vertical_label_minutes_.get()); 300 RemoveChildView(vertical_label_minutes_.get());
271 SetLayoutManager( 301 SetLayoutManager(
272 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); 302 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0));
273 AddChildView(horizontal_label_.get()); 303 AddChildView(horizontal_label_.get());
274 } else { 304 } else {
275 RemoveChildView(horizontal_label_.get()); 305 RemoveChildView(horizontal_label_.get());
276 views::GridLayout* layout = new views::GridLayout(this); 306 views::GridLayout* layout = new views::GridLayout(this);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 346
317 void TimeView::SetupLabel(views::Label* label) { 347 void TimeView::SetupLabel(views::Label* label) {
318 label->set_owned_by_client(); 348 label->set_owned_by_client();
319 SetupLabelForTray(label); 349 SetupLabelForTray(label);
320 label->SetFontList(label->font_list().DeriveWithStyle( 350 label->SetFontList(label->font_list().DeriveWithStyle(
321 label->font_list().GetFontStyle() & ~gfx::Font::BOLD)); 351 label->font_list().GetFontStyle() & ~gfx::Font::BOLD));
322 } 352 }
323 353
324 } // namespace tray 354 } // namespace tray
325 } // namespace ash 355 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698