| 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/core/SkBitmap.h" | |
| 8 #include "third_party/skia/include/effects/SkGradientShader.h" | 7 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 9 #include "ui/gfx/canvas.h" | 8 #include "ui/gfx/canvas.h" |
| 9 #include "ui/gfx/image/image_skia.h" |
| 10 #include "ui/gfx/skbitmap_operations.h" | 10 #include "ui/gfx/skbitmap_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 kOpacityScale = 0.5; |
| 17 | 17 |
| 18 // How long the hover state takes. | 18 // How long the hover state takes. |
| 19 static const int kHoverDurationMs = 400; | 19 static const int kHoverDurationMs = 400; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 | 57 |
| 58 double GlowHoverController::GetAnimationValue() const { | 58 double GlowHoverController::GetAnimationValue() const { |
| 59 return animation_.GetCurrentValue(); | 59 return animation_.GetCurrentValue(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 bool GlowHoverController::ShouldDraw() const { | 62 bool GlowHoverController::ShouldDraw() const { |
| 63 return animation_.IsShowing() || animation_.is_animating(); | 63 return animation_.IsShowing() || animation_.is_animating(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void GlowHoverController::Draw(gfx::Canvas* canvas, | 66 void GlowHoverController::Draw(gfx::Canvas* canvas, |
| 67 const SkBitmap& mask_image) const { | 67 const gfx::ImageSkia& mask_image) const { |
| 68 if (!ShouldDraw()) | 68 if (!ShouldDraw()) |
| 69 return; | 69 return; |
| 70 | 70 |
| 71 // Draw a radial gradient to hover_canvas. | 71 // Draw a radial gradient to hover_canvas. |
| 72 gfx::Canvas hover_canvas(gfx::Size(mask_image.width(), mask_image.height()), | 72 gfx::Canvas hover_canvas(gfx::Size(mask_image.width(), mask_image.height()), |
| 73 false); | 73 false); |
| 74 | 74 |
| 75 // Draw a radial gradient to hover_canvas. | 75 // Draw a radial gradient to hover_canvas. |
| 76 int radius = view_->width() / 3; | 76 int radius = view_->width() / 3; |
| 77 | 77 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 89 if (shader) { | 89 if (shader) { |
| 90 SkPaint paint; | 90 SkPaint paint; |
| 91 paint.setStyle(SkPaint::kFill_Style); | 91 paint.setStyle(SkPaint::kFill_Style); |
| 92 paint.setAntiAlias(true); | 92 paint.setAntiAlias(true); |
| 93 paint.setShader(shader); | 93 paint.setShader(shader); |
| 94 shader->unref(); | 94 shader->unref(); |
| 95 hover_canvas.DrawRect(gfx::Rect(location_.x() - radius, | 95 hover_canvas.DrawRect(gfx::Rect(location_.x() - radius, |
| 96 location_.y() - radius, | 96 location_.y() - radius, |
| 97 radius * 2, radius * 2), paint); | 97 radius * 2, radius * 2), paint); |
| 98 } | 98 } |
| 99 SkBitmap result = SkBitmapOperations::CreateMaskedBitmap( | 99 gfx::ImageSkia result = SkBitmapOperations::CreateMaskedBitmap( |
| 100 hover_canvas.ExtractBitmap(), mask_image); | 100 hover_canvas.ExtractBitmap(), mask_image); |
| 101 canvas->DrawBitmapInt(result, (view_->width() - mask_image.width()) / 2, | 101 canvas->DrawBitmapInt(result, (view_->width() - mask_image.width()) / 2, |
| 102 (view_->height() - mask_image.height()) / 2); | 102 (view_->height() - mask_image.height()) / 2); |
| 103 } | 103 } |
| 104 | 104 |
| 105 void GlowHoverController::AnimationEnded(const ui::Animation* animation) { | 105 void GlowHoverController::AnimationEnded(const ui::Animation* animation) { |
| 106 view_->SchedulePaint(); | 106 view_->SchedulePaint(); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void GlowHoverController::AnimationProgressed(const ui::Animation* animation) { | 109 void GlowHoverController::AnimationProgressed(const ui::Animation* animation) { |
| 110 view_->SchedulePaint(); | 110 view_->SchedulePaint(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 } // namespace views | 113 } // namespace views |
| OLD | NEW |