| OLD | NEW |
| 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 // Force the end state to show immediately. |
| 54 animation_.Show(); |
| 55 animation_.End(); |
| 56 break; |
| 57 } |
| 45 } | 58 } |
| 46 | 59 |
| 47 void GlowHoverController::Hide() { | 60 void GlowHoverController::Hide() { |
| 48 animation_.SetTweenType(ui::Tween::EASE_IN); | 61 animation_.SetTweenType(ui::Tween::EASE_IN); |
| 49 animation_.Hide(); | 62 animation_.Hide(); |
| 50 } | 63 } |
| 51 | 64 |
| 52 void GlowHoverController::HideImmediately() { | 65 void GlowHoverController::HideImmediately() { |
| 53 if (ShouldDraw()) | 66 if (ShouldDraw()) |
| 54 view_->SchedulePaint(); | 67 view_->SchedulePaint(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 73 canvas->scale_factor(), | 86 canvas->scale_factor(), |
| 74 false); | 87 false); |
| 75 | 88 |
| 76 // Draw a radial gradient to hover_canvas. | 89 // Draw a radial gradient to hover_canvas. |
| 77 int radius = view_->width() / 3; | 90 int radius = view_->width() / 3; |
| 78 | 91 |
| 79 SkPoint center_point; | 92 SkPoint center_point; |
| 80 center_point.iset(location_.x(), location_.y()); | 93 center_point.iset(location_.x(), location_.y()); |
| 81 SkColor colors[2]; | 94 SkColor colors[2]; |
| 82 int hover_alpha = | 95 int hover_alpha = |
| 83 static_cast<int>(255 * kOpacityScale * animation_.GetCurrentValue()); | 96 static_cast<int>(255 * opacity_scale_ * animation_.GetCurrentValue()); |
| 84 colors[0] = SkColorSetARGB(hover_alpha, 255, 255, 255); | 97 colors[0] = SkColorSetARGB(hover_alpha, 255, 255, 255); |
| 85 colors[1] = SkColorSetARGB(0, 255, 255, 255); | 98 colors[1] = SkColorSetARGB(0, 255, 255, 255); |
| 86 skia::RefPtr<SkShader> shader = skia::AdoptRef( | 99 skia::RefPtr<SkShader> shader = skia::AdoptRef( |
| 87 SkGradientShader::CreateRadial( | 100 SkGradientShader::CreateRadial( |
| 88 center_point, SkIntToScalar(radius), colors, NULL, 2, | 101 center_point, SkIntToScalar(radius), colors, NULL, 2, |
| 89 SkShader::kClamp_TileMode)); | 102 SkShader::kClamp_TileMode)); |
| 90 // Shader can end up null when radius = 0. | 103 // Shader can end up null when radius = 0. |
| 91 // If so, this results in default full tab glow behavior. | 104 // If so, this results in default full tab glow behavior. |
| 92 if (shader) { | 105 if (shader) { |
| 93 SkPaint paint; | 106 SkPaint paint; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 106 | 119 |
| 107 void GlowHoverController::AnimationEnded(const ui::Animation* animation) { | 120 void GlowHoverController::AnimationEnded(const ui::Animation* animation) { |
| 108 view_->SchedulePaint(); | 121 view_->SchedulePaint(); |
| 109 } | 122 } |
| 110 | 123 |
| 111 void GlowHoverController::AnimationProgressed(const ui::Animation* animation) { | 124 void GlowHoverController::AnimationProgressed(const ui::Animation* animation) { |
| 112 view_->SchedulePaint(); | 125 view_->SchedulePaint(); |
| 113 } | 126 } |
| 114 | 127 |
| 115 } // namespace views | 128 } // namespace views |
| OLD | NEW |