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

Side by Side Diff: ui/views/controls/glow_hover_controller.cc

Issue 1710253003: Misc. Tab-related cleanup. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Better structure for #ifdefs Created 4 years, 9 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/gfx/animation/multi_animation_unittest.cc ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/controls/glow_hover_controller.h" 5 #include "ui/views/controls/glow_hover_controller.h"
6 6
7 #include "ui/views/view.h" 7 #include "ui/views/view.h"
8 8
9 namespace views { 9 namespace views {
10 10
11 // Amount to scale the opacity. 11 // Amount to scale the opacity.
12 static const double kTrackOpacityScale = 0.25; 12 static const double kSubtleOpacityScale = 0.25;
13 static const double kHighlightOpacityScale = 1.0; 13 static const double kPronouncedOpacityScale = 1.0;
14 14
15 // How long the hover state takes. 15 // How long the hover state takes.
16 static const int kTrackHoverDurationMs = 400; 16 static const int kTrackHoverDurationMs = 400;
17 17
18 GlowHoverController::GlowHoverController(views::View* view) 18 GlowHoverController::GlowHoverController(views::View* view)
19 : view_(view), 19 : view_(view),
20 animation_(this), 20 animation_(this),
21 opacity_scale_(kTrackOpacityScale) { 21 opacity_scale_(kSubtleOpacityScale) {
22 animation_.set_delegate(this); 22 animation_.set_delegate(this);
23 } 23 }
24 24
25 GlowHoverController::~GlowHoverController() { 25 GlowHoverController::~GlowHoverController() {
26 } 26 }
27 27
28 void GlowHoverController::SetAnimationContainer( 28 void GlowHoverController::SetAnimationContainer(
29 gfx::AnimationContainer* container) { 29 gfx::AnimationContainer* container) {
30 animation_.SetContainer(container); 30 animation_.SetContainer(container);
31 } 31 }
32 32
33 void GlowHoverController::SetLocation(const gfx::Point& location) { 33 void GlowHoverController::SetLocation(const gfx::Point& location) {
34 location_ = location; 34 location_ = location;
35 if (ShouldDraw()) 35 if (ShouldDraw())
36 view_->SchedulePaint(); 36 view_->SchedulePaint();
37 } 37 }
38 38
39 void GlowHoverController::Show(Style style) { 39 void GlowHoverController::Show(Style style) {
40 switch (style) { 40 switch (style) {
41 case SUBTLE: 41 case SUBTLE:
42 opacity_scale_ = kTrackOpacityScale; 42 opacity_scale_ = kSubtleOpacityScale;
43 animation_.SetSlideDuration(kTrackHoverDurationMs); 43 animation_.SetSlideDuration(kTrackHoverDurationMs);
44 animation_.SetTweenType(gfx::Tween::EASE_OUT); 44 animation_.SetTweenType(gfx::Tween::EASE_OUT);
45 animation_.Show(); 45 animation_.Show();
46 break; 46 break;
47 case PRONOUNCED: 47 case PRONOUNCED:
48 opacity_scale_ = kHighlightOpacityScale; 48 opacity_scale_ = kPronouncedOpacityScale;
49 // Force the end state to show immediately. 49 // Force the end state to show immediately.
50 animation_.Show(); 50 animation_.Show();
51 animation_.End(); 51 animation_.End();
52 break; 52 break;
53 } 53 }
54 } 54 }
55 55
56 void GlowHoverController::Hide() { 56 void GlowHoverController::Hide() {
57 animation_.SetTweenType(gfx::Tween::EASE_IN); 57 animation_.SetTweenType(gfx::Tween::EASE_IN);
58 animation_.Hide(); 58 animation_.Hide();
59 } 59 }
60 60
61 void GlowHoverController::HideImmediately() { 61 void GlowHoverController::HideImmediately() {
62 if (ShouldDraw()) 62 if (ShouldDraw())
63 view_->SchedulePaint(); 63 view_->SchedulePaint();
64 animation_.Reset(); 64 animation_.Reset();
65 } 65 }
66 66
67 double GlowHoverController::GetAnimationValue() const { 67 double GlowHoverController::GetAnimationValue() const {
68 return animation_.GetCurrentValue(); 68 return animation_.GetCurrentValue();
69 } 69 }
70 70
71 SkAlpha GlowHoverController::GetAlpha() const { 71 SkAlpha GlowHoverController::GetAlpha() const {
72 return static_cast<SkAlpha>(gfx::ToFlooredInt( 72 return static_cast<SkAlpha>(animation_.CurrentValueBetween(
73 0.5 + animation_.CurrentValueBetween(0., 255 * opacity_scale_))); 73 0, gfx::ToRoundedInt(255 * opacity_scale_)));
74 } 74 }
75 75
76 bool GlowHoverController::ShouldDraw() const { 76 bool GlowHoverController::ShouldDraw() const {
77 return animation_.IsShowing() || animation_.is_animating(); 77 return animation_.IsShowing() || animation_.is_animating();
78 } 78 }
79 79
80 void GlowHoverController::AnimationEnded(const gfx::Animation* animation) { 80 void GlowHoverController::AnimationEnded(const gfx::Animation* animation) {
81 view_->SchedulePaint(); 81 view_->SchedulePaint();
82 } 82 }
83 83
84 void GlowHoverController::AnimationProgressed(const gfx::Animation* animation) { 84 void GlowHoverController::AnimationProgressed(const gfx::Animation* animation) {
85 view_->SchedulePaint(); 85 view_->SchedulePaint();
86 } 86 }
87 87
88 } // namespace views 88 } // namespace views
OLDNEW
« no previous file with comments | « ui/gfx/animation/multi_animation_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698