OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef ASH_COMMON_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_H_ | 5 #ifndef ASH_COMMON_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_H_ |
6 #define ASH_COMMON_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_H_ | 6 #define ASH_COMMON_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "ash/ash_export.h" | 10 #include "ash/ash_export.h" |
11 #include "ash/common/frame/caption_buttons/caption_button_types.h" | 11 #include "ash/common/frame/caption_buttons/caption_button_types.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "ui/gfx/image/image_skia.h" | 13 #include "ui/gfx/image/image_skia.h" |
14 #include "ui/views/controls/button/custom_button.h" | 14 #include "ui/views/controls/button/custom_button.h" |
15 | 15 |
16 namespace gfx { | 16 namespace gfx { |
17 class SlideAnimation; | 17 class SlideAnimation; |
18 struct VectorIcon; | 18 enum class VectorIconId; |
19 } | 19 } |
20 | 20 |
21 namespace ash { | 21 namespace ash { |
22 | 22 |
23 // Base class for the window caption buttons (minimize, maximize, restore, | 23 // Base class for the window caption buttons (minimize, maximize, restore, |
24 // close). | 24 // close). |
25 class ASH_EXPORT FrameCaptionButton : public views::CustomButton { | 25 class ASH_EXPORT FrameCaptionButton : public views::CustomButton { |
26 public: | 26 public: |
27 enum Animate { ANIMATE_YES, ANIMATE_NO }; | 27 enum Animate { ANIMATE_YES, ANIMATE_NO }; |
28 | 28 |
29 static const char kViewClassName[]; | 29 static const char kViewClassName[]; |
30 | 30 |
31 FrameCaptionButton(views::ButtonListener* listener, CaptionButtonIcon icon); | 31 FrameCaptionButton(views::ButtonListener* listener, CaptionButtonIcon icon); |
32 ~FrameCaptionButton() override; | 32 ~FrameCaptionButton() override; |
33 | 33 |
34 // Sets the image to use to paint the button. If |animate| is ANIMATE_YES, | 34 // Sets the image to use to paint the button. If |animate| is ANIMATE_YES, |
35 // the button crossfades to the new visuals. If the image matches the one | 35 // the button crossfades to the new visuals. If the image id matches the one |
36 // currently used by the button and |animate| is ANIMATE_NO, the crossfade | 36 // currently used by the button and |animate| is ANIMATE_NO, the crossfade |
37 // animation is progressed to the end. | 37 // animation is progressed to the end. |
38 void SetImage(CaptionButtonIcon icon, | 38 void SetImage(CaptionButtonIcon icon, |
39 Animate animate, | 39 Animate animate, |
40 const gfx::VectorIcon& icon_image); | 40 gfx::VectorIconId icon_image_id); |
41 | 41 |
42 // Returns true if the button is crossfading to new visuals set in | 42 // Returns true if the button is crossfading to new visuals set in |
43 // SetImage(). | 43 // SetImage(). |
44 bool IsAnimatingImageSwap() const; | 44 bool IsAnimatingImageSwap() const; |
45 | 45 |
46 // Sets the alpha to use for painting. Used to animate visibility changes. | 46 // Sets the alpha to use for painting. Used to animate visibility changes. |
47 void SetAlpha(int alpha); | 47 void SetAlpha(int alpha); |
48 | 48 |
49 // views::View overrides: | 49 // views::View overrides: |
50 gfx::Size GetPreferredSize() const override; | 50 gfx::Size GetPreferredSize() const override; |
51 const char* GetClassName() const override; | 51 const char* GetClassName() const override; |
52 void OnPaint(gfx::Canvas* canvas) override; | 52 void OnPaint(gfx::Canvas* canvas) override; |
53 | 53 |
54 void set_paint_as_active(bool paint_as_active) { | 54 void set_paint_as_active(bool paint_as_active) { |
55 paint_as_active_ = paint_as_active; | 55 paint_as_active_ = paint_as_active; |
56 } | 56 } |
57 | 57 |
58 void set_use_light_images(bool light) { use_light_images_ = light; } | 58 void set_use_light_images(bool light) { use_light_images_ = light; } |
59 | 59 |
60 CaptionButtonIcon icon() const { return icon_; } | 60 CaptionButtonIcon icon() const { return icon_; } |
61 | 61 |
| 62 gfx::VectorIconId icon_image_id() const { return icon_image_id_; } |
| 63 |
62 void set_size(const gfx::Size& size) { size_ = size; } | 64 void set_size(const gfx::Size& size) { size_ = size; } |
63 | 65 |
64 protected: | 66 protected: |
65 // views::CustomButton override: | 67 // views::CustomButton override: |
66 void OnGestureEvent(ui::GestureEvent* event) override; | 68 void OnGestureEvent(ui::GestureEvent* event) override; |
67 | 69 |
68 private: | 70 private: |
69 // Paints |to_center| centered within the button with |alpha|. | 71 // Paints |to_center| centered within the button with |alpha|. |
70 void PaintCentered(gfx::Canvas* canvas, | 72 void PaintCentered(gfx::Canvas* canvas, |
71 const gfx::ImageSkia& to_center, | 73 const gfx::ImageSkia& to_center, |
72 int alpha); | 74 int alpha); |
73 | 75 |
74 // The button's current icon. | 76 // The button's current icon. |
75 CaptionButtonIcon icon_; | 77 CaptionButtonIcon icon_; |
76 | 78 |
77 // The size of the button. | 79 // The size of the button. |
78 gfx::Size size_; | 80 gfx::Size size_; |
79 | 81 |
80 // Whether the button should be painted as active. | 82 // Whether the button should be painted as active. |
81 bool paint_as_active_; | 83 bool paint_as_active_; |
82 | 84 |
83 // Whether to paint in a lighter color (for use on dark backgrounds). | 85 // Whether to paint in a lighter color (for use on dark backgrounds). |
84 bool use_light_images_; | 86 bool use_light_images_; |
85 | 87 |
86 // Current alpha to use for painting. | 88 // Current alpha to use for painting. |
87 int alpha_; | 89 int alpha_; |
88 | 90 |
89 // The image id (kept for the purposes of testing) and image used to paint the | 91 // The image id (kept for the purposes of testing) and image used to paint the |
90 // button's icon. | 92 // button's icon. |
91 const gfx::VectorIcon* icon_definition_ = nullptr; | 93 gfx::VectorIconId icon_image_id_; |
92 gfx::ImageSkia icon_image_; | 94 gfx::ImageSkia icon_image_; |
93 | 95 |
94 // The icon image to crossfade from. | 96 // The icon image to crossfade from. |
95 gfx::ImageSkia crossfade_icon_image_; | 97 gfx::ImageSkia crossfade_icon_image_; |
96 | 98 |
97 // Crossfade animation started when the button's images are changed by | 99 // Crossfade animation started when the button's images are changed by |
98 // SetImage(). | 100 // SetImage(). |
99 std::unique_ptr<gfx::SlideAnimation> swap_images_animation_; | 101 std::unique_ptr<gfx::SlideAnimation> swap_images_animation_; |
100 | 102 |
101 DISALLOW_COPY_AND_ASSIGN(FrameCaptionButton); | 103 DISALLOW_COPY_AND_ASSIGN(FrameCaptionButton); |
102 }; | 104 }; |
103 | 105 |
104 } // namespace ash | 106 } // namespace ash |
105 | 107 |
106 #endif // ASH_COMMON_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_H_ | 108 #endif // ASH_COMMON_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_H_ |
OLD | NEW |