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_WM_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_H_
      6 #define ASH_WM_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_H_
      7 
      8 #include "ash/ash_export.h"
      9 #include "ash/wm/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/image_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::ImageButton {
     23  public:
     24   enum Animate {
     25     ANIMATE_YES,
     26     ANIMATE_NO
     27   };
     28 
     29   enum Style {
     30     // Restored tabbed browser windows.
     31     STYLE_TALL_RESTORED,
     32 
     33     // All other restored windows.
     34     STYLE_SHORT_RESTORED,
     35 
     36     // Maximized or fullscreen windows.
     37     STYLE_SHORT_MAXIMIZED_OR_FULLSCREEN
     38   };
     39 
     40   static const char kViewClassName[];
     41 
     42   FrameCaptionButton(views::ButtonListener* listener, CaptionButtonIcon icon);
     43   virtual ~FrameCaptionButton();
     44 
     45   // Sets the button's icon. If |animate| is ANIMATE_YES, the button crossfades
     46   // to the new icon.
     47   void SetIcon(CaptionButtonIcon icon, Animate animate);
     48 
     49   // Sets the button's style. The transition to the new style is not animated.
     50   void SetStyle(Style style);
     51 
     52   // views::View overrides:
     53   virtual const char* GetClassName() const OVERRIDE;
     54   virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
     55 
     56   CaptionButtonIcon icon() const {
     57     return icon_;
     58   }
     59 
     60  protected:
     61   // views::CustomButton overrides:
     62   virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
     63   virtual void StateChanged() OVERRIDE;
     64 
     65  private:
     66   // Updates the button's images based on the current icon and style.
     67   void UpdateImages();
     68 
     69   // Sets the button's images based on the given ids.
     70   void SetImages(int normal_image_id, int hot_image_id, int pushed_image_id);
     71 
     72   // gfx::AnimationDelegate override:
     73   virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
     74 
     75   // The button's current icon.
     76   CaptionButtonIcon icon_;
     77 
     78   // The button's current style.
     79   Style style_;
     80 
     81   // The scale at which the button was previously painted.
     82   float last_paint_scale_;
     83 
     84   // The image to crossfade from.
     85   gfx::ImageSkia crossfade_image_;
     86 
     87   scoped_ptr<gfx::SlideAnimation> animation_;
     88 
     89   DISALLOW_COPY_AND_ASSIGN(FrameCaptionButton);
     90 };
     91 
     92 }  // namespace ash
     93 
     94 #endif  // ASH_WM_CAPTION_BUTTONS_FRAME_CAPTION_BUTTON_H_
     95