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