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

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

Issue 1682893002: Color the ink drop ripple and hover effects based on theming. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix unit tests Created 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_hover.h" 5 #include "ui/views/animation/ink_drop_hover.h"
6 6
7 #include "third_party/skia/include/core/SkColor.h" 7 #include "third_party/skia/include/core/SkColor.h"
8 #include "ui/compositor/callback_layer_animation_observer.h" 8 #include "ui/compositor/callback_layer_animation_observer.h"
9 #include "ui/compositor/layer.h" 9 #include "ui/compositor/layer.h"
10 #include "ui/compositor/layer_animation_sequence.h" 10 #include "ui/compositor/layer_animation_sequence.h"
11 #include "ui/compositor/scoped_layer_animation_settings.h" 11 #include "ui/compositor/scoped_layer_animation_settings.h"
12 #include "ui/views/animation/ink_drop_painted_layer_delegates.h" 12 #include "ui/views/animation/ink_drop_painted_layer_delegates.h"
13 13
14 namespace views { 14 namespace views {
15 15
16 namespace { 16 namespace {
17 17
18 // The opacity of the hover when it is visible. 18 // The opacity of the hover when it is visible.
19 const float kHoverVisibleOpacity = 0.08f; 19 const float kHoverVisibleOpacity = 0.128f;
Evan Stade 2016/02/09 20:39:28 I used algebra for these conversions
bruthig 2016/02/09 21:01:06 Do you think we'll have to parameterize these in t
Evan Stade 2016/02/09 22:54:28 no
20 20
21 // The opacity of the hover when it is not visible. 21 // The opacity of the hover when it is not visible.
22 const float kHiddenOpacity = 0.0f; 22 const float kHiddenOpacity = 0.0f;
23 23
24 // The hover color.
25 const SkColor kHoverColor = SK_ColorBLACK;
26
27 } // namespace 24 } // namespace
28 25
29 InkDropHover::InkDropHover(const gfx::Size& size, int corner_radius) 26 InkDropHover::InkDropHover(SkColor color,
27 const gfx::Size& size,
28 int corner_radius)
30 : layer_delegate_( 29 : layer_delegate_(
31 new RoundedRectangleLayerDelegate(kHoverColor, size, corner_radius)), 30 new RoundedRectangleLayerDelegate(color, size, corner_radius)),
32 layer_(new ui::Layer()) { 31 layer_(new ui::Layer()) {
33 layer_->SetBounds(gfx::Rect(size)); 32 layer_->SetBounds(gfx::Rect(size));
34 layer_->SetFillsBoundsOpaquely(false); 33 layer_->SetFillsBoundsOpaquely(false);
35 layer_->set_delegate(layer_delegate_.get()); 34 layer_->set_delegate(layer_delegate_.get());
36 layer_->SetVisible(false); 35 layer_->SetVisible(false);
37 layer_->SetOpacity(kHoverVisibleOpacity); 36 layer_->SetOpacity(kHoverVisibleOpacity);
38 layer_->SetMasksToBounds(false); 37 layer_->SetMasksToBounds(false);
39 layer_->set_name("InkDropHover:layer"); 38 layer_->set_name("InkDropHover:layer");
40 SetCenterPoint(gfx::Rect(size).CenterPoint()); 39 SetCenterPoint(gfx::Rect(size).CenterPoint());
41 } 40 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 duration); 75 duration);
77 ui::LayerAnimationSequence* animation_sequence = 76 ui::LayerAnimationSequence* animation_sequence =
78 new ui::LayerAnimationSequence(animation_element); 77 new ui::LayerAnimationSequence(animation_element);
79 animation_sequence->AddObserver(animation_observer); 78 animation_sequence->AddObserver(animation_observer);
80 79
81 animator->StartAnimation(animation_sequence); 80 animator->StartAnimation(animation_sequence);
82 81
83 animation_observer->SetActive(); 82 animation_observer->SetActive();
84 } 83 }
85 84
85 SkColor InkDropHover::GetColor() const {
86 return layer_delegate_->color();
87 }
88
86 void InkDropHover::SetCenterPoint(const gfx::Point& center_point) { 89 void InkDropHover::SetCenterPoint(const gfx::Point& center_point) {
87 gfx::Transform transform; 90 gfx::Transform transform;
88 transform.Translate(center_point.x() - layer_->bounds().CenterPoint().x(), 91 transform.Translate(center_point.x() - layer_->bounds().CenterPoint().x(),
89 center_point.y() - layer_->bounds().CenterPoint().y()); 92 center_point.y() - layer_->bounds().CenterPoint().y());
90 layer_->SetTransform(transform); 93 layer_->SetTransform(transform);
91 } 94 }
92 95
93 bool InkDropHover::AnimationEndedCallback( 96 bool InkDropHover::AnimationEndedCallback(
94 HoverAnimationType animation_type, 97 HoverAnimationType animation_type,
95 const ui::CallbackLayerAnimationObserver& observer) { 98 const ui::CallbackLayerAnimationObserver& observer) {
96 // AnimationEndedCallback() may be invoked when this is being destroyed and 99 // AnimationEndedCallback() may be invoked when this is being destroyed and
97 // |layer_| may be null. 100 // |layer_| may be null.
98 if (animation_type == FADE_OUT && layer_) 101 if (animation_type == FADE_OUT && layer_)
99 layer_->SetVisible(false); 102 layer_->SetVisible(false);
100 return true; 103 return true;
101 } 104 }
102 105
103 } // namespace views 106 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698