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

Side by Side Diff: ui/views/animation/ink_drop_host_view.cc

Issue 2041033002: Moved ButtonInkDropDelegate logic into InkDropHostView and deleted InkDropDelegates. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/animation/ink_drop_host_view.h" 5 #include "ui/views/animation/ink_drop_host_view.h"
6 6
7 #include "ui/events/event.h"
8 #include "ui/events/scoped_target_handler.h"
7 #include "ui/gfx/color_palette.h" 9 #include "ui/gfx/color_palette.h"
8 #include "ui/gfx/geometry/size_conversions.h" 10 #include "ui/gfx/geometry/size_conversions.h"
9 #include "ui/views/animation/ink_drop.h" 11 #include "ui/views/animation/ink_drop.h"
12 #include "ui/views/animation/ink_drop_factory.h"
10 #include "ui/views/animation/ink_drop_highlight.h" 13 #include "ui/views/animation/ink_drop_highlight.h"
14 #include "ui/views/animation/ink_drop_stub.h"
11 #include "ui/views/animation/square_ink_drop_ripple.h" 15 #include "ui/views/animation/square_ink_drop_ripple.h"
12 16
13 namespace views { 17 namespace views {
14 18
15 // Default sizes for ink drop effects. 19 // Default sizes for ink drop effects.
16 const int kInkDropSize = 24; 20 const int kInkDropSize = 24;
17 const int kInkDropLargeCornerRadius = 4; 21 const int kInkDropLargeCornerRadius = 4;
18 22
19 // The scale factor to compute the large ink drop size. 23 // The scale factor to compute the large ink drop size.
20 const float kLargeInkDropScale = 1.333f; 24 const float kLargeInkDropScale = 1.333f;
21 25
22 namespace { 26 namespace {
23 27
24 gfx::Size CalculateLargeInkDropSize(const gfx::Size small_size) { 28 gfx::Size CalculateLargeInkDropSize(const gfx::Size small_size) {
25 return gfx::ScaleToCeiledSize(gfx::Size(small_size), kLargeInkDropScale); 29 return gfx::ScaleToCeiledSize(gfx::Size(small_size), kLargeInkDropScale);
26 } 30 }
27 31
28 } // namespace 32 } // namespace
29 33
30 // static 34 // static
31 const int InkDropHostView::kInkDropSmallCornerRadius = 2; 35 const int InkDropHostView::kInkDropSmallCornerRadius = 2;
32 36
37 // An EventHandler that is guaranteed to be invoked and is not prone to
38 // InkDropHostView descendents who do not call
39 // InkDropHostView::OnGestureEvent().
40 //
41 // TODO(bruthig): Consider getting rid of this class.
42 class InkDropHostView::InkDropGestureHandler : public ui::EventHandler {
43 public:
44 InkDropGestureHandler(View* view, InkDrop* ink_drop) {}
bruthig 2016/06/06 18:57:59 FIXME(bruthig): |view| and |ink_drop| are not used
bruthig 2016/06/07 15:14:52 Done.
45
46 ~InkDropGestureHandler() override {}
47
48 // ui::EventHandler:
49 void OnGestureEvent(ui::GestureEvent* event) override {
50 InkDropState current_ink_drop_state = ink_drop_->GetTargetInkDropState();
51
52 InkDropState ink_drop_state = InkDropState::HIDDEN;
53 switch (event->type()) {
54 case ui::ET_GESTURE_TAP_DOWN:
55 ink_drop_state = InkDropState::ACTION_PENDING;
56 // The ui::ET_GESTURE_TAP_DOWN event needs to be marked as handled so
57 // that
58 // subsequent events for the gesture are sent to |this|.
59 event->SetHandled();
60 break;
61 case ui::ET_GESTURE_LONG_PRESS:
62 ink_drop_state = InkDropState::ALTERNATE_ACTION_PENDING;
63 break;
64 case ui::ET_GESTURE_LONG_TAP:
65 ink_drop_state = InkDropState::ALTERNATE_ACTION_TRIGGERED;
66 break;
67 case ui::ET_GESTURE_END:
68 if (current_ink_drop_state == InkDropState::ACTIVATED)
69 return;
70 // Fall through to ui::ET_GESTURE_SCROLL_BEGIN case.
71 case ui::ET_GESTURE_SCROLL_BEGIN:
72 ink_drop_state = InkDropState::HIDDEN;
73 break;
74 default:
75 return;
76 }
77
78 if (ink_drop_state == InkDropState::HIDDEN &&
79 (current_ink_drop_state == InkDropState::ACTION_TRIGGERED ||
80 current_ink_drop_state == InkDropState::ALTERNATE_ACTION_TRIGGERED ||
81 current_ink_drop_state == InkDropState::DEACTIVATED)) {
82 // These InkDropStates automatically transition to the HIDDEN state so we
83 // don't make an explicit call. Explicitly animating to HIDDEN in this
84 // case would prematurely pre-empt these animations.
85 return;
86 }
87 ink_drop_->AnimateToState(ink_drop_state);
88 }
89
90 private:
91 // An instance of ScopedTargetHandler allowing |this| to handle events.
92 std::unique_ptr<ui::ScopedTargetHandler> target_handler_;
93
94 // Animation controller for the ink drop ripple effect.
95 InkDrop* ink_drop_;
96
97 DISALLOW_COPY_AND_ASSIGN(InkDropGestureHandler);
98 };
99
33 InkDropHostView::InkDropHostView() 100 InkDropHostView::InkDropHostView()
34 : ink_drop_size_(kInkDropSize, kInkDropSize), destroying_(false) {} 101 : ink_drop_(new InkDropStub()),
102 ink_drop_size_(kInkDropSize, kInkDropSize),
103 destroying_(false) {}
35 104
36 InkDropHostView::~InkDropHostView() { 105 InkDropHostView::~InkDropHostView() {
37 // TODO(bruthig): Improve InkDropImpl to be safer about calling back to 106 // TODO(bruthig): Improve InkDropImpl to be safer about calling back to
38 // potentially destroyed InkDropHosts and remove |destroying_|. 107 // potentially destroyed InkDropHosts and remove |destroying_|.
39 destroying_ = true; 108 destroying_ = true;
40 } 109 }
41 110
42 void InkDropHostView::AddInkDropLayer(ui::Layer* ink_drop_layer) { 111 void InkDropHostView::AddInkDropLayer(ui::Layer* ink_drop_layer) {
43 SetPaintToLayer(true); 112 SetPaintToLayer(true);
44 layer()->SetFillsBoundsOpaquely(false); 113 layer()->SetFillsBoundsOpaquely(false);
(...skipping 23 matching lines...) Expand all
68 const { 137 const {
69 std::unique_ptr<InkDropHighlight> highlight( 138 std::unique_ptr<InkDropHighlight> highlight(
70 new InkDropHighlight(ink_drop_size_, kInkDropSmallCornerRadius, 139 new InkDropHighlight(ink_drop_size_, kInkDropSmallCornerRadius,
71 GetInkDropCenter(), GetInkDropBaseColor())); 140 GetInkDropCenter(), GetInkDropBaseColor()));
72 highlight->set_explode_size(CalculateLargeInkDropSize(ink_drop_size_)); 141 highlight->set_explode_size(CalculateLargeInkDropSize(ink_drop_size_));
73 return highlight; 142 return highlight;
74 } 143 }
75 144
76 void InkDropHostView::OnFocus() { 145 void InkDropHostView::OnFocus() {
77 views::View::OnFocus(); 146 views::View::OnFocus();
78 if (ink_drop_delegate() && ShouldShowInkDropForFocus()) 147 if (ShouldShowInkDropForFocus())
79 ink_drop_delegate()->GetInkDrop()->SetFocused(true); 148 ink_drop()->SetFocused(true);
80 } 149 }
81 150
82 void InkDropHostView::OnBlur() { 151 void InkDropHostView::OnBlur() {
83 views::View::OnBlur(); 152 views::View::OnBlur();
84 if (ink_drop_delegate() && ShouldShowInkDropForFocus()) 153 if (ShouldShowInkDropForFocus())
85 ink_drop_delegate()->GetInkDrop()->SetFocused(false); 154 ink_drop()->SetFocused(false);
155 }
156
157 void InkDropHostView::OnMouseEvent(ui::MouseEvent* event) {
158 switch (event->type()) {
159 case ui::ET_MOUSE_ENTERED:
160 ink_drop_->SetHovered(true);
161 break;
162 case ui::ET_MOUSE_EXITED:
163 ink_drop_->SetHovered(false);
164 break;
165 default:
166 break;
167 }
168 View::OnMouseEvent(event);
86 } 169 }
87 170
88 gfx::Point InkDropHostView::GetInkDropCenter() const { 171 gfx::Point InkDropHostView::GetInkDropCenter() const {
89 return GetLocalBounds().CenterPoint(); 172 return GetLocalBounds().CenterPoint();
90 } 173 }
91 174
92 SkColor InkDropHostView::GetInkDropBaseColor() const { 175 SkColor InkDropHostView::GetInkDropBaseColor() const {
93 NOTREACHED(); 176 NOTREACHED();
94 return gfx::kPlaceholderColor; 177 return gfx::kPlaceholderColor;
95 } 178 }
96 179
97 bool InkDropHostView::ShouldShowInkDropForFocus() const { 180 bool InkDropHostView::ShouldShowInkDropForFocus() const {
98 return false; 181 return false;
99 } 182 }
100 183
184 void InkDropHostView::SetHasInkDrop(bool has_an_ink_drop) {
185 if (has_an_ink_drop) {
186 ink_drop_ = InkDropFactory::CreateInkDrop(this);
187 gesture_handler_.reset(new InkDropGestureHandler(this, ink_drop_.get()));
188 } else {
189 gesture_handler_.reset();
190 ink_drop_.reset(new InkDropStub());
191 }
192 }
193
194 void InkDropHostView::AnimateInkDrop(InkDropState ink_drop_state) {
195 ink_drop_->AnimateToState(ink_drop_state);
196 }
197
101 } // namespace views 198 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698