Chromium Code Reviews| 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" |
|
sky
2015/11/05 03:27:16
nit: nuke any includes that are now stale.
Peter Kasting
2015/11/05 06:25:17
Good call, didn't even think of it. Done.
| |
| 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 kTrackOpacityScale = 0.5; | 16 static const double kTrackOpacityScale = 0.5; |
| 17 static const double kHighlightOpacityScale = 1.0; | 17 static const double kHighlightOpacityScale = 1.0; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 void GlowHoverController::HideImmediately() { | 65 void GlowHoverController::HideImmediately() { |
| 66 if (ShouldDraw()) | 66 if (ShouldDraw()) |
| 67 view_->SchedulePaint(); | 67 view_->SchedulePaint(); |
| 68 animation_.Reset(); | 68 animation_.Reset(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 double GlowHoverController::GetAnimationValue() const { | 71 double GlowHoverController::GetAnimationValue() const { |
| 72 return animation_.GetCurrentValue(); | 72 return animation_.GetCurrentValue(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 SkAlpha GlowHoverController::GetAlpha() const { | |
| 76 return static_cast<SkAlpha>(gfx::ToFlooredInt( | |
| 77 0.5 + animation_.CurrentValueBetween(0., 255 * opacity_scale_))); | |
| 78 } | |
| 79 | |
| 75 bool GlowHoverController::ShouldDraw() const { | 80 bool GlowHoverController::ShouldDraw() const { |
| 76 return animation_.IsShowing() || animation_.is_animating(); | 81 return animation_.IsShowing() || animation_.is_animating(); |
| 77 } | 82 } |
| 78 | 83 |
| 79 void GlowHoverController::Draw(gfx::Canvas* canvas, | |
| 80 const gfx::ImageSkia& mask_image) const { | |
| 81 if (!ShouldDraw()) | |
| 82 return; | |
| 83 | |
| 84 // Draw a radial gradient to hover_canvas. | |
| 85 gfx::Canvas hover_canvas(gfx::Size(mask_image.width(), mask_image.height()), | |
| 86 canvas->image_scale(), | |
| 87 false); | |
| 88 | |
| 89 // Draw a radial gradient to hover_canvas. | |
| 90 int radius = view_->width() / 3; | |
| 91 | |
| 92 SkPoint center_point; | |
| 93 center_point.iset(location_.x(), location_.y()); | |
| 94 SkColor colors[2]; | |
| 95 int hover_alpha = | |
| 96 static_cast<int>(255 * opacity_scale_ * animation_.GetCurrentValue()); | |
| 97 colors[0] = SkColorSetARGB(hover_alpha, 255, 255, 255); | |
| 98 colors[1] = SkColorSetARGB(0, 255, 255, 255); | |
| 99 skia::RefPtr<SkShader> shader = skia::AdoptRef( | |
| 100 SkGradientShader::CreateRadial( | |
| 101 center_point, SkIntToScalar(radius), colors, NULL, 2, | |
| 102 SkShader::kClamp_TileMode)); | |
| 103 // Shader can end up null when radius = 0. | |
| 104 // If so, this results in default full tab glow behavior. | |
| 105 if (shader) { | |
| 106 SkPaint paint; | |
| 107 paint.setStyle(SkPaint::kFill_Style); | |
| 108 paint.setAntiAlias(true); | |
| 109 paint.setShader(shader.get()); | |
| 110 hover_canvas.DrawRect(gfx::Rect(location_.x() - radius, | |
| 111 location_.y() - radius, | |
| 112 radius * 2, radius * 2), paint); | |
| 113 } | |
| 114 gfx::ImageSkia result = gfx::ImageSkiaOperations::CreateMaskedImage( | |
| 115 gfx::ImageSkia(hover_canvas.ExtractImageRep()), mask_image); | |
| 116 canvas->DrawImageInt(result, (view_->width() - mask_image.width()) / 2, | |
| 117 (view_->height() - mask_image.height()) / 2); | |
| 118 } | |
| 119 | |
| 120 void GlowHoverController::AnimationEnded(const gfx::Animation* animation) { | 84 void GlowHoverController::AnimationEnded(const gfx::Animation* animation) { |
| 121 view_->SchedulePaint(); | 85 view_->SchedulePaint(); |
| 122 } | 86 } |
| 123 | 87 |
| 124 void GlowHoverController::AnimationProgressed(const gfx::Animation* animation) { | 88 void GlowHoverController::AnimationProgressed(const gfx::Animation* animation) { |
| 125 view_->SchedulePaint(); | 89 view_->SchedulePaint(); |
| 126 } | 90 } |
| 127 | 91 |
| 128 } // namespace views | 92 } // namespace views |
| OLD | NEW |