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

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

Issue 11881042: highlight intermediate tabs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make check for Gesture vs Scroll event for flings explicit Created 7 years, 11 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 | Annotate | Revision Log
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 "third_party/skia/include/effects/SkGradientShader.h" 7 #include "third_party/skia/include/effects/SkGradientShader.h"
8 #include "ui/gfx/canvas.h" 8 #include "ui/gfx/canvas.h"
9 #include "ui/gfx/image/image_skia.h" 9 #include "ui/gfx/image/image_skia.h"
10 #include "ui/gfx/image/image_skia_operations.h" 10 #include "ui/gfx/image/image_skia_operations.h"
11 #include "ui/views/view.h" 11 #include "ui/views/view.h"
12 12
13 namespace views { 13 namespace views {
14 14
15 // Amount to scale the opacity. 15 // Amount to scale the opacity.
16 static const double kOpacityScale = 0.5; 16 static const double kTrackOpacityScale = 0.5;
17 static const double kHighlightOpacityScale = 1.0;
17 18
18 // How long the hover state takes. 19 // How long the hover state takes.
19 static const int kHoverDurationMs = 400; 20 static const int kTrackHoverDurationMs = 400;
20 21
21 GlowHoverController::GlowHoverController(views::View* view) 22 GlowHoverController::GlowHoverController(views::View* view)
22 : view_(view), 23 : view_(view),
23 ALLOW_THIS_IN_INITIALIZER_LIST(animation_(this)) { 24 ALLOW_THIS_IN_INITIALIZER_LIST(animation_(this)),
25 opacity_scale_(kTrackOpacityScale) {
24 animation_.set_delegate(this); 26 animation_.set_delegate(this);
25 animation_.SetSlideDuration(kHoverDurationMs);
26 } 27 }
27 28
28 GlowHoverController::~GlowHoverController() { 29 GlowHoverController::~GlowHoverController() {
29 } 30 }
30 31
31 void GlowHoverController::SetAnimationContainer( 32 void GlowHoverController::SetAnimationContainer(
32 ui::AnimationContainer* container) { 33 ui::AnimationContainer* container) {
33 animation_.SetContainer(container); 34 animation_.SetContainer(container);
34 } 35 }
35 36
36 void GlowHoverController::SetLocation(const gfx::Point& location) { 37 void GlowHoverController::SetLocation(const gfx::Point& location) {
37 location_ = location; 38 location_ = location;
38 if (ShouldDraw()) 39 if (ShouldDraw())
39 view_->SchedulePaint(); 40 view_->SchedulePaint();
40 } 41 }
41 42
42 void GlowHoverController::Show() { 43 void GlowHoverController::Show(Style style) {
43 animation_.SetTweenType(ui::Tween::EASE_OUT); 44 switch (style) {
44 animation_.Show(); 45 case SUBTLE:
46 opacity_scale_ = kTrackOpacityScale;
47 animation_.SetSlideDuration(kTrackHoverDurationMs);
48 animation_.SetTweenType(ui::Tween::EASE_OUT);
49 animation_.Show();
50 break;
51 case PRONOUNCED:
52 opacity_scale_ = kHighlightOpacityScale;
53 animation_.Show();
sky 2013/01/22 18:05:01 Add comment why you do the Show() then End().
DaveMoore 2013/01/27 21:21:54 Done.
54 animation_.End();
55 break;
56 }
45 } 57 }
46 58
47 void GlowHoverController::Hide() { 59 void GlowHoverController::Hide() {
48 animation_.SetTweenType(ui::Tween::EASE_IN); 60 animation_.SetTweenType(ui::Tween::EASE_IN);
49 animation_.Hide(); 61 animation_.Hide();
50 } 62 }
51 63
52 void GlowHoverController::HideImmediately() { 64 void GlowHoverController::HideImmediately() {
53 if (ShouldDraw()) 65 if (ShouldDraw())
54 view_->SchedulePaint(); 66 view_->SchedulePaint();
(...skipping 18 matching lines...) Expand all
73 canvas->scale_factor(), 85 canvas->scale_factor(),
74 false); 86 false);
75 87
76 // Draw a radial gradient to hover_canvas. 88 // Draw a radial gradient to hover_canvas.
77 int radius = view_->width() / 3; 89 int radius = view_->width() / 3;
78 90
79 SkPoint center_point; 91 SkPoint center_point;
80 center_point.iset(location_.x(), location_.y()); 92 center_point.iset(location_.x(), location_.y());
81 SkColor colors[2]; 93 SkColor colors[2];
82 int hover_alpha = 94 int hover_alpha =
83 static_cast<int>(255 * kOpacityScale * animation_.GetCurrentValue()); 95 static_cast<int>(255 * opacity_scale_ * animation_.GetCurrentValue());
84 colors[0] = SkColorSetARGB(hover_alpha, 255, 255, 255); 96 colors[0] = SkColorSetARGB(hover_alpha, 255, 255, 255);
85 colors[1] = SkColorSetARGB(0, 255, 255, 255); 97 colors[1] = SkColorSetARGB(0, 255, 255, 255);
86 skia::RefPtr<SkShader> shader = skia::AdoptRef( 98 skia::RefPtr<SkShader> shader = skia::AdoptRef(
87 SkGradientShader::CreateRadial( 99 SkGradientShader::CreateRadial(
88 center_point, SkIntToScalar(radius), colors, NULL, 2, 100 center_point, SkIntToScalar(radius), colors, NULL, 2,
89 SkShader::kClamp_TileMode)); 101 SkShader::kClamp_TileMode));
90 // Shader can end up null when radius = 0. 102 // Shader can end up null when radius = 0.
91 // If so, this results in default full tab glow behavior. 103 // If so, this results in default full tab glow behavior.
92 if (shader) { 104 if (shader) {
93 SkPaint paint; 105 SkPaint paint;
(...skipping 12 matching lines...) Expand all
106 118
107 void GlowHoverController::AnimationEnded(const ui::Animation* animation) { 119 void GlowHoverController::AnimationEnded(const ui::Animation* animation) {
108 view_->SchedulePaint(); 120 view_->SchedulePaint();
109 } 121 }
110 122
111 void GlowHoverController::AnimationProgressed(const ui::Animation* animation) { 123 void GlowHoverController::AnimationProgressed(const ui::Animation* animation) {
112 view_->SchedulePaint(); 124 view_->SchedulePaint();
113 } 125 }
114 126
115 } // namespace views 127 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698