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

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

Issue 2447523002: [ash-md] Added different highlighting modes to the InkDropImpl. (Closed)
Patch Set: Fixed InkDropHostView::GetInkDrop() to use CreateInkDrop(). Created 4 years, 1 month 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 | « ui/views/controls/button/custom_button.h ('k') | ui/views/controls/button/label_button.h » ('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 (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_node_data.h" 7 #include "ui/accessibility/ax_node_data.h"
8 #include "ui/events/event.h" 8 #include "ui/events/event.h"
9 #include "ui/events/event_utils.h" 9 #include "ui/events/event_utils.h"
10 #include "ui/events/keycodes/keyboard_codes.h" 10 #include "ui/events/keycodes/keyboard_codes.h"
11 #include "ui/gfx/animation/throb_animation.h" 11 #include "ui/gfx/animation/throb_animation.h"
12 #include "ui/gfx/color_palette.h" 12 #include "ui/gfx/color_palette.h"
13 #include "ui/native_theme/native_theme.h" 13 #include "ui/native_theme/native_theme.h"
14 #include "ui/views/animation/ink_drop_highlight.h" 14 #include "ui/views/animation/ink_drop_highlight.h"
15 #include "ui/views/animation/ink_drop_impl.h"
15 #include "ui/views/controls/button/blue_button.h" 16 #include "ui/views/controls/button/blue_button.h"
16 #include "ui/views/controls/button/checkbox.h" 17 #include "ui/views/controls/button/checkbox.h"
17 #include "ui/views/controls/button/image_button.h" 18 #include "ui/views/controls/button/image_button.h"
18 #include "ui/views/controls/button/label_button.h" 19 #include "ui/views/controls/button/label_button.h"
19 #include "ui/views/controls/button/menu_button.h" 20 #include "ui/views/controls/button/menu_button.h"
20 #include "ui/views/controls/button/radio_button.h" 21 #include "ui/views/controls/button/radio_button.h"
21 #include "ui/views/controls/button/toggle_button.h" 22 #include "ui/views/controls/button/toggle_button.h"
22 #include "ui/views/widget/widget.h" 23 #include "ui/views/widget/widget.h"
23 24
24 #if defined(USE_AURA) 25 #if defined(USE_AURA)
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 OnClickCanceled(event); 206 OnClickCanceled(event);
206 } 207 }
207 208
208 void CustomButton::OnMouseCaptureLost() { 209 void CustomButton::OnMouseCaptureLost() {
209 // Starting a drag results in a MouseCaptureLost. Reset button state. 210 // Starting a drag results in a MouseCaptureLost. Reset button state.
210 // TODO(varkha): Reset the state even while in drag. The same logic may 211 // TODO(varkha): Reset the state even while in drag. The same logic may
211 // applies everywhere so gather any feedback and update. 212 // applies everywhere so gather any feedback and update.
212 if (state_ != STATE_DISABLED) 213 if (state_ != STATE_DISABLED)
213 SetState(STATE_NORMAL); 214 SetState(STATE_NORMAL);
214 AnimateInkDrop(views::InkDropState::HIDDEN, nullptr /* event */); 215 AnimateInkDrop(views::InkDropState::HIDDEN, nullptr /* event */);
216 GetInkDrop()->SetHovered(false);
217 Button::OnMouseCaptureLost();
215 } 218 }
216 219
217 void CustomButton::OnMouseEntered(const ui::MouseEvent& event) { 220 void CustomButton::OnMouseEntered(const ui::MouseEvent& event) {
218 if (state_ != STATE_DISABLED) 221 if (state_ != STATE_DISABLED)
219 SetState(STATE_HOVERED); 222 SetState(STATE_HOVERED);
220 } 223 }
221 224
222 void CustomButton::OnMouseExited(const ui::MouseEvent& event) { 225 void CustomButton::OnMouseExited(const ui::MouseEvent& event) {
223 // Starting a drag results in a MouseExited, we need to ignore it. 226 // Starting a drag results in a MouseExited, we need to ignore it.
224 if (state_ != STATE_DISABLED && !InDrag()) 227 if (state_ != STATE_DISABLED && !InDrag())
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 } 353 }
351 } 354 }
352 355
353 void CustomButton::VisibilityChanged(View* starting_from, bool visible) { 356 void CustomButton::VisibilityChanged(View* starting_from, bool visible) {
354 Button::VisibilityChanged(starting_from, visible); 357 Button::VisibilityChanged(starting_from, visible);
355 if (state_ == STATE_DISABLED) 358 if (state_ == STATE_DISABLED)
356 return; 359 return;
357 SetState(visible && ShouldEnterHoveredState() ? STATE_HOVERED : STATE_NORMAL); 360 SetState(visible && ShouldEnterHoveredState() ? STATE_HOVERED : STATE_NORMAL);
358 } 361 }
359 362
360 std::unique_ptr<InkDropHighlight> CustomButton::CreateInkDropHighlight() const { 363 std::unique_ptr<InkDrop> CustomButton::CreateInkDrop() {
361 return ShouldShowInkDropHighlight() ? Button::CreateInkDropHighlight() 364 std::unique_ptr<views::InkDropImpl> ink_drop = CreateDefaultInkDropImpl();
362 : nullptr; 365 ink_drop->SetShowHighlightOnFocus(true);
366 return std::move(ink_drop);
363 } 367 }
364 368
365 SkColor CustomButton::GetInkDropBaseColor() const { 369 SkColor CustomButton::GetInkDropBaseColor() const {
366 return ink_drop_base_color_; 370 return ink_drop_base_color_;
367 } 371 }
368 372
369 //////////////////////////////////////////////////////////////////////////////// 373 ////////////////////////////////////////////////////////////////////////////////
370 // CustomButton, gfx::AnimationDelegate implementation: 374 // CustomButton, gfx::AnimationDelegate implementation:
371 375
372 void CustomButton::AnimationProgressed(const gfx::Animation* animation) { 376 void CustomButton::AnimationProgressed(const gfx::Animation* animation) {
(...skipping 15 matching lines...) Expand all
388 SetState(STATE_NORMAL); 392 SetState(STATE_NORMAL);
389 if (GetInkDrop()->GetTargetInkDropState() != views::InkDropState::HIDDEN) 393 if (GetInkDrop()->GetTargetInkDropState() != views::InkDropState::HIDDEN)
390 AnimateInkDrop(views::InkDropState::HIDDEN, nullptr /* event */); 394 AnimateInkDrop(views::InkDropState::HIDDEN, nullptr /* event */);
391 // TODO(bruthig) : Fix CustomButtons to work well when multiple input 395 // TODO(bruthig) : Fix CustomButtons to work well when multiple input
392 // methods are interacting with a button. e.g. By animating to HIDDEN here 396 // methods are interacting with a button. e.g. By animating to HIDDEN here
393 // it is possible for a Mouse Release to trigger an action however there 397 // it is possible for a Mouse Release to trigger an action however there
394 // would be no visual cue to the user that this will occur. 398 // would be no visual cue to the user that this will occur.
395 } 399 }
396 } 400 }
397 401
398 bool CustomButton::ShouldShowInkDropForFocus() const {
399 return true;
400 }
401
402 //////////////////////////////////////////////////////////////////////////////// 402 ////////////////////////////////////////////////////////////////////////////////
403 // CustomButton, protected: 403 // CustomButton, protected:
404 404
405 CustomButton::CustomButton(ButtonListener* listener) 405 CustomButton::CustomButton(ButtonListener* listener)
406 : Button(listener), 406 : Button(listener),
407 state_(STATE_NORMAL), 407 state_(STATE_NORMAL),
408 hover_animation_(this), 408 hover_animation_(this),
409 is_throbbing_(false), 409 is_throbbing_(false),
410 triggerable_event_flags_(ui::EF_LEFT_MOUSE_BUTTON), 410 triggerable_event_flags_(ui::EF_LEFT_MOUSE_BUTTON),
411 request_focus_on_press_(false), 411 request_focus_on_press_(false),
(...skipping 11 matching lines...) Expand all
423 return event.type() == ui::ET_GESTURE_TAP_DOWN || 423 return event.type() == ui::ET_GESTURE_TAP_DOWN ||
424 event.type() == ui::ET_GESTURE_TAP || 424 event.type() == ui::ET_GESTURE_TAP ||
425 (event.IsMouseEvent() && 425 (event.IsMouseEvent() &&
426 (triggerable_event_flags_ & event.flags()) != 0); 426 (triggerable_event_flags_ & event.flags()) != 0);
427 } 427 }
428 428
429 bool CustomButton::ShouldEnterPushedState(const ui::Event& event) { 429 bool CustomButton::ShouldEnterPushedState(const ui::Event& event) {
430 return IsTriggerableEvent(event); 430 return IsTriggerableEvent(event);
431 } 431 }
432 432
433 bool CustomButton::ShouldShowInkDropHighlight() const {
434 return enabled() && !InDrag() &&
435 (IsMouseHovered() || (ShouldShowInkDropForFocus() && HasFocus()));
436 }
437
438 bool CustomButton::ShouldEnterHoveredState() { 433 bool CustomButton::ShouldEnterHoveredState() {
439 if (!visible()) 434 if (!visible())
440 return false; 435 return false;
441 436
442 bool check_mouse_position = true; 437 bool check_mouse_position = true;
443 #if defined(USE_AURA) 438 #if defined(USE_AURA)
444 // If another window has capture, we shouldn't check the current mouse 439 // If another window has capture, we shouldn't check the current mouse
445 // position because the button won't receive any mouse events - so if the 440 // position because the button won't receive any mouse events - so if the
446 // mouse was hovered, the button would be stuck in a hovered state (since it 441 // mouse was hovered, the button would be stuck in a hovered state (since it
447 // would never receive OnMouseExited). 442 // would never receive OnMouseExited).
(...skipping 27 matching lines...) Expand all
475 views::InkDropState::ACTION_PENDING || 470 views::InkDropState::ACTION_PENDING ||
476 GetInkDrop()->GetTargetInkDropState() == 471 GetInkDrop()->GetTargetInkDropState() ==
477 views::InkDropState::ALTERNATE_ACTION_PENDING) { 472 views::InkDropState::ALTERNATE_ACTION_PENDING) {
478 AnimateInkDrop(views::InkDropState::HIDDEN, 473 AnimateInkDrop(views::InkDropState::HIDDEN,
479 ui::LocatedEvent::FromIfValid(&event)); 474 ui::LocatedEvent::FromIfValid(&event));
480 } 475 }
481 Button::OnClickCanceled(event); 476 Button::OnClickCanceled(event);
482 } 477 }
483 478
484 } // namespace views 479 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/button/custom_button.h ('k') | ui/views/controls/button/label_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698