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

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: Fixed merge conflict in custom_button.cc 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
« no previous file with comments | « ui/views/animation/ink_drop_host_view.h ('k') | ui/views/animation/ink_drop_impl.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 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)
45 : ink_drop_(ink_drop), target_handler_(view, this) {}
46
47 ~InkDropGestureHandler() override {}
48
49 // ui::EventHandler:
50 void OnGestureEvent(ui::GestureEvent* event) override {
51 InkDropState current_ink_drop_state = ink_drop_->GetTargetInkDropState();
52
53 InkDropState ink_drop_state = InkDropState::HIDDEN;
54 switch (event->type()) {
55 case ui::ET_GESTURE_TAP_DOWN:
56 ink_drop_state = InkDropState::ACTION_PENDING;
57 // The ui::ET_GESTURE_TAP_DOWN event needs to be marked as handled so
58 // that
59 // subsequent events for the gesture are sent to |this|.
60 event->SetHandled();
61 break;
62 case ui::ET_GESTURE_LONG_PRESS:
63 ink_drop_state = InkDropState::ALTERNATE_ACTION_PENDING;
64 break;
65 case ui::ET_GESTURE_LONG_TAP:
66 ink_drop_state = InkDropState::ALTERNATE_ACTION_TRIGGERED;
67 break;
68 case ui::ET_GESTURE_END:
69 if (current_ink_drop_state == InkDropState::ACTIVATED)
70 return;
71 // Fall through to ui::ET_GESTURE_SCROLL_BEGIN case.
72 case ui::ET_GESTURE_SCROLL_BEGIN:
73 ink_drop_state = InkDropState::HIDDEN;
74 break;
75 default:
76 return;
77 }
78
79 if (ink_drop_state == InkDropState::HIDDEN &&
80 (current_ink_drop_state == InkDropState::ACTION_TRIGGERED ||
81 current_ink_drop_state == InkDropState::ALTERNATE_ACTION_TRIGGERED ||
82 current_ink_drop_state == InkDropState::DEACTIVATED)) {
83 // These InkDropStates automatically transition to the HIDDEN state so we
84 // don't make an explicit call. Explicitly animating to HIDDEN in this
85 // case would prematurely pre-empt these animations.
86 return;
87 }
88 ink_drop_->AnimateToState(ink_drop_state);
89 }
90
91 private:
92 // Animation controller for the ink drop ripple effect.
93 InkDrop* ink_drop_;
94
95 // An instance of ScopedTargetHandler allowing |this| to handle events.
96 ui::ScopedTargetHandler target_handler_;
97
98 DISALLOW_COPY_AND_ASSIGN(InkDropGestureHandler);
99 };
100
33 InkDropHostView::InkDropHostView() 101 InkDropHostView::InkDropHostView()
34 : ink_drop_size_(kInkDropSize, kInkDropSize), destroying_(false) {} 102 : ink_drop_(new InkDropStub()),
103 ink_drop_size_(kInkDropSize, kInkDropSize),
104 destroying_(false) {}
35 105
36 InkDropHostView::~InkDropHostView() { 106 InkDropHostView::~InkDropHostView() {
37 // TODO(bruthig): Improve InkDropImpl to be safer about calling back to 107 // TODO(bruthig): Improve InkDropImpl to be safer about calling back to
38 // potentially destroyed InkDropHosts and remove |destroying_|. 108 // potentially destroyed InkDropHosts and remove |destroying_|.
39 destroying_ = true; 109 destroying_ = true;
40 } 110 }
41 111
42 void InkDropHostView::AddInkDropLayer(ui::Layer* ink_drop_layer) { 112 void InkDropHostView::AddInkDropLayer(ui::Layer* ink_drop_layer) {
43 SetPaintToLayer(true); 113 SetPaintToLayer(true);
44 layer()->SetFillsBoundsOpaquely(false); 114 layer()->SetFillsBoundsOpaquely(false);
(...skipping 23 matching lines...) Expand all
68 const { 138 const {
69 std::unique_ptr<InkDropHighlight> highlight( 139 std::unique_ptr<InkDropHighlight> highlight(
70 new InkDropHighlight(ink_drop_size_, kInkDropSmallCornerRadius, 140 new InkDropHighlight(ink_drop_size_, kInkDropSmallCornerRadius,
71 GetInkDropCenter(), GetInkDropBaseColor())); 141 GetInkDropCenter(), GetInkDropBaseColor()));
72 highlight->set_explode_size(CalculateLargeInkDropSize(ink_drop_size_)); 142 highlight->set_explode_size(CalculateLargeInkDropSize(ink_drop_size_));
73 return highlight; 143 return highlight;
74 } 144 }
75 145
76 void InkDropHostView::OnFocus() { 146 void InkDropHostView::OnFocus() {
77 views::View::OnFocus(); 147 views::View::OnFocus();
78 if (ink_drop_delegate() && ShouldShowInkDropForFocus()) 148 if (ShouldShowInkDropForFocus())
79 ink_drop_delegate()->GetInkDrop()->SetFocused(true); 149 ink_drop()->SetFocused(true);
80 } 150 }
81 151
82 void InkDropHostView::OnBlur() { 152 void InkDropHostView::OnBlur() {
83 views::View::OnBlur(); 153 views::View::OnBlur();
84 if (ink_drop_delegate() && ShouldShowInkDropForFocus()) 154 if (ShouldShowInkDropForFocus())
85 ink_drop_delegate()->GetInkDrop()->SetFocused(false); 155 ink_drop()->SetFocused(false);
156 }
157
158 void InkDropHostView::OnMouseEvent(ui::MouseEvent* event) {
159 switch (event->type()) {
160 case ui::ET_MOUSE_ENTERED:
161 ink_drop_->SetHovered(true);
162 break;
163 case ui::ET_MOUSE_EXITED:
164 ink_drop_->SetHovered(false);
165 break;
166 default:
167 break;
168 }
169 View::OnMouseEvent(event);
86 } 170 }
87 171
88 gfx::Point InkDropHostView::GetInkDropCenter() const { 172 gfx::Point InkDropHostView::GetInkDropCenter() const {
89 return GetLocalBounds().CenterPoint(); 173 return GetLocalBounds().CenterPoint();
90 } 174 }
91 175
92 SkColor InkDropHostView::GetInkDropBaseColor() const { 176 SkColor InkDropHostView::GetInkDropBaseColor() const {
93 NOTREACHED(); 177 NOTREACHED();
94 return gfx::kPlaceholderColor; 178 return gfx::kPlaceholderColor;
95 } 179 }
96 180
97 bool InkDropHostView::ShouldShowInkDropForFocus() const { 181 bool InkDropHostView::ShouldShowInkDropForFocus() const {
98 return false; 182 return false;
99 } 183 }
100 184
185 void InkDropHostView::SetHasInkDrop(bool has_an_ink_drop) {
186 if (has_an_ink_drop) {
187 ink_drop_ = InkDropFactory::CreateInkDrop(this);
188 gesture_handler_.reset(new InkDropGestureHandler(this, ink_drop_.get()));
189 } else {
190 gesture_handler_.reset();
191 ink_drop_.reset(new InkDropStub());
192 }
193 }
194
195 void InkDropHostView::AnimateInkDrop(InkDropState ink_drop_state) {
196 ink_drop_->AnimateToState(ink_drop_state);
197 }
198
101 } // namespace views 199 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/animation/ink_drop_host_view.h ('k') | ui/views/animation/ink_drop_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698