Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / ash / launcher / launcher_button.h
blob41169e8250ab53dce712916657715ded6329f559
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.
5 #ifndef ASH_LAUNCHER_LAUNCHER_BUTTON_H_
6 #define ASH_LAUNCHER_LAUNCHER_BUTTON_H_
8 #include "ash/ash_export.h"
9 #include "ui/gfx/shadow_value.h"
10 #include "ui/views/controls/button/custom_button.h"
11 #include "ui/views/controls/image_view.h"
13 namespace ash {
14 namespace internal {
16 class LauncherButtonHost;
17 class ShelfLayoutManager;
19 // Button used for items on the launcher, except for the AppList.
20 class ASH_EXPORT LauncherButton : public views::CustomButton {
21 public:
22 // Used to indicate the current state of the button.
23 enum State {
24 // Nothing special. Usually represents an app shortcut item with no running
25 // instance.
26 STATE_NORMAL = 0,
27 // Button has mouse hovering on it.
28 STATE_HOVERED = 1 << 0,
29 // Underlying LauncherItem has a running instance.
30 // e.g. A TYPE_TABBED item that has a window.
31 STATE_RUNNING = 1 << 1,
32 // Underlying LauncherItem is active (i.e. has focus).
33 STATE_ACTIVE = 1 << 2,
34 // Underlying LauncherItem needs user's attention.
35 STATE_ATTENTION = 1 << 3,
36 STATE_FOCUSED = 1 << 4,
39 virtual ~LauncherButton();
41 // Called to create an instance of a LauncherButton.
42 static LauncherButton* Create(views::ButtonListener* listener,
43 LauncherButtonHost* host,
44 ShelfLayoutManager* shelf_layout_manager);
46 // Sets the image to display for this entry.
47 void SetImage(const gfx::ImageSkia& image);
49 // |state| is or'd into the current state.
50 void AddState(State state);
51 void ClearState(State state);
52 int state() const { return state_; }
53 const ShelfLayoutManager* shelf_layout_manager() const {
54 return shelf_layout_manager_;
57 // Returns the bounds of the icon.
58 gfx::Rect GetIconBounds() const;
60 // Overrides to views::CustomButton:
61 virtual void ShowContextMenu(const gfx::Point& p,
62 bool is_mouse_gesture) OVERRIDE;
64 protected:
65 LauncherButton(views::ButtonListener* listener,
66 LauncherButtonHost* host,
67 ShelfLayoutManager* shelf_layout_manager);
69 // Class that draws the icon part of a button, so it can be animated
70 // independently of the rest. This can be subclassed to provide a custom
71 // implementation, by overriding CreateIconView().
72 class IconView : public views::ImageView {
73 public:
74 IconView();
75 virtual ~IconView();
77 void set_icon_size(int icon_size) { icon_size_ = icon_size; }
78 int icon_size() const { return icon_size_; }
80 // views::View overrides.
81 virtual bool HitTestRect(const gfx::Rect& rect) const OVERRIDE;
83 private:
84 // Set to non-zero to force icons to be resized to fit within a square,
85 // while maintaining original proportions.
86 int icon_size_;
88 DISALLOW_COPY_AND_ASSIGN(IconView);
91 // View overrides:
92 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
93 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE;
94 virtual void OnMouseCaptureLost() OVERRIDE;
95 virtual bool OnMouseDragged(const ui::MouseEvent& event) OVERRIDE;
96 virtual void OnMouseMoved(const ui::MouseEvent& event) OVERRIDE;
97 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
98 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
99 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
100 virtual void Layout() OVERRIDE;
101 virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE;
102 virtual void OnFocus() OVERRIDE;
103 virtual void OnBlur() OVERRIDE;
105 // ui::EventHandler overrides:
106 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
108 // Sets the icon image with a shadow.
109 void SetShadowedImage(const gfx::ImageSkia& bitmap);
110 // Override for custom initialization.
111 virtual void Init();
112 // Override to subclass IconView.
113 virtual IconView* CreateIconView();
114 IconView* icon_view() const { return icon_view_; }
115 LauncherButtonHost* host() const { return host_; }
117 private:
118 class BarView;
120 // Returns true if the shelf is horizontal. If this returns false the shelf is
121 // vertical.
122 bool IsShelfHorizontal() const;
124 // Updates the parts of the button to reflect the current |state_| and
125 // alignment. This may add or remove views, layout and paint.
126 void UpdateState();
128 LauncherButtonHost* host_;
129 IconView* icon_view_;
130 // Draws a bar underneath the image to represent the state of the application.
131 BarView* bar_;
132 // The current state of the application, multiple values of AppState are or'd
133 // together.
134 int state_;
136 ShelfLayoutManager* shelf_layout_manager_;
138 gfx::ShadowValues icon_shadows_;
140 // If non-null the destuctor sets this to true. This is set while the menu is
141 // showing and used to detect if the menu was deleted while running.
142 bool* destroyed_flag_;
144 DISALLOW_COPY_AND_ASSIGN(LauncherButton);
147 } // namespace internal
148 } // namespace ash
150 #endif // ASH_LAUNCHER_LAUNCHER_BUTTON_H_