summaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorpkasting <pkasting@chromium.org>2015-11-04 23:36:23 -0800
committerCommit bot <commit-bot@chromium.org>2015-11-05 07:37:12 +0000
commit44f92d1b16b0d3b67f53469be5aa205e58cb0748 (patch)
tree4e541429c270724e97560f6cbdcd163347b945fa /ui
parentd21fd694202cec4e3cb6400319540969d5db9428 (diff)
downloadchromium_src-44f92d1b16b0d3b67f53469be5aa205e58cb0748.zip
chromium_src-44f92d1b16b0d3b67f53469be5aa205e58cb0748.tar.gz
chromium_src-44f92d1b16b0d3b67f53469be5aa205e58cb0748.tar.bz2
Use the new DrawHighlight() helper to replace GlowHoverController::Draw().
This also makes a behavioral change: we now draw the hover effect for background tabs even when there is a custom theme. In testing, I couldn't find a reason to exclude custom themes; drawing the hover effect works fine and is as helpful as it is on the default theme. BUG=none TEST=none Review URL: https://codereview.chromium.org/1418563016 Cr-Commit-Position: refs/heads/master@{#358012}
Diffstat (limited to 'ui')
-rw-r--r--ui/views/controls/glow_hover_controller.cc50
-rw-r--r--ui/views/controls/glow_hover_controller.h8
2 files changed, 9 insertions, 49 deletions
diff --git a/ui/views/controls/glow_hover_controller.cc b/ui/views/controls/glow_hover_controller.cc
index 5ce23fa..d621cea 100644
--- a/ui/views/controls/glow_hover_controller.cc
+++ b/ui/views/controls/glow_hover_controller.cc
@@ -4,10 +4,6 @@
#include "ui/views/controls/glow_hover_controller.h"
-#include "third_party/skia/include/effects/SkGradientShader.h"
-#include "ui/gfx/canvas.h"
-#include "ui/gfx/image/image_skia.h"
-#include "ui/gfx/image/image_skia_operations.h"
#include "ui/views/view.h"
namespace views {
@@ -72,49 +68,13 @@ double GlowHoverController::GetAnimationValue() const {
return animation_.GetCurrentValue();
}
-bool GlowHoverController::ShouldDraw() const {
- return animation_.IsShowing() || animation_.is_animating();
+SkAlpha GlowHoverController::GetAlpha() const {
+ return static_cast<SkAlpha>(gfx::ToFlooredInt(
+ 0.5 + animation_.CurrentValueBetween(0., 255 * opacity_scale_)));
}
-void GlowHoverController::Draw(gfx::Canvas* canvas,
- const gfx::ImageSkia& mask_image) const {
- if (!ShouldDraw())
- return;
-
- // Draw a radial gradient to hover_canvas.
- gfx::Canvas hover_canvas(gfx::Size(mask_image.width(), mask_image.height()),
- canvas->image_scale(),
- false);
-
- // Draw a radial gradient to hover_canvas.
- int radius = view_->width() / 3;
-
- SkPoint center_point;
- center_point.iset(location_.x(), location_.y());
- SkColor colors[2];
- int hover_alpha =
- static_cast<int>(255 * opacity_scale_ * animation_.GetCurrentValue());
- colors[0] = SkColorSetARGB(hover_alpha, 255, 255, 255);
- colors[1] = SkColorSetARGB(0, 255, 255, 255);
- skia::RefPtr<SkShader> shader = skia::AdoptRef(
- SkGradientShader::CreateRadial(
- center_point, SkIntToScalar(radius), colors, NULL, 2,
- SkShader::kClamp_TileMode));
- // Shader can end up null when radius = 0.
- // If so, this results in default full tab glow behavior.
- if (shader) {
- SkPaint paint;
- paint.setStyle(SkPaint::kFill_Style);
- paint.setAntiAlias(true);
- paint.setShader(shader.get());
- hover_canvas.DrawRect(gfx::Rect(location_.x() - radius,
- location_.y() - radius,
- radius * 2, radius * 2), paint);
- }
- gfx::ImageSkia result = gfx::ImageSkiaOperations::CreateMaskedImage(
- gfx::ImageSkia(hover_canvas.ExtractImageRep()), mask_image);
- canvas->DrawImageInt(result, (view_->width() - mask_image.width()) / 2,
- (view_->height() - mask_image.height()) / 2);
+bool GlowHoverController::ShouldDraw() const {
+ return animation_.IsShowing() || animation_.is_animating();
}
void GlowHoverController::AnimationEnded(const gfx::Animation* animation) {
diff --git a/ui/views/controls/glow_hover_controller.h b/ui/views/controls/glow_hover_controller.h
index 6be5ae7..00bf528 100644
--- a/ui/views/controls/glow_hover_controller.h
+++ b/ui/views/controls/glow_hover_controller.h
@@ -44,6 +44,8 @@ class VIEWS_EXPORT GlowHoverController : public gfx::AnimationDelegate {
// constructor.
void SetLocation(const gfx::Point& location);
+ const gfx::Point& location() const { return location_; }
+
// Initiates showing the hover.
void Show(Style style);
@@ -56,14 +58,12 @@ class VIEWS_EXPORT GlowHoverController : public gfx::AnimationDelegate {
// Returns the value of the animation.
double GetAnimationValue() const;
+ SkAlpha GetAlpha() const;
+
// Returns true if there is something to be drawn. Use this instead of
// invoking Draw() if creating |mask_image| is expensive.
bool ShouldDraw() const;
- // If the hover is currently visible it is drawn to the supplied canvas.
- // |mask_image| is used to determine what parts of the canvas to draw on.
- void Draw(gfx::Canvas* canvas, const gfx::ImageSkia& mask_image) const;
-
// gfx::AnimationDelegate overrides:
void AnimationEnded(const gfx::Animation* animation) override;
void AnimationProgressed(const gfx::Animation* animation) override;