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

Unified Diff: ui/views/controls/button/custom_button.cc

Issue 1411833006: Refactoring to make adding ink drop animations easier (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactor ink drop animations (comments in ui/views/) Created 5 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/controls/button/custom_button.cc
diff --git a/ui/views/controls/button/custom_button.cc b/ui/views/controls/button/custom_button.cc
index aafbf2d65a63aa32810d6da8d352f9bf1663f8af..ac9d0938d6a29b241a863cae997ec5d752d5bc20 100644
--- a/ui/views/controls/button/custom_button.cc
+++ b/ui/views/controls/button/custom_button.cc
@@ -10,6 +10,7 @@
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/gfx/animation/throb_animation.h"
#include "ui/gfx/screen.h"
+#include "ui/views/animation/ink_drop_delegate.h"
#include "ui/views/controls/button/blue_button.h"
#include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/button/image_button.h"
@@ -25,9 +26,33 @@
namespace views {
+namespace {
+
+// A stub InkDropDelegate implementation that always exists and does nothing.
+// A real InkDropDelegate descendant can be returned by a View's descendant via
+// GetInkDropDelegate().
+class InkDropDelegateStub : public InkDropDelegate {
+ public:
+ InkDropDelegateStub() {}
+ ~InkDropDelegateStub() override {}
+
+ // InkDropDelegate:
+ void SetInkDropSize(int large_size,
+ int large_corner_radius,
+ int small_size,
+ int small_corner_radius) override {}
+ void OnBoundsChanged() override {}
+ void OnAction(InkDropState state) override {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(InkDropDelegateStub);
+};
sadrul 2015/11/25 22:38:58 Still not a fan of this stub. I think we should st
varkha 2015/11/26 00:05:46 Done.
+
// How long the hover animation takes if uninterrupted.
static const int kHoverFadeDurationMs = 150;
+} // namespace
+
// static
const char CustomButton::kViewClassName[] = "CustomButton";
@@ -284,6 +309,8 @@ void CustomButton::OnDragDone() {
// (since disabled buttons may still be able to be dragged).
if (state_ != STATE_DISABLED)
SetState(STATE_NORMAL);
+ Button::OnDragDone();
sadrul 2015/11/25 22:38:58 Is this still needed?
varkha 2015/11/26 00:05:47 Done.
+ ink_drop_delegate_->OnAction(InkDropState::HIDDEN);
}
void CustomButton::GetAccessibleState(ui::AXViewState* state) {
@@ -324,6 +351,7 @@ void CustomButton::AnimationProgressed(const gfx::Animation* animation) {
CustomButton::CustomButton(ButtonListener* listener)
: Button(listener),
state_(STATE_NORMAL),
+ ink_drop_delegate_(new InkDropDelegateStub),
animate_on_state_change_(true),
is_throbbing_(false),
triggerable_event_flags_(ui::EF_LEFT_MOUSE_BUTTON),
@@ -374,6 +402,10 @@ bool CustomButton::ShouldEnterHoveredState() {
////////////////////////////////////////////////////////////////////////////////
// CustomButton, View overrides (protected):
+void CustomButton::OnBoundsChanged(const gfx::Rect& previous_bounds) {
+ ink_drop_delegate_->OnBoundsChanged();
+}
+
void CustomButton::ViewHierarchyChanged(
const ViewHierarchyChangedDetails& details) {
if (!details.is_add && state_ != STATE_DISABLED)

Powered by Google App Engine
This is Rietveld 408576698