| 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/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" |
| 11 #include "ui/events/keycodes/keyboard_codes.h" | 11 #include "ui/events/keycodes/keyboard_codes.h" |
| 12 #include "ui/gfx/animation/throb_animation.h" | 12 #include "ui/gfx/animation/throb_animation.h" |
| 13 #include "ui/gfx/color_palette.h" | 13 #include "ui/gfx/color_palette.h" |
| 14 #include "ui/native_theme/native_theme.h" | 14 #include "ui/native_theme/native_theme.h" |
| 15 #include "ui/views/animation/ink_drop_delegate.h" | 15 #include "ui/views/animation/ink_drop_delegate.h" |
| 16 #include "ui/views/animation/ink_drop_hover.h" | 16 #include "ui/views/animation/ink_drop_highlight.h" |
| 17 #include "ui/views/controls/button/blue_button.h" | 17 #include "ui/views/controls/button/blue_button.h" |
| 18 #include "ui/views/controls/button/checkbox.h" | 18 #include "ui/views/controls/button/checkbox.h" |
| 19 #include "ui/views/controls/button/image_button.h" | 19 #include "ui/views/controls/button/image_button.h" |
| 20 #include "ui/views/controls/button/label_button.h" | 20 #include "ui/views/controls/button/label_button.h" |
| 21 #include "ui/views/controls/button/menu_button.h" | 21 #include "ui/views/controls/button/menu_button.h" |
| 22 #include "ui/views/controls/button/radio_button.h" | 22 #include "ui/views/controls/button/radio_button.h" |
| 23 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
| 24 | 24 |
| 25 #if defined(USE_AURA) | 25 #if defined(USE_AURA) |
| 26 #include "ui/aura/client/capture_client.h" | 26 #include "ui/aura/client/capture_client.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 // Button::OnEnabledChanged() here? | 129 // Button::OnEnabledChanged() here? |
| 130 if (enabled() ? (state_ != STATE_DISABLED) : (state_ == STATE_DISABLED)) | 130 if (enabled() ? (state_ != STATE_DISABLED) : (state_ == STATE_DISABLED)) |
| 131 return; | 131 return; |
| 132 | 132 |
| 133 if (enabled()) | 133 if (enabled()) |
| 134 SetState(ShouldEnterHoveredState() ? STATE_HOVERED : STATE_NORMAL); | 134 SetState(ShouldEnterHoveredState() ? STATE_HOVERED : STATE_NORMAL); |
| 135 else | 135 else |
| 136 SetState(STATE_DISABLED); | 136 SetState(STATE_DISABLED); |
| 137 | 137 |
| 138 if (ink_drop_delegate()) | 138 if (ink_drop_delegate()) |
| 139 ink_drop_delegate()->SetHovered(ShouldShowInkDropHover()); | 139 ink_drop_delegate()->SetHovered(ShouldShowInkDropHighlight()); |
| 140 } | 140 } |
| 141 | 141 |
| 142 const char* CustomButton::GetClassName() const { | 142 const char* CustomButton::GetClassName() const { |
| 143 return kViewClassName; | 143 return kViewClassName; |
| 144 } | 144 } |
| 145 | 145 |
| 146 bool CustomButton::OnMousePressed(const ui::MouseEvent& event) { | 146 bool CustomButton::OnMousePressed(const ui::MouseEvent& event) { |
| 147 if (state_ == STATE_DISABLED) | 147 if (state_ == STATE_DISABLED) |
| 148 return true; | 148 return true; |
| 149 if (state_ != STATE_PRESSED && ShouldEnterPushedState(event) && | 149 if (state_ != STATE_PRESSED && ShouldEnterPushedState(event) && |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 break; | 347 break; |
| 348 } | 348 } |
| 349 } | 349 } |
| 350 | 350 |
| 351 void CustomButton::VisibilityChanged(View* starting_from, bool visible) { | 351 void CustomButton::VisibilityChanged(View* starting_from, bool visible) { |
| 352 if (state_ == STATE_DISABLED) | 352 if (state_ == STATE_DISABLED) |
| 353 return; | 353 return; |
| 354 SetState(visible && ShouldEnterHoveredState() ? STATE_HOVERED : STATE_NORMAL); | 354 SetState(visible && ShouldEnterHoveredState() ? STATE_HOVERED : STATE_NORMAL); |
| 355 } | 355 } |
| 356 | 356 |
| 357 std::unique_ptr<InkDropHover> CustomButton::CreateInkDropHover() const { | 357 std::unique_ptr<InkDropHighlight> CustomButton::CreateInkDropHighlight() const { |
| 358 return ShouldShowInkDropHover() ? Button::CreateInkDropHover() : nullptr; | 358 return ShouldShowInkDropHighlight() ? Button::CreateInkDropHighlight() |
| 359 : nullptr; |
| 359 } | 360 } |
| 360 | 361 |
| 361 SkColor CustomButton::GetInkDropBaseColor() const { | 362 SkColor CustomButton::GetInkDropBaseColor() const { |
| 362 return ink_drop_base_color_; | 363 return ink_drop_base_color_; |
| 363 } | 364 } |
| 364 | 365 |
| 365 //////////////////////////////////////////////////////////////////////////////// | 366 //////////////////////////////////////////////////////////////////////////////// |
| 366 // CustomButton, gfx::AnimationDelegate implementation: | 367 // CustomButton, gfx::AnimationDelegate implementation: |
| 367 | 368 |
| 368 void CustomButton::AnimationProgressed(const gfx::Animation* animation) { | 369 void CustomButton::AnimationProgressed(const gfx::Animation* animation) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 return event.type() == ui::ET_GESTURE_TAP_DOWN || | 424 return event.type() == ui::ET_GESTURE_TAP_DOWN || |
| 424 event.type() == ui::ET_GESTURE_TAP || | 425 event.type() == ui::ET_GESTURE_TAP || |
| 425 (event.IsMouseEvent() && | 426 (event.IsMouseEvent() && |
| 426 (triggerable_event_flags_ & event.flags()) != 0); | 427 (triggerable_event_flags_ & event.flags()) != 0); |
| 427 } | 428 } |
| 428 | 429 |
| 429 bool CustomButton::ShouldEnterPushedState(const ui::Event& event) { | 430 bool CustomButton::ShouldEnterPushedState(const ui::Event& event) { |
| 430 return IsTriggerableEvent(event); | 431 return IsTriggerableEvent(event); |
| 431 } | 432 } |
| 432 | 433 |
| 433 bool CustomButton::ShouldShowInkDropHover() const { | 434 bool CustomButton::ShouldShowInkDropHighlight() const { |
| 434 return enabled() && !InDrag() && | 435 return enabled() && !InDrag() && |
| 435 (IsMouseHovered() || (ShouldShowInkDropForFocus() && HasFocus())); | 436 (IsMouseHovered() || (ShouldShowInkDropForFocus() && HasFocus())); |
| 436 } | 437 } |
| 437 | 438 |
| 438 bool CustomButton::ShouldEnterHoveredState() { | 439 bool CustomButton::ShouldEnterHoveredState() { |
| 439 if (!visible()) | 440 if (!visible()) |
| 440 return false; | 441 return false; |
| 441 | 442 |
| 442 bool check_mouse_position = true; | 443 bool check_mouse_position = true; |
| 443 #if defined(USE_AURA) | 444 #if defined(USE_AURA) |
| (...skipping 24 matching lines...) Expand all Loading... |
| 468 Button::NotifyClick(event); | 469 Button::NotifyClick(event); |
| 469 } | 470 } |
| 470 | 471 |
| 471 void CustomButton::OnClickCanceled(const ui::Event& event) { | 472 void CustomButton::OnClickCanceled(const ui::Event& event) { |
| 472 if (ink_drop_delegate()) | 473 if (ink_drop_delegate()) |
| 473 ink_drop_delegate()->OnAction(views::InkDropState::HIDDEN); | 474 ink_drop_delegate()->OnAction(views::InkDropState::HIDDEN); |
| 474 Button::OnClickCanceled(event); | 475 Button::OnClickCanceled(event); |
| 475 } | 476 } |
| 476 | 477 |
| 477 } // namespace views | 478 } // namespace views |
| OLD | NEW |