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

Side by Side Diff: ui/views/controls/button/custom_button.cc

Issue 2042073002: Centered flood fill style ink drop ripples on mouse/touch points. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Renamed LocatedEvent::AsLocatedIfLocatedEvent() as FromIfValid(). Created 4 years, 6 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 "ui/views/controls/button/custom_button.h" 5 #include "ui/views/controls/button/custom_button.h"
6 6
7 #include "ui/accessibility/ax_view_state.h" 7 #include "ui/accessibility/ax_view_state.h"
8 #include "ui/base/material_design/material_design_controller.h" 8 #include "ui/base/material_design/material_design_controller.h"
9 #include "ui/events/event.h" 9 #include "ui/events/event.h"
10 #include "ui/events/event_utils.h" 10 #include "ui/events/event_utils.h"
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 const char* CustomButton::GetClassName() const { 141 const char* CustomButton::GetClassName() const {
142 return kViewClassName; 142 return kViewClassName;
143 } 143 }
144 144
145 bool CustomButton::OnMousePressed(const ui::MouseEvent& event) { 145 bool CustomButton::OnMousePressed(const ui::MouseEvent& event) {
146 if (state_ == STATE_DISABLED) 146 if (state_ == STATE_DISABLED)
147 return true; 147 return true;
148 if (state_ != STATE_PRESSED && ShouldEnterPushedState(event) && 148 if (state_ != STATE_PRESSED && ShouldEnterPushedState(event) &&
149 HitTestPoint(event.location())) { 149 HitTestPoint(event.location())) {
150 SetState(STATE_PRESSED); 150 SetState(STATE_PRESSED);
151 AnimateInkDrop(views::InkDropState::ACTION_PENDING); 151 AnimateInkDrop(views::InkDropState::ACTION_PENDING, &event);
152 } 152 }
153 if (request_focus_on_press_) 153 if (request_focus_on_press_)
154 RequestFocus(); 154 RequestFocus();
155 if (IsTriggerableEvent(event) && notify_action_ == NOTIFY_ON_PRESS) { 155 if (IsTriggerableEvent(event) && notify_action_ == NOTIFY_ON_PRESS) {
156 NotifyClick(event); 156 NotifyClick(event);
157 // NOTE: We may be deleted at this point (by the listener's notification 157 // NOTE: We may be deleted at this point (by the listener's notification
158 // handler). 158 // handler).
159 } 159 }
160 return true; 160 return true;
161 } 161 }
162 162
163 bool CustomButton::OnMouseDragged(const ui::MouseEvent& event) { 163 bool CustomButton::OnMouseDragged(const ui::MouseEvent& event) {
164 if (state_ != STATE_DISABLED) { 164 if (state_ != STATE_DISABLED) {
165 bool should_enter_pushed = ShouldEnterPushedState(event); 165 const bool should_enter_pushed = ShouldEnterPushedState(event);
166 if (HitTestPoint(event.location())) { 166 if (HitTestPoint(event.location())) {
167 SetState(should_enter_pushed ? STATE_PRESSED : STATE_HOVERED); 167 SetState(should_enter_pushed ? STATE_PRESSED : STATE_HOVERED);
168 if (!InDrag() && should_enter_pushed && 168 if (!InDrag() && should_enter_pushed &&
169 ink_drop()->GetTargetInkDropState() == views::InkDropState::HIDDEN) { 169 ink_drop()->GetTargetInkDropState() == views::InkDropState::HIDDEN) {
170 AnimateInkDrop(views::InkDropState::ACTION_PENDING); 170 AnimateInkDrop(views::InkDropState::ACTION_PENDING, &event);
171 } 171 }
172 } else { 172 } else {
173 SetState(STATE_NORMAL); 173 SetState(STATE_NORMAL);
174 if (!InDrag() && should_enter_pushed && 174 if (!InDrag() && should_enter_pushed &&
175 ink_drop()->GetTargetInkDropState() == 175 ink_drop()->GetTargetInkDropState() ==
176 views::InkDropState::ACTION_PENDING) { 176 views::InkDropState::ACTION_PENDING) {
177 AnimateInkDrop(views::InkDropState::HIDDEN); 177 AnimateInkDrop(views::InkDropState::HIDDEN, &event);
178 } 178 }
179 } 179 }
180 } 180 }
181 return true; 181 return true;
182 } 182 }
183 183
184 void CustomButton::OnMouseReleased(const ui::MouseEvent& event) { 184 void CustomButton::OnMouseReleased(const ui::MouseEvent& event) {
185 if (state_ != STATE_DISABLED) { 185 if (state_ != STATE_DISABLED) {
186 if (!HitTestPoint(event.location())) { 186 if (!HitTestPoint(event.location())) {
187 SetState(STATE_NORMAL); 187 SetState(STATE_NORMAL);
(...skipping 12 matching lines...) Expand all
200 } 200 }
201 201
202 void CustomButton::OnMouseCaptureLost() { 202 void CustomButton::OnMouseCaptureLost() {
203 // Starting a drag results in a MouseCaptureLost. Reset button state. 203 // Starting a drag results in a MouseCaptureLost. Reset button state.
204 // TODO(varkha) While in drag only reset the state with Material Design. 204 // TODO(varkha) While in drag only reset the state with Material Design.
205 // The same logic may applies everywhere so gather any feedback and update. 205 // The same logic may applies everywhere so gather any feedback and update.
206 bool reset_button_state = 206 bool reset_button_state =
207 !InDrag() || ui::MaterialDesignController::IsModeMaterial(); 207 !InDrag() || ui::MaterialDesignController::IsModeMaterial();
208 if (state_ != STATE_DISABLED && reset_button_state) 208 if (state_ != STATE_DISABLED && reset_button_state)
209 SetState(STATE_NORMAL); 209 SetState(STATE_NORMAL);
210 AnimateInkDrop(views::InkDropState::HIDDEN); 210 AnimateInkDrop(views::InkDropState::HIDDEN, nullptr /* event */);
211 } 211 }
212 212
213 void CustomButton::OnMouseEntered(const ui::MouseEvent& event) { 213 void CustomButton::OnMouseEntered(const ui::MouseEvent& event) {
214 if (state_ != STATE_DISABLED) 214 if (state_ != STATE_DISABLED)
215 SetState(STATE_HOVERED); 215 SetState(STATE_HOVERED);
216 } 216 }
217 217
218 void CustomButton::OnMouseExited(const ui::MouseEvent& event) { 218 void CustomButton::OnMouseExited(const ui::MouseEvent& event) {
219 // Starting a drag results in a MouseExited, we need to ignore it. 219 // Starting a drag results in a MouseExited, we need to ignore it.
220 if (state_ != STATE_DISABLED && !InDrag()) 220 if (state_ != STATE_DISABLED && !InDrag())
221 SetState(STATE_NORMAL); 221 SetState(STATE_NORMAL);
222 } 222 }
223 223
224 void CustomButton::OnMouseMoved(const ui::MouseEvent& event) { 224 void CustomButton::OnMouseMoved(const ui::MouseEvent& event) {
225 if (state_ != STATE_DISABLED) 225 if (state_ != STATE_DISABLED)
226 SetState(HitTestPoint(event.location()) ? STATE_HOVERED : STATE_NORMAL); 226 SetState(HitTestPoint(event.location()) ? STATE_HOVERED : STATE_NORMAL);
227 } 227 }
228 228
229 bool CustomButton::OnKeyPressed(const ui::KeyEvent& event) { 229 bool CustomButton::OnKeyPressed(const ui::KeyEvent& event) {
230 if (state_ == STATE_DISABLED) 230 if (state_ == STATE_DISABLED)
231 return false; 231 return false;
232 232
233 // Space sets button state to pushed. Enter clicks the button. This matches 233 // Space sets button state to pushed. Enter clicks the button. This matches
234 // the Windows native behavior of buttons, where Space clicks the button on 234 // the Windows native behavior of buttons, where Space clicks the button on
235 // KeyRelease and Enter clicks the button on KeyPressed. 235 // KeyRelease and Enter clicks the button on KeyPressed.
236 if (event.key_code() == ui::VKEY_SPACE) { 236 if (event.key_code() == ui::VKEY_SPACE) {
237 SetState(STATE_PRESSED); 237 SetState(STATE_PRESSED);
238 if (ink_drop()->GetTargetInkDropState() != 238 if (ink_drop()->GetTargetInkDropState() !=
239 views::InkDropState::ACTION_PENDING) { 239 views::InkDropState::ACTION_PENDING) {
240 AnimateInkDrop(views::InkDropState::ACTION_PENDING); 240 AnimateInkDrop(views::InkDropState::ACTION_PENDING, nullptr /* event */);
241 } 241 }
242 } else if (event.key_code() == ui::VKEY_RETURN) { 242 } else if (event.key_code() == ui::VKEY_RETURN) {
243 SetState(STATE_NORMAL); 243 SetState(STATE_NORMAL);
244 NotifyClick(event); 244 NotifyClick(event);
245 } else { 245 } else {
246 return false; 246 return false;
247 } 247 }
248 return true; 248 return true;
249 } 249 }
250 250
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 ui::MenuSourceType source_type) { 307 ui::MenuSourceType source_type) {
308 if (!context_menu_controller()) 308 if (!context_menu_controller())
309 return; 309 return;
310 310
311 // We're about to show the context menu. Showing the context menu likely means 311 // We're about to show the context menu. Showing the context menu likely means
312 // we won't get a mouse exited and reset state. Reset it now to be sure. 312 // we won't get a mouse exited and reset state. Reset it now to be sure.
313 if (state_ != STATE_DISABLED) 313 if (state_ != STATE_DISABLED)
314 SetState(STATE_NORMAL); 314 SetState(STATE_NORMAL);
315 if (hide_ink_drop_when_showing_context_menu_) { 315 if (hide_ink_drop_when_showing_context_menu_) {
316 ink_drop()->SetHovered(false); 316 ink_drop()->SetHovered(false);
317 AnimateInkDrop(InkDropState::HIDDEN); 317 AnimateInkDrop(InkDropState::HIDDEN, nullptr /* event */);
318 } 318 }
319 View::ShowContextMenu(p, source_type); 319 View::ShowContextMenu(p, source_type);
320 } 320 }
321 321
322 void CustomButton::OnDragDone() { 322 void CustomButton::OnDragDone() {
323 // Only reset the state to normal if the button isn't currently disabled 323 // Only reset the state to normal if the button isn't currently disabled
324 // (since disabled buttons may still be able to be dragged). 324 // (since disabled buttons may still be able to be dragged).
325 if (state_ != STATE_DISABLED) 325 if (state_ != STATE_DISABLED)
326 SetState(STATE_NORMAL); 326 SetState(STATE_NORMAL);
327 AnimateInkDrop(InkDropState::HIDDEN); 327 AnimateInkDrop(InkDropState::HIDDEN, nullptr /* event */);
328 } 328 }
329 329
330 void CustomButton::GetAccessibleState(ui::AXViewState* state) { 330 void CustomButton::GetAccessibleState(ui::AXViewState* state) {
331 Button::GetAccessibleState(state); 331 Button::GetAccessibleState(state);
332 switch (state_) { 332 switch (state_) {
333 case STATE_HOVERED: 333 case STATE_HOVERED:
334 state->AddStateFlag(ui::AX_STATE_HOVERED); 334 state->AddStateFlag(ui::AX_STATE_HOVERED);
335 break; 335 break;
336 case STATE_PRESSED: 336 case STATE_PRESSED:
337 state->AddStateFlag(ui::AX_STATE_PRESSED); 337 state->AddStateFlag(ui::AX_STATE_PRESSED);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 const ViewHierarchyChangedDetails& details) { 376 const ViewHierarchyChangedDetails& details) {
377 if (!details.is_add && state_ != STATE_DISABLED) 377 if (!details.is_add && state_ != STATE_DISABLED)
378 SetState(STATE_NORMAL); 378 SetState(STATE_NORMAL);
379 } 379 }
380 380
381 void CustomButton::OnBlur() { 381 void CustomButton::OnBlur() {
382 Button::OnBlur(); 382 Button::OnBlur();
383 if (IsHotTracked() || state_ == STATE_PRESSED) { 383 if (IsHotTracked() || state_ == STATE_PRESSED) {
384 SetState(STATE_NORMAL); 384 SetState(STATE_NORMAL);
385 if (ink_drop()->GetTargetInkDropState() != views::InkDropState::HIDDEN) 385 if (ink_drop()->GetTargetInkDropState() != views::InkDropState::HIDDEN)
386 AnimateInkDrop(views::InkDropState::HIDDEN); 386 AnimateInkDrop(views::InkDropState::HIDDEN, nullptr /* event */);
387 // TODO(bruthig) : Fix CustomButtons to work well when multiple input 387 // TODO(bruthig) : Fix CustomButtons to work well when multiple input
388 // methods are interacting with a button.e.g.By animating to HIDDEN here 388 // methods are interacting with a button. e.g. By animating to HIDDEN here
389 // it is possible for a Mouse Release to trigger an action however there 389 // it is possible for a Mouse Release to trigger an action however there
390 // would be no visual cue to the user that this will occur. 390 // would be no visual cue to the user that this will occur.
391 } 391 }
392 } 392 }
393 393
394 bool CustomButton::ShouldShowInkDropForFocus() const { 394 bool CustomButton::ShouldShowInkDropForFocus() const {
395 return true; 395 return true;
396 } 396 }
397 397
398 //////////////////////////////////////////////////////////////////////////////// 398 ////////////////////////////////////////////////////////////////////////////////
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 } 453 }
454 #endif 454 #endif
455 455
456 return check_mouse_position && IsMouseHovered(); 456 return check_mouse_position && IsMouseHovered();
457 } 457 }
458 458
459 //////////////////////////////////////////////////////////////////////////////// 459 ////////////////////////////////////////////////////////////////////////////////
460 // CustomButton, Button overrides (protected): 460 // CustomButton, Button overrides (protected):
461 461
462 void CustomButton::NotifyClick(const ui::Event& event) { 462 void CustomButton::NotifyClick(const ui::Event& event) {
463 if (has_ink_drop_action_on_click_) 463 if (has_ink_drop_action_on_click_) {
464 AnimateInkDrop(InkDropState::ACTION_TRIGGERED); 464 AnimateInkDrop(InkDropState::ACTION_TRIGGERED,
465 ui::LocatedEvent::FromIfValid(&event));
466 }
465 Button::NotifyClick(event); 467 Button::NotifyClick(event);
466 } 468 }
467 469
468 void CustomButton::OnClickCanceled(const ui::Event& event) { 470 void CustomButton::OnClickCanceled(const ui::Event& event) {
469 AnimateInkDrop(views::InkDropState::HIDDEN); 471 AnimateInkDrop(views::InkDropState::HIDDEN,
472 ui::LocatedEvent::FromIfValid(&event));
470 Button::OnClickCanceled(event); 473 Button::OnClickCanceled(event);
471 } 474 }
472 475
473 } // namespace views 476 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/animation/test/ink_drop_host_view_test_api.cc ('k') | ui/views/controls/button/label_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698