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 inactive_icon_image_id,
42 int hovered_background_image_id,
43 int pressed_background_image_id);
45 // Returns true if the button is crossfading to new visuals set in
47 bool IsAnimatingImageSwap() const;
49 // Sets the alpha to use for painting. Used to animate visibility changes.
50 void SetAlpha(int alpha);
52 // views::View overrides:
53 gfx::Size GetPreferredSize() const override;
54 const char* GetClassName() const override;
55 void OnPaint(gfx::Canvas* canvas) override;
57 void set_paint_as_active(bool paint_as_active) {
58 paint_as_active_ = paint_as_active;
61 CaptionButtonIcon icon() const {
66 // views::CustomButton override:
67 void OnGestureEvent(ui::GestureEvent* event) override;
70 // Returns the icon image to paint based on |paint_as_active_|.
71 const gfx::ImageSkia& GetIconImageToPaint() const;
73 // Paints |to_center| centered within the button with |alpha|.
74 void PaintCentered(gfx::Canvas* canvas,
75 const gfx::ImageSkia& to_center,
78 // The button's current icon.
79 CaptionButtonIcon icon_;
81 // Whether the button should be painted as active.
82 bool paint_as_active_;
84 // Current alpha to use for painting.
87 // The images and image ids used to paint the button.
89 int inactive_icon_image_id_;
90 int hovered_background_image_id_;
91 int pressed_background_image_id_;
92 gfx::ImageSkia icon_image_;
93 gfx::ImageSkia inactive_icon_image_;
94 gfx::ImageSkia hovered_background_image_;
95 gfx::ImageSkia pressed_background_image_;
97 // The icon image to crossfade from.
98 gfx::ImageSkia crossfade_icon_image_;
100 // Crossfade animation started when the button's images are changed by
102 scoped_ptr<gfx::SlideAnimation> swap_images_animation_;
104 DISALLOW_COPY_AND_ASSIGN(FrameCaptionButton);
109 #endif // ASH_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_H_