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