Home | History | Annotate | Download | only in caption_buttons
      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   virtual ~FrameCaptionButton();
     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   // views::View overrides:
     50   virtual gfx::Size GetPreferredSize() const OVERRIDE;
     51   virtual const char* GetClassName() const OVERRIDE;
     52   virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
     53 
     54   void set_paint_as_active(bool paint_as_active) {
     55     paint_as_active_ = paint_as_active;
     56   }
     57 
     58   CaptionButtonIcon icon() const {
     59     return icon_;
     60   }
     61 
     62  protected:
     63   // views::CustomButton override:
     64   virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
     65 
     66  private:
     67   // Returns the icon image to paint based on |paint_as_active_|.
     68   const gfx::ImageSkia& GetIconImageToPaint() const;
     69 
     70   // Paints |to_center| centered within the button with |alpha|.
     71   void PaintCentered(gfx::Canvas* canvas,
     72                      const gfx::ImageSkia& to_center,
     73                      int alpha);
     74 
     75   // The button's current icon.
     76   CaptionButtonIcon icon_;
     77 
     78   // Whether the button should be painted as active.
     79   bool paint_as_active_;
     80 
     81   // The images and image ids used to paint the button.
     82   int icon_image_id_;
     83   int inactive_icon_image_id_;
     84   int hovered_background_image_id_;
     85   int pressed_background_image_id_;
     86   gfx::ImageSkia icon_image_;
     87   gfx::ImageSkia inactive_icon_image_;
     88   gfx::ImageSkia hovered_background_image_;
     89   gfx::ImageSkia pressed_background_image_;
     90 
     91   // The icon image to crossfade from.
     92   gfx::ImageSkia crossfade_icon_image_;
     93 
     94   // Crossfade animation started when the button's images are changed by
     95   // SetImages().
     96   scoped_ptr<gfx::SlideAnimation> swap_images_animation_;
     97 
     98   DISALLOW_COPY_AND_ASSIGN(FrameCaptionButton);
     99 };
    100 
    101 }  // namespace ash
    102 
    103 #endif  // ASH_FRAME_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_H_
    104