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