Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ash / frame / caption_buttons / frame_caption_button.h
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.
4
5 #ifndef ASH_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_H_
6 #define ASH_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_H_
7
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"
13
14 namespace gfx {
15 class SlideAnimation;
16 }
17
18 namespace ash {
19
20 // Base class for the window caption buttons (minimize, maximize, restore,
21 // close).
22 class ASH_EXPORT FrameCaptionButton : public views::CustomButton {
23  public:
24   enum Animate {
25     ANIMATE_YES,
26     ANIMATE_NO
27   };
28
29   static const char kViewClassName[];
30
31   FrameCaptionButton(views::ButtonListener* listener, CaptionButtonIcon icon);
32   ~FrameCaptionButton() override;
33
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,
39                  Animate animate,
40                  int icon_image_id,
41                  int inactive_icon_image_id,
42                  int hovered_background_image_id,
43                  int pressed_background_image_id);
44
45   // Returns true if the button is crossfading to new visuals set in
46   // SetImages().
47   bool IsAnimatingImageSwap() const;
48
49   // Sets the alpha to use for painting. Used to animate visibility changes.
50   void SetAlpha(int alpha);
51
52   // views::View overrides:
53   gfx::Size GetPreferredSize() const override;
54   const char* GetClassName() const override;
55   void OnPaint(gfx::Canvas* canvas) override;
56
57   void set_paint_as_active(bool paint_as_active) {
58     paint_as_active_ = paint_as_active;
59   }
60
61   CaptionButtonIcon icon() const {
62     return icon_;
63   }
64
65  protected:
66   // views::CustomButton override:
67   void OnGestureEvent(ui::GestureEvent* event) override;
68
69  private:
70   // Returns the icon image to paint based on |paint_as_active_|.
71   const gfx::ImageSkia& GetIconImageToPaint() const;
72
73   // Paints |to_center| centered within the button with |alpha|.
74   void PaintCentered(gfx::Canvas* canvas,
75                      const gfx::ImageSkia& to_center,
76                      int alpha);
77
78   // The button's current icon.
79   CaptionButtonIcon icon_;
80
81   // Whether the button should be painted as active.
82   bool paint_as_active_;
83
84   // Current alpha to use for painting.
85   int alpha_;
86
87   // The images and image ids used to paint the button.
88   int icon_image_id_;
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_;
96
97   // The icon image to crossfade from.
98   gfx::ImageSkia crossfade_icon_image_;
99
100   // Crossfade animation started when the button's images are changed by
101   // SetImages().
102   scoped_ptr<gfx::SlideAnimation> swap_images_animation_;
103
104   DISALLOW_COPY_AND_ASSIGN(FrameCaptionButton);
105 };
106
107 }  // namespace ash
108
109 #endif  // ASH_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_H_