Home | History | Annotate | Download | only in launcher
      1 // Copyright (c) 2012 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_LAUNCHER_TABBED_LAUNCHER_BUTTON_H_
      6 #define ASH_LAUNCHER_TABBED_LAUNCHER_BUTTON_H_
      7 
      8 #include "ash/launcher/launcher_button.h"
      9 #include "base/memory/scoped_ptr.h"
     10 #include "base/timer/timer.h"
     11 #include "ui/base/animation/animation_delegate.h"
     12 #include "ui/views/controls/button/image_button.h"
     13 #include "ui/views/controls/glow_hover_controller.h"
     14 
     15 namespace gfx {
     16 class ImageSkia;
     17 }
     18 
     19 namespace ui {
     20 class MultiAnimation;
     21 }
     22 
     23 namespace ash {
     24 
     25 struct LauncherItem;
     26 
     27 namespace internal {
     28 
     29 // Button used for items on the launcher corresponding to tabbed windows.
     30 class TabbedLauncherButton : public LauncherButton {
     31  public:
     32   // Indicates if this button is incognito or not.
     33   enum IncognitoState {
     34     STATE_INCOGNITO,
     35     STATE_NOT_INCOGNITO,
     36   };
     37 
     38   static TabbedLauncherButton* Create(views::ButtonListener* listener,
     39                                       LauncherButtonHost* host,
     40                                       ShelfLayoutManager* shelf_layout_manager,
     41                                       IncognitoState is_incognito);
     42   virtual ~TabbedLauncherButton();
     43 
     44   // Sets the images to display for this entry.
     45   void SetTabImage(const gfx::ImageSkia& image);
     46 
     47   // This only defines how the icon is drawn. Do not use it for other purposes.
     48   IncognitoState is_incognito() const { return is_incognito_; }
     49 
     50  protected:
     51   TabbedLauncherButton(views::ButtonListener* listener,
     52                        LauncherButtonHost* host,
     53                        ShelfLayoutManager* shelf_layout_manager,
     54                        IncognitoState is_incognito);
     55   // View override.
     56   virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
     57 
     58   // LauncherButton override.
     59   virtual IconView* CreateIconView() OVERRIDE;
     60 
     61  private:
     62   // Used as the delegate for |animation_|.
     63   class IconView : public LauncherButton::IconView,
     64                    public ui::AnimationDelegate {
     65    public:
     66     explicit IconView(TabbedLauncherButton* host);
     67     virtual ~IconView();
     68 
     69     // ui::AnimationDelegateImpl overrides:
     70     virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE;
     71     virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE;
     72 
     73     // Sets the image to display for this entry.
     74     void SetTabImage(const gfx::ImageSkia& image);
     75 
     76    protected:
     77     // View override.
     78     virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
     79 
     80    private:
     81     TabbedLauncherButton* host_;
     82     gfx::ImageSkia image_;
     83     gfx::ImageSkia animating_image_;
     84 
     85     // Used to animate image.
     86     scoped_ptr<ui::MultiAnimation> animation_;
     87 
     88     // Background images. Which one is chosen depends on the type of the window.
     89     static const gfx::ImageSkia* browser_image_;
     90     static const gfx::ImageSkia* incognito_browser_image_;
     91     // TODO[dave] implement panel specific image.
     92     static const gfx::ImageSkia* browser_panel_image_;
     93     static const gfx::ImageSkia* incognito_browser_panel_image_;
     94 
     95     DISALLOW_COPY_AND_ASSIGN(IconView);
     96   };
     97 
     98   IconView* tabbed_icon_view() {
     99     return static_cast<IconView*>(icon_view());
    100   }
    101 
    102   // Indicates how the icon is drawn. If true an Incognito symbol will be
    103   // drawn. It does not necessarily indicate if the window is 'incognito'.
    104   const IncognitoState is_incognito_;
    105 
    106   DISALLOW_COPY_AND_ASSIGN(TabbedLauncherButton);
    107 };
    108 
    109 }  // namespace internal
    110 }  // namespace ash
    111 
    112 #endif  // ASH_LAUNCHER_TABBED_LAUNCHER_BUTTON_H_
    113