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

Side by Side Diff: ash/system/tray/hover_highlight_view.cc

Issue 556383002: Status Panel Touch Feedback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restrict test to ChromeOS Created 6 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
« no previous file with comments | « ash/system/tray/hover_highlight_view.h ('k') | ash/system/tray/system_tray_bubble.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/tray/hover_highlight_view.h" 5 #include "ash/system/tray/hover_highlight_view.h"
6 6
7 #include "ash/system/tray/fixed_sized_image_view.h" 7 #include "ash/system/tray/fixed_sized_image_view.h"
8 #include "ash/system/tray/tray_constants.h" 8 #include "ash/system/tray/tray_constants.h"
9 #include "ash/system/tray/view_click_listener.h" 9 #include "ash/system/tray/view_click_listener.h"
10 #include "ui/accessibility/ax_view_state.h" 10 #include "ui/accessibility/ax_view_state.h"
11 #include "ui/base/resource/resource_bundle.h" 11 #include "ui/base/resource/resource_bundle.h"
12 #include "ui/base/ui_base_switches_util.h"
12 #include "ui/gfx/canvas.h" 13 #include "ui/gfx/canvas.h"
13 #include "ui/gfx/font_list.h" 14 #include "ui/gfx/font_list.h"
14 #include "ui/resources/grit/ui_resources.h" 15 #include "ui/resources/grit/ui_resources.h"
15 #include "ui/views/border.h" 16 #include "ui/views/border.h"
16 #include "ui/views/controls/image_view.h" 17 #include "ui/views/controls/image_view.h"
17 #include "ui/views/controls/label.h" 18 #include "ui/views/controls/label.h"
18 #include "ui/views/layout/box_layout.h" 19 #include "ui/views/layout/box_layout.h"
19 #include "ui/views/layout/fill_layout.h" 20 #include "ui/views/layout/fill_layout.h"
20 21
21 namespace { 22 namespace {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 return AddLabel(text, gfx::ALIGN_LEFT, style); 124 return AddLabel(text, gfx::ALIGN_LEFT, style);
124 } 125 }
125 126
126 void HoverHighlightView::SetExpandable(bool expandable) { 127 void HoverHighlightView::SetExpandable(bool expandable) {
127 if (expandable != expandable_) { 128 if (expandable != expandable_) {
128 expandable_ = expandable; 129 expandable_ = expandable;
129 InvalidateLayout(); 130 InvalidateLayout();
130 } 131 }
131 } 132 }
132 133
134 void HoverHighlightView::SetHoverHighlight(bool hover) {
135 if (hover_ == hover)
136 return;
137 hover_ = hover;
138 if (!text_label_)
139 return;
140 if (hover_ && text_highlight_color_)
141 text_label_->SetEnabledColor(text_highlight_color_);
142 if (!hover_ && text_default_color_)
143 text_label_->SetEnabledColor(text_default_color_);
144 SchedulePaint();
145 }
146
133 bool HoverHighlightView::PerformAction(const ui::Event& event) { 147 bool HoverHighlightView::PerformAction(const ui::Event& event) {
134 if (!listener_) 148 if (!listener_)
135 return false; 149 return false;
136 listener_->OnViewClicked(this); 150 listener_->OnViewClicked(this);
137 return true; 151 return true;
138 } 152 }
139 153
140 void HoverHighlightView::GetAccessibleState(ui::AXViewState* state) { 154 void HoverHighlightView::GetAccessibleState(ui::AXViewState* state) {
141 ActionableView::GetAccessibleState(state); 155 ActionableView::GetAccessibleState(state);
142 156
143 if (checkable_) { 157 if (checkable_) {
144 state->role = ui::AX_ROLE_CHECK_BOX; 158 state->role = ui::AX_ROLE_CHECK_BOX;
145 if (checked_) 159 if (checked_)
146 state->AddStateFlag(ui::AX_STATE_CHECKED); 160 state->AddStateFlag(ui::AX_STATE_CHECKED);
147 } 161 }
148 } 162 }
149 163
150 gfx::Size HoverHighlightView::GetPreferredSize() const { 164 gfx::Size HoverHighlightView::GetPreferredSize() const {
151 gfx::Size size = ActionableView::GetPreferredSize(); 165 gfx::Size size = ActionableView::GetPreferredSize();
152 if (!expandable_ || size.height() < kTrayPopupItemHeight) 166 if (!expandable_ || size.height() < kTrayPopupItemHeight)
153 size.set_height(kTrayPopupItemHeight); 167 size.set_height(kTrayPopupItemHeight);
154 return size; 168 return size;
155 } 169 }
156 170
157 int HoverHighlightView::GetHeightForWidth(int width) const { 171 int HoverHighlightView::GetHeightForWidth(int width) const {
158 return GetPreferredSize().height(); 172 return GetPreferredSize().height();
159 } 173 }
160 174
161 void HoverHighlightView::OnMouseEntered(const ui::MouseEvent& event) { 175 void HoverHighlightView::OnMouseEntered(const ui::MouseEvent& event) {
162 hover_ = true; 176 SetHoverHighlight(true);
163 if (text_highlight_color_ && text_label_)
164 text_label_->SetEnabledColor(text_highlight_color_);
165 SchedulePaint();
166 } 177 }
167 178
168 void HoverHighlightView::OnMouseExited(const ui::MouseEvent& event) { 179 void HoverHighlightView::OnMouseExited(const ui::MouseEvent& event) {
169 hover_ = false; 180 SetHoverHighlight(false);
170 if (text_default_color_ && text_label_) 181 }
171 text_label_->SetEnabledColor(text_default_color_); 182
172 SchedulePaint(); 183 void HoverHighlightView::OnGestureEvent(ui::GestureEvent* event) {
184 if (switches::IsTouchFeedbackEnabled()) {
185 if (event->type() == ui::ET_GESTURE_TAP_DOWN) {
186 SetHoverHighlight(true);
187 } else if (event->type() == ui::ET_GESTURE_TAP_CANCEL ||
188 event->type() == ui::ET_GESTURE_TAP) {
189 SetHoverHighlight(false);
190 }
191 }
192 ActionableView::OnGestureEvent(event);
173 } 193 }
174 194
175 void HoverHighlightView::OnEnabledChanged() { 195 void HoverHighlightView::OnEnabledChanged() {
176 for (int i = 0; i < child_count(); ++i) 196 for (int i = 0; i < child_count(); ++i)
177 child_at(i)->SetEnabled(enabled()); 197 child_at(i)->SetEnabled(enabled());
178 } 198 }
179 199
180 void HoverHighlightView::OnPaintBackground(gfx::Canvas* canvas) { 200 void HoverHighlightView::OnPaintBackground(gfx::Canvas* canvas) {
181 canvas->DrawColor(hover_ ? highlight_color_ : default_color_); 201 canvas->DrawColor(hover_ ? highlight_color_ : default_color_);
182 } 202 }
183 203
184 void HoverHighlightView::OnFocus() { 204 void HoverHighlightView::OnFocus() {
185 ScrollRectToVisible(gfx::Rect(gfx::Point(), size())); 205 ScrollRectToVisible(gfx::Rect(gfx::Point(), size()));
186 ActionableView::OnFocus(); 206 ActionableView::OnFocus();
187 } 207 }
188 208
189 } // namespace ash 209 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/tray/hover_highlight_view.h ('k') | ash/system/tray/system_tray_bubble.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698