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" | 7 #include "third_party/skia/include/core/SkBitmap.h" |
8 #include "third_party/skia/include/effects/SkGradientShader.h" | 8 #include "third_party/skia/include/effects/SkGradientShader.h" |
9 #include "ui/gfx/canvas_skia.h" | 9 #include "ui/gfx/canvas_skia.h" |
10 #include "ui/gfx/skbitmap_operations.h" | 10 #include "ui/gfx/skbitmap_operations.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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::CanvasSkia hover_canvas( | 72 gfx::CanvasSkia hover_canvas( |
73 gfx::Size(mask_image.width(), mask_image.height()), false); | 73 gfx::Size(mask_image.width(), mask_image.height()), 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 |
78 SkPaint paint; | 78 SkPoint center_point; |
79 paint.setStyle(SkPaint::kFill_Style); | 79 center_point.iset(location_.x(), location_.y()); |
80 paint.setFlags(SkPaint::kAntiAlias_Flag); | |
81 SkPoint loc = { SkIntToScalar(location_.x()), SkIntToScalar(location_.y()) }; | |
82 SkColor colors[2]; | 80 SkColor colors[2]; |
83 int hover_alpha = | 81 int hover_alpha = |
84 static_cast<int>(255 * kOpacityScale * animation_.GetCurrentValue()); | 82 static_cast<int>(255 * kOpacityScale * animation_.GetCurrentValue()); |
85 colors[0] = SkColorSetARGB(hover_alpha, 255, 255, 255); | 83 colors[0] = SkColorSetARGB(hover_alpha, 255, 255, 255); |
86 colors[1] = SkColorSetARGB(0, 255, 255, 255); | 84 colors[1] = SkColorSetARGB(0, 255, 255, 255); |
87 SkShader* shader = SkGradientShader::CreateRadial( | 85 SkShader* shader = SkGradientShader::CreateRadial(center_point, |
88 loc, | 86 SkIntToScalar(radius), colors, NULL, 2, SkShader::kClamp_TileMode); |
89 SkIntToScalar(radius), | |
90 colors, | |
91 NULL, | |
92 2, | |
93 SkShader::kClamp_TileMode); | |
94 // Shader can end up null when radius = 0. | 87 // Shader can end up null when radius = 0. |
95 // If so, this results in default full tab glow behavior. | 88 // If so, this results in default full tab glow behavior. |
96 if (shader) { | 89 if (shader) { |
| 90 SkPaint paint; |
| 91 paint.setStyle(SkPaint::kFill_Style); |
| 92 paint.setAntiAlias(true); |
97 paint.setShader(shader); | 93 paint.setShader(shader); |
98 shader->unref(); | 94 shader->unref(); |
99 hover_canvas.DrawRect(gfx::Rect(location_.x() - radius, | 95 hover_canvas.DrawRect(gfx::Rect(location_.x() - radius, |
100 location_.y() - radius, | 96 location_.y() - radius, |
101 radius * 2, radius * 2), paint); | 97 radius * 2, radius * 2), paint); |
102 } | 98 } |
103 SkBitmap result = SkBitmapOperations::CreateMaskedBitmap( | 99 SkBitmap result = SkBitmapOperations::CreateMaskedBitmap( |
104 hover_canvas.ExtractBitmap(), mask_image); | 100 hover_canvas.ExtractBitmap(), mask_image); |
105 canvas->DrawBitmapInt(result, (view_->width() - mask_image.width()) / 2, | 101 canvas->DrawBitmapInt(result, (view_->width() - mask_image.width()) / 2, |
106 (view_->height() - mask_image.height()) / 2); | 102 (view_->height() - mask_image.height()) / 2); |
107 } | 103 } |
108 | 104 |
109 void GlowHoverController::AnimationEnded(const ui::Animation* animation) { | 105 void GlowHoverController::AnimationEnded(const ui::Animation* animation) { |
110 view_->SchedulePaint(); | 106 view_->SchedulePaint(); |
111 } | 107 } |
112 | 108 |
113 void GlowHoverController::AnimationProgressed(const ui::Animation* animation) { | 109 void GlowHoverController::AnimationProgressed(const ui::Animation* animation) { |
114 view_->SchedulePaint(); | 110 view_->SchedulePaint(); |
115 } | 111 } |
116 | 112 |
117 } // namespace views | 113 } // namespace views |
OLD | NEW |