| OLD | NEW |
| 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/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" |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 OnClickCanceled(event); | 204 OnClickCanceled(event); |
| 205 } | 205 } |
| 206 | 206 |
| 207 void CustomButton::OnMouseCaptureLost() { | 207 void CustomButton::OnMouseCaptureLost() { |
| 208 // Starting a drag results in a MouseCaptureLost. Reset button state. | 208 // Starting a drag results in a MouseCaptureLost. Reset button state. |
| 209 // TODO(varkha): Reset the state even while in drag. The same logic may | 209 // TODO(varkha): Reset the state even while in drag. The same logic may |
| 210 // applies everywhere so gather any feedback and update. | 210 // applies everywhere so gather any feedback and update. |
| 211 if (state_ != STATE_DISABLED) | 211 if (state_ != STATE_DISABLED) |
| 212 SetState(STATE_NORMAL); | 212 SetState(STATE_NORMAL); |
| 213 AnimateInkDrop(views::InkDropState::HIDDEN, nullptr /* event */); | 213 AnimateInkDrop(views::InkDropState::HIDDEN, nullptr /* event */); |
| 214 ink_drop()->SetHovered(false); |
| 215 Button::OnMouseCaptureLost(); |
| 214 } | 216 } |
| 215 | 217 |
| 216 void CustomButton::OnMouseEntered(const ui::MouseEvent& event) { | 218 void CustomButton::OnMouseEntered(const ui::MouseEvent& event) { |
| 217 if (state_ != STATE_DISABLED) | 219 if (state_ != STATE_DISABLED) |
| 218 SetState(STATE_HOVERED); | 220 SetState(STATE_HOVERED); |
| 219 } | 221 } |
| 220 | 222 |
| 221 void CustomButton::OnMouseExited(const ui::MouseEvent& event) { | 223 void CustomButton::OnMouseExited(const ui::MouseEvent& event) { |
| 222 // Starting a drag results in a MouseExited, we need to ignore it. | 224 // Starting a drag results in a MouseExited, we need to ignore it. |
| 223 if (state_ != STATE_DISABLED && !InDrag()) | 225 if (state_ != STATE_DISABLED && !InDrag()) |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 } | 351 } |
| 350 } | 352 } |
| 351 | 353 |
| 352 void CustomButton::VisibilityChanged(View* starting_from, bool visible) { | 354 void CustomButton::VisibilityChanged(View* starting_from, bool visible) { |
| 353 Button::VisibilityChanged(starting_from, visible); | 355 Button::VisibilityChanged(starting_from, visible); |
| 354 if (state_ == STATE_DISABLED) | 356 if (state_ == STATE_DISABLED) |
| 355 return; | 357 return; |
| 356 SetState(visible && ShouldEnterHoveredState() ? STATE_HOVERED : STATE_NORMAL); | 358 SetState(visible && ShouldEnterHoveredState() ? STATE_HOVERED : STATE_NORMAL); |
| 357 } | 359 } |
| 358 | 360 |
| 359 std::unique_ptr<InkDropHighlight> CustomButton::CreateInkDropHighlight() const { | |
| 360 return ShouldShowInkDropHighlight() ? Button::CreateInkDropHighlight() | |
| 361 : nullptr; | |
| 362 } | |
| 363 | |
| 364 SkColor CustomButton::GetInkDropBaseColor() const { | 361 SkColor CustomButton::GetInkDropBaseColor() const { |
| 365 return ink_drop_base_color_; | 362 return ink_drop_base_color_; |
| 366 } | 363 } |
| 367 | 364 |
| 368 //////////////////////////////////////////////////////////////////////////////// | 365 //////////////////////////////////////////////////////////////////////////////// |
| 369 // CustomButton, gfx::AnimationDelegate implementation: | 366 // CustomButton, gfx::AnimationDelegate implementation: |
| 370 | 367 |
| 371 void CustomButton::AnimationProgressed(const gfx::Animation* animation) { | 368 void CustomButton::AnimationProgressed(const gfx::Animation* animation) { |
| 372 SchedulePaint(); | 369 SchedulePaint(); |
| 373 } | 370 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 return event.type() == ui::ET_GESTURE_TAP_DOWN || | 419 return event.type() == ui::ET_GESTURE_TAP_DOWN || |
| 423 event.type() == ui::ET_GESTURE_TAP || | 420 event.type() == ui::ET_GESTURE_TAP || |
| 424 (event.IsMouseEvent() && | 421 (event.IsMouseEvent() && |
| 425 (triggerable_event_flags_ & event.flags()) != 0); | 422 (triggerable_event_flags_ & event.flags()) != 0); |
| 426 } | 423 } |
| 427 | 424 |
| 428 bool CustomButton::ShouldEnterPushedState(const ui::Event& event) { | 425 bool CustomButton::ShouldEnterPushedState(const ui::Event& event) { |
| 429 return IsTriggerableEvent(event); | 426 return IsTriggerableEvent(event); |
| 430 } | 427 } |
| 431 | 428 |
| 432 bool CustomButton::ShouldShowInkDropHighlight() const { | |
| 433 return enabled() && !InDrag() && | |
| 434 (IsMouseHovered() || (ShouldShowInkDropForFocus() && HasFocus())); | |
| 435 } | |
| 436 | |
| 437 bool CustomButton::ShouldEnterHoveredState() { | 429 bool CustomButton::ShouldEnterHoveredState() { |
| 438 if (!visible()) | 430 if (!visible()) |
| 439 return false; | 431 return false; |
| 440 | 432 |
| 441 bool check_mouse_position = true; | 433 bool check_mouse_position = true; |
| 442 #if defined(USE_AURA) | 434 #if defined(USE_AURA) |
| 443 // If another window has capture, we shouldn't check the current mouse | 435 // If another window has capture, we shouldn't check the current mouse |
| 444 // position because the button won't receive any mouse events - so if the | 436 // position because the button won't receive any mouse events - so if the |
| 445 // mouse was hovered, the button would be stuck in a hovered state (since it | 437 // mouse was hovered, the button would be stuck in a hovered state (since it |
| 446 // would never receive OnMouseExited). | 438 // would never receive OnMouseExited). |
| (...skipping 27 matching lines...) Expand all Loading... |
| 474 views::InkDropState::ACTION_PENDING || | 466 views::InkDropState::ACTION_PENDING || |
| 475 ink_drop()->GetTargetInkDropState() == | 467 ink_drop()->GetTargetInkDropState() == |
| 476 views::InkDropState::ALTERNATE_ACTION_PENDING) { | 468 views::InkDropState::ALTERNATE_ACTION_PENDING) { |
| 477 AnimateInkDrop(views::InkDropState::HIDDEN, | 469 AnimateInkDrop(views::InkDropState::HIDDEN, |
| 478 ui::LocatedEvent::FromIfValid(&event)); | 470 ui::LocatedEvent::FromIfValid(&event)); |
| 479 } | 471 } |
| 480 Button::OnClickCanceled(event); | 472 Button::OnClickCanceled(event); |
| 481 } | 473 } |
| 482 | 474 |
| 483 } // namespace views | 475 } // namespace views |
| OLD | NEW |