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

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

Issue 2447523002: [ash-md] Added different highlighting modes to the InkDropImpl. (Closed)
Patch Set: Fixed compile errors. Created 4 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 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"
11 #include "ui/views/animation/ink_drop.h" 11 #include "ui/views/animation/ink_drop.h"
12 #include "ui/views/animation/ink_drop_highlight.h" 12 #include "ui/views/animation/ink_drop_highlight.h"
13 #include "ui/views/animation/ink_drop_impl.h" 13 #include "ui/views/animation/ink_drop_impl.h"
14 #include "ui/views/animation/ink_drop_stub.h" 14 #include "ui/views/animation/ink_drop_stub.h"
15 #include "ui/views/animation/square_ink_drop_ripple.h" 15 #include "ui/views/animation/square_ink_drop_ripple.h"
16 16
17 namespace views { 17 namespace views {
18 namespace { 18 namespace {
19 19
20 // Default sizes for ink drop effects. 20 // Default sizes for ink drop effects.
21 const int kInkDropSize = 24; 21 const int kInkDropSize = 24;
22 const int kInkDropLargeCornerRadius = 4;
23 22
24 // The scale factor to compute the large ink drop size. 23 // The scale factor to compute the large ink drop size.
25 const float kLargeInkDropScale = 1.333f; 24 const float kLargeInkDropScale = 1.333f;
26 25
27 // Default opacity of the ink drop when it is visible. 26 // Default opacity of the ink drop when it is visible.
28 const float kInkDropVisibleOpacity = 0.175f; 27 const float kInkDropVisibleOpacity = 0.175f;
29 28
30 gfx::Size CalculateLargeInkDropSize(const gfx::Size small_size) {
31 return gfx::ScaleToCeiledSize(gfx::Size(small_size), kLargeInkDropScale);
32 }
33
34 } // namespace 29 } // namespace
35 30
36 // static 31 // static
37 const int InkDropHostView::kInkDropSmallCornerRadius = 2; 32 const int InkDropHostView::kInkDropSmallCornerRadius = 2;
33 const int InkDropHostView::kInkDropLargeCornerRadius = 4;
38 34
39 // An EventHandler that is guaranteed to be invoked and is not prone to 35 // An EventHandler that is guaranteed to be invoked and is not prone to
40 // InkDropHostView descendents who do not call 36 // InkDropHostView descendents who do not call
41 // InkDropHostView::OnGestureEvent(). Only one instance of this class can exist 37 // InkDropHostView::OnGestureEvent(). Only one instance of this class can exist
42 // at any given time for each ink drop host view. 38 // at any given time for each ink drop host view.
43 // 39 //
44 // TODO(bruthig): Consider getting rid of this class. 40 // TODO(bruthig): Consider getting rid of this class.
45 class InkDropHostView::InkDropGestureHandler : public ui::EventHandler { 41 class InkDropHostView::InkDropGestureHandler : public ui::EventHandler {
46 public: 42 public:
47 explicit InkDropGestureHandler(InkDropHostView* host_view) 43 explicit InkDropGestureHandler(InkDropHostView* host_view)
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 private: 95 private:
100 // Allows |this| to handle all GestureEvents on |host_view_|. 96 // Allows |this| to handle all GestureEvents on |host_view_|.
101 std::unique_ptr<ui::ScopedTargetHandler> target_handler_; 97 std::unique_ptr<ui::ScopedTargetHandler> target_handler_;
102 98
103 // The host view to cache ui::Events to when animating the ink drop. 99 // The host view to cache ui::Events to when animating the ink drop.
104 InkDropHostView* host_view_; 100 InkDropHostView* host_view_;
105 101
106 DISALLOW_COPY_AND_ASSIGN(InkDropGestureHandler); 102 DISALLOW_COPY_AND_ASSIGN(InkDropGestureHandler);
107 }; 103 };
108 104
105 // static
106
107 gfx::Size InkDropHostView::CalculateLargeInkDropSize(
108 const gfx::Size small_size) {
109 return gfx::ScaleToCeiledSize(gfx::Size(small_size), kLargeInkDropScale);
110 }
111
109 InkDropHostView::InkDropHostView() 112 InkDropHostView::InkDropHostView()
110 : ink_drop_(new InkDropStub()), 113 : ink_drop_(new InkDropStub()),
111 ink_drop_size_(kInkDropSize, kInkDropSize),
112 ink_drop_visible_opacity_(kInkDropVisibleOpacity), 114 ink_drop_visible_opacity_(kInkDropVisibleOpacity),
113 old_paint_to_layer_(false), 115 old_paint_to_layer_(false),
114 destroying_(false) {} 116 destroying_(false) {}
115 117
116 InkDropHostView::~InkDropHostView() { 118 InkDropHostView::~InkDropHostView() {
117 // TODO(bruthig): Improve InkDropImpl to be safer about calling back to 119 // TODO(bruthig): Improve InkDropImpl to be safer about calling back to
118 // potentially destroyed InkDropHosts and remove |destroying_|. 120 // potentially destroyed InkDropHosts and remove |destroying_|.
119 destroying_ = true; 121 destroying_ = true;
120 } 122 }
121 123
122 void InkDropHostView::AddInkDropLayer(ui::Layer* ink_drop_layer) { 124 void InkDropHostView::AddInkDropLayer(ui::Layer* ink_drop_layer) {
123 old_paint_to_layer_ = layer() != nullptr; 125 old_paint_to_layer_ = layer() != nullptr;
124 SetPaintToLayer(true); 126 SetPaintToLayer(true);
125 layer()->SetFillsBoundsOpaquely(false); 127 layer()->SetFillsBoundsOpaquely(false);
126 layer()->Add(ink_drop_layer); 128 layer()->Add(ink_drop_layer);
127 layer()->StackAtBottom(ink_drop_layer); 129 layer()->StackAtBottom(ink_drop_layer);
128 } 130 }
129 131
130 void InkDropHostView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) { 132 void InkDropHostView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) {
131 // No need to do anything when called during shutdown, and if a derived 133 // No need to do anything when called during shutdown, and if a derived
132 // class has overridden Add/RemoveInkDropLayer, running this implementation 134 // class has overridden Add/RemoveInkDropLayer, running this implementation
133 // would be wrong. 135 // would be wrong.
134 if (destroying_) 136 if (destroying_)
135 return; 137 return;
136 layer()->Remove(ink_drop_layer); 138 layer()->Remove(ink_drop_layer);
137 SetPaintToLayer(old_paint_to_layer_); 139 SetPaintToLayer(old_paint_to_layer_);
138 } 140 }
139 141
142 std::unique_ptr<InkDrop> InkDropHostView::CreateInkDrop() {
143 return CreateDefaultInkDropImpl();
144 }
145
140 std::unique_ptr<InkDropRipple> InkDropHostView::CreateInkDropRipple() const { 146 std::unique_ptr<InkDropRipple> InkDropHostView::CreateInkDropRipple() const {
141 return CreateDefaultInkDropRipple(GetLocalBounds().CenterPoint()); 147 return CreateDefaultInkDropRipple(GetLocalBounds().CenterPoint());
142 } 148 }
143 149
144 std::unique_ptr<InkDropHighlight> InkDropHostView::CreateInkDropHighlight() 150 std::unique_ptr<InkDropHighlight> InkDropHostView::CreateInkDropHighlight()
145 const { 151 const {
146 return CreateDefaultInkDropHighlight( 152 return CreateDefaultInkDropHighlight(
147 gfx::RectF(GetLocalBounds()).CenterPoint()); 153 gfx::RectF(GetLocalBounds()).CenterPoint());
148 } 154 }
149 155
150 std::unique_ptr<InkDropRipple> InkDropHostView::CreateDefaultInkDropRipple( 156 std::unique_ptr<InkDropRipple> InkDropHostView::CreateDefaultInkDropRipple(
151 const gfx::Point& center_point) const { 157 const gfx::Point& center_point) const {
152 std::unique_ptr<InkDropRipple> ripple(new SquareInkDropRipple( 158 std::unique_ptr<InkDropRipple> ripple(new SquareInkDropRipple(
153 CalculateLargeInkDropSize(ink_drop_size_), kInkDropLargeCornerRadius, 159 CalculateLargeInkDropSize(gfx::Size(kInkDropSize, kInkDropSize)),
154 ink_drop_size_, kInkDropSmallCornerRadius, center_point, 160 kInkDropLargeCornerRadius, gfx::Size(kInkDropSize, kInkDropSize),
155 GetInkDropBaseColor(), ink_drop_visible_opacity())); 161 kInkDropSmallCornerRadius, center_point, GetInkDropBaseColor(),
162 ink_drop_visible_opacity()));
156 return ripple; 163 return ripple;
157 } 164 }
158 165
159 std::unique_ptr<InkDropHighlight> 166 std::unique_ptr<InkDropHighlight>
160 InkDropHostView::CreateDefaultInkDropHighlight( 167 InkDropHostView::CreateDefaultInkDropHighlight(
161 const gfx::PointF& center_point) const { 168 const gfx::PointF& center_point) const {
162 std::unique_ptr<InkDropHighlight> highlight( 169 std::unique_ptr<InkDropHighlight> highlight(new InkDropHighlight(
163 new InkDropHighlight(ink_drop_size_, kInkDropSmallCornerRadius, 170 gfx::Size(kInkDropSize, kInkDropSize), kInkDropSmallCornerRadius,
164 center_point, GetInkDropBaseColor())); 171 center_point, GetInkDropBaseColor()));
165 highlight->set_explode_size(CalculateLargeInkDropSize(ink_drop_size_)); 172 highlight->set_explode_size(
173 CalculateLargeInkDropSize(gfx::Size(kInkDropSize, kInkDropSize)));
166 return highlight; 174 return highlight;
167 } 175 }
168 176
169 gfx::Point InkDropHostView::GetInkDropCenterBasedOnLastEvent() const { 177 gfx::Point InkDropHostView::GetInkDropCenterBasedOnLastEvent() const {
170 return last_ripple_triggering_event_ 178 return last_ripple_triggering_event_
171 ? last_ripple_triggering_event_->location() 179 ? last_ripple_triggering_event_->location()
172 : GetLocalBounds().CenterPoint(); 180 : GetLocalBounds().CenterPoint();
173 } 181 }
174 182
175 void InkDropHostView::AnimateInkDrop(InkDropState state, 183 void InkDropHostView::AnimateInkDrop(InkDropState state,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 } 219 }
212 220
213 void InkDropHostView::OnMouseEvent(ui::MouseEvent* event) { 221 void InkDropHostView::OnMouseEvent(ui::MouseEvent* event) {
214 switch (event->type()) { 222 switch (event->type()) {
215 case ui::ET_MOUSE_ENTERED: 223 case ui::ET_MOUSE_ENTERED:
216 ink_drop_->SetHovered(true); 224 ink_drop_->SetHovered(true);
217 break; 225 break;
218 case ui::ET_MOUSE_EXITED: 226 case ui::ET_MOUSE_EXITED:
219 ink_drop_->SetHovered(false); 227 ink_drop_->SetHovered(false);
220 break; 228 break;
229 case ui::ET_MOUSE_DRAGGED:
230 ink_drop_->SetHovered(GetLocalBounds().Contains(event->location()));
231 break;
221 default: 232 default:
222 break; 233 break;
223 } 234 }
224 View::OnMouseEvent(event); 235 View::OnMouseEvent(event);
225 } 236 }
226 237
227 SkColor InkDropHostView::GetInkDropBaseColor() const { 238 SkColor InkDropHostView::GetInkDropBaseColor() const {
228 NOTREACHED(); 239 NOTREACHED();
229 return gfx::kPlaceholderColor; 240 return gfx::kPlaceholderColor;
230 } 241 }
231 242
232 bool InkDropHostView::ShouldShowInkDropForFocus() const { 243 bool InkDropHostView::ShouldShowInkDropForFocus() const {
233 return false; 244 return false;
234 } 245 }
235 246
236 void InkDropHostView::SetInkDropMode(InkDropMode ink_drop_mode) { 247 void InkDropHostView::SetInkDropMode(InkDropMode ink_drop_mode) {
237 if (ink_drop_mode == InkDropMode::OFF) 248 if (ink_drop_mode == InkDropMode::OFF)
238 ink_drop_.reset(new InkDropStub()); 249 ink_drop_.reset(new InkDropStub());
239 else 250 else
240 ink_drop_.reset(new InkDropImpl(this)); 251 ink_drop_ = CreateInkDrop();
241 252
242 if (ink_drop_mode != InkDropMode::ON) 253 if (ink_drop_mode != InkDropMode::ON)
243 gesture_handler_.reset(); 254 gesture_handler_.reset();
244 else if (!gesture_handler_) 255 else if (!gesture_handler_)
245 gesture_handler_.reset(new InkDropGestureHandler(this)); 256 gesture_handler_.reset(new InkDropGestureHandler(this));
246 } 257 }
247 258
259 std::unique_ptr<InkDropImpl> InkDropHostView::CreateDefaultInkDropImpl() {
260 std::unique_ptr<InkDropImpl> ink_drop(new InkDropImpl(this));
sky 2016/11/02 02:52:11 MakeUnique.
bruthig 2016/11/04 18:50:36 Done.
261 ink_drop->SetAutoHighlightMode(
262 views::InkDropImpl::AutoHighlightMode::HIDE_ON_RIPPLE);
263 return ink_drop;
264 }
265
266 std::unique_ptr<InkDropImpl>
267 InkDropHostView::CreateDefaultFloodFillInkDropImpl() {
268 std::unique_ptr<views::InkDropImpl> ink_drop =
269 InkDropHostView::CreateDefaultInkDropImpl();
270 ink_drop->SetAutoHighlightMode(
271 views::InkDropImpl::AutoHighlightMode::SHOW_ON_RIPPLE);
272 return ink_drop;
273 }
274
248 } // namespace views 275 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698