| 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" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 // Draw a radial gradient to hover_canvas. | 76 // Draw a radial gradient to hover_canvas. |
| 77 int radius = view_->width() / 3; | 77 int radius = view_->width() / 3; |
| 78 | 78 |
| 79 SkPoint center_point; | 79 SkPoint center_point; |
| 80 center_point.iset(location_.x(), location_.y()); | 80 center_point.iset(location_.x(), location_.y()); |
| 81 SkColor colors[2]; | 81 SkColor colors[2]; |
| 82 int hover_alpha = | 82 int hover_alpha = |
| 83 static_cast<int>(255 * kOpacityScale * animation_.GetCurrentValue()); | 83 static_cast<int>(255 * kOpacityScale * animation_.GetCurrentValue()); |
| 84 colors[0] = SkColorSetARGB(hover_alpha, 255, 255, 255); | 84 colors[0] = SkColorSetARGB(hover_alpha, 255, 255, 255); |
| 85 colors[1] = SkColorSetARGB(0, 255, 255, 255); | 85 colors[1] = SkColorSetARGB(0, 255, 255, 255); |
| 86 SkShader* shader = SkGradientShader::CreateRadial(center_point, | 86 skia::RefPtr<SkShader> shader = skia::AdoptRef( |
| 87 SkIntToScalar(radius), colors, NULL, 2, SkShader::kClamp_TileMode); | 87 SkGradientShader::CreateRadial( |
| 88 center_point, SkIntToScalar(radius), colors, NULL, 2, |
| 89 SkShader::kClamp_TileMode)); |
| 88 // Shader can end up null when radius = 0. | 90 // Shader can end up null when radius = 0. |
| 89 // If so, this results in default full tab glow behavior. | 91 // If so, this results in default full tab glow behavior. |
| 90 if (shader) { | 92 if (shader) { |
| 91 SkPaint paint; | 93 SkPaint paint; |
| 92 paint.setStyle(SkPaint::kFill_Style); | 94 paint.setStyle(SkPaint::kFill_Style); |
| 93 paint.setAntiAlias(true); | 95 paint.setAntiAlias(true); |
| 94 paint.setShader(shader); | 96 paint.setShader(shader.get()); |
| 95 shader->unref(); | |
| 96 hover_canvas.DrawRect(gfx::Rect(location_.x() - radius, | 97 hover_canvas.DrawRect(gfx::Rect(location_.x() - radius, |
| 97 location_.y() - radius, | 98 location_.y() - radius, |
| 98 radius * 2, radius * 2), paint); | 99 radius * 2, radius * 2), paint); |
| 99 } | 100 } |
| 100 gfx::ImageSkia result = gfx::ImageSkiaOperations::CreateMaskedImage( | 101 gfx::ImageSkia result = gfx::ImageSkiaOperations::CreateMaskedImage( |
| 101 gfx::ImageSkia(hover_canvas.ExtractImageRep()), mask_image); | 102 gfx::ImageSkia(hover_canvas.ExtractImageRep()), mask_image); |
| 102 canvas->DrawImageInt(result, (view_->width() - mask_image.width()) / 2, | 103 canvas->DrawImageInt(result, (view_->width() - mask_image.width()) / 2, |
| 103 (view_->height() - mask_image.height()) / 2); | 104 (view_->height() - mask_image.height()) / 2); |
| 104 } | 105 } |
| 105 | 106 |
| 106 void GlowHoverController::AnimationEnded(const ui::Animation* animation) { | 107 void GlowHoverController::AnimationEnded(const ui::Animation* animation) { |
| 107 view_->SchedulePaint(); | 108 view_->SchedulePaint(); |
| 108 } | 109 } |
| 109 | 110 |
| 110 void GlowHoverController::AnimationProgressed(const ui::Animation* animation) { | 111 void GlowHoverController::AnimationProgressed(const ui::Animation* animation) { |
| 111 view_->SchedulePaint(); | 112 view_->SchedulePaint(); |
| 112 } | 113 } |
| 113 | 114 |
| 114 } // namespace views | 115 } // namespace views |
| OLD | NEW |