1 // Copyright 2013 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 ASH_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_H_
6 #define ASH_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_H_
8 #include "ash/ash_export.h"
9 #include "ash/frame/caption_buttons/caption_button_types.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "ui/gfx/image/image_skia.h"
12 #include "ui/views/controls/button/custom_button.h"
20 // Base class for the window caption buttons (minimize, maximize, restore,
22 class ASH_EXPORT FrameCaptionButton
: public views::CustomButton
{
29 static const char kViewClassName
[];
31 FrameCaptionButton(views::ButtonListener
* listener
, CaptionButtonIcon icon
);
32 ~FrameCaptionButton() override
;
34 // Sets the images to use to paint the button. If |animate| is ANIMATE_YES,
35 // the button crossfades to the new visuals. If the image ids match those
36 // currently used by the button and |animate| is ANIMATE_NO the crossfade
37 // animation is progressed to the end.
38 void SetImages(CaptionButtonIcon icon
,
41 int hovered_background_image_id
,
42 int pressed_background_image_id
);
44 // Returns true if the button is crossfading to new visuals set in
46 bool IsAnimatingImageSwap() const;
48 // Sets the alpha to use for painting. Used to animate visibility changes.
49 void SetAlpha(int alpha
);
51 // views::View overrides:
52 gfx::Size
GetPreferredSize() const override
;
53 const char* GetClassName() const override
;
54 void OnPaint(gfx::Canvas
* canvas
) override
;
56 void set_paint_as_active(bool paint_as_active
) {
57 paint_as_active_
= paint_as_active
;
60 CaptionButtonIcon
icon() const {
64 int icon_image_id() const { return icon_image_id_
; }
67 // views::CustomButton override:
68 void OnGestureEvent(ui::GestureEvent
* event
) override
;
71 // Paints |to_center| centered within the button with |alpha|.
72 void PaintCentered(gfx::Canvas
* canvas
,
73 const gfx::ImageSkia
& to_center
,
76 // The button's current icon.
77 CaptionButtonIcon icon_
;
79 // Whether the button should be painted as active.
80 bool paint_as_active_
;
82 // Current alpha to use for painting.
85 // The images and image ids used to paint the button.
87 int hovered_background_image_id_
;
88 int pressed_background_image_id_
;
89 gfx::ImageSkia icon_image_
;
90 gfx::ImageSkia hovered_background_image_
;
91 gfx::ImageSkia pressed_background_image_
;
93 // The icon image to crossfade from.
94 gfx::ImageSkia crossfade_icon_image_
;
96 // Crossfade animation started when the button's images are changed by
98 scoped_ptr
<gfx::SlideAnimation
> swap_images_animation_
;
100 DISALLOW_COPY_AND_ASSIGN(FrameCaptionButton
);
105 #endif // ASH_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_H_