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

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

Issue 2665073002: Allow ripple hover/press effects to be more easily sized by subclasses. (Closed)
Patch Set: Review comment, compile fix Created 3 years, 10 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') | no next file » | 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 "base/memory/ptr_util.h"
8 #include "ui/events/event.h" 8 #include "ui/events/event.h"
9 #include "ui/events/scoped_target_handler.h" 9 #include "ui/events/scoped_target_handler.h"
10 #include "ui/gfx/color_palette.h" 10 #include "ui/gfx/color_palette.h"
11 #include "ui/gfx/geometry/size_conversions.h" 11 #include "ui/gfx/geometry/size_conversions.h"
12 #include "ui/views/animation/ink_drop.h" 12 #include "ui/views/animation/ink_drop.h"
13 #include "ui/views/animation/ink_drop_highlight.h" 13 #include "ui/views/animation/ink_drop_highlight.h"
14 #include "ui/views/animation/ink_drop_impl.h" 14 #include "ui/views/animation/ink_drop_impl.h"
15 #include "ui/views/animation/ink_drop_mask.h" 15 #include "ui/views/animation/ink_drop_mask.h"
16 #include "ui/views/animation/ink_drop_stub.h" 16 #include "ui/views/animation/ink_drop_stub.h"
17 #include "ui/views/animation/square_ink_drop_ripple.h" 17 #include "ui/views/animation/square_ink_drop_ripple.h"
18 18
19 namespace views { 19 namespace views {
20 namespace { 20 namespace {
21 21
22 // Size used for the default SquareInkDropRipple.
23 const int kInkDropSize = 24;
24
25 // The scale factor to compute the large size of the default 22 // The scale factor to compute the large size of the default
26 // SquareInkDropRipple. 23 // SquareInkDropRipple.
27 const float kLargeInkDropScale = 1.333f; 24 const float kLargeInkDropScale = 1.333f;
28 25
29 // Default opacity of the ink drop when it is visible. 26 // Default opacity of the ink drop when it is visible.
30 const float kInkDropVisibleOpacity = 0.175f; 27 const float kInkDropVisibleOpacity = 0.175f;
31 28
32 } // namespace 29 } // namespace
33 30
34 // static 31 // static
35 const int InkDropHostView::kInkDropSmallCornerRadius = 2; 32 constexpr int InkDropHostView::kInkDropSmallCornerRadius;
36 const int InkDropHostView::kInkDropLargeCornerRadius = 4; 33 constexpr int InkDropHostView::kInkDropLargeCornerRadius;
37 34
38 // 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
39 // InkDropHostView descendents who do not call 36 // InkDropHostView descendents who do not call
40 // InkDropHostView::OnGestureEvent(). Only one instance of this class can exist 37 // InkDropHostView::OnGestureEvent(). Only one instance of this class can exist
41 // at any given time for each ink drop host view. 38 // at any given time for each ink drop host view.
42 // 39 //
43 // TODO(bruthig): Consider getting rid of this class. 40 // TODO(bruthig): Consider getting rid of this class.
44 class InkDropHostView::InkDropGestureHandler : public ui::EventHandler { 41 class InkDropHostView::InkDropGestureHandler : public ui::EventHandler {
45 public: 42 public:
46 explicit InkDropGestureHandler(InkDropHostView* host_view) 43 explicit InkDropGestureHandler(InkDropHostView* host_view)
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 return CreateDefaultInkDropRipple(GetLocalBounds().CenterPoint()); 157 return CreateDefaultInkDropRipple(GetLocalBounds().CenterPoint());
161 } 158 }
162 159
163 std::unique_ptr<InkDropHighlight> InkDropHostView::CreateInkDropHighlight() 160 std::unique_ptr<InkDropHighlight> InkDropHostView::CreateInkDropHighlight()
164 const { 161 const {
165 return CreateDefaultInkDropHighlight( 162 return CreateDefaultInkDropHighlight(
166 gfx::RectF(GetLocalBounds()).CenterPoint()); 163 gfx::RectF(GetLocalBounds()).CenterPoint());
167 } 164 }
168 165
169 std::unique_ptr<InkDropRipple> InkDropHostView::CreateDefaultInkDropRipple( 166 std::unique_ptr<InkDropRipple> InkDropHostView::CreateDefaultInkDropRipple(
170 const gfx::Point& center_point) const { 167 const gfx::Point& center_point,
171 const gfx::Size small_size(kInkDropSize, kInkDropSize); 168 const gfx::Size& size) const {
172 std::unique_ptr<InkDropRipple> ripple(new SquareInkDropRipple( 169 std::unique_ptr<InkDropRipple> ripple(new SquareInkDropRipple(
173 CalculateLargeInkDropSize(small_size), kInkDropLargeCornerRadius, 170 CalculateLargeInkDropSize(size), kInkDropLargeCornerRadius, size,
174 small_size, kInkDropSmallCornerRadius, center_point, 171 kInkDropSmallCornerRadius, center_point, GetInkDropBaseColor(),
175 GetInkDropBaseColor(), ink_drop_visible_opacity())); 172 ink_drop_visible_opacity()));
176 return ripple; 173 return ripple;
177 } 174 }
178 175
179 std::unique_ptr<InkDropHighlight> 176 std::unique_ptr<InkDropHighlight>
180 InkDropHostView::CreateDefaultInkDropHighlight( 177 InkDropHostView::CreateDefaultInkDropHighlight(const gfx::PointF& center_point,
181 const gfx::PointF& center_point) const { 178 const gfx::Size& size) const {
182 const gfx::Size small_size(kInkDropSize, kInkDropSize); 179 std::unique_ptr<InkDropHighlight> highlight(new InkDropHighlight(
183 std::unique_ptr<InkDropHighlight> highlight( 180 size, kInkDropSmallCornerRadius, center_point, GetInkDropBaseColor()));
184 new InkDropHighlight(small_size, kInkDropSmallCornerRadius, center_point, 181 highlight->set_explode_size(CalculateLargeInkDropSize(size));
185 GetInkDropBaseColor()));
186 highlight->set_explode_size(CalculateLargeInkDropSize(small_size));
187 return highlight; 182 return highlight;
188 } 183 }
189 184
190 void InkDropHostView::SetInkDropMode(InkDropMode ink_drop_mode) { 185 void InkDropHostView::SetInkDropMode(InkDropMode ink_drop_mode) {
191 ink_drop_mode_ = ink_drop_mode; 186 ink_drop_mode_ = ink_drop_mode;
192 ink_drop_ = nullptr; 187 ink_drop_ = nullptr;
193 188
194 if (ink_drop_mode_ != InkDropMode::ON) 189 if (ink_drop_mode_ != InkDropMode::ON)
195 gesture_handler_ = nullptr; 190 gesture_handler_ = nullptr;
196 else if (!gesture_handler_) 191 else if (!gesture_handler_)
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 std::unique_ptr<InkDropImpl> 288 std::unique_ptr<InkDropImpl>
294 InkDropHostView::CreateDefaultFloodFillInkDropImpl() { 289 InkDropHostView::CreateDefaultFloodFillInkDropImpl() {
295 std::unique_ptr<views::InkDropImpl> ink_drop = 290 std::unique_ptr<views::InkDropImpl> ink_drop =
296 InkDropHostView::CreateDefaultInkDropImpl(); 291 InkDropHostView::CreateDefaultInkDropImpl();
297 ink_drop->SetAutoHighlightMode( 292 ink_drop->SetAutoHighlightMode(
298 views::InkDropImpl::AutoHighlightMode::SHOW_ON_RIPPLE); 293 views::InkDropImpl::AutoHighlightMode::SHOW_ON_RIPPLE);
299 return ink_drop; 294 return ink_drop;
300 } 295 }
301 296
302 } // namespace views 297 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/animation/ink_drop_host_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698