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