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

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

Issue 2042073002: Centered flood fill style ink drop ripples on mouse/touch points. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Polished for review. 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" 7 #include "ui/events/event.h"
8 #include "ui/events/scoped_target_handler.h" 8 #include "ui/events/scoped_target_handler.h"
9 #include "ui/gfx/color_palette.h" 9 #include "ui/gfx/color_palette.h"
10 #include "ui/gfx/geometry/size_conversions.h" 10 #include "ui/gfx/geometry/size_conversions.h"
(...skipping 23 matching lines...) Expand all
34 // static 34 // static
35 const int InkDropHostView::kInkDropSmallCornerRadius = 2; 35 const int InkDropHostView::kInkDropSmallCornerRadius = 2;
36 36
37 // An EventHandler that is guaranteed to be invoked and is not prone to 37 // An EventHandler that is guaranteed to be invoked and is not prone to
38 // InkDropHostView descendents who do not call 38 // InkDropHostView descendents who do not call
39 // InkDropHostView::OnGestureEvent(). 39 // InkDropHostView::OnGestureEvent().
40 // 40 //
41 // TODO(bruthig): Consider getting rid of this class. 41 // TODO(bruthig): Consider getting rid of this class.
42 class InkDropHostView::InkDropGestureHandler : public ui::EventHandler { 42 class InkDropHostView::InkDropGestureHandler : public ui::EventHandler {
43 public: 43 public:
44 InkDropGestureHandler(View* view, InkDrop* ink_drop) 44 InkDropGestureHandler(InkDropHostView* host_view, InkDrop* ink_drop)
45 : ink_drop_(ink_drop), target_handler_(view, this) {} 45 : target_handler_(new ui::ScopedTargetHandler(host_view, this)),
46 host_view_(host_view),
47 ink_drop_(ink_drop) {}
46 48
47 ~InkDropGestureHandler() override {} 49 ~InkDropGestureHandler() override {}
48 50
49 // ui::EventHandler: 51 // ui::EventHandler:
50 void OnGestureEvent(ui::GestureEvent* event) override { 52 void OnGestureEvent(ui::GestureEvent* event) override {
51 InkDropState current_ink_drop_state = ink_drop_->GetTargetInkDropState(); 53 InkDropState current_ink_drop_state = ink_drop_->GetTargetInkDropState();
52 54
53 InkDropState ink_drop_state = InkDropState::HIDDEN; 55 InkDropState ink_drop_state = InkDropState::HIDDEN;
54 switch (event->type()) { 56 switch (event->type()) {
55 case ui::ET_GESTURE_TAP_DOWN: 57 case ui::ET_GESTURE_TAP_DOWN:
(...skipping 22 matching lines...) Expand all
78 80
79 if (ink_drop_state == InkDropState::HIDDEN && 81 if (ink_drop_state == InkDropState::HIDDEN &&
80 (current_ink_drop_state == InkDropState::ACTION_TRIGGERED || 82 (current_ink_drop_state == InkDropState::ACTION_TRIGGERED ||
81 current_ink_drop_state == InkDropState::ALTERNATE_ACTION_TRIGGERED || 83 current_ink_drop_state == InkDropState::ALTERNATE_ACTION_TRIGGERED ||
82 current_ink_drop_state == InkDropState::DEACTIVATED)) { 84 current_ink_drop_state == InkDropState::DEACTIVATED)) {
83 // These InkDropStates automatically transition to the HIDDEN state so we 85 // These InkDropStates automatically transition to the HIDDEN state so we
84 // don't make an explicit call. Explicitly animating to HIDDEN in this 86 // don't make an explicit call. Explicitly animating to HIDDEN in this
85 // case would prematurely pre-empt these animations. 87 // case would prematurely pre-empt these animations.
86 return; 88 return;
87 } 89 }
88 ink_drop_->AnimateToState(ink_drop_state); 90 host_view_->AnimateInkDrop(ink_drop_state, event);
89 } 91 }
90 92
91 private: 93 private:
94 // Allows |this| to handle all GestureEvents on |host_view_|.
95 std::unique_ptr<ui::ScopedTargetHandler> target_handler_;
96
97 // The host view to cache ui::Events to when animating the ink drop.
98 InkDropHostView* host_view_;
99
92 // Animation controller for the ink drop ripple effect. 100 // Animation controller for the ink drop ripple effect.
93 InkDrop* ink_drop_; 101 InkDrop* ink_drop_;
94 102
95 // An instance of ScopedTargetHandler allowing |this| to handle events.
96 ui::ScopedTargetHandler target_handler_;
97
98 DISALLOW_COPY_AND_ASSIGN(InkDropGestureHandler); 103 DISALLOW_COPY_AND_ASSIGN(InkDropGestureHandler);
99 }; 104 };
100 105
101 InkDropHostView::InkDropHostView() 106 InkDropHostView::InkDropHostView()
102 : ink_drop_(new InkDropStub()), 107 : ink_drop_(new InkDropStub()),
103 ink_drop_size_(kInkDropSize, kInkDropSize), 108 ink_drop_size_(kInkDropSize, kInkDropSize),
104 destroying_(false) {} 109 destroying_(false) {}
105 110
106 InkDropHostView::~InkDropHostView() { 111 InkDropHostView::~InkDropHostView() {
107 // TODO(bruthig): Improve InkDropImpl to be safer about calling back to 112 // TODO(bruthig): Improve InkDropImpl to be safer about calling back to
(...skipping 12 matching lines...) Expand all
120 // No need to do anything when called during shutdown, and if a derived 125 // No need to do anything when called during shutdown, and if a derived
121 // class has overridden Add/RemoveInkDropLayer, running this implementation 126 // class has overridden Add/RemoveInkDropLayer, running this implementation
122 // would be wrong. 127 // would be wrong.
123 if (destroying_) 128 if (destroying_)
124 return; 129 return;
125 layer()->Remove(ink_drop_layer); 130 layer()->Remove(ink_drop_layer);
126 SetPaintToLayer(false); 131 SetPaintToLayer(false);
127 } 132 }
128 133
129 std::unique_ptr<InkDropRipple> InkDropHostView::CreateInkDropRipple() const { 134 std::unique_ptr<InkDropRipple> InkDropHostView::CreateInkDropRipple() const {
135 return CreateDefaultInkDropRipple(GetLocalBounds().CenterPoint());
136 }
137
138 std::unique_ptr<InkDropHighlight> InkDropHostView::CreateInkDropHighlight()
139 const {
140 return CreateDefaultInkDropHighlight(GetLocalBounds().CenterPoint());
141 }
142
143 std::unique_ptr<InkDropRipple> InkDropHostView::CreateDefaultInkDropRipple(
144 const gfx::Point& center_point) const {
130 std::unique_ptr<InkDropRipple> ripple(new SquareInkDropRipple( 145 std::unique_ptr<InkDropRipple> ripple(new SquareInkDropRipple(
131 CalculateLargeInkDropSize(ink_drop_size_), kInkDropLargeCornerRadius, 146 CalculateLargeInkDropSize(ink_drop_size_), kInkDropLargeCornerRadius,
132 ink_drop_size_, kInkDropSmallCornerRadius, GetInkDropCenter(), 147 ink_drop_size_, kInkDropSmallCornerRadius, center_point,
133 GetInkDropBaseColor())); 148 GetInkDropBaseColor()));
134 return ripple; 149 return ripple;
135 } 150 }
136 151
137 std::unique_ptr<InkDropHighlight> InkDropHostView::CreateInkDropHighlight() 152 std::unique_ptr<InkDropHighlight>
138 const { 153 InkDropHostView::CreateDefaultInkDropHighlight(
154 const gfx::Point& center_point) const {
139 std::unique_ptr<InkDropHighlight> highlight( 155 std::unique_ptr<InkDropHighlight> highlight(
140 new InkDropHighlight(ink_drop_size_, kInkDropSmallCornerRadius, 156 new InkDropHighlight(ink_drop_size_, kInkDropSmallCornerRadius,
141 GetInkDropCenter(), GetInkDropBaseColor())); 157 center_point, GetInkDropBaseColor()));
142 highlight->set_explode_size(CalculateLargeInkDropSize(ink_drop_size_)); 158 highlight->set_explode_size(CalculateLargeInkDropSize(ink_drop_size_));
143 return highlight; 159 return highlight;
144 } 160 }
145 161
162 gfx::Point InkDropHostView::GetInkDropCenterBasedOnLastEvent() const {
163 return last_ripple_triggering_event_ &&
164 last_ripple_triggering_event_->IsLocatedEvent()
165 ? last_ripple_triggering_event_->AsLocatedEvent()->location()
166 : GetLocalBounds().CenterPoint();
167 }
168
169 void InkDropHostView::AnimateInkDrop(InkDropState state,
170 const ui::Event* event) {
171 last_ripple_triggering_event_ = event ? ui::Event::Clone(*event) : nullptr;
172 ink_drop_->AnimateToState(state);
173 }
174
146 void InkDropHostView::VisibilityChanged(View* starting_from, bool is_visible) { 175 void InkDropHostView::VisibilityChanged(View* starting_from, bool is_visible) {
147 View::VisibilityChanged(starting_from, is_visible); 176 View::VisibilityChanged(starting_from, is_visible);
148 if (GetWidget() && !is_visible) { 177 if (GetWidget() && !is_visible) {
149 ink_drop()->AnimateToState(InkDropState::HIDDEN); 178 ink_drop()->AnimateToState(InkDropState::HIDDEN);
150 ink_drop()->SetHovered(false); 179 ink_drop()->SetHovered(false);
151 } 180 }
152 } 181 }
153 182
154 void InkDropHostView::OnFocus() { 183 void InkDropHostView::OnFocus() {
155 views::View::OnFocus(); 184 views::View::OnFocus();
(...skipping 14 matching lines...) Expand all
170 break; 199 break;
171 case ui::ET_MOUSE_EXITED: 200 case ui::ET_MOUSE_EXITED:
172 ink_drop_->SetHovered(false); 201 ink_drop_->SetHovered(false);
173 break; 202 break;
174 default: 203 default:
175 break; 204 break;
176 } 205 }
177 View::OnMouseEvent(event); 206 View::OnMouseEvent(event);
178 } 207 }
179 208
180 gfx::Point InkDropHostView::GetInkDropCenter() const {
181 return GetLocalBounds().CenterPoint();
182 }
183
184 SkColor InkDropHostView::GetInkDropBaseColor() const { 209 SkColor InkDropHostView::GetInkDropBaseColor() const {
185 NOTREACHED(); 210 NOTREACHED();
186 return gfx::kPlaceholderColor; 211 return gfx::kPlaceholderColor;
187 } 212 }
188 213
189 bool InkDropHostView::ShouldShowInkDropForFocus() const { 214 bool InkDropHostView::ShouldShowInkDropForFocus() const {
190 return false; 215 return false;
191 } 216 }
192 217
193 void InkDropHostView::SetHasInkDrop(bool has_an_ink_drop) { 218 void InkDropHostView::SetHasInkDrop(bool has_an_ink_drop) {
194 if (has_an_ink_drop) { 219 if (has_an_ink_drop) {
195 ink_drop_ = InkDropFactory::CreateInkDrop(this); 220 ink_drop_ = InkDropFactory::CreateInkDrop(this);
196 gesture_handler_.reset(new InkDropGestureHandler(this, ink_drop_.get())); 221 gesture_handler_.reset(new InkDropGestureHandler(this, ink_drop_.get()));
197 } else { 222 } else {
198 gesture_handler_.reset(); 223 gesture_handler_.reset();
199 ink_drop_.reset(new InkDropStub()); 224 ink_drop_.reset(new InkDropStub());
200 } 225 }
201 } 226 }
202 227
203 void InkDropHostView::AnimateInkDrop(InkDropState ink_drop_state) {
204 ink_drop_->AnimateToState(ink_drop_state);
205 }
206
207 } // namespace views 228 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698