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
3 // found in the LICENSE file.
5 #ifndef UI_VIEWS_CONTROLS_GLOW_HOVER_CONTROLLER_H_
6 #define UI_VIEWS_CONTROLS_GLOW_HOVER_CONTROLLER_H_
8 #include "ui/gfx/animation/animation_delegate.h"
9 #include "ui/gfx/animation/slide_animation.h"
10 #include "ui/views/views_export.h"
22 // GlowHoverController is responsible for drawing a hover effect as is used by
23 // the tabstrip. Typical usage:
24 // OnMouseEntered() -> invoke Show().
25 // OnMouseMoved() -> invoke SetLocation().
26 // OnMouseExited() -> invoke Hide().
27 // OnPaint() -> if ShouldDraw() returns true invoke Draw().
28 // Internally GlowHoverController uses an animation to animate the glow and
29 // invokes SchedulePaint() back on the View as necessary.
30 class VIEWS_EXPORT GlowHoverController
: public gfx::AnimationDelegate
{
37 explicit GlowHoverController(views::View
* view
);
38 virtual ~GlowHoverController();
40 // Sets the AnimationContainer used by the animation.
41 void SetAnimationContainer(gfx::AnimationContainer
* container
);
43 // Sets the location of the hover, relative to the View passed to the
45 void SetLocation(const gfx::Point
& location
);
47 // Initiates showing the hover.
48 void Show(Style style
);
53 // Hides the hover immediately.
54 void HideImmediately();
56 // Returns the value of the animation.
57 double GetAnimationValue() const;
59 // Returns true if there is something to be drawn. Use this instead of
60 // invoking Draw() if creating |mask_image| is expensive.
61 bool ShouldDraw() const;
63 // If the hover is currently visible it is drawn to the supplied canvas.
64 // |mask_image| is used to determine what parts of the canvas to draw on.
65 void Draw(gfx::Canvas
* canvas
, const gfx::ImageSkia
& mask_image
) const;
67 // gfx::AnimationDelegate overrides:
68 virtual void AnimationEnded(const gfx::Animation
* animation
) OVERRIDE
;
69 virtual void AnimationProgressed(const gfx::Animation
* animation
) OVERRIDE
;
72 // View we're drawing to.
75 // Opacity of the glow ramps up over time.
76 gfx::SlideAnimation animation_
;
78 // Location of the glow, relative to view.
80 double opacity_scale_
;
82 DISALLOW_COPY_AND_ASSIGN(GlowHoverController
);
87 #endif // UI_VIEWS_CONTROLS_GLOW_HOVER_CONTROLLER_H_